From 14c48bc1bf674cd913ba0293063006fb11ada8a6 Mon Sep 17 00:00:00 2001 From: guanghongwei Date: Tue, 7 Oct 2014 19:04:57 +0800 Subject: [PATCH] =?UTF-8?q?sudo=E9=8F=84=E5=89=A7=E3=81=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webroot/AutoSa/AutoSa/views.py | 16 +++++++++++++++- webroot/AutoSa/templates/showSudo.html | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 webroot/AutoSa/templates/showSudo.html diff --git a/webroot/AutoSa/AutoSa/views.py b/webroot/AutoSa/AutoSa/views.py index 3ef035d04..40e8b5335 100644 --- a/webroot/AutoSa/AutoSa/views.py +++ b/webroot/AutoSa/AutoSa/views.py @@ -120,12 +120,15 @@ class LDAPMgmt(): self.conn.simple_bind_s(admin_cn, admin_pass) def list(self, filter, scope=ldap.SCOPE_SUBTREE, attr=None): + result = {} try: ldap_result = self.conn.search_s(self.ldap_base_dn, scope, filter, attr) for entry in ldap_result: name, data = entry for k, v in data.items(): - print '%s: %s' % (k,v) + print '%s: %s' % (k, v) + result[k] = v + return result except ldap.LDAPError, e: print e @@ -605,6 +608,17 @@ def showSudo(request): username = request.GET.get('username') if not username: return HttpResponseRedirect('/showUser/') + l = LDAPMgmt() + result = l.list('entryDN=cn=%s,Sudoers,%s' % (str(username), ldap_base_dn), attr=['sudoHost', 'sudoCommand']) + sudoHost = result.get('sudoHost') + sudoCommand = result.get('sudoCommand') + return render_to_response('showSudo.html', + {'sudoHost': sudoHost, + 'sudoCommand': sudoCommand, + 'user_menu': 'active'}, + context_instance=RequestContext(request)) + + diff --git a/webroot/AutoSa/templates/showSudo.html b/webroot/AutoSa/templates/showSudo.html new file mode 100644 index 000000000..41795f5e5 --- /dev/null +++ b/webroot/AutoSa/templates/showSudo.html @@ -0,0 +1,21 @@ +{% extends 'base.html' %} +{% block content %} +
+ {{ username }} + 允许sudo的主机: + +
+ 允许的sudo命令: + + + +
+{% endblock %} \ No newline at end of file