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
e78d7b02
Commit
e78d7b02
authored
9 years ago
by
wangyong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cu asset page and sth
parent
b346e1c4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
413 additions
and
14 deletions
+413
-14
asset_api.py
jasset/asset_api.py
+2
-2
views.py
jasset/views.py
+15
-5
asset_cu_list.html
templates/jasset/asset_cu_list.html
+389
-0
asset_list.html
templates/jasset/asset_list.html
+7
-7
No files found.
jasset/asset_api.py
View file @
e78d7b02
...
...
@@ -213,8 +213,8 @@ def write_excel(asset_all):
group_all
=
'/'
.
join
(
group_list
)
status
=
asset
.
get_status_display
()
idc_name
=
asset
.
idc
.
name
if
asset
.
idc
else
u''
system_type
=
asset
.
system_type
if
asset
.
idc
else
u''
system_version
=
asset
.
system_version
if
asset
.
idc
else
u''
system_type
=
asset
.
system_type
if
asset
.
system_type
else
u''
system_version
=
asset
.
system_version
if
asset
.
system_version
else
u''
system_os
=
unicode
(
system_type
)
+
unicode
(
system_version
)
alter_dic
=
[
asset
.
hostname
,
asset
.
ip
,
idc_name
,
group_all
,
system_os
,
asset
.
cpu
,
asset
.
memory
,
...
...
This diff is collapsed.
Click to expand it.
jasset/views.py
View file @
e78d7b02
...
...
@@ -6,9 +6,7 @@ from jumpserver.api import *
from
jumpserver.models
import
Setting
from
jasset.forms
import
AssetForm
,
IdcForm
from
jasset.models
import
Asset
,
IDC
,
AssetGroup
,
ASSET_TYPE
,
ASSET_STATUS
from
jperm.perm_api
import
get_group_asset_perm
from
jperm.ansible_api
import
MyRunner
from
jperm.perm_api
import
gen_resource
from
jperm.perm_api
import
get_group_asset_perm
,
get_group_user_perm
@require_role
(
'admin'
)
...
...
@@ -169,7 +167,7 @@ def asset_add(request):
@require_role
(
'admin'
)
def
asset_add_batch
(
request
):
header_title
,
path1
,
path2
=
u'添加资产'
,
u'资产管理'
,
u'批量添加'
return
my_render
(
'jasset/
asset
_add_batch.html'
,
locals
(),
request
)
return
my_render
(
'jasset/
server
_add_batch.html'
,
locals
(),
request
)
@require_role
(
'admin'
)
...
...
@@ -259,6 +257,8 @@ def asset_list(request):
asset list view
"""
header_title
,
path1
,
path2
=
u'查看资产'
,
u'资产管理'
,
u'查看资产'
username
=
request
.
user
.
username
user_perm
=
request
.
session
[
'role_id'
]
idc_all
=
IDC
.
objects
.
filter
()
asset_group_all
=
AssetGroup
.
objects
.
all
()
asset_types
=
ASSET_TYPE
...
...
@@ -282,12 +282,19 @@ def asset_list(request):
if
idc
:
asset_find
=
Asset
.
objects
.
filter
(
idc
=
idc
)
else
:
if
user_perm
!=
0
:
asset_find
=
Asset
.
objects
.
all
()
else
:
user
=
get_object
(
User
,
username
=
username
)
asset_perm
=
get_group_user_perm
(
user
)
if
user
else
{
'asset'
:
''
}
asset_find
=
asset_perm
[
'asset'
]
.
keys
()
asset_group_all
=
list
(
asset_perm
[
'asset_group'
])
if
idc_name
:
asset_find
=
asset_find
.
filter
(
idc__name__contains
=
idc_name
)
if
group_name
:
print
asset_find
,
type
(
asset_find
)
asset_find
=
asset_find
.
filter
(
group__name__contains
=
group_name
)
if
asset_type
:
...
...
@@ -324,7 +331,10 @@ def asset_list(request):
smg
=
u'excel文件已生成,请点击下载!'
return
my_render
(
'jasset/asset_excel_download.html'
,
locals
(),
request
)
assets_list
,
p
,
assets
,
page_range
,
current_page
,
show_first
,
show_end
=
pages
(
asset_find
,
request
)
if
user_perm
!=
0
:
return
my_render
(
'jasset/asset_list.html'
,
locals
(),
request
)
else
:
return
my_render
(
'jasset/asset_cu_list.html'
,
locals
(),
request
)
@require_role
(
'admin'
)
...
...
@@ -551,4 +561,4 @@ def asset_upload(request):
smg
=
u'批量添加成功'
else
:
emg
=
u'批量添加失败,请检查格式.'
return
my_render
(
'jasset/
asset
_add_batch.html'
,
locals
(),
request
)
return
my_render
(
'jasset/
server
_add_batch.html'
,
locals
(),
request
)
This diff is collapsed.
Click to expand it.
templates/jasset/asset_cu_list.html
0 → 100644
View file @
e78d7b02
{% extends 'base.html' %}
{% load mytags %}
{% block content %}
{% include 'nav_cat_bar.html' %}
<div
class=
"wrapper wrapper-content animated fadeInRight"
>
<div
class=
"row"
>
<div
class=
"col-sm-12"
>
<div
class=
"ibox float-e-margins"
id=
"all"
>
<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>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
<div
class=
"ibox-content"
>
<form
id=
"asset_form"
>
<div
class=
"col-sm-7"
style=
"padding-left: 0px"
>
<label>
<select
name=
"idc"
class=
"form-control m-b input-sm"
onchange=
"change_info()"
>
<option
value=
""
>
机房
</option>
{% for idc in idc_all %}
{% ifequal idc.name idc_name %}
<option
value=
"{{idc.name}}"
selected
>
{{ idc.name }}
</option>
{% else %}
<option
value=
"{{idc.name}}"
>
{{ idc.name }}
</option>
{% endifequal %}
{% endfor %}
</select>
</label>
<label>
<select
name=
"group"
class=
"form-control m-b input-sm"
onchange=
"change_info()"
>
<option
value=
""
>
主机组
</option>
{% for asset_group in asset_group_all %}
{% ifequal asset_group.name group_name %}
<option
value=
"{{ asset_group.name }}"
selected
>
{{ asset_group.name }}
</option>
{% else %}
<option
value=
"{{ asset_group.name }}"
>
{{ asset_group.name }}
</option>
{% endifequal %}
{% endfor %}
</select>
</label>
<label>
<select
name=
"asset_type"
class=
"form-control m-b input-sm"
onchange=
"change_info()"
>
<option
value=
""
>
资产类型
</option>
{% for type in asset_types %}
{% ifequal type.0|int2str asset_type %}
<option
value=
"{{ type.0 }}"
selected
>
{{ type.1 }}
</option>
{% else %}
<option
value=
"{{ type.0 }}"
>
{{ type.1 }}
</option>
{% endifequal %}
{% endfor %}
</select>
</label>
<label>
<select
name=
"status"
class=
"form-control m-b input-sm"
onchange=
"change_info()"
>
<option
value=
""
>
资产状态
</option>
{% for s in asset_status %}
{% ifequal s.0|int2str status %}
<option
value=
"{{ s.0 }}"
selected
>
{{ s.1 }}
</option>
{% else %}
<option
value=
"{{ s.0 }}"
>
{{ s.1 }}
</option>
{% endifequal %}
{% endfor %}
</select>
</label>
</div>
<div
class=
"col-sm-4"
style=
"padding-right: 0"
>
<div
class=
"input-group inline-group"
>
<input
type=
"text"
class=
"form-control m-b input-sm"
id=
"search_input"
name=
"keyword"
value=
"{{ keyword }}"
placeholder=
"Search"
>
<input
type=
"text"
style=
"display: none"
>
<div
class=
"input-group-btn"
>
<button
id=
'search_btn'
href=
"/jasset/asset_list/?search=true"
type=
"button"
class=
"btn btn-sm btn-primary search-btn"
onclick=
"change_info()"
>
- 搜索 -
</button>
<button
type=
"button"
href=
"/jasset/asset_list/?export=true"
name=
"export"
class=
"btn btn-sm btn-success search-btn-excel"
onclick=
"return false"
>
- 导出 -
</button>
</div>
</div>
</div>
<div
id=
"export"
></div>
<table
class=
"table table-striped table-bordered table-hover "
id=
"editable"
name=
"editable"
>
<thead>
<tr>
<th
class=
"text-center"
>
<input
id=
"checkall"
type=
"checkbox"
class=
"i-checks"
name=
"checkall"
value=
"checkall"
data-editable=
'false'
onclick=
"check_all('asset_form')"
>
</th>
<th
class=
"text-center"
>
主机名
</th>
<th
class=
"text-center"
name=
"ip"
>
IP地址
</th>
<th
class=
"text-center"
>
IDC
</th>
<th
class=
"text-center"
>
所属主机组
</th>
{#
<th
class=
"text-center"
>
配置信息
</th>
#}
<th
class=
"text-center"
>
操作系统
</th>
<th
class=
"text-center"
>
cpu核数
</th>
<th
class=
"text-center"
>
内存
</th>
<th
class=
"text-center"
>
硬盘
</th>
<th
class=
"text-center"
>
操作
</th>
</tr>
</thead>
<tbody>
{% for asset in assets.object_list %}
<tr
class=
"gradeX"
>
<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 hostname"
>
<a
href=
"/jasset/asset_detail/?id={{ asset.id }}"
>
{{ asset.hostname|default_if_none:"" }}
</a></td>
<td
class=
"text-center"
>
{{ asset.ip|default_if_none:"" }}
</td>
<td
class=
"text-center"
>
{{ asset.idc.name|default_if_none:"" }}
</td>
<td
class=
"text-center"
>
{{ asset.group.all|group_str2 }}
</td>
{#
<td
class=
"text-center"
>
{{ asset.cpu }}|{{ asset.memory }}|{{ asset.disk }}
</td>
#}
<td
class=
"text-center"
>
{{ asset.system_type|default_if_none:"" }}{{ asset.system_version|default_if_none:"" }}
</td>
<td
class=
"text-center"
>
{{ asset.cpu|get_cpu_core|default_if_none:"" }}
</td>
<td
class=
"text-center"
>
{{ asset.memory }}{% if asset.memory %}G{% endif %}
</td>
<td
class=
"text-center"
>
{{ asset.disk|get_disk_info }}{% if asset.memory %}G{% endif %}
</td>
<td
class=
"text-center"
data-editable=
'false'
>
<a
value=
"{{ asset.id }}"
class=
"conn btn btn-xs btn-warning"
>
连接
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div
class=
"row"
>
<div
class=
"col-sm-6"
>
<input
type=
"button"
id=
"exec_cmd"
class=
"btn btn-sm btn-primary"
name=
"exec_cmd"
value=
"执行命令"
/>
</div>
{% include 'paginator.html' %}
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block self_footer_js %}
<script>
$
(
document
).
ready
(
function
(){
$
(
'.asset_del'
).
click
(
function
(){
var
row
=
$
(
this
).
closest
(
'tr'
);
if
(
confirm
(
"确定删除?"
))
{
$
.
get
(
$
(
this
).
attr
(
'value'
),
{},
function
(
data
)
{
row
.
remove
()
}
)
}
});
$
(
'#exec_cmd'
).
click
(
function
(){
var
url
=
'/jperm/role/get/'
;
var
new_url
=
'/exec_cmd/?role='
;
var
check_array
=
[];
$
(
".gradeX input:checked"
).
closest
(
'tr'
).
find
(
'.hostname a'
).
each
(
function
()
{
check_array
.
push
(
$
(
this
).
text
())
});
check_assets
=
check_array
.
join
(
':'
);
$
.
ajax
({
type
:
'GET'
,
url
:
url
,
data
:
{},
success
:
function
(
data
){
var
dataArray
=
data
.
split
(
','
);
if
(
dataArray
.
length
==
1
&&
data
!=
'error'
){
var
title
=
'Jumpserver Exec Terminal'
;
layer
.
open
({
type
:
2
,
title
:
title
,
maxmin
:
true
,
shade
:
false
,
area
:
[
'800px'
,
'600px'
],
content
:
new_url
+
data
+
'&check_assets='
+
check_assets
});
//window.open(new_url + data, '', 'location=no, resizeable=no, height=410, width=625, top=89px, left=99px,toolbar=no,menubar=no,scrollbars=auto,status=no');
}
else
if
(
dataArray
.
length
==
'1'
&&
data
==
'error'
){
layer
.
alert
(
'没有授权角色'
)
}
else
{
aUrl
=
''
;
$
.
each
(
dataArray
,
function
(
index
,
value
){
aUrl
+=
'<a onclick="windowOpenExec(this); return false" class="btn btn-xs btn-primary newa" href='
+
new_url
+
value
+
'&check_assets='
+
check_assets
+
'>'
+
value
+
'</a> '
});
layer
.
alert
(
aUrl
,
{
skin
:
'layui-layer-molv'
,
title
:
'多个角色,请选择一个连接'
,
shade
:
false
,
closeBtn
:
0
})
}
}
});
return
false
});
$
(
'.conn'
).
click
(
function
(){
var
url
=
'/jperm/role/get/?id='
+
$
(
this
).
attr
(
'value'
);
var
href
=
$
(
this
).
attr
(
'href'
);
var
new_url
=
'/jlog/web_terminal/?id='
+
$
(
this
).
attr
(
'value'
)
+
'&role='
;
var
hostname
=
$
(
this
).
closest
(
'tr'
).
find
(
'.hostname a'
)[
0
].
innerHTML
;
$
.
ajax
({
type
:
'GET'
,
url
:
url
,
data
:
{},
success
:
function
(
data
){
var
dataArray
=
data
.
split
(
','
);
if
(
dataArray
.
length
==
1
&&
data
!=
'error'
){
var
title
=
'Jumpserver Web Terminal'
+
'<span class="text-info"> '
+
hostname
+
'</span>'
;
layer
.
open
({
type
:
2
,
title
:
title
,
maxmin
:
true
,
shade
:
false
,
area
:
[
'628px'
,
'452px'
],
content
:
new_url
+
data
});
//window.open(new_url + data, '', 'location=no, resizeable=no, height=410, width=625, top=89px, left=99px,toolbar=no,menubar=no,scrollbars=auto,status=no');
}
else
if
(
dataArray
.
length
==
'1'
&&
data
==
'error'
){
layer
.
alert
(
'没有授权角色'
)
}
else
{
aUrl
=
''
;
$
.
each
(
dataArray
,
function
(
index
,
value
){
aUrl
+=
'<a onclick="windowOpen(this); return false" class="btn btn-xs btn-primary newa" href='
+
new_url
+
value
+
' value='
+
hostname
+
'>'
+
value
+
'</a> '
});
console
.
log
(
aUrl
);
layer
.
alert
(
aUrl
,
{
skin
:
'layui-layer-molv'
,
title
:
'多个角色,请选择一个连接'
,
shade
:
false
,
closeBtn
:
0
})
}
}
});
return
false
});
});
function
windowOpen
(
a
){
var
new_url
=
$
(
a
).
attr
(
'href'
);
var
hostname
=
$
(
a
).
attr
(
'value'
);
var
title
=
'Jumpserver Web Terminal - '
+
'<span class="text-info"> '
+
hostname
+
'</span>'
;
layer
.
open
({
type
:
2
,
title
:
title
,
maxmin
:
true
,
area
:
[
'628px'
,
'452px'
],
shade
:
false
,
content
:
new_url
});
return
false
}
function
windowOpenExec
(
a
){
var
new_url
=
$
(
a
).
attr
(
'href'
);
var
title
=
'Jumpserver Exec Terminal'
;
layer
.
open
({
type
:
2
,
title
:
title
,
maxmin
:
true
,
area
:
[
'800px'
,
'600px'
],
shade
:
false
,
content
:
new_url
});
console
.
log
(
new_url
);
return
false
}
$
(
".iframe"
).
on
(
'click'
,
function
(){
var
asset_id_all
=
getIDall
();
if
(
asset_id_all
==
''
){
alert
(
"请至少选择一行!"
);
return
false
;
}
var
url
=
$
(
this
).
attr
(
"value"
)
+
'?asset_id_all='
+
asset_id_all
;
layer
.
open
({
type
:
2
,
title
:
'JumpServer - 批量修改主机'
,
maxmin
:
true
,
shift
:
'top'
,
border
:
[
2
,
0.3
,
'#1AB394'
],
shade
:
[
0.5
,
'#000000'
],
area
:
[
'800px'
,
'600px'
],
shadeClose
:
true
,
content
:
url
,
cancel
:
function
(){
location
.
replace
(
location
.
href
);
}
});
});
$
(
'.search-btn-excel'
).
unbind
(
'click'
).
bind
(
'click'
,
function
(){
var
url
=
$
(
this
).
attr
(
"href"
);
$
.
ajax
({
type
:
"GET"
,
url
:
url
,
data
:
$
(
"#asset_form"
).
serialize
(),
success
:
function
(
data
)
{
$
(
"#export"
).
html
(
data
);
}
});
});
$
(
'#asset_del'
).
click
(
function
()
{
var
asset_id_all
=
getIDall
();
if
(
asset_id_all
==
''
){
alert
(
"请至少选择一行!"
);
return
false
;
}
if
(
confirm
(
"确定删除?"
))
{
$
.
ajax
({
type
:
"post"
,
data
:
{
asset_id_all
:
asset_id_all
},
url
:
"/jasset/asset_del/?arg=batch"
,
success
:
function
()
{
parent
.
location
.
reload
();
}
});
}
});
$
(
'#asset_update'
).
click
(
function
()
{
var
asset_id_all
=
getIDall
();
if
(
asset_id_all
==
''
){
if
(
confirm
(
"更新全部资产信息?"
))
{
layer
.
msg
(
'玩命更新中...'
,
{
time
:
200000
});
$
.
ajax
({
type
:
"post"
,
url
:
"/jasset/asset_update_batch/?arg=all"
,
success
:
function
()
{
parent
.
location
.
reload
();
}
});
}
}
else
{
layer
.
msg
(
'玩命更新中...'
,
{
time
:
200000
});
$
.
ajax
({
type
:
"post"
,
data
:
{
asset_id_all
:
asset_id_all
},
url
:
"/jasset/asset_update_batch/"
,
success
:
function
()
{
parent
.
location
.
reload
();
}
});
}
});
{
#
$
(
'#asset_update_all'
).
click
(
function
()
{
#
}
{
#
layer
.
msg
(
'玩命更新中...'
,
{
time
:
200000
});
#
}
{
#
$
.
ajax
({
#
}
{
#
type
:
"post"
,
#
}
{
#
url
:
"/jasset/asset_update_batch/?arg=all"
,
#
}
{
#
success
:
function
()
{
#
}
{
#
parent
.
location
.
reload
();
#
}
{
#
}
#
}
{
#
});
#
}
{
#
});
#
}
function
change_info
(){
var
args
=
$
(
"#asset_form"
).
serialize
();
window
.
location
=
"/jasset/asset_list/?"
+
args
}
$
(
"#search_input"
).
keydown
(
function
(
e
){
if
(
e
.
keyCode
==
13
){
change_info
()
}
});
</script>
{% endblock %}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
templates/jasset/asset_list.html
View file @
e78d7b02
...
...
@@ -30,7 +30,7 @@
<div
class=
"col-sm-7"
style=
"padding-left: 0px"
>
<label>
<select
name=
"idc"
class=
"form-control m-b"
onchange=
"change_info()"
>
<select
name=
"idc"
class=
"form-control m-b
input-sm
"
onchange=
"change_info()"
>
<option
value=
""
>
机房
</option>
{% for idc in idc_all %}
{% ifequal idc.name idc_name %}
...
...
@@ -43,7 +43,7 @@
</label>
<label>
<select
name=
"group"
class=
"form-control m-b"
onchange=
"change_info()"
>
<select
name=
"group"
class=
"form-control m-b
input-sm
"
onchange=
"change_info()"
>
<option
value=
""
>
主机组
</option>
{% for asset_group in asset_group_all %}
{% ifequal asset_group.name group_name %}
...
...
@@ -56,7 +56,7 @@
</label>
<label>
<select
name=
"asset_type"
class=
"form-control m-b"
onchange=
"change_info()"
>
<select
name=
"asset_type"
class=
"form-control m-b
input-sm
"
onchange=
"change_info()"
>
<option
value=
""
>
资产类型
</option>
{% for type in asset_types %}
{% ifequal type.0|int2str asset_type %}
...
...
@@ -69,7 +69,7 @@
</label>
<label>
<select
name=
"status"
class=
"form-control m-b"
onchange=
"change_info()"
>
<select
name=
"status"
class=
"form-control m-b
input-sm
"
onchange=
"change_info()"
>
<option
value=
""
>
资产状态
</option>
{% for s in asset_status %}
{% ifequal s.0|int2str status %}
...
...
@@ -84,13 +84,13 @@
<div
class=
"col-sm-4"
style=
"padding-right: 0"
>
<div
class=
"input-group inline-group"
>
<input
type=
"text"
class=
"form-control m-b"
id=
"search_input"
name=
"keyword"
value=
"{{ keyword }}"
placeholder=
"Search"
>
<input
type=
"text"
class=
"form-control m-b
input-sm
"
id=
"search_input"
name=
"keyword"
value=
"{{ keyword }}"
placeholder=
"Search"
>
<input
type=
"text"
style=
"display: none"
>
<div
class=
"input-group-btn"
>
<button
id=
'search_btn'
href=
"/jasset/asset_list/?search=true"
type=
"button"
class=
"btn btn-
x
m btn-primary search-btn"
onclick=
"change_info()"
>
<button
id=
'search_btn'
href=
"/jasset/asset_list/?search=true"
type=
"button"
class=
"btn btn-
s
m btn-primary search-btn"
onclick=
"change_info()"
>
- 搜索 -
</button>
<button
type=
"button"
href=
"/jasset/asset_list/?export=true"
name=
"export"
class=
"btn btn-
x
m btn-success search-btn-excel"
onclick=
"return false"
>
<button
type=
"button"
href=
"/jasset/asset_list/?export=true"
name=
"export"
class=
"btn btn-
s
m btn-success search-btn-excel"
onclick=
"return false"
>
- 导出 -
</button>
</div>
...
...
This diff is collapsed.
Click to expand it.
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