mirror of https://github.com/jumpserver/jumpserver
just do it
parent
159398b391
commit
e77ec102d9
|
@ -1,7 +1,9 @@
|
|||
# coding: utf-8
|
||||
import ast
|
||||
import xlsxwriter
|
||||
|
||||
from jumpserver.api import *
|
||||
from jasset.models import ASSET_STATUS, ASSET_TYPE, ASSET_ENV, IDC, AssetRecord
|
||||
|
||||
|
||||
def group_add_asset(group, asset_id=None, asset_ip=None):
|
||||
|
@ -99,9 +101,9 @@ def db_asset_update(**kwargs):
|
|||
|
||||
#
|
||||
#
|
||||
# def batch_host_edit(host_info, j_user='', j_password=''):
|
||||
# def batch_host_edit(host_alter_dic, j_user='', j_password=''):
|
||||
# """ 批量修改主机函数 """
|
||||
# j_id, j_ip, j_idc, j_port, j_type, j_group, j_dept, j_active, j_comment = host_info
|
||||
# j_id, j_ip, j_idc, j_port, j_type, j_group, j_dept, j_active, j_comment = host_alter_dic
|
||||
# groups, depts = [], []
|
||||
# is_active = {u'是': '1', u'否': '2'}
|
||||
# login_types = {'LDAP': 'L', 'MAP': 'M'}
|
||||
|
@ -174,34 +176,117 @@ def db_asset_update(**kwargs):
|
|||
# return httperror(request, '删除失败, 没有这个IDC!')
|
||||
|
||||
|
||||
SERVER_STATUS = {1: u"已安装系统", 2: u"未安装系统", 3: u"正在安装系统", 4: u"报废"}
|
||||
now = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M')
|
||||
file_name = 'cmdb_excel_' + now + '.xlsx'
|
||||
workbook = xlsxwriter.Workbook('static/excels/%s' % file_name)
|
||||
worksheet = workbook.add_worksheet('CMDB数据')
|
||||
worksheet.set_first_sheet()
|
||||
worksheet.set_column('A:Z', 15)
|
||||
def sort_ip_list(ip_list):
|
||||
""" ip地址排序 """
|
||||
ip_list.sort(key=lambda s: map(int, s.split('.')))
|
||||
return ip_list
|
||||
|
||||
|
||||
def write_excel(hosts):
|
||||
def get_tuple_name(asset_tuple, value):
|
||||
""""""
|
||||
for t in asset_tuple:
|
||||
if t[0] == value:
|
||||
return t[1]
|
||||
|
||||
return ''
|
||||
|
||||
|
||||
def get_tuple_diff(asset_tuple, field_name, value):
|
||||
""""""
|
||||
old_name = get_tuple_name(asset_tuple, int(value[0])) if value[0] else u''
|
||||
new_name = get_tuple_name(asset_tuple, int(value[1])) if value[1] else u''
|
||||
alert_info = [field_name, old_name, new_name]
|
||||
return alert_info
|
||||
|
||||
|
||||
def asset_diff(before, after):
|
||||
"""
|
||||
asset change before and after
|
||||
"""
|
||||
alter_dic = {}
|
||||
before_dic, after_dic = before, dict(after.iterlists())
|
||||
for k, v in before_dic.items():
|
||||
after_dic_values = after_dic.get(k, [])
|
||||
if k == 'group':
|
||||
after_dic_value = after_dic_values if len(after_dic_values) > 0 else u''
|
||||
uv = v if v is not None else u''
|
||||
else:
|
||||
after_dic_value = after_dic_values[0] if len(after_dic_values) > 0 else u''
|
||||
uv = unicode(v) if v is not None else u''
|
||||
if uv != after_dic_value:
|
||||
alter_dic.update({k: [uv, after_dic_value]})
|
||||
|
||||
for k, v in alter_dic.items():
|
||||
if v == [None, u'']:
|
||||
alter_dic.pop(k)
|
||||
|
||||
return alter_dic
|
||||
|
||||
|
||||
def db_asset_alert(asset, username, alert_dic):
|
||||
"""
|
||||
asset alert info to db
|
||||
"""
|
||||
alert_list = []
|
||||
asset_tuple_dic = {'status': ASSET_STATUS, 'env': ASSET_ENV, 'asset_type': ASSET_TYPE}
|
||||
for field, value in alert_dic.iteritems():
|
||||
print field
|
||||
field_name = Asset._meta.get_field_by_name(field)[0].verbose_name
|
||||
if field == 'idc':
|
||||
old = IDC.objects.filter(id=value[0])
|
||||
new = IDC.objects.filter(id=value[1])
|
||||
old_name = old[0].name if old else u''
|
||||
new_name = new[0].name if new else u''
|
||||
alert_info = [field_name, old_name, new_name]
|
||||
|
||||
elif field in ['status', 'env', 'asset_type']:
|
||||
alert_info = get_tuple_diff(asset_tuple_dic.get(field), field_name, value)
|
||||
|
||||
elif field == 'group':
|
||||
old, new = [], []
|
||||
for group_id in value[0]:
|
||||
group_name = AssetGroup.objects.get(id=int(group_id)).name
|
||||
old.append(group_name)
|
||||
for group_id in value[1]:
|
||||
group_name = AssetGroup.objects.get(id=int(group_id)).name
|
||||
new.append(group_name)
|
||||
alert_info = [field_name, ','.join(old), ','.join(new)]
|
||||
|
||||
elif field == 'use_default_auth':
|
||||
pass
|
||||
elif field == 'is_active':
|
||||
pass
|
||||
|
||||
else:
|
||||
alert_info = [field_name, unicode(value[0]), unicode(value[1])]
|
||||
|
||||
if 'alert_info' in dir():
|
||||
alert_list.append(alert_info)
|
||||
|
||||
if alert_list:
|
||||
AssetRecord.objects.create(asset=asset, username=username, content=alert_list)
|
||||
|
||||
|
||||
def write_excel(asset_all):
|
||||
data = []
|
||||
now = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M')
|
||||
file_name = 'cmdb_excel_' + now + '.xlsx'
|
||||
workbook = xlsxwriter.Workbook('static/files/excels/%s' % file_name)
|
||||
worksheet = workbook.add_worksheet(u'CMDB数据')
|
||||
worksheet.set_first_sheet()
|
||||
worksheet.set_column('A:Z', 14)
|
||||
title = [u'主机名', u'IP', u'IDC', u'MAC', u'远控IP', u'CPU', u'内存', u'硬盘', u'操作系统', u'机柜位置',
|
||||
u'资产编号', u'所属业务', u'机器状态', u'SN', u'运行服务', u'备注']
|
||||
for host in hosts:
|
||||
projects_list, services_list = [], []
|
||||
for p in host.project.all():
|
||||
projects_list.append(p.name)
|
||||
for s in host.service.all():
|
||||
print s.name, s.port
|
||||
services_list.append(s.name + '-' + str(s.port))
|
||||
projects = '/'.join(projects_list)
|
||||
services = '/'.join(services_list)
|
||||
status = SERVER_STATUS.get(int(host.status))
|
||||
info = [host.hostname, host.eth1, host.idc.name, host.mac, host.remote_ip, host.cpu, host.memory,
|
||||
host.disk, host.system_type, host.cabinet, host.number, projects, status,
|
||||
host.sn, services, host.comment]
|
||||
data.append(info)
|
||||
print data
|
||||
u'所属主机组', u'机器状态', u'备注']
|
||||
for asset in asset_all:
|
||||
group_list = []
|
||||
for p in asset.group.all():
|
||||
group_list.append(p.name)
|
||||
|
||||
group_all = '/'.join(group_list)
|
||||
status = asset.get_status_display()
|
||||
alter_dic = [asset.hostname, asset.ip, asset.idc.name, asset.mac, asset.remote_ip, asset.cpu, asset.memory,
|
||||
asset.disk, asset.system_type, asset.cabinet, group_all, status, asset.comment]
|
||||
data.append(alter_dic)
|
||||
format = workbook.add_format()
|
||||
format.set_border(1)
|
||||
format.set_align('center')
|
||||
|
@ -218,17 +303,11 @@ def write_excel(hosts):
|
|||
|
||||
worksheet.write_row('A1', title, format_title)
|
||||
i = 2
|
||||
for info in data:
|
||||
for alter_dic in data:
|
||||
location = 'A' + str(i)
|
||||
worksheet.write_row(location, info, format)
|
||||
worksheet.write_row(location, alter_dic, format)
|
||||
i += 1
|
||||
|
||||
workbook.close()
|
||||
ret = (True, file_name)
|
||||
return ret
|
||||
|
||||
|
||||
def sort_ip_list(ip_list):
|
||||
""" ip地址排序 """
|
||||
ip_list.sort(key=lambda s: map(int, s.split('.')))
|
||||
return ip_list
|
|
@ -5,19 +5,12 @@ from jasset.models import IDC, Asset, AssetGroup
|
|||
|
||||
|
||||
class AssetForm(forms.ModelForm):
|
||||
active_choice = (
|
||||
(1, "激活"),
|
||||
(0, "禁用")
|
||||
)
|
||||
is_active = forms.ChoiceField(
|
||||
label=u"是否激活", required=True, initial = 1,
|
||||
widget=forms.RadioSelect, choices=active_choice
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Asset
|
||||
|
||||
fields = [
|
||||
"ip", "second_ip", "hostname", "port", "group", "username", "password", "use_default_auth",
|
||||
"ip", "other_ip", "hostname", "port", "group", "username", "password", "use_default_auth",
|
||||
"idc", "mac", "remote_ip", "brand", "cpu", "memory", "disk", "system_type", "system_version",
|
||||
"cabinet", "position", "number", "status", "asset_type", "env", "sn", "is_active", "comment"
|
||||
]
|
||||
|
|
|
@ -4,19 +4,19 @@ import datetime
|
|||
from django.db import models
|
||||
from juser.models import User, UserGroup
|
||||
|
||||
ENVIRONMENT = (
|
||||
(0, U'生产环境'),
|
||||
(1, U'测试环境')
|
||||
ASSET_ENV = (
|
||||
(1, U'生产环境'),
|
||||
(2, U'测试环境')
|
||||
)
|
||||
|
||||
ASSET_STATUS = (
|
||||
(0, u"已使用"),
|
||||
(1, u"未使用"),
|
||||
(2, u"报废")
|
||||
(1, u"已使用"),
|
||||
(2, u"未使用"),
|
||||
(3, u"报废")
|
||||
)
|
||||
|
||||
ASSET_TYPE = (
|
||||
(0, u"服务器"),
|
||||
(1, u"服务器"),
|
||||
(2, u"网络设备"),
|
||||
(3, u"其他")
|
||||
)
|
||||
|
@ -33,49 +33,6 @@ class AssetGroup(models.Model):
|
|||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
def get_asset(self):
|
||||
return self.asset_set.all()
|
||||
|
||||
def get_asset_info(self, printable=False):
|
||||
assets = self.get_asset()
|
||||
ip_comment = {}
|
||||
for asset in assets:
|
||||
ip_comment[asset.ip] = asset.comment
|
||||
|
||||
for ip in sorted(ip_comment):
|
||||
if ip_comment[ip]:
|
||||
print '%-15s -- %s' % (ip, ip_comment[ip])
|
||||
else:
|
||||
print '%-15s' % ip
|
||||
print ''
|
||||
|
||||
def get_asset_num(self):
|
||||
return len(self.get_asset())
|
||||
|
||||
def get_user_group(self):
|
||||
perm_list = self.perm_set.all()
|
||||
user_group_list = []
|
||||
for perm in perm_list:
|
||||
user_group_list.append(perm.user_group)
|
||||
return user_group_list
|
||||
|
||||
def get_user(self):
|
||||
user_list = []
|
||||
user_group_list = self.get_user_group()
|
||||
for user_group in user_group_list:
|
||||
user_list.extend(user_group.user_set.all())
|
||||
return user_list
|
||||
|
||||
def is_permed(self, user=None, user_group=None):
|
||||
if user:
|
||||
if user in self.get_user():
|
||||
return True
|
||||
|
||||
if user_group:
|
||||
if user_group in self.get_user_group():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class IDC(models.Model):
|
||||
name = models.CharField(max_length=32, verbose_name=u'机房名称')
|
||||
|
@ -101,7 +58,7 @@ class Asset(models.Model):
|
|||
asset modle
|
||||
"""
|
||||
ip = models.IPAddressField(unique=True, verbose_name=u"主机IP")
|
||||
second_ip = models.CharField(max_length=255, blank=True, null=True, verbose_name=u"其他IP")
|
||||
other_ip = models.CharField(max_length=255, blank=True, null=True, verbose_name=u"其他IP")
|
||||
hostname = models.CharField(max_length=64, blank=True, null=True, verbose_name=u"主机名")
|
||||
port = models.IntegerField(max_length=6, verbose_name=u"端口号")
|
||||
group = models.ManyToManyField(AssetGroup, blank=True, null=True, verbose_name=u"所属主机组")
|
||||
|
@ -122,7 +79,7 @@ class Asset(models.Model):
|
|||
number = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'资产编号')
|
||||
status = models.IntegerField(max_length=2, choices=ASSET_STATUS, blank=True, null=True, default=1, verbose_name=u"机器状态")
|
||||
asset_type = models.IntegerField(max_length=2, choices=ASSET_TYPE, blank=True, null=True, verbose_name=u"主机类型")
|
||||
env = models.IntegerField(max_length=2, choices=ENVIRONMENT, blank=True, null=True, verbose_name=u"运行环境")
|
||||
env = models.IntegerField(max_length=2, choices=ASSET_ENV, blank=True, null=True, verbose_name=u"运行环境")
|
||||
sn = models.CharField(max_length=32, blank=True, null=True, verbose_name=u"SN编号")
|
||||
date_added = models.DateTimeField(auto_now=True, default=datetime.datetime.now(), null=True)
|
||||
is_active = models.BooleanField(default=True, verbose_name=u"是否激活")
|
||||
|
@ -132,6 +89,14 @@ class Asset(models.Model):
|
|||
return self.ip
|
||||
|
||||
|
||||
class AssetRecord(models.Model):
|
||||
asset = models.ForeignKey(Asset)
|
||||
username = models.CharField(max_length=30, null=True)
|
||||
alert_time = models.DateTimeField(auto_now_add=True)
|
||||
content = models.TextField(null=True, blank=True)
|
||||
comment = models.TextField(null=True, blank=True)
|
||||
|
||||
|
||||
class AssetAlias(models.Model):
|
||||
user = models.ForeignKey(User)
|
||||
asset = models.ForeignKey(Asset)
|
||||
|
|
|
@ -12,7 +12,6 @@ urlpatterns = patterns('',
|
|||
url(r'^asset_del/$', asset_del),
|
||||
url(r"^asset_detail/$", asset_detail),
|
||||
url(r'^asset_edit/$', asset_edit),
|
||||
url(r'^asset_search/$', asset_search),
|
||||
# url(r'^search/$', host_search),
|
||||
# url(r"^host_detail/$", host_detail),
|
||||
# url(r"^dept_host_ajax/$", dept_host_ajax),
|
||||
|
@ -22,6 +21,6 @@ urlpatterns = patterns('',
|
|||
url(r'^group_detail/$', group_detail),
|
||||
# url(r'^group_del_host/$', group_del_host),
|
||||
|
||||
# url(r'^host_edit/batch/$', host_edit_batch),
|
||||
url(r'^asset_edit_batch/$', asset_edit_batch),
|
||||
# url(r'^host_edit_common/batch/$', host_edit_common_batch),
|
||||
)
|
192
jasset/views.py
192
jasset/views.py
|
@ -146,8 +146,10 @@ def asset_add(request):
|
|||
af = AssetForm()
|
||||
if request.method == 'POST':
|
||||
af_post = AssetForm(request.POST)
|
||||
ip = request.POST.get('ip')
|
||||
|
||||
print af_post
|
||||
ip = request.POST.get('ip', '')
|
||||
is_active = True if request.POST.get('is_active') == '1' else False
|
||||
use_default_auth = request.POST.get('use_default_auth', '')
|
||||
try:
|
||||
if Asset.objects.filter(ip=str(ip)):
|
||||
error = u'该IP %s 已存在!' % ip
|
||||
|
@ -159,8 +161,14 @@ def asset_add(request):
|
|||
else:
|
||||
if af_post.is_valid():
|
||||
asset_save = af_post.save(commit=False)
|
||||
if not use_default_auth:
|
||||
password = request.POST.get('password', '')
|
||||
password_encode = CRYPTOR.encrypt(password)
|
||||
asset_save.password = password_encode
|
||||
asset_save.is_active = True if is_active else False
|
||||
asset_save.save()
|
||||
af_post.save_m2m()
|
||||
|
||||
msg = u'主机 %s 添加成功' % ip
|
||||
else:
|
||||
esg = u'主机 %s 添加失败' % ip
|
||||
|
@ -168,30 +176,6 @@ def asset_add(request):
|
|||
return my_render('jasset/asset_add.html', locals(), request)
|
||||
|
||||
|
||||
@require_role(role='user')
|
||||
def asset_list(request):
|
||||
"""
|
||||
list assets
|
||||
列出资产表
|
||||
"""
|
||||
header_title, path1, path2 = u'查看主机', u'资产管理', u'查看主机'
|
||||
idc_all = IDC.objects.filter()
|
||||
asset_group_all = AssetGroup.objects.all()
|
||||
asset_type = ASSET_TYPE
|
||||
asset_status = ASSET_STATUS
|
||||
keyword = request.GET.get('keyword', '')
|
||||
gid = request.GET.get('gid', '') # asset group id
|
||||
sid = request.GET.get('sid', '')
|
||||
assets_list = Asset.objects.all().order_by('ip')
|
||||
|
||||
if keyword:
|
||||
assets_list = assets_list.filter(Q(ip__contains=keyword) |
|
||||
Q(comment__contains=keyword)).distinct().order_by('ip')
|
||||
|
||||
assets_list, p, assets, page_range, current_page, show_first, show_end = pages(assets_list, request)
|
||||
return my_render('jasset/asset_list.html', locals(), request)
|
||||
|
||||
|
||||
@require_role('admin')
|
||||
def asset_del(request):
|
||||
"""
|
||||
|
@ -223,8 +207,9 @@ def asset_edit(request):
|
|||
header_title, path1, path2 = u'修改资产', u'资产管理', u'修改资产'
|
||||
|
||||
asset_id = request.GET.get('id', '')
|
||||
if not asset_id:
|
||||
return HttpResponse('没有该主机')
|
||||
username = request.session.get('username', 'admin')
|
||||
# if not asset_id:
|
||||
# return HttpResponse('没有该主机')
|
||||
asset = get_object(Asset, id=asset_id)
|
||||
af = AssetForm(instance=asset)
|
||||
if request.method == 'POST':
|
||||
|
@ -239,8 +224,8 @@ def asset_edit(request):
|
|||
# comment = request.POST.get('comment')
|
||||
|
||||
# if not use_default_auth:
|
||||
# username = request.POST.get('username')
|
||||
# password = request.POST.get('password')
|
||||
# username = request.POST.get('username')
|
||||
# password = request.POST.get('password')
|
||||
# if password == asset.password:
|
||||
# password_encode = password
|
||||
# else:
|
||||
|
@ -251,7 +236,7 @@ def asset_edit(request):
|
|||
|
||||
try:
|
||||
asset_test = get_object(Asset, ip=ip)
|
||||
if asset_test and asset_id != str(asset_test.id):
|
||||
if asset_test and asset_id != unicode(asset_test.id):
|
||||
error = u'该IP %s 已存在!' % ip
|
||||
raise ServerError(error)
|
||||
except ServerError:
|
||||
|
@ -261,6 +246,10 @@ def asset_edit(request):
|
|||
af_save = af_post.save(commit=False)
|
||||
af_save.save()
|
||||
af_post.save_m2m()
|
||||
info = asset_diff(af_post.__dict__.get('initial'), request.POST)
|
||||
print info
|
||||
db_asset_alert(asset, username, info)
|
||||
|
||||
msg = u'主机 %s 修改成功' % ip
|
||||
else:
|
||||
emg = u'主机 %s 修改失败' % ip
|
||||
|
@ -269,6 +258,65 @@ def asset_edit(request):
|
|||
return my_render('jasset/asset_edit.html', locals(), request)
|
||||
|
||||
|
||||
@require_role('user')
|
||||
def asset_list(request):
|
||||
"""
|
||||
asset list view
|
||||
"""
|
||||
idc_all = IDC.objects.filter()
|
||||
asset_group_all = AssetGroup.objects.all()
|
||||
asset_types = ASSET_TYPE
|
||||
asset_status = ASSET_STATUS
|
||||
|
||||
idc_name = request.GET.get('idc', '')
|
||||
group_name = request.GET.get('group', '')
|
||||
asset_type = request.GET.get('asset_type', '')
|
||||
status = request.GET.get('status', '')
|
||||
keyword = request.GET.get('keyword', '')
|
||||
export = request.GET.get("export", False)
|
||||
|
||||
asset_find = Asset.objects.all()
|
||||
if idc_name:
|
||||
asset_find = asset_find.filter(idc__name__contains=idc_name)
|
||||
|
||||
if group_name:
|
||||
asset_find = asset_find.filter(group__name__contains=group_name)
|
||||
|
||||
if asset_type:
|
||||
asset_find = asset_find.filter(asset_type__contains=asset_type)
|
||||
|
||||
if status:
|
||||
asset_find = asset_find.filter(status__contains=status)
|
||||
|
||||
if keyword:
|
||||
asset_find = asset_find.filter(
|
||||
Q(hostname__contains=keyword) |
|
||||
Q(other_ip__contains=keyword) |
|
||||
Q(ip__contains=keyword) |
|
||||
Q(remote_ip__contains=keyword) |
|
||||
Q(comment__contains=keyword) |
|
||||
Q(group__name__contains=keyword) |
|
||||
Q(cpu__contains=keyword) |
|
||||
Q(memory__contains=keyword) |
|
||||
Q(disk__contains=keyword))
|
||||
|
||||
if export:
|
||||
s = write_excel(asset_find)
|
||||
if s[0]:
|
||||
file_name = s[1]
|
||||
smg = '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)
|
||||
return my_render('jasset/asset_list.html', locals(), request)
|
||||
|
||||
|
||||
@require_role('admin')
|
||||
def asset_edit_batch(request):
|
||||
af = AssetForm()
|
||||
asset_group_all = AssetGroup.objects.all()
|
||||
return my_render('jasset/asset_edit_batch.html', locals(), request)
|
||||
|
||||
|
||||
@require_role('admin')
|
||||
def asset_detail(request):
|
||||
"""
|
||||
|
@ -277,86 +325,6 @@ def asset_detail(request):
|
|||
header_title, path1, path2 = u'主机详细信息', u'资产管理', u'主机详情'
|
||||
asset_id = request.GET.get('id', '')
|
||||
asset = get_object(Asset, id=asset_id)
|
||||
asset_record = AssetRecord.objects.filter(asset=asset).order_by('-alert_time')
|
||||
|
||||
return my_render('jasset/asset_detail.html', locals(), request)
|
||||
|
||||
|
||||
@require_role('user')
|
||||
def asset_search(request):
|
||||
"""
|
||||
主机搜索
|
||||
"""
|
||||
idc_all = IDC.objects.filter()
|
||||
asset_group_all = AssetGroup.objects.all()
|
||||
asset_type = ASSET_TYPE
|
||||
asset_status = ASSET_STATUS
|
||||
|
||||
idc_name = request.GET.get('idc', '')
|
||||
group_name = request.GET.get('group', '')
|
||||
asset_type = request.GET.get('asset_type', '')
|
||||
status = request.GET.get('status', '')
|
||||
keyword = request.GET.get('keyword', '')
|
||||
|
||||
if not idc_name and not asset_type and not status and group_name == 'all':
|
||||
select_number = 0
|
||||
else:
|
||||
select_number = 1
|
||||
|
||||
if group_name == 'all':
|
||||
asset_find = Asset.objects.filter(
|
||||
idc__name__contains=idc_name,
|
||||
asset_type__contains=asset_type,
|
||||
status__contains=status
|
||||
)
|
||||
|
||||
else:
|
||||
asset_find = Asset.objects.filter(
|
||||
idc__name__contains=idc_name,
|
||||
group__name__contains=group_name,
|
||||
asset_type__contains=asset_type,
|
||||
status__contains=status
|
||||
)
|
||||
if keyword and select_number == 1:
|
||||
asset_find = asset_find.filter(
|
||||
Q(hostname__contains=keyword) |
|
||||
Q(idc__name__contains=keyword) |
|
||||
Q(ip__contains=keyword) |
|
||||
Q(remote_ip__contains=keyword) |
|
||||
Q(comment__contains=keyword) |
|
||||
Q(group__name__contains=keyword) |
|
||||
Q(cpu__contains=keyword) |
|
||||
Q(memory__contains=keyword) |
|
||||
Q(disk__contains=keyword))
|
||||
|
||||
elif keyword:
|
||||
asset_find = Asset.objects.filter(
|
||||
Q(hostname__contains=keyword) |
|
||||
Q(idc__name__contains=keyword) |
|
||||
Q(ip__contains=keyword) |
|
||||
Q(remote_ip__contains=keyword) |
|
||||
Q(comment__contains=keyword) |
|
||||
Q(group__name__contains=keyword) |
|
||||
Q(cpu__contains=keyword) |
|
||||
Q(memory__contains=keyword) |
|
||||
Q(disk__contains=keyword))
|
||||
|
||||
# asset_find = list(set(asset_find))
|
||||
# asset_find_dic = {}
|
||||
# asset_find_lis = []
|
||||
# for server in asset_find:
|
||||
# if server.ip:
|
||||
# asset_find_dic[server.ip] = server
|
||||
# asset_find_lis.append(server.ip)
|
||||
# sort_ip_list(asset_find_lis)
|
||||
# asset_find = []
|
||||
# for ip in asset_find_lis:
|
||||
# asset_find.append(asset_find_dic[ip])
|
||||
# search_status = request.GET.get("_search", False)
|
||||
# if search_status:
|
||||
# s = write_excel(asset_find)
|
||||
# if s[0]:
|
||||
# file_name = s[1]
|
||||
# smg = 'excel文件已生成,请点击下载!'
|
||||
# return my_render('cmdb/excel_download.html', locals(), request)
|
||||
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(asset_find, request)
|
||||
return my_render('jasset/asset_list.html', locals(), request)
|
|
@ -408,3 +408,19 @@ def to_avatar(role_id='0'):
|
|||
# @register.filter(name='cmd_group_split')
|
||||
# def cmd_group_split(cmd_group):
|
||||
# return cmd_group.cmd.split(',')
|
||||
|
||||
|
||||
@register.filter(name='str_to_list')
|
||||
def str_to_list(info):
|
||||
"""
|
||||
str to list
|
||||
"""
|
||||
return ast.literal_eval(info)
|
||||
|
||||
|
||||
@register.filter(name='str_to_code')
|
||||
def str_to_code(char_str):
|
||||
if char_str:
|
||||
return char_str
|
||||
else:
|
||||
return u'空'
|
||||
|
|
|
@ -4562,3 +4562,8 @@ body.skin-3 {
|
|||
.red-fonts {
|
||||
color: #ed5565;
|
||||
}
|
||||
|
||||
.form-group.required .control-label:after {
|
||||
content: " *";
|
||||
color: red;
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -50,11 +50,9 @@
|
|||
<div class="hr-line-dashed"></div>
|
||||
{{ af.idc|bootstrap_horizontal }}
|
||||
|
||||
{# {{ af.use_default_auth|bootstrap_horizontal }}#}
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="j_group" class="col-sm-2 control-label">管理账号</label>
|
||||
<label for="j_group" class="col-sm-2 control-label">管理账号<span class="red-fonts"> *</span></label>
|
||||
<div class="col-sm-2">
|
||||
<div class="radio i-checks">
|
||||
<label>
|
||||
|
@ -79,21 +77,17 @@
|
|||
<div class="hr-line-dashed"></div>
|
||||
{{ af.group|bootstrap_horizontal }}
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
{{ af.is_active|bootstrap_horizontal }}
|
||||
|
||||
{# <div class="hr-line-dashed"></div>#}
|
||||
{# <div class="form-group"><label class="col-sm-2 control-label"> 是否激活<span class="red-fonts">*</span> </label>#}
|
||||
{# <div class="col-sm-8">#}
|
||||
{# <div class="radio i-checks">#}
|
||||
{# <label> <input type="radio" checked="" name="is_active">激活 </label>#}
|
||||
{# <label> <input type="radio" name="is_active"> 禁用</label>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# {{ af.is_active|bootstrap_horizontal }}#}
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
{{ af.comment|bootstrap_horizontal }}
|
||||
<div class="form-group"><label class="col-sm-2 control-label"> 是否激活<span class="red-fonts"> *</span> </label>
|
||||
<div class="col-sm-8">
|
||||
<div class="radio i-checks">
|
||||
<label> <input type="radio" checked="" value="1" name="is_active">激活 </label>
|
||||
<label> <input type="radio" value="0" name="is_active"> 禁用</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
|
@ -116,43 +110,47 @@
|
|||
|
||||
{% block self_footer_js %}
|
||||
<script>
|
||||
$('document').ready(function(){
|
||||
$('#id_use_default_auth').click(function(){
|
||||
if ($(this).is(':checked')){
|
||||
$('#admin_account').css('display', 'none')
|
||||
}
|
||||
else {
|
||||
$('#admin_account').css('display', 'block')
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
$('document').ready(function(){
|
||||
$('#id_use_default_auth').click(function(){
|
||||
if ($(this).is(':checked')){
|
||||
$('#admin_account').css('display', 'none')
|
||||
}
|
||||
else {
|
||||
$('#admin_account').css('display', 'block')
|
||||
}
|
||||
})
|
||||
});
|
||||
var required_fields = ["id_hostname", "id_ip", "id_port"];
|
||||
required_fields.forEach(function(field) {
|
||||
$('label[for="' + field + '"]').parent().addClass("required");
|
||||
});
|
||||
|
||||
$('#assetForm').validator({
|
||||
timely: 2,
|
||||
theme: "yellow_right_effect",
|
||||
rules: {
|
||||
check_ip: [/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/, 'ip地址不正确'],
|
||||
check_port: [/^\d{1,5}$/, '端口号不正确'],
|
||||
},
|
||||
fields: {
|
||||
"ip": {
|
||||
rule: "required;check_ip",
|
||||
tip: "输入IP",
|
||||
ok: "",
|
||||
msg: {required: "必须填写!"}
|
||||
$('#assetForm').validator({
|
||||
timely: 2,
|
||||
theme: "yellow_right_effect",
|
||||
rules: {
|
||||
check_ip: [/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/, 'ip地址不正确'],
|
||||
check_port: [/^\d{1,5}$/, '端口号不正确'],
|
||||
},
|
||||
"port": {
|
||||
rule: "required;check_port",
|
||||
tip: "输入端口号",
|
||||
ok: "",
|
||||
msg: {required: "必须填写!"}
|
||||
fields: {
|
||||
"ip": {
|
||||
rule: "required;check_ip",
|
||||
tip: "输入IP",
|
||||
ok: "",
|
||||
msg: {required: "必须填写!"}
|
||||
},
|
||||
"port": {
|
||||
rule: "required;check_port",
|
||||
tip: "输入端口号",
|
||||
ok: "",
|
||||
msg: {required: "必须填写!"}
|
||||
}
|
||||
},
|
||||
valid: function(form) {
|
||||
form.submit();
|
||||
}
|
||||
},
|
||||
valid: function(form) {
|
||||
form.submit();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{% extends 'base.html' %}
|
||||
{% load mytags %}
|
||||
|
||||
{% load humanize %}
|
||||
|
||||
{% block content %}
|
||||
{% include 'nav_cat_bar.html' %}
|
||||
|
@ -60,7 +60,8 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td class="text-navy">使用默认管理账号</td>
|
||||
<td>{{ asset.use_default_auth|bool2str }}</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>
|
||||
|
@ -152,8 +153,8 @@
|
|||
</div>
|
||||
<div class="ibox-content">
|
||||
<div>
|
||||
<div class="text-left">
|
||||
<table class="table">
|
||||
{# <div class="text-left">#}
|
||||
{# <table class="table">#}
|
||||
{# {% if user_permed_list %}#}
|
||||
{# {% for user in user_permed_list %}#}
|
||||
{# <tr>#}
|
||||
|
@ -165,8 +166,48 @@
|
|||
{# {% else %}#}
|
||||
{# <p class="text-center">(暂无)</p>#}
|
||||
{# {% endif %}#}
|
||||
</table>
|
||||
</div>
|
||||
{# </table>#}
|
||||
{# </div>#}
|
||||
</div>
|
||||
</div>
|
||||
<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 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>
|
||||
|
|
|
@ -39,6 +39,9 @@
|
|||
<div class="hr-line-dashed"></div>
|
||||
{{ af.hostname|bootstrap_horizontal }}
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
{{ af.other_ip|bootstrap_horizontal }}
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
{{ af.remote_ip|bootstrap_horizontal }}
|
||||
|
||||
|
@ -47,25 +50,25 @@
|
|||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="j_group" class="col-sm-2 control-label">管理账号</label>
|
||||
<label for="j_group" class="col-sm-2 control-label">管理账号 <span class="red-fonts">*</span></label>
|
||||
<div class="col-sm-2">
|
||||
<div class="radio i-checks">
|
||||
<label>
|
||||
<input type="checkbox" checked="" id="id_use_default_auth" name="use_default_auth"><span> 使用默认 </span>
|
||||
<input type="checkbox" {% if asset.use_default_auth %} checked="" {% endif %} id="id_use_default_auth" name="use_default_auth"><span> 使用默认 </span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" id="admin_account" style="display: none">
|
||||
<label class="col-sm-2 control-label"> 管理用户名<span class="red-fonts">*</span> </label>
|
||||
<div class="form-group" id="admin_account" {% if asset.use_default_auth %} style="display: none" {% endif %}>
|
||||
<label class="col-sm-2 control-label"> 管理用户名 <span class="red-fonts">*</span> </label>
|
||||
<div class="col-sm-3">
|
||||
<input type="text" placeholder="Username" name="username" class="form-control">
|
||||
<input type="text" value="{{ asset.username }}" name="username" class="form-control">
|
||||
</div>
|
||||
|
||||
<label class="col-sm-1 control-label"> 密码<span class="red-fonts">*</span> </label>
|
||||
<div class="col-sm-4">
|
||||
<input type="password" placeholder="Password" name="password" class="form-control">
|
||||
<input type="password" value="{{ asset.password }}" name="password" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -109,23 +112,23 @@
|
|||
<div class="hr-line-dashed"></div>
|
||||
{{ af.status|bootstrap_horizontal }}
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
{{ af.is_active|bootstrap_horizontal }}
|
||||
|
||||
{# <div class="hr-line-dashed"></div>#}
|
||||
{# <div class="form-group"><label class="col-sm-2 control-label"> 是否激活<span class="red-fonts">*</span> </label>#}
|
||||
{# <div class="col-sm-8">#}
|
||||
{# <div class="radio i-checks">#}
|
||||
{# {% ifequal asset.is_active 1 %}#}
|
||||
{# <label> <input type="radio" checked="" value="1" name="is_active">激活 </label>#}
|
||||
{# <label> <input type="radio" value="0" name="is_active"> 禁用</label>#}
|
||||
{# {% else %}#}
|
||||
{# <label> <input type="radio" value="1" name="is_active">激活 </label>#}
|
||||
{# <label> <input type="radio" checked="" value="0" name="is_active"> 禁用</label>#}
|
||||
{# {% endifequal %}#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# {{ af.is_active|bootstrap_horizontal }}#}
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group"><label class="col-sm-2 control-label"> 是否激活<span class="red-fonts">*</span> </label>
|
||||
<div class="col-sm-8">
|
||||
<div class="radio i-checks">
|
||||
{% ifequal asset.is_active 1 %}
|
||||
<label> <input type="radio" checked="" value="1" name="is_active">激活 </label>
|
||||
<label> <input type="radio" value="0" name="is_active"> 禁用</label>
|
||||
{% else %}
|
||||
<label> <input type="radio" value="1" name="is_active">激活 </label>
|
||||
<label> <input type="radio" checked="" value="0" name="is_active"> 禁用</label>
|
||||
{% endifequal %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
{{ af.comment|bootstrap_horizontal }}
|
||||
|
@ -151,43 +154,47 @@
|
|||
|
||||
{% block self_footer_js %}
|
||||
<script>
|
||||
$('document').ready(function(){
|
||||
$('#id_use_default_auth').click(function(){
|
||||
if ($(this).is(':checked')){
|
||||
$('#admin_account').css('display', 'none')
|
||||
}
|
||||
else {
|
||||
$('#admin_account').css('display', 'block')
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
$('document').ready(function(){
|
||||
$('#id_use_default_auth').click(function(){
|
||||
if ($(this).is(':checked')){
|
||||
$('#admin_account').css('display', 'none')
|
||||
}
|
||||
else {
|
||||
$('#admin_account').css('display', 'block')
|
||||
}
|
||||
})
|
||||
});
|
||||
var required_fields = ["id_ip", "id_port"];
|
||||
required_fields.forEach(function(field) {
|
||||
$('label[for="' + field + '"]').parent().addClass("required");
|
||||
});
|
||||
|
||||
$('#assetForm').validator({
|
||||
timely: 2,
|
||||
theme: "yellow_right_effect",
|
||||
rules: {
|
||||
check_ip: [/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/, 'ip地址不正确'],
|
||||
check_port: [/^\d{1,5}$/, '端口号不正确'],
|
||||
},
|
||||
fields: {
|
||||
"ip": {
|
||||
rule: "required;check_ip",
|
||||
tip: "输入IP",
|
||||
ok: "",
|
||||
msg: {required: "必须填写!"}
|
||||
$('#assetForm').validator({
|
||||
timely: 2,
|
||||
theme: "yellow_right_effect",
|
||||
rules: {
|
||||
check_ip: [/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/, 'ip地址不正确'],
|
||||
check_port: [/^\d{1,5}$/, '端口号不正确'],
|
||||
},
|
||||
"port": {
|
||||
rule: "required;check_port",
|
||||
tip: "输入端口号",
|
||||
ok: "",
|
||||
msg: {required: "必须填写!"}
|
||||
fields: {
|
||||
"ip": {
|
||||
rule: "required;check_ip",
|
||||
tip: "输入IP",
|
||||
ok: "",
|
||||
msg: {required: "必须填写!"}
|
||||
},
|
||||
"port": {
|
||||
rule: "required;check_port",
|
||||
tip: "输入端口号",
|
||||
ok: "",
|
||||
msg: {required: "必须填写!"}
|
||||
}
|
||||
},
|
||||
valid: function(form) {
|
||||
form.submit();
|
||||
}
|
||||
},
|
||||
valid: function(form) {
|
||||
form.submit();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
|
|
|
@ -0,0 +1,180 @@
|
|||
<html>
|
||||
<head>
|
||||
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="/static/font-awesome/css/font-awesome.css" rel="stylesheet">
|
||||
<link href="/static/css/plugins/iCheck/custom.css" rel="stylesheet">
|
||||
<link href="/static/css/animate.css" rel="stylesheet">
|
||||
<link href="/static/css/style.css" rel="stylesheet">
|
||||
|
||||
<script src="/static/js/jquery-2.1.1.js"></script>
|
||||
{# <style>#}
|
||||
{# body {background: #ffffff;}#}
|
||||
{# </style>#}
|
||||
</head>
|
||||
|
||||
{% load bootstrap %}
|
||||
{% block content %}
|
||||
|
||||
<body>
|
||||
<div class="wrapper wrapper-content animated fadeInRight">
|
||||
<div class="row">
|
||||
<div class="col-lg-10">
|
||||
<div class="ibox float-e-margins">
|
||||
<div class="ibox-title">
|
||||
<h5 class="text-center"> 填写修改主机信息. </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">
|
||||
<form class="form-horizontal" action="" id="signupForm" method="post" name="horizontal" role="form" autocomplete="off">
|
||||
{% csrf_token %}
|
||||
<input id="ids" style="display: none">
|
||||
{{ af.env|bootstrap_horizontal }}
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
{{ af.idc|bootstrap_horizontal }}
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
{{ af.port|bootstrap_horizontal }}
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="j_group" class="col-sm-2 control-label">管理账号</label>
|
||||
<div class="col-sm-2">
|
||||
<div class="radio i-checks">
|
||||
<label>
|
||||
<input type="radio" checked="" value="no_action" name="use_default_auth"><span> 不修改 </span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio i-checks">
|
||||
<label>
|
||||
<input type="radio" name="use_default_auth"><span> 使用默认 </span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio i-checks">
|
||||
<label>
|
||||
<input type="radio" id="id_use_default_auth" name="use_default_auth"><span> 用户名密码 </span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" id="admin_account" style="display: none">
|
||||
<label class="col-sm-2 control-label"> 管理用户名<span class="red-fonts"> *</span></label>
|
||||
<div class="col-sm-3">
|
||||
<input type="text" placeholder="Username" name="username" class="form-control">
|
||||
</div>
|
||||
|
||||
<label class="col-sm-1 control-label"> 密码<span class="red-fonts">*</span> </label>
|
||||
<div class="col-sm-4">
|
||||
<input type="password" placeholder="Password" name="password" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
<div class="form-group">
|
||||
<label for="groups" class="col-sm-2 control-label">所属主机组</label>
|
||||
|
||||
<div class="col-sm-3">
|
||||
<select id="groups" size="10" class="form-control m-b" multiple>
|
||||
{% for asset_group in asset_group_all %}
|
||||
<option value="{{ asset_group.id }}">{{ asset_group.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-sm-1">
|
||||
<div class="btn-group" style="margin-top: 50px;">
|
||||
<button type="button" class="btn btn-white" onclick="move_right('groups', 'groups_selected')"><i class="fa fa-chevron-right"></i></button>
|
||||
<button type="button" class="btn btn-white" onclick="move_left('groups_selected', 'groups')"><i class="fa fa-chevron-left"></i> </button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<div>
|
||||
<select id="groups_selected" name="project" class="form-control m-b" size="10" multiple>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
{{ af.cabinet|bootstrap_horizontal }}
|
||||
|
||||
<div class="hr-line-dashed"></div>
|
||||
{{ af.comment|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="submit"> 重置 </button>
|
||||
<button class="btn btn-primary" id="host_edit"> 提交 </button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#host_edit').click(function () {
|
||||
var args = {};
|
||||
var match = null;
|
||||
var uuid = decodeURIComponent(location.search.substring(1));
|
||||
var reg = /(?:([^&]+)=([^&]+))/g;
|
||||
while((match = reg.exec(uuid))!==null){
|
||||
args[match[1]] = match[2];
|
||||
}
|
||||
var ids = args['uuid'];
|
||||
$('#uuid').val(ids)
|
||||
});
|
||||
|
||||
$('#id_use_default_auth').click(function(){
|
||||
if ($(this).is(':checked')){
|
||||
$('#admin_account').css('display', 'block')
|
||||
}
|
||||
else {
|
||||
$('#admin_account').css('display', 'none')
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
function move_left(from, to) {
|
||||
$("#"+from+" option").each(function(){
|
||||
if ( $(this).prop("selected") == true ) {
|
||||
$("#"+to).append(this);
|
||||
$(this).attr("selected",'false');
|
||||
}
|
||||
$(this).attr("selected",'true');
|
||||
});
|
||||
}
|
||||
function move_right(from, to) {
|
||||
$("#"+from+" option").each(function(){
|
||||
if ( $(this).prop("selected") == true ) {
|
||||
$("#"+to).append(this);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function move_all(from, to){
|
||||
$("#"+from).children().each(function(){
|
||||
$("#"+to).append(this);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{% endblock content %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<div class="col-md-12 column">
|
||||
<div class="alert alert-success alert-dismissable">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
<h4>
|
||||
</h4> <strong>Nice!</strong> excel文件已生成请点击 <a href="/static/files/excels/{{ file_name }}" target="_blank" class="alert-link">下载</a>
|
||||
</div>
|
||||
</div>
|
|
@ -41,7 +41,7 @@
|
|||
<div class="col-sm-2">
|
||||
<label>
|
||||
<select name="group" class="form-control m-b" onchange="change_info()">
|
||||
<option value="all">主机组</option>
|
||||
<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>
|
||||
|
@ -55,9 +55,9 @@
|
|||
|
||||
<div class="col-sm-2">
|
||||
<label>
|
||||
<select name="server_type" class="form-control m-b" onchange="change_info()">
|
||||
<select name="asset_type" class="form-control m-b" onchange="change_info()">
|
||||
<option value="">所有类型</option>
|
||||
{% for type in asset_type %}
|
||||
{% for type in asset_types %}
|
||||
{% ifequal type.0|int2str asset_type %}
|
||||
<option value="{{ type.0 }}" selected> {{ type.1 }}</option>
|
||||
{% else %}
|
||||
|
@ -71,35 +71,37 @@
|
|||
<label>
|
||||
<select name="status" class="form-control m-b" onchange="change_info()">
|
||||
<option value="">状态</option>
|
||||
{% for status in asset_status %}
|
||||
{% ifequal status.0|int2str status %}
|
||||
<option value="{{ status.0 }}" selected> {{ status.1 }}</option>
|
||||
{% for s in asset_status %}
|
||||
{% ifequal s.0|int2str status %}
|
||||
<option value="{{ s.0 }}" selected> {{ s.1 }}</option>
|
||||
{% else %}
|
||||
<option value="{{ status.0 }}"> {{ status.1 }}</option>
|
||||
<option value="{{ s.0 }}"> {{ s.1 }}</option>
|
||||
{% endifequal %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<form id="search_form" method="get" action="" class="pull-right mail-search">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control input-sm" id="search_input" name="keyword" placeholder="Search">
|
||||
<input type="text" style="display: none">
|
||||
<div class="input-group-btn">
|
||||
<button type="submit" class="btn btn-sm btn-primary">
|
||||
- 搜索 -
|
||||
</button>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control m-b" 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-xm btn-primary search-btn" onclick="change_info()">
|
||||
- 搜索 -
|
||||
</button>
|
||||
<button type="button" href="/jasset/asset_list/?export=true" name="export" class="btn btn-xm btn-success search-btn-excel" onclick="return false">
|
||||
- 导出 -
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</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('contents_form')">
|
||||
<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" name="ip"> IP地址 </th>
|
||||
<th class="text-center"> 主机名 </th>
|
||||
|
@ -119,7 +121,7 @@
|
|||
<td class="text-center"> {{ asset.ip }} </td>
|
||||
<td class="text-center"> {{ asset.hostname }} </td>
|
||||
<td class="text-center"> {{ asset.idc.name }} </td>
|
||||
<td class="text-center">{{ asset.port }}</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.use_default_auth|bool2str }} </td>
|
||||
<td class="text-center" data-editable='false'>
|
||||
|
@ -136,12 +138,12 @@
|
|||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<input type="button" id="asset_del" class="btn btn-danger btn-sm" name="del_button" value="删除"/>
|
||||
<input type="button" id="alter_button" class="btn btn-warning btn-sm" name="alter_button" value="修改" onclick="alter('contents_form')" />
|
||||
<a value="/jasset/asset_edit_batch/" type="button" class="btn btn-sm btn-warning iframe">修改</a>
|
||||
</div>
|
||||
{% include 'paginator.html' %}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -178,23 +180,41 @@
|
|||
})
|
||||
});
|
||||
|
||||
|
||||
function alter(form) {
|
||||
selectData = GetTableDataBox();
|
||||
console.log(selectData[0])
|
||||
if (selectData[1] != 0) {
|
||||
$.ajax({
|
||||
type: "post",
|
||||
url: "/jasset/host_edit/batch/",
|
||||
data: {"editable": selectData[0], "len_table": selectData[1]},
|
||||
success: function (data) {
|
||||
alert("修改成功");
|
||||
window.open("/jasset/host_list/", "_self");
|
||||
error: window.open("/jasset/host_list/", "_self");
|
||||
$(".iframe").on('click', function(){
|
||||
var ids = getIDall();
|
||||
if (ids == ''){
|
||||
alert("请至少选择一行!");
|
||||
return false;
|
||||
}
|
||||
var url= $(this).attr("value") + '?id=' + ids;
|
||||
index = $.layer({
|
||||
type: 2,
|
||||
title: 'JumpServer - 批量修改主机',
|
||||
maxmin: true,
|
||||
shift: 'top',
|
||||
border: [2, 0.3, '#1AB394'],
|
||||
shade: [0.5, '#000000'],
|
||||
shadeClose: true,
|
||||
area : ['800px' , '600px'],
|
||||
iframe: {src: url},
|
||||
close: function(){
|
||||
location.replace(location.href);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('.search-btn-excel').unbind('click').bind('click',function(){
|
||||
var url= $(this).attr("href");
|
||||
console.log(url);
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: url,
|
||||
data: $("#asset_form").serialize(),
|
||||
success: function (data) {
|
||||
$("#export").html(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#asset_del').click(function () {
|
||||
var asset_id_all = getIDall();
|
||||
|
@ -218,13 +238,12 @@
|
|||
|
||||
function change_info(){
|
||||
var args = $("#asset_form").serialize();
|
||||
window.location = "/jasset/asset_search/?" + args
|
||||
window.location = "/jasset/asset_list/?" + args
|
||||
}
|
||||
|
||||
|
||||
$("#search_input").keydown(function(e){
|
||||
if(e.keyCode==13){
|
||||
host_search()
|
||||
change_info()
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -234,7 +253,6 @@
|
|||
$.ajax({
|
||||
type: "GET",
|
||||
url: url,
|
||||
// data: $("#search_form").serialize(),
|
||||
success: function (data) {
|
||||
$("#j_group_" + id).html(data);
|
||||
|
||||
|
|
Loading…
Reference in New Issue