changeset 355:1398baaa7034

Stak patches fra PIL: - control/nosubconfirm - webinterface update, så det kan håndtere subscribers - snippet til at kontrollere at group writable bit er sat
author mmj
date Wed, 10 Nov 2004 02:19:04 +1100
parents a862c68e3d1e
children 68bfdc8aeff7
files ChangeLog TUNABLES contrib/web/perl-admin/README contrib/web/perl-admin/conf/tunables.pl contrib/web/perl-admin/htdocs/edit.cgi contrib/web/perl-admin/htdocs/index.cgi contrib/web/perl-admin/htdocs/save.cgi contrib/web/perl-admin/templates/index.html src/listcontrol.c src/mlmmj-maintd.c src/mlmmj-sub.c src/mlmmj-unsub.c
diffstat 12 files changed, 71 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Nov 09 22:36:14 2004 +1100
+++ b/ChangeLog	Wed Nov 10 02:19:04 2004 +1100
@@ -1,3 +1,7 @@
+ o Enhance perl webinterface - including group writable patch
+ o Add option control/nosubconfirm which makes it possible to subscribe
+   without confirmation by just sending the mail. USE WITH CARE!
+ o Make files discarded by maintd end in .by-maintd to make them distinct
  o Fix off-by-one error in the function cleaning quoted printable chars
  o Close the correct fd's in mlmmj-process
  o Be consistent when using To: or Delivered-To:
--- a/TUNABLES	Tue Nov 09 22:36:14 2004 +1100
+++ b/TUNABLES	Wed Nov 10 02:19:04 2004 +1100
@@ -98,3 +98,9 @@
 
    If this file exists, the mail won't be saved in the archive but simply
    deleted.
+
+ · nosubconfirm			(boolean)
+
+   If this file exists, no mail confirmation is needed to subscribe to the
+   list. This should in principle never ever be used, but there is times
+   on local lists etc. where this is useful. HANDLE WITH CARE!
--- a/contrib/web/perl-admin/README	Tue Nov 09 22:36:14 2004 +1100
+++ b/contrib/web/perl-admin/README	Wed Nov 10 02:19:04 2004 +1100
@@ -23,9 +23,16 @@
 
      # chown -R wwwrun /var/spool/mlmmj/mlmmj-test/control/
 
+4) If the web server does not run as the same user the mailserver writes as
+   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/
+
 To enable access control on Apache you have to:
 
-4) Rename dot.htaccess to .htaccess and edit the path inside the file to point
+5) Rename dot.htaccess to .htaccess and edit the path inside the file to point
    to a htpasswd file somewhere outside the webscope.
 
    If you don't have one already, you can create one like this
@@ -34,7 +41,7 @@
 
    It will then ask you for a password for the given username.
 
-5) That is it, you are ready to use the interface.
+6) That is it, you are ready to use the interface.
 
 Further customization:
 
--- a/contrib/web/perl-admin/conf/tunables.pl	Tue Nov 09 22:36:14 2004 +1100
+++ b/contrib/web/perl-admin/conf/tunables.pl	Wed Nov 10 02:19:04 2004 +1100
@@ -2,6 +2,10 @@
 			  "Closed list",
 			  "If this option is set, subscribtion and unsubscription via mail is disabled.");
 
+mlmmj_boolean("nosubconfirm",
+			  "No subscribe confirmation",
+			  "If this option is set, the user is not required to confirm when subscribing or unsubscribing.");
+
 mlmmj_boolean("moderated",
 			  "Moderated",
 			  "If this option is set, the emailaddresses in the file listdir/control/moderators will act as moderators for the list.");
--- a/contrib/web/perl-admin/htdocs/edit.cgi	Tue Nov 09 22:36:14 2004 +1100
+++ b/contrib/web/perl-admin/htdocs/edit.cgi	Wed Nov 10 02:19:04 2004 +1100
@@ -41,6 +41,7 @@
 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.html",
--- a/contrib/web/perl-admin/htdocs/index.cgi	Tue Nov 09 22:36:14 2004 +1100
+++ b/contrib/web/perl-admin/htdocs/index.cgi	Wed Nov 10 02:19:04 2004 +1100
@@ -38,18 +38,19 @@
 
 my $tpl = new CGI::FastTemplate($templatedir);
 
