mirror of https://github.com/jumpserver/jumpserver
				
				
				
			initial sudo views
							parent
							
								
									d9278c2c24
								
							
						
					
					
						commit
						82412831d5
					
				| 
						 | 
					@ -0,0 +1,14 @@
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					    jumpserver.__app__.hands.py
 | 
				
			||||||
 | 
					    ~~~~~~~~~~~~~~~~~
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    This app depends other apps api, function .. should be import or write mack here.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Other module of this app shouldn't connect with other app.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    :copyright: (c) 2014-2016 by Jumpserver Team.
 | 
				
			||||||
 | 
					    :license: GPL v2, see LICENSE for more details.
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from users.utils import AdminUserRequiredMixin
 | 
				
			||||||
| 
						 | 
					@ -334,7 +334,7 @@ class Sudo(models.Model):
 | 
				
			||||||
                   "Host_Alias": self.hosts,
 | 
					                   "Host_Alias": self.hosts,
 | 
				
			||||||
                   "Runas_Alias": self.runas,
 | 
					                   "Runas_Alias": self.runas,
 | 
				
			||||||
                   "Extra_Lines": self.extras,
 | 
					                   "Extra_Lines": self.extras,
 | 
				
			||||||
                   "privileges": self.privileges}
 | 
					                   "Privileges": self.privileges}
 | 
				
			||||||
        return template.render(context)
 | 
					        return template.render(context)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
| 
						 | 
					@ -392,7 +392,7 @@ root    ALL=(ALL:ALL) ALL
 | 
				
			||||||
# JumpServer Generate User privilege is here.
 | 
					# JumpServer Generate User privilege is here.
 | 
				
			||||||
# Note privileges is a tuple list like [(user, host, runas, command, nopassword),]
 | 
					# Note privileges is a tuple list like [(user, host, runas, command, nopassword),]
 | 
				
			||||||
{% if privileges -%}
 | 
					{% if privileges -%}
 | 
				
			||||||
{% for User_Flag, Host_Flag, Runas_Flag, Command_Flag, NopassWord in privileges -%}
 | 
					{% for User_Flag, Host_Flag, Runas_Flag, Command_Flag, NopassWord in Privileges -%}
 | 
				
			||||||
{% if NopassWord -%}
 | 
					{% if NopassWord -%}
 | 
				
			||||||
{{ User_Flag }} {{ Host_Flag }}=({{ Runas_Flag }}) NOPASSWD: {{ Command_Flag }}
 | 
					{{ User_Flag }} {{ Host_Flag }}=({{ Runas_Flag }}) NOPASSWD: {{ Command_Flag }}
 | 
				
			||||||
{%- else -%}
 | 
					{%- else -%}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,2 +1,41 @@
 | 
				
			||||||
# ~*~ coding: utf-8 ~*~
 | 
					# ~*~ coding: utf-8 ~*~
 | 
				
			||||||
#
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class CreateHostAliasMinxin(object):
 | 
				
			||||||
 | 
					    pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class CreateUserAliasMinxin(object):
 | 
				
			||||||
 | 
					    pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class CreateCmdAliasMinxin(object):
 | 
				
			||||||
 | 
					    pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class CreateRunasAliasMinxin(object):
 | 
				
			||||||
 | 
					    pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class CreateExtralineAliasMinxin(object):
 | 
				
			||||||
 | 
					    pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class UpdateHostAliasMinxin(object):
 | 
				
			||||||
 | 
					    pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class UpdateUserAliasMinxin(object):
 | 
				
			||||||
 | 
					    pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class UpdateCmdAliasMinxin(object):
 | 
				
			||||||
 | 
					    pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class UpdateRunasAliasMinxin(object):
 | 
				
			||||||
 | 
					    pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class UpdateExtralineAliasMinxin(object):
 | 
				
			||||||
 | 
					    pass
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,121 @@
 | 
				
			||||||
