[ mailman-Feature Requests-1577374 ] PHP in mailman templates

SourceForge.net noreply at sourceforge.net
Sat Oct 14 22:46:56 CEST 2006


Feature Requests item #1577374, was opened at 2006-10-14 15:46
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=350103&aid=1577374&group_id=103

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Lindsay Haisley (fmouse)
Assigned to: Nobody/Anonymous (nobody)
Summary: PHP in mailman templates

Initial Comment:
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.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=350103&aid=1577374&group_id=103


More information about the Mailman-coders mailing list