mirror of https://github.com/jumpserver/jumpserver
Merge branch 'dev' of git.coding.net:jumpserver/jumpserver into dev
commit
40ae57d7ea
|
@ -1,6 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import random
|
||||
import os.path
|
||||
import shutil
|
||||
from paramiko import SSHException
|
||||
|
@ -8,9 +7,9 @@ from paramiko.rsakey import RSAKey
|
|||
from jumpserver.api import mkdir
|
||||
from uuid import uuid4
|
||||
from jumpserver.api import CRYPTOR
|
||||
from os import makedirs
|
||||
|
||||
from tempfile import NamedTemporaryFile
|
||||
from jumpserver.api import logger
|
||||
|
||||
|
||||
from jumpserver.settings import KEY_DIR
|
||||
|
||||
|
@ -55,9 +54,9 @@ def gen_keys(key="", key_path_dir=""):
|
|||
with open(key_file) as f:
|
||||
try:
|
||||
key = RSAKey.from_private_key(f)
|
||||
except SSHException:
|
||||
except SSHException, e:
|
||||
shutil.rmtree(key_path_dir, ignore_errors=True)
|
||||
raise SSHException
|
||||
raise SSHException(e)
|
||||
os.chmod(private_key, 0644)
|
||||
|
||||
with open(public_key, 'w') as content_file:
|
||||
|
|
|
@ -294,7 +294,10 @@ def perm_role_add(request):
|
|||
# 生成随机密码,生成秘钥对
|
||||
sudos_obj = [get_object(PermSudo, id=sudo_id) for sudo_id in sudo_ids]
|
||||
if key_content:
|
||||
try:
|
||||
key_path = gen_keys(key=key_content)
|
||||
except SSHException, e:
|
||||
raise ServerError(e)
|
||||
else:
|
||||
key_path = gen_keys()
|
||||
logger.debug('generate role key: %s' % key_path)
|
||||
|
@ -305,7 +308,6 @@ def perm_role_add(request):
|
|||
return HttpResponseRedirect(reverse('role_list'))
|
||||
except ServerError, e:
|
||||
error = e
|
||||
|
||||
return my_render('jperm/perm_role_add.html', locals(), request)
|
||||
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
<div class="form-group">
|
||||
<label for="role_key" class="col-sm-2 control-label">用户密钥</label>
|
||||
<div class="col-sm-8">
|
||||
<textarea class="form-control" name="role_key" placeholder="请复制粘贴私钥" rows="10" style="font-size: 9px;"></textarea>
|
||||
<textarea id='role_key' class="form-control" name="role_key" placeholder="请复制粘贴私钥" rows="10" style="font-size: 9px;"></textarea>
|
||||
<span class="help-block m-b-none">如果不添加密钥,会自动生成 </span>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -93,6 +93,7 @@ $('#roleForm').validator({
|
|||
theme: "yellow_right_effect",
|
||||
rules: {
|
||||
check_name: [/^\w{2,20}$/, '大小写字母数字和下划线,2-20位'],
|
||||
check_begin: [/^[\-]+BEGIN RSA PRIVATE KEY[\-]+/gm, '请填写正确的RSA Key'],
|
||||
{# either: function(){#}
|
||||
{# return $('#role_password').val() == ''#}
|
||||
{# }#}
|
||||
|
@ -105,6 +106,10 @@ $('#roleForm').validator({
|
|||
ok: "",
|
||||
msg: {required: "系统用户名称必填"}
|
||||
},
|
||||
"role_key": {
|
||||
rule: "required;check_begin",
|
||||
tip: "请输入正确格式的RSA私钥"
|
||||
},
|
||||
{# "role_key": {#}
|
||||
{# rule: "required(either)",#}
|
||||
{# tip: "输入密钥",#}
|
||||
|
@ -129,6 +134,8 @@ for (var selector in config) {
|
|||
$(selector).chosen(config[selector]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
<script src="/static/js/cropper/cropper.min.js"></script>
|
||||
<script src="/static/js/datapicker/bootstrap-datepicker.js"></script>
|
||||
|
|
Loading…
Reference in New Issue