Index: trunk/tools/subversion/user-management/change-ldap-passwd |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | #!/usr/bin/python |
3 | | -import sys, traceback, getpass, ldapsupportlib |
| 3 | +import sys, traceback, getpass, ldapsupportlib, string, random |
4 | 4 | from optparse import OptionParser |
5 | 5 | |
6 | 6 | try: |
— | — | @@ -17,6 +17,7 @@ |
18 | 18 | ldapSupportLib.addParserOptions(parser, "scriptuser") |
19 | 19 | |
20 | 20 | parser.add_option("-m", "--directorymanager", action="store_true", dest="directorymanager", help="Use the Directory Manager's credentials, rather than your own") |
| 21 | + parser.add_option("--random", action="store_true", dest="random", help="Choose a random password, and return it.") |
21 | 22 | (options, args) = parser.parse_args() |
22 | 23 | |
23 | 24 | if len(args) != 1: |
— | — | @@ -32,15 +33,23 @@ |
33 | 34 | try: |
34 | 35 | username = args[0] |
35 | 36 | dn = 'uid=' + username + ',ou=people,' + base |
36 | | - while True: |
37 | | - newpass = getpass.getpass('New password: ') |
38 | | - repeat = getpass.getpass('Repeat new password: ') |
39 | | - if newpass != repeat: |
40 | | - print "Passwords do no match, please try again" |
41 | | - else: |
42 | | - break |
| 37 | + if options.random: |
| 38 | + chars = string.letters + string.digits + '!@#$%^&*()-=+_[]{};:.<>`~ ' |
| 39 | + newpass = '' |
| 40 | + for i in range(15): |
| 41 | + newpass = newpass + random.choice(chars) |
| 42 | + else: |
| 43 | + while True: |
| 44 | + newpass = getpass.getpass('New password: ') |
| 45 | + repeat = getpass.getpass('Repeat new password: ') |
| 46 | + if newpass != repeat: |
| 47 | + print "Passwords do no match, please try again" |
| 48 | + else: |
| 49 | + break |
43 | 50 | mod_attrs = [( ldap.MOD_REPLACE, 'userPassword', newpass )] |
44 | 51 | ds.modify_s(dn, mod_attrs) |
| 52 | + if options.random: |
| 53 | + print newpass |
45 | 54 | except ldap.UNWILLING_TO_PERFORM, msg: |
46 | 55 | sys.stderr.write("LDAP was unwilling to change the user's password. Error was: %s\n" % msg[0]["info"]) |
47 | 56 | ds.unbind() |
Index: trunk/tools/subversion/user-management/add-labs-user |
— | — | @@ -0,0 +1,39 @@ |
| 2 | +#!/usr/bin/python |
| 3 | +import sys, subprocess, ldapsupportlib |
| 4 | +from optparse import OptionParser |
| 5 | + |
| 6 | +def main(): |
| 7 | + parser = OptionParser(conflict_handler="resolve") |
| 8 | + parser.set_usage('add-labs-user --wikiname="Wiki Name" --mail="wikiname@domain.org" <username>') |
| 9 | + |
| 10 | + parser.add_option("--wikiname", action="store", dest="wikiname", help="Set the user's wiki name (required)") |
| 11 | + parser.add_option("--mail", action="store", dest="mail", help="Set the user's email address (required)") |
| 12 | + (options, args) = parser.parse_args() |
| 13 | + |
| 14 | + if len(args) != 1: |
| 15 | + parser.error("Username is required.\n") |
| 16 | + |
| 17 | + if not (options.wikiname and options.mail): |
| 18 | + parser.error("--wikiname and --mail options are required.\n") |
| 19 | + |
| 20 | + username = args[0] |
| 21 | + |
| 22 | + # Set a random password for the user |
| 23 | + passwdargs = ['/usr/local/bin/change-ldap-passwd', '--random', username] |
| 24 | + passwd = subprocess.Popen(passwdargs, stdout=PIPE).communicate()[0] |
| 25 | + |
| 26 | + # Do an initial log in as the user, which will cause the wiki to create an account |
| 27 | + # for the user. |
| 28 | + data = {'action': 'login', |
| 29 | + 'lgname': username, |
| 30 | + 'lgpassword': passwd, |
| 31 | + 'lgdomain': scriptconfig.domain |
| 32 | + } |
| 33 | + postdata = urllib.urlencode(data) |
| 34 | + resp = urllib.urlopen(scriptconfig.controllerapiurl, data=postdata) |
| 35 | + if resp.code != 200: |
| 36 | + print resp.read() |
| 37 | + resp.close() |
| 38 | + |
| 39 | +if __name__ == "__main__": |
| 40 | + main() |
Property changes on: trunk/tools/subversion/user-management/add-labs-user |
___________________________________________________________________ |
Added: svn:executable |
1 | 41 | + * |
Index: trunk/tools/subversion/user-management/ldapsupportlib.py |
— | — | @@ -1,5 +1,7 @@ |
2 | 2 | #!/usr/bin/python |
3 | 3 | import os, traceback, getpass, sys |
| 4 | +sys.path.append('/etc/ldap') |
| 5 | +import scriptconfig |
4 | 6 | |
5 | 7 | try: |
6 | 8 | import ldap |