fixed merge...

pull/26/head
yumaojun 2015-11-29 15:50:36 +08:00
commit 4d844548c2
20 changed files with 246 additions and 298 deletions

View File

@ -46,12 +46,12 @@ def scriptToJSON(scriptf, timing=None):
ret = [] ret = []
with closing(scriptf): with closing(scriptf):
print "# %s #" % scriptf.readline() # ignore first header line from script file scriptf.readline() # ignore first header line from script file
offset = 0 offset = 0
for t in timing: for t in timing:
dt = scriptf.read(t[1]) dt = scriptf.read(t[1])
data = escapeString(dt) data = escapeString(dt)
print ('###### (%s, %s)' % (t[1], repr(data))) # print ('###### (%s, %s)' % (t[1], repr(data)))
offset += t[0] offset += t[0]
ret.append((data, offset)) ret.append((data, offset))
return dumps(ret) return dumps(ret)

View File

@ -326,7 +326,7 @@ class Tasks(Command):
module_args = 'name=%s shell=/bin/bash password=%s' % (username, encrypt_pass) module_args = 'name=%s shell=/bin/bash password=%s' % (username, encrypt_pass)
self.__run(module_args, "user") self.__run(module_args, "user")
return {"status": "failed","msg": self.msg} if self.msg else {"status": "ok"} return {"status": "failed", "msg": self.msg} if self.msg else {"status": "ok"}
def add_multi_user(self, **user_info): def add_multi_user(self, **user_info):
""" """
@ -457,6 +457,7 @@ class Tasks(Command):
return result return result
class CustomAggregateStats(callbacks.AggregateStats): class CustomAggregateStats(callbacks.AggregateStats):
""" """
Holds stats about per-host activity during playbook runs. Holds stats about per-host activity during playbook runs.

View File

@ -22,6 +22,7 @@ class SysUser(models.Model):
class PermSudo(models.Model): class PermSudo(models.Model):
name = models.CharField(max_length=100, unique=True) name = models.CharField(max_length=100, unique=True)
date_added = models.DateTimeField(auto_now=True) date_added = models.DateTimeField(auto_now=True)
runas = models.CharField(max_length=200, default='root')
commands = models.TextField() commands = models.TextField()
comment = models.CharField(max_length=100, null=True, blank=True, default='') comment = models.CharField(max_length=100, null=True, blank=True, default='')

View File

@ -96,23 +96,21 @@ def gen_sudo(role_custom, role_name, role_chosen):
return sudo_file_path return sudo_file_path
def get_add_sudo_script(sudo_chosen_aliase, sudo_chosen_obj): def get_add_sudo_script(role_chosen_aliase, sudo_alias):
""" """
get the sudo file get the sudo file
:param kwargs: :param kwargs:
:return: :return:
""" """
sudo_j2 = get_template('jperm/role_sudo.j2') sudo_j2 = get_template('jperm/role_sudo.j2')
sudo_content = sudo_j2.render(Context({"sudo_chosen_aliase": sudo_chosen_aliase, sudo_content = sudo_j2.render(Context({"role_chosen_aliase": role_chosen_aliase,
"sudo_chosen_obj": sudo_chosen_obj})) "sudo_alias": sudo_alias}))
sudo_file = NamedTemporaryFile(delete=False) sudo_file = NamedTemporaryFile(delete=False)
sudo_file.write(sudo_content) sudo_file.write(sudo_content)
sudo_file.close() sudo_file.close()
print(sudo_file.name) print(sudo_file.name)
return sudo_file.name return sudo_file.name
if __name__ == "__main__": if __name__ == "__main__":
print gen_keys() print gen_keys()

View File

