mirror of https://github.com/jumpserver/jumpserver
[Update] 修改一些逻辑
parent
44bf01d4ed
commit
70fa43adaa
|
@ -1,5 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
from django import forms
|
||||
|
||||
from orgs.mixins import OrgModelForm
|
||||
from ..models import CommandFilter, CommandFilterRule
|
||||
|
||||
|
@ -18,3 +20,8 @@ class CommandFilterRuleForm(OrgModelForm):
|
|||
fields = [
|
||||
'filter', 'type', 'content', 'priority', 'action', 'comment'
|
||||
]
|
||||
widgets = {
|
||||
'content': forms.Textarea(attrs={
|
||||
'placeholder': 'eg:\r\nreboot\r\nrm -rf'
|
||||
}),
|
||||
}
|
||||
|
|
|
@ -35,11 +35,10 @@ class CommandFilterRule(OrgModelMixin):
|
|||
(TYPE_COMMAND, _('Command')),
|
||||
)
|
||||
|
||||
ACTION_DENY = 'deny'
|
||||
ACTION_ACCEPT = 'accept'
|
||||
ACTION_DENY, ACTION_ALLOW = range(2)
|
||||
ACTION_CHOICES = (
|
||||
(ACTION_DENY, _('Deny')),
|
||||
(ACTION_ACCEPT, _('Accept'))
|
||||
(ACTION_ALLOW, _('Allow')),
|
||||
)
|
||||
|
||||
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
|
||||
|
@ -47,11 +46,14 @@ class CommandFilterRule(OrgModelMixin):
|
|||
type = models.CharField(max_length=16, default=TYPE_COMMAND, choices=TYPE_CHOICES, verbose_name=_("Type"))
|
||||
priority = models.IntegerField(default=50, verbose_name=_("Priority"), validators=[MinValueValidator(1), MaxValueValidator(100)])
|
||||
content = models.TextField(max_length=1024, verbose_name=_("Content"), help_text=_("One line one command"))
|
||||
action = models.CharField(max_length=16, default=ACTION_DENY, choices=ACTION_CHOICES, verbose_name=_("Action"))
|
||||
action = models.IntegerField(default=ACTION_DENY, choices=ACTION_CHOICES, verbose_name=_("Action"))
|
||||
comment = models.CharField(max_length=64, blank=True, default='', verbose_name=_("Comment"))
|
||||
date_created = models.DateTimeField(auto_now_add=True)
|
||||
date_updated = models.DateTimeField(auto_now=True)
|
||||
created_by = models.CharField(max_length=128, blank=True, default='', verbose_name=_('Created by'))
|
||||
|
||||
class Meta:
|
||||
ordering = ('priority', 'action')
|
||||
|
||||
def __str__(self):
|
||||
return '{} % {}'.format(self.type, self.content)
|
||||
|
|
|
@ -38,12 +38,10 @@ class Node(OrgModelMixin):
|
|||
return True
|
||||
self_key = [int(k) for k in self.key.split(':')]
|
||||
other_key = [int(k) for k in other.key.split(':')]
|
||||
if len(self_key) < len(other_key):
|
||||
return True
|
||||
elif len(self_key) > len(other_key):
|
||||
return False
|
||||
else:
|
||||
return self_key[-1] < other_key[-1]
|
||||
return self_key.__lt__(other_key)
|
||||
|
||||
def __lt__(self, other):
|
||||
return not self.__gt__(other)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -117,7 +117,7 @@ class SystemUser(AssetUser):
|
|||
sudo = models.TextField(default='/bin/whoami', verbose_name=_('Sudo'))
|
||||
shell = models.CharField(max_length=64, default='/bin/bash', verbose_name=_('Shell'))
|
||||
login_mode = models.CharField(choices=LOGIN_MODE_CHOICES, default=AUTO_LOGIN, max_length=10, verbose_name=_('Login mode'))
|
||||
cmd_filters = models.ManyToManyField('CommandFilter', related_name='system_users', verbose_name=_("Command filter"))
|
||||
cmd_filters = models.ManyToManyField('CommandFilter', related_name='system_users', verbose_name=_("Command filter"), blank=True)
|
||||
|
||||
cache_key = "__SYSTEM_USER_CACHED_{}"
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ $(document).ready(function(){
|
|||
var $data_table = $('#cmd_filter_list_table').DataTable();
|
||||
var name = $(this).closest("tr").find(":nth-child(2)").children('a').html();
|
||||
var uid = $this.data('uid');
|
||||
var the_url = '{% url "api-assets:label-detail" pk=DEFAULT_PK %}'.replace('{{ DEFAULT_PK }}', uid);
|
||||
var the_url = '{% url "api-assets:cmd-filter-detail" pk=DEFAULT_PK %}'.replace('{{ DEFAULT_PK }}', uid);
|
||||
objectDelete($this, name, the_url);
|
||||
setTimeout( function () {
|
||||
$data_table.ajax.reload();
|
||||
|
|
|
@ -51,7 +51,24 @@
|
|||
|
||||
{% block custom_foot_js %}
|
||||
<script>
|
||||
var content_origin_placeholder = '';
|
||||
var content_origin_help_text = '';
|
||||
var content_ref = '';
|
||||
var content_help_ref = '';
|
||||
|
||||
$(document).ready(function(){
|
||||
content_ref = $('#id_content');
|
||||
content_help_ref = content_ref.next();
|
||||
content_origin_placeholder = content_ref.attr('placeholder');
|
||||
content_origin_help_text = content_help_ref.html();
|
||||
}).on('change', '#id_type', function () {
|
||||
if ($('#id_type :selected').val() === 'regex') {
|
||||
content_ref.attr('placeholder', 'rm.*|reboot|shutdown');
|
||||
content_help_ref.html("");
|
||||
} else {
|
||||
content_ref.attr('placeholder', content_origin_placeholder);
|
||||
content_help_ref.html(content_origin_help_text);
|
||||
}
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
|
@ -1,4 +1,5 @@
|
|||
{% extends 'base.html' %}
|
||||
{% load common_tags %}
|
||||
{% load static %}
|
||||
{% load i18n %}
|
||||
|
||||
|
@ -113,7 +114,7 @@
|
|||
</tr>
|
||||
</form>
|
||||
|
||||
{% for node in system_user.nodes.all %}
|
||||
{% for node in system_user.nodes.all|sort %}
|
||||
<tr>
|
||||
<td ><b class="bdg_node" data-gid={{ node.id }}>{{ node }}</b></td>
|
||||
<td>
|
||||
|
|
|
@ -91,10 +91,11 @@ class SystemUserAssetView(AdminUserRequiredMixin, DetailView):
|
|||
context_object_name = 'system_user'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
nodes_remain = sorted(Node.objects.exclude(systemuser=self.object), reverse=True)
|
||||
context = {
|
||||
'app': _('assets'),
|
||||
'action': _('System user asset'),
|
||||
'nodes_remain': Node.objects.exclude(systemuser=self.object)
|
||||
'nodes_remain': nodes_remain
|
||||
}
|
||||
kwargs.update(context)
|
||||
return super().get_context_data(**kwargs)
|
||||
|
|
|
@ -100,3 +100,9 @@ def is_bool_field(field):
|
|||
@register.filter
|
||||
def to_dict(data):
|
||||
return dict(data)
|
||||
|
||||
|
||||
@register.filter
|
||||
def sort(data):
|
||||
print(data)
|
||||
return sorted(data)
|
||||
|
|
Binary file not shown.
|
@ -1295,7 +1295,7 @@ msgstr "创建规则"
|
|||
|
||||
#: assets/templates/assets/cmd_filter_rule_list.html:61
|
||||
msgid "Strategy"
|
||||
msgstr "分类"
|
||||
msgstr "策略"
|
||||
|
||||
#: assets/templates/assets/delete_confirm.html:6
|
||||
#: perms/templates/perms/delete_confirm.html:6 templates/delete_confirm.html:6
|
||||
|
|
Loading…
Reference in New Issue