Attachment 'ShowDecrypted.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - ShowDecrypted Action
   4 
   5     PURPOSE:
   6         This action is used to display an encrypted page
   7 
   8     MODIFICATION HISTORY:
   9         @copyright: 2008 by Frank Maloschytzki (Frank.Maloschytzki@gansnett.de)
  10         @license: GNU GPL, see COPYING for details.
  11         Version: 0.1
  12 
  13     Part of code is copied from Whois.py  and test.py
  14 
  15 
  16 
  17 """
  18 
  19 from MoinMoin.Page import Page
  20 from MoinMoin.formatter.text_html import Formatter
  21 from MoinMoin.action import ActionBase
  22 from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
  23 from base64 import b64decode
  24 from Crypto.Cipher import AES
  25 
  26 
  27 PAGENAME = u'ThisPageDoesNotExistsAndWillNeverBeReally'
  28 CRYPTHEADER = u'Encrypted Page:'
  29 
  30 
  31 class ShowDecrypted(ActionBase):
  32     """ Show Decrypted page action
  33 
  34     """
  35 
  36 
  37     def __init__(self, pagename, request):
  38         ActionBase.__init__(self, pagename, request)
  39         self.use_ticket = False
  40         _ = self._
  41         self.form_trigger = 'passphrase'
  42         self.form_trigger_label = _('Show Decrypted')
  43         self.thispage = Page(request, pagename)
  44 
  45 
  46 
  47 
  48     def expandto16(self, text, fillchar=' '):
  49         """ Expand length of string to multiple of 16 by adding spaces
  50         """
  51         i = len(text) % 16
  52         if i != 0:
  53             return text + fillchar*(16-i)
  54         else:
  55             return text
  56 
  57 
  58 
  59 
  60     def parse(self, text):
  61         """Parse text and return html
  62         Create a page with text, then parse it and format using html formatter
  63         """
  64         request = self.request
  65         assert text is not None
  66         request.reset()
  67         page = Page(request, PAGENAME)
  68         page.hilite_re = None
  69         page.set_raw_body(text)
  70         formatter = Formatter(request)
  71         formatter.setPage(page)
  72         page.formatter = formatter
  73         request.formatter = formatter
  74         parser = WikiParser(text, request, line_anchors=False)
  75         formatter.startContent('') # needed for _include_stack init
  76         output = request.redirectedOutput(parser.format, formatter)
  77         formatter.endContent('')
  78         return output
  79 
  80 
  81 
  82     def do_action(self):
  83         _ = self._
  84         form = self.form
  85         passphrase = self.expandto16(form.get('pass', [u''])[0])
  86         #passphrase = form.get('pass', [u''])[0]
  87         text = self.thispage.get_body()
  88         if text.find(CRYPTHEADER) == -1:
  89             self.render_msg(_('This page is not encrypted'))
  90             return
  91         text = text[len(CRYPTHEADER):]
  92         text = b64decode(text)
  93         # Now decrypt
  94         obj = AES.new(passphrase, AES.MODE_ECB)
  95         ctext = obj.decrypt(text)
  96 
  97         self.request.formatter = Formatter(self.request)
  98         self.request.http_headers()
  99         self.request.setContentLanguage(self.request.lang)
 100         self.request.theme.send_title(self.pagename, pagename=self.pagename)
 101         self.request.write(self.request.formatter.startContent("content"))
 102         self.request.write(self.parse(unicode(ctext, 'latin-1')))
 103         self.request.write(self.request.formatter.endContent())
 104         self.request.theme.send_footer(self.pagename)
 105         
 106         return
 107 
 108     
 109     
 110 
 111     def get_form_html(self, buttons_html):
 112         _ = self._
 113         d = {
 114             'pagename': self.pagename,
 115             'pass_label': _("Passphrase"),
 116             'buttons_html': buttons_html,
 117         }
 118         return '''
 119 <table>
 120                <tr>
 121                <td class="label"><label>%(pass_label)s</label></td>
 122                <td class="content">
 123                <input type="text" name="pass" maxlength="128">
 124                </td>
 125                </tr>
 126                <tr>
 127                <td></td>
 128                <td class="buttons">
 129                %(buttons_html)s
 130                </td>
 131                </tr>
 132 </table>
 133 ''' % d
 134 
 135     
 136     
 137     
 138     def work(self):
 139         """ This is the main function called by action's
 140             execute() function.
 141 
 142             check for user and for posted forms, etc.
 143         """
 144         _ = self._
 145         form = self.form
 146 
 147         if form.has_key(self.form_cancel):
 148             self.render_cancel()
 149             return
 150 
 151         # Validate allowance, user rights and other conditions.
 152         error = None
 153         if self.is_excluded():
 154             error = _('Action %(actionname)s is excluded in this wiki!') % {'actionname': self.actionname }
 155         elif not self.is_allowed():
 156             error = _('You are not allowed to use action %(actionname)s on thispage!') % {'actionname': self.actionname }
 157         if error is None:
 158             self.check_condition()
 159         if error:
 160             self.render_msg(error)
 161         elif form.has_key(self.form_trigger) or form.has_key('pass'):
 162             # user hit the trigger button
 163             if self.ticket_ok():
 164                 self.do_action()
 165                 return
 166             else:
 167                 self.render_msg(_('Please use the interactive user interface to use action %(actionname)s!') % {'actionname': self.actionname })
 168             return
 169         else:
 170             # Return a new form
 171             self.render_msg(self.make_form())
 172 
 173 def execute(pagename, request):
 174     """ Do your work
 175     """
 176     _ = request.getText
 177 
 178 # Don't check if personal wiki
 179 #    if request.user.valid:
 180 #        username = request.user.name
 181 #    else:
 182 #        username = ''
 183 #
 184 #    if not username:
 185 #        return thispage.send_page(
 186 #            msg = _('Please log in first.'))
 187 
 188     
 189     ShowDecrypted(pagename, request).work()

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] (2011-04-14 07:28:03, 4.7 KB) [[attachment:CreateNewPage.py]]
  • [get | view] (2011-04-14 07:26:24, 4.2 KB) [[attachment:CreateNewPage1.6.py]]
  • [get | view] (2006-09-10 21:29:29, 40.4 KB) [[attachment:CreatePdfDocument2_0_3.py]]
  • [get | view] (2006-09-12 06:05:06, 40.5 KB) [[attachment:CreatePdfDocument2_0_4.py]]
  • [get | view] (2006-09-12 12:00:09, 40.6 KB) [[attachment:CreatePdfDocument2_0_5.py]]
  • [get | view] (2006-11-14 21:56:11, 43.5 KB) [[attachment:CreatePdfDocument2_0_6.py]]
  • [get | view] (2006-11-15 17:00:47, 43.8 KB) [[attachment:CreatePdfDocument2_0_7.py]]
  • [get | view] (2006-11-16 22:06:18, 43.8 KB) [[attachment:CreatePdfDocument2_0_8.py]]
  • [get | view] (2006-12-17 15:54:21, 43.6 KB) [[attachment:CreatePdfDocument2_0_9.py]]
  • [get | view] (2007-08-20 09:10:23, 67.2 KB) [[attachment:CreatePdfDocument2_1_0.py]]
  • [get | view] (2007-08-21 07:39:49, 67.1 KB) [[attachment:CreatePdfDocument2_1_1.py]]
  • [get | view] (2007-09-11 19:16:37, 67.3 KB) [[attachment:CreatePdfDocument2_1_2.py]]
  • [get | view] (2007-09-18 20:17:58, 68.1 KB) [[attachment:CreatePdfDocument2_1_3.py]]
  • [get | view] (2007-09-21 13:32:54, 71.1 KB) [[attachment:CreatePdfDocument2_1_4.py]]
  • [get | view] (2007-09-23 20:56:30, 73.4 KB) [[attachment:CreatePdfDocument2_1_5.py]]
  • [get | view] (2007-09-25 20:54:48, 74.5 KB) [[attachment:CreatePdfDocument2_2_0.py]]
  • [get | view] (2008-06-23 21:08:49, 77.0 KB) [[attachment:CreatePdfDocument2_3_0.py]]
  • [get | view] (2008-06-26 19:25:07, 81.0 KB) [[attachment:CreatePdfDocument2_3_1.py]]
  • [get | view] (2008-07-06 05:50:38, 83.1 KB) [[attachment:CreatePdfDocument2_3_2.py]]
  • [get | view] (2008-07-09 17:42:02, 83.3 KB) [[attachment:CreatePdfDocument2_3_3.py]]
  • [get | view] (2008-09-07 11:11:01, 83.5 KB) [[attachment:CreatePdfDocument2_3_4.py]]
  • [get | view] (2009-01-11 15:53:09, 84.3 KB) [[attachment:CreatePdfDocument2_3_5.py]]
  • [get | view] (2009-02-16 06:52:06, 84.2 KB) [[attachment:CreatePdfDocument2_3_6.py]]
  • [get | view] (2010-01-29 11:53:21, 82.8 KB) [[attachment:CreatePdfDocument2_4_0.py]]
  • [get | view] (2010-01-31 14:10:03, 84.6 KB) [[attachment:CreatePdfDocument2_4_1.py]]
  • [get | view] (2010-09-18 16:23:23, 85.6 KB) [[attachment:CreatePdfDocument2_4_2.py]]
  • [get | view] (2006-06-16 20:56:53, 4.9 KB) [[attachment:FlashManager.py-1.5.3-1]]
  • [get | view] (2003-12-07 18:15:53, 3.9 KB) [[attachment:HTML2MoinMoin.py]]
  • [get | view] (2005-10-16 08:24:35, 4.9 KB) [[attachment:HelpOn-1.3.5-4.py]]
  • [get | view] (2006-02-03 19:21:04, 4.9 KB) [[attachment:HelpOn-1.5.1-5.py]]
  • [get | view] (2006-07-04 10:45:22, 4.8 KB) [[attachment:HelpOn-1.5.4-6.py]]
  • [get | view] (2006-07-04 22:39:14, 4.8 KB) [[attachment:HelpOn-1.6.0-7.py]]
  • [get | view] (2006-07-06 13:50:17, 4.0 KB) [[attachment:HelpOn-1.6.0-8.py]]
  • [get | view] (2008-01-10 17:43:24, 4.8 KB) [[attachment:HelpOn-1.6.0-9.py]]
  • [get | view] (2008-08-19 14:44:54, 5.0 KB) [[attachment:HelpOn-1.7.1-10.py]]
  • [get | view] (2005-02-20 18:28:34, 10.8 KB) [[attachment:IRSS.py]]
  • [get | view] (2005-03-09 22:46:23, 2.9 KB) [[attachment:ImportHtml-1.2.py]]
  • [get | view] (2003-12-07 18:15:53, 2.8 KB) [[attachment:ImportHtml.py]]
  • [get | view] (2003-12-07 18:15:53, 1.8 KB) [[attachment:IrcChat.py]]
  • [get | view] (2008-06-09 11:27:20, 4.4 KB) [[attachment:MoinCrypt.py]]
  • [get | view] (2010-11-29 12:08:27, 7.5 KB) [[attachment:PageActions.py]]
  • [get | view] (2006-08-07 15:12:19, 0.5 KB) [[attachment:PermanentLink.py]]
  • [get | view] (2003-12-07 18:15:53, 6.3 KB) [[attachment:PhoneDial.py]]
  • [get | view] (2005-04-17 14:21:47, 3.6 KB) [[attachment:RecommendPage-1.3.4-1.py]]
  • [get | view] (2005-04-19 18:21:52, 5.5 KB) [[attachment:RecommendPage-1.3.4-2.py]]
  • [get | view] (2005-05-02 19:53:09, 5.6 KB) [[attachment:RecommendPage-1.3.4-3.py]]
  • [get | view] (2005-09-03 07:33:35, 6.3 KB) [[attachment:RecommendPage-1.3.4-4.py]]
  • [get | view] (2005-09-05 17:44:03, 6.9 KB) [[attachment:RecommendPage-1.3.5-5.py]]
  • [get | view] (2005-09-07 16:42:26, 7.5 KB) [[attachment:RecommendPage-1.3.5-6.py]]
  • [get | view] (2005-09-08 16:06:28, 7.7 KB) [[attachment:RecommendPage-1.3.5-7.py]]
  • [get | view] (2005-11-01 11:31:51, 9.0 KB) [[attachment:RecommendPage-1.3.5-8.py]]
  • [get | view] (2006-02-03 19:40:51, 8.3 KB) [[attachment:RecommendPage-1.5.1-9.py]]
  • [get | view] (2008-01-11 09:14:35, 6.8 KB) [[attachment:RecommendPage-1.6.0-10.py]]
  • [get | view] (2008-08-19 14:44:59, 6.9 KB) [[attachment:RecommendPage-1.7.1-11.py]]
  • [get | view] (2008-06-09 11:27:40, 1.7 KB) [[attachment:ShowActions.py]]
  • [get | view] (2008-06-09 10:34:02, 5.3 KB) [[attachment:ShowDecrypted.py]]
  • [get | view] (2005-03-30 21:17:28, 7.7 KB) [[attachment:Slideshow.py]]
  • [get | view] (2004-02-02 20:48:31, 2.0 KB) [[attachment:SubscribeUser.py]]
  • [get | view] (2007-01-26 17:08:30, 2.2 KB) [[attachment:Subscribers-1.6.0.py]]
  • [get | view] (2003-12-07 18:15:53, 1.8 KB) [[attachment:Subscribers.py]]
  • [get | view] (2006-03-18 23:16:51, 0.8 KB) [[attachment:UserPreferences.py]]
  • [get | view] (2004-01-05 09:56:25, 8.1 KB) [[attachment:VisualSiteMap.py]]
  • [get | view] (2015-08-30 21:04:23, 11.1 KB) [[attachment:VisualSiteMap_1.10.py]]
  • [get | view] (2004-10-08 10:59:16, 9.3 KB) [[attachment:VisualSiteMap_1.2.py]]
  • [get | view] (2005-03-16 01:30:09, 9.8 KB) [[attachment:VisualSiteMap_1.3.py]]
  • [get | view] (2014-08-19 01:34:10, 10.8 KB) [[attachment:VisualSiteMap_1.9.py]]
  • [get | view] (2007-08-18 18:52:55, 1.0 KB) [[attachment:backlink.py]]
  • [get | view] (2007-03-15 05:53:49, 23.5 KB) [[attachment:findandreplace0.1Beta.py]]
  • [get | view] (2005-03-27 20:32:10, 3.6 KB) [[attachment:gallery2image-1.3.3-1.py]]
  • [get | view] (2005-08-03 20:14:56, 4.0 KB) [[attachment:gallery2image-1.3.3-2.py]]
  • [get | view] (2005-11-13 18:10:26, 20.7 KB) [[attachment:gallery2image-1.3.5-10.py]]
  • [get | view] (2005-11-25 22:03:50, 20.8 KB) [[attachment:gallery2image-1.3.5-11.py]]
  • [get | view] (2005-08-08 17:23:43, 8.4 KB) [[attachment:gallery2image-1.3.5-4.py]]
  • [get | view] (2005-08-13 15:15:45, 13.7 KB) [[attachment:gallery2image-1.3.5-5.py]]
  • [get | view] (2005-08-31 22:05:22, 15.5 KB) [[attachment:gallery2image-1.3.5-6.py]]
  • [get | view] (2005-10-29 20:23:50, 15.9 KB) [[attachment:gallery2image-1.3.5-8.py]]
  • [get | view] (2005-11-01 11:31:24, 17.6 KB) [[attachment:gallery2image-1.3.5-9.py]]
  • [get | view] (2006-01-27 20:52:32, 20.9 KB) [[attachment:gallery2image-1.5.1-12.py]]
  • [get | view] (2006-08-06 09:01:01, 22.1 KB) [[attachment:gallery2image-1.5.4-13.py]]
  • [get | view] (2006-08-11 18:21:40, 22.2 KB) [[attachment:gallery2image-1.5.4-14.py]]
  • [get | view] (2006-11-16 20:23:27, 22.6 KB) [[attachment:gallery2image-1.5.6-16.py]]
  • [get | view] (2006-08-11 18:30:22, 22.2 KB) [[attachment:gallery2image-1.6.0-15.py]]
  • [get | view] (2008-02-06 10:13:45, 22.3 KB) [[attachment:gallery2image-1.6.0-16.py]]
  • [get | view] (2008-05-20 15:51:09, 22.4 KB) [[attachment:gallery2image-1.6.3-17.py]]
  • [get | view] (2006-09-06 06:19:48, 1.3 KB) [[attachment:getmmap.py]]
  • [get | view] (2004-07-18 09:48:00, 1.5 KB) [[attachment:localnames.py]]
  • [get | view] (2005-03-25 15:02:31, 2.6 KB) [[attachment:newpageonly.py]]
  • [get | view] (2005-03-30 09:02:00, 3.5 KB) [[attachment:newpageonly_20050330.py]]
  • [get | view] (2006-06-06 19:12:27, 9.7 KB) [[attachment:pdf.py]]
  • [get | view] (2006-08-30 10:51:51, 36.0 KB) [[attachment:pdf2_0_0.py]]
  • [get | view] (2006-08-30 13:57:36, 36.5 KB) [[attachment:pdf2_0_1.py]]
  • [get | view] (2006-02-04 04:25:29, 1.0 KB) [[attachment:sisterindex.py]]
  • [get | view] (2004-10-28 07:33:10, 0.7 KB) [[attachment:xml.py]]
 All files | Selected Files: delete move to page copy to page

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