@ -69,17 +69,14 @@ def perm_rule_add(request):
# 渲染数据 # 渲染数据
header_title, path1, path2 = "授权规则", "规则管理", "添加规则" header_title, path1, path2 = "授权规则", "规则管理", "添加规则"
if request.method == 'GET': # 渲染数据, 获取所有 用户,用户组,资产,资产组,用户角色, 用于添加授权规则
# 渲染数据, 获取所有 用户,用户组,资产,资产组,用户角色, 用于添加授权规则 users = User.objects.all()
users = User.objects.all() user_groups = UserGroup.objects.all()
user_groups = UserGroup.objects.all() assets = Asset.objects.all()
assets = Asset.objects.all() asset_groups = AssetGroup.objects.all()
asset_groups = AssetGroup.objects.all() roles = PermRole.objects.all()
roles = PermRole.objects.all()
return my_render('jperm/perm_rule_add.html', locals(), request) if request.method == 'POST':
elif request.method == 'POST':
# 获取用户选择的 用户,用户组,资产,资产组,用户角色 # 获取用户选择的 用户,用户组,资产,资产组,用户角色
users_select = request.POST.getlist('user', []) users_select = request.POST.getlist('user', [])
user_groups_select = request.POST.getlist('usergroup', []) user_groups_select = request.POST.getlist('usergroup', [])
@ -88,45 +85,43 @@ def perm_rule_add(request):
roles_select = request.POST.getlist('role', []) roles_select = request.POST.getlist('role', [])
rule_name = request.POST.get('rulename') rule_name = request.POST.get('rulename')
rule_comment = request.POST.get('rule_comment') rule_comment = request.POST.get('rule_comment')
rule_ssh_key = request.POST.get("use_publicKey")
# 获取需要授权的主机列表 try:
assets_obj = [Asset.objects.get(ip=asset) for asset in assets_select] rule = get_object(PermRule, name=rule_name)
asset_groups_obj = [AssetGroup.objects.get(name=group) for group in asset_groups_select] if rule:
group_assets_obj = [asset for asset in [group.asset_set.all() for group in asset_groups_obj]] raise ServerError(u'授权规则 %s 已存在' % rule_name)
calc_assets = set(group_assets_obj) | set(assets_obj)
# 获取需要授权的用户列表 # 获取需要授权的主机列表
users_obj = [User.objects.get(name=user) for user in users_select] assets_obj = [Asset.objects.get(id=asset_id) for asset_id in assets_select]
user_groups_obj = [UserGroup.objects.get(name=group) for group in user_groups_select] asset_groups_obj = [AssetGroup.objects.get(id=group_id) for group_id in asset_groups_select]
group_users_obj = [user for user in [group.user_set.all() for group in user_groups_obj]] # group_assets_obj = [asset for asset in [group.asset_set.all() for group in asset_groups_obj]]
calc_users = set(group_users_obj) | set(users_obj) # calc_assets = set(group_assets_obj) | set(assets_obj)
# 获取授予的角色列表 # 获取需要授权的用户列表
roles_obj = [PermRole.objects.get(name=role) for role in roles_select] users_obj = [User.objects.get(id=user_id) for user_id in users_select]
user_groups_obj = [UserGroup.objects.get(id=group_id) for group_id in user_groups_select]
# group_users_obj = [user for user in [group.user_set.all() for group in user_groups_obj]]
# calc_users = set(group_users_obj) | set(users_obj)
# 仅授权成功的,写回数据库(授权规则,用户,用户组,资产,资产组,用户角色) # 获取授予的角色列表
rule = PermRule(name=rule_name, comment=rule_comment) roles_obj = [PermRole.objects.get(id=role_id) for role_id in roles_select]
rule.save()
rule.user = users_obj
rule.usergroup = user_groups_obj
rule.asset = assets_obj
rule.asset_group = asset_groups_obj
rule.role = roles_obj
rule.save()
msg = u"添加授权规则:%s" % rule.name # 仅授权成功的,写回数据库(授权规则,用户,用户组,资产,资产组,用户角色)
# 渲染数据 rule = PermRule(name=rule_name, comment=rule_comment)
header_title, path1, path2 = "授权规则", "规则管理", "查看规则" rule.save()
rules_list = PermRule.objects.all() rule.user = users_obj
rule.user_group = user_groups_obj
rule.asset = assets_obj
rule.asset_group = asset_groups_obj
rule.role = roles_obj
rule.save()
# TODO: 搜索和分页 msg = u"添加授权规则:%s" % rule.name
keyword = request.GET.get('search', '') # 渲染数据
if keyword: return HttpResponseRedirect('/jperm/rule/')
rules_list = rules_list.filter(Q(name=keyword)) except ServerError, e:
rules_list, p, rules, page_range, current_page, show_first, show_end = pages(rules_list, request) error = e
return my_render('jperm/perm_rule_add.html', locals(), request)
return my_render('jperm/perm_rule_list.html', locals(), request)
@require_role('admin') @require_role('admin')
@ -155,7 +150,6 @@ def perm_rule_edit(request):
assets = Asset.objects.all() assets = Asset.objects.all()
asset_groups = AssetGroup.objects.all() asset_groups = AssetGroup.objects.all()
roles = PermRole.objects.all() roles = PermRole.objects.all()
return my_render('jperm/perm_rule_edit.html', locals(), request) return my_render('jperm/perm_rule_edit.html', locals(), request)
elif request.method == 'POST' and rule_id: elif request.method == 'POST' and rule_id:
@ -168,24 +162,23 @@ def perm_rule_edit(request):
asset_groups_select = request.POST.getlist('assetgroup', []) asset_groups_select = request.POST.getlist('assetgroup', [])
roles_select = request.POST.getlist('role', []) roles_select = request.POST.getlist('role', [])
# 获取需要授权的主机列表 assets_obj = [Asset.objects.get(id=asset_id) for asset_id in assets_select]
assets_obj = [Asset.objects.get(ip=asset) for asset in assets_select] asset_groups_obj = [AssetGroup.objects.get(id=group_id) for group_id in asset_groups_select]
asset_groups_obj = [AssetGroup.objects.get(name=group) for group in asset_groups_select] # group_assets_obj = [asset for asset in [group.asset_set.all() for group in asset_groups_obj]]
group_assets_obj = [asset for asset in [group.asset_set.all() for group in asset_groups_obj]] # calc_assets = set(group_assets_obj) | set(assets_obj)
calc_assets = set(group_assets_obj) | set(assets_obj)
# 获取需要授权的用户列表 # 获取需要授权的用户列表
users_obj = [User.objects.get(name=user) for user in users_select] users_obj = [User.objects.get(id=user_id) for user_id in users_select]
user_groups_obj = [UserGroup.objects.get(name=group) for group in user_groups_select] user_groups_obj = [UserGroup.objects.get(id=group_id) for group_id in user_groups_select]
group_users_obj = [user for user in [group.user_set.all() for group in user_groups_obj]] # group_users_obj = [user for user in [group.user_set.all() for group in user_groups_obj]]
calc_users = set(group_users_obj) | set(users_obj) # calc_users = set(group_users_obj) | set(users_obj)
# 获取授予的角色列表 # 获取授予的角色列表
roles_obj = [PermRole.objects.get(name=role) for role in roles_select] roles_obj = [PermRole.objects.get(id=role_id) for role_id in roles_select]
# 仅授权成功的,写回数据库(授权规则,用户,用户组,资产,资产组,用户角色) # 仅授权成功的,写回数据库(授权规则,用户,用户组,资产,资产组,用户角色)
rule.user = users_obj rule.user = users_obj
rule.usergroup = user_groups_obj rule.user_group = user_groups_obj
rule.asset = assets_obj rule.asset = assets_obj
rule.asset_group = asset_groups_obj rule.asset_group = asset_groups_obj
rule.role = roles_obj rule.role = roles_obj
@ -194,17 +187,8 @@ def perm_rule_edit(request):
rule.save() rule.save()
msg = u"更新授权规则:%s" % rule.name msg = u"更新授权规则:%s" % rule.name
# 渲染数据
header_title, path1, path2 = "授权规则", "规则管理", "查看规则"
rules_list = PermRule.objects.all()
# TODO: 搜索和分页 return HttpResponseRedirect('/jperm/rule/')
keyword = request.GET.get('search', '')
if keyword:
rules_list = rules_list.filter(Q(name=keyword))
rules_list, p, rules, page_range, current_page, show_first, show_end = pages(rules_list, request)
return my_render('jperm/perm_rule_list.html', locals(), request)
@require_role('admin') @require_role('admin')
@ -254,37 +238,37 @@ def perm_role_add(request):
""" """
# 渲染数据 # 渲染数据
header_title, path1, path2 = "系统角色", "角色管理", "添加角色" header_title, path1, path2 = "系统角色", "角色管理", "添加角色"
sudos = PermSudo.objects.all()
if request.method == "GET": if request.method == "POST":
default_password = get_rand_pass() # 获取参数: name, comment
sudos = PermSudo.objects.all() name = request.POST.get("role_name", "")
return my_render('jperm/perm_role_add.html', locals(), request) comment = request.POST.get("role_comment", "")
password = request.POST.get("role_password", "")
elif request.method == "POST": key_content = request.POST.get("role_key", "")
# 获取参数: name, comment, sudo sudo_ids = request.POST.getlist('sudo_name')
name = request.POST.get("role_name")
comment = request.POST.get("role_comment")
password = request.POST.get("role_password")
sudos_name = request.POST.getlist("sudo_name")
sudos_obj = [PermSudo.objects.get(name=sudo_name) for sudo_name in sudos_name]
encrypt_pass = CRYPTOR.encrypt(password)
# 生成随机密码,生成秘钥对
key_path = gen_keys()
role = PermRole(name=name, comment=comment, password=encrypt_pass, key_path=key_path)
role.save()
role.sudo = sudos_obj
role.save()
msg = u"添加角色: %s" % name
# 渲染 刷新数据
header_title, path1, path2 = "系统角色", "角色管理", "查看角色"
roles_list = PermRole.objects.all()
# TODO: 搜索和分页
keyword = request.GET.get('search', '')
if keyword:
roles_list = roles_list.filter(Q(name=keyword))
try:
if get_object(PermRole, name=name):
raise ServerError('已经存在该用户 %s' % name)
if password:
encrypt_pass = CRYPTOR.encrypt(password)
else:
encrypt_pass = CRYPTOR.encrypt(CRYPTOR.gen_rand_pass(20))
# 生成随机密码,生成秘钥对
sudos_obj = [get_object(PermSudo, id=sudo_id) for sudo_id in sudo_ids]
if key_content:
key_path = gen_keys(key=key_content)
else:
key_path = gen_keys()
logger.debug('generate role key: %s' % key_path)
role = PermRole(name=name, comment=comment, password=encrypt_pass, key_path=key_path)
role.save()
role.sudo = sudos_obj
msg = u"添加角色: %s" % name
return HttpResponseRedirect('/jperm/role/')
except ServerError, e:
error = e
return my_render('jperm/perm_role_add.html', locals(), request) return my_render('jperm/perm_role_add.html', locals(), request)
@ -352,6 +336,7 @@ def perm_role_edit(request):
role_id = request.GET.get("id") role_id = request.GET.get("id")
role = PermRole.objects.get(id=role_id) role = PermRole.objects.get(id=role_id)
role_pass = CRYPTOR.decrypt(role.password) role_pass = CRYPTOR.decrypt(role.password)
sudo_all = PermSudo.objects.all()
role_sudos = role.sudo.all() role_sudos = role.sudo.all()
sudo_all = PermSudo.objects.all() sudo_all = PermSudo.objects.all()
if request.method == "GET": if request.method == "GET":
@ -363,7 +348,7 @@ def perm_role_edit(request):
role_password = request.POST.get("role_password") role_password = request.POST.get("role_password")
role_comment = request.POST.get("role_comment") role_comment = request.POST.get("role_comment")
role_sudo_names = request.POST.getlist("sudo_name") role_sudo_names = request.POST.getlist("sudo_name")
role_sudos = [PermSudo.objects.get(name=sudo_name) for sudo_name in role_sudo_names] role_sudos = [PermSudo.objects.get(id=sudo_id) for sudo_id in role_sudo_names]
key_content = request.POST.get("role_key", "") key_content = request.POST.get("role_key", "")
try: try:
@ -382,11 +367,9 @@ def perm_role_edit(request):
logger.debug('Recreate role key: %s' % role.key_path) logger.debug('Recreate role key: %s' % role.key_path)
# 写入数据库 # 写入数据库
role.name = role_name role.name = role_name
role.password = encrypt_role_pass
role.comment = role_comment role.comment = role_comment
role.sudo = role_sudos role.sudo = role_sudos
role.save() role.save()
msg = u"更新系统角色: %s" % role.name msg = u"更新系统角色: %s" % role.name
return HttpResponseRedirect('/jperm/role/') return HttpResponseRedirect('/jperm/role/')
@ -404,23 +387,19 @@ def perm_role_push(request):
# 渲染数据 # 渲染数据
header_title, path1, path2 = "系统角色", "角色管理", "角色推送" header_title, path1, path2 = "系统角色", "角色管理", "角色推送"
if request.method == "GET": roles = PermRole.objects.all()
# 渲染数据 assets = Asset.objects.all()
roles = PermRole.objects.all() asset_groups = AssetGroup.objects.all()
assets = Asset.objects.all()
asset_groups = AssetGroup.objects.all()
return my_render('jperm/perm_role_push.html', locals(), request)
if request.method == "POST": if request.method == "POST":
# 获取推荐角色的名称列表 # 获取推荐角色的名称列表
role_names = request.POST.getlist("roles") role_ids = request.POST.getlist("roles")
# 计算出需要推送的资产列表 # 计算出需要推送的资产列表
asset_ips = request.POST.getlist("assets") asset_ids = request.POST.getlist("assets")
asset_group_names = request.POST.getlist("asset_groups") asset_group_ids = request.POST.getlist("asset_groups")
assets_obj = [Asset.objects.get(ip=asset_ip) for asset_ip in asset_ips] assets_obj = [Asset.objects.get(id=asset_id) for asset_id in asset_ids]
asset_groups_obj = [AssetGroup.objects.get(name=asset_group_name) for asset_group_name in asset_group_names] asset_groups_obj = [AssetGroup.objects.get(id=asset_group_id) for asset_group_id in asset_group_ids]
group_assets_obj = [] group_assets_obj = []
for asset_group in asset_groups_obj: for asset_group in asset_groups_obj:
group_assets_obj.extend(asset_group.asset_set.all()) group_assets_obj.extend(asset_group.asset_set.all())
@ -442,10 +421,9 @@ def perm_role_push(request):
# "username": username, # "username": username,
# "password": password}) # "password": password})
push_resource = gen_resource(calc_assets) push_resource = gen_resource(calc_assets)
print push_resource
# 获取角色的推送方式,以及推送需要的信息 # 获取角色的推送方式,以及推送需要的信息
roles_obj = [PermRole.objects.get(name=role_name) for role_name in role_names] roles_obj = [PermRole.objects.get(id=role_id) for role_id in role_ids]
role_pass = {} role_pass = {}
role_key = {} role_key = {}
for role in roles_obj: for role in roles_obj:
@ -476,31 +454,28 @@ def perm_role_push(request):
ret_failed["step2-2"] = "failed" ret_failed["step2-2"] = "failed"
# 3. 推送sudo配置文件 # 3. 推送sudo配置文件
sudo_chosen_aliase = {} role_chosen_aliase = {} # {'dev': [sudo1, sudo2], 'sa': [sudo2, sudo3]}
sudo_alias = [] sudo_alias = set() # set(sudo1, sudo2, sudo3)
for role in roles_obj: for role in roles_obj:
role_alias = [sudo.name for sudo in role.sudo.all()] sudos = set([sudo for sudo in role.sudo.all()])
sudo_alias.extend(role_alias) sudo_alias.update(sudos)
sudo_chosen_aliase[role.name] = ','.join(role_alias) role_chosen_aliase[role.name] = sudos
sudo_chosen_obj = [PermSudo.objects.get(name=sudo_name) for sudo_name in set(sudo_alias)] add_sudo_script = get_add_sudo_script(role_chosen_aliase, sudo_alias)
add_sudo_script = get_add_sudo_script(sudo_chosen_aliase, sudo_chosen_obj)
ret_sudo = task.push_sudo_file(add_sudo_script) ret_sudo = task.push_sudo_file(add_sudo_script)
if ret_sudo["step1"] != "ok" or ret_sudo["step2"] != "ok": if ret_sudo["step1"] != "ok" or ret_sudo["step2"] != "ok":
ret_failed["step3"] = "failed" ret_failed["step3"] = "failed"
# os.remove(add_sudo_script) os.remove(add_sudo_script)
print ret print ret
# 结果汇总统计 # 结果汇总统计
if ret_failed: if ret_failed:
# 推送失败 # 推送失败
error = u"推送失败, 原因: %s 失败" % ','.join(ret_failed.keys()) error = u"推送失败, 原因: %s 失败" % ','.join(ret_failed.keys())
else: else:
# 推送成功 回写push表 # 推送成功 回写push表
msg = u"推送系统角色: %s" % ','.join(role_names) msg = u"推送系统角色: %s" % ','.join(role_chosen_aliase.keys())
push = PermPush(is_public_key=bool(key_push), is_password=bool(password_push)) push = PermPush(is_public_key=bool(key_push), is_password=bool(password_push))
push.save() push.save()
push.asset_group = asset_groups_obj push.asset_group = asset_groups_obj
@ -508,16 +483,7 @@ def perm_role_push(request):
push.role = roles_obj push.role = roles_obj
push.save() push.save()
# 渲染 刷新数据 return my_render('jperm/perm_role_push.html', locals(), request)
header_title, path1, path2 = "系统角色", "角色管理", "查看角色"
roles_list = PermRole.objects.all()
# TODO: 搜索和分页
keyword = request.GET.get('search', '')
if keyword:
roles_list = roles_list.filter(Q(name=keyword))
roles_list, p, roles, page_range, current_page, show_first, show_end = pages(roles_list, request)
return my_render('jperm/perm_role_list.html', locals(), request)
@require_role('admin') @require_role('admin')
@ -553,34 +519,22 @@ def perm_sudo_add(request):
# 渲染数据 # 渲染数据
header_title, path1, path2 = "Sudo命令", "别名管理", "添加别名" header_title, path1, path2 = "Sudo命令", "别名管理", "添加别名"
if request.method == "GET": if request.method == "POST":
return my_render('jperm/perm_sudo_add.html', locals(), request)
elif request.method == "POST":
# 获取参数: name, comment # 获取参数: name, comment
name = request.POST.get("sudo_name") name = request.POST.get("sudo_name").strip()
comment = request.POST.get("sudo_comment") runas = request.POST.get('sudo_runas', 'root').strip()
commands = request.POST.get("sudo_commands") comment = request.POST.get("sudo_comment").strip()
commands = request.POST.get("sudo_commands").strip()
sudo = PermSudo(name=name.strip(), comment=comment, commands=commands.strip()) if get_object(PermSudo, name=name):
sudo.save() error = 'Sudo别名 %s已经存在' % name
else:
msg = u"添加Sudo命令别名: %s" % name sudo = PermSudo(name=name.strip(), runas=runas, comment=comment, commands=commands.strip())
sudo.save()
msg = u"添加Sudo命令别名: %s" % name
# 渲染数据 # 渲染数据
header_title, path1, path2 = "Sudo命令", "别名管理", "查看别名"
# 获取所有sudo 命令别名
sudos_list = PermSudo.objects.all()
# TODO: 搜索和分页 return my_render('jperm/perm_sudo_add.html', locals(), request)
keyword = request.GET.get('search', '')
if keyword:
roles_list = sudos_list.filter(Q(name=keyword))
sudos_list, p, sudos, page_range, current_page, show_first, show_end = pages(sudos_list, request)
return my_render('jperm/perm_sudo_list.html', locals(), request)
else:
return HttpResponse(u"不支持该操作")
@require_role('admin') @require_role('admin')
@ -595,29 +549,21 @@ def perm_sudo_edit(request):
sudo_id = request.GET.get("id") sudo_id = request.GET.get("id")
sudo = PermSudo.objects.get(id=sudo_id) sudo = PermSudo.objects.get(id=sudo_id)
if request.method == "GET":
return my_render('jperm/perm_sudo_edit.html', locals(), request)
if request.method == "POST": if request.method == "POST":
name = request.POST.get("sudo_name") name = request.POST.get("sudo_name")
commands = request.POST.get("sudo_commands") commands = request.POST.get("sudo_commands")
runas = request.POST.get('sudo_runas', 'root')
comment = request.POST.get("sudo_comment") comment = request.POST.get("sudo_comment")
sudo.name = name.strip() sudo.name = name.strip()
sudo.commands = commands.strip() sudo.commands = commands.strip()
sudo.runas = runas.strip()
sudo.comment = comment sudo.comment = comment
sudo.save() sudo.save()
msg = u"更新命令别名: %s" % name msg = u"更新命令别名: %s" % name
# 渲染数据
header_title, path1, path2 = "Sudo命令", "别名管理", "查看别名" return my_render('jperm/perm_sudo_edit.html', locals(), request)
# 获取所有sudo 命令别名
sudos_list = PermSudo.objects.all()
# TODO: 搜索和分页
keyword = request.GET.get('search', '')
if keyword:
sudos_list = sudos_list.filter(Q(name=keyword))
sudos_list, p, sudos, page_range, current_page, show_first, show_end = pages(sudos_list, request)
return my_render('jperm/perm_sudo_list.html', locals(), request)
@require_role('admin') @require_role('admin')

