mirror of https://github.com/jumpserver/jumpserver
回收sudo用户, 添加sudo别名添加规则检查
parent
f6a228008b
commit
beeb2442ad
|
@ -608,25 +608,28 @@ def perm_sudo_add(request):
|
||||||
"""
|
"""
|
||||||
# 渲染数据
|
# 渲染数据
|
||||||
header_title, path1, path2 = "Sudo命令", "别名管理", "添加别名"
|
header_title, path1, path2 = "Sudo命令", "别名管理", "添加别名"
|
||||||
|
try:
|
||||||
|
if request.method == "POST":
|
||||||
|
# 获取参数: name, comment
|
||||||
|
name = request.POST.get("sudo_name").strip().upper()
|
||||||
|
comment = request.POST.get("sudo_comment").strip()
|
||||||
|
commands = request.POST.get("sudo_commands").strip()
|
||||||
|
|
||||||
if request.method == "POST":
|
if not name or not commands:
|
||||||
# 获取参数: name, comment
|
raise ServerError(u"sudo name 和 commands是必填项!")
|
||||||
name = request.POST.get("sudo_name").strip().upper()
|
|
||||||
comment = request.POST.get("sudo_comment").strip()
|
|
||||||
commands = request.POST.get("sudo_commands").strip()
|
|
||||||
|
|
||||||
pattern = re.compile(r'[\n,\r]')
|
pattern = re.compile(r'[\n,\r]')
|
||||||
commands = ', '.join(list_drop_str(pattern.split(commands), u''))
|
commands = ', '.join(list_drop_str(pattern.split(commands), u''))
|
||||||
logger.debug(u'添加sudo %s: %s' % (name, commands))
|
logger.debug(u'添加sudo %s: %s' % (name, commands))
|
||||||
|
|
||||||
if get_object(PermSudo, name=name):
|
|
||||||
error = 'Sudo别名 %s已经存在' % name
|
|
||||||
else:
|
|
||||||
sudo = PermSudo(name=name.strip(), comment=comment, commands=commands)
|
|
||||||
sudo.save()
|
|
||||||
msg = u"添加Sudo命令别名: %s" % name
|
|
||||||
# 渲染数据
|
|
||||||
|
|
||||||
|
if get_object(PermSudo, name=name):
|
||||||
|
error = 'Sudo别名 %s已经存在' % name
|
||||||
|
else:
|
||||||
|
sudo = PermSudo(name=name.strip(), comment=comment, commands=commands)
|
||||||
|
sudo.save()
|
||||||
|
msg = u"添加Sudo命令别名: %s" % name
|
||||||
|
except ServerError, e:
|
||||||
|
error = e
|
||||||
return my_render('jperm/perm_sudo_add.html', locals(), request)
|
return my_render('jperm/perm_sudo_add.html', locals(), request)
|
||||||
|
|
||||||
|
|
||||||
|
@ -643,22 +646,27 @@ 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 == "POST":
|
try:
|
||||||
name = request.POST.get("sudo_name").upper()
|
if request.method == "POST":
|
||||||
commands = request.POST.get("sudo_commands")
|
name = request.POST.get("sudo_name").upper()
|
||||||
comment = request.POST.get("sudo_comment")
|
commands = request.POST.get("sudo_commands")
|
||||||
|
comment = request.POST.get("sudo_comment")
|
||||||
|
|
||||||
pattern = re.compile(r'[\n,\r]')
|
if not name or not commands:
|
||||||
commands = ', '.join(list_drop_str(pattern.split(commands), u'')).strip()
|
raise ServerError(u"sudo name 和 commands是必填项!")
|
||||||
logger.debug(u'添加sudo %s: %s' % (name, commands))
|
|
||||||
|
|
||||||
sudo.name = name.strip()
|
pattern = re.compile(r'[\n,\r]')
|
||||||
sudo.commands = commands
|
commands = ', '.join(list_drop_str(pattern.split(commands), u'')).strip()
|
||||||
sudo.comment = comment
|
logger.debug(u'添加sudo %s: %s' % (name, commands))
|
||||||
sudo.save()
|
|
||||||
|
|
||||||
msg = u"更新命令别名: %s" % name
|
sudo.name = name.strip()
|
||||||
|
sudo.commands = commands
|
||||||
|
sudo.comment = comment
|
||||||
|
sudo.save()
|
||||||
|
|
||||||
|
msg = u"更新命令别名: %s" % name
|
||||||
|
except ServerError, e:
|
||||||
|
error = e
|
||||||
return my_render('jperm/perm_sudo_edit.html', locals(), request)
|
return my_render('jperm/perm_sudo_edit.html', locals(), request)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue