| 1 | # -*- coding: iso-8859-1 -*- | |
|---|---|---|
| 2 | """ | |
| 3 | MoinMoin - NewPassword action | |
| 4 | ||
| 5 | This action allows you to create a new password. | |
| 6 | ||
| 7 | @copyright: 2007-2008 Alan Snelson <alan@wave2.org> | |
| 8 | @license: GNU GPL, see COPYING for details. | |
| 9 | ||
| 10 | Usage: | |
| 11 | Replace the database conenction fields and MySQL AES | |
| 12 | encyption password before copying into your MoinMoin | |
| 13 | actions folder. | |
| 14 | ||
| 15 | History: | |
| 16 | Alan Snelson: | |
| 17 | 01/02/2007 mmPasswords was born. | |
| 18 | """ | |
| 19 | ||
| 20 | import os | |
| 21 | import MySQLdb | |
| 22 | from MoinMoin import wikiutil | |
| 23 | from MoinMoin.Page import Page | |
| 24 | from MoinMoin.PageEditor import PageEditor | |
| 25 | from MoinMoin.action import ActionBase | |
| 26 | ||
| 27 | class NewPassword(ActionBase): | |
| 28 | """ | |
| 29 | NewPassword action | |
| 30 | """ | |
| 31 | ||
| 32 | def __init__(self, pagename, request): | |
| 33 | ActionBase.__init__(self, pagename, request) | |
| 34 | self.use_ticket = True | |
| 35 | _ = self._ | |
| 36 | self.form_trigger = 'newpassword' | |
| 37 | self.form_trigger_label = _('New Password') | |
| 38 | ||
| 39 | def do_action(self): | |
| 40 | """ Rename this page to "pagename" """ | |
| 41 | _ = self._ | |
| 42 | form = self.form | |
| 43 | account = form.get('account', [u''])[0] | |
| 44 | userid = form.get('userid', [u''])[0] | |
| 45 | newpassword = form.get('newpassword', [u''])[0] | |
| 46 | notes = form.get('notes', [u''])[0] | |
| 47 | notes = wikiutil.clean_comment(notes) | |
| 48 | if newpassword == 'New Password': | |
| 49 | success = False | |
| 50 | msg = 'Password field cannot be empty!.' | |
| 51 | return success, msg | |
| 52 | ||
| 53 | db=MySQLdb.connect(user="[DB Username]", passwd="[DB Password]", db="[DB Name]") | |
| 54 | #Check if password exists | |
| 55 | c=db.cursor() | |
| 56 | c.execute("""SELECT id FROM passwords WHERE account=%s AND userid=%s AND password=AES_ENCRYPT(%s,'[Insert AES Encryption Password Here]')""",(account,userid,newpassword)) | |
| 57 | row = c.fetchone() | |
| 58 | if row != None: | |
| 59 | success = False | |
| 60 | msg = 'Password already exists. To use add [[mmPassword(' + str(row[0]) + ')]]' | |
| 61 | return success, msg | |
| 62 | c.execute("""INSERT INTO passwords (account,userid,password,notes) VALUES (%s,%s,AES_ENCRYPT(%s,'[Insert AES Encryption Password Here]'),%s)""", (account,userid,newpassword,notes)) | |
| 63 | c.execute("""SELECT LAST_INSERT_ID() FROM passwords""") | |
| 64 | row = c.fetchone() | |
| 65 | success = True | |
| 66 | msg = "Password created. To use add [[mmPassword(" + str(row[0]) + ")]]" | |
| 67 | return success, msg | |
| 68 | ||
| 69 | def do_action_finish(self, success): | |
| 70 | if success: | |
| 71 | return self.page.send_page(self.request,self.error) | |
| 72 | else: | |
| 73 | self.render_msg(self.make_form()) | |
| 74 | ||
| 75 | def get_form_html(self, buttons_html): | |
| 76 | _ = self._ | |
| 77 | d = { | |
| 78 | 'pagename': self.pagename, | |
| 79 | 'account_label': _("Account"), | |
| 80 | 'userid_label': _("UserID"), | |
| 81 | 'password_label': _("Password"), | |
| 82 | 'notes_label': _("Notes"), | |
| 83 | 'buttons_html': buttons_html, | |
| 84 | } | |
| 85 | return ''' | |
| 86 | <table> | |
| 87 | <tr> | |
| 88 | <td class="label"><label>%(account_label)s</label></td> | |
| 89 | <td class="content"> | |
| 90 | <input type="text" name="account" maxlength="200"> | |
| 91 | </td> | |
| 92 | </tr> | |
| 93 | <tr> | |
| 94 | <td class="label"><label>%(userid_label)s</label></td> | |
| 95 | <td class="content"> | |
| 96 | <input type="text" name="userid" maxlength="200"> | |
| 97 | </td> | |
| 98 | </tr> | |
| 99 | <tr> | |
| 100 | <td class="label"><label>%(password_label)s</label></td> | |
| 101 | <td class="content"> | |
| 102 | <input type="text" name="newpassword"> | |
| 103 | </td> | |
| 104 | </tr> | |
| 105 | <tr> | |
| 106 | <td class="label"><label>%(notes_label)s</label></td> | |
| 107 | <td class="content"> | |
| 108 | <input type="text" name="notes" maxlength="200"> | |
| 109 | </td> | |
| 110 | </tr> | |
| 111 | <tr> | |
| 112 | <td></td> | |
| 113 | <td class="buttons"> | |
| 114 | %(buttons_html)s | |
| 115 | </td> | |
| 116 | </tr> | |
| 117 | </table> | |
| 118 | ''' % d | |
| 119 | ||
| 120 | def execute(pagename, request): | |
| 121 | """ Glue code for actions """ | |
| 122 | ||
| 123 | _ = request.getText | |
| 124 | thispage = Page(request, pagename) | |
| 125 | ||
| 126 | if request.user.valid: | |
| 127 | username = request.user.name | |
| 128 | else: | |
| 129 | username = '' | |
| 130 | ||
| 131 | if not username: | |
| 132 | return thispage.send_page(request, | |
| 133 | msg = _('Please log in first.')) | |
| 134 | ||
| 135 | NewPassword(pagename, request).render() |
| 1 | # -*- coding: iso-8859-1 -*- | |
|---|---|---|
| 2 | """ | |
| 3 | MoinMoin - Password Macro | |
| 4 | ||
| 5 | @copyright: 2007-2008 Alan Snelson - Wave2 Limited | |
| 6 | @license: GNU GPL, see COPYING for details | |
| 7 | ||
| 8 | Usage: | |
| 9 | Modify mysql connection parameters and AES | |
| 10 | encryption password before copying to the | |
| 11 | MoinMoin macros folder. | |
| 12 | ||
| 13 | """ | |
| 14 | ||
| 15 | from datetime import datetime | |
| 16 | import MySQLdb | |
| 17 | from MoinMoin.action import AttachFile | |
| 18 | from MoinMoin import wikiutil, config | |
| 19 | ||
| 20 | def execute(macro, text): | |
| 21 | """Check for valid user""" | |
| 22 | if (macro.request.user.valid == 0): | |
| 23 | return "%s%s%s" % (macro.formatter.sysmsg(1), macro.formatter.text("********"), macro.formatter.sysmsg(0)) | |
| 24 | ||
| 25 | #Connect to database | |
| 26 | db=MySQLdb.connect(user="[Database Username]", passwd="[Database Password]", db="[Database Name]") | |
| 27 | ||
| 28 | #Check if password exists | |
| 29 | c=db.cursor() | |
| 30 | c.execute("""SELECT userid, AES_DECRYPT(password,'[Insert AES Encryption Password Here]') FROM passwords WHERE id=%s""", text) | |
| 31 | row = c.fetchone() | |
| 32 | dt = datetime.now() | |
| 33 | return macro.formatter.rawHTML(""" | |
| 34 | <div id='fade""" + str(dt.microsecond) + """' class='fade'>""" + row[0] + " / " + row[1] + """</div>""") |
| 1 | -- | |
|---|---|---|
| 2 | -- Table structure for table `passwords` | |
| 3 | -- | |
| 4 | -- Import using mysql mmpasswords < mysql.sql | |
| 5 | -- | |
| 6 | -- Database must exist prior to running this script | |
| 7 | -- You can create using CREATE DATABASE 'mmpasswords'; | |
| 8 | -- | |
| 9 | ||
| 10 | DROP TABLE IF EXISTS `passwords`; | |
| 11 | CREATE TABLE `passwords` ( | |
| 12 | `id` int(11) NOT NULL auto_increment, | |
| 13 | `password` blob, | |
| 14 | `account` text, | |
| 15 | `userid` text, | |
| 16 | `notes` text, | |
| 17 | PRIMARY KEY (`id`) | |
| 18 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8; | |
| 19 | ||
| 20 | /*!40000 ALTER TABLE `passwords` ENABLE KEYS */; | |
| 21 | UNLOCK TABLES; |