diff --git a/jasset/urls.py b/jasset/urls.py index e60b47f71..280ed090c 100644 --- a/jasset/urls.py +++ b/jasset/urls.py @@ -4,11 +4,16 @@ from jasset.views import * urlpatterns = patterns('', url(r'^$', index), - url(r'host_add/$', jadd_host), - url(r'host_list/$', jlist_host), - url(r"(\d+.\d+.\d+.\d+)/$",jlist_ip), - url(r'idc_add/$', jadd_idc), - url(r'idc_list/$', jlist_idc), - url(r'group_add/$', jadd_group), - url(r'group_list/$', jlist_group), + url(r'^host_add/$', jadd_host), + url(r'^host_list/$', jlist_host), + url(r"^(\d+.\d+.\d+.\d+)/$",jlist_ip), + url(r'^idc_add/$', jadd_idc), + url(r'^idc_list/$', jlist_idc), + url(r'^idc_del/(\d+)/$', idc_del), + 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'^test/$', test), ) \ No newline at end of file diff --git a/jasset/views.py b/jasset/views.py index 8472d3d3f..02f887b69 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -1,26 +1,25 @@ # coding:utf-8 +from django.http import HttpResponseRedirect from django.template import RequestContext from django.shortcuts import render_to_response from django.core.paginator import Paginator, EmptyPage from models import IDC, Asset, BisGroup -from models import IDC, Asset, UserGroup from connect import PyCrypt, KEY +cryptor = PyCrypt(KEY) + def index(request): return render_to_response('jasset/jasset.html', ) def jadd_host(request): - header_title, path1, path2 = '添加主机 | Add Host', '资产管理', '添加主机' + login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'} + header_title, path1, path2 = u'添加主机 | Add Host', u'资产管理', u'添加主机' groups = [] - cryptor = PyCrypt(KEY) eidc = IDC.objects.all() egroup = BisGroup.objects.all() - egroup = UserGroup.objects.all() - is_actived = {'active': 1, 'no_active': 0} - login_typed = {'LDAP': 'L', 'SSH_KEY': 'S', 'PASSWORD': 'P', 'MAP': 'M'} if request.method == 'POST': j_ip = request.POST.get('j_ip') @@ -30,26 +29,23 @@ def jadd_host(request): j_group = request.POST.getlist('j_group') j_active = request.POST.get('j_active') j_comment = request.POST.get('j_comment') - j_idc = IDC.objects.get(name=j_idc) + for group in j_group: c = BisGroup.objects.get(name=group) - c = UserGroup.objects.get(name=group) groups.append(c) if Asset.objects.filter(ip=str(j_ip)): emg = u'该IP已存在!' - return render_to_response('jasset/jadd.html', locals(), context_instance=RequestContext(request)) + return render_to_response('jasset/host_add.html', locals(), context_instance=RequestContext(request)) - if j_type == 'MAP': + if j_type == 'M': j_user = request.POST.get('j_user') j_password = cryptor.encrypt(request.POST.get('j_password')) j_root = request.POST.get('j_root') j_passwd = cryptor.encrypt(request.POST.get('j_passwd')) - a = Asset(ip=j_ip, - port=j_port, - login_type=j_type, - idc=j_idc, + a = Asset(ip=j_ip, port=j_port, + login_type=j_type, idc=j_idc, is_active=int(j_active), comment=j_comment, username_common=j_user, @@ -57,21 +53,21 @@ def jadd_host(request): username_super=j_root, password_super=j_passwd,) else: - a = Asset(ip=j_ip, - port=j_port, - login_type=j_type, - idc=j_idc, + a = Asset(ip=j_ip, port=j_port, + login_type=j_type, idc=j_idc, is_active=int(j_active), comment=j_comment) a.save() + print 'ok' a.bis_group = groups a.save() - - return render_to_response('jasset/jadd.html', locals(), context_instance=RequestContext(request)) + smg = u'主机 %s 添加成功' %j_ip + return render_to_response('jasset/host_add.html', locals(), context_instance=RequestContext(request)) def jlist_host(request): - header_title, path1, path2 = '查看主机 | List Host', '资产管理', '查看主机' + header_title, path1, path2 = u'查看主机 | List Host', u'资产管理', u'查看主机' + login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'} posts = contact_list = Asset.objects.all().order_by('ip') print posts p = paginator = Paginator(contact_list, 5) @@ -85,16 +81,77 @@ def jlist_host(request): except (EmptyPage, InvalidPage): contacts = paginator.page(paginator.num_pages) - return render_to_response('jasset/jlist.html', locals(), context_instance=RequestContext(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() + return HttpResponseRedirect('/jasset/host_list/') + +def host_edit(request, offset): + actives = {1: u'激活', 0: u'禁用'} + login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'} + 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(): + e_group.append(g) + post = Asset.objects.get(ip = str(offset)) + if request.method == 'POST': + j_ip = request.POST.get('j_ip') + j_idc = request.POST.get('j_idc') + j_port = request.POST.get('j_port') + j_type = request.POST.get('j_type') + j_group = request.POST.getlist('j_group') + j_active = request.POST.get('j_active') + j_comment = request.POST.get('j_comment') + j_idc = IDC.objects.get(name=j_idc) + for group in j_group: + c = BisGroup.objects.get(name=group) + groups.append(c) + + a = Asset.objects.get(ip=str(offset)) + + if j_type == 'M': + j_user = request.POST.get('j_user') + j_password = cryptor.encrypt(request.POST.get('j_password')) + j_root = request.POST.get('j_root') + j_passwd = cryptor.encrypt(request.POST.get('j_passwd')) + 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 = j_active + a.comment = j_comment + + a.save() + a.bis_group = groups + a.save() + smg = u'主机 %s 修改成功' %j_ip + return HttpResponseRedirect('/jasset/host_list') + + return render_to_response('jasset/host_edit.html', locals(), context_instance=RequestContext(request)) + def jlist_ip(request, offset): - header_title, path1, path2 = '主机详细信息 | Host Detail.', '资产管理', '主机详情' + header_title, path1, path2 = u'主机详细信息 | Host Detail.', u'资产管理', u'主机详情' print offset post = contact_list = Asset.objects.get(ip = str(offset)) return render_to_response('jasset/jlist_ip.html', locals(), context_instance=RequestContext(request)) def jadd_idc(request): - header_title, path1, path2 = '添加IDC | Add IDC', '资产管理', '添加IDC' + header_title, path1, path2 = u'添加IDC | Add IDC', u'资产管理', u'添加IDC' if request.method == 'POST': j_idc = request.POST.get('j_idc') j_comment = request.POST.get('j_comment') @@ -102,37 +159,47 @@ def jadd_idc(request): if IDC.objects.filter(name=j_idc): emg = u'该IDC已存在!' - return render_to_response('jasset/jadd_idc.html', - {'emg': emg, 'j_idc': j_idc, 'j_comment': j_comment,}, - context_instance=RequestContext(request)) + return render_to_response('jasset/idc_add.html', locals(), context_instance=RequestContext(request)) else: + smg = u'IDC:%s添加成功' %j_idc IDC.objects.create(name=j_idc, comment=j_comment) - return render_to_response('jasset/jadd_idc.html', locals(), context_instance=RequestContext(request)) + return render_to_response('jasset/idc_add.html', locals(), context_instance=RequestContext(request)) def jlist_idc(request): - header_title, path1, path2 = '查看IDC | List Host', '资产管理', '查看IDC' + header_title, path1, path2 = u'查看IDC | List Host', u'资产管理', u'查看IDC' posts = IDC.objects.all().order_by('id') - return render_to_response('jasset/jlist_idc.html', locals(), context_instance=RequestContext(request)) + return render_to_response('jasset/idc_list.html', locals(), context_instance=RequestContext(request)) +def idc_del(request, offset): + IDC.objects.filter(id=offset).delete() + return HttpResponseRedirect('/jasset/idc_list/') def jadd_group(request): - header_title, path1, path2 = '添加业务组 | Add Group', '资产管理', '添加业务组' + 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'该业务组已存在!' - return render_to_response('jasset/jadd_group.html', locals(), context_instance=RequestContext(request)) + 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) - return render_to_response('jasset/jadd_group.html', locals(), context_instance=RequestContext(request)) + return render_to_response('jasset/group_add.html', locals(), context_instance=RequestContext(request)) def jlist_group(request): - header_title, path1, path2 = '添加业务组 | Add Group', '资产管理', '查看业务组' + header_title, path1, path2 = u'查看业务组 | Add Group', u'资产管理', u'查看业务组' posts = BisGroup.objects.all().order_by('id') - return render_to_response('jasset/jlist_group.html', locals(), context_instance=RequestContext(request)) + return render_to_response('jasset/group_list.html', locals(), context_instance=RequestContext(request)) + +def group_del(request, offset): + BisGroup.objects.filter(id=offset).delete() + return HttpResponseRedirect('/jasset/group_list/') + +def test(request): + return render_to_response('jasset/test.html', locals()) \ No newline at end of file diff --git a/jumpserver/templatetags/mytags.py b/jumpserver/templatetags/mytags.py index 3ef015a5c..19224af43 100644 --- a/jumpserver/templatetags/mytags.py +++ b/jumpserver/templatetags/mytags.py @@ -15,3 +15,7 @@ def stamp2str(value): @register.filter(name='int2str') def int2str(value): return str(value) + +@register.filter(name='get_item') +def get_item(dictionary, key): + return dictionary.get(key) diff --git a/juser/views.py b/juser/views.py index 09e262b2c..8387e5914 100644 --- a/juser/views.py +++ b/juser/views.py @@ -158,7 +158,6 @@ def user_list(request): def db_add_user(**kwargs): groups_post = kwargs.pop('groups') user = User(**kwargs) - group_select = [] for group_id in groups_post: group = UserGroup.objects.filter(id=group_id) group_select.extend(group) diff --git a/templates/jasset/jadd_group.html b/templates/jasset/group_add.html similarity index 60% rename from templates/jasset/jadd_group.html rename to templates/jasset/group_add.html index 179794ebb..f610d740f 100644 --- a/templates/jasset/jadd_group.html +++ b/templates/jasset/group_add.html @@ -30,14 +30,17 @@ {% if emg %}
{{ emg }}
{% endif %} -
+ {% if smg %} +
{{ smg }}
+ {% endif %} +
-
+
-
+
@@ -54,52 +57,23 @@ - - - - - - - - - - - diff --git a/templates/jasset/jlist_idc.html b/templates/jasset/group_list.html similarity index 62% rename from templates/jasset/jlist_idc.html rename to templates/jasset/group_list.html index 182dd2b23..8f707d213 100644 --- a/templates/jasset/jlist_idc.html +++ b/templates/jasset/group_list.html @@ -29,23 +29,29 @@
- 添加 + 添加
- - - + + + + {% for post in posts %} - - - + + + + {% endfor %} diff --git a/templates/jasset/jadd.html b/templates/jasset/host_add.html similarity index 70% rename from templates/jasset/jadd.html rename to templates/jasset/host_add.html index 1ba125809..24ee3a98e 100644 --- a/templates/jasset/jadd.html +++ b/templates/jasset/host_add.html @@ -32,53 +32,55 @@ -
+
{% if emg %}
{{ emg }}
{% endif %} - + {% if smg %} +
{{ smg }}
+ {% endif %} +
-
+
-
+
-
-
-
-
+
+
+
+
-
@@ -111,13 +113,13 @@
-
+
- +
@@ -129,79 +131,71 @@
+ +{% endblock %} \ No newline at end of file diff --git a/templates/jasset/jlist.html b/templates/jasset/host_list.html similarity index 60% rename from templates/jasset/jlist.html rename to templates/jasset/host_list.html index 7798b3a2a..eae48d9e4 100644 --- a/templates/jasset/jlist.html +++ b/templates/jasset/host_list.html @@ -1,10 +1,11 @@ {% extends 'base.html' %} +{% load mytags %} {% block content %} {% include 'nav_cat_bar.html' %}
-
+
主机详细信息列表
@@ -29,35 +30,43 @@
ID 机房名 备注 ID 机房名 备注 操作
{{ post.id }} {{ post.name }} {{ post.comment }} {{ post.id }} {{ post.name }} {{ post.comment }} + 详情 + 编辑 + 删除 +
- - - - - - - + + + + + + + + + {% for post in contacts.object_list %} - - - - - + + + + + - - + + + {% endfor %} diff --git a/templates/jasset/jadd_idc.html b/templates/jasset/idc_add.html similarity index 64% rename from templates/jasset/jadd_idc.html rename to templates/jasset/idc_add.html index 5a2b66f72..32ba1e8b8 100644 --- a/templates/jasset/jadd_idc.html +++ b/templates/jasset/idc_add.html @@ -30,7 +30,10 @@ {% if emg %}
{{ emg }}
{% endif %} - + {% if smg %} +
{{ smg }}
+ {% endif %} +
@@ -44,7 +47,7 @@
- +
@@ -54,53 +57,23 @@ - - - - - - - - - - - {% endblock %} \ No newline at end of file diff --git a/templates/jasset/jlist_group.html b/templates/jasset/idc_list.html similarity index 62% rename from templates/jasset/jlist_group.html rename to templates/jasset/idc_list.html index 182dd2b23..05087e030 100644 --- a/templates/jasset/jlist_group.html +++ b/templates/jasset/idc_list.html @@ -29,23 +29,29 @@
IP地址 端口号 登录方式 所属IDC 所属业务组 添加时间 备注 IP地址 端口号 登录方式 所属IDC 所属业务组 添加时间 备注 操作
{{ post.ip }} {{ post.port }} {{ post.get_login_type}} {{ post.idc.name }} + {{ post.ip }} {{ post.port }} {{ login_types|get_item:post.login_type }} {{ post.idc.name }} {% for group in post.bis_group.all %} {{ group }} {% endfor %} {{ post.date_added }} {{ post.comment }} {{ post.date_added }} {{ post.comment }} + 详情 + 编辑 + 删除 +
- - - + + + + {% for post in posts %} - - - + + + + {% endfor %} diff --git a/templates/jasset/test.html b/templates/jasset/test.html new file mode 100644 index 000000000..6ece5b502 --- /dev/null +++ b/templates/jasset/test.html @@ -0,0 +1,30 @@ + + +
+
+
全名
+
+ +
+
+
+
电子邮件地址
+
+ +
+
+
+
创建密码
+
+ +
+
+
+
选择你的用户名
+
+ +
+
+
+ + \ No newline at end of file
ID 机房名 备注 ID 机房名 备注 操作
{{ post.id }} {{ post.name }} {{ post.comment }} {{ post.id }} {{ post.name }} {{ post.comment }} + 详情 + 编辑 + 删除 +