from django.shortcuts import render
 | 
					# ~*~ coding: utf-8 ~*~
 | 
				
			||||||
 | 
					from __future__ import unicode_literals
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Create your views here.
 | 
					from django.conf import settings
 | 
				
			||||||
 | 
					from django.views.generic.list import ListView, MultipleObjectMixin
 | 
				
			||||||
 | 
					from django.views.generic.edit import CreateView, DeleteView, UpdateView
 | 
				
			||||||
 | 
					from django.views.generic.detail import DetailView, SingleObjectMixin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from .hands import AdminUserRequiredMixin
 | 
				
			||||||
 | 
					from .utils import *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class SudoListView(AdminUserRequiredMixin, ListView):
 | 
				
			||||||
 | 
					    paginate_by = settings.CONFIG.DISPLAY_PER_PAGE
 | 
				
			||||||
 | 
					    model = Asset
 | 
				
			||||||
 | 
					    context_object_name = 'asset_list'
 | 
				
			||||||
 | 
					    template_name = 'assets/asset_list.html'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_queryset(self):
 | 
				
			||||||
 | 
					        queryset = super(AssetListView, self).get_queryset()
 | 
				
			||||||
 | 
					        queryset = sorted(queryset, key=self.sorted_by_valid_and_ip)
 | 
				
			||||||
 | 
					        return queryset
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @staticmethod
 | 
				
			||||||
 | 
					    def sorted_by_valid_and_ip(asset):
 | 
				
			||||||
 | 
					        ip_list = int_seq(asset.ip.split('.'))
 | 
				
			||||||
 | 
					        ip_list.insert(0, asset.is_valid()[0])
 | 
				
			||||||
 | 
					        return ip_list
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_context_data(self, **kwargs):
 | 
				
			||||||
 | 
					        context = {
 | 
				
			||||||
 | 
					            'app': 'Assets',
 | 
				
			||||||
 | 
					            'action': 'asset list',
 | 
				
			||||||
 | 
					            'tag_list': [(i.id,i.name,i.asset_set.all().count())for i in Tag.objects.all().order_by('name')]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        kwargs.update(context)
 | 
				
			||||||
 | 
					        return super(AssetListView, self).get_context_data(**kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class SudoCreateView(AdminUserRequiredMixin,
 | 
				
			||||||
 | 
					                     CreateHostAliasMinxin,
 | 
				
			||||||
 | 
					                     CreateUserAliasMinxin,
 | 
				
			||||||
 | 
					                     CreateCmdAliasMinxin,
 | 
				
			||||||
 | 
					                     CreateRunasAliasMinxin,
 | 
				
			||||||
 | 
					                     CreateExtralineAliasMinxin,
 | 
				
			||||||
 | 
					                     CreateView):
 | 
				
			||||||
 | 
					    model = Asset
 | 
				
			||||||
 | 
					    tag_type = 'asset'
 | 
				
			||||||
 | 
					    form_class = AssetCreateForm
 | 
				
			||||||
 | 
					    template_name = 'assets/asset_create.html'
 | 
				
			||||||
 | 
					    success_url = reverse_lazy('assets:asset-list')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def form_valid(self, form):
 | 
				
			||||||
 | 
					        asset = form.save()
 | 
				
			||||||
 | 
					        asset.created_by = self.request.user.username or 'Admin'
 | 
				
			||||||
 | 
					        asset.save()
 | 
				
			||||||
 | 
					        return super(AssetCreateView, self).form_valid(form)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def form_invalid(self, form):
 | 
				
			||||||
 | 
					        print(form.errors)
 | 
				
			||||||
 | 
					        return super(AssetCreateView, self).form_invalid(form)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_context_data(self, **kwargs):
 | 
				
			||||||
 | 
					        context = {
 | 
				
			||||||
 | 
					            'app': 'Assets',
 | 
				
			||||||
 | 
					            'action': 'Create asset',
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        kwargs.update(context)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return super(AssetCreateView, self).get_context_data(**kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class SudoUpdateView(AdminUserRequiredMixin,
 | 
				
			||||||
 | 
					                     UpdateHostAliasMinxin,
 | 
				
			||||||
 | 
					                     UpdateUserAliasMinxin,
 | 
				
			||||||
 | 
					                     UpdateCmdAliasMinxin,
 | 
				
			||||||
 | 
					                     UpdateRunasAliasMinxin,
 | 
				
			||||||
 | 
					                     UpdateExtralineAliasMinxin,
 | 
				
			||||||
 | 
					                     UpdateView):
 | 
				
			||||||
 | 
					    model = Asset
 | 
				
			||||||
 | 
					    form_class = AssetCreateForm
 | 
				
			||||||
 | 
					    template_name = 'assets/asset_update.html'
 | 
				
			||||||
 | 
					    success_url = reverse_lazy('assets:asset-list')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_context_data(self, **kwargs):
 | 
				
			||||||
 | 
					        context = {
 | 
				
			||||||
 | 
					            'app': 'Assets',
 | 
				
			||||||
 | 
					            'action': 'Update asset',
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        kwargs.update(context)
 | 
				
			||||||
 | 
					        return super(AssetUpdateView, self).get_context_data(**kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def form_invalid(self, form):
 | 
				
			||||||
 | 
					        print(form.errors)
 | 
				
			||||||
 | 
					        return super(AssetUpdateView, self).form_invalid(form)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class SudoDeleteView(DeleteView):
 | 
				
			||||||
 | 
					    model = Asset
 | 
				
			||||||
 | 
					    template_name = 'assets/delete_confirm.html'
 | 
				
			||||||
 | 
					    success_url = reverse_lazy('assets:asset-list')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class SudoDetailView(DetailView):
 | 
				
			||||||
 | 
					    model = Asset
 | 
				
			||||||
 | 
					    context_object_name = 'asset'
 | 
				
			||||||
 | 
					    template_name = 'assets/asset_detail.html'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_context_data(self, **kwargs):
 | 
				
			||||||
 | 
					        asset_groups = self.object.groups.all()
 | 
				
			||||||
 | 
					        context = {
 | 
				
			||||||
 | 
					            'app': 'Assets',
 | 
				
			||||||
 | 
					            'action': 'Asset detail',
 | 
				
			||||||
 | 
					            'asset_groups_remain': [asset_group for asset_group in AssetGroup.objects.all()
 | 
				
			||||||
 | 
					                                   if asset_group not in asset_groups],
 | 
				
			||||||
 | 
					            'asset_groups': asset_groups,
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        kwargs.update(context)
 | 
				
			||||||
 | 
					        return super(AssetDetailView, self).get_context_data(**kwargs)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue