diff --git a/connect.py b/connect.py index 3fed445f2..9a94764bf 100755 --- a/connect.py +++ b/connect.py @@ -25,6 +25,7 @@ django.setup() from juser.models import User from jasset.models import Asset from jlog.models import Log +from jperm.views import perm_user_asset try: import termios @@ -207,15 +208,10 @@ def posix_shell(chan, username, host): def get_user_host(username): """Get the hosts of under the user control.""" hosts_attr = {} - try: - user = User.objects.get(username=username) - except ObjectDoesNotExist: - raise ServerError("Username \033[1;31m%s\033[0m doesn't exist on Jumpserver." % username) - else: - perm_all = user.permission_set.all() - for perm in perm_all: - hosts_attr[perm.asset.ip] = [perm.asset.id, perm.asset.comment] - return hosts_attr + asset_all = perm_user_asset(username=username) + for asset in asset_all: + hosts_attr[asset.ip] = [asset.id, asset.comment] + return hosts_attr def get_connect_item(username, ip): @@ -234,7 +230,6 @@ def get_connect_item(username, ip): login_type_dict = { 'L': user.ldap_pwd, - 'S': user.ssh_key_pwd2, 'P': user.ssh_pwd, } @@ -244,7 +239,7 @@ def get_connect_item(username, ip): elif asset.login_type == 'M': username = asset.username - password= cryptor.decrypt(asset.password) + password = cryptor.decrypt(asset.password) return username, password, ip, port else: diff --git a/jperm/views.py b/jperm/views.py index a53b7938a..b9da25c6b 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -25,8 +25,11 @@ def perm_group_update(user_group_name='', user_group_id='', asset_groups_name='' Perm(user_group=user_group, asset_group=asset_group).save() -def perm_user_asset(user_id): - user = User.objects.get(id=user_id) +def perm_user_asset(user_id=None, username=None): + if user_id: + user = User.objects.get(id=user_id) + else: + user = User.objects.get(username=username) user_groups = user.user_group.all() perms = [] assets = [] @@ -99,84 +102,3 @@ def perm_asset_detail(request): return render_to_response('jperm/perm_asset_detail.html', locals()) -# def perm_user_host(username, ips): -# user = User.objects.get(username=username) -# user.perm_set.all().delete() -# for ip in ips: -# asset = Asset.objects.get(ip=ip) -# Perm.objects.create(user=user, asset=asset) -# -# -# def perm_user_edit(request): -# header_title, path1, path2 = u'授权编辑 | Perm Edit.', u'jperm', u'perm_edit' -# if request.method == 'GET': -# if request.GET.get('id', None): -# user_id = request.GET.get('id') -# user = User.objects.get(id=user_id) -# assets = Asset.objects.all() -# assets_permed = [] -# for perm in user.perm_set.all(): -# assets_permed.append(perm.asset) -# assets_unperm = list(set(assets)-set(assets_permed)) -# return render_to_response('jperm/perm_user_edit.html', locals()) -# else: -# host_ips = request.POST.getlist('host_permed', '') -# username = request.POST.get('username') -# perm_user_host(username, host_ips) -# -# return HttpResponseRedirect('/jperm/perm_host/') -# -# -# def perm_user_detail(request): -# user_id = request.GET.get('id', '') -# user = User.objects.get(id=user_id) -# host_permed = [] -# for perm in user.perm_set.all(): -# host_permed.append(perm.asset) -# -# return render_to_response('jperm/perm_detail.html', locals()) -# -# -# def perm_group_edit(request): -# if request.method == 'GET': -# group_id = request.GET.get('id', '') -# group = UserGroup.objects.get(id=group_id) -# -# return render_to_response('jperm/perm_group_edit.html') -# -# -# def perm_add(request): -# header_title, path1, path2 = u'添加授权 | Add User perm.', u'授权管理', u'添加授权' -# if request.method == 'GET': -# username = request.GET.get('username', None) -# if not username: -# return HttpResponseRedirect('/') -# -# user = User.objects.get(username=username) -# permed_hosts = [] -# for perm in user.perm_set.all(): -# permed_hosts.append(perm.asset) -# -# hosts_all = Asset.objects.all() -# hosts = list(set(hosts_all) - set(permed_hosts)) -# -# else: -# username = request.POST.get('username', None) -# host_ids = request.POST.getlist('host_ids', None) -# -# user = User.objects.get(username=username) -# for host_id in host_ids: -# asset = Asset.objects.get(id=host_id) -# perm = Perm(user=user, asset=asset) -# perm.save() -# msg = u'添加成功' -# -# return render_to_response('jperm/perm_add.html', locals()) -# -# -# def perm_user_show(request): -# header_title, path1, path2 = u'查看授权用户 | Perm User Detail.', u'授权管理', u'用户详情' -# users = User.objects.all() -# return render_to_response('jperm/perm_user_show.html', locals(),) - - diff --git a/templates/jperm/perm_group_edit.html b/templates/jperm/perm_group_edit.html deleted file mode 100644 index 20121cc66..000000000 --- a/templates/jperm/perm_group_edit.html +++ /dev/null @@ -1,151 +0,0 @@ -{% extends 'base.html' %} -{% load mytags %} - -{% block content %} - - - {% include 'nav_cat_bar.html' %} -
-
-
-
- -
-
授权编辑表单 Edit perm of user group
- -
- -
-
-
-
- - -
-
-
-
- -
-
-
-
- - -
-
- -
-
- -
-

未授权主机

-
- - -
-
- -
-
- - -
-
- -

授权主机

-
- -
-
-
-
-
-
- - -
-
-
-
- -
-
-
-
-
- -{# #} - -{% endblock %} \ No newline at end of file diff --git a/templates/jperm/perm_list2.htl.html b/templates/jperm/perm_list2.htl.html deleted file mode 100644 index 15270e669..000000000 --- a/templates/jperm/perm_list2.htl.html +++ /dev/null @@ -1,193 +0,0 @@ -{% extends 'base.html' %} -{% load mytags %} -{% block content %} -{% include 'nav_cat_bar.html' %} - -
-
-
-
-
-
主机授权 show host perm info.
- -
- -
-
- - -
- -
-
- - - - - - - - - - - - {% for user in contacts.object_list %} - - - - - - - - {% endfor %} - -
用户名姓名属组授权总数操作
{{ user.username }} {{ user.name }} {{ user.username|groups_str }} {{ user.id|perm_count }} - 详情 - 编辑 -
-
-
-
- Showing {{ contacts.start_index }} to {{ contacts.end_index }} of {{ p.count }} entries -
-
-
-
-
    - {% if contacts.has_previous %} - - {% else %} - - {% endif %} - {% for page in p.page_range %} - {% ifequal offset1 page %} -
  • {{ page }}
  • - {% else %} -
  • {{ page }}
  • - {% endifequal %} - {% endfor %} - {% if contacts.has_next %} - - {% else %} - - {% endif %} -
-
-
-
-
- -
- - - - - - - - - - {% for group in contacts2.object_list %} - - - - - - {% endfor %} - -
组名备注操作
{{ group.name }} {{ group.comment }} - 详情 - 编辑 -
-
-
-
- Showing {{ contacts2.start_index }} to {{ contacts2.end_index }} of {{ p2.count }} entries -
-
-
-
-
    - {% if contacts2.has_previous %} - - {% else %} - - {% endif %} - {% for page in p2.page_range %} - {% ifequal offset1 page %} -
  • {{ page }}
  • - {% else %} -
  • {{ page }}
  • - {% endifequal %} - {% endfor %} - {% if contacts2.has_next %} - - {% else %} - - {% endif %} -
-
-
-
- -
-
- -
- -
- - - -
-
-
-
-
- - - -{% endblock %} \ No newline at end of file diff --git a/templates/jperm/perm_user_edit.html b/templates/jperm/perm_user_edit.html deleted file mode 100644 index 00cc85e73..000000000 --- a/templates/jperm/perm_user_edit.html +++ /dev/null @@ -1,138 +0,0 @@ -{% extends 'base.html' %} -{% load mytags %} - -{% block content %} - - - {% include 'nav_cat_bar.html' %} -
-
-
-
- -
-
授权编辑表单 Edit perm of user
- -
- -
-
-
-
- - -
-
-
-
- -
-
-
-
- - -
-
- -
-
- -
-

未授权主机

-
- - -
-
- -
-
- - -
-
- -

授权主机

-
- -
-
-
-
-
-
- - -
-
-
-
- -
-
-
-
-
- -{# #} - -{% endblock %} \ No newline at end of file diff --git a/templates/jperm/perm_user_show.html b/templates/jperm/perm_user_show.html deleted file mode 100644 index 842de720b..000000000 --- a/templates/jperm/perm_user_show.html +++ /dev/null @@ -1,61 +0,0 @@ -{% extends 'base.html' %} -{% load mytags %} - -{% block content %} - {% include 'nav_cat_bar.html' %} -
-
-
-
-
-
用户信息 show user info.
- -
-
-
- - - - - - - - - {% for user in users %} - - - - - - {% endfor %} - -
ID添加授权
{{ user.id }}{{ user.username }}查看权限
-
-
- - -
-
-
-
-
-
-
-
-{% endblock %} \ No newline at end of file