From f6a228008b8a3fad9d58e7fe188e3bae7c59cbac Mon Sep 17 00:00:00 2001 From: yumaojun <719118794@qq.com> Date: Thu, 7 Jan 2016 15:15:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E6=94=B6sudo=E7=94=A8=E6=88=B7?= =?UTF-8?q?=EF=BC=8C=20=E6=B7=BB=E5=8A=A0sudo=E5=88=AB=E5=90=8D=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=A7=84=E5=88=99=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jperm/ansible_api.py | 10 ++++++++++ jperm/views.py | 6 ++++-- templates/jperm/perm_sudo_edit.html | 21 +++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/jperm/ansible_api.py b/jperm/ansible_api.py index 0ceea61d5..a71d36a63 100644 --- a/jperm/ansible_api.py +++ b/jperm/ansible_api.py @@ -364,6 +364,16 @@ class MyTask(MyRunner): self.run("user", module_args, become=True) return self.results + def del_user_sudo(self, username): + """ + delete a role sudo item + :param username: + :return: + """ + module_args = "sed -i 's/^%s.*//' /etc/sudoers" % username + self.run("command", module_args, become=True) + return self.results + @staticmethod def gen_sudo_script(role_list, sudo_list): # receive role_list = [role1, role2] sudo_list = [sudo1, sudo2] diff --git a/jperm/views.py b/jperm/views.py index 0e45319f4..26d6c4468 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -358,11 +358,13 @@ def perm_role_delete(request): recycle_resource = gen_resource(recycle_assets) task = MyTask(recycle_resource) try: - msg = task.del_user(get_object(PermRole, id=role_id).name) + msg_del_user = task.del_user(get_object(PermRole, id=role_id).name) + msg_del_sudo = task.del_user_sudo(get_object(PermRole, id=role_id).name) except Exception, e: logger.warning(u"Recycle Role failed: %s" % e) raise ServerError(u"回收已推送的系统用户失败: %s" % e) - logger.info(u"delete role %s - execute delete user: %s" % (role.name, msg)) + logger.info(u"delete role %s - execute delete user: %s" % (role.name, msg_del_user)) + logger.info(u"delete role %s - execute delete sudo: %s" % (role.name, msg_del_sudo)) # TODO: 判断返回结果,处理异常 # 删除存储的秘钥,以及目录 try: diff --git a/templates/jperm/perm_sudo_edit.html b/templates/jperm/perm_sudo_edit.html index b90fb151d..248289a40 100644 --- a/templates/jperm/perm_sudo_edit.html +++ b/templates/jperm/perm_sudo_edit.html @@ -112,7 +112,28 @@ var config = { for (var selector in config) { $(selector).chosen(config[selector]); } +$('#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(); + } +});