-$tpl->define(main => "index.html");
+$tpl->define(main => "index.html",
+			 row => "index_row.html");
 
 my $lists = "";
 opendir(DIR, $topdir) or die "Couldn't open $topdir for reading: $!";
 while (my $list = readdir(DIR)) {
     next if $list =~ /^\./;
-    $lists .= "<a href=\"edit.cgi?list=".uri_escape($list)."\">".encode_entities($list)."</a><br />\n";
+	$tpl->assign(LIST => encode_entities($list));
+	$tpl->assign(ULIST => uri_escape($list));
+	$tpl->parse(LISTS => '.row');
 }
 closedir(DIR);
 
-$tpl->assign(LISTS => $lists);
-
 print "Content-type: text/html\n\n";
 
 $tpl->parse(CONTENT => "main");
--- a/contrib/web/perl-admin/htdocs/save.cgi	Tue Nov 09 22:36:14 2004 +1100
+++ b/contrib/web/perl-admin/htdocs/save.cgi	Wed Nov 10 02:19:04 2004 +1100
@@ -45,6 +45,7 @@
 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.html");
--- a/contrib/web/perl-admin/templates/index.html	Tue Nov 09 22:36:14 2004 +1100
+++ b/contrib/web/perl-admin/templates/index.html	Wed Nov 10 02:19:04 2004 +1100
@@ -1,4 +1,6 @@
 <html><head><title>mlmmj config</title></head><body>
 <h1>mlmmj config</h1>
+<table border="1">
 $LISTS
+</table>
 </body></html>
--- a/src/listcontrol.c	Tue Nov 09 22:36:14 2004 +1100
+++ b/src/listcontrol.c	Wed Nov 10 02:19:04 2004 +1100
@@ -100,15 +100,22 @@
 	char *atsign, *recipdelimsign, *bouncenr, *tmpstr;
 	char *controlstr, *param, *conffilename, *moderatefilename;
 	char *c, *archivefilename;
+	const char *subswitch;
 	size_t len;
 	struct stat stbuf;
-	int closedlist, tmpfd;
+	int closedlist, nosubconfirm, tmpfd;
 	size_t cmdlen;
 	unsigned int ctrl;
 	
 	/* A closed list doesn't allow subscribtion and unsubscription */
 	closedlist = statctrl(listdir, "closedlist");
 
+	nosubconfirm = statctrl(listdir, "nosubconfirm");
+	if(nosubconfirm)
+		subswitch = "-c";
+	else
+		subswitch = "-C";
+	
 	recipdelimsign = index(controladdr, RECIPDELIM);
 	MY_ASSERT(recipdelimsign);
 	atsign = index(controladdr, '@');
@@ -169,7 +176,7 @@
 				"-L", listdir,
 				"-a", fromemails->emaillist[0],
 				"-d",
-				"-C", NULL);
+				subswitch, NULL);
 		log_error(LOG_ARGS, "execlp() of '%s' failed",
 					mlmmjsub);
 		exit(EXIT_FAILURE);
@@ -187,7 +194,7 @@
 				"-L", listdir,
 				"-a", fromemails->emaillist[0],
 				"-n",
-				"-C", NULL);
+				subswitch, NULL);
 		log_error(LOG_ARGS, "execlp() of '%s' failed",
 					mlmmjsub);
 		exit(EXIT_FAILURE);
@@ -204,7 +211,7 @@
 		execlp(mlmmjsub, mlmmjsub,
 				"-L", listdir,
 				"-a", fromemails->emaillist[0],
-				"-C", NULL);
+				subswitch, NULL);
 		log_error(LOG_ARGS, "execlp() of '%s' failed",
 					mlmmjsub);
 		exit(EXIT_FAILURE);
@@ -296,7 +303,7 @@
 				"-L", listdir,
 				"-a", fromemails->emaillist[0],
 				"-d",
-				"-C", NULL);
+				subswitch, NULL);
 		log_error(LOG_ARGS, "execlp() of '%s' failed",
 				mlmmjunsub);
 		exit(EXIT_FAILURE);
@@ -314,7 +321,7 @@
 				"-L", listdir,
 				"-a", fromemails->emaillist[0],
 				"-n",
-				"-C", NULL);
+				subswitch, NULL);
 		log_error(LOG_ARGS, "execlp() of '%s' failed",
 				mlmmjunsub);
 		exit(EXIT_FAILURE);
@@ -331,7 +338,7 @@
 		execlp(mlmmjunsub, mlmmjunsub,
 				"-L", listdir,
 				"-a", fromemails->emaillist[0],
-				"-C", NULL);
+				subswitch, NULL);
 		log_error(LOG_ARGS, "execlp() of '%s' failed",
 				mlmmjunsub);
 		exit(EXIT_FAILURE);
--- a/src/mlmmj-maintd.c	Tue Nov 09 22:36:14 2004 +1100
+++ b/src/mlmmj-maintd.c	Wed Nov 10 02:19:04 2004 +1100
@@ -239,9 +239,9 @@
 		fromname = concatstr(2, mailname, ".mailfrom");
 		if(stat(fromname, &st) < 0) {
 			if(errno == ENOENT) {
-				discardedname = concatstr(3,
+				discardedname = concatstr(4,
 						listdir, "/queue/discarded/",
-						dp->d_name);
+						dp->d_name, ".by-maintd");
 				discarded = discardmail(mailname,
 							discardedname,
 							3600);
@@ -256,9 +256,9 @@
 		toname = concatstr(2, mailname, ".reciptto");
 		if(!discarded && stat(toname, &st) < 0) {
 			if(errno == ENOENT) {
-				discardedname = concatstr(3,
+				discardedname = concatstr(4,
 						listdir, "/queue/discarded/",
-						dp->d_name);
+						dp->d_name, ".by-maintd");
 				discarded = discardmail(mailname,
 							discardedname,
 							3600);
--- a/src/mlmmj-sub.c	Tue Nov 09 22:36:14 2004 +1100
+++ b/src/mlmmj-sub.c	Wed Nov 10 02:19:04 2004 +1100
@@ -390,9 +390,10 @@
 int main(int argc, char **argv)
 {
 	char *listaddr, *listdir = NULL, *address = NULL, *subfilename = NULL;
-	char *mlmmjsend, *bindir, chstr[2], *subdir;
+	char *mlmmjsend, *bindir, chstr[2], *subdir, *subddirname = NULL;
 	int subconfirm = 0, confirmsub = 0, opt, subfilefd, lock, notifysub;
 	int changeuid = 1, status, digest = 0, nomail = 0;
+	int groupwritable = 0;
 	size_t len;
 	off_t suboff;
 	struct stat st;
@@ -470,6 +471,15 @@
 		exit(EXIT_SUCCESS);  /* XXX is this success? */
 	}
 
+	subddirname = concatstr(2, listdir, "/subscribers.d");
+	if (stat(subddirname, &st) == 0) {
+		if(st.st_mode & S_IWGRP) {
+			groupwritable = S_IRGRP|S_IWGRP;
+			umask(S_IWOTH);
+			setgid(st.st_gid);
+		}
+	}
+
 	if(changeuid) {
 		uid = getuid();
 		if(!uid && stat(listdir, &st) == 0) {
@@ -501,7 +511,8 @@
 	subfilename = concatstr(3, listdir, subdir, chstr);
 	myfree(subdir);
 
-	subfilefd = open(subfilename, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
+	subfilefd = open(subfilename, O_RDWR|O_CREAT,
+				S_IRUSR|S_IWUSR|groupwritable);
 	if(subfilefd == -1) {
 		log_error(LOG_ARGS, "Could not open '%s'", subfilename);
 		exit(EXIT_FAILURE);
--- a/src/mlmmj-unsub.c	Tue Nov 09 22:36:14 2004 +1100
+++ b/src/mlmmj-unsub.c	Wed Nov 10 02:19:04 2004 +1100
@@ -427,7 +427,7 @@
 {
 	int subread, subwrite, rlock, wlock, opt, unsubres, status, nomail = 0;
 	int confirmunsub = 0, unsubconfirm = 0, notifysub = 0, digest = 0;
-	int changeuid = 1;
+	int changeuid = 1, groupwritable = 0;
 	char *listaddr, *listdir = NULL, *address = NULL, *subreadname = NULL;
 	char *subwritename, *mlmmjsend, *bindir, *subdir;
 	char *subddirname;
@@ -530,6 +530,12 @@
 	}
 		
 	subddirname = concatstr(2, listdir, subdir);
+	if (stat(subddirname, &st) == 0) {
+		if(st.st_mode & S_IWGRP) {
+			groupwritable = S_IRGRP|S_IWGRP;
+			umask(S_IWOTH);
+		}
+	}
 
 	if(is_subbed_in(subddirname, address)) {
 		/* Address is not subscribed, so exit silently */
@@ -588,7 +594,7 @@
 		subwritename = concatstr(2, subreadname, ".new");
 
 		subwrite = open(subwritename, O_RDWR | O_CREAT | O_EXCL,
-				S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+				S_IRUSR | S_IWUSR | groupwritable);
 		if(subwrite == -1){
 			log_error(LOG_ARGS, "Could not open '%s'",
 					subwritename);