Mercurial > hg > mlmmj
changeset 657:7fefd9a9fad5
Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
- bulk (file) upload of subscribers
- remove all subscribers (with double "are you sure" check)
- possibility to edit all texts
- README correction
author | xi |
---|---|
date | Thu, 02 Aug 2007 04:15:55 +1000 |
parents | 2b70ab446832 |
children | 47959df55acd |
files | contrib/web/perl-admin/README contrib/web/perl-admin/htdocs/edit_text.cgi contrib/web/perl-admin/htdocs/save.cgi contrib/web/perl-admin/htdocs/save_text.cgi contrib/web/perl-admin/htdocs/subscribers.cgi contrib/web/perl-admin/templates/edit.html contrib/web/perl-admin/templates/edit_text.html contrib/web/perl-admin/templates/edit_textstring.html contrib/web/perl-admin/templates/index_row.html contrib/web/perl-admin/templates/save.html contrib/web/perl-admin/templates/save_text.html contrib/web/perl-admin/templates/subscribers.html |
diffstat | 12 files changed, 269 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/web/perl-admin/README Mon Jun 18 06:52:00 2007 +1000 +++ b/contrib/web/perl-admin/README Thu Aug 02 04:15:55 2007 +1000 @@ -27,8 +27,14 @@ you need to create a group (eg. mlmmj) and add both users to it. The subscribers.d directory then needs to be writable by that group: - # chgrp -R mlmmj /var/spool/mlmmj/mlmmj-test/subscribers.d/ - # chmod -R g+w /var/spool/mlmmj/mlmmj-test/subscribers.d/ + # chgrp -R mlmmj /var/spool/mlmmj/mlmmj-test/subscribers.d + # chmod -R g+w /var/spool/mlmmj/mlmmj-test/subscribers.d + # chgrp -R mlmmj /var/spool/mlmmj/mlmmj-test/digesters.d + # chmod -R g+w /var/spool/mlmmj/mlmmj-test/digesters.d + # chgrp -R mlmmj /var/spool/mlmmj/mlmmj-test/nomailsubs.d + # chmod -R g+w /var/spool/mlmmj/mlmmj-test/nomailsubs.d + # chgrp -R mlmmj /var/spool/mlmmj/mlmmj-test/text + # chmod -R g+w /var/spool/mlmmj/mlmmj-test/text To enable access control on Apache you have to:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/web/perl-admin/htdocs/edit_text.cgi Thu Aug 02 04:15:55 2007 +1000 @@ -0,0 +1,85 @@ +#!/usr/bin/perl -w + +# Copyright (C) 2007 Franky Van Liedekerke <liedekef@telenet.be> +# +# $Id$ +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. + +use strict; +use CGI; +use CGI::FastTemplate; +use HTML::Entities; + +use vars qw($topdir $templatedir $list); + +if (exists $ENV{CONFIG_PATH}) { + require $ENV{CONFIG_PATH}; +} else { + require "../conf/config.pl"; +} + +my $tpl = new CGI::FastTemplate($templatedir); + +my $q = new CGI; +$list = $q->param("list"); + +die "no list specified" unless $list; +die "non-existent list" unless -d("$topdir/$list"); + +$tpl->define(main => "edit_text.html", + list => "edit_textstring.html"); + +$tpl->assign(LIST => encode_entities($list)); + +my $textdir = "$topdir/$list/text"; +my @files; +opendir(DIR, $textdir ) || die "can't opendir $textdir: $!"; +@files = grep { !/^\./ && -f "$textdir/$_" } readdir(DIR); +closedir DIR; + +for my $textfile (sort @files) { + mlmmj_text($textfile); +} + +print "Content-type: text/html\n\n"; +$tpl->parse(CONTENT => "main"); +$tpl->print; + +sub mlmmj_text { + my ($name) = @_; + my $file = "$textdir/$name"; + my $value; + + if (! -f $file) { + $value = ""; + } else { + open(F, $file) or die("can't open $file"); + while (<F>) { + $value .= $_; + } + close(F); + chomp($value); + } + + $tpl->assign(NAME => encode_entities($name)); + $tpl->assign(VALUE => encode_entities($value)); + + $tpl->parse(ROWS => ".list"); +}
--- a/contrib/web/perl-admin/htdocs/save.cgi Mon Jun 18 06:52:00 2007 +1000 +++ b/contrib/web/perl-admin/htdocs/save.cgi Thu Aug 02 04:15:55 2007 +1000 @@ -1,7 +1,7 @@ #!/usr/bin/perl -w # Copyright (C) 2004 Morten K. Poulsen <morten at afdelingp.dk> -# Copyright (C) 2004 Christian Laursen <christian@pil.dk> +# Copyright (C) 2004, 2005 Christian Laursen <christian@pil.dk> # # $Id$ #
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/web/perl-admin/htdocs/save_text.cgi Thu Aug 02 04:15:55 2007 +1000 @@ -0,0 +1,77 @@ +#!/usr/bin/perl -w + +# Copyright (C) 2007 Franky Van Liedekerke <liedekef@telenet.be> +# +# $Id$ +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. + +# We might want some kind of validation of the values we are about to save, +# but that would require save.cgi to know about all kind of options that mlmmj +# accepts. I am not sure we want that. -- mortenp 20040709 + +use strict; +use CGI; +use CGI::FastTemplate; +use HTML::Entities; + +use vars qw($topdir $templatedir $list); + +if (exists $ENV{CONFIG_PATH}) { + require $ENV{CONFIG_PATH}; +} else { + require "../conf/config.pl"; +} + +my $tpl = new CGI::FastTemplate($templatedir); + +my $q = new CGI; +$list = $q->param("list"); + +die "no list specified" unless $list; +die "non-existent list" unless -d("$topdir/$list"); + +$tpl->define(main => "save_text.html"); +$tpl->assign(LIST => encode_entities($list)); + +my $textdir = "$topdir/$list/text"; +my @files; +opendir(DIR, $textdir ) || die "can't opendir $textdir: $!"; +@files = grep { !/^\./ && -f "$textdir/$_" } readdir(DIR); +closedir DIR; + +for my $textfile (sort @files) { + mlmmj_text($textfile); +} + +print "Content-type: text/html\n\n"; +$tpl->parse(CONTENT => "main"); +$tpl->print; + +sub mlmmj_text { + my ($name, $nicename, $text) = @_; + + my $file = "$textdir/$name"; + + my $value = $q->param($name); + + open (FILE, ">$file") or die "Couldn't open $file for writing: $!"; + print FILE $value; + close FILE; +}
--- a/contrib/web/perl-admin/htdocs/subscribers.cgi Mon Jun 18 06:52:00 2007 +1000 +++ b/contrib/web/perl-admin/htdocs/subscribers.cgi Thu Aug 02 04:15:55 2007 +1000 @@ -1,6 +1,7 @@ #!/usr/bin/perl -w -# Copyright (C) 2004, 2005, 2006 Christian Laursen <christian@pil.dk> +# Copyright (C) 2004, 2005, 2006, 2007 Christian Laursen <christian@pil.dk> +# Copyright (C) 2007 Franky Van Liedekerke <liedekef@telenet.be> # # $Id$ # @@ -47,6 +48,8 @@ my $update = $q->param("update"); my $search = $q->param("search"); my $email = $q->param("email"); +my $file = $q->param("file"); +my $removeall = $q->param("removeall"); # Everything is submitted from the same form so a little hackery is needed # to pick the right action to perform. When doing subscribe and search we @@ -72,21 +75,55 @@ my $subscribers; my $subcount; -if (defined $email) { +if (defined $removeall) { + my $removeall_check = $q->param("removeall_check"); + if ($removeall_check) { + unlink <$topdir/$list/subscribers.d/*>; + unlink <$topdir/$list/nomailsubs.d/*>; + unlink <$topdir/$list/digesters.d/*>; + $action = "All subscribers have been removed."; + } else { + $action = "Safety check not clicked, nothing done."; + } +} elsif (defined $file) { + my $subscriber = $q->param("subscriber"); + my $digester = $q->param("digester"); + my $nomailsub = $q->param("nomailsub"); + my $upload_handle = $q->upload("file"); + binmode $upload_handle; + while (<$upload_handle>) { + s/\r?\n$//; + my $email=$_; + if ($email =~ /^[a-z0-9\.\-_\@]+$/i) { + if ($subscriber) { + system "$mlmmjsub -L $topdir/$list -a $email -U -s"; + } + if ($digester) { + system "$mlmmjsub -L $topdir/$list -a $email -Ud -s"; + } + if ($nomailsub) { + system "$mlmmjsub -L $topdir/$list -a $email -Un -s"; + } + $action .= "$email has been subscribed.<br>\n"; + } else { + $action .= '"'.encode_entities($email).'" is not a valid email address.<br>'; + } + } +} elsif (defined $email) { my $subscriber = $q->param("subscriber"); my $digester = $q->param("digester"); my $nomailsub = $q->param("nomailsub"); if ($email =~ /^[a-z0-9\.\-_\@]+$/i) { if ($subscriber) { - system "$mlmmjsub -L $topdir/$list -a $email -U"; + system "$mlmmjsub -L $topdir/$list -a $email -U -s"; } if ($digester) { - system "$mlmmjsub -L $topdir/$list -a $email -Ud"; + system "$mlmmjsub -L $topdir/$list -a $email -Ud -s"; } if ($nomailsub) { - system "$mlmmjsub -L $topdir/$list -a $email -Un"; + system "$mlmmjsub -L $topdir/$list -a $email -Un -s"; } - $action = "$email has been subscribed."; + $action = "error adding $email (code $?)"; } else { $action = '"'.encode_entities($email).'" is not a valid email address.'; } @@ -137,7 +174,7 @@ my $paginator = ''; my $page = $q->param('page'); -$page = 0 unless $page =~ /^\d+$/; +$page = 0 unless defined $page && $page =~ /^\d+$/; if (keys %$subscribers > 50) { $paginator = 'Pages: '; my $pages = (keys %$subscribers) / 50;
--- a/contrib/web/perl-admin/templates/edit.html Mon Jun 18 06:52:00 2007 +1000 +++ b/contrib/web/perl-admin/templates/edit.html Thu Aug 02 04:15:55 2007 +1000 @@ -1,7 +1,7 @@ <html><head><title>mlmmj config</title></head><body> <h1>mlmmj config</h1> <p> -<a href="index.cgi">Index</a> | <a href="subscribers.cgi?list=$LIST">Subscribers</a> +<a href="index.cgi">Index</a> | <a href="subscribers.cgi?list=$LIST">Subscribers</a> | <a href="edit_text.cgi?list=$LIST">Edit texts</a></td> </p> <p> List: $LIST
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/web/perl-admin/templates/edit_text.html Thu Aug 02 04:15:55 2007 +1000 @@ -0,0 +1,16 @@ +<html><head><title>mlmmj config</title></head><body> +<h1>mlmmj config</h1> +<p> +<a href="index.cgi">Index</a> | <a href="edit.cgi?list=$LIST">Configuration</a> | <a href="subscribers.cgi?list=$LIST">Subscribers</a> +</p> +<p> +List: $LIST +</p> +<form method="post" action="save_text.cgi"> +<input type="hidden" name="list" value="$LIST"> +<table border="1"> +$ROWS +</table> +<input type="submit" name="submit" value="Update texts" /> +</form> +</body></html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/web/perl-admin/templates/edit_textstring.html Thu Aug 02 04:15:55 2007 +1000 @@ -0,0 +1,1 @@ +<tr><td>$NAME</td><td><textarea name="$NAME" rows="10" cols="70">$VALUE</textarea></td></tr>
--- a/contrib/web/perl-admin/templates/index_row.html Mon Jun 18 06:52:00 2007 +1000 +++ b/contrib/web/perl-admin/templates/index_row.html Thu Aug 02 04:15:55 2007 +1000 @@ -1,1 +1,1 @@ -<tr><td>$LIST</td><td><a href="edit.cgi?list=$ULIST">Configure</a></td><td><a href="subscribers.cgi?list=$ULIST">Subscribers</a></td></tr> +<tr><td>$LIST</td><td><a href="edit.cgi?list=$ULIST">Configure</a></td><td><a href="subscribers.cgi?list=$ULIST">Subscribers</a></td><td><a href="edit_text.cgi?list=$ULIST">Edit texts</a></td></tr>
--- a/contrib/web/perl-admin/templates/save.html Mon Jun 18 06:52:00 2007 +1000 +++ b/contrib/web/perl-admin/templates/save.html Thu Aug 02 04:15:55 2007 +1000 @@ -4,6 +4,6 @@ $LIST control values saved! </p> <p> -<a href="index.cgi">Index</a> | <a href="edit.cgi?list=$LIST">Back to configuration</a> +<a href="index.cgi">Index</a> | <a href="edit.cgi?list=$LIST">Configuration</a> | <a href="edit_text.cgi?list=$LIST">Edit texts</a></td> </p> </body></html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/web/perl-admin/templates/save_text.html Thu Aug 02 04:15:55 2007 +1000 @@ -0,0 +1,9 @@ +<html><head><title>mlmmj config</title></head><body> +<h1>mlmmj config</h1> +<p> +$LIST text values saved! +</p> +<p> +<a href="index.cgi">Index</a> | <a href="edit.cgi?list=$LIST">Configuration</a> | <a href="edit_text.cgi?list=$LIST">Edit texts</a></td> +</p> +</body></html>
--- a/contrib/web/perl-admin/templates/subscribers.html Mon Jun 18 06:52:00 2007 +1000 +++ b/contrib/web/perl-admin/templates/subscribers.html Thu Aug 02 04:15:55 2007 +1000 @@ -1,11 +1,35 @@ <html><head><title>mlmmj subscribers</title></head><body> <h1>mlmmj subscribers</h1> <p> -<a href="index.cgi">Index</a> | <a href="subscribers.cgi?list=$LIST">Reload subscriber list</a> | <a href="edit.cgi?list=$LIST">Configure</a> +<a href="index.cgi">Index</a> | <a href="subscribers.cgi?list=$LIST">Reload subscriber list</a> | <a href="edit.cgi?list=$LIST">Configuration</a> | <a href="edit_text.cgi?list=$LIST">Edit texts</a></td> </p> <p> $ACTION </p> +<hr> +<form action="subscribers.cgi" method="post" onSubmit="if (window.confirm('Are you sure you want to do this?')) this.submit(); else return false;"> +<input type="hidden" name="list" value="$LIST"> +<input type="hidden" name="maxid" value="$MAXID"> +<input type="hidden" name="removeall" value="1"> +<table><tr><td rowspan="5" valign="top">Remove all subscribers: </td> +<td><input type="submit" name="remove" value="Remove all"></td></tr> +<tr><td>Click this as extra safety check: <input type="checkbox" name="removeall_check" value="1" unchecked></td></tr> +</table> +</form> +<hr> +<form action="subscribers.cgi" method="post" enctype="multipart/form-data"> +<input type="hidden" name="list" value="$LIST"> +<input type="hidden" name="maxid" value="$MAXID"> +<input type="hidden" name="page" value="$PAGE"> +<table><tr><td rowspan="5" valign="top">Bulk add subscribers: </td> +<td>File: <input type="FILE" name="file"></td></tr> +<tr><td>Normal subscribers: <input type="checkbox" name="subscriber" value="1" checked></td></tr> +<tr><td>Digest subscribers: <input type="checkbox" name="digester" value="1"></td></tr> +<tr><td>No-mail subscribers: <input type="checkbox" name="nomailsub" value="1"></td></tr> +<tr><td><input type="submit" name="subscribe" value="Subscribe"></td></tr> +</table> +</form> + <form action="subscribers.cgi" method="post"> <input type="hidden" name="list" value="$LIST"> <input type="hidden" name="maxid" value="$MAXID">