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 @@