diff --git a/jumpserver/views.py b/jumpserver/views.py index 87cdf0126..4563a9fd4 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): """ @@ -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,6 +80,21 @@ def index_cu(request): login_types = {'L': 'LDAP', 'M': 'MAP'} username = request.user.username # TODO: need fix,liuzheng need Asset help + GUP = get_group_user_perm(request.user) + print GUP + assets = GUP.get('asset') + idcs = [] + for i in assets: + 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/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..dc02487a7 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: @@ -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() @@ -487,4 +487,12 @@ 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 +@require_role(role='user') +def RunCommand(request): + if request.method == 'GET': + 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/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' %} +
+
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/nav.html b/templates/nav.html index bbcf4c26e..e1f05862e 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -126,6 +126,9 @@
  • 申请记录
  • +
  • + 批量执行命令 +
  • 登录历史
  • 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 @@
    + {#