r96383 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96382‎ | r96383 | r96384 >
Date:23:01, 6 September 2011
Author:laner
Status:deferred
Tags:
Comment:
Add a new script for linking labs users with ldap users, and make all scripts import a config file
Modified paths:
  • /trunk/tools/subversion/user-management/add-labs-user (added) (history)
  • /trunk/tools/subversion/user-management/change-ldap-passwd (modified) (history)
  • /trunk/tools/subversion/user-management/ldapsupportlib.py (modified) (history)

Diff [purge]

Index: trunk/tools/subversion/user-management/change-ldap-passwd
@@ -1,5 +1,5 @@
22 #!/usr/bin/python
3 -import sys, traceback, getpass, ldapsupportlib
 3+import sys, traceback, getpass, ldapsupportlib, string, random
44 from optparse import OptionParser
55
66 try:
@@ -17,6 +17,7 @@
1818 ldapSupportLib.addParserOptions(parser, "scriptuser")
1919
2020 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.")
2122 (options, args) = parser.parse_args()
2223
2324 if len(args) != 1:
@@ -32,15 +33,23 @@
3334 try:
3435 username = args[0]
3536 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
4350 mod_attrs = [( ldap.MOD_REPLACE, 'userPassword', newpass )]
4451 ds.modify_s(dn, mod_attrs)
 52+ if options.random:
 53+ print newpass
4554 except ldap.UNWILLING_TO_PERFORM, msg:
4655 sys.stderr.write("LDAP was unwilling to change the user's password. Error was: %s\n" % msg[0]["info"])
4756 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
141 + *
Index: trunk/tools/subversion/user-management/ldapsupportlib.py
@@ -1,5 +1,7 @@
22 #!/usr/bin/python
33 import os, traceback, getpass, sys
 4+sys.path.append('/etc/ldap')
 5+import scriptconfig
46
57 try:
68 import ldap

Status & tagging log