Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
guo xiaoyong
Jumpserver
Commits
70fa43ad
Commit
70fa43ad
authored
6 years ago
by
ibuler
Browse files
Options
Download
Email Patches
Plain Diff
[Update] 修改一些逻辑
parent
44bf01d4
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
apps/assets/forms/cmd_filter.py
+7
-0
apps/assets/forms/cmd_filter.py
apps/assets/models/cmd_filter.py
+6
-4
apps/assets/models/cmd_filter.py
apps/assets/models/node.py
+4
-6
apps/assets/models/node.py
apps/assets/models/user.py
+1
-1
apps/assets/models/user.py
apps/assets/templates/assets/cmd_filter_list.html
+1
-1
apps/assets/templates/assets/cmd_filter_list.html
apps/assets/templates/assets/cmd_filter_rule_create_update.html
+17
-0
...ssets/templates/assets/cmd_filter_rule_create_update.html
apps/assets/templates/assets/system_user_asset.html
+2
-1
apps/assets/templates/assets/system_user_asset.html
apps/assets/views/system_user.py
+2
-1
apps/assets/views/system_user.py
apps/common/templatetags/common_tags.py
+6
-0
apps/common/templatetags/common_tags.py
apps/locale/zh/LC_MESSAGES/django.mo
+0
-0
apps/locale/zh/LC_MESSAGES/django.mo
apps/locale/zh/LC_MESSAGES/django.po
+1
-1
apps/locale/zh/LC_MESSAGES/django.po
with
47 additions
and
15 deletions
+47
-15
apps/assets/forms/cmd_filter.py
+
7
-
0
View file @
70fa43ad
# -*- 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\n
reboot
\r\n
rm -rf'
}),
}
This diff is collapsed.
Click to expand it.
apps/assets/models/cmd_filter.py
+
6
-
4
View file @
70fa43ad
...
...
@@ -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_A
CCEPT
,
_
(
'A
ccept
'
))
(
ACTION_A
LLOW
,
_
(
'A
llow
'
))
,
)
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
.
Cha
rField
(
max_length
=
16
,
default
=
ACTION_DENY
,
choices
=
ACTION_CHOICES
,
verbose_name
=
_
(
"Action"
))
action
=
models
.
Intege
rField
(
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
)
This diff is collapsed.
Click to expand it.
apps/assets/models/node.py
+
4
-
6
View file @
70fa43ad
...
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
apps/assets/models/user.py
+
1
-
1
View file @
70fa43ad
...
...
@@ -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_{}"
...
...
This diff is collapsed.
Click to expand it.
apps/assets/templates/assets/cmd_filter_list.html
+
1
-
1
View file @
70fa43ad
...
...
@@ -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
();
...
...
This diff is collapsed.
Click to expand it.
apps/assets/templates/assets/cmd_filter_rule_create_update.html
+
17
-
0
View file @
70fa43ad
...
...
@@ -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 %}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
apps/assets/templates/assets/system_user_asset.html
+
2
-
1
View file @
70fa43ad
{% 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>
...
...
This diff is collapsed.
Click to expand it.
apps/assets/views/system_user.py
+
2
-
1
View file @
70fa43ad
...
...
@@ -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'
:
N
ode
.
objects
.
exclude
(
systemuser
=
self
.
object
)
'nodes_remain'
:
n
ode
s_remain
}
kwargs
.
update
(
context
)
return
super
().
get_context_data
(
**
kwargs
)
This diff is collapsed.
Click to expand it.
apps/common/templatetags/common_tags.py
+
6
-
0
View file @
70fa43ad
...
...
@@ -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
)
This diff is collapsed.
Click to expand it.
apps/locale/zh/LC_MESSAGES/django.mo
+
0
-
0
View file @
70fa43ad
No preview for this file type
This diff is collapsed.
Click to expand it.
apps/locale/zh/LC_MESSAGES/django.po
+
1
-
1
View file @
70fa43ad
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help