Attachment 'SmbPass-0.1.py'

Download

   1 # vim: fileencoding=latin2
   2 
   3 import os, re
   4 
   5 Dependencies = ['host']
   6 
   7 def change_pass(host, user, oldpass, newpass):
   8     if not re.match(r'^[A-Za-z0-9]+$', user):
   9         return 'Bad username!'
  10     if not re.match(r'^[.a-z0-9-]+$', host):
  11         return 'Bad host name!: %s' % host 
  12     (inf, errf) = os.popen4('''/usr/bin/smbpasswd -r '%s' -U '%s' -s'''%(host, user), 'rw')
  13     inf.write('%s\n'%oldpass)
  14     inf.write('%s\n'%newpass)
  15     inf.write('%s\n'%newpass)
  16     inf.close()
  17     msg = errf.read()
  18     errf.close()
  19     return msg
  20 
  21 def execute(macro, args):
  22     request = macro.request
  23     formatter = macro.formatter
  24     _ = request.getText
  25     host = args
  26     username = request.form.get('smbusername', [''])[0]
  27     oldpass = request.form.get('smbpassword', [''])[0]
  28     newpass1 = request.form.get('smbnewpassword1', [''])[0]
  29     newpass2 = request.form.get('smbnewpassword2', [''])[0]
  30     msg = ''
  31     if not username:
  32         msg = u"Please enter the username and the passwords for server %s." % host
  33     elif not oldpass:
  34         msg = u"You didn;t enter your current password."
  35     elif not (newpass1 and newpass2):
  36         msg = u"You didn't enter your new password twice."
  37     elif not newpass1==newpass2:
  38         msg = u"New password must be repeated twice. Make sure it's the same."
  39     elif not len(newpass1)>=7:
  40         msg = u'New password must be at least 7 characters long.'
  41     else:
  42         msg = change_pass(args, username, oldpass, newpass1)
  43     html = [
  44         u'<form method="post" action="" enctype="application/x-www-form-urlencoded" class="poppass" name="smbpass">',
  45         u'<p class="popmessage">', msg, u'</p>'
  46         u'<label>Username: <input type="text" name="smbusername"></label>',
  47         u'<label>Current password: <input type="password" name="smbpassword"></label>',
  48         u'<label>New password: <input type="password" name="smbnewpassword1"></label>',
  49         u'<label>Repeat new password: <input type="password" name="smbnewpassword2"></label>',
  50         u'<input type="submit" name="submit" value="Change" action="submit">',
  51         u'</form>',
  52     ]
  53     return formatter.rawHTML('\n'.join(html));

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2008-07-08 20:54:55, 2.1 KB) [[attachment:SmbPass-0.1.py]]
  • [get | view] (2006-09-07 01:00:05, 2.0 KB) [[attachment:SmbPass.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.