From 9979fdf6dea674cd19638cccab1c6d51402000b6 Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 11 Dec 2015 15:32:06 +0800 Subject: [PATCH 01/17] bugfix --- jperm/ansible_api.py | 29 +++++++++++++++-------------- templates/jperm/perm_rule_add.html | 2 +- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/jperm/ansible_api.py b/jperm/ansible_api.py index 1fb081966..71d6e9979 100644 --- a/jperm/ansible_api.py +++ b/jperm/ansible_api.py @@ -1,27 +1,28 @@ # -*- coding: utf-8 -*- -from ansible.inventory.group import Group -from ansible.inventory.host import Host -from ansible.inventory import Inventory -from ansible.runner import Runner -from ansible.playbook import PlayBook - -from ansible import callbacks -from ansible import utils -from passlib.hash import sha512_crypt - -from utils import get_rand_pass -from jumpserver.api import logger - from tempfile import NamedTemporaryFile +import os.path + +from ansible.inventory.group import Group +from ansible.inventory.host import Host +from ansible.inventory import Inventory +from ansible.runner import Runner +from ansible.playbook import PlayBook +from ansible import callbacks +from ansible import utils +import ansible.constants as C +from passlib.hash import sha512_crypt from django.template.loader import get_template from django.template import Context -import os.path +from utils import get_rand_pass +from jumpserver.api import logger + API_DIR = os.path.dirname(os.path.abspath(__file__)) ANSIBLE_DIR = os.path.join(API_DIR, 'playbooks') +C.HOST_KEY_CHECKING = False class AnsibleError(StandardError): diff --git a/templates/jperm/perm_rule_add.html b/templates/jperm/perm_rule_add.html index e0ea6bd75..0fd3b18b7 100644 --- a/templates/jperm/perm_rule_add.html +++ b/templates/jperm/perm_rule_add.html @@ -133,7 +133,7 @@ $('#ruleForm').validator({ fields: { "name": { - rule: "required;check_name", + rule: "required", tip: "输入规则名称", msg: {required: "规则名称必填"} }, From b27e2075ff73614a1b038472ef7de293b0a40df2 Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 11 Dec 2015 17:28:01 +0800 Subject: [PATCH 02/17] bug fix --- templates/nav.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/nav.html b/templates/nav.html index 505439011..7fcd4a27f 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -24,14 +24,14 @@
  • 授权管理
  • From 6d5513c69e73873d57050da78cf3c31eec4e5b7b Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 11 Dec 2015 17:40:52 +0800 Subject: [PATCH 03/17] open in current window --- templates/jasset/asset_list.html | 2 +- templates/jasset/group_list.html | 4 ++-- templates/jasset/idc_list.html | 2 +- templates/juser/group_list.html | 2 +- templates/juser/user_list.html | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/templates/jasset/asset_list.html b/templates/jasset/asset_list.html index 73e281e83..d14a1fe5f 100644 --- a/templates/jasset/asset_list.html +++ b/templates/jasset/asset_list.html @@ -25,7 +25,7 @@
    diff --git a/templates/jasset/group_list.html b/templates/jasset/group_list.html index ce647c2bc..da573bcf9 100644 --- a/templates/jasset/group_list.html +++ b/templates/jasset/group_list.html @@ -23,8 +23,8 @@
    - 添加主机组 - 删除所选 + 添加主机组 + 删除所选
    diff --git a/templates/jasset/idc_list.html b/templates/jasset/idc_list.html index 399fac549..bb95fcc5d 100644 --- a/templates/jasset/idc_list.html +++ b/templates/jasset/idc_list.html @@ -29,7 +29,7 @@
    - 添加机房 + 添加机房
    diff --git a/templates/juser/group_list.html b/templates/juser/group_list.html index 590b9f592..47beec70e 100644 --- a/templates/juser/group_list.html +++ b/templates/juser/group_list.html @@ -25,7 +25,7 @@
    - 添加用户组 + 添加用户组 删除所选
    diff --git a/templates/juser/user_list.html b/templates/juser/user_list.html index 0140b3170..c0c752630 100644 --- a/templates/juser/user_list.html +++ b/templates/juser/user_list.html @@ -24,7 +24,7 @@
    - 添加用户 + 添加用户 删除所选
    From f849ffef3ed289d935109ec4f41899d264d620f6 Mon Sep 17 00:00:00 2001 From: ibuler Date: Sat, 12 Dec 2015 19:30:39 +0800 Subject: [PATCH 04/17] url modify --- jasset/models.py | 16 +-- jasset/urls.py | 37 +++--- jasset/views.py | 14 +-- jlog/urls.py | 12 +- jlog/views.py | 8 -- jperm/urls.py | 34 +++--- jperm/views.py | 6 +- jumpserver/api.py | 9 +- jumpserver/urls.py | 29 ++--- jumpserver/views.py | 14 ++- juser/urls.py | 37 +++--- juser/user_api.py | 4 +- juser/views.py | 14 +-- run_websocket.py | 3 + templates/exec_cmd.html | 13 ++- templates/foot_script.html | 17 ++- templates/index.html | 8 +- templates/index_cu.html | 2 +- templates/jasset/asset_add.html | 4 +- templates/jasset/asset_add_batch.html | 4 +- templates/jasset/asset_cu_list.html | 6 +- templates/jasset/asset_detail.html | 12 +- templates/jasset/asset_list.html | 32 +++--- templates/jasset/group_list.html | 12 +- templates/jasset/idc_list.html | 26 ++--- templates/jasset/jlist_ip.html | 106 ------------------ templates/jlog/log_exec.html | 10 +- templates/jlog/log_file.html | 10 +- templates/jlog/log_filter.html | 139 ----------------------- templates/jlog/log_offline.html | 12 +- templates/jlog/log_online.html | 10 +- templates/jlog/log_search.html | 2 +- templates/jperm/perm_group_edit.html | 155 -------------------------- templates/jperm/perm_group_list.html | 81 -------------- templates/jperm/perm_role_detail.html | 12 +- templates/jperm/perm_role_list.html | 9 +- templates/jperm/perm_rule_detail.html | 8 +- templates/jperm/perm_rule_list.html | 6 +- templates/jperm/perm_sudo_list.html | 4 +- templates/jperm/sys_user_add.html | 130 --------------------- templates/jperm/sys_user_list.html | 102 ----------------- templates/juser/group_list.html | 10 +- templates/juser/user_detail.html | 12 +- templates/juser/user_list.html | 14 +-- templates/login.html | 2 +- templates/nav.html | 36 +++--- templates/nav_bar_header.html | 6 +- templates/nav_cat_bar.html | 2 +- templates/nav_li_profile.html | 6 +- 49 files changed, 269 insertions(+), 988 deletions(-) delete mode 100644 templates/jasset/jlist_ip.html delete mode 100644 templates/jlog/log_filter.html delete mode 100644 templates/jperm/perm_group_edit.html delete mode 100644 templates/jperm/perm_group_list.html delete mode 100644 templates/jperm/sys_user_add.html delete mode 100644 templates/jperm/sys_user_list.html diff --git a/jasset/models.py b/jasset/models.py index 558479111..746f3d109 100644 --- a/jasset/models.py +++ b/jasset/models.py @@ -40,14 +40,14 @@ class AssetGroup(models.Model): class IDC(models.Model): name = models.CharField(max_length=32, verbose_name=u'机房名称') - bandwidth = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'机房带宽') - linkman = models.CharField(max_length=16, blank=True, null=True, verbose_name=u'联系人') - phone = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'联系电话') - address = models.CharField(max_length=128, blank=True, null=True, verbose_name=u"机房地址") - network = models.TextField(blank=True, null=True, verbose_name=u"IP地址段") - date_added = models.DateField(auto_now=True, null=True) - operator = models.CharField(max_length=32, blank=True, null=True, verbose_name=u"运营商") - comment = models.CharField(max_length=128, blank=True, null=True, verbose_name=u"备注") + bandwidth = models.CharField(max_length=32, blank=True, null=True, default='', verbose_name=u'机房带宽') + linkman = models.CharField(max_length=16, blank=True, null=True, default='', verbose_name=u'联系人') + phone = models.CharField(max_length=32, blank=True, null=True, default='', verbose_name=u'联系电话') + address = models.CharField(max_length=128, blank=True, null=True, default='', verbose_name=u"机房地址") + network = models.TextField(blank=True, null=True, default='', verbose_name=u"IP地址段") + date_added = models.DateField(auto_now=True, default='', null=True) + operator = models.CharField(max_length=32, blank=True, default='', null=True, verbose_name=u"运营商") + comment = models.CharField(max_length=128, blank=True, default='', null=True, verbose_name=u"备注") def __unicode__(self): return self.name diff --git a/jasset/urls.py b/jasset/urls.py index ab7b6ac10..7daa9be20 100644 --- a/jasset/urls.py +++ b/jasset/urls.py @@ -3,23 +3,22 @@ from django.conf.urls import patterns, include, url from jasset.views import * urlpatterns = patterns('', - url(r'^asset_add/$', asset_add), - url(r"^asset_add_batch/$", asset_add_batch), - url(r'^group_del/$', group_del), - url(r'^asset_list/$', asset_list), - url(r'^asset_del/$', asset_del), - url(r"^asset_detail/$", asset_detail), - url(r'^asset_edit/$', asset_edit), - url(r'^asset_update/$', asset_update), - url(r'^asset_update_batch/$', asset_update_batch), - url(r'^group_add/$', group_add), - url(r'^group_list/$', group_list), - url(r'^group_edit/$', group_edit), - url(r'^group_list/$', group_list), - url(r'^asset_edit_batch/$', asset_edit_batch), - url(r'^idc_add/$', idc_add), - url(r'^idc_list/$', idc_list), - url(r'^idc_edit/$', idc_edit), - url(r'^idc_del/$', idc_del), - url(r'^upload/$', asset_upload), + url(r'^asset/add/$', asset_add, name='asset_add'), + url(r"^asset/add_batch/$", asset_add_batch, name='asset_add_batch'), + url(r'^asset/list/$', asset_list, name='asset_list'), + url(r'^asset/del/$', asset_del, name='asset_del'), + url(r"^asset/detail/$", asset_detail, name='asset_detail'), + url(r'^asset/edit/$', asset_edit, name='asset_edit'), + url(r'^asset/edit_batch/$', asset_edit_batch, name='asset_edit_batch'), + url(r'^asset/update/$', asset_update, name='asset_update'), + url(r'^asset/update_batch/$', asset_update_batch, name='asset_update_batch'), + url(r'^asset/upload/$', asset_upload, name='asset_upload'), + url(r'^group/del/$', group_del, name='asset_group_del'), + url(r'^group/add/$', group_add, name='asset_group_add'), + url(r'^group/list/$', group_list, name='asset_group_list'), + url(r'^group/edit/$', group_edit, name='asset_group_edit'), + url(r'^idc/add/$', idc_add, name='idc_add'), + url(r'^idc/list/$', idc_list, name='idc_list'), + url(r'^idc/edit/$', idc_edit, name='idc_edit'), + url(r'^idc/del/$', idc_del, name='idc_del'), ) \ No newline at end of file diff --git a/jasset/views.py b/jasset/views.py index 01aa1b7eb..bc03d2490 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -81,7 +81,7 @@ def group_edit(request): db_update_group(id=group_id, name=name, comment=comment, asset_select=asset_select) smg = u"主机组 %s 添加成功" % name - return HttpResponseRedirect('/jasset/group_list') + return HttpResponseRedirect(reverse('asset_group_list')) return my_render('jasset/group_edit.html', locals(), request) @@ -246,7 +246,7 @@ def asset_edit(request): else: emg = u'主机 %s 修改失败' % ip return my_render('jasset/error.html', locals(), request) - return HttpResponseRedirect('/jasset/asset_detail/?id=%s' % asset_id) + return HttpResponseRedirect(reverse('asset_detail')+'?id=%s' % asset_id) return my_render('jasset/asset_edit.html', locals(), request) @@ -451,10 +451,10 @@ def asset_update(request): asset = get_object(Asset, id=asset_id) name = request.user.username if not asset: - return HttpResponseRedirect('/jasset/asset_detail/?id=%s' % asset_id) + return HttpResponseRedirect(reverse('asset_detail')+'?id=%s' % asset_id) else: asset_ansible_update([asset], name) - return HttpResponseRedirect('/jasset/asset_detail/?id=%s' % asset_id) + return HttpResponseRedirect(reverse('asset_detail')+'/?id=%s' % asset_id) @require_role('admin') @@ -494,7 +494,7 @@ def idc_add(request): else: idc_form.save() smg = u'IDC: %s添加成功' % idc_name - return HttpResponseRedirect("/jasset/idc_list/") + return HttpResponseRedirect(reverse('idc_list')) else: idc_form = IdcForm() return my_render('jasset/idc_add.html', locals(), request) @@ -528,7 +528,7 @@ def idc_edit(request): idc_form = IdcForm(request.POST, instance=idc) if idc_form.is_valid(): idc_form.save() - return HttpResponseRedirect("/jasset/idc_list/") + return HttpResponseRedirect(reverse('idc_list')) else: idc_form = IdcForm(instance=idc) return my_render('jasset/idc_edit.html', locals(), request) @@ -545,7 +545,7 @@ def idc_del(request): for idc_id in idc_id_list: IDC.objects.filter(id=idc_id).delete() - return HttpResponseRedirect('/jasset/idc_list/') + return HttpResponseRedirect(reverse('idc_list')) @require_role('admin') diff --git a/jlog/urls.py b/jlog/urls.py index a490f46eb..0790c9307 100644 --- a/jlog/urls.py +++ b/jlog/urls.py @@ -3,11 +3,9 @@ from django.conf.urls import patterns, include, url from jlog.views import * urlpatterns = patterns('', - (r'^$', log_list), - (r'^log_list/(\w+)/$', log_list), - (r'^log_detail/(\w+)/$', log_detail), - (r'^history/$', log_history), - (r'^log_kill/', log_kill), - (r'^record/$', log_record), - (r'^web_terminal/$', web_terminal), + url(r'^list/(\w+)/$', log_list, name='log_list'), + url(r'^detail/(\w+)/$', log_detail, name='log_detail'), + url(r'^history/$', log_history, name='log_history'), + url(r'^log_kill/', log_kill, name='log_kill'), + url(r'^record/$', log_record, name='log_record'), ) \ No newline at end of file diff --git a/jlog/views.py b/jlog/views.py index 3665e8968..360265c4f 100644 --- a/jlog/views.py +++ b/jlog/views.py @@ -127,14 +127,6 @@ def log_record(request): return HttpResponse('无日志记录!') -@require_role('user') -def web_terminal(request): - asset_id = request.GET.get('id') - role_name = request.GET.get('role') - web_terminal_uri = 'ws://%s/terminal?id=%s&role=%s' % (WEB_SOCKET_HOST, asset_id, role_name) - return render_to_response('jlog/web_terminal.html', locals()) - - @require_role('admin') def log_detail(request, offset): log_id = request.GET.get('id') diff --git a/jperm/urls.py b/jperm/urls.py index 0d26aad45..3f76eaf2a 100644 --- a/jperm/urls.py +++ b/jperm/urls.py @@ -2,21 +2,21 @@ from django.conf.urls import patterns, include, url from jperm.views import * urlpatterns = patterns('jperm.views', - (r'^rule/$', perm_rule_list), - (r'^perm_rule_add/$', perm_rule_add), - (r'^perm_rule_detail/$', perm_rule_detail), - (r'^perm_rule_edit/$', perm_rule_edit), - (r'^perm_rule_delete/$', perm_rule_delete), - (r'^role/$', perm_role_list), - (r'^role/perm_role_add/$', perm_role_add), - (r'^role/perm_role_delete/$', perm_role_delete), - (r'^role/perm_role_detail/$', perm_role_detail), - (r'^role/perm_role_edit/$', perm_role_edit), - (r'^role/push/$', perm_role_push), - (r'^role/recycle/$', perm_role_recycle), - (r'^role/get/$', perm_role_get), - (r'^sudo/$', perm_sudo_list), - (r'^sudo/perm_sudo_add/$', perm_sudo_add), - (r'^sudo/perm_sudo_delete/$', perm_sudo_delete), - (r'^sudo/perm_sudo_edit/$', perm_sudo_edit), + url(r'^rule/$', perm_rule_list, name='rule_list'), + url(r'^perm_rule_add/$', perm_rule_add, name='rule_add'), + url(r'^perm_rule_detail/$', perm_rule_detail, name='rule_detail'), + url(r'^perm_rule_edit/$', perm_rule_edit, name='rule_edit'), + url(r'^perm_rule_delete/$', perm_rule_delete, name='rule_del'), + url(r'^role/$', perm_role_list, name='role_list'), + url(r'^role/perm_role_add/$', perm_role_add, name='role_add'), + url(r'^role/perm_role_delete/$', perm_role_delete, name='role_del'), + url(r'^role/perm_role_detail/$', perm_role_detail, name='role_detail'), + url(r'^role/perm_role_edit/$', perm_role_edit, name='role_edit'), + url(r'^role/push/$', perm_role_push, name='role_push'), + url(r'^role/recycle/$', perm_role_recycle, name='role_recycle'), + url(r'^role/get/$', perm_role_get, name='role_get'), + url(r'^sudo/$', perm_sudo_list, name='sudo_list'), + url(r'^sudo/perm_sudo_add/$', perm_sudo_add, name='sudo_add'), + url(r'^sudo/perm_sudo_delete/$', perm_sudo_delete, name='sudo_del'), + url(r'^sudo/perm_sudo_edit/$', perm_sudo_edit, name='sudo_edit'), ) diff --git a/jperm/views.py b/jperm/views.py index 77e9b1e1b..da769abfd 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -140,7 +140,7 @@ def perm_rule_add(request): rule.save() msg = u"添加授权规则:%s" % rule.name - return HttpResponseRedirect('/jperm/rule/') + return HttpResponseRedirect(reverse('rule_list')) except ServerError, e: error = e return my_render('jperm/perm_rule_add.html', locals(), request) @@ -296,7 +296,7 @@ def perm_role_add(request): role.save() role.sudo = sudos_obj msg = u"添加角色: %s" % name - return HttpResponseRedirect('/jperm/role/') + return HttpResponseRedirect(reverse('role_list')) except ServerError, e: error = e @@ -414,7 +414,7 @@ def perm_role_edit(request): role.save() msg = u"更新系统角色: %s" % role.name - return HttpResponseRedirect('/jperm/role/') + return HttpResponseRedirect(reverse('role_list')) except ServerError, e: error = e diff --git a/jumpserver/api.py b/jumpserver/api.py index 0b3c065c3..0e772eb85 100644 --- a/jumpserver/api.py +++ b/jumpserver/api.py @@ -25,6 +25,7 @@ from jumpserver.models import Setting from django.http import HttpResponseRedirect from django.shortcuts import render_to_response from django.core.mail import send_mail +from django.core.urlresolvers import reverse def set_log(level, filename='jumpserver.log'): @@ -265,15 +266,15 @@ def require_role(role='user'): def __deco(request, *args, **kwargs): request.session['pre_url'] = request.path if not request.user.is_authenticated(): - return HttpResponseRedirect('/login/') + return HttpResponseRedirect(reverse('login')) if role == 'admin': # if request.session.get('role_id', 0) < 1: if request.user.role == 'CU': - return HttpResponseRedirect('/') + return HttpResponseRedirect(reverse('index')) elif role == 'super': # if request.session.get('role_id', 0) < 2: if request.user.role in ['CU', 'GA']: - return HttpResponseRedirect('/') + return HttpResponseRedirect(reverse('index')) return func(request, *args, **kwargs) return __deco @@ -350,7 +351,7 @@ def view_splitter(request, su=None, adm=None): elif is_role_request(request, 'admin'): return adm(request) else: - return HttpResponseRedirect('/login/') + return HttpResponseRedirect(reverse('login')) def validate(request, user_group=None, user=None, asset_group=None, asset=None, edept=None): diff --git a/jumpserver/urls.py b/jumpserver/urls.py index 3be4e631a..4bce88592 100644 --- a/jumpserver/urls.py +++ b/jumpserver/urls.py @@ -1,19 +1,20 @@ from django.conf.urls import patterns, include, url -urlpatterns = patterns('', +urlpatterns = patterns('jumpserver.views', # Examples: - (r'^$', 'jumpserver.views.index'), - (r'^api/user/$', 'jumpserver.api.api_user'), - (r'^skin_config/$', 'jumpserver.views.skin_config'), - (r'^login/$', 'jumpserver.views.Login'), - (r'^logout/$', 'jumpserver.views.Logout'), - (r'^exec_cmd/$', 'jumpserver.views.exec_cmd'), - (r'^file/upload/$', 'jumpserver.views.upload'), - (r'^file/download/$', 'jumpserver.views.download'), - (r'^setting', 'jumpserver.views.setting'), - (r'^juser/', include('juser.urls')), - (r'^jasset/', include('jasset.urls')), - (r'^jlog/', include('jlog.urls')), - (r'^jperm/', include('jperm.urls')), + url(r'^$', 'index', name='index'), + # url(r'^api/user/$', 'api_user'), + url(r'^skin_config/$', 'skin_config', name='skin_config'), + url(r'^login/$', 'Login', name='login'), + url(r'^logout/$', 'Logout', name='logout'), + url(r'^exec_cmd/$', 'exec_cmd', name='exec_cmd'), + url(r'^file/upload/$', 'upload', name='file_upload'), + url(r'^file/download/$', 'download', name='file_download'), + url(r'^setting', 'setting', name='setting'), + url(r'^terminal/$', 'web_terminal', name='terminal'), + url(r'^juser/', include('juser.urls')), + url(r'^jasset/', include('jasset.urls')), + url(r'^jlog/', include('jlog.urls')), + url(r'^jperm/', include('jperm.urls')), ) diff --git a/jumpserver/views.py b/jumpserver/views.py index 9a880aa4b..49e5fc592 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -79,7 +79,7 @@ def get_count_by_date(date_li, item): @require_role(role='user') def index_cu(request): username = request.user.username - return HttpResponseRedirect('/juser/user_detail/') + return HttpResponseRedirect(reverse('user_detail')) @require_role(role='user') @@ -169,7 +169,7 @@ def Login(request): """登录界面""" error = '' if request.user.is_authenticated(): - return HttpResponseRedirect('/') + return HttpResponseRedirect(reverse('index')) if request.method == 'GET': return render_to_response('login.html') else: @@ -211,7 +211,7 @@ def Login(request): @require_role('user') def Logout(request): logout(request) - return HttpResponseRedirect('/login/') + return HttpResponseRedirect(reverse('index')) @require_role('admin') @@ -343,3 +343,11 @@ def exec_cmd(request): check_assets = request.GET.get('check_assets', '') web_terminal_uri = 'ws://%s/exec?role=%s' % (WEB_SOCKET_HOST, role) return my_render('exec_cmd.html', locals(), request) + + +@require_role('user') +def web_terminal(request): + asset_id = request.GET.get('id') + role_name = request.GET.get('role') + web_terminal_uri = 'ws://%s/terminal?id=%s&role=%s' % (WEB_SOCKET_HOST, asset_id, role_name) + return render_to_response('jlog/web_terminal.html', locals()) diff --git a/juser/urls.py b/juser/urls.py index 098587770..47952dd11 100644 --- a/juser/urls.py +++ b/juser/urls.py @@ -6,25 +6,20 @@ urlpatterns = patterns('juser.views', # Examples: # url(r'^$', 'jumpserver.views.home', name='home'), # url(r'^blog/', include('blog.urls')), - - (r'^group_add/$', group_add), - (r'^group_list/$', group_list), - (r'^group_del/$', group_del), - (r'^group_edit/$', group_edit), - - (r'^user_add/$', user_add), - (r'^user_del/$', 'user_del'), - (r'^user_list/$', user_list), - (r'^user_edit/$', user_edit), - (r'^user_detail/$', 'user_detail'), - - (r'^profile/$', 'profile'), - - (r'^send_mail_retry/$', send_mail_retry), - (r'^reset_password/$', reset_password), - (r'^forget_password/$', forget_password), - - (r'^change_info/$', 'change_info'), - (r'^regen_ssh_key/$', 'regen_ssh_key'), - (r'^down_key/$', 'down_key'), + url(r'^group/add/$', 'group_add', name='user_group_add'), + url(r'^group/list/$', 'group_list', name='user_group_list'), + url(r'^group/del/$', 'group_del', name='user_group_del'), + url(r'^group/edit/$', 'group_edit', name='user_group_edit'), + url(r'^user/add/$', 'user_add', name='user_add'), + url(r'^user/del/$', 'user_del', name='user_del'), + url(r'^user/list/$', 'user_list', name='user_list'), + url(r'^user/edit/$', 'user_edit', name='user_edit'), + url(r'^user/detail/$', 'user_detail', name='user_detail'), + url(r'^user/profile/$', 'profile', name='user_profile'), + url(r'^user/update/$', 'change_info', name='user_update'), + url(r'^mail/retry/$', 'send_mail_retry', name='mail_retry'), + url(r'^password/reset/$', 'reset_password', name='password_reset'), + url(r'^password/forget/$', 'forget_password', name='password_forget'), + url(r'^key/gen/$', 'regen_ssh_key', name='key_gen'), + url(r'^key/down/$', 'down_key', name='key_down'), ) diff --git a/juser/user_api.py b/juser/user_api.py index abe173213..0db1d556e 100644 --- a/juser/user_api.py +++ b/juser/user_api.py @@ -169,7 +169,7 @@ def user_add_mail(user, kwargs): 您的权限: %s 您的web登录密码: %s 您的ssh密钥文件密码: %s - 密钥下载地址: %s/juser/down_key/?uuid=%s + 密钥下载地址: %s/juser/key/down/?uuid=%s 说明: 请登陆后再下载密钥! """ % (user.name, user.username, user_role.get(user.role, u'普通用户'), kwargs.get('password'), kwargs.get('ssh_key_pwd'), URL, user.uuid) @@ -195,7 +195,7 @@ def get_display_msg(user, password, ssh_key_pwd, ssh_key_login_need, send_mail_n 用户名:%s 密码:%s 密钥密码:%s - 密钥下载url: %s/juser/down_key/?uuid=%s + 密钥下载url: %s/juser/key/down/?uuid=%s 该账号密码可以登陆web和跳板机。 """ % (URL, user.username, password, ssh_key_pwd, URL, user.uuid) else: diff --git a/juser/views.py b/juser/views.py index e08a92639..3e1b6eeb3 100644 --- a/juser/views.py +++ b/juser/views.py @@ -124,7 +124,7 @@ def group_edit(request): except ServerError, e: error = e if not error: - return HttpResponseRedirect('/juser/group_list/') + return HttpResponseRedirect(reverse('user_group_list')) else: users_all = User.objects.all() users_selected = User.objects.filter(group=user_group) @@ -229,7 +229,7 @@ def user_detail(request): user = get_object(User, id=user_id) if not user: - return HttpResponseRedirect('/juser/user_list/') + return HttpResponseRedirect(reverse('user_list')) user_perm_info = get_group_user_perm(user) role_assets = user_perm_info.get('role') @@ -339,7 +339,7 @@ def user_edit(request): if request.method == 'GET': user_id = request.GET.get('id', '') if not user_id: - return HttpResponseRedirect('/') + return HttpResponseRedirect(reverse('index')) user_role = {'SU': u'超级管理员', 'CU': u'普通用户'} user = get_object(User, id=user_id) @@ -364,7 +364,7 @@ def user_edit(request): if user_id: user = get_object(User, id=user_id) else: - return HttpResponseRedirect('/juser/user_list/') + return HttpResponseRedirect(reverse('user_list')) if password != '': password_decode = password @@ -392,7 +392,7 @@ def user_edit(request): """ % (user.name, URL, user.username, password_decode, user_role.get(role_post, u'')) send_mail('您的信息已修改', msg, MAIL_FROM, [email], fail_silently=False) - return HttpResponseRedirect('/juser/user_list/') + return HttpResponseRedirect(reverse('user_list')) return my_render('juser/user_edit.html', locals(), request) @@ -400,7 +400,7 @@ def user_edit(request): def profile(request): user_id = request.user.id if not user_id: - return HttpResponseRedirect('/') + return HttpResponseRedirect(reverse('index')) user = User.objects.get(id=user_id) return my_render('juser/profile.html', locals(), request) @@ -411,7 +411,7 @@ def change_info(request): user = User.objects.get(id=user_id) error = '' if not user: - return HttpResponseRedirect('/') + return HttpResponseRedirect(reverse('index')) if request.method == 'POST': name = request.POST.get('name', '') diff --git a/run_websocket.py b/run_websocket.py index f80df243b..3ecc9b578 100644 --- a/run_websocket.py +++ b/run_websocket.py @@ -270,8 +270,11 @@ class ExecHandler(tornado.websocket.WebSocketHandler): def run_cmd(self, command, pattern): self.runner.run('shell', command, pattern=pattern) + newline_pattern = re.compile(r'\n') for k, v in self.runner.results.items(): for host, output in v.items(): + output = newline_pattern.sub('
    ', output) + logger.debug(output) if k == 'ok': header = "[ %s => %s]\n" % (host, 'Ok') else: diff --git a/templates/exec_cmd.html b/templates/exec_cmd.html index b3a9d8ffe..754105cee 100644 --- a/templates/exec_cmd.html +++ b/templates/exec_cmd.html @@ -15,7 +15,7 @@ @@ -92,7 +92,7 @@ {# background-color: #ecf0f1;#} {# border: #000 solid 5px;#} background: #000; - width: 800px; + width: 720px; box-shadow: rgba(0, 0, 0, 0.8) 2px 2px 20px; color: #fff; } @@ -109,7 +109,7 @@ position: fixed; bottom: 0; height: 50px; - width: 800px; + width: 720px; {# border: #000 solid -10px;#} background-color: #2980b9; } @@ -130,7 +130,7 @@ } .content { - width: 800px; + width: 720px; margin-left: 5px; } @@ -169,11 +169,11 @@ } @media(max-width: 1000px) { - .content { width: 90%; } + .content { width: 100%; } } @media(max-width: 780px) { - #footer { height: 91px; } + #footer { height: 51px; } #chat_box { padding-bottom: 91px; } #user { width: 100%; } @@ -192,6 +192,7 @@ } } +
    diff --git a/templates/foot_script.html b/templates/foot_script.html index c9db331b9..eb653ad8c 100644 --- a/templates/foot_script.html +++ b/templates/foot_script.html @@ -28,14 +28,13 @@ diff --git a/templates/index.html b/templates/index.html index ec6afc4e5..27a048353 100644 --- a/templates/index.html +++ b/templates/index.html @@ -13,7 +13,7 @@
    用户总数
    @@ -25,7 +25,7 @@
    主机总数
    @@ -38,7 +38,7 @@
    在线用户
    -

    {{ online_user | length }}

    +

    {{ online_user | length }}

    {#
    {{ percent_online_user }}
    #} Online user
    @@ -52,7 +52,7 @@
    已连接服务器
    diff --git a/templates/index_cu.html b/templates/index_cu.html index 45632fe98..4ba361479 100644 --- a/templates/index_cu.html +++ b/templates/index_cu.html @@ -25,7 +25,7 @@
    迎使用Jumpserver跳板机系统, - 首先需要 下载 登录跳板机的SSH密钥文件,然后导入到工具或者ssh命令指定密钥文件(确保密钥文件权限600),输入收到的密钥密码,登录跳板机。 + 首先需要 下载 登录跳板机的SSH密钥文件,然后导入到工具或者ssh命令指定密钥文件(确保密钥文件权限600),输入收到的密钥密码,登录跳板机。 登录后根据提示进行操作。跳板机web界面支持修改密码、个人信息和上传下载文件等功能,可以向管理员申请权限。
    diff --git a/templates/jasset/asset_add.html b/templates/jasset/asset_add.html index 74efb345d..b12f71dd4 100644 --- a/templates/jasset/asset_add.html +++ b/templates/jasset/asset_add.html @@ -26,8 +26,8 @@
    diff --git a/templates/jasset/asset_add_batch.html b/templates/jasset/asset_add_batch.html index 56ba03ff9..cedb53246 100644 --- a/templates/jasset/asset_add_batch.html +++ b/templates/jasset/asset_add_batch.html @@ -31,8 +31,8 @@
    diff --git a/templates/jasset/asset_cu_list.html b/templates/jasset/asset_cu_list.html index 49d81e12d..af80adead 100644 --- a/templates/jasset/asset_cu_list.html +++ b/templates/jasset/asset_cu_list.html @@ -29,10 +29,10 @@
    - -
    @@ -63,7 +63,7 @@ - {{ asset.hostname|default_if_none:"" }} + {{ asset.hostname|default_if_none:"" }} {{ asset.ip|default_if_none:"" }} {{ asset.idc.name|default_if_none:"" }} {{ asset.group.all|group_str2 }} diff --git a/templates/jasset/asset_detail.html b/templates/jasset/asset_detail.html index 53f9f357a..f8e417fa0 100644 --- a/templates/jasset/asset_detail.html +++ b/templates/jasset/asset_detail.html @@ -11,7 +11,7 @@
    {{ asset.ip }}
    - + @@ -200,13 +200,13 @@ 系统角色 {% for perm in user_perm %} - {{ perm.0 }} + {{ perm.0 }} {% if perm.1 %} {% for role in perm.1 %} - + {% endfor %} {% endif %} @@ -224,7 +224,7 @@ {% for user_group in user_group_perm %} - + {% endfor %}
    {{ role }}{{ role }}
    {{ user_group }}详情详情
    @@ -238,7 +238,7 @@ {% for rule in user_rule_perm %} {{ rule }} - 详情 + 详情 {% endfor %} @@ -251,7 +251,7 @@
    主机修改记录
    -     点击修改 +     点击修改
    diff --git a/templates/jasset/asset_list.html b/templates/jasset/asset_list.html index d14a1fe5f..8aea9e1d5 100644 --- a/templates/jasset/asset_list.html +++ b/templates/jasset/asset_list.html @@ -25,7 +25,7 @@
    @@ -87,10 +87,10 @@
    - -
    @@ -121,7 +121,7 @@ - {{ asset.hostname|default_if_none:"" }} + {{ asset.hostname|default_if_none:"" }} {{ asset.ip|default_if_none:"" }} {{ asset.idc.name|default_if_none:"" }} {{ asset.group.all|group_str2 }} @@ -131,9 +131,9 @@ {{ asset.memory|default_if_none:"" }}{% if asset.memory %}G{% endif %} {{ asset.disk|get_disk_info }}{% if asset.memory %}G{% endif %} - 编辑 + 编辑 连接 - 删除 + 删除 {% endfor %} @@ -142,7 +142,7 @@
    - 修改 + 修改 {# #} @@ -174,8 +174,8 @@ }); $('#exec_cmd').click(function(){ - var url = '/jperm/role/get/'; - var new_url = '/exec_cmd/?role='; + var url = '{% url "role_get" %}'; + var new_url = '{% url "exec_cmd" %}?role='; var check_array = []; $(".gradeX input:checked").closest('tr').find('.hostname a').each(function() { check_array.push($(this).text()) @@ -194,7 +194,7 @@ title: title, maxmin: true, shade: false, - area: ['800px', '600px'], + area: ['725px', '600px'], content: new_url+data+'&check_assets='+check_assets }); //window.open(new_url + data, '', 'location=no, resizeable=no, height=410, width=625, top=89px, left=99px,toolbar=no,menubar=no,scrollbars=auto,status=no'); @@ -219,9 +219,9 @@ }); $('.conn').click(function(){ - var url='/jperm/role/get/?id=' + $(this).attr('value'); // 获取用户有权限的角色 + var url='{% url "role_get" %}?id=' + $(this).attr('value'); // 获取用户有权限的角色 var href = $(this).attr('href'); - var new_url = '/jlog/web_terminal/?id=' + $(this).attr('value') + '&role='; // webterminal socket url + var new_url = '{% url "terminal" %}?id=' + $(this).attr('value') + '&role='; // webterminal socket url var hostname = $(this).closest('tr').find('.hostname a')[0].innerHTML; $.ajax({ type: 'GET', @@ -338,7 +338,7 @@ $.ajax({ type: "post", data: {asset_id_all: asset_id_all}, - url: "/jasset/asset_del/?arg=batch", + url: "{% url 'asset_del' %}?arg=batch", success: function () { parent.location.reload(); } @@ -353,7 +353,7 @@ layer.msg('玩命更新中...', {time: 200000}); $.ajax({ type: "post", - url: "/jasset/asset_update_batch/?arg=all", + url: "{% url 'asset_update_batch' %}?arg=all", success: function () { parent.location.reload(); } @@ -365,7 +365,7 @@ $.ajax({ type: "post", data: {asset_id_all: asset_id_all}, - url: "/jasset/asset_update_batch/", + url: "{% url 'asset_add_batch' %}", success: function () { parent.location.reload(); } @@ -386,7 +386,7 @@ function change_info(){ var args = $("#asset_form").serialize(); - window.location = "/jasset/asset_list/?" + args + window.location = "{% url 'asset_list' %}?" + args } $("#search_input").keydown(function(e){ diff --git a/templates/jasset/group_list.html b/templates/jasset/group_list.html index da573bcf9..4327bc312 100644 --- a/templates/jasset/group_list.html +++ b/templates/jasset/group_list.html @@ -23,7 +23,7 @@
    - 添加主机组 + 添加主机组 删除所选
    @@ -58,12 +58,12 @@ {{ asset_group.name }} - {{ asset_group.asset_set.count }} + {{ asset_group.asset_set.count }} {{ asset_group.comment }} - 详情 - 编辑 - 删除 + 详情 + 编辑 + 删除 {% endfor %} @@ -108,7 +108,7 @@ check_array.push($(this).attr('value')) }); $.get( - '/jasset/group_del/', + '{% url "asset_group_del" %}', {id: check_array.join(',')}, function(data){ $('tr.gradeX input:checked').closest('tr').remove(); diff --git a/templates/jasset/idc_list.html b/templates/jasset/idc_list.html index bb95fcc5d..e88871320 100644 --- a/templates/jasset/idc_list.html +++ b/templates/jasset/idc_list.html @@ -17,10 +17,6 @@ @@ -29,7 +25,7 @@
    - 添加机房 + 添加机房
    @@ -64,14 +60,14 @@ {{ post.name }} - {{ post.asset_set.count }} + {{ post.asset_set.count }} {{ post.linkman }} {{ post.phone }} {{ post.comment }} - 详情 - 编辑 - 删除 + 详情 + 编辑 + 删除 {% endfor %} @@ -91,7 +87,9 @@
    +{% endblock %} +{% block self_footer_js %} - {% endblock %} \ No newline at end of file diff --git a/templates/jasset/jlist_ip.html b/templates/jasset/jlist_ip.html deleted file mode 100644 index f41dd01c8..000000000 --- a/templates/jasset/jlist_ip.html +++ /dev/null @@ -1,106 +0,0 @@ -{% load mytags %} - - - {% include 'link_css.html' %} - {% include 'head_script.html' %} - - - - - -
    -
    -

    {{ offset }}主机详情

    - - - - - - - - - - - - - - - - - - - - - - - -
    IP地址 端口号 登录方式 所属IDC 所属业务组 添加时间 备注
    {{ post.ip }} {{ post.port }} {{ post.login_type|get_login_type }} {{ post.idc.name }} {% for group in post.bis_group.all %} {{ group }} {% endfor %} {{ post.date_added|date:"Y-m-d H:i:s" }} {{ post.comment }}
    -

    {{ offset }}主机用户权限详情

    - - - - - - - - - - - -
    用户名
    - {% for user in user_permed_list %} - {{ user.name }} - {% endfor %} -
    - -

    最近一周登录详情

    - - - - - - - - - - - {% for l in log %} - - - - - - - {% endfor %} - -
    用户名 登录时间 退出时间 详情
    {{ l.user }} {{ l.start_time|date:"Y-m-d H:i:s" }} {{ l.end_time|date:"Y-m-d H:i:s" }} - 命令统计 -
    -
    -
    - - - - - \ No newline at end of file diff --git a/templates/jlog/log_exec.html b/templates/jlog/log_exec.html index 5de2ccf9f..72f392b90 100644 --- a/templates/jlog/log_exec.html +++ b/templates/jlog/log_exec.html @@ -29,10 +29,10 @@