Attachment 'PopPass.py'

Download

   1 # vim: fileencoding=latin2
   2 
   3 import socket
   4 
   5 Dependencies = ['host']
   6 
   7 def change_pass(host, user, oldpass, newpass):
   8     port=106
   9     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  10     s.connect((host, port))
  11     data = s.recv(1024)
  12     if data[0]=='2':
  13         s.send('user %s\r\n'%user)
  14         data = s.recv(1024)
  15         if data[0]=='2':
  16             s.send('pass %s\r\n'%oldpass)
  17             data = s.recv(1024)
  18             if data[0]=='2':
  19                 s.send('newpass %s\r\n'%newpass)
  20                 data = s.recv(1024)
  21     s.close()
  22     return data
  23 
  24 def execute(macro, args):
  25     request = macro.request
  26     formatter = macro.formatter
  27     _ = request.getText
  28     username = request.form.get('popusername', [''])[0]
  29     oldpass = request.form.get('poppassword', [''])[0]
  30     newpass1 = request.form.get('popnewpassword1', [''])[0]
  31     newpass2 = request.form.get('popnewpassword2', [''])[0]
  32     msg = ''
  33     if not username:
  34         msg = u'Please enter the username and all the passwords.'
  35     elif not oldpass:
  36         msg = u"You didn't enter your current password."
  37     elif not (newpass1 and newpass2):
  38         msg = u"You didn't enter your new password twice."
  39     elif not newpass1==newpass2:
  40         msg = u"The new password doesn't match -- please enter the same password twice."
  41     elif not len(newpass1)>=6:
  42         msg = u'The new passowrd must be at least 6 characters long.'
  43     else:
  44         msg = change_pass(args, username, oldpass, newpass1)
  45         if msg[0]=='2':
  46             msg = u'Password for <strong>%s</strong> has been changed.' % username
  47     html = [
  48         u'<form method="post" action="" enctype="application/x-www-form-urlencoded" class="poppass" name="poppass">',
  49         u'<p class="popmessage">', msg, u'</p>'
  50         u'<label>Username: <input type="text" name="popusername"></label>',
  51         u'<label>Current password: <input type="password" name="poppassword"></label>',
  52         u'<label>New password: <input type="password" name="popnewpassword1"></label>',
  53         u'<label>Repeat new password: <input type="password" name="popnewpassword2"></label>',
  54         u'<input type="submit" name="submit" value="Change" action="submit">',
  55         u'</form>',
  56     ]
  57     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] (2006-09-07 00:59:41, 2.2 KB) [[attachment:PopPass.py]]
 All files | Selected Files: delete move to page copy to page

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