|
|
|
@ -137,7 +137,7 @@ def gen_ssh_key(username, password='',
|
|
|
|
|
|
|
|
|
|
if authorized_keys:
|
|
|
|
|
auth_key_dir = os.path.join(home, username, '.ssh')
|
|
|
|
|
mkdir(auth_key_dir, username=username , mode=0700)
|
|
|
|
|
mkdir(auth_key_dir, username=username, mode=0700)
|
|
|
|
|
authorized_key_file = os.path.join(auth_key_dir, 'authorized_keys')
|
|
|
|
|
with open(private_key_file+'.pub') as pub_f:
|
|
|
|
|
with open(authorized_key_file, 'w') as auth_f:
|
|
|
|
@ -146,15 +146,13 @@ def gen_ssh_key(username, password='',
|
|
|
|
|
chown(authorized_key_file, username)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def server_add_user(username, password, ssh_key_pwd='', ssh_key_login_need=True):
|
|
|
|
|
def server_add_user(username, ssh_key_pwd=''):
|
|
|
|
|
"""
|
|
|
|
|
add a system user in jumpserver
|
|
|
|
|
在jumpserver服务器上添加一个用户
|
|
|
|
|
"""
|
|
|
|
|
bash("useradd -s '%s' '%s'; echo '%s'; echo '%s:%s' | chpasswd " %
|
|
|
|
|
(os.path.join(BASE_DIR, 'init.sh'), username, password, username, password))
|
|
|
|
|
if ssh_key_login_need:
|
|
|
|
|
gen_ssh_key(username, ssh_key_pwd)
|
|
|
|
|
bash("useradd -s '%s' '%s'" % (os.path.join(BASE_DIR, 'init.sh'), username))
|
|
|
|
|
gen_ssh_key(username, ssh_key_pwd)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def user_add_mail(user, kwargs):
|
|
|
|
@ -171,7 +169,7 @@ def user_add_mail(user, kwargs):
|
|
|
|
|
您的web登录密码: %s
|
|
|
|
|
您的ssh密钥文件密码: %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)
|
|
|
|
|
send_mail(mail_title, mail_msg, MAIL_FROM, [user.email], fail_silently=False)
|
|
|
|
@ -185,27 +183,17 @@ def server_del_user(username):
|
|
|
|
|
bash('userdel -r %s' % username)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_display_msg(user, password, ssh_key_pwd, ssh_key_login_need, send_mail_need):
|
|
|
|
|
def get_display_msg(user, password, ssh_key_pwd, send_mail_need=False):
|
|
|
|
|
if send_mail_need:
|
|
|
|
|
msg = u'添加用户 %s 成功! 用户密码已发送到 %s 邮箱!' % (user.name, user.email)
|
|
|
|
|
return msg
|
|
|
|
|
|
|
|
|
|
if ssh_key_login_need:
|
|
|
|
|
msg = u"""
|
|
|
|
|
跳板机地址: %s
|
|
|
|
|
用户名:%s
|
|
|
|
|
密码:%s
|
|
|
|
|
密钥密码:%s
|
|
|
|
|
密钥下载url: %s/juser/key/down/?uuid=%s
|
|
|
|
|
该账号密码可以登陆web和跳板机。
|
|
|
|
|
""" % (URL, user.username, password, ssh_key_pwd, URL, user.uuid)
|
|
|
|
|
else:
|
|
|
|
|
msg = u"""
|
|
|
|
|
跳板机地址: %s \n
|
|
|
|
|
用户名:%s \n
|
|
|
|
|
密码:%s \n
|
|
|
|
|
跳板机地址: %s <br />
|
|
|
|
|
用户名:%s <br />
|
|
|
|
|
密码:%s <br />
|
|
|
|
|
密钥密码:%s <br />
|
|
|
|
|
密钥下载url: %s/juser/key/down/?uuid=%s <br />
|
|
|
|
|
该账号密码可以登陆web和跳板机。
|
|
|
|
|
""" % (URL, user.username, password)
|
|
|
|
|
|
|
|
|
|
""" % (URL, user.username, password, ssh_key_pwd, URL, user.uuid)
|
|
|
|
|
return msg
|
|
|
|
|
|
|
|
|
|