pull/2/head
guanghongwei 10 years ago
parent 30cbf15b57
commit 14c48bc1bf

@ -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))

@ -0,0 +1,21 @@
{% extends 'base.html' %}
{% block content %}
<fieldset >
<legend>{{ username }}</legend>
允许sudo的主机
<ul class="list-group">
{% for host in sudoHost %}
<li class="list-group-item">{{ host }}</li>
{% endfor %}
</ul>
<br />
允许的sudo命令
<ul class="list-group">
{% for cmd in sudoCommand %}
<li class="list-group-item">{{ cmd }}</li>
{% endfor %}
</ul>
</fieldset>
{% endblock %}
Loading…
Cancel
Save