diff --git a/jasset/urls.py b/jasset/urls.py index bf108e16b..463d696bc 100644 --- a/jasset/urls.py +++ b/jasset/urls.py @@ -4,8 +4,10 @@ from jasset.views import * urlpatterns = patterns('', url(r'^$', index), - url(r'jadd', jadd), - url(r'jlist', jlist), - url(r'jadd_idc', jadd_idc), - url(r'jlist_idc', jlist_idc), + url(r'host_add', jadd_host), + url(r'host_list', jlist_host), + url(r'idc_add', jadd_idc), + url(r'idc_list', jlist_idc), + url(r'group_add', jadd_group), + url(r'group_list', jlist_group), ) \ No newline at end of file diff --git a/jasset/views.py b/jasset/views.py index 52a95d32e..cfcb1818b 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -5,9 +5,9 @@ from django.http import HttpResponse from django.template import RequestContext from django.shortcuts import render_to_response from django.http import HttpResponseRedirect -from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger +from django.core.paginator import Paginator, EmptyPage -from models import IDC, Asset, Group +from models import IDC, Asset, BisGroup from connect import PyCrypt, KEY @@ -15,14 +15,12 @@ def index(request): return render_to_response('jasset/jasset.html', ) -def jadd(request): - global j_passwd +def jadd_host(request): + header_title, path1, path2 = '添加主机 | Add Host', '资产管理', '添加主机' groups = [] cryptor = PyCrypt(KEY) eidc = IDC.objects.all() - egroup = Group.objects.all() - is_actived = {'active': 1, 'no_active': 0} - login_typed = {'LDAP': 'L', 'SSH_KEY': 'S', 'PASSWORD': 'P', 'MAP': 'M'} + egroup = BisGroup.objects.all() if request.method == 'POST': j_ip = request.POST.get('j_ip') @@ -32,27 +30,26 @@ def jadd(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) + 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)) + if j_type == 'MAP': 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')) - - j_idc = IDC.objects.get(name=j_idc) - for group in j_group: - c = Group.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', {'emg': emg, 'j_ip': j_ip}) - - elif j_type == 'MAP': a = Asset(ip=j_ip, port=j_port, - login_type=login_typed[j_type], + login_type=j_type, idc=j_idc, - is_active=int(is_actived[j_active]), + is_active=int(j_active), comment=j_comment, username_common=j_user, password_common=j_password, @@ -61,24 +58,19 @@ def jadd(request): else: a = Asset(ip=j_ip, port=j_port, - login_type=login_typed[j_type], + login_type=j_type, idc=j_idc, - is_active=int(is_actived[j_active]), + is_active=int(j_active), comment=j_comment) a.save() - a.group = groups + a.bis_group = groups a.save() - return render_to_response('jasset/jadd.html', - {'header_title': u'添加主机 | Add Host', - 'path1': '资产管理', - 'path2': '添加主机', - 'eidc': eidc, - 'egroup': egroup, } - ) + return render_to_response('jasset/jadd.html', locals(), context_instance=RequestContext(request)) -def jlist(request): +def jlist_host(request): + header_title, path1, path2 = '查看主机 | List Host', '资产管理', '查看主机' posts = contact_list = Asset.objects.all().order_by('ip') print posts paginator = Paginator(contact_list, 5) @@ -92,19 +84,49 @@ def jlist(request): except (EmptyPage, InvalidPage): contacts = paginator.page(paginator.num_pages) - return render_to_response('jasset/jlist.html', - {"contacts": contacts, - 'p': paginator, - 'posts': posts, - 'header_title': u'查看主机 | List Host', - 'path1': '资产管理', - 'path2': '查看主机', }, - context_instance=RequestContext(request)) + return render_to_response('jasset/jlist.html', locals(), context_instance=RequestContext(request)) def jadd_idc(request): - pass + header_title, path1, path2 = '添加IDC | Add IDC', '资产管理', '添加IDC' + if request.method == 'POST': + j_idc = request.POST.get('j_idc') + j_comment = request.POST.get('j_comment') + print j_idc,j_comment + + 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)) + else: + IDC.objects.create(name=j_idc, comment=j_comment) + + return render_to_response('jasset/jadd_idc.html', locals(), context_instance=RequestContext(request)) def jlist_idc(request): - pass \ No newline at end of file + header_title, path1, path2 = '查看IDC | List Host', '资产管理', '查看IDC' + posts = IDC.objects.all().order_by('id') + return render_to_response('jasset/jlist_idc.html', locals(), context_instance=RequestContext(request)) + + +def jadd_group(request): + header_title, path1, path2 = '添加业务组 | Add Group', '资产管理', '添加业务组' + 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)) + else: + BisGroup.objects.create(name=j_group, comment=j_comment) + + return render_to_response('jasset/jadd_group.html', locals(), context_instance=RequestContext(request)) + + +def jlist_group(request): + header_title, path1, path2 = '添加业务组 | Add Group', '资产管理', '查看业务组' + posts = BisGroup.objects.all().order_by('id') + return render_to_response('jasset/jlist_group.html', locals(), context_instance=RequestContext(request)) \ No newline at end of file diff --git a/jumpserver.conf b/jumpserver.conf index f54c84c15..1523fb3ba 100644 --- a/jumpserver.conf +++ b/jumpserver.conf @@ -8,10 +8,10 @@ password = mysql234 database = jumpserver [ldap] -host_url = ldap://127.0.0.1:389 -base_dn = dc=jumpserver,dc=org -root_dn = cn=admin,dc=jumpserver,dc=org -root_pw = secret234 +host_url = ldap://192.168.8.60:389 +base_dn = dc=fengxing,dc=org +root_dn = cn=admin,dc=fengxing,dc=org +root_pw = 123456 [web] key = 88aaaf7ffe3c6c04 diff --git a/templates/jasset/jadd.html b/templates/jasset/jadd.html index 6d3985beb..bae139d69 100644 --- a/templates/jasset/jadd.html +++ b/templates/jasset/jadd.html @@ -5,7 +5,13 @@
-
+
+ 请选择添加内容: + 添加主机 + 添加IDC + 添加业务组 +
+
填写主机基本信息
@@ -37,16 +43,16 @@
-
+
-
-
-
-
+
+
+
+
+ + + + + + + + {% endblock %} \ No newline at end of file diff --git a/templates/jasset/jadd_group.html b/templates/jasset/jadd_group.html new file mode 100644 index 000000000..179794ebb --- /dev/null +++ b/templates/jasset/jadd_group.html @@ -0,0 +1,106 @@ +{% extends 'base.html' %} +{% block content %} +{% include 'nav_cat_bar.html' %} +
+
+
+
+ + +
+ {% if emg %} +
{{ emg }}
+ {% endif %} +
+
+
+
+ +
+
+
+
+ +
+
+
+ + +
+
+
+
+
+
+
+
+ + + + + + + + + + + + + + +{% endblock %} \ No newline at end of file diff --git a/templates/jasset/jadd_idc.html b/templates/jasset/jadd_idc.html new file mode 100644 index 000000000..5a2b66f72 --- /dev/null +++ b/templates/jasset/jadd_idc.html @@ -0,0 +1,106 @@ +{% extends 'base.html' %} +{% block content %} +{% include 'nav_cat_bar.html' %} +
+
+
+
+
+
填写IDC基本信息
+ +
+ +
+ {% if emg %} +
{{ emg }}
+ {% endif %} +
+
+
+
+ +
+
+
+
+ +
+
+
+ + +
+
+
+
+
+
+
+
+ + + + + + + + + + + + + + +{% endblock %} \ No newline at end of file diff --git a/templates/jasset/jlist.html b/templates/jasset/jlist.html index 67ff7b909..5d1c3ed75 100644 --- a/templates/jasset/jlist.html +++ b/templates/jasset/jlist.html @@ -52,7 +52,7 @@ {{ post.login_type}} {{ post.idc.name }} - {% for group in post.group.all %} + {% for group in post.bis_group.all %} {{ group }} {% endfor %} diff --git a/templates/jasset/jlist_group.html b/templates/jasset/jlist_group.html new file mode 100644 index 000000000..182dd2b23 --- /dev/null +++ b/templates/jasset/jlist_group.html @@ -0,0 +1,59 @@ +{% extends 'base.html' %} +{% block content %} +{% include 'nav_cat_bar.html' %} + +
+
+
+
+
+
IDC详细信息列表
+ +
+ +
+ + + + + + + + + + + + {% for post in posts %} + + + + + + {% endfor %} + +
ID 机房名 备注
{{ post.id }} {{ post.name }} {{ post.comment }}
+
+
+
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/templates/jasset/jlist_idc.html b/templates/jasset/jlist_idc.html new file mode 100644 index 000000000..182dd2b23 --- /dev/null +++ b/templates/jasset/jlist_idc.html @@ -0,0 +1,59 @@ +{% extends 'base.html' %} +{% block content %} +{% include 'nav_cat_bar.html' %} + +
+
+
+
+
+
IDC详细信息列表
+ +
+ +
+ + + + + + + + + + + + {% for post in posts %} + + + + + + {% endfor %} + +
ID 机房名 备注
{{ post.id }} {{ post.name }} {{ post.comment }}
+
+
+
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/templates/nav.html b/templates/nav.html index 32d3b3165..0b830731d 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -23,10 +23,12 @@
  • 资产管理
  • diff --git a/templates/script.html b/templates/script.html index 490d4eb88..da70b090e 100644 --- a/templates/script.html +++ b/templates/script.html @@ -17,12 +17,12 @@ - +