diff --git a/jasset/models.py b/jasset/models.py index 99f435f96..92fd9c1ce 100644 --- a/jasset/models.py +++ b/jasset/models.py @@ -12,8 +12,13 @@ class IDC(models.Model): class BisGroup(models.Model): + GROUP_TYPE = ( + ('P', 'PRIVATE'), + ('A', 'ASSET'), + ) name = models.CharField(max_length=80, unique=True) comment = models.CharField(max_length=160, blank=True, null=True) + type = models.CharField(max_length=1, choices=GROUP_TYPE, default='P') def __unicode__(self): return self.name diff --git a/jasset/urls.py b/jasset/urls.py index 280ed090c..3b8fd120d 100644 --- a/jasset/urls.py +++ b/jasset/urls.py @@ -13,7 +13,8 @@ urlpatterns = patterns('', url(r'^group_add/$', jadd_group), url(r'^group_list/$', jlist_group), url(r'^group_del/(\d+)/$', group_del), - url(r'^host_del/(\d+.\d+.\d+.\d+)/$', host_del), - url(r'^host_edit/(\d+.\d+.\d+.\d+)/$', host_edit), + url(r'^host_del/(\d+)/$', host_del), + url(r'^host_edit/(\d+)$', host_edit), + url(r'^host_edit/batch/$', batch_host_edit), url(r'^test/$', test), ) \ No newline at end of file diff --git a/jasset/views.py b/jasset/views.py index 482ed8fad..706f166cd 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -7,7 +7,7 @@ from django.core.paginator import Paginator, EmptyPage from models import IDC, Asset, BisGroup from juser.models import UserGroup from connect import PyCrypt, KEY -from jpermission.models import Permission +from jumpserver.views import jasset_group_add, jasset_host_edit cryptor = PyCrypt(KEY) @@ -21,7 +21,7 @@ def jadd_host(request): header_title, path1, path2 = u'添加主机 | Add Host', u'资产管理', u'添加主机' groups = [] eidc = IDC.objects.all() - egroup = BisGroup.objects.all() + egroup = BisGroup.objects.filter(type='A') eusergroup = UserGroup.objects.all() if request.method == 'POST': @@ -60,13 +60,39 @@ def jadd_host(request): login_type=j_type, idc=j_idc, is_active=int(j_active), comment=j_comment) + jasset_group_add(j_ip, j_ip, 'P') a.save() - print 'ok' a.bis_group = groups a.save() smg = u'主机 %s 添加成功' %j_ip return render_to_response('jasset/host_add.html', locals(), context_instance=RequestContext(request)) +def batch_host_edit(request): + if request.method == 'POST': + len_table = request.POST.get('len_table') + print len_table + for i in range(int(len_table)): + j_ip = "editable["+str(i)+"][j_ip]" + j_port = "editable["+str(i)+"][j_port]" + j_idc = "editable["+str(i)+"][j_idc]" + j_type = "editable["+str(i)+"][j_type]" + j_group = "editable["+str(i)+"][j_group]" + j_active = "editable["+str(i)+"][j_active]" + j_comment = "editable["+str(i)+"][j_comment]" + + j_ip = request.POST.get(j_ip).strip() + j_port = request.POST.get(j_port).strip() + j_idc = request.POST.get(j_idc).strip() + j_type = request.POST.get(j_type).strip() + j_group = request.POST.getlist(j_group) + j_active = request.POST.get(j_active).strip() + j_comment = request.POST.get(j_comment).strip() + print j_ip + + jasset_host_edit(j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment) + + return render_to_response('jasset/host_list.html') + def jlist_host(request): header_title, path1, path2 = u'查看主机 | List Host', u'资产管理', u'查看主机' @@ -87,7 +113,13 @@ def jlist_host(request): return render_to_response('jasset/host_list.html', locals(), context_instance=RequestContext(request)) def host_del(request, offset): - Asset.objects.filter(ip=str(offset)).delete() + len_list = request.POST.get("len_list") + for i in range(int(len_list)): + key = "id_list["+str(i)+"]" + print key + jid = request.POST.get(key) + print jid + Asset.objects.filter(id=jid).delete() return HttpResponseRedirect('/jasset/host_list/') def host_edit(request, offset): @@ -96,10 +128,10 @@ def host_edit(request, offset): header_title, path1, path2 = u'修改主机 | Edit Host', u'资产管理', u'修改主机' groups, e_group = [], [] eidc = IDC.objects.all() - egroup = BisGroup.objects.all() - for g in Asset.objects.get(ip=offset).bis_group.all(): + egroup = BisGroup.objects.filter(type='A') + for g in Asset.objects.get(id=int(offset)).bis_group.all(): e_group.append(g) - post = Asset.objects.get(ip = str(offset)) + post = Asset.objects.get(id = int(offset)) if request.method == 'POST': j_ip = request.POST.get('j_ip') j_idc = request.POST.get('j_idc') @@ -113,7 +145,7 @@ def host_edit(request, offset): c = BisGroup.objects.get(name=group) groups.append(c) - a = Asset.objects.get(ip=str(offset)) + a = Asset.objects.get(ip=int(offset)) if j_type == 'M': j_user = request.POST.get('j_user') @@ -180,24 +212,24 @@ def idc_del(request, offset): return HttpResponseRedirect('/jasset/idc_list/') def jadd_group(request): - header_title, path1, path2 = u'添加业务组 | Add Group', u'资产管理', u'添加业务组' + header_title, path1, path2 = u'添加主机组 | Add Group', u'资产管理', u'添加主机组' if request.method == 'POST': j_group = request.POST.get('j_group') j_comment = request.POST.get('j_comment') if BisGroup.objects.filter(name=j_group): - emg = u'该业务组已存在!' + emg = u'该主机组已存在!' return render_to_response('jasset/group_add.html', locals(), context_instance=RequestContext(request)) else: - smg = u'业务组%s添加成功' %j_group - BisGroup.objects.create(name=j_group, comment=j_comment) + smg = u'主机组%s添加成功' %j_group + BisGroup.objects.create(name=j_group, comment=j_comment, type='A') return render_to_response('jasset/group_add.html', locals(), context_instance=RequestContext(request)) def jlist_group(request): header_title, path1, path2 = u'查看业务组 | Add Group', u'资产管理', u'查看业务组' - posts = BisGroup.objects.all().order_by('id') + posts = BisGroup.objects.filter(type='A').order_by('id') return render_to_response('jasset/group_list.html', locals(), context_instance=RequestContext(request)) def group_del(request, offset): diff --git a/jumpserver/views.py b/jumpserver/views.py index ef9c9560c..57646eb5e 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -1,6 +1,6 @@ #coding: utf-8 - -from django.http import HttpResponse +from connect import PyCrypt, KEY +from jasset.models import Asset, BisGroup, IDC from django.shortcuts import render_to_response @@ -12,3 +12,43 @@ def skin_config(request): return render_to_response('skin_config.html') +def jasset_group_add(name, comment, type): + if BisGroup.objects.filter(name=name): + emg = u'该业务组已存在!' + else: + BisGroup.objects.create(name=name, comment=comment, type=type) + smg = u'业务组%s添加成功' %name + +def jasset_host_edit(j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment): + groups = [] + is_active = {u'是': '1', u'否': '2'} + login_types = {'LDAP': 'L', 'SSH_KEY': 'S', 'PASSWORD': 'P', 'MAP': 'M'} + for group in j_group: + c = BisGroup.objects.get(name=group.strip()) + groups.append(c) + j_type = login_types[j_type] + j_idc = IDC.objects.get(name=j_idc) + a = Asset.objects.get(ip=str(j_ip)) + + if j_type == 'M': + a.ip = j_ip + a.port = j_port + a.login_type = j_type + a.idc = j_idc + a.is_active = j_active + a.comment = j_comment + a.username_common = j_user + a.password_common = j_password + a.username_super = j_root + a.password_super = j_passwd + else: + a.ip = j_ip + a.port = j_port + a.idc = j_idc + a.login_type = j_type + a.is_active = is_active[j_active] + a.comment = j_comment + + a.save() + a.bis_group = groups + a.save() \ No newline at end of file diff --git a/logs/connect/20150128/halcyon_192.168.8.63_144102.log b/logs/connect/20150128/halcyon_192.168.8.63_144102.log new file mode 100644 index 000000000..0cc6f5ec2 --- /dev/null +++ b/logs/connect/20150128/halcyon_192.168.8.63_144102.log @@ -0,0 +1,13 @@ +Last login: Mon Jan 26 23:43:44 2015 from 192.168.8.59 +PS1='[\u@192.168.8.63 \W]\$ ' +clear;echo -e '\033[32mLogin 192.168.8.63 done. Enjoy it.\033[0m' +[halcyon@hadoop03 ~]$ PS1='[\u@192.168.8.63 \W]\$ ' +[halcyon@192.168.8.63 ~]$ clear;echo -e '\033[32mLogin 192.168.8.63 done. Enjoy it.\033[0m' +Login 192.168.8.63 done. Enjoy it. +[halcyon@192.168.8.63 ~]$ ll +total 0 +[halcyon@192.168.8.63 ~]$ ll +total 0 +[halcyon@192.168.8.63 ~]$ pwd +/home/halcyon +[halcyon@192.168.8.63 ~]$ \ No newline at end of file diff --git a/logs/connect/20150129/halcyon_192.168.8.63_151603.log b/logs/connect/20150129/halcyon_192.168.8.63_151603.log new file mode 100644 index 000000000..4aeaa5700 --- /dev/null +++ b/logs/connect/20150129/halcyon_192.168.8.63_151603.log @@ -0,0 +1,158 @@ +Last login: Wed Jan 28 22:40:12 2015 from 192.168.8.59 +PS1='[\u@192.168.8.63 \W]\$ ' +clear;echo -e '\033[32mLogin 192.168.8.63 done. Enjoy it.\033[0m' +[halcyon@hadoop03 ~]$ PS1='[\u@192.168.8.63 \W]\$ ' +[halcyon@192.168.8.63 ~]$ clear;echo -e '\033[32mLogin 192.168.8.63 done. Enjoy it.\033[0m' +Login 192.168.8.63 done. Enjoy it. +[halcyon@192.168.8.63 ~]$ ifconfig +eth1 Link encap:Ethernet HWaddr 00:0C:29:8E:55:19 + inet addr:192.168.8.63 Bcast:192.168.8.255 Mask:255.255.255.0 + inet6 addr: fe80::20c:29ff:fe8e:5519/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:4942926 errors:0 dropped:0 overruns:0 frame:0 + TX packets:11998 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:375187346 (357.8 MiB) TX bytes:2185924 (2.0 MiB) + +lo Link encap:Local Loopback + inet addr:127.0.0.1 Mask:255.0.0.0 + inet6 addr: ::1/128 Scope:Host + UP LOOPBACK RUNNING MTU:16436 Metric:1 + RX packets:1446 errors:0 dropped:0 overruns:0 frame:0 + TX packets:1446 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:78084 (76.2 KiB) TX bytes:78084 (76.2 KiB) + +[halcyon@192.168.8.63 ~]$ ll +total 0 +[halcyon@192.168.8.63 ~]$ pwd +/home/halcyon +[halcyon@192.168.8.63 ~]$ ll +total 0 +[halcyon@192.168.8.63 ~]$ ifconfig +eth1 Link encap:Ethernet HWaddr 00:0C:29:8E:55:19 + inet addr:192.168.8.63 Bcast:192.168.8.255 Mask:255.255.255.0 + inet6 addr: fe80::20c:29ff:fe8e:5519/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:4942977 errors:0 dropped:0 overruns:0 frame:0 + TX packets:12020 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:375191826 (357.8 MiB) TX bytes:2188600 (2.0 MiB) + +lo Link encap:Local Loopback + inet addr:127.0.0.1 Mask:255.0.0.0 + inet6 addr: ::1/128 Scope:Host + UP LOOPBACK RUNNING MTU:16436 Metric:1 + RX packets:1446 errors:0 dropped:0 overruns:0 frame:0 + TX packets:1446 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:78084 (76.2 KiB) TX bytes:78084 (76.2 KiB) + +[halcyon@192.168.8.63 ~]$ ifconfig +eth1 Link encap:Ethernet HWaddr 00:0C:29:8E:55:19 + inet addr:192.168.8.63 Bcast:192.168.8.255 Mask:255.255.255.0 + inet6 addr: fe80::20c:29ff:fe8e:5519/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:4942990 errors:0 dropped:0 overruns:0 frame:0 + TX packets:12027 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:375192932 (357.8 MiB) TX bytes:2189322 (2.0 MiB) + +lo Link encap:Local Loopback + inet addr:127.0.0.1 Mask:255.0.0.0 + inet6 addr: ::1/128 Scope:Host + UP LOOPBACK RUNNING MTU:16436 Metric:1 + RX packets:1446 errors:0 dropped:0 overruns:0 frame:0 + TX packets:1446 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:78084 (76.2 KiB) TX bytes:78084 (76.2 KiB) + +[halcyon@192.168.8.63 ~]$ ifconfig +eth1 Link encap:Ethernet HWaddr 00:0C:29:8E:55:19 + inet addr:192.168.8.63 Bcast:192.168.8.255 Mask:255.255.255.0 + inet6 addr: fe80::20c:29ff:fe8e:5519/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:4942999 errors:0 dropped:0 overruns:0 frame:0 + TX packets:12033 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:375193748 (357.8 MiB) TX bytes:2189926 (2.0 MiB) + +lo Link encap:Local Loopback + inet addr:127.0.0.1 Mask:255.0.0.0 + inet6 addr: ::1/128 Scope:Host + UP LOOPBACK RUNNING MTU:16436 Metric:1 + RX packets:1446 errors:0 dropped:0 overruns:0 frame:0 + TX packets:1446 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:78084 (76.2 KiB) TX bytes:78084 (76.2 KiB) + +[halcyon@192.168.8.63 ~]$ ifconfig +eth1 Link encap:Ethernet HWaddr 00:0C:29:8E:55:19 + inet addr:192.168.8.63 Bcast:192.168.8.255 Mask:255.255.255.0 + inet6 addr: fe80::20c:29ff:fe8e:5519/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:4943007 errors:0 dropped:0 overruns:0 frame:0 + TX packets:12039 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:375194484 (357.8 MiB) TX bytes:2190498 (2.0 MiB) + +lo Link encap:Local Loopback + inet addr:127.0.0.1 Mask:255.0.0.0 + inet6 addr: ::1/128 Scope:Host + UP LOOPBACK RUNNING MTU:16436 Metric:1 + RX packets:1446 errors:0 dropped:0 overruns:0 frame:0 + TX packets:1446 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:78084 (76.2 KiB) TX bytes:78084 (76.2 KiB) + +[halcyon@192.168.8.63 ~]$ ifconfig +eth1 Link encap:Ethernet HWaddr 00:0C:29:8E:55:19 + inet addr:192.168.8.63 Bcast:192.168.8.255 Mask:255.255.255.0 + inet6 addr: fe80::20c:29ff:fe8e:5519/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:4943015 errors:0 dropped:0 overruns:0 frame:0 + TX packets:12044 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:375195234 (357.8 MiB) TX bytes:2190984 (2.0 MiB) + +lo Link encap:Local Loopback + inet addr:127.0.0.1 Mask:255.0.0.0 + inet6 addr: ::1/128 Scope:Host + UP LOOPBACK RUNNING MTU:16436 Metric:1 + RX packets:1446 errors:0 dropped:0 overruns:0 frame:0 + TX packets:1446 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:78084 (76.2 KiB) TX bytes:78084 (76.2 KiB) + +[halcyon@192.168.8.63 ~]$ ifconfig +eth1 Link encap:Ethernet HWaddr 00:0C:29:8E:55:19 + inet addr:192.168.8.63 Bcast:192.168.8.255 Mask:255.255.255.0 + inet6 addr: fe80::20c:29ff:fe8e:5519/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:4945950 errors:0 dropped:0 overruns:0 frame:0 + TX packets:12071 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:375405180 (358.0 MiB) TX bytes:2192946 (2.0 MiB) + +lo Link encap:Local Loopback + inet addr:127.0.0.1 Mask:255.0.0.0 + inet6 addr: ::1/128 Scope:Host + UP LOOPBACK RUNNING MTU:16436 Metric:1 + RX packets:1448 errors:0 dropped:0 overruns:0 frame:0 + TX packets:1448 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:78192 (76.3 KiB) TX bytes:78192 (76.3 KiB) + +[halcyon@192.168.8.63 ~]$ ll +total 0 +[halcyon@192.168.8.63 ~]$ ll +total 0 +[halcyon@192.168.8.63 ~]$ pwd +/home/halcyon +[halcyon@192.168.8.63 ~]$ ll +total 0 +[halcyon@192.168.8.63 ~]$ ll +total 0 +[halcyon@192.168.8.63 ~]$ ll +total 0 +[halcyon@192.168.8.63 ~]$ \ No newline at end of file diff --git a/static/js/base.js b/static/js/base.js index e69de29bb..303b58964 100644 --- a/static/js/base.js +++ b/static/js/base.js @@ -0,0 +1,61 @@ +//jumpserver 自定义js 2015-01-29 + +//此函数用于checkbox的全选和反选 +var checked=false; +function check_all(form) { + var checkboxes = document.getElementById(form); + if (checked == false) { + checked = true + } else { + checked = false + } + for (var i = 0; i < checkboxes.elements.length; i++) { + if (checkboxes.elements[i].type == "checkbox") { + checkboxes.elements[i].checked = checked; + } + } +} + +//提取指定行的数据,JSON格式 +function GetRowData(row){ + var rowData = {}; + for(var j=0;j 0) { + possibleMove.focus(); + e.preventDefault(); + e.stopPropagation(); + } + } + }) + .on('input paste', function () { + var evt = $.Event('validate'); + active.trigger(evt, editor.val()); + if (evt.result === false) { + editor.addClass('error'); + } else { + editor.removeClass('error'); + } + }); + //element.on('click keypress dblclick', showEditor) + element.find("td:not([data-editable='false'])").on('click keypress dblclick', showEditor) + .css('cursor', 'pointer') + .keydown(function (e) { + var prevent = true, + possibleMove = movement($(e.target), e.which); + if (possibleMove.length > 0) { + possibleMove.focus(); + } else if (e.which === ENTER) { + showEditor(false); + } else if (e.which === 17 || e.which === 91 || e.which === 93) { + showEditor(true); + prevent = false; + } else { + prevent = false; + } + if (prevent) { + e.stopPropagation(); + e.preventDefault(); + } + }); + + //element.find('td').prop('tabindex', 1); + element.find("td:not([data-editable='false'])").prop('tabindex', 1); + + $(window).on('resize', function () { + if (editor.is(':visible')) { + editor.offset(active.offset()) + .width(active.width()) + .height(active.height()); + } + }); + }); + +}; +$.fn.editableTableWidget.defaultOptions = { + cloneProperties: ['padding', 'padding-top', 'padding-bottom', 'padding-left', 'padding-right', + 'text-align', 'font', 'font-size', 'font-family', 'font-weight', + 'border', 'border-top', 'border-bottom', 'border-left', 'border-right'], + editor: $('') +}; + diff --git a/templates/jasset/host_add.html b/templates/jasset/host_add.html index 224e0dc1f..4483ac57c 100644 --- a/templates/jasset/host_add.html +++ b/templates/jasset/host_add.html @@ -4,13 +4,13 @@
-
-
- 请选择添加内容: - 添加主机 - 添加IDC - 添加业务组 -
+
+ 请选择添加内容: + 添加主机 + 添加IDC + 添加业务组 +
+
填写主机基本信息
@@ -150,6 +150,18 @@ else{ document.getElementById("a1").style.display="none"; }}; + + function change(type){ + if (type == 'addhost') { + var data = $('#add_asset'); + } else if (type == 'addidc') { + var data = $('#addidc'); + } else { + var data = $('addgroup'); + } + $("#add_asset").html(data); + } + $('#assetForm').validator({ timely: 2, theme: "yellow_right_effect", diff --git a/templates/jasset/host_list.html b/templates/jasset/host_list.html index cc6707490..5d485a623 100644 --- a/templates/jasset/host_list.html +++ b/templates/jasset/host_list.html @@ -6,7 +6,7 @@
-
+
主机详细信息列表
@@ -33,39 +33,38 @@ 添加
- + +
- - + + - - + + - - + + + {% for post in contacts.object_list %} - - - - - - + + + + + + + - - + {% endfor %} @@ -73,9 +72,8 @@
IP地址 IP地址 端口号 登录方式 所属IDC 登录方式 所属IDC 所属业务组 添加时间 备注 是否激活 添加时间 备注 操作
{{ post.ip }} {{ post.port }} {{ login_types|get_item:post.login_type }} {{ post.idc.name }} - {% for group in post.bis_group.all %} - {{ group }} - {% endfor %} - {{ post.ip }} {{ post.port }} {{ login_types|get_item:post.login_type }} {{ post.idc.name }} {% for group in post.bis_group.all %} {{ group }} {% endfor %} {{ post.is_active|bool2str }} {{ post.date_added|date:"Y-m-d H:i:s" }} {{ post.comment }} + {{ post.comment }} 详情 - 编辑 - 删除 + 编辑 + 删除
-
- Showing {{ contacts.start_index }} to {{ contacts.end_index }} of {{ p.count }} entries -
+ +
@@ -99,6 +97,7 @@
+
@@ -108,7 +107,45 @@ {% endblock %} \ No newline at end of file diff --git a/templates/script.html b/templates/script.html index 7976a85c5..32e03f70c 100644 --- a/templates/script.html +++ b/templates/script.html @@ -4,6 +4,8 @@ + +