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
b95c1dee
Commit
b95c1dee
authored
Sep 17, 2016
by
wangyong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
alter asset add and detail
parent
42012d7b
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
320 additions
and
442 deletions
+320
-442
forms.py
apps/assets/forms.py
+4
-2
models.py
apps/assets/models.py
+20
-31
asset_create.html
apps/assets/templates/assets/asset_create.html
+53
-49
asset_detail.html
apps/assets/templates/assets/asset_detail.html
+226
-354
asset_list.html
apps/assets/templates/assets/asset_list.html
+1
-1
views.py
apps/assets/views.py
+14
-5
style.css
apps/static/css/style.css
+2
-0
No files found.
apps/assets/forms.py
View file @
b95c1dee
...
...
@@ -12,11 +12,13 @@ class AssetForm(forms.ModelForm):
fields
=
[
"ip"
,
"other_ip"
,
"remote_card_ip"
,
"hostname"
,
"port"
,
"groups"
,
"username"
,
"password"
,
"idc"
,
"mac_address"
,
"brand"
,
"cpu"
,
"memory"
,
"disk"
,
"os"
,
"cabinet_no"
,
"cabinet_pos"
,
"number"
,
"status"
,
"type"
,
"env"
,
"sn"
,
"is_active"
,
"comment"
"number"
,
"status"
,
"type"
,
"env"
,
"sn"
,
"is_active"
,
"comment"
,
"admin_user"
,
"system_user"
]
widgets
=
{
'groups'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
'Select asset groups'
)}),
'groups'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2-groups'
,
'data-placeholder'
:
_
(
'Select asset groups'
)}),
'system_user'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2-system-user'
,
'data-placeholder'
:
_
(
'Select asset system user'
)}),
# 'admin_user': forms.SelectMultiple(attrs={'class': 'select2-admin-user', 'data-placeholder': _('Select asset admin user')}),
}
...
...
apps/assets/models.py
View file @
b95c1dee
...
...
@@ -7,18 +7,6 @@ from django.utils.translation import ugettext_lazy as _
from
common.utils
import
encrypt
,
decrypt
class
AssetGroup
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
64
,
unique
=
True
,
verbose_name
=
_
(
'Name'
))
created_by
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Created by'
))
comment
=
models
.
TextField
(
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Comment'
))
def
__unicode__
(
self
):
return
self
.
name
class
Meta
:
db_table
=
'asset_group'
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -66,8 +54,8 @@ class IDC(models.Model):
class
AssetExtend
(
models
.
Model
):
key
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
_
(
'KEY'
))
value
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
_
(
'VALUE'
))
key
=
models
.
CharField
(
max_length
=
64
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'KEY'
))
value
=
models
.
CharField
(
max_length
=
64
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'VALUE'
))
created_by
=
models
.
CharField
(
max_length
=
32
,
blank
=
True
,
verbose_name
=
_
(
"Created by"
))
date_created
=
models
.
DateTimeField
(
auto_now
=
True
,
null
=
True
,
blank
=
True
)
comment
=
models
.
TextField
(
blank
=
True
,
verbose_name
=
_
(
'Comment'
))
...
...
@@ -272,14 +260,14 @@ class Asset(models.Model):
other_ip
=
models
.
CharField
(
max_length
=
255
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Other IP'
))
remote_card_ip
=
models
.
CharField
(
max_length
=
16
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Remote card IP'
))
hostname
=
models
.
CharField
(
max_length
=
128
,
unique
=
True
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Hostname'
))
port
=
models
.
IntegerField
(
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Port'
))
groups
=
models
.
ManyToManyField
(
AssetGroup
,
related_name
=
'assets'
,
verbose_name
=
_
(
'Asset groups'
))
port
=
models
.
IntegerField
(
default
=
22
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Port'
))
groups
=
models
.
ManyToManyField
(
AssetGroup
,
blank
=
True
,
related_name
=
'assets'
,
verbose_name
=
_
(
'Asset groups'
))
username
=
models
.
CharField
(
max_length
=
16
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Admin user'
))
password
=
models
.
CharField
(
max_length
=
256
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
"Admin password"
))
admin_user
=
models
.
ForeignKey
(
AdminUser
,
null
=
True
,
related_name
=
'assets'
,
admin_user
=
models
.
ForeignKey
(
AdminUser
,
null
=
True
,
blank
=
True
,
related_name
=
'assets'
,
on_delete
=
models
.
SET_NULL
,
verbose_name
=
_
(
"Admin user"
))
system_user
=
models
.
ManyToManyField
(
SystemUser
,
blank
=
True
,
related_name
=
'assets'
,
verbose_name
=
_
(
"System User"
))
idc
=
models
.
ForeignKey
(
IDC
,
null
=
True
,
related_name
=
'assets'
,
on_delete
=
models
.
SET_NULL
,
verbose_name
=
_
(
'IDC'
))
idc
=
models
.
ForeignKey
(
IDC
,
null
=
True
,
blank
=
True
,
related_name
=
'assets'
,
on_delete
=
models
.
SET_NULL
,
verbose_name
=
_
(
'IDC'
))
mac_address
=
models
.
CharField
(
max_length
=
20
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
"Mac address"
))
brand
=
models
.
CharField
(
max_length
=
64
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Brand'
))
cpu
=
models
.
CharField
(
max_length
=
64
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'CPU'
))
...
...
@@ -288,15 +276,15 @@ class Asset(models.Model):
os
=
models
.
CharField
(
max_length
=
128
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'OS'
))
cabinet_no
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Cabinet number'
))
cabinet_pos
=
models
.
IntegerField
(
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Cabinet position'
))
number
=
models
.
CharField
(
max_length
=
32
,
blank
=
True
,
verbose_name
=
_
(
'Asset number'
))
status
=
models
.
ForeignKey
(
AssetExtend
,
null
=
True
,
blank
=
True
,
related_name
=
"asset_status_extend"
,
verbose_name
=
_
(
'Asset status'
))
type
=
models
.
ForeignKey
(
AssetExtend
,
null
=
True
,
blank
=
True
,
related_name
=
"asset_type_extend"
,
verbose_name
=
_
(
'Asset type'
))
env
=
models
.
ForeignKey
(
AssetExtend
,
null
=
True
,
blank
=
True
,
related_name
=
"asset_env_extend"
,
verbose_name
=
_
(
'Asset environment'
))
sn
=
models
.
CharField
(
max_length
=
128
,
blank
=
True
,
verbose_name
=
_
(
'Serial number'
))
created_by
=
models
.
CharField
(
max_length
=
32
,
blank
=
True
,
verbose_name
=
_
(
'Created by'
))
number
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Asset number'
))
status
=
models
.
ForeignKey
(
AssetExtend
,
null
=
True
,
blank
=
True
,
related_name
=
"asset_status_extend"
,
verbose_name
=
_
(
'Asset status'
))
type
=
models
.
ForeignKey
(
AssetExtend
,
null
=
True
,
blank
=
True
,
related_name
=
"asset_type_extend"
,
verbose_name
=
_
(
'Asset type'
))
env
=
models
.
ForeignKey
(
AssetExtend
,
null
=
True
,
blank
=
True
,
related_name
=
"asset_env_extend"
,
verbose_name
=
_
(
'Asset environment'
))
sn
=
models
.
CharField
(
max_length
=
128
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Serial number'
))
created_by
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Created by'
))
is_active
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
_
(
'Is active'
))
date_created
=
models
.
DateTimeField
(
auto_now
=
True
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Date added'
))
comment
=
models
.
CharField
(
max_length
=
128
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Comment'
))
...
...
@@ -332,15 +320,15 @@ class Asset(models.Model):
class
Label
(
models
.
Model
):
key
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
_
(
'KEY'
))
value
=
models
.
CharField
(
max_length
=
64
,
verbose_name
=
_
(
'VALUE'
))
key
=
models
.
CharField
(
max_length
=
64
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'KEY'
))
value
=
models
.
CharField
(
max_length
=
64
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'VALUE'
))
asset
=
models
.
ForeignKey
(
Asset
,
null
=
True
,
blank
=
True
,
on_delete
=
models
.
SET_NULL
,
verbose_name
=
_
(
'Asset'
))
created_by
=
models
.
CharField
(
max_length
=
32
,
blank
=
True
,
verbose_name
=
_
(
"Created by"
))
date_created
=
models
.
DateTimeField
(
auto_now
=
True
,
null
=
True
)
comment
=
models
.
CharField
(
max_length
=
128
,
blank
=
True
,
verbose_name
=
_
(
'Comment'
))
def
__unicode__
(
self
):
return
self
.
name
return
self
.
key
class
Meta
:
db_table
=
'label'
...
...
@@ -348,4 +336,4 @@ class Label(models.Model):
def
generate_fake
():
for
cls
in
(
Asset
,
AssetGroup
,
IDC
):
cls
.
generate_fake
()
cls
.
generate_fake
()
\ No newline at end of file
apps/assets/templates/assets/asset_create.html
View file @
b95c1dee
...
...
@@ -27,67 +27,68 @@
<div
class=
"ibox-content"
>
<div
class=
"panel blank-panel"
>
<div
class=
"panel-body"
>
<div
class=
"tab-content"
>
<div
id=
"tab-1"
class=
"ibox float-e-margins tab-pane active"
></div>
<form
id=
"assetForm"
method=
"post"
class=
"form-horizontal"
>
{% csrf_token %}
<h3
class=
"widget-head-color-box"
>
基本信息
</h3>
<div
class=
"tab-content"
>
<form
id=
"assetForm"
method=
"post"
class=
"form-horizontal"
>
{% csrf_token %}
<h3
class=
"widget-head-color-box"
>
基本信息
</h3>
{{ form.hostname|bootstrap_horizontal }}
{{ form.hostname|bootstrap_horizontal }}
{{ form.ip|bootstrap_horizontal }}
{{ form.ip|bootstrap_horizontal }}
{{ form.port|bootstrap_horizontal }}
{{ form.port|bootstrap_horizontal }}
{{ form.type|bootstrap_horizontal }}
{{ form.type|bootstrap_horizontal }}
{{ form.comment|bootstrap_horizontal }}
<div
class=
"hr-line-dashed"
></div>
<h3>
关联资产用户
</h3>
<div
class=
"form-group"
>
<label
for=
"j_group"
class=
"col-sm-2 control-label"
>
管理用户
</label>
<div
class=
"col-sm-9"
>
<div
class=
"radio i-checks"
>
<label><input
type=
"radio"
checked=
"checked"
id=
"id_use_default_auth"
name=
"use_default_auth"
><span>
使用预定义管理用户
</span></label>
<label><input
type=
"radio"
id=
"id_use_default_auth"
name=
"use_default_auth"
><span>
自定义
</span></label>
</div>
</div>
</div>
{{ form.comment|bootstrap_horizontal }}
<div
class=
"form-group"
id=
"id_manager_user"
>
<div
class=
"col-sm-offset-2 col-sm-9"
>
<input
type=
"text"
placeholder=
"请选择管理用户"
name=
"manager_user"
class=
"form-control"
>
</div>
<div
class=
"hr-line-dashed"
></div>
<h3>
关联资产用户
</h3>
<div
class=
"form-group"
>
<label
for=
"j_group"
class=
"col-sm-2 control-label"
>
管理用户
</label>
<div
class=
"col-sm-9"
>
<div
class=
"radio i-checks"
>
<label><input
type=
"radio"
checked=
"checked"
id=
"id_use_default_auth"
name=
"use_default_auth"
><span>
使用预定义管理用户
</span></label>
<label><input
type=
"radio"
id=
"id_use_default_auth"
name=
"use_default_auth"
><span>
自定义
</span></label>
</div>
<p
class=
"col-sm-offset-2"
>
Tips: 管理用户是服务器存在的root或拥有sudo的用户,用来推送系统用户
</p>
</div>
</div>
<div
class=
"form-group"
>
<label
for=
"system_user"
class=
"col-sm-2 control-label"
>
系统用户
</label>
<div
class=
"col-sm-9"
>
<input
type=
"text"
placeholder=
""
name=
"system_user"
class=
"form-control"
>
</div>
</div>
{{ form.admin_user|bootstrap_horizontal }}
<p
class=
"col-sm-offset-2"
>
Tips: 管理用户是服务器存在的root或拥有sudo的用户,用来推送系统用户
</p>
<div
class=
"hr-line-dashed"
></div>
<h3>
所属
</h3>
{{ form.idc|bootstrap_horizontal }}
<div
class=
"hr-line-dashed"
></div>
{{ form.system_user|bootstrap_horizontal }}
{{ form.groups|bootstrap_horizontal }}
<div
class=
"hr-line-dashed"
></div>
<h3>
所属
</h3>
{{ form.idc|bootstrap_horizontal }}
<div
class=
"hr-line-dashed"
></div>
<h3>
标签
</h3>
{{ form.groups|bootstrap_horizontal }}
<div
class=
"hr-line-dashed"
></div>
<div
class=
"form-group"
>
<div
class=
"col-sm-4 col-sm-offset-5"
>
<button
class=
"btn btn-white"
type=
"reset"
>
重置
</button>
<button
class=
"btn btn-primary"
type=
"submit"
>
提交
</button>
</div>
</div>
</form>
<div
class=
"hr-line-dashed"
></div>
<h3>
标签
</h3>
<div
class=
"form-group"
id=
"id_label"
>
<label
class=
"col-sm-2 control-label"
>
Label
</label>
<div
class=
"col-sm-4"
>
<input
type=
"text"
placeholder=
"Key"
name=
"key"
class=
"form-control"
>
</div>
<div
class=
"col-sm-5"
>
<input
type=
"text"
placeholder=
"Value"
name=
"value"
class=
"form-control"
>
</div>
</div>
<div
class=
"col-sm-offset-2"
>
<i
class=
"fa fa-plus-circle"
></i>
<span
class=
"nav-label"
>
添加
</span><span
class=
"fa arrow"
></span>
</div>
<div
class=
"hr-line-dashed"
></div>
<div
class=
"form-group"
>
<div
class=
"col-sm-4 col-sm-offset-5"
>
<button
class=
"btn btn-white"
type=
"reset"
>
重置
</button>
<button
class=
"btn btn-primary"
type=
"submit"
>
提交
</button>
</div>
</div>
</
div
>
</
form
>
</div>
</div>
</div>
...
...
@@ -100,7 +101,9 @@
{% block custom_foot_js %}
<script>
$
(
document
).
ready
(
function
()
{
$
(
'.select2'
).
select2
();
$
(
'.select2-groups'
).
select2
();
$
(
'.select2-admin-user'
).
select2
();
$
(
'.select2-system-user'
).
select2
();
})
</script>
{% endblock %}
\ No newline at end of file
apps/assets/templates/assets/asset_detail.html
View file @
b95c1dee
{% extends 'base.html' %}
{% load common_tags %}
{% load static %}
{% load i18n %}
{% block custom_head_css_js %}
<link
href=
"{% static "
css
/
plugins
/
select2
/
select2
.
min
.
css
"
%}"
rel=
"stylesheet"
>
<link
href=
"{% static "
css
/
plugins
/
sweetalert
/
sweetalert
.
css
"
%}"
rel=
"stylesheet"
>
<script
src=
"{% static "
js
/
plugins
/
select2
/
select2
.
full
.
min
.
js
"
%}"
></script>
<script
src=
"{% static "
js
/
plugins
/
sweetalert
/
sweetalert
.
min
.
js
"
%}"
></script>
{% endblock %}
{% block content %}
<div
class=
"wrapper wrapper-content animated fadeInRight"
>
<div
class=
"row"
>
<div
class=
"col-sm-
4
"
>
<div
class=
"col-sm-
12
"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<span
class=
"text text-primary"
><b>
{{ asset.ip }}
</b></span>
<div
class=
"ibox-tools"
>
{#
<a
class=
""
href=
"{% url 'assets:asset-update' %}"
>
#}
<i
class=
"fa fa-refresh"
></i>
</a>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
<i
class=
"fa fa-wrench"
></i>
</a>
<ul
class=
"dropdown-menu dropdown-user"
>
</ul>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
<div
class=
"panel-options"
>
<ul
class=
"nav nav-tabs"
>
<li
class=
"active"
><a
href=
""
class=
"text-center"
><i
class=
"fa fa-laptop"
></i>
{% trans 'Asset detail' %}
</a>
</li>
<li><a
href=
""
class=
"text-center"
><i
class=
"fa fa-bar-chart-o"
></i>
{% trans 'Asset users' %}
</a></li>
<li><a
href=
""
class=
"text-center"
><i
class=
"fa fa-bar-chart-o"
></i>
{% trans 'Asset login log' %}
</a></li>
</ul>
</div>
<div
class=
"ibox-content ibox-heading"
>
<h3>
主机详细信息
</h3>
<small><i
class=
"fa fa-map-marker"
></i>
此主机详细信息.
</small>
</div>
<div
class=
"ibox-content"
>
<div>
<div
class=
"text-left"
>
<table
class=
"table"
>
<tr>
<td
class=
"text-navy"
>
主机名
</td>
<td>
{{ asset.hostname|default_if_none:"" }}
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
IP
</td>
<td>
{{ asset.ip|default_if_none:"" }}
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
其他IP
</td>
<td>
<table
class=
"table"
>
{% if asset.other_ip %}
{% for ip in asset.other_ip %}
<tr>
<td>
{{ ip }}
</td>
</tr>
{% endfor %}
{% endif %}
</table>
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
远控IP
</td>
<td>
{{ asset.remote_ip|default_if_none:"" }}
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
端口
</td>
<td>
{{ asset.port|default_if_none:"" }}
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
主机组
</td>
<td>
<table
class=
"table"
>
{% for asset_group in asset.group.all %}
<tr>
<td>
{{ asset_group.name|default_if_none:"" }}
</td>
</tr>
{% endfor %}
</table>
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
使用默认管理账号
</td>
{#
<td>
{{ asset.use_default_auth|bool2str }}
</td>
#}
{#
<td>
{{ asset.use_default_auth|bool2str }} {% if not asset.use_default_auth %}
<span
class=
"text-info"
>
{{ asset.username }}
</span>
{% endif %}
</td>
#}
</tr>
<tr>
<td
class=
"text-navy"
>
机房
</td>
<td>
{{ asset.idc.name|default_if_none:"" }}
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
硬件厂商型号
</td>
<td>
{{ asset.brand|default_if_none:"" }}
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
CPU
</td>
<td>
{{ asset.cpu|default_if_none:"" }}
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
内存
</td>
<td>
{{ asset.memory|default_if_none:"" }}{% if asset.memory %}G{% endif %}
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
硬盘
</td>
<td>
<table
class=
"table"
>
{% if asset.disk %}
{% for disk, value in asset.disk %}
<tr>
<td><span
class=
"text-navy"
>
{{ disk|default_if_none:"" }}
</span>
&
nbsp
&
nbsp
&
nbsp {{ value|default_if_none:"" }}
</td>
</tr>
{% endfor %}
{% endif %}
</table>
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
资产编号
</td>
<td>
{{ asset.number|default_if_none:"" }}
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
SN
</td>
<td>
{{ asset.sn|default_if_none:"" }}
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
主机类型
</td>
<td>
{{ asset.get_asset_type_display|default_if_none:"" }}
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
系统版本
</td>
<td>
{{ asset.system_type|default_if_none:"" }} {{ asset.system_version|default_if_none:"" }}
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
系统平台
</td>
<td>
{{ asset.system_arch|default_if_none:"" }}
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
运行环境
</td>
<td>
{{ asset.get_env_display|default_if_none:"" }}
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
机器状态
</td>
<td>
{{ asset.get_status_display|default_if_none:"" }}
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
机柜号
</td>
<td>
{{ asset.cabinet|default_if_none:"" }}
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
机柜位置
</td>
<td>
{{ asset.position|default_if_none:"" }}
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
激活
</td>
<td>
{{ asset.is_active }}
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
添加日期
</td>
<td>
{{ asset.date_created|date:"Y-m-d H:i:s" }}
</td>
</tr>
<tr>
<td
class=
"text-navy"
>
备注
</td>
<td>
{{ asset.comment|default_if_none:"" }}
</td>
</tr>
</table>
<div
class=
"tab-content"
>
<div
class=
"col-sm-7"
style=
"padding-left: 0"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<span
class=
"label"
><b>
{{ asset.hostname }}
</b></span>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
<i
class=
"fa fa-wrench"
></i>
</a>
<ul
class=
"dropdown-menu dropdown-user"
>
</ul>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
<div
class=
"ibox-content"
>
<table
class=
"table"
>
<tbody>
<tr
class=
"no-borders-tr"
>
{#
<td
colspan=
"2"
>
#}
{#
<img
src=
"{{ asset | user_avatar_url }}"
class=
"img-circle"
width=
"64"
height=
"64"
>
#}
{#
</td>
#}
</tr>
<tr>
<td
width=
"20%"
>
{% trans 'Hostname' %}:
</td>
<td><b>
{{ asset.hostname }}
</b></td>
</tr>
<tr>
<td>
{% trans 'IP' %}:
</td>
<td><b>
{{ asset.ip }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Other IP' %}:
</td>
<td><b>
{{ asset.other_ip }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Remote card IP' %}:
</td>
<td><b>
{{ asset.remote_card_ip }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Port' %}:
</td>
<td><b>
{{ asset.port }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Mac address' %}:
</td>
<td><b>
{{ asset.mac_addr }}
</b></td>
</tr>
<tr>
<td>
{% trans 'CPU' %}:
</td>
<td><b>
{{ asset.cpu }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Memory' %}:
</td>
<td><b>
{{ asset.memory }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Disk' %}:
</td>
<td><b>
{{ asset.disk }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Label' %}:
</td>
{% for label in asset.label_set.all %}
<td><b>
{{ label.key }} - {{ label.value }}
</b></td>
{% endfor %}
</tr>
<tr>
<td>
{% trans 'OS' %}:
</td>
<td><b>
{{ asset.os }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Mac address' %}:
</td>
<td><b>
{{ asset.mac_addr }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Asset status' %}:
</td>
<td><b>
{{ asset.status }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Is active' %}:
</td>
<td><b>
{{ asset.is_active }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Asset type' %}:
</td>
<td><b>
{{ asset.type }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Asset environment' %}:
</td>
<td><b>
{{ asset.env }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Serial number' %}:
</td>
<td><b>
{{ asset.sn }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Asset number' %}:
</td>
<td><b>
{{ asset.number }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Created by' %}:
</td>
<td><b>
{{ asset.created_by }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Date joined' %}:
</td>
<td><b>
{{ asset.date_joined|date:"Y-m-j H:i:s" }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Comment' %}:
</td>
<td><b>
{{ asset.comment }}
</b></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<div
class=
"col-sm-4"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<h5>
拥有权限的用户
</h5>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
<i
class=
"fa fa-wrench"
></i>
</a>
<ul
class=
"dropdown-menu dropdown-user"
>
</ul>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
<div
class=
"ibox-content ibox-heading"
>
<h3>
主机所有授权的信息
</h3>
<small><i
class=
"fa fa-map-marker"
></i>
包含了此主机所有授权的信息.
</small>
</div>
<div
class=
"ibox-content"
>
<div>
<div
class=
"text-left"
>
{% if perm_info %}
{% if user_perm %}
<table
class=
"table"
>
<p>
授权用户信息
</p>
<td
class=
"text-navy"
>
授权用户
</td>
<td
class=
"text-navy"
>
关联用户
</td>
{% for perm in user_perm %}
<div
class=
"col-sm-5"
style=
"padding-left: 0;padding-right: 0"
>
<div
class=
"panel panel-primary"
>
<div
class=
"panel-heading"
>
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Quick modify' %}
</div>
<div
class=
"panel-body"
>
<table
class=
"table"
>
<tbody>
<tr
class=
"no-borders-tr"
>
<td
width=
"50%"
>
{% trans 'Active' %}:
</td>
<td><span
class=
"pull-right"
>
<div
class=
"switch"
>
<div
class=
"onoffswitch"
>
<input
type=
"checkbox"
{%
if
asset
.
is_active
%}
checked
{%
endif
%}
class=
"onoffswitch-checkbox"
id=
"is_active"
>
<label
class=
"onoffswitch-label"
for=
"is_active"
>
<span
class=
"onoffswitch-inner"
></span>
<span
class=
"onoffswitch-switch"
></span>
</label>
</div>
</div>
</span></td>
</tr>
<tr>
<td>
{% trans 'Enable OTP' %}:
</td>
<td><span
class=
"pull-right"
>
<div
class=
"switch"
>
<div
class=
"onoffswitch"
>
<input
type=
"checkbox"
class=
"onoffswitch-checkbox"
{%
if
asset
.
enable_otp
%}
checked
{%
endif
%}
id=
"enable_otp"
>
<label
class=
"onoffswitch-label"
for=
"enable_otp"
>
<span
class=
"onoffswitch-inner"
></span>
<span
class=
"onoffswitch-switch"
></span>
</label>
</div>
</div>
</span></td>
</tr>
<tr>
<td>
{% trans 'Reset password' %}:
</td>
<td>
<span
class=
"pull-right"
>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
id=
"btn_reset_password"
style=
"width: 54px"
>
{% trans 'Reset' %}
</button>
</span>
</td>
</tr>
<tr>
<td>
{% trans 'Reset ssh key' %}:
</td>
<td>
<span
class=
"pull-right"
>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
id=
"btn_reset_pk"
style=
"width: 54px;"
>
{% trans 'Reset' %}
</button>
</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div
class=
"panel panel-info"
>
<div
class=
"panel-heading"
>
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Asset group' %}
</div>
<div
class=
"panel-body"
>
<table
class=
"table group_edit"
>
<tbody>
<form>
<tr>
<td
class=
"text-navy"
><a
href=
"{% url 'user_detail' %}?id={{ perm.0.id }}"
>
{{ perm.0 }}
</a></td>
<td>
<table
class=
"table"
>
{% if perm.1 %}
{% for role in perm.1 %}
<tr>
<td
class=
"text-navy"
><a
href=
"{% url 'role_detail' %}?id={{ role.id }}"
>
{{ role }}
</a></td>
</tr>
{% endfor %}
{% endif %}
</table>
<td
colspan=
"2"
class=
"no-borders"
>
<select
data-placeholder=
"{% trans 'Join user groups' %}"
id=
"slct_groups"
class=
"select2"
style=
"width: 100%"
multiple=
""
tabindex=
"4"
>
{% for group in groups %}
<option
value=
"{{ group.id }}"
id=
"opt_{{ group.id }}"
>
{{ group.name }}
</option>
{% endfor %}
</select>
</td>
</tr>
{% endfor %}
</table>
{% endif %}
{% if user_group_perm %}
<table
class=
"table"
>
<p>
授权用户组信息
</p>
<td
class=
"text-navy"
>
授权用户组
</td>
<td
class=
"text-navy"
>
组详情
</td>
{% for user_group in user_group_perm %}
<tr>
<td
class=
"text-navy"
>
{{ user_group }}
</td>
<td
class=
"text-navy"
><a
href=
"{% url 'user_group_list' %}?gid={{ user_group.id }}"
>
详情
</a></td>
</tr>
{% endfor %}
</table>
{% endif %}
<tr>
<td
colspan=
"2"
class=
"no-borders"
>
<button
type=
"button"
class=
"btn btn-info btn-small"
id=
"btn_add_user_group"
>
{% trans 'Join' %}
</button>
</td>
</tr>
</form>
{% if user_rule_perm %}
<table
class=
"table"
>
<p>
授权规则信息
</p>
<td
class=
"text-navy"
>
授权规则
</td>
<td
class=
"text-navy"
>
详情
</td>
{% for rule in user_rule_perm %}
<tr>
<td
class=
"text-navy"
>
{{ rule }}
</td>
<td
class=
"text-navy"
><a
href=
"{% url 'rule_detail' %}?id={{ rule.id }}"
>
详情
</a></td>
</tr>
{% endfor %}
</table>
{% endif %}
{% else %}
<p
class=
"text-center"
>
(暂无)
</p>
{% endif %}
{% for group in asset.groups.all %}
<tr>
<td
><b
class=
"bdg_user_group"
data-gid=
{{
group
.
id
}}
>
{{ group.name }}
</b></td>
<td>
<button
class=
"btn btn-danger pull-right btn-sm btn_delete_user_group"
type=
"button"
><i
class=
"fa fa-minus"
></i></button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
<div
class=
"ibox-title"
>
<h5>
主机修改记录
</h5>
{#
<a
href=
"{% url 'asset_edit' %}?id={{ asset.id }}"
data-toggle=
"tooltip"
class=
"text-success pull-center"
data-placement=
"bottom"
title=
"修改"
>
&
nbsp
&
nbsp
&
nbsp
&
nbsp点击修改
</a>
#}
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
<i
class=
"fa fa-wrench"
></i>
</a>
<ul
class=
"dropdown-menu dropdown-user"
>
</ul>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
<div
class=
"ibox-content ibox-heading"
>
<h3>
主机修改记录
</h3>
<small><i
class=
"fa fa-map-marker"
></i>
包含了此主机所有历史修改记录.
</small>
</div>
<div
class=
"ibox-content"
>
<div
class=
"feed-activity-list"
>
{% if asset_record %}
{# {% for r in asset_record %}#}
{#
<div
class=
"feed-element"
>
#}
{#
<div>
#}
{#
<small
class=
"pull-right"
>
{{ r.alert_time|naturaltime }}
</small>
#}
{#
<strong
class=
"text-navy"
>
{{ r.username }}
</strong>
#}
{# {% for i in r.content|str_to_list %}#}
{#
<div>
{{ i.0 }} 由
<span
class=
"text-success"
>
{{ i.1|str_to_code }}
</span>
改为
<span
class=
"text-warning"
>
{{ i.2|str_to_code }}
</span></div>
#}
{# {% endfor %}#}
{#
<small
class=
"text-success"
>
{{ r.alert_time }}
</small>
#}
{#
</div>
#}
{#
</div>
#}
{# {% endfor %}#}
{% else %}
<p
class=
"text-center"
>
(暂无)
</p>
{% endif %}
</div>
</div>
</div>
</div>
<div
class=
"col-sm-4"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<h5>
最近一周登录记录
</h5>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
<i
class=
"fa fa-wrench"
></i>
</a>
<ul
class=
"dropdown-menu dropdown-user"
>
</ul>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
<div
class=
"ibox-content ibox-heading"
>
<h3>
最近一周登录记录
</h3>
<small><i
class=
"fa fa-map-marker"
></i>
此主机最近一周用户登录信息.
</small>
</div>
<div
class=
"ibox-content inspinia-timeline"
>
{% if log %}
{% for l in log %}
<div
class=
"timeline-item"
>
<div
class=
"row"
>
<div
class=
"col-xs-5 date"
>
<i
class=
"fa fa-info-circle"
></i>
<small
class=
"text-navy"
>
{{ l.user }}
</small>
<br/>
</div>
<div
class=
"col-xs-7 content no-top-border"
>
<p
class=
"m-b-xs"
><strong>
详细信息
</strong></p>
<p>
来源IP: {{ l.remote_ip }}
</p>
<p>
开始: {{ l.start_time |date:"Y-m-d H:i:s" }}
</p>
<p>
结束: {{ l.end_time |date:"Y-m-d H:i:s" }}
</p>
</div>
</div>
</div>
{% endfor %}
<button
id=
"show"
class=
"btn btn-primary btn-block m-t"
><i
class=
"fa fa-arrow-down"
></i>
所有
</button>
<div
id=
'more'
style=
"display: none"
>
<br/>
{% for l in log_more %}
<div
class=
"timeline-item"
>
<div
class=
"row"
>
<div
class=
"col-xs-5 date"
>
<i
class=
"fa fa-info-circle"
></i>
<small
class=
"text-navy"
>
{{ l.user }}
</small>
<br/>
</div>
<div
class=
"col-xs-7 content no-top-border"
>
<p
class=
"m-b-xs"
><strong>
详细信息
</strong></p>
<p>
来源IP: {{ l.remote_ip }}
</p>
<p>
开始: {{ l.start_time |date:"Y-m-d H:i:s" }}
</p>
<p>
结束: {{ l.end_time |date:"Y-m-d H:i:s" }}
</p>
</div>
</div>
</div>
{% endfor %}
{% else %}
<p
class=
"text-center"
>
(暂无)
</p>
{% endif %}
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block custom_foot_js %}
<script>
$
(
document
).
ready
(
function
(){
$
(
'#show'
).
click
(
function
(){
$
(
'#show'
).
css
(
'display'
,
'none'
);
$
(
'#more'
).
css
(
'display'
,
'block'
);
})
})
</script>
{% endblock %}
\ No newline at end of file
{% endblock %}
apps/assets/templates/assets/asset_list.html
View file @
b95c1dee
...
...
@@ -117,7 +117,7 @@
<td
class=
"text-center"
name=
"id"
value=
"{{ asset.id }}"
data-editable=
'false'
>
<input
name=
"id"
value=
"{{ asset.id }}"
type=
"checkbox"
class=
"i-checks"
>
</td>
<td
class=
"text-center"
>
{{ asset.hostname }}
</td>
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:asset-detail' pk=asset.id %}"
>
{{ asset.hostname }}
</a>
</td>
<td
class=
"text-center"
>
{{ asset.ip }}
</td>
<td
class=
"text-center"
>
{{ asset.system_type }}
</td>
<td
class=
"text-center"
>
{{ asset.cpu }} | {{ asset.memory }} | {{ asset.disk }}
</td>
...
...
apps/assets/views.py
View file @
b95c1dee
...
...
@@ -10,22 +10,31 @@ from django.urls import reverse_lazy
from
django.contrib.messages.views
import
SuccessMessageMixin
from
django.views.generic.detail
import
DetailView
,
SingleObjectMixin
from
.models
import
Asset
,
AssetGroup
,
IDC
,
AssetExtend
,
AdminUser
,
SystemUser
from
.models
import
Asset
,
AssetGroup
,
IDC
,
AssetExtend
,
AdminUser
,
SystemUser
,
Label
from
.forms
import
AssetForm
,
AssetGroupForm
,
IDCForm
,
AdminUserForm
,
SystemUserForm
from
.hands
import
AdminUserRequiredMixin
class
AssetCreateView
(
CreateView
):
class
AssetCreateView
(
AdminUserRequiredMixin
,
CreateView
):
model
=
Asset
form_class
=
AssetForm
template_name
=
'assets/asset_create.html'
success_url
=
reverse_lazy
(
'assets:asset-list'
)
def
form_
in
valid
(
self
,
form
):
def
form_valid
(
self
,
form
):
asset
=
form
.
save
(
commit
=
False
)
asset
.
is_active
=
1
key
=
self
.
request
.
POST
.
get
(
'key'
,
''
)
value
=
self
.
request
.
POST
.
get
(
'value'
,
''
)
asset
.
save
()
return
super
(
AssetCreateView
,
self
)
.
form_invalid
(
form
)
Label
.
objects
.
create
(
key
=
key
,
value
=
value
,
asset
=
asset
)
return
super
(
AssetCreateView
,
self
)
.
form_valid
(
form
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
AssetCreateView
,
self
)
.
get_context_data
(
**
kwargs
)
context
.
update
({
'admin_users'
:
AdminUser
.
objects
.
all
()})
assert
isinstance
(
context
,
object
)
print
(
context
)
return
context
class
AssetUpdateView
(
UpdateView
):
...
...
apps/static/css/style.css
View file @
b95c1dee
/*
@import url("https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700");
@import url("https://fonts.googleapis.com/css?family=Roboto:400,300,500,700");
*/
/*
*
* INSPINIA - Responsive Admin Theme
...
...
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