PHP in mailman templates

Bug #266846 reported by Fmouse-users
2
Affects Status Importance Assigned to Milestone
GNU Mailman
New
Medium
Unassigned

Bug Description

Here's a way to force html produced from mailman
templates to execute PHP code when they're served from
a mailman CGI. This idea needs a lot of development,
and although I'm using it on a production system, it's
mainly a proof of concept.

I don't claim much credit for this. I stole the idea
quite blatantly from Fredrik Lundh's "Python Standard
Library" (pub. by O'Reilly).

~mailman/Mailman/Cgi/private.py is patched with two
lines of code:

--- private.py.orig 2006-09-18 14:00:19.000000000 -0500
+++ private.py 2006-10-08 18:36:35.000000000 -0500
@@ -29,6 +29,7 @@
 from Mailman import i18n
 from Mailman.htmlformat import *
 from Mailman.Logging.Syslog import syslog
+from php_redirect import Redirect

 # Set up i18n. Until we know which list is being
requested, we use the
 # server's default.
@@ -123,6 +124,8 @@
     realname = mlist.real_name
     message = ''

+ sys.stdout = Redirect(sys.stdout)
+
     if not mlist.WebAuthenticate((mm_cfg.AuthUser,

mm_cfg.AuthListModerator,
                                   mm_cfg.AuthListAdmin,

The Redirect class, in php_redirect.py, is as follows:

class Redirect:
    """Redirect stdout to PHP command line interpreter.
    Usage: sys.stdout = Redirect(sys.stdout)"""

    def __init__(self, stdout):
        self.stdout = stdout
        import os
        self.os = os

    def write(self, s):
        if self.os.access("/usr/bin/php", self.os.X_OK):
            wpipe = self.os.popen("/usr/bin/php", "w")
            wpipe.write(s)
        else:
            self.stdout.write(s)

Any output after the sys.stdout = Redirect(sys.stdout)
line in private.py will be passed through the PHP
command line interpreter if it's present.

This solution doesn't cover the situation where an
archive index.html is public and is accessed directly
by the web server rather than by a mailman CGI. For
this, the quick and dirty hack is to tell apache to
'AddType application/x-httpd-php .html' for the mailman
archive directory, but mailman might look at the
filename on a template and create the working file with
the same extension. e.g. if, say,
~mailman/templates/en/archtocnombox.html existed, then
it would be used to create
~mailman/archives/private/listname/index.html. On the
other hand, if the same template were called
archtocnombox.php, then it would be used to create
index.php in the proper archive directory.

[http://sourceforge.net/tracker/index.php?func=detail&aid=1577374&group_id=103&atid=350103]

Revision history for this message
Fmouse-users (fmouse-users) wrote :

Since the tracker munged my code a bit, I'm attaching a
couple of files.

Revision history for this message
Fmouse-users (fmouse-users) wrote : php_redirect.py containing Redirect class

Other attachments

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.