From 6ae4907520f18d1cce2e7aafc6cf82829a6ff61b Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Sat, 21 Nov 2015 21:24:01 +0800 Subject: [PATCH 1/4] update --- juser/urls.py | 2 ++ juser/views.py | 7 ++++++- templates/nav.html | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/juser/urls.py b/juser/urls.py index 9764c01ce..bfd3a6270 100644 --- a/juser/urls.py +++ b/juser/urls.py @@ -28,4 +28,6 @@ urlpatterns = patterns('juser.views', (r'^change_role/$', 'chg_role'), (r'^regen_ssh_key/$', 'regen_ssh_key'), (r'^down_key/$', 'down_key'), + + (r'runcommand/$', 'RunCommand'), ) diff --git a/juser/views.py b/juser/views.py index 84f39954b..59f542729 100644 --- a/juser/views.py +++ b/juser/views.py @@ -487,4 +487,9 @@ def down_key(request): response['Content-Disposition'] = 'attachment; filename=%s' % os.path.basename(private_key_file) return response - return HttpResponse('No Key File. Contact Admin.') \ No newline at end of file + return HttpResponse('No Key File. Contact Admin.') +from jperm.perm_api import get_group_user_perm +def RunCommand(request): + if request.method == 'GET': + print + return render_to_response('juser/run_command.html', locals(), context_instance=RequestContext(request)) \ No newline at end of file diff --git a/templates/nav.html b/templates/nav.html index c5d46fb54..d45ea0ea6 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -128,6 +128,9 @@
  • 申请记录
  • +
  • + 批量执行命令 +
  • 登录历史
  • From 246e8770accfa55331f37b453f6853dfcea3f25a Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Sat, 21 Nov 2015 22:40:28 +0800 Subject: [PATCH 2/4] http://localhost:8000/juser/user_detail/?id=5001 fix --- juser/views.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/juser/views.py b/juser/views.py index 59f542729..6ddbac281 100644 --- a/juser/views.py +++ b/juser/views.py @@ -238,10 +238,10 @@ def user_detail(request): # user, dept = get_session_user_dept(request) # if not validate(request, user=[user_id]): # return HttpResponseRedirect('/') - # if not user_id: - # return HttpResponseRedirect('/juser/user_list/') - - # user = get_object(User, id=user_id) + user_id = request.GET.get('id', '') + if not user_id: + return HttpResponseRedirect('/juser/user_list/') + user = User.objects.get(id=user_id) # if user: # pass # asset_group_permed = user.get_asset_group() @@ -491,5 +491,5 @@ def down_key(request): from jperm.perm_api import get_group_user_perm def RunCommand(request): if request.method == 'GET': - print + print get_group_user_perm(request.user) return render_to_response('juser/run_command.html', locals(), context_instance=RequestContext(request)) \ No newline at end of file From 09de12c02a4b4c88e0a629735ae1953d03ef1af6 Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Sun, 22 Nov 2015 13:04:11 +0800 Subject: [PATCH 3/4] index show assets, need discussion --- jumpserver/views.py | 13 +++- juser/views.py | 2 +- templates/index_cu.html | 151 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 153 insertions(+), 13 deletions(-) diff --git a/jumpserver/views.py b/jumpserver/views.py index 57ae3f5dd..a99ec4f56 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -16,7 +16,7 @@ from jumpserver.models import Setting from django.contrib.auth import authenticate, login, logout from django.contrib.auth.decorators import login_required from jlog.models import Log - +from jperm.perm_api import get_group_user_perm def getDaysByNum(num): """ @@ -80,6 +80,17 @@ def index_cu(request): login_types = {'L': 'LDAP', 'M': 'MAP'} username = request.user.username # TODO: need fix,liuzheng need Asset help + asset = get_group_user_perm(request.user) + print asset + assets = asset.get('asset') + # idc = [] + # for i in assets: + # idc.append(i.idc.id) + # idc_all = IDC.objects.filter(id__in=idc) + idc_all = [] + for i in assets: + idc_all.append(i.idc) + asset_group_all = asset.get('asset_group') # posts = Asset.object.all() # host_count = len(posts) # diff --git a/juser/views.py b/juser/views.py index 6ddbac281..e0a318433 100644 --- a/juser/views.py +++ b/juser/views.py @@ -12,7 +12,7 @@ from juser.user_api import * MAIL_FROM = EMAIL_HOST_USER - +@login_required(login_url='/login') def chg_role(request): role = {'SU': 2, 'GA': 1, 'CU': 0} if request.session['role_id'] > 0: diff --git a/templates/index_cu.html b/templates/index_cu.html index 3edb68a75..bfc8ef030 100644 --- a/templates/index_cu.html +++ b/templates/index_cu.html @@ -53,18 +53,147 @@
    - - {% for host_five in new_posts %} - - {% for host in host_five %} - + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    +
    +
    + + + +
    + + +
    +
    +
    + +
    +
    {{ host.ip }}
    + + + + + + + + {# #} + + + + + + + {% for asset in assets %} + + + + + + + {# #} + + + + {% endfor %} - - {% endfor %} -
    + + 主机名 IP地址 IDC 所属主机组 配置信息 操作系统 使用默认管理 操作
    + + {{ asset.hostname|default_if_none:"" }} {{ asset.ip|default_if_none:"" }} {{ asset.idc.name|default_if_none:"" }} {{ asset.group.all|group_str2 }}{{ asset.cpu }}|{{ asset.memory }}|{{ asset.disk }} + {{ asset.system_type|default_if_none:"" }}{{ asset.system_version|default_if_none:"" }} {{ asset.use_default_auth|bool2str }} + 详情 + {% ifnotequal session_role_id 0 %} + {% if user.role == 'admin' %} + + 编辑 + 更新 + 删除 + {% endif %} + {% endifnotequal %} +
    - {% ifequal host_count 0 %} - (空) - {% endifequal %} + + +
    +
    + {% if user.role == 'admin' %} + + 修改 + {% endif %} +
    + {% include 'paginator.html' %} +
    +
    From c89d43d26946c5fb5ffda92ed1211df49aa3822a Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Sun, 22 Nov 2015 22:20:55 +0800 Subject: [PATCH 4/4] update, now Mac to develop will be all egg pain --- jumpserver/views.py | 26 +++--- juser/views.py | 5 +- templates/juser/run_command.html | 138 +++++++++++++++++++++++++++++++ templates/upload.html | 5 ++ 4 files changed, 162 insertions(+), 12 deletions(-) create mode 100644 templates/juser/run_command.html diff --git a/jumpserver/views.py b/jumpserver/views.py index a99ec4f56..269053d35 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -72,7 +72,7 @@ def get_count_by_date(date_li, item): return len(set(data_count_tmp)) - +from jasset.models import Asset, IDC @require_role(role='user') def index_cu(request): # user_id = request.user.id @@ -80,17 +80,21 @@ def index_cu(request): login_types = {'L': 'LDAP', 'M': 'MAP'} username = request.user.username # TODO: need fix,liuzheng need Asset help - asset = get_group_user_perm(request.user) - print asset - assets = asset.get('asset') - # idc = [] - # for i in assets: - # idc.append(i.idc.id) - # idc_all = IDC.objects.filter(id__in=idc) - idc_all = [] + GUP = get_group_user_perm(request.user) + print GUP + assets = GUP.get('asset') + idcs = [] for i in assets: - idc_all.append(i.idc) - asset_group_all = asset.get('asset_group') + if i.idc_id: + idcs.append(i.idc_id) + idc_all = IDC.objects.filter(id__in=idcs) + for i in idc_all: + print i.name + # idc_all = [] + # for i in assets: + # idc_all.append(i.idc) + # print i.idc.name + asset_group_all = GUP.get('asset_group') # posts = Asset.object.all() # host_count = len(posts) # diff --git a/juser/views.py b/juser/views.py index e0a318433..dc02487a7 100644 --- a/juser/views.py +++ b/juser/views.py @@ -489,7 +489,10 @@ def down_key(request): return HttpResponse('No Key File. Contact Admin.') from jperm.perm_api import get_group_user_perm +@require_role(role='user') def RunCommand(request): if request.method == 'GET': - print get_group_user_perm(request.user) + GUP = get_group_user_perm(request.user) + print GUP + assets = GUP.get('asset') return render_to_response('juser/run_command.html', locals(), context_instance=RequestContext(request)) \ No newline at end of file diff --git a/templates/juser/run_command.html b/templates/juser/run_command.html new file mode 100644 index 000000000..f075f9c90 --- /dev/null +++ b/templates/juser/run_command.html @@ -0,0 +1,138 @@ +{% extends 'base.html' %} + +{% load mytags %} +{% block content %} +{% include 'nav_cat_bar.html' %} + +
    +
    +
    +
    +
    +
    命令批量执行
    + +
    + +
    +
    + {% if error %} +
    {{ error }}
    + {% endif %} + {% if msg %} +
    {{ msg }}
    + {% endif %} +
    + + +
    + +
    +
    +
    + +
    + +
    + +
    + +
    +
    + + +
    +
    +
    + +
    +
    +
    +
    +
    + +{% endblock %} +{% block self_head_css_js %} + {% load staticfiles %} + + + + +{% endblock %} +{% block self_footer_js %} + +{% endblock %} \ No newline at end of file diff --git a/templates/upload.html b/templates/upload.html index 88e859a88..fb50a7cfa 100644 --- a/templates/upload.html +++ b/templates/upload.html @@ -73,6 +73,11 @@
    + {#