Browse Source

修改添加的类型

pull/2/head
guanghongwei 10 years ago
parent
commit
8756172b9b
  1. 4
      jumpserver.conf
  2. 32
      webroot/AutoSa/AutoSa/views.py

4
jumpserver.conf

@ -21,6 +21,6 @@ keygen_shell = /opt/jumpserver/genkey.sh
chgpass_shell = /opt/jumpserver/chgpass.sh chgpass_shell = /opt/jumpserver/chgpass.sh
rsa_dir = /opt/jumpserver/keys rsa_dir = /opt/jumpserver/keys
ldap_host = ldap://127.0.0.1:389 ldap_host = ldap://127.0.0.1:389
ldap_base_dn = "dc=yolu,dc=com" ldap_base_dn = dc=yolu,dc=com
admin_cn = 'cn=admin,dc=yolu,dc=com' admin_cn = cn=admin,dc=yolu,dc=com
admin_pass = VNLqNCjpNBIetEoCA2h3 admin_pass = VNLqNCjpNBIetEoCA2h3

32
webroot/AutoSa/AutoSa/views.py

@ -305,18 +305,18 @@ def addUser(request):
user_dn = "uid=%s,ou=People,%s" % (username, ldap_base_dn) user_dn = "uid=%s,ou=People,%s" % (username, ldap_base_dn)
userPassword = gen_sha512(keygen(6), ldap_password) userPassword = gen_sha512(keygen(6), ldap_password)
user_attr = {'uid': [username], user_attr = {'uid': [str(username)],
'cn': [username], 'cn': [str(username)],
'objectClass': ['account', 'posixAccount', 'top', 'shadowAccount'], 'objectClass': ['account', 'posixAccount', 'top', 'shadowAccount'],
'userPassword': ['{crypt}%s' % userPassword], 'userPassword': ['{crypt}%s' % userPassword],
'shadowLastChange': ['16328'], 'shadowLastChange': ['16328'],
'shadowMin': ['0'], 'shadowMin': ['0'],
'shadowMax': ['99999'], 'shadowMax': ['99999'],
'shadowWarning': ['7'], 'shadowWarning': ['7'],
'loginShell': ['/bin/bash'], 'loginShell': ['/bin/bash'],
'uidNumber': [u.id], 'uidNumber': [str(u.id)],
'gidNumber': [u.id], 'gidNumber': [str(u.id)],
'homeDirectory': ['/home/%s' % username] 'homeDirectory': [str('/home/%s' % username)]
} }
group_dn = "cn=%s,out=Group,%s" % (username, ldap_base_dn) group_dn = "cn=%s,out=Group,%s" % (username, ldap_base_dn)
@ -324,20 +324,20 @@ def addUser(request):
'objectClass': ['posixGroup', 'top'], 'objectClass': ['posixGroup', 'top'],
'cn': [username], 'cn': [username],
'userPassword': ['{crypt}x'], 'userPassword': ['{crypt}x'],
'gidNumber': [u.id] 'gidNumber': [str(u.id)]
} }
try: try:
ldap_user = LDAPMgmt() ldap_user = LDAPMgmt()
ldap_user.add(user_dn, user_attr) ldap_user.add(user_dn, user_attr)
ldap_user.add(group_dn, group_attr) ldap_user.add(group_dn, group_attr)
except ldap.LDAPError, e: except Exception, e:
error = u'添加ladp用户失败' + unicode(e) error = u'添加ladp用户失败' + unicode(e)
try: try:
ldap_user.delete(user_dn)
ldap_user.delete(group_dn)
bash('userdel -r %s' % username) bash('userdel -r %s' % username)
u.delete() u.delete()
ldap_user.delete(user_dn)
ldap_user.delete(group_dn)
except: except:
pass pass
return render_to_response('addUser.html', {'user_menu': 'active', 'form': form, 'error': error}, return render_to_response('addUser.html', {'user_menu': 'active', 'form': form, 'error': error},

Loading…
Cancel
Save