diff --git a/connect.py b/connect.py index 535b61b0e..7a04c4a17 100755 --- a/connect.py +++ b/connect.py @@ -7,7 +7,6 @@ import re import ast import select import time -from datetime import datetime import paramiko import struct import fcntl @@ -119,8 +118,9 @@ def log_record(username, host): except IOError: raise ServerError('Create logfile failed, Please modify %s permission.' % today_connect_log_dir) - log = Log(user=username, host=host, remote_ip=ip_list, dept_name=dept_name, log_path=log_file_path, start_time=datetime.now(), pid=pid) - log_file.write('Starttime is %s\n' % datetime.now()) + log = Log(user=username, host=host, remote_ip=ip_list, dept_name=dept_name, + log_path=log_file_path, start_time=datetime.datetime.now(), pid=pid) + log_file.write('Starttime is %s\n' % datetime.datetime.now()) log.save() return log_file, log @@ -162,11 +162,11 @@ def posix_shell(chan, username, host): finally: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_tty) - log_file.write('Endtime is %s' % datetime.now()) + log_file.write('Endtime is %s' % datetime.datetime.now()) log_file.close() log.is_finished = True log.log_finished = False - log.end_time = datetime.now() + log.end_time = datetime.datetime.now() log.save() print_prompt() @@ -280,7 +280,7 @@ def print_user_hostgroup(username): group_attr = get_user_hostgroup(username) groups = group_attr.keys() for g in groups: - print "[%3s]%s -- %s" % (group_attr[g][0], g, group_attr[g][1]) + print "[%3s] %s -- %s" % (group_attr[g][0], g, group_attr[g][1]) def print_user_hostgroup_host(username, gid): diff --git a/jperm/models.py b/jperm/models.py index 0d1b276a0..2f9c13063 100644 --- a/jperm/models.py +++ b/jperm/models.py @@ -16,7 +16,7 @@ class Perm(models.Model): class CmdGroup(models.Model): - name = models.CharField(max_length=50) + name = models.CharField(max_length=50, unique=True) cmd = models.CharField(max_length=999) dept = models.ForeignKey(DEPT) comment = models.CharField(blank=True, null=True, max_length=50) diff --git a/jperm/urls.py b/jperm/urls.py index f859e7590..19cdf9a49 100644 --- a/jperm/urls.py +++ b/jperm/urls.py @@ -23,6 +23,7 @@ urlpatterns = patterns('jperm.views', (r'^cmd_list/$', 'cmd_list'), (r'^cmd_del/$', 'cmd_del'), (r'^cmd_edit/$', 'cmd_edit'), + (r'^cmd_detail/$', 'cmd_detail'), (r'^apply/$', 'perm_apply'), (r'^apply_show/(\w+)/$', 'perm_apply_log'), (r'^apply_exec/$', 'perm_apply_exec'), diff --git a/jperm/views.py b/jperm/views.py index 27f471c37..3e6d2085c 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -3,19 +3,13 @@ import sys reload(sys) sys.setdefaultencoding('utf8') -import datetime from django.core.mail import send_mail from django.shortcuts import render_to_response -from django.http import HttpResponseRedirect, HttpResponse from django.template import RequestContext -from juser.models import User, UserGroup, DEPT -from jasset.models import Asset, BisGroup from jperm.models import Perm, SudoPerm, CmdGroup, Apply -from django.core.paginator import Paginator, EmptyPage, InvalidPage from django.db.models import Q -from jumpserver.views import LDAP_ENABLE, ldap_conn, CONF, page_list_return, pages from jumpserver.api import * @@ -544,8 +538,6 @@ def cmd_add(request): error = u"部门不能为空" msg = u'命令组添加成功' - return HttpResponseRedirect('/jperm/cmd_list/') - return render_to_response('jperm/sudo_cmd_add.html', locals(), context_instance=RequestContext(request)) @@ -597,7 +589,7 @@ def cmd_edit(request): def cmd_list(request): header_title, path1, path2 = u'sudo命令查看', u'权限管理', u'Sudo命令添加' - if request.session.get('role_id', '0') == '2': + if is_super_user(request): cmd_groups = contact_list = CmdGroup.objects.all() else: user, dept = get_session_user_dept(request) @@ -626,6 +618,16 @@ def cmd_del(request): return HttpResponseRedirect('/jperm/cmd_list/') +@require_admin +def cmd_detail(request): + cmd_id = request.GET.get('id') + cmd_group = CmdGroup.objects.filter(id=cmd_id) + if cmd_group: + cmd_group = cmd_group[0] + + return render_to_response('jperm/sudo_cmd_detail.html', locals(), context_instance=RequestContext(request)) + + @require_login def perm_apply(request): header_title, path1, path2 = u'主机权限申请', u'权限管理', u'申请主机' diff --git a/jumpserver/templatetags/mytags.py b/jumpserver/templatetags/mytags.py index 5cf0d50ae..a9c0539aa 100644 --- a/jumpserver/templatetags/mytags.py +++ b/jumpserver/templatetags/mytags.py @@ -5,7 +5,7 @@ import ast import time from django import template -from juser.models import User, UserGroup, DEPT +from jperm.models import CmdGroup from jumpserver.api import * from jasset.models import AssetAlias @@ -264,3 +264,19 @@ def time_delta(time_before): return '%s 分钟前' % mins else: return '%s 秒前' % delta.seconds + + +@register.filter(name='sudo_cmd_list') +def sudo_cmd_list(cmd_group_id): + cmd_group = CmdGroup.objects.filter(id=cmd_group_id) + if cmd_group: + cmd_group = cmd_group[0] + return cmd_group.cmd.split(',') + + +@register.filter(name='sudo_cmd_count') +def sudo_cmd_count(cmd_group_id): + cmd_group = CmdGroup.objects.filter(id=cmd_group_id) + if cmd_group: + cmd_group = cmd_group[0] + return len(cmd_group.cmd.split(',')) diff --git a/jumpserver/views.py b/jumpserver/views.py index 80600c0c6..e2c629676 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -144,11 +144,14 @@ def index(request): active_users = User.objects.filter(is_active=1) active_hosts = Asset.objects.filter(is_active=1) + users_total = users.count() if users.count() else 1 + hosts_total = hosts.count() if hosts.count() else 1 + # percent of dashboard - percent_user = format(active_users.count() / users.count(), '.0%') - percent_host = format(active_hosts.count() / hosts.count(), '.0%') - percent_online_user = format(online_user.count() / users.count(), '.0%') - percent_online_host = format(online_host.count() / hosts.count(), '.0%') + percent_user = format(active_users.count() / users_total, '.0%') + percent_host = format(active_hosts.count() / hosts_total, '.0%') + percent_online_user = format(online_user.count() / users_total, '.0%') + percent_online_host = format(online_host.count() / hosts_total, '.0%') li_date, li_str = getDaysByNum(7) today = datetime.datetime.now().day @@ -290,4 +293,12 @@ def install(request): def upload(request): - pass + if request.method == 'POST': + host = request.POST.get('host') + path = request.POST.get('path') + upload_file = request.FILES.getlist('file', None) + + if upload_file: + return HttpResponse(upload_file) + + return render_to_response('upload.html', locals(), context_instance=RequestContext(request)) diff --git a/templates/foot_script.html b/templates/foot_script.html index 6a57f92cd..5cd6b71d4 100644 --- a/templates/foot_script.html +++ b/templates/foot_script.html @@ -24,6 +24,7 @@ + + diff --git a/templates/jperm/sudo_cmd_detail.html b/templates/jperm/sudo_cmd_detail.html new file mode 100644 index 000000000..215961585 --- /dev/null +++ b/templates/jperm/sudo_cmd_detail.html @@ -0,0 +1,44 @@ +{% load mytags %} + + + {% include 'link_css.html' %} + + + + + +
+
+

{{ cmd_group.name }} 命令详情

+
+ + + + + + + + + + + + + + + + + + + +
ID名称部门
{{ cmd_group.id }}{{ cmd_group.name }}{{ cmd_group.dept.name }}
命令: + {{ cmd_group.cmd }} +
+
+
+ + \ No newline at end of file diff --git a/templates/jperm/sudo_list.html b/templates/jperm/sudo_list.html index 9cd3f21bd..6dde473a7 100644 --- a/templates/jperm/sudo_list.html +++ b/templates/jperm/sudo_list.html @@ -69,7 +69,7 @@ {{ group.id | member_count }} {{ group.id | ugrp_perm_agrp_count }} {{ group.id | ugrp_perm_asset_count }} - {{ group.id | ugrp_perm_asset_count }} + {{ group.id | sudo_cmd_count }} {{ group.comment }} sudo授权 @@ -104,7 +104,20 @@ + + +{% endblock %} \ No newline at end of file