Hello,

After some busy time I'm trying to get back in touch with webware, I've
noticed that my old patch for password setting on install wasn't
incorporated, I assume it was lost so I resend it again.

If there are any comments or things to improve in it just let me know.

-- 
Baruch Even
http://baruch.ev-en.org/
Index: install.py
===================================================================
RCS file: /cvsroot/webware/Webware/install.py,v
retrieving revision 1.30
diff -u -r1.30 install.py
--- install.py  2001/10/25 03:23:59     1.30
+++ install.py  2001/11/09 13:25:53
@@ -45,7 +45,7 @@
 
        ## Running the installation ##
 
-       def run(self, verbose=0):
+       def run(self, verbose=0, passprompt=1, defaultpass=''):
                self._verbose = verbose
                if self._verbose: self.printMsg = self._printMsg
                else: self.printMsg = self._nop
@@ -55,6 +55,7 @@
                self.installDocs()
                self.backupConfigs()
                self.fixPermissions()
+               self.setupWebKitPassword(passprompt, defaultpass)
                self.finished()
                self.printGoodbye()
                return self
@@ -106,6 +107,61 @@
                print
                self._comps.sort(lambda a, b: cmp(a['name'], b['name']))
 
+
+       def setupWebKitPassword(self, prompt, defpass):
+               ''' Setup a password for WebKit Application server. '''
+               print 'Setting passwords...'
+               print
+
+               password = defpass
+
+               if prompt:
+                       print 'Choose a Password for WebKit Application Server'
+                       print 'If you will just press enter without entering anything'
+                       print 'a random password will be generated, you can check the 
+password'
+                       print 'after installation at: 
+WebKit/Configs/Application.config'
+                       import getpass
+                       password = getpass.getpass()
+               else:
+                       print 'A password is autogenerated, check the file: ',
+                       print 'WebKit/Configs/Application.config'
+                       print 'after installation for the password'
+
+               if len(password) == 0:
+                       # Generate 7 digits worth of a password.
+                       # The random function gives back a real number.
+                       characters = string.letters + string.digits
+                       
+                       import whrandom
+                       for i in range(8):
+                               password = password + whrandom.choice(characters)
+               
+               try:
+                       data = open('WebKit/Configs/Application.config', 'r').read()
+               except IOError:
+                       print 'Error reading config file, possibly a permission 
+problem,'
+                       print 'password not replaced, make sure to edit it by hand.'
+                       return
+
+               # This will search for the construct:
+               # 'AdminPassword': 'password'
+               # and replace whatever password is written there with what is
+               # given in the 'password' variable.
+               pattern = "('AdminPassword'\s*:)\s*'.*?'"
+               repl    = "\g<1>\t'%s'" % (password,)
+               import re
+               # Still need to verify that we actually found a match!
+               data = re.sub(pattern, repl, data)
+
+               try:
+                       open('WebKit/Configs/Application.config', 'w').write(data)
+               except IOError:
+                       print 'Error writing config file, possibly a permission 
+problem,'
+                       print 'password not replaced, make sure to edit it by hand.'
+                       return
+
+               print 'Password replaced successfully.'
+       
        def installDocs(self):
                self.propagateStyleSheet()
                self.processRawFiles()
@@ -412,10 +468,35 @@
                file.close()
 
 
+def printHelp():
+       print 'Usage: install.py [options]'
+       print 'Install WebWare in the local directory.'
+       print
+       print '  -h, --help                  This help screen'
+       print '  -v, --verbose               Print extra information messages during 
+install'
+       print '  --password-prompt=yes/no    Do not prompt for password during install'
+       print '                              Will autogenerate a random password'
+       print '  --set-password=password     Set the password, if you follow it with'
+       print '                              --password-prompt=yes it will be used as 
+a default'
+
 if __name__=='__main__':
-       import sys, getopt
+       import getopt
        verbose=0
-       opts, args = getopt.getopt(sys.argv[1:], "v")
+       passprompt=1
+       defaultpass=''
+       opts, args = getopt.getopt(sys.argv[1:], "hv", ["help", "verbose", 
+"password-prompt=", "set-password="])
        for o, a in opts:
-               if o in ("-v", ): verbose=1
-       Installer().run(verbose=verbose)
+               if o in ("-v", "--verbose"): verbose=1
+               if o in ("--password-prompt",):
+                       if a in ("1", "yes", "true"):
+                               passprompt=1
+                       elif a in ("0", "no", "false"):
+                               passprompt=0
+               if o in ("--set-password",):
+                       password=a
+                       passprompt=0
+               if o in ("-h", "--help"): 
+                       printHelp()
+                       sys.exit(0)
+               
+       Installer().run(verbose=verbose, passprompt=passprompt, 
+defaultpass=defaultpass)

Reply via email to