Attachment 'SmbPass.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!'
  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     username = request.form.get('smbusername', [''])[0]
  26     oldpass = request.form.get('smbpassword', [''])[0]
  27     newpass1 = request.form.get('smbnewpassword1', [''])[0]
  28     newpass2 = request.form.get('smbnewpassword2', [''])[0]
  29     msg = ''
  30     if not username:
  31         msg = u"Please enter the username and the passwords."
  32     elif not oldpass:
  33         msg = u"You didn;t enter your current password."
  34     elif not (newpass1 and newpass2):
  35         msg = u"You didn't enter your new password twice."
  36     elif not newpass1==newpass2:
  37         msg = u"New password must be repeated twice. Make sure it's the same.'
  38     elif not len(newpass1)>=7:
  39         msg = u'New password must be at least 7 characters long.'
  40     else:
  41         msg = change_pass(args, username, oldpass, newpass1)
  42     html = [
  43         u'<form method="post" action="" enctype="application/x-www-form-urlencoded" class="poppass" name="smbpass">',
  44         u'<p class="popmessage">', msg, u'</p>'
  45         u'<label>Username: <input type="text" name="smbusername"></label>',
  46         u'<label>Current password: <input type="password" name="smbpassword"></label>',
  47         u'<label>New password: <input type="password" name="smbnewpassword1"></label>',
  48         u'<label>Repeat new password: <input type="password" name="smbnewpassword2"></label>',
  49         u'<input type="submit" name="submit" value="Change" action="submit">',
  50         u'</form>',
  51     ]
  52     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.