Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ! /usr/bin/python
- # _*_ coding: utf-8 _*_
- from __future__ import unicode_literals
- import cgi
- import uuid
- import os
- import time
- import ldap
- import sys
- def index():
- print """Content-type: text/html
- <meta charset="UTF-8">
- <head>
- </head>
- <h1>Reseting password web program</h1>"""
- #Declaring variables for the program for later use we could use input fields.
- PASSWORD_ATTR = "utf-8"
- username="joey hendricks" # Username for the user we want to change the password for.
- user_dn = "CN=%s,OU=Admin,OU=Assengraaf,DC=Assengraaf,DC=nl" % username
- password = 'New12345' # New password for the user we want to change the passwordfor.
- attr_name = 'mobile'
- attr_val = '12345678'
- print """<h1>"""+username,password+"""</h1>"""
- # Setting up connection tot the LDAP server we use a SSL engrypted connection to the server.
- # Without a SSL connection you could run into certain errors the avoid these we use SSL by defaul$
- ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
- conn = ldap.initialize("ldaps://192.168.210.1:636")
- conn.set_option(ldap.OPT_REFERRALS, 0)
- conn.set_option(ldap.OPT_PROTOCOL_VERSION, 3)
- conn.set_option(ldap.OPT_X_TLS,ldap.OPT_X_TLS_DEMAND)
- conn.set_option( ldap.OPT_X_TLS_DEMAND, True )
- conn.set_option( ldap.OPT_DEBUG_LEVEL, 255 )
- conn.simple_bind_s("administrator@assengraaf.nl","password") # Admin credentials to reset the pa$
- if conn.compare_s(user_dn, attr_name, attr_val):
- unicode_pass = unicode(""" + password + """, "iso-8859-1")
- password_value = unicode_pass.encode("utf-8")
- add_pass = [(ldap.MOD_REPLACE, PASSWORD_ATTR, [password_value])]
- try:
- conn.modify_s(user_dn, add_pass)
- conn.unbind_s() # Cancel the connection freeing up recources
- print"<p1> Password set succesfull</p1>"
- except ldap.LDAPError, e:
- sys.stderr.write('Error setting AD password for: ' + username + 'n')
- sys.stderr.write('Message: ' + str(e) + 'n')
- sys.exit(1)
- conn.unbind_s() # Cancel the connection freeing up recources
- print"<p2>Error setting password</p2>"
- else:
- print"<p3>No match found</p3>"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement