Initial mod_perl-2.0 port.
[www.jankratochvil.net.git] / Mailman.pm
diff --git a/Mailman.pm b/Mailman.pm
new file mode 100644 (file)
index 0000000..3b5f39d
--- /dev/null
@@ -0,0 +1,71 @@
+# $Id$
+# Mailman page Perl template.
+# Copyright (C) 2003-2005 Jan Kratochvil <project-www.jankratochvil.net@jankratochvil.net>
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; exactly version 2 of June 1991 is required
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+package Mailman;
+require 5.6.0; # at least 'use warnings;' but we need some 5.6.0+ modules anyway
+use vars qw($VERSION $CVS_ID);
+$VERSION=do { my @r=(q$Revision$=~/\d+/g); sprintf "%d.".("%03d"x$#r),@r; };
+$CVS_ID=q$Id$;
+use strict;
+use warnings;
+
+use My::Web;
+require CGI;
+use URI::Escape;
+require LWP::Simple;
+
+
+our $HTML_TEST=0;
+
+sub handler
+{
+my $W=My::Web->init(
+               "title"=>"Mailman Interface",
+               "no_job"=>1,
+               "args_check"=>{
+                               "email"=>'',
+                               "pw"=>'',
+                               "pw-conf"=>'',
+                               "list"=>['^[-\w]+$'],
+                               "back"=>'',
+                               },
+               );
+My::Web->heading();
+
+
+for my $list (@{$W->{"args"}{"list"}}) {
+       print "<h1>List <i>$list</i></h1><blockquote>\n";
+               my $url_base=$W->{"mailman_url"}."/subscribe/$list";
+               my $t=LWP::Simple::get("$url_base?"
+                               .join('&',
+                                               "list=$list",
+                                               map({ $_."=".uri_escape($W->{"args"}{$_}); } qw(email pw pw-conf))));
+               $t=($t=~m#^.*<body\b[^>]*>(.*?)</body>#is)[0];
+               $t=~s#(href=")(../[^"]*)(")#$1$url_base/$2$3#gi;
+               print $t;
+       print "</blockquote>\n";
+       }
+
+if ($W->{"args"}{"back"}) {
+       print '<h1>'.a_href($W->{"args"}{"back"},'Back to the original page').'</h1>'."\n";
+       }
+
+
+My::Web->footer();
+}
+1;