Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
f886e7c2
Commit
f886e7c2
authored
Feb 27, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改授权api, windows资产只有rdp协议,linux只有ssh协议
parent
91863107
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
52 additions
and
9 deletions
+52
-9
asset.py
apps/assets/forms/asset.py
+2
-2
asset.py
apps/assets/models/asset.py
+17
-1
asset_create.html
apps/assets/templates/assets/asset_create.html
+1
-0
asset_update.html
apps/assets/templates/assets/asset_update.html
+1
-0
api.py
apps/perms/api.py
+13
-2
asset_permission_list.html
apps/perms/templates/perms/asset_permission_list.html
+1
-1
models.py
apps/terminal/models.py
+2
-0
tasks.py
apps/terminal/tasks.py
+13
-3
session_list.html
apps/terminal/templates/terminal/session_list.html
+2
-0
No files found.
apps/assets/forms/asset.py
View file @
f886e7c2
...
...
@@ -15,7 +15,7 @@ class AssetCreateForm(forms.ModelForm):
model
=
Asset
fields
=
[
'hostname'
,
'ip'
,
'public_ip'
,
'port'
,
'comment'
,
'nodes'
,
'is_active'
,
'admin_user'
,
'labels'
,
'nodes'
,
'is_active'
,
'admin_user'
,
'labels'
,
'platform'
,
]
widgets
=
{
...
...
@@ -44,7 +44,7 @@ class AssetUpdateForm(forms.ModelForm):
class
Meta
:
model
=
Asset
fields
=
[
'hostname'
,
'ip'
,
'port'
,
'nodes'
,
'is_active'
,
'hostname'
,
'ip'
,
'port'
,
'nodes'
,
'is_active'
,
'platform'
,
'public_ip'
,
'number'
,
'comment'
,
'admin_user'
,
'labels'
,
]
widgets
=
{
...
...
apps/assets/models/asset.py
View file @
f886e7c2
...
...
@@ -38,6 +38,14 @@ def default_node():
class
Asset
(
models
.
Model
):
# Important
PLATFORM_CHOICES
=
(
(
'Linux'
,
'Linux'
),
(
'Unix'
,
'Unix'
),
(
'MacOS'
,
'MacOS'
),
(
'BSD'
,
'BSD'
),
(
'Windows'
,
'Windows'
),
(
'Other'
,
'Other'
),
)
id
=
models
.
UUIDField
(
default
=
uuid
.
uuid4
,
primary_key
=
True
)
ip
=
models
.
GenericIPAddressField
(
max_length
=
32
,
verbose_name
=
_
(
'IP'
),
db_index
=
True
)
hostname
=
models
.
CharField
(
max_length
=
128
,
unique
=
True
,
verbose_name
=
_
(
'Hostname'
))
...
...
@@ -64,7 +72,7 @@ class Asset(models.Model):
disk_total
=
models
.
CharField
(
max_length
=
1024
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Disk total'
))
disk_info
=
models
.
CharField
(
max_length
=
1024
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Disk info'
))
platform
=
models
.
CharField
(
max_length
=
128
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Platform'
))
platform
=
models
.
CharField
(
max_length
=
128
,
choices
=
PLATFORM_CHOICES
,
default
=
'Linux'
,
verbose_name
=
_
(
'Platform'
))
os
=
models
.
CharField
(
max_length
=
128
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'OS'
))
os_version
=
models
.
CharField
(
max_length
=
16
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'OS version'
))
os_arch
=
models
.
CharField
(
max_length
=
16
,
blank
=
True
,
null
=
True
,
verbose_name
=
_
(
'OS arch'
))
...
...
@@ -87,6 +95,12 @@ class Asset(models.Model):
return
True
,
''
return
False
,
warning
def
is_unixlike
(
self
):
if
self
.
platform
not
in
(
"Windows"
,
"Other"
):
return
True
else
:
return
False
@property
def
hardware_info
(
self
):
if
self
.
cpu_count
:
...
...
@@ -99,6 +113,8 @@ class Asset(models.Model):
@property
def
is_connective
(
self
):
if
not
self
.
is_unixlike
():
return
True
val
=
cache
.
get
(
ASSET_ADMIN_CONN_CACHE_KEY
.
format
(
self
.
hostname
))
if
val
==
1
:
return
True
...
...
apps/assets/templates/assets/asset_create.html
View file @
f886e7c2
...
...
@@ -17,6 +17,7 @@
{% bootstrap_field form.hostname layout="horizontal" %}
{% bootstrap_field form.ip layout="horizontal" %}
{% bootstrap_field form.port layout="horizontal" %}
{% bootstrap_field form.platform layout="horizontal" %}
{% bootstrap_field form.public_ip layout="horizontal" %}
<div
class=
"hr-line-dashed"
></div>
...
...
apps/assets/templates/assets/asset_update.html
View file @
f886e7c2
...
...
@@ -22,6 +22,7 @@
{% bootstrap_field form.hostname layout="horizontal" %}
{% bootstrap_field form.ip layout="horizontal" %}
{% bootstrap_field form.port layout="horizontal" %}
{% bootstrap_field form.platform layout="horizontal" %}
{% bootstrap_field form.public_ip layout="horizontal" %}
<div
class=
"hr-line-dashed"
></div>
...
...
apps/perms/api.py
View file @
f886e7c2
...
...
@@ -54,7 +54,11 @@ class UserGrantedAssetsApi(ListAPIView):
user
=
self
.
request
.
user
for
k
,
v
in
NodePermissionUtil
.
get_user_assets
(
user
)
.
items
():
k
.
system_users_granted
=
v
if
k
.
is_unixlike
():
system_users_granted
=
[
s
for
s
in
v
if
s
.
protocol
==
'ssh'
]
else
:
system_users_granted
=
[
s
for
s
in
v
if
s
.
protocol
==
'rdp'
]
k
.
system_users_granted
=
system_users_granted
queryset
.
append
(
k
)
return
queryset
...
...
@@ -118,9 +122,16 @@ class UserGrantedNodesWithAssetsApi(ListAPIView):
user
=
get_object_or_404
(
User
,
id
=
user_id
)
nodes
=
NodePermissionUtil
.
get_user_nodes_with_assets
(
user
)
assets
=
{}
for
k
,
v
in
NodePermissionUtil
.
get_user_assets
(
user
)
.
items
():
if
k
.
is_unixlike
():
system_users_granted
=
[
s
for
s
in
v
if
s
.
protocol
==
'ssh'
]
else
:
system_users_granted
=
[
s
for
s
in
v
if
s
.
protocol
==
'rdp'
]
assets
[
k
]
=
system_users_granted
for
node
,
v
in
nodes
.
items
():
for
asset
in
v
[
'assets'
]:
asset
.
system_users_granted
=
v
[
'system_users'
]
asset
.
system_users_granted
=
assets
[
asset
]
node
.
assets_granted
=
v
[
'assets'
]
queryset
.
append
(
node
)
return
queryset
...
...
apps/perms/templates/perms/asset_permission_list.html
View file @
f886e7c2
...
...
@@ -223,7 +223,7 @@ $(document).ready(function(){
current_node
=
nodes
[
0
];
url
+=
"?node="
+
current_node
.
id
;
}
window
.
open
(
url
);
window
.
open
(
url
,
'_self'
);
})
.
on
(
'click'
,
'.btn-del'
,
function
()
{
var
$this
=
$
(
this
);
...
...
apps/terminal/models.py
View file @
f886e7c2
...
...
@@ -4,6 +4,7 @@ import uuid
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils
import
timezone
from
django.conf
import
settings
from
users.models
import
User
...
...
@@ -127,6 +128,7 @@ class Session(models.Model):
has_replay
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
_
(
"Replay"
))
has_command
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
_
(
"Command"
))
terminal
=
models
.
ForeignKey
(
Terminal
,
null
=
True
,
on_delete
=
models
.
CASCADE
)
date_last_active
=
models
.
DateTimeField
(
verbose_name
=
_
(
"Date last active"
),
default
=
timezone
.
now
)
date_start
=
models
.
DateTimeField
(
verbose_name
=
_
(
"Date start"
))
date_end
=
models
.
DateTimeField
(
verbose_name
=
_
(
"Date end"
),
null
=
True
)
...
...
apps/terminal/tasks.py
View file @
f886e7c2
# -*- coding: utf-8 -*-
#
import
datetime
from
celery
import
shared_task
from
django.utils
import
timezone
from
common.celery
import
register_as_period_task
,
after_app_ready_start
,
\
after_app_shutdown_clean
from
.models
import
Status
CACHE_REFRESH_INTERVAL
=
10
RUNNING
=
False
# Todo: 定期清理上报history
@shared_task
def
clean_terminal_history
():
pass
@register_as_period_task
(
interval
=
3600
)
@after_app_ready_start
@after_app_shutdown_clean
def
delete_terminal_status_period
():
yesterday
=
timezone
.
now
()
-
datetime
.
timedelta
(
days
=
1
)
Status
.
objects
.
filter
(
date_created__lt
=
yesterday
)
.
delete
()
...
...
apps/terminal/templates/terminal/session_list.html
View file @
f886e7c2
...
...
@@ -75,6 +75,7 @@
<th
class=
"text-center"
>
{% trans 'Terminal' %}
</th>
<th
class=
"text-center"
>
{% trans 'Command' %}
</th>
<th
class=
"text-center"
>
{% trans 'Date start' %}
</th>
{#
<th
class=
"text-center"
>
{% trans 'Date last active' %}
</th>
#}
<th
class=
"text-center"
>
{% trans 'Duration' %}
</th>
<th
class=
"text-center"
>
{% trans 'Action' %}
</th>
{% endblock %}
...
...
@@ -94,6 +95,7 @@
<td
class=
"text-center"
>
{{ session.id | get_session_command_amount }}
</td>
<td
class=
"text-center"
>
{{ session.date_start }}
</td>
{#
<td
class=
"text-center"
>
{{ session.date_last_active }}
</td>
#}
<td
class=
"text-center"
>
{{ session.date_start|time_util_with_seconds:session.date_end }}
</td>
<td>
{% if session.is_finished %}
...
...
Write
Preview
Markdown
is supported
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