From 95bb96ebbf18a5164e88b95ab89357e549527334 Mon Sep 17 00:00:00 2001 From: halcyon <864072399@qq.com> Date: Sat, 7 Mar 2015 18:37:23 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=90=84=E7=A7=8Dbug=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jasset/urls.py | 4 ++-- jasset/views.py | 24 +++++++++++++++++++--- templates/jasset/group_list.html | 34 +++++++++++++++++++++++++++++-- templates/jasset/host_list.html | 8 +++++++- templates/jasset/host_search.html | 33 +----------------------------- templates/jasset/idc_list.html | 34 ++++++++++++++++++++++++++++++- templates/jlog/log_offline.html | 6 +++++- templates/jlog/log_online.html | 6 +++++- 8 files changed, 106 insertions(+), 43 deletions(-) diff --git a/jasset/urls.py b/jasset/urls.py index 386538a74..602ed6a69 100644 --- a/jasset/urls.py +++ b/jasset/urls.py @@ -12,13 +12,13 @@ urlpatterns = patterns('', url(r'^idc_add/$', add_idc), url(r'^idc_list/$', list_idc), url(r'^idc_detail/$', detail_idc), - url(r'^idc_del/(\d+)/$', del_idc), + url(r'^idc_del/(\w+)/$', del_idc), url(r'^jgroup_add/$', add_group), url(r'^group_edit/$', edit_group), url(r'^jgroup_list/$', list_group), url(r'^group_detail/$', detail_group), url(r'^group_del_host/(\w+)/$', group_del_host), - url(r'^group_del/(\d+)/$', group_del), + url(r'^group_del/(\w+)/$', group_del), url(r'^host_del/(\w+)/$', host_del), url(r'^host_edit/$', host_edit), url(r'^host_edit/batch/$', batch_host_edit), diff --git a/jasset/views.py b/jasset/views.py index 757c9770c..2b8b4bbda 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -251,7 +251,15 @@ def list_idc(request): def del_idc(request, offset): - IDC.objects.filter(id=offset).delete() + if offset == 'multi': + len_list = request.POST.get("len_list") + for i in range(int(len_list)): + key = "id_list[" + str(i) + "]" + gid = request.POST.get(key) + IDC.objects.filter(id=gid).delete() + else: + gid = int(offset) + IDC.objects.filter(id=gid).delete() return HttpResponseRedirect('/jasset/idc_list/') @@ -354,8 +362,18 @@ def group_del_host(request, offset): def group_del(request, offset): - BisGroup.objects.filter(id=offset).delete() - return HttpResponseRedirect('/jasset/group_list/') + if offset == 'multi': + len_list = request.POST.get("len_list") + for i in range(int(len_list)): + key = "id_list[" + str(i) + "]" + gid = request.POST.get(key) + BisGroup.objects.filter(id=gid).delete() + else: + gid = int(offset) + BisGroup.objects.filter(id=gid).delete() + return HttpResponseRedirect('/jasset/jgroup_list/') + + def host_search(request): diff --git a/templates/jasset/group_list.html b/templates/jasset/group_list.html index b427266ca..a9e62dc17 100644 --- a/templates/jasset/group_list.html +++ b/templates/jasset/group_list.html @@ -38,7 +38,13 @@ {% endfor %} - {% include 'paginator.html' %} +
+
+ + +
+ {% include 'paginator.html' %} +
@@ -46,4 +52,28 @@ -{% endblock %} \ No newline at end of file + + +{% endblock %} diff --git a/templates/jasset/host_list.html b/templates/jasset/host_list.html index 4f24879c6..5638342d8 100644 --- a/templates/jasset/host_list.html +++ b/templates/jasset/host_list.html @@ -81,7 +81,13 @@ {% endfor %} - {% include 'paginator.html' %} +
+
+ + +
+ {% include 'paginator.html' %} +
diff --git a/templates/jasset/host_search.html b/templates/jasset/host_search.html index 2c9652926..11fe6ce14 100644 --- a/templates/jasset/host_search.html +++ b/templates/jasset/host_search.html @@ -40,38 +40,7 @@ -
-
- -
-
+ {% include 'paginator.html' %} + {% endblock %} \ No newline at end of file diff --git a/templates/jlog/log_offline.html b/templates/jlog/log_offline.html index abd621ac0..914eb04a5 100644 --- a/templates/jlog/log_offline.html +++ b/templates/jlog/log_offline.html @@ -96,7 +96,11 @@ {% endfor %} - {% include 'paginator.html' %} +
+
+
+ {% include 'paginator.html' %} +
diff --git a/templates/jlog/log_online.html b/templates/jlog/log_online.html index 582d08433..a5833c9c6 100644 --- a/templates/jlog/log_online.html +++ b/templates/jlog/log_online.html @@ -96,7 +96,11 @@ {% endfor %} - {% include 'paginator.html' %} +
+
+
+ {% include 'paginator.html' %} +
From d72d55c9653303511c4148fbde18fb3e4cc1799a Mon Sep 17 00:00:00 2001 From: guanghongwei Date: Sun, 8 Mar 2015 22:48:50 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B2=A1=E6=80=8E=E4=B9=88=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jumpserver.conf | 2 +- templates/jasset/host_list.html | 2 +- templates/juser/group_edit.html | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jumpserver.conf b/jumpserver.conf index 9540fa014..a24c2190a 100644 --- a/jumpserver.conf +++ b/jumpserver.conf @@ -8,7 +8,7 @@ password = mysql234 database = jumpserver [ldap] -ldap_enable = 0 +ldap_enable = 1 host_url = ldap://127.0.0.1:389 base_dn = dc=jumpserver, dc=org root_dn = cn=admin,dc=jumpserver,dc=org diff --git a/templates/jasset/host_list.html b/templates/jasset/host_list.html index 5638342d8..805b03c72 100644 --- a/templates/jasset/host_list.html +++ b/templates/jasset/host_list.html @@ -68,7 +68,7 @@ {{ post.port }} {{ login_types|get_item:post.login_type }} {{ post.idc.name }} - {% for group in post.bis_group.all|filter_private %} {{ group }} {% endfor %} + {{ post.bis_group.all | group_str2}} {{ post.is_active|bool2str }} {{ post.date_added|date:"Y-m-d H:i:s" }} {{ post.comment }} diff --git a/templates/juser/group_edit.html b/templates/juser/group_edit.html index 9f9b724c1..e565fc5b2 100644 --- a/templates/juser/group_edit.html +++ b/templates/juser/group_edit.html @@ -37,7 +37,7 @@
- +
From 5c54128f8d5b45627109712b704d66e623b19622 Mon Sep 17 00:00:00 2001 From: guanghongwei Date: Wed, 11 Mar 2015 10:18:20 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BE=88=E5=A4=9A?= =?UTF-8?q?=E5=86=85=E5=AE=B9,=E4=BD=86=E4=B8=8D=E6=89=93=E7=AE=97?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/AddUserAsset.py | 13 +++-- jperm/models.py | 29 +++++++--- jperm/views.py | 2 + jumpserver/views.py | 17 +++++- templates/filter_ajax_api.html | 9 ++++ templates/jperm/perm_add.html | 97 ++++++++++++++++++++++++++++------ 6 files changed, 137 insertions(+), 30 deletions(-) create mode 100644 templates/filter_ajax_api.html diff --git a/docs/AddUserAsset.py b/docs/AddUserAsset.py index b1750caf6..8ae015568 100644 --- a/docs/AddUserAsset.py +++ b/docs/AddUserAsset.py @@ -108,14 +108,13 @@ def test_add_log(): if __name__ == '__main__': + # test_add_dept() + # test_add_group() + # test_add_user() + # test_add_idc() + # test_add_asset_group() test_add_asset() - test_add_dept() - test_add_group() - test_add_user() - test_add_idc() - test_add_asset_group() - test_add_asset() - test_add_log() + # test_add_log() diff --git a/jperm/models.py b/jperm/models.py index bfc2bbf6e..6aca0ff4f 100644 --- a/jperm/models.py +++ b/jperm/models.py @@ -1,16 +1,31 @@ from django.db import models -from juser.models import UserGroup -from jasset.models import BisGroup +from juser.models import User, UserGroup, DEPT +from jasset.models import Asset, BisGroup class Perm(models.Model): - name = models.CharField(max_length=100) - user_group = models.ManyToManyField(UserGroup) - asset_group = models.ManyToManyField(BisGroup) - comment = models.CharField(max_length=100) + user = models.ForeignKey(User) + asset = models.ForeignKey(Asset) def __unicode__(self): - return '%s_%s' % (self.user_group.name, self.asset_group.name) + return '%s_%s' % (self.user.name, self.asset.ip) + + +class DeptPerm(models.Model): + dept = models.ForeignKey(DEPT) + asset = models.ForeignKey(Asset) + + def __unicode__(self): + return '%s_%s' % (self.dept.name, self.asset.ip) + + +class ShowPerm(models.Model): + uid = models.CharField(max_length=500, blank=True, null=True) + gid = models.CharField(max_length=500, blank=True, null=True) + did = models.CharField(max_length=500, blank=True, null=True) + aid = models.CharField(max_length=500, blank=True, null=True) + bid = models.CharField(max_length=500, blank=True, null=True) + comment = models.CharField(max_length=200, blank=True, null=True) class CmdGroup(models.Model): diff --git a/jperm/views.py b/jperm/views.py index ee91942f4..4cfe98aca 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -42,6 +42,8 @@ def perm_add(request): if request.method == 'GET': user_groups = UserGroup.objects.filter(id__gt=2) asset_groups = BisGroup.objects.all() + users = User.objects.all() + assets = Asset.objects.all() else: name = request.POST.get('name', '') diff --git a/jumpserver/views.py b/jumpserver/views.py index 09afd48fa..3a114ad57 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -18,7 +18,7 @@ from django.template import RequestContext from django.core.paginator import Paginator, EmptyPage, InvalidPage from django.template import RequestContext -from juser.models import User +from juser.models import User, UserGroup from jlog.models import Log from jasset.models import Asset, BisGroup, IDC @@ -301,6 +301,21 @@ class PyCrypt(object): return plain_text.rstrip('\0') +def filter_ajax_api(request): + attr = request.GET.get('attr', 'user') + value = request.GET.get('value', '') + if attr == 'user': + contact_list = User.objects.filter(name__icontains=value) + elif attr == "user_group": + contact_list = UserGroup.objects.filter(name__icontains=value) + elif attr == "asset": + contact_list = Asset.objects.filter(ip__icontains=value) + elif attr == "asset": + contact_list = BisGroup.objects.filter(name__icontains=value) + + return render_to_response('filter_ajax_api.html', locals()) + + # def perm_user_asset(user_id=None, username=None): # if user_id: # user = User.objects.get(id=user_id) diff --git a/templates/filter_ajax_api.html b/templates/filter_ajax_api.html new file mode 100644 index 000000000..0698300a9 --- /dev/null +++ b/templates/filter_ajax_api.html @@ -0,0 +1,9 @@ +{% for object in contact_list %} + {% ifequal attr "asset" %} + + {% else %} + + {% endifequal %} + + +{% endfor %} \ No newline at end of file diff --git a/templates/jperm/perm_add.html b/templates/jperm/perm_add.html index e65f960b3..464181d92 100644 --- a/templates/jperm/perm_add.html +++ b/templates/jperm/perm_add.html @@ -36,23 +36,45 @@ {% if msg %}
{{ msg }}
{% endif %} + + + + + + + + +
-
- -
- - 取个名字方便辨识 -
-
-
- +
- {% for user_group in user_groups %} - + {% endfor %}
@@ -68,7 +90,7 @@
-
@@ -77,10 +99,23 @@
- + +
+ +
+
+
+
- {% for asset_group in asset_groups %} {% endfor %} @@ -97,7 +132,7 @@
-
@@ -168,6 +203,38 @@ $(document).ready(function(){ }) }) }) + +function userChoice(value){ + if (value == "1"){ + $("#user_groups").children().each(function(){$(this).remove()}); + $("#user_groups_select").children().each(function(){$(this).remove()}); + $("#user_group_all").children().each(function(){ + $("#user_groups").append($(this).clone()) + }) + } + else + $("#user_groups").children().each(function(){$(this).remove()}); + $("#user_groups_select").children().each(function(){$(this).remove()}); + $("#user_all").children().each(function(){ + $("#user_groups").append($(this).clone()) + }) +} + +function assetChoice(value){ + if (value == "1"){ + $("#asset_groups").children().each(function(){$(this).remove()}); + $("#asset_groups_select").children().each(function(){$(this).remove()}); + $("#asset_group_all").children().each(function(){ + $("#asset_groups").append($(this).clone()) + }) + } + else + $("#asset_groups").children().each(function(){$(this).remove()}); + $("#asset_groups_select").children().each(function(){$(this).remove()}); + $("#asset_all").children().each(function(){ + $("#asset_groups").append($(this).clone()) + }) +} {% endblock %} \ No newline at end of file