View File

@ -250,6 +250,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
if asset: if asset:
roles = user_have_perm(self.user, asset) roles = user_have_perm(self.user, asset)
logger.debug(roles) logger.debug(roles)
logger.debug('rolename: %s' % role_name)
login_role = '' login_role = ''
for role in roles: for role in roles:
if role.name == role_name: if role.name == role_name:

View File

@ -31,7 +31,7 @@
<div class="col-sm-7" style="padding-left: 0px"> <div class="col-sm-7" style="padding-left: 0px">
<label> <label>
<select name="idc" class="form-control m-b" onchange="change_info()"> <select name="idc" class="form-control m-b" onchange="change_info()">
<option value="">IDC机房</option> <option value="">机房</option>
{% for idc in idc_all %} {% for idc in idc_all %}
{% ifequal idc.name idc_name %} {% ifequal idc.name idc_name %}
<option value="{{idc.name}}" selected> {{ idc.name }}</option> <option value="{{idc.name}}" selected> {{ idc.name }}</option>
@ -57,7 +57,7 @@
<label> <label>
<select name="asset_type" class="form-control m-b" onchange="change_info()"> <select name="asset_type" class="form-control m-b" onchange="change_info()">
<option value="">所有类型</option> <option value="">资产类型</option>
{% for type in asset_types %} {% for type in asset_types %}
{% ifequal type.0|int2str asset_type %} {% ifequal type.0|int2str asset_type %}
<option value="{{ type.0 }}" selected> {{ type.1 }}</option> <option value="{{ type.0 }}" selected> {{ type.1 }}</option>
@ -70,7 +70,7 @@
<label> <label>
<select name="status" class="form-control m-b" onchange="change_info()"> <select name="status" class="form-control m-b" onchange="change_info()">
<option value="">所有状态</option> <option value="">资产状态</option>
{% for s in asset_status %} {% for s in asset_status %}
{% ifequal s.0|int2str status %} {% ifequal s.0|int2str status %}
<option value="{{ s.0 }}" selected> {{ s.1 }}</option> <option value="{{ s.0 }}" selected> {{ s.1 }}</option>
@ -215,7 +215,7 @@
maxmin: true, maxmin: true,
shade: false, shade: false,
area: ['628px', '452px'], area: ['628px', '452px'],
content: new_url content: new_url+data
}); });
//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'); //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');
} else if (dataArray.length == '1' && data == 'error'){ } else if (dataArray.length == '1' && data == 'error'){

View File

@ -29,7 +29,7 @@
</div> </div>
<div class="ibox-content"> <div class="ibox-content">
<div class=""> <div class="">
<a target="_blank" href="/jasset/idc_add" class="btn btn-sm btn-primary "> 添加IDC </a> <a target="_blank" href="/jasset/idc_add" class="btn btn-sm btn-primary "> 添加机房 </a>
<input type="button" id="del_check" class="btn btn-danger btn-sm" name="del_button" value="删除所选"/> <input type="button" id="del_check" class="btn btn-danger btn-sm" name="del_button" value="删除所选"/>
<form id="search_form" method="get" action="" class="pull-right mail-search"> <form id="search_form" method="get" action="" class="pull-right mail-search">
<div class="input-group"> <div class="input-group">

View File

@ -97,7 +97,7 @@
<td class="text-center"> {{ post.login_type }} </td> <td class="text-center"> {{ post.login_type }} </td>
<td class="text-center"><a href="/jlog/history/?id={{ post.id }}" class="log_command"> 统计 </a></td> <td class="text-center"><a href="/jlog/history/?id={{ post.id }}" class="log_command"> 统计 </a></td>
<td class="text-center"><a class="monitor" file_path="{{ post.log_path }}"> 监控 </a></td> <td class="text-center"><a class="monitor" file_path="{{ post.log_path }}"> 监控 </a></td>
<td class="text-center"><input type="button" id="cut" class="btn btn-danger btn-xs" name="cut" value="阻断" onclick='cut("{{ post.pid }}", "{{ post.remote_ip }}")' /></td> <td class="text-center"><input type="button" id="cut" class="btn btn-danger btn-xs" name="cut" value="阻断" onclick='cut("{{ post.pid }}", "{{ post.login_type }}")' /></td>
<td class="text-center" id="start_time"> {{ post.start_time|date:"Y-m-d H:i:s" }} </td> <td class="text-center" id="start_time"> {{ post.start_time|date:"Y-m-d H:i:s" }} </td>
</tr> </tr>
{% endfor %} {% endfor %}
@ -189,9 +189,9 @@
}); });
}); });
function cut(num, host){ function cut(num, login_type){
console.log(host); console.log(login_type);
if (host=='Web'){ if (login_type=='web'){
var g_url = '{{ web_kill_uri }}' + '?id=' + num; var g_url = '{{ web_kill_uri }}' + '?id=' + num;
} else { } else {
var g_url = "/jlog/log_kill/?id=" + num; var g_url = "/jlog/log_kill/?id=" + num;

View File

@ -56,11 +56,11 @@
</div> </div>
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
<div class="form-group"> <div class="form-group">
<label for="sudo" class="col-sm-2 control-label">角色Sudo命令<span class="red-fonts">*</span></label> <label for="sudo" class="col-sm-2 control-label">角色Sudo命令</label>
<div class="col-sm-8" id="sudo_name"> <div class="col-sm-8" id="sudo_name">
<select name="sudo_name" data-placeholder="请选择Sudo别名" class="chosen-select form-control m-b" multiple tabindex="2"> <select name="sudo_name" data-placeholder="请选择Sudo别名" class="chosen-select form-control m-b" multiple tabindex="2">
{% for sudo in sudos %} {% for sudo in sudos %}
<option >{{ sudo.name }}</option> <option value="{{ sudo.id }}">{{ sudo.name }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
@ -93,9 +93,9 @@ $('#roleForm').validator({
theme: "yellow_right_effect", theme: "yellow_right_effect",
rules: { rules: {
check_name: [/^\w{2,20}$/, '大小写字母数字和下划线,2-20位'], check_name: [/^\w{2,20}$/, '大小写字母数字和下划线,2-20位'],
either: function(){ {# either: function(){#}
return $('#role_password').val() == '' {# return $('#role_password').val() == ''#}
} {# }#}
}, },
fields: { fields: {
@ -105,12 +105,12 @@ $('#roleForm').validator({
ok: "", ok: "",
msg: {required: "角色名称必填"} msg: {required: "角色名称必填"}
}, },
"role_key": { {# "role_key": {#}
rule: "required(either)", {# rule: "required(either)",#}
tip: "输入密钥", {# tip: "输入密钥",#}
ok: "", {# ok: "",#}
msg: {required: "密码和密钥必填一个!"} {# msg: {required: "密码和密钥必填一个!"}#}
} {# }#}
}, },
valid: function(form) { valid: function(form) {
form.submit(); form.submit();

View File

@ -61,7 +61,7 @@
<div class="col-sm-8"> <div class="col-sm-8">
<select name="sudo_name" data-placeholder="请选择Sudo别名" class="chosen-select form-control m-b" multiple tabindex="2"> <select name="sudo_name" data-placeholder="请选择Sudo别名" class="chosen-select form-control m-b" multiple tabindex="2">
{% for sudo in sudo_all %} {% for sudo in sudo_all %}
<option value="{{ sudo.name }}" {% if sudo in role_sudos %} selected {% endif %}>{{ sudo.name }}</option> <option value="{{ sudo.id }}" {% if sudo in role_sudos %} selected {% endif %}>{{ sudo.name }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>

View File

@ -33,7 +33,7 @@
<div class="ibox-content"> <div class="ibox-content">
<div class=""> <div class="">
<a href="/jperm/role/perm_role_add/" class="btn btn-sm btn-primary "> 添加角色 </a> <a href="/jperm/role/perm_role_add/" class="btn btn-sm btn-primary "> 添加角色 </a>
<a href="/jperm/role/perm_role_push/" class="btn btn-sm btn-primary "> 推送角色 </a> <a href="/jperm/role/perm_role_push/" class="btn btn-sm btn-danger "> 推送角色 </a>
<form id="search_form" method="get" action="" class="pull-right mail-search"> <form id="search_form" method="get" action="" class="pull-right mail-search">
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control input-sm" id="search_input" name="search" placeholder="Search"> <input type="text" class="form-control input-sm" id="search_input" name="search" placeholder="Search">

View File

@ -26,7 +26,7 @@
</div> </div>
</div> </div>
<div class="ibox-content"> <div class="ibox-content">
<form method="post" id="userForm" class="form-horizontal" action=""> <form method="post" id="pushForm" class="form-horizontal" action="">
{% if error %} {% if error %}
<div class="alert alert-warning text-center">{{ error }}</div> <div class="alert alert-warning text-center">{{ error }}</div>
{% endif %} {% endif %}
@ -34,22 +34,22 @@
<div class="alert alert-success text-center">{{ msg }}</div> <div class="alert alert-success text-center">{{ msg }}</div>
{% endif %} {% endif %}
<div class="form-group"> <div class="form-group">
<label for="asset" class="col-sm-2 control-label">资产<span class="red-fonts">*</span></label> <label for="asset" class="col-sm-2 control-label">资产</label>
<div class="col-sm-8"> <div class="col-sm-8">
<select name="assets" data-placeholder="请选择资产" class="chosen-select form-control m-b" multiple tabindex="2"> <select name="assets" id="assets" data-placeholder="请选择资产" class="chosen-select form-control m-b" multiple tabindex="2">
{% for asset in assets %} {% for asset in assets %}
<option value="{{ asset.ip }}">{{ asset.ip }}</option> <option value="{{ asset.id }}">{{ asset.ip }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
</div> </div>
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
<div class="form-group"> <div class="form-group">
<label for="assetgroup" class="col-sm-2 control-label">资产组<span class="red-fonts">*</span></label> <label for="assetgroup" class="col-sm-2 control-label">资产组</label>
<div class="col-sm-8"> <div class="col-sm-8">
<select name="asset_groups" data-placeholder="请选择资产组" class="chosen-select form-control m-b" multiple tabindex="2"> <select name="asset_groups" data-placeholder="请选择资产组" class="chosen-select form-control m-b" multiple tabindex="2">
{% for asset_group in asset_groups %} {% for asset_group in asset_groups %}
<option value="{{ asset_group.name }}">{{ asset_group.name }}</option> <option value="{{ asset_group.id }}">{{ asset_group.name }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
@ -60,7 +60,7 @@
<div class="col-sm-8"> <div class="col-sm-8">
<select name="roles" data-placeholder="请选择角色" class="chosen-select form-control m-b" multiple tabindex="2"> <select name="roles" data-placeholder="请选择角色" class="chosen-select form-control m-b" multiple tabindex="2">
{% for role in roles %} {% for role in roles %}
<option value="{{ role.name }}">{{ role.name }}</option> <option value="{{ role.id }}">{{ role.name }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
@ -68,11 +68,11 @@
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
<div class="row"> <div class="row">
<div class="form-group"> <div class="form-group">
<label for="j_group" class="col-sm-2 control-label">使用</label> <label for="j_group" class="col-sm-2 control-label">使用</label>
<div class="col-sm-1"> <div class="col-sm-1">
<div class="radio i-checks"> <div class="radio i-checks">
<label> <label>
<input type="checkbox" value="1" id="use_publicKey" name="use_publicKey"> <input type="checkbox" value="1" id="use_publicKey" name="use_publicKey" checked>
</label> </label>
</div> </div>
</div> </div>
@ -111,38 +111,34 @@
{% endblock %} {% endblock %}
{% block self_footer_js %} {% block self_footer_js %}
<script> <script>
$(document).ready(function(){ $('#pushForm').validator({
$("input.role").click(function(){ timely: 2,
if($("input.role[value=GA]").is( ":checked" )){ theme: "yellow_right_effect",
$("#admin_groups").css("display", 'none'); rules: {
check_name: [/^\w{2,20}$/, '大小写字母数字和下划线,2-20位'],
check_asset: function(){
return $('#assets').val() == null
} }
else { },
fields: {
$("#admin_groups").css("display", 'block'); "asset_groups": {
rule: "required(check_asset)",
tip: "输入资产组",
msg: {required: "资产和资产组必选一个!"}
},
"roles": {
rule: "required",
tip: "请选择角色",
msg: {required: "必须选择角色"}
} }
}); },
valid: function(form) {
$('#use_password').click(function(){ form.submit();
if ($(this).is(':checked')){
$('#admin_account_password').css('display', 'block')
} }
else {
$('#admin_account_password').css('display', 'none')
}
});
$('#use_publicKey').click(function(){
if ($(this).is(':checked')){
$('#admin_account_publicKey').css('display', 'block')
}
else {
$('#admin_account_publicKey').css('display', 'none')
}
});
}); });
var config = { var config = {
'.chosen-select' : {}, '.chosen-select' : {},
'.chosen-select-deselect' : {allow_single_deselect:true}, '.chosen-select-deselect' : {allow_single_deselect:true},

View File

@ -44,9 +44,8 @@
<label for="user" class="col-sm-2 control-label">用户</label> <label for="user" class="col-sm-2 control-label">用户</label>
<div class="col-sm-8"> <div class="col-sm-8">
<select name="user" id="user" data-placeholder="用户名" class="chosen-select form-control m-b" multiple tabindex="2"> <select name="user" id="user" data-placeholder="用户名" class="chosen-select form-control m-b" multiple tabindex="2">
{% for user in users %} {% for user in users %}
<option>{{ user.name }}</option> <option value="{{ user.id }}">{{ user.name }}</option>
{% endfor %} {% endfor %}
</select> </select>
<span class="help-block m-b-none">用户和用户组必选一个</span> <span class="help-block m-b-none">用户和用户组必选一个</span>
@ -58,7 +57,7 @@
<select name="usergroup" id="usergroup" data-placeholder="请选择用户组" class="chosen-select form-control m-b" multiple tabindex="2"> <select name="usergroup" id="usergroup" data-placeholder="请选择用户组" class="chosen-select form-control m-b" multiple tabindex="2">
{% for user_group in user_groups %} {% for user_group in user_groups %}
<option value="{{ user_group.name }}">{{ user_group.name }}</option> <option value="{{ user_group.id }}">{{ user_group.name }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
@ -69,7 +68,7 @@
<div class="col-sm-8"> <div class="col-sm-8">
<select name="asset" id="asset" data-placeholder="请选择资产" class="chosen-select form-control m-b" multiple tabindex="2"> <select name="asset" id="asset" data-placeholder="请选择资产" class="chosen-select form-control m-b" multiple tabindex="2">
{% for asset in assets %} {% for asset in assets %}
<option value="{{ asset.ip }}">{{ asset.ip }}</option> <option value="{{ asset.id }}">{{ asset.ip }}</option>
{% endfor %} {% endfor %}
</select> </select>
<span class="help-block m-b-none">资产和资产组必选一个</span> <span class="help-block m-b-none">资产和资产组必选一个</span>
@ -80,7 +79,7 @@
<div class="col-sm-8"> <div class="col-sm-8">
<select name="assetgroup" data-placeholder="请选择资产组" class="chosen-select form-control m-b" multiple tabindex="2"> <select name="assetgroup" data-placeholder="请选择资产组" class="chosen-select form-control m-b" multiple tabindex="2">
{% for asset_group in asset_groups %} {% for asset_group in asset_groups %}
<option value="{{ asset_group.name }}">{{ asset_group.name }}</option> <option value="{{ asset_group.id }}">{{ asset_group.name }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
@ -91,7 +90,7 @@
<div class="col-sm-8" id="role_name"> <div class="col-sm-8" id="role_name">
<select name="role" data-placeholder="请选择角色" class="chosen-select form-control m-b" multiple tabindex="2"> <select name="role" data-placeholder="请选择角色" class="chosen-select form-control m-b" multiple tabindex="2">
{% for role in roles %} {% for role in roles %}
<option value="{{ role.name }}">{{ role.name }}</option> <option value="{{ role.id }}">{{ role.name }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>

View File

@ -45,7 +45,7 @@
<div class="col-sm-8"> <div class="col-sm-8">
<select name="user" data-placeholder="用户名" class="chosen-select form-control m-b" multiple tabindex="2"> <select name="user" data-placeholder="用户名" class="chosen-select form-control m-b" multiple tabindex="2">
{% for user in users %} {% for user in users %}
<option value="{{ user.name }}" {% if user in users_select %} selected {% endif %}>{{ user.name }}</option> <option value="{{ user.id }}" {% if user in users_select %} selected {% endif %}>{{ user.name }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
@ -56,7 +56,7 @@
<div class="col-sm-8"> <div class="col-sm-8">
<select name="usergroup" data-placeholder="请选择用户组" class="chosen-select form-control m-b" multiple tabindex="2"> <select name="usergroup" data-placeholder="请选择用户组" class="chosen-select form-control m-b" multiple tabindex="2">
{% for user_group in user_groups %} {% for user_group in user_groups %}
<option value="{{ user_group.name }}"{% if user_group in users_groups_select %} selected {% endif %}>{{ user_group.name }}</option> <option value="{{ user_group.id }}"{% if user_group in user_groups_select %} selected {% endif %}>{{ user_group.name }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
@ -67,7 +67,7 @@
<div class="col-sm-8"> <div class="col-sm-8">
<select name="asset" data-placeholder="请选择资产" class="chosen-select form-control m-b" multiple tabindex="2"> <select name="asset" data-placeholder="请选择资产" class="chosen-select form-control m-b" multiple tabindex="2">
{% for asset in assets %} {% for asset in assets %}
<option value="{{ asset.ip }}"{% if asset in assets_select %} selected {% endif %}>{{ asset.ip }}</option> <option value="{{ asset.id }}"{% if asset in assets_select %} selected {% endif %}>{{ asset.ip }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
@ -78,7 +78,7 @@
<div class="col-sm-8"> <div class="col-sm-8">
<select name="assetgroup" data-placeholder="请选择资产组" class="chosen-select form-control m-b" multiple tabindex="2"> <select name="assetgroup" data-placeholder="请选择资产组" class="chosen-select form-control m-b" multiple tabindex="2">
{% for asset_group in asset_groups %} {% for asset_group in asset_groups %}
<option value="{{ asset_group.name }}"{% if asset_group in asset_groups_select %} selected {% endif %}>{{ asset_group.name }}</option> <option value="{{ asset_group.id }}"{% if asset_group in asset_groups_select %} selected {% endif %}>{{ asset_group.name }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
@ -89,7 +89,7 @@
<div class="col-sm-8"> <div class="col-sm-8">
<select name="role" data-placeholder="请选择角色" class="chosen-select form-control m-b" multiple tabindex="2"> <select name="role" data-placeholder="请选择角色" class="chosen-select form-control m-b" multiple tabindex="2">
{% for role in roles %} {% for role in roles %}
<option value="{{ role.name }}"{% if role in roles_select %} selected {% endif %}>{{ role.name }}</option> <option value="{{ role.id }}"{% if role in roles_select %} selected {% endif %}>{{ role.name }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
@ -118,37 +118,6 @@
{% endblock %} {% endblock %}
{% block self_footer_js %} {% block self_footer_js %}
<script> <script>
$(document).ready(function(){
$("input.role").click(function(){
if($("input.role[value=GA]").is( ":checked" )){
$("#admin_groups").css("display", 'none');
}
else {
$("#admin_groups").css("display", 'block');
}
});
$('#use_password').click(function(){
if ($(this).is(':checked')){
$('#admin_account_password').css('display', 'block')
}
else {
$('#admin_account_password').css('display', 'none')
}
});
$('#use_publicKey').click(function(){
if ($(this).is(':checked')){
$('#admin_account_publicKey').css('display', 'block')
}
else {
$('#admin_account_publicKey').css('display', 'none')
}
});
});
var config = { var config = {
'.chosen-select' : {}, '.chosen-select' : {},

View File

@ -36,9 +36,17 @@
</div> </div>
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
<div class="form-group"> <div class="form-group">
<label for="sudo_commands_label" class="col-sm-2 control-label">系统命令<span class="red-fonts">*</span></label> <label for="sudo_runas" class="col-sm-2 control-label">RunAs<span class="red-fonts">*</span></label>
<div class="col-sm-8"> <div class="col-sm-8">
<textarea id="sudo_commands" name="sudo_commands" class="form-control" rows="3"></textarea> <input id="sudo_runas" name="sudo_runas" placeholder="Sudo RunAs User" type="text" class="form-control">
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="sudo_commands" class="col-sm-2 control-label">系统命令<span class="red-fonts">*</span></label>
<div class="col-sm-8">
<textarea id="sudo_commands" name="sudo_commands" class="form-control" rows="3" placeholder="/bin/grep, /bin/find"></textarea>
<span class="help-block m-b-none">sudo命令逗号分隔, 不支持换行</span>
</div> </div>
</div> </div>
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
@ -64,7 +72,28 @@
{% endblock %} {% endblock %}
{% block self_footer_js %} {% block self_footer_js %}
<script> <script>
$('#sudoForm').validator({
timely: 2,
theme: "yellow_right_effect",
rules: {
check_name: [/^\w{2,20}$/, '大小写字母数字和下划线,2-20位']
},
fields: {
"sudo_name": {
rule: "required;check_name"
},
"sudo_runas": {
rule: "required;check_name"
},
"sudo_commands": {
rule: "required"
}
},
valid: function(form) {
form.submit();
}
});
</script> </script>
{% endblock %} {% endblock %}

View File

@ -40,6 +40,13 @@
</div> </div>
</div> </div>
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
<div class="form-group">
<label for="sudo_runas" class="col-sm-2 control-label">RunAs<span class="red-fonts">*</span></label>
<div class="col-sm-8">
<input id="sudo_runas" name="sudo_runas" placeholder="Sudo RunAs User" type="text" class="form-control" value="{{ sudo.runas }}">
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group"> <div class="form-group">
<label for="sudo_commands_label" class="col-sm-2 control-label">系统命令<span class="red-fonts">*</span></label> <label for="sudo_commands_label" class="col-sm-2 control-label">系统命令<span class="red-fonts">*</span></label>
<div class="col-sm-8"> <div class="col-sm-8">

View File

@ -6,7 +6,7 @@ sudo_file=/etc/sudoers
# Add Command Aliases # Add Command Aliases
add_cmd_alias() { add_cmd_alias() {
{% for sudo in sudo_chosen_obj %} {% for sudo in sudo_alias %}
if $(grep '^Cmnd_Alias {{ sudo.name }}' ${sudo_file} &> /dev/null); then if $(grep '^Cmnd_Alias {{ sudo.name }}' ${sudo_file} &> /dev/null); then
sed -i 's@^Cmnd_Alias.*{{ sudo.name }}.*@Cmnd_Alias {{ sudo.name }} = {{ sudo.commands }}@g' ${sudo_file} sed -i 's@^Cmnd_Alias.*{{ sudo.name }}.*@Cmnd_Alias {{ sudo.name }} = {{ sudo.commands }}@g' ${sudo_file}
else else
@ -17,12 +17,14 @@ add_cmd_alias() {
add_role_chosen() { add_role_chosen() {
{% for role, alias in sudo_chosen_aliase.items %} {% for role, sudos in role_chosen_aliase.items %}
if $(grep '^{{ role }}' ${sudo_file} &> /dev/null); then {% for sudo in sudos %}
sed -i 's@^{{ role }}.*@{{ role }} ALL = {{ alias }}@g' ${sudo_file} if $(grep '^{{ role }}.*sudo.name' ${sudo_file} &> /dev/null); then
else sed -i 's@^{{ role }}.*sudo.name@{{ role }} ALL = ({{ sudo.runas }}) NOPASSWD: {{ sudo.name }}@g' ${sudo_file}
echo "{{ role }} ALL = {{ alias }}" >> ${sudo_file} else
fi echo "{{ role }} ALL = ({{ sudo.runas }}) NOPASSWD: {{ sudo.name }}" >> ${sudo_file}
fi
{% endfor %}
{% endfor %} {% endfor %}
} }

View File

@ -28,14 +28,12 @@
<a href="/jperm/rule/">授权规则</a> <a href="/jperm/rule/">授权规则</a>
</li> </li>
<li class="sudo_list sudo_edit sudo_add cmd_list cmd_edit cmd_add sudo_detail"> <li class="role">
<a href="/jperm/role/">系统角色</a> <a href="/jperm/role/">系统角色</a>
</li> </li>
<li class="sudo_list sudo_edit sudo_add cmd_list cmd_edit cmd_add sudo_detail"> <li class="sudo">
<a href="/jperm/sudo/">Sudo命令</a> <a href="/jperm/sudo/">Sudo命令</a>
</li> </li>
<li class="apply_show online"><a href="/jperm/apply_show/online/">权限审批</a></li>
<li class="apply_show online"><a href="/jperm/log/">授权记录</a></li>
</ul> </ul>
</li> </li>

View File

@ -45,17 +45,11 @@
<div class="alert alert-success text-center">{{ msg }}</div> <div class="alert alert-success text-center">{{ msg }}</div>
{% endif %} {% endif %}
<div class="form-group"> <div class="form-group">
<label for="username" class="col-sm-2 control-label">默认用户<span class="red-fonts">*</span></label> <label for="username" class="col-sm-2 control-label">默认管理用户<span class="red-fonts">*</span></label>
<input name="setting" value="default" style="display: none"> <input name="setting" value="default" style="display: none">
<div class="col-sm-8"> <div class="col-sm-8">
<input id="username" name="username" placeholder="Username" type="text" value="{{ setting_default.field1 }}" class="form-control"> <input id="username" name="username" placeholder="Username" type="text" value="{{ setting_default.field1 }}" class="form-control">
</div> <span class="help-block m-b-none">该用户为root或用户NOPASS:ALL sudo权限的用户</span>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="port" class="col-sm-2 control-label">默认ssh端口<span class="red-fonts">*</span></label>
<div class="col-sm-8">
<input id="port" name="port" placeholder="Port" type="text" value="{{ setting_default.field2 }}" class="form-control">
</div> </div>
</div> </div>
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
@ -67,6 +61,13 @@
</div> </div>
</div> </div>
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
<div class="form-group">
<label for="port" class="col-sm-2 control-label">默认ssh端口<span class="red-fonts">*</span></label>
<div class="col-sm-8">
<input id="port" name="port" placeholder="Port" type="text" value="{{ setting_default.field2 }}" class="form-control">
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group"> <div class="form-group">
<label for="key" class="col-sm-2 control-label">默认密钥</label> <label for="key" class="col-sm-2 control-label">默认密钥</label>
<div class="col-sm-8"> <div class="col-sm-8">
@ -118,7 +119,7 @@
fields: { fields: {
"username": { "username": {
rule: "required;check_name", rule: "required;check_name",
tip: "输入用户名", tip: "输入管理用户名",
ok: "", ok: "",
msg: {required: "用户名称必填"} msg: {required: "用户名称必填"}
}, },