diff --git a/jasset/urls.py b/jasset/urls.py index d0e7e3f89..da52529b6 100644 --- a/jasset/urls.py +++ b/jasset/urls.py @@ -9,6 +9,7 @@ urlpatterns = patterns('', url(r'^search/$', host_search), url(r"^host_detail/$", host_detail), url(r"^dept_host_ajax/$", dept_host_ajax), + url(r"^show_all_ajax/$", show_all_ajax), url(r'^idc_add/$', idc_add), url(r'^idc_list/$', idc_list), url(r'^idc_edit/$', idc_edit), diff --git a/jasset/views.py b/jasset/views.py index 6515f2696..a62aaca00 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -105,15 +105,23 @@ def batch_host_edit(host_info, j_user='', j_password=''): groups, depts = [], [] is_active = {u'是': '1', u'否': '2'} login_types = {'LDAP': 'L', 'MAP': 'M'} - for group in j_group[0].split(): - c = BisGroup.objects.get(name=group.strip()) - groups.append(c) - for d in j_dept[0].split(): - p = DEPT.objects.get(name=d.strip()) - depts.append(p) + a = Asset.objects.get(id=j_id) + if '...' in j_group[0].split(): + groups = a.bis_group.all() + else: + for group in j_group[0].split(): + c = BisGroup.objects.get(name=group.strip()) + groups.append(c) + + if '...' in j_dept[0].split(): + depts = a.dept.all() + else: + for d in j_dept[0].split(): + p = DEPT.objects.get(name=d.strip()) + depts.append(p) + j_type = login_types[j_type] j_idc = IDC.objects.get(name=j_idc) - a = Asset.objects.get(id=j_id) if j_type == 'M': if a.password != j_password: j_password = cryptor.decrypt(j_password) @@ -140,7 +148,6 @@ def batch_host_edit(host_info, j_user='', j_password=''): def db_host_delete(request, host_id): """ 删除主机操作 """ - print host_id if is_group_admin(request) and not validate(request, asset=[host_id]): return httperror(request, '删除失败, 您无权删除!') @@ -197,7 +204,6 @@ def host_add(request): host_info = [j_ip, j_port, j_idc, j_type, j_group, [j_dept], j_active, j_comment] if is_group_admin(request) and not validate(request, asset_group=j_group, edept=[j_dept]): - print j_dept return httperror(request, u'添加失败,您无权操作!') if Asset.objects.filter(ip=str(j_ip)): @@ -430,8 +436,7 @@ def host_del(request, offset): host_id = request.POST.get(key) db_host_delete(request, host_id) else: - host_id = int(offset) - db_host_delete(request, host_id) + db_host_delete(request, offset) return HttpResponseRedirect('/jasset/host_list/') @@ -886,6 +891,16 @@ def dept_host_ajax(request): return my_render('jasset/dept_host_ajax.html', locals(), request) +def show_all_ajax(request): + """ 批量修改主机时, 部门和组全部显示 """ + env = request.GET.get('env', '') + get_id = request.GET.get('id', '') + host = Asset.objects.filter(id=get_id) + if host: + host = host[0] + return my_render('jasset/show_all_ajax.html', locals(), request) + + @require_login def host_search(request): """ 搜索主机 """ diff --git a/jperm/models.py b/jperm/models.py index 091478012..c29cb8e54 100644 --- a/jperm/models.py +++ b/jperm/models.py @@ -39,6 +39,7 @@ class SudoPerm(models.Model): class Apply(models.Model): uuid = UUIDField(auto=True) applyer = models.CharField(max_length=20) + admin = models.CharField(max_length=20) approver = models.CharField(max_length=20) dept = models.CharField(max_length=20) bisgroup = models.CharField(max_length=500) @@ -47,6 +48,7 @@ class Apply(models.Model): status = models.IntegerField(max_length=2) date_add = models.DateTimeField(null=True) date_end = models.DateTimeField(null=True) + read = models.IntegerField(max_length=2) def __unicode__(self): return self.applyer diff --git a/jperm/views.py b/jperm/views.py index b307740e7..d9c0cc85b 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -676,6 +676,7 @@ def perm_apply(request): """ 权限申请 """ header_title, path1, path2 = u'主机权限申请', u'权限管理', u'申请主机' user_id, username = get_session_user_info(request)[0:2] + name = User.objects.get(id=user_id).name dept_id, deptname, dept = get_session_user_info(request)[3:6] perm_host = user_perm_asset_api(username) all_host = Asset.objects.filter(dept=dept) @@ -687,6 +688,7 @@ def perm_apply(request): egroup = [d for d in all_group if d not in perm_group] dept_da = User.objects.filter(dept_id=dept_id, role='DA') + admin = User.objects.get(name='admin') if request.method == 'POST': applyer = request.POST.get('applyer') @@ -695,14 +697,16 @@ def perm_apply(request): group = request.POST.getlist('group') hosts = request.POST.getlist('hosts') comment = request.POST.get('comment') + if not da: + return httperror(request, u'请选择管理员!') da = User.objects.get(id=da) mail_address = da.email mail_title = '%s - 权限申请' % username group_lis = ', '.join(group) hosts_lis = ', '.join(hosts) time_now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') - a = Apply.objects.create(applyer=applyer, dept=dept, bisgroup=group, date_add=datetime.datetime.now(), - asset=hosts, status=0, comment=comment) + a = Apply.objects.create(applyer=applyer, admin=da, dept=dept, bisgroup=group, date_add=datetime.datetime.now(), + asset=hosts, status=0, comment=comment, read=0) uuid = a.uuid url = "http://%s:%s/jperm/apply_exec/?uuid=%s" % (SEND_IP, SEND_PORT, uuid) mail_msg = """ @@ -774,9 +778,9 @@ def get_apply_posts(request, status, username, dept_name, keyword=None): posts = post_all.filter(dept=dept_name) elif is_common_user(request): if keyword: - posts = post_keyword_all.filter(user=username) + posts = post_keyword_all.filter(applyer=username) else: - posts = post_all.filter(user=username) + posts = post_all.filter(applyer=username) return posts @@ -786,7 +790,8 @@ def perm_apply_log(request, offset): """ 申请记录 """ header_title, path1, path2 = u'权限申请记录', u'权限管理', u'申请记录' keyword = request.GET.get('keyword', '') - username = get_session_user_info(request)[1] + user_id = get_session_user_info(request)[0] + username = User.objects.get(id=user_id).name dept_name = get_session_user_info(request)[4] status_dic = {'online': 0, 'offline': 1} status = status_dic[offset] @@ -798,8 +803,17 @@ def perm_apply_log(request, offset): @require_login def perm_apply_info(request): """ 申请信息详情 """ - uuid = request.GET.get('uuid') - post = Apply.objects.get(uuid=uuid) + uuid = request.GET.get('uuid', '') + post = Apply.objects.filter(uuid=uuid) + username = get_session_user_info(request)[1] + if post: + post = post[0] + if post.read == 0 and post.applyer != username: + post.read = 1 + post.save() + else: + return httperror(request, u'没有这个申请记录!') + return render_to_response('jperm/perm_apply_info.html', locals(), context_instance=RequestContext(request)) diff --git a/jumpserver.conf b/jumpserver.conf index d08e6cc0b..d1c576dcd 100644 --- a/jumpserver.conf +++ b/jumpserver.conf @@ -1,7 +1,7 @@ #coding: utf8 [base] -ip = 192.168.0.129 +ip = 192.168.199.180 port = 80 key = 88aaaf7ffe3c6c04 @@ -16,14 +16,14 @@ database = jumpserver [ldap] ldap_enable = 1 -host_url = ldap://127.0.0.1:389 +host_url = ldap://192.168.199.180:389 base_dn = dc=jumpserver, dc=org root_dn = cn=admin,dc=jumpserver,dc=org root_pw = secret234 [websocket] -web_socket_host = 192.168.20.209:3000 +web_socket_host = 192.168.199.180:3000 [mail] diff --git a/jumpserver/context_processors.py b/jumpserver/context_processors.py index cda6f64a1..aac09c7a7 100644 --- a/jumpserver/context_processors.py +++ b/jumpserver/context_processors.py @@ -1,6 +1,7 @@ from juser.models import User from jasset.models import Asset from jumpserver.api import * +from jperm.models import Apply def name_proc(request): @@ -17,6 +18,9 @@ def name_proc(request): user_active_num = dept.user_set.filter(is_active=True).count() host_total_num = dept.asset_set.all().count() host_active_num = dept.asset_set.all().filter(is_active=True).count() + + username = User.objects.get(id=user_id).name + apply_info = Apply.objects.filter(admin=username, status=0, read=0) request.session.set_expiry(3600) info_dic = {'session_user_id': user_id, @@ -24,7 +28,8 @@ def name_proc(request): 'user_total_num': user_total_num, 'user_active_num': user_active_num, 'host_total_num': host_total_num, - 'host_active_num': host_active_num} + 'host_active_num': host_active_num, + 'apply_info': apply_info} return info_dic diff --git a/jumpserver/templatetags/mytags.py b/jumpserver/templatetags/mytags.py index f5e1e343c..6b4cc44e5 100644 --- a/jumpserver/templatetags/mytags.py +++ b/jumpserver/templatetags/mytags.py @@ -68,6 +68,15 @@ def group_str2_all(group_list): return '%s ...' % ' '.join([group.name for group in group_lis[0:2]]) +@register.filter(name='group_dept_all') +def group_dept_all(group_list): + group_lis = [] + for i in group_list: + if str(i) != 'ALL': + group_lis.append(i) + return ' '.join([group.name for group in group_lis]) + + @register.filter(name='group_manage_str') def group_manage_str(username): user = User.objects.get(username=username) diff --git a/log_handler.py b/log_handler.py index 590d77bdb..0d8b91e77 100755 --- a/log_handler.py +++ b/log_handler.py @@ -16,7 +16,7 @@ from jlog.models import Log def log_hanler(id): log = Log.objects.get(id=id) - pattern = re.compile(r'([\[.*@.*\][\$#].* | mysql>.*])') + pattern = re.compile(r'([\[.*@.*\][\$#].*)|(.*mysql>.*)') if log: filename = log.log_path if os.path.isfile(filename): diff --git a/templates/jasset/group_detail.html b/templates/jasset/group_detail.html index 14b7afde7..6d08bcbbc 100644 --- a/templates/jasset/group_detail.html +++ b/templates/jasset/group_detail.html @@ -62,7 +62,7 @@