Advertisement
Guest User

Untitled

a guest
May 20th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. ! /usr/bin/python
  2. # _*_ coding: utf-8 _*_
  3. from __future__ import unicode_literals
  4. import cgi
  5. import uuid
  6. import os
  7. import time
  8. import ldap
  9. import sys
  10.  
  11. def index():
  12. print """Content-type: text/html
  13. <meta charset="UTF-8">
  14. <head>
  15. </head>
  16.  
  17. <h1>Reseting password web program</h1>"""
  18. #Declaring variables for the program for later use we could use input fields.
  19. PASSWORD_ATTR = "utf-8"
  20. username="joey hendricks" # Username for the user we want to change the password for.
  21. user_dn = "CN=%s,OU=Admin,OU=Assengraaf,DC=Assengraaf,DC=nl" % username
  22. password = 'New12345' # New password for the user we want to change the passwordfor.
  23. attr_name = 'mobile'
  24. attr_val = '12345678'
  25. print """<h1>"""+username,password+"""</h1>"""
  26. # Setting up connection tot the LDAP server we use a SSL engrypted connection to the server.
  27. # Without a SSL connection you could run into certain errors the avoid these we use SSL by defaul$
  28. ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
  29. conn = ldap.initialize("ldaps://192.168.210.1:636")
  30. conn.set_option(ldap.OPT_REFERRALS, 0)
  31. conn.set_option(ldap.OPT_PROTOCOL_VERSION, 3)
  32. conn.set_option(ldap.OPT_X_TLS,ldap.OPT_X_TLS_DEMAND)
  33. conn.set_option( ldap.OPT_X_TLS_DEMAND, True )
  34. conn.set_option( ldap.OPT_DEBUG_LEVEL, 255 )
  35. conn.simple_bind_s("administrator@assengraaf.nl","password") # Admin credentials to reset the pa$
  36.  
  37. if conn.compare_s(user_dn, attr_name, attr_val):
  38. unicode_pass = unicode(""" + password + """, "iso-8859-1")
  39. password_value = unicode_pass.encode("utf-8")
  40. add_pass = [(ldap.MOD_REPLACE, PASSWORD_ATTR, [password_value])]
  41. try:
  42. conn.modify_s(user_dn, add_pass)
  43. conn.unbind_s() # Cancel the connection freeing up recources
  44. print"<p1> Password set succesfull</p1>"
  45.  
  46. except ldap.LDAPError, e:
  47. sys.stderr.write('Error setting AD password for: ' + username + 'n')
  48. sys.stderr.write('Message: ' + str(e) + 'n')
  49. sys.exit(1)
  50. conn.unbind_s() # Cancel the connection freeing up recources
  51. print"<p2>Error setting password</p2>"
  52.  
  53. else:
  54. print"<p3>No match found</p3>"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement