changeset 388:b58c5059749e

perl interface update from xi
author mmj
date Sat, 27 Nov 2004 01:36:27 +1100
parents 76232e610354
children b16868d3f926
files contrib/web/perl-admin/conf/tunables.pl contrib/web/perl-admin/htdocs/subscribers.cgi contrib/web/perl-admin/templates/edit.html contrib/web/perl-admin/templates/save.html contrib/web/perl-admin/templates/subscribers.html contrib/web/perl-admin/templates/subscribers_row.html
diffstat 6 files changed, 124 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/web/perl-admin/conf/tunables.pl	Fri Nov 26 07:01:02 2004 +1100
+++ b/contrib/web/perl-admin/conf/tunables.pl	Sat Nov 27 01:36:27 2004 +1100
@@ -1,6 +1,9 @@
 mlmmj_boolean("closedlist",
 			  "Closed list",
-			  "If this option is set, subscribtion and unsubscription via mail is disabled.");
+			  "If the list is open or closed. If it's closed subscription ".
+			  "and unsubscription via mail is disabled. Also note that ".
+			  "confirmation is disabled too, so the -C option to mlmmj-sub ".
+			  "and mlmmj-unsub is of no use with a closed list.");
 
 mlmmj_boolean("nosubconfirm",
 			  "No subscribe confirmation",
@@ -37,6 +40,13 @@
 		   "Owner",
 		   "The emailaddresses in this list will get mails to ".encode_entities($list)."+owner");
 
+mlmmj_list("customheaders",
+		   "Custom headers",
+		   "These headers are added to every mail coming through. This is ".
+		   "the place you want to add Reply-To: header in case you want ".
+		   "such. ".
+		   "If a header should not occur twice in the mail it should be listed in the 'Delete headers' box too.");
+
 mlmmj_list("delheaders",
 		   "Delete headers",
 		   "In this file is specified *ONE* headertoken to match pr. line. ".
@@ -57,13 +67,32 @@
 
 mlmmj_string("relayhost",
 			 "Relay host",
-			 "The host specified (IP address og domainname, both works) in this file will be used for relaying the mail sent to the list. ".
+			 "The host specified (IP address or domainname, both works) in this file will be used for relaying the mail sent to the list. ".
 			 "Defaults to 127.0.0.1.");
 
 mlmmj_boolean("notifysub",
 			  "Notify subscribers",
 			  "If this option is set, the owner(s) will get a mail with the address of someone sub/unsubscribing to a mailinglist.");
+
+mlmmj_string("digestinterval",
+			 "Digest interval",
+			 "This option specifies how many seconds will pass before the ".
+			 "next digest is sent. Defaults to 604800 seconds, which is 7 ".
+			 "days.");
+
+mlmmj_string("digestmaxmails",
+			 "Max. digest mails",
+			 "This option specifies how many mails can accumulate before ".
+			 "digest sending is triggered. Defaults to 50 mails, meaning ".
+			 "that if 50 mails arrive to the list before digestinterval have ".
+			 "passed, the digest is delivered.");
+
 mlmmj_string("bouncelife",
 			  "Bouncing lifetime",
 			  "Here is specified for how long time in seconds an address can bounce before it's unsubscribed. Defaults ".
 			  "to 432000 seconds, which is 5 days.");
+
+mlmmj_boolean("noarchive",
+			  "No archive",
+			  "If this option is set, the mails won't be saved in the ".
+			  "archive but simply deleted");
--- a/contrib/web/perl-admin/htdocs/subscribers.cgi	Fri Nov 26 07:01:02 2004 +1100
+++ b/contrib/web/perl-admin/htdocs/subscribers.cgi	Sat Nov 27 01:36:27 2004 +1100
@@ -45,7 +45,7 @@
 my $q = new CGI;
 $list = $q->param("list");
 my $subscribe = $q->param("subscribe");
-my $unsubscribe = $q->param("unsubscribe");
+my $update = $q->param("update");
 
 die "no list specified" unless $list;
 die "non-existent list" unless -d("$topdir/$list");
@@ -59,27 +59,56 @@
 
 if (defined $subscribe) {
 	my $email = $q->param("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";
-		if (is_subscribed($email)) {
+		}
+		if ($digester) {
+			system "$mlmmjsub -L $topdir/$list -a $email -Ud";
+		}
+		if ($nomailsub) {
+			system "$mlmmjsub -L $topdir/$list -a $email -Un";
+		}
 			$action = "$email has been subscribed.";
 		} else {
-			$action = "$email was not subscribed.";
-		}
-	} else {
 		$action = '"'.encode_entities($email).'" is not a valid email address.';
 	}
-} elsif (defined $unsubscribe) {
+} elsif (defined $update) {
 	my $maxid = $q->param("maxid");
+	$subscribers = get_subscribers();
 	for (my $i = 0; $i < $maxid; ++$i) {
 		my $email = $q->param("email$i");
 		if (defined $email) {
 			if ($email =~ /^[a-z0-9\.\-_\@]+$/i) {
-				system "$mlmmjunsub -L $topdir/$list -a $email";
-				if (!is_subscribed($email)) {
-					$action .= "$email has been unsubscribed.<br>\n";
-				} else {
-					$action .= "$email was not unsubscribed.<br>\n";
+				my $updated = 0;
+
+				my @actions = ();
+
+				push @actions, {oldstatus => exists $subscribers->{$email}->{subscriber},
+								newstatus => defined $q->param("subscriber$i"),
+								action => ''};
+				push @actions, {oldstatus => exists $subscribers->{$email}->{digester},
+								newstatus => defined $q->param("digester$i"),
+								action => '-d'};
+				push @actions, {oldstatus => exists $subscribers->{$email}->{nomailsub},
+								newstatus => defined $q->param("nomailsub$i"),
+								action => '-n'};
+
+				for my $action (@actions) {
+					if ($action->{oldstatus} && !$action->{newstatus}) {
+						system "$mlmmjunsub -L $topdir/$list -a $email $action->{action}";
+						$updated = 1;
+					} elsif (!$action->{oldstatus} && $action->{newstatus}) {
+						system "$mlmmjsub -L $topdir/$list -a $email $action->{action}";
+						$updated = 1;
+					}
+				}
+
+				if ($updated) {
+					$action .= "Subscription for $email has been updated.<br>\n";
 				}
 			} else {
 				$action .= '"'.encode_entities($email).'" is not a valid email address.'."<br>\n";
@@ -92,17 +121,21 @@
 
 $subscribers = get_subscribers();
 
-for (my $i = 0; $i < @$subscribers; ++$i) {
-	$tpl->assign(EMAIL => $subscribers->[$i],
-				 ID => $i);
+my $i = 0;
+for my $address (sort keys %$subscribers) {
+	$tpl->assign(EMAIL => $address,
+				 ID => $i++,
+				 SCHECKED => $subscribers->{$address}->{subscriber} ? 'checked' : '',
+				 DCHECKED => $subscribers->{$address}->{digester} ? 'checked' : '',
+				 NCHECKED => $subscribers->{$address}->{nomailsub} ? 'checked' : '');
 	$tpl->parse(ROWS => '.row');
 }
-if (@$subscribers == 0) {
+if (keys %$subscribers == 0) {
 	$tpl->assign(ROWS => '');
 }
 
 $tpl->assign(LIST => encode_entities($list),
-			 MAXID => scalar(@$subscribers));
+			 MAXID => scalar(keys %$subscribers));
 
 print "Content-type: text/html\n\n";
 
@@ -110,48 +143,27 @@
 $tpl->print;
 
 sub get_subscribers {
-	my @subscribers = ();
+	my %subscribers = ();
+
+	my @subscribers = `/usr/local/bin/mlmmj-list -L $topdir/$list`;
+	my @digesters = `/usr/local/bin/mlmmj-list -L $topdir/$list -d`;
+	my @nomailsubs = `/usr/local/bin/mlmmj-list -L $topdir/$list -n`;
 
-	opendir (DIR, "$topdir/$list/subscribers.d") or die "Couldn't read dir $topdir/$list/subscribers.d: $!";
-	my @files = grep(/^.$/, readdir(DIR));
-	closedir DIR;
-	for my $file (@files) {
-		my $filename = "$topdir/$list/subscribers.d/$file";
-		if (-f $filename) {
-			open (FILE, $filename) or die "Couldn't open $filename for reading: $!";
-			while (<FILE>) {
-				chomp;
-				push @subscribers, $_;
-			}
-			close FILE;
-		}
-	}
+	chomp @subscribers;
+	chomp @digesters;
+	chomp @nomailsubs;
 
-	@subscribers = sort @subscribers;
-
-	return \@subscribers;
+	for my $address (@subscribers) {
+		$subscribers{$address}->{subscriber} = 1;
 }
 
-sub is_subscribed {
-	my ($email) = @_;
-
-	opendir (DIR, "$topdir/$list/subscribers.d") or die "Couldn't read dir $topdir/$list/subscribers.d: $!";
-	my @files = grep(/^.$/, readdir(DIR));
-	closedir DIR;
-
-	for my $file (@files) {
-		my $filename = "$topdir/$list/subscribers.d/$file";
-		if (-f $filename) {
-			open (FILE, $filename) or die "Couldn't open $filename for reading: $!";
-			while (<FILE>) {
-				chomp;
-				if ($email eq $_) {
-					return 1;
-				}
-			}
-			close FILE;
-		}
+	for my $address (@digesters) {
+		$subscribers{$address}->{digester} = 1;
 	}
 
-	return 0;
+	for my $address (@nomailsubs) {
+		$subscribers{$address}->{nomailsub} = 1;
 }
+
+	return \%subscribers;
+}
--- a/contrib/web/perl-admin/templates/edit.html	Fri Nov 26 07:01:02 2004 +1100
+++ b/contrib/web/perl-admin/templates/edit.html	Sat Nov 27 01:36:27 2004 +1100
@@ -1,10 +1,13 @@
 <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>
+</p>
 <form method="post" action="save.cgi">
 <input type="hidden" name="list" value="$LIST">
 <table border="1">
 $ROWS
 </table>
-<input type="submit" name="submit" />
+<input type="submit" name="submit" value="Update configuration" />
 </form>
 </body></html>
--- a/contrib/web/perl-admin/templates/save.html	Fri Nov 26 07:01:02 2004 +1100
+++ b/contrib/web/perl-admin/templates/save.html	Sat Nov 27 01:36:27 2004 +1100
@@ -4,6 +4,6 @@
 $LIST control values saved!
 </p>
 <p>
-<a href="index.cgi">Index</a> | <a href="edit.cgi?list=$LIST">$LIST</a>
+<a href="index.cgi">Index</a> | <a href="edit.cgi?list=$LIST">Back to configuration</a>
 </p>
 </body></html>
--- a/contrib/web/perl-admin/templates/subscribers.html	Fri Nov 26 07:01:02 2004 +1100
+++ b/contrib/web/perl-admin/templates/subscribers.html	Sat Nov 27 01:36:27 2004 +1100
@@ -1,7 +1,7 @@
 <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="index.cgi">Index</a> | <a href="subscribers.cgi?list=$LIST">Reload subscriber list</a> | <a href="edit.cgi?list=$LIST">Configure</a>
 </p>
 <p>
 $ACTION
@@ -9,11 +9,18 @@
 <form action="subscribers.cgi" method="post">
 <input type="hidden" name="list" value="$LIST">
 <input type="hidden" name="maxid" value="$MAXID">
-<p>Add subscriber: <input type="text" name="email"> <input type="submit" name="subscribe" value="Subscribe"></p>
+<table><tr><td rowspan="4" valign="top">Add subscriber:&nbsp;&nbsp;</td>
+<td>Email address: <input type="text" name="email"></td></tr>
+<tr><td>Normal subscriber: <input type="checkbox" name="subscriber" value="1" checked></td></tr>
+<tr><td>Digest subscriber: <input type="checkbox" name="digester" value="1"></td></tr>
+<tr><td>No-mail subscriber: <input type="checkbox" name="nomailsub" value="1"></td></tr>
+<tr><td>&nbsp;</td><td><input type="submit" name="subscribe" value="Subscribe"></td></tr>
+</table>
+<hr>
 <table border="1">
-<tr><th>Email address</th><th>Unsubscribe</th></tr>
+<tr><th>Email address</th><th>Normal subscriber</th><th>Digest subscriber</th><th>No-mail subscriber</th></tr>
 $ROWS
 </table>
-<p><input type="submit" name="unsubscribe" value="Unsubscribe selected"></p>
+<p><input type="submit" name="update" value="Update subscriptions"></p>
 </form>
 </body></html>
--- a/contrib/web/perl-admin/templates/subscribers_row.html	Fri Nov 26 07:01:02 2004 +1100
+++ b/contrib/web/perl-admin/templates/subscribers_row.html	Sat Nov 27 01:36:27 2004 +1100
@@ -1,1 +1,6 @@
-<tr><td>$EMAIL</td><td><input type="checkbox" name="email$ID" value="$EMAIL"></td></tr>
+<tr>
+    <td>$EMAIL<input type="hidden" name="email$ID" value="$EMAIL"></td>
+    <td><input type="checkbox" name="subscriber$ID" value="1" $SCHECKED></td>
+    <td><input type="checkbox" name="digester$ID" value="1" $DCHECKED></td>
+    <td><input type="checkbox" name="nomailsub$ID" value="1" $NCHECKED></td>
+</tr>