Skip to contentSkip to conversation

Subscribers management in php-admin

mlmmj Marc MAURICE 4 participants 14 messages Feb 27, 2012 – Mar 11, 2012

lore
Share & tools
lore
#0 lore raw

Hello mlmmj team,

Here is a patch I made to add simple subscribers management in the php-admin interface.

I added some lines in php-admin README file in order to fix some permission issues. Those issues might also be relevant for the perl version.

I also suggest you to add a log_error line in subscriberfuncs.c. Without it we have no clue about what is wrong when mlmmj is not able to read subdir files.

Feel free to adapt my patch if needed.

Thanks for providing mlmmj to us !

Regards,
Marc

contrib/web/php-admin/README +11 -0
diff -r 3168aed4b01a contrib/web/php-admin/README
@@ -22,8 +22,19 @@
    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:
 
+     # addgroup mlmmj
+     # adduser wwwrun mlmmj
+     # adduser mailuser mlmmj
      # chgrp -R mlmmj /var/spool/mlmmj/mlmmj-test/subscribers.d/
      # chmod -R g+w /var/spool/mlmmj/mlmmj-test/subscribers.d/
+     # chmod g+s /var/spool/mlmmj/mlmmj-test/subscribers.d/
+
+   setgid flag is needed when the webserver calls mlmmj-sub and creates a file
+   under subscribers.d, to keep the mlmmj group.
+
+   If using the Exim mailserver, you should add initgroups = true in your
+   mlmmj_transport, otherwise it won't be able to write files having write
+   permission to mlmmj group.
 
 5) To enable access control on Apache you have to rename dot.htaccess to
    .htaccess and edit the path inside the file to point to a htpasswd file
contrib/web/php-admin/htdocs/index.php +6 -5
diff -r 3168aed4b01a contrib/web/php-admin/htdocs/index.php
@@ -35,15 +35,16 @@
 
 $lists = "";
 
-$dir = opendir($topdir);
-while ($file = readdir($dir)) {
+# use scandir to have alphabetical order
+foreach (scandir($topdir) as $file) {
     if (!ereg("^\.",$file))
     {
-	$lists .= "<a href=\"edit.php?list=".urlencode($file)."\">".
-	    htmlentities($file)."</a><br />\n";
+	$lists .= "<p>".htmlentities($file)."<br/>
+<a href=\"edit.php?list=".urlencode($file)."\">Config</a> - <a href=\"subscribers.php?list=".urlencode($file)."\">Subscribers</a>
+</p>
+";
     }
 }
-closedir($dir); 
 
 $tpl->assign(array("LISTS" => $lists));
 
contrib/web/php-admin/htdocs/subscribers.php new file +86 -0

86 lines not on this page · raw message

contrib/web/php-admin/templates/subscribers.html new file +38 -0
diff -r 3168aed4b01a contrib/web/php-admin/templates/subscribers.html
@@ -0,0 +1,38 @@
+<html>
+<head>
+<title>mlmmj - {LIST} subscribers</title>
+<style type="text/css">
+#subscribers {
+	float: left;
+}
+
+#addsubscribers {
+        float: left;
+	margin-left: 2em;
+}
+#index {
+	clear: both;
+}
+</style>
+</head>
+<body>
+<h1>{LIST} subscribers</h1>
+
+{MESSAGE}
+
+<table id="subscribers">
+{SUBS}
+</table>
+
+<form method="post" action="subscribers.php?list={LIST}" id="addsubscribers">
+Add subscribers:<br/>
+<textarea name="tosubscribe" rows="5" cols="30">
+</textarea><br/>
+<input type="submit" name="submit" value="Add" />
+</form>
+
+<p id="index">
+<a href="index.php">Index</a>
+</p>
+</body>
+</html>
src/subscriberfuncs.c +1 -0
diff -r 3168aed4b01a src/subscriberfuncs.c
@@ -132,6 +132,7 @@
 		subreadname = concatstr(2, subddirname, dp->d_name);
 		subread = open(subreadname, O_RDONLY);
 		if(subread < 0) {
+	                log_error(LOG_ARGS, "Could not open %s", subreadname);
 			myfree(subreadname);
 			continue;
 		}
#1 lore raw

contrib/web/php-admin/htdocs/subscribers.php line 45

Quoted 4 lines · Marc MAURICE
contrib/web/php-admin/htdocs/subscribers.php new file +4 -0
+} else if (isset($_POST["delete"])) {
+
+	$email = $_POST["email"];
+	$cmd = "/usr/bin/mlmmj-unsub -L /var/spool/mlmmj/$list -a '$email' 2>&1";

What if $email contains:

'; rm -rf /

Please don't accept such a weak code. At least, a minimum check on the validity of $email variable content should be made. In fact, and generally speaking, absolutely *all* input variables should be checked.

Thomas

#2 lore raw
In reply to Marc MAURICE

I agree with you Thomas.
I forgot the check because the interface is http auth restricted, but this is not not an excuse.

We should also fix the existing code in save.php.

Marc

Quoted 16 lines · Thomas Goirand

contrib/web/php-admin/htdocs/subscribers.php line 45

Quoted 4 lines · Marc MAURICE
contrib/web/php-admin/htdocs/subscribers.php new file +4 -0
+} else if (isset($_POST["delete"])) {
+
+	$email = $_POST["email"];
+	$cmd = "/usr/bin/mlmmj-unsub -L /var/spool/mlmmj/$list -a '$email' 2>&1";

What if $email contains:

'; rm -rf /

Please don't accept such a weak code. At least, a minimum check on the validity of $email variable content should be made. In fact, and generally speaking, absolutely *all* input variables should be checked.

Thomas

#3 lore raw
In reply to Marc MAURICE
Quoted 8 lines · Thomas Goirand

contrib/web/php-admin/htdocs/subscribers.php line 45

Quoted 4 lines · Marc MAURICE
contrib/web/php-admin/htdocs/subscribers.php new file +4 -0
+} else if (isset($_POST["delete"])) {
+
+	$email = $_POST["email"];
+	$cmd = "/usr/bin/mlmmj-unsub -L /var/spool/mlmmj/$list -a '$email' 2>&1";

What if $email contains:

Quoted 5 lines

'; rm -rf /

Please don't accept such a weak code. At least, a minimum check on the validity of $email variable content should be made. In fact, and generally speaking, absolutely *all* input variables should be checked.

And indeed, since ' is a valid character in an email address, the value will have to be properly escaped when passed to the shell, not just validated.

It wouldn't surprise me if some of the other PHP code is wrong, too.

Please do throw some good patches my way and I'll get them in. These kinds of validation fixes are worth getting into a release as soon as possible.

The extra functionality will go in too, but perhaps not into the next release unless I get it very soon. (I finished implementation for the next release tonight, so in a day or two, after a little testing, I'll release an alpha and declare feature-freeze.)

Ben.

#4 lore raw
In reply to Marc MAURICE
Quoted 7 lines · Marc MAURICE

I agree with you Thomas.
I forgot the check because the interface is http auth restricted, but this is not not an excuse.

We should also fix the existing code in save.php.

Marc

Not only this. You should check for the variable validity, with a regular expression like this one for example:
$reg = "/(^([a-zA-Z0-9])|^([a-zA-Z0-9]+)([._a-zA-Z0-9-]*))@ ([a-z0-9]+)([-a-z0-9.]*)\.([a-z0-9-]*)([a-z0-9]+)\$/";

(note that you should remove the \n after the @)

but you should *also* use escapeshellarg():
http://www.php.net/manual/en/function.escapeshellarg.php

As for the save.php, I also found some very silly piece of code like this one:
// Perl's encode_entities (to be able to use tunables.pl) function encode_entities($str) { return htmlentities($str); }

I'd like someone to explain to me why htmlentities() has to be wrapped like this... :)

Then, there's things like this which worries me:
fwrite($fp, $HTTP_POST_VARS[$name]);

Not only the variable should be checked, but also, if I'm not mistaking, $HTTP_POST_VARS is deprecated, and maybe even *removed* (I didn't check) from php 5.4, which is going to reach Debian SID in a mater of weeks now (we should be using $_POST instead).

Functions like mlmmj_boolean() has parameters that it isn't using, so it's weird.

So yes, all this needs a code review... :)

Thomas

#5 lore raw
In reply to Marc MAURICE
Quoted 7 lines

As for the save.php, I also found some very silly piece of code like this one:
// Perl's encode_entities (to be able to use tunables.pl) function encode_entities($str) { return htmlentities($str); }

I'd like someone to explain to me why htmlentities() has to be wrapped like this... :)

For exactly the reason in the code comment: it's so that tunables.pl can be used. The PHP file evaluates the tunables.pl (Perl) file as if it were a PHP file. The tunables.pl file uses the Perl function encode_entities(), so to make it work, a function of that name is defined in PHP that just calls the equivalent PHP function. The benefit is that only one tunables.pl file needs to be maintained, not a tunables.pl and a tunables.php.

Quoted 7 lines

Then, there's things like this which worries me:
fwrite($fp, $HTTP_POST_VARS[$name]);

Not only the variable should be checked, but also, if I'm not mistaking, $HTTP_POST_VARS is deprecated, and maybe even *removed* (I didn't check) from php 5.4, which is going to reach Debian SID in a mater of weeks now (we should be using $_POST instead).

This was at least partly fixed ages ago in version control, so you evidently didn't check the current state of Mlmmj either. :-)

Quoted 4 lines

Functions like mlmmj_boolean() has parameters that it isn't using, so it's weird.

So yes, all this needs a code review... :)

Never hurts.

Ben.

#6 lore raw
In reply to Marc MAURICE

Hello,

A new patch using
filter_var($email, FILTER_VALIDATE_EMAIL)
and escapeshellarg().

Marc

Quoted 27 lines · Ben Schmidt
Quoted 7 lines

As for the save.php, I also found some very silly piece of code like this one:
// Perl's encode_entities (to be able to use tunables.pl) function encode_entities($str) { return htmlentities($str); }

I'd like someone to explain to me why htmlentities() has to be wrapped like this... :)

For exactly the reason in the code comment: it's so that tunables.pl can be used. The PHP file evaluates the tunables.pl (Perl) file as if it were a PHP file. The tunables.pl file uses the Perl function encode_entities(), so to make it work, a function of that name is defined in PHP that just calls the equivalent PHP function. The benefit is that only one tunables.pl file needs to be maintained, not a tunables.pl and a tunables.php.

Quoted 7 lines

Then, there's things like this which worries me:
fwrite($fp, $HTTP_POST_VARS[$name]);

Not only the variable should be checked, but also, if I'm not mistaking, $HTTP_POST_VARS is deprecated, and maybe even *removed* (I didn't check) from php 5.4, which is going to reach Debian SID in a mater of weeks now (we should be using $_POST instead).

This was at least partly fixed ages ago in version control, so you evidently didn't check the current state of Mlmmj either. :-)

Quoted 13 lines
Quoted 4 lines

Functions like mlmmj_boolean() has parameters that it isn't using, so it's weird.

So yes, all this needs a code review... :)

Never hurts.

Ben.

contrib/web/php-admin/README +11 -0
diff -r 3168aed4b01a contrib/web/php-admin/README
@@ -22,8 +22,19 @@
    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:
 
+     # addgroup mlmmj
+     # adduser wwwrun mlmmj
+     # adduser mailuser mlmmj
      # chgrp -R mlmmj /var/spool/mlmmj/mlmmj-test/subscribers.d/
      # chmod -R g+w /var/spool/mlmmj/mlmmj-test/subscribers.d/
+     # chmod g+s /var/spool/mlmmj/mlmmj-test/subscribers.d/
+
+   setgid flag is needed when the webserver calls mlmmj-sub and creates a file
+   under subscribers.d, to keep the mlmmj group.
+
+   If using the Exim mailserver, you should add initgroups = true in your
+   mlmmj_transport, otherwise it won't be able to write files having write
+   permission to mlmmj group.
 
 5) To enable access control on Apache you have to rename dot.htaccess to
    .htaccess and edit the path inside the file to point to a htpasswd file
contrib/web/php-admin/htdocs/index.php +6 -5
diff -r 3168aed4b01a contrib/web/php-admin/htdocs/index.php
@@ -35,15 +35,16 @@
 
 $lists = "";
 
-$dir = opendir($topdir);
-while ($file = readdir($dir)) {
+# use scandir to have alphabetical order
+foreach (scandir($topdir) as $file) {
     if (!ereg("^\.",$file))
     {
-	$lists .= "<a href=\"edit.php?list=".urlencode($file)."\">".
-	    htmlentities($file)."</a><br />\n";
+	$lists .= "<p>".htmlentities($file)."<br/>
+<a href=\"edit.php?list=".urlencode($file)."\">Config</a> - <a href=\"subscribers.php?list=".urlencode($file)."\">Subscribers</a>
+</p>
+";
     }
 }
-closedir($dir); 
 
 $tpl->assign(array("LISTS" => $lists));
 
contrib/web/php-admin/htdocs/subscribers.php new file +92 -0

92 lines not on this page · raw message

contrib/web/php-admin/templates/subscribers.html new file +38 -0
diff -r 3168aed4b01a contrib/web/php-admin/templates/subscribers.html
@@ -0,0 +1,38 @@
+<html>
+<head>
+<title>mlmmj - {LIST} subscribers</title>
+<style type="text/css">
+#subscribers {
+	float: left;
+}
+
+#addsubscribers {
+        float: left;
+	margin-left: 2em;
+}
+#index {
+	clear: both;
+}
+</style>
+</head>
+<body>
+<h1>{LIST} subscribers</h1>
+
+{MESSAGE}
+
+<table id="subscribers">
+{SUBS}
+</table>
+
+<form method="post" action="subscribers.php?list={LIST}" id="addsubscribers">
+Add subscribers:<br/>
+<textarea name="tosubscribe" rows="5" cols="30">
+</textarea><br/>
+<input type="submit" name="submit" value="Add" />
+</form>
+
+<p id="index">
+<a href="index.php">Index</a>
+</p>
+</body>
+</html>
src/subscriberfuncs.c +1 -0
diff -r 3168aed4b01a src/subscriberfuncs.c
@@ -132,6 +132,7 @@
 		subreadname = concatstr(2, subddirname, dp->d_name);
 		subread = open(subreadname, O_RDONLY);
 		if(subread < 0) {
+	                log_error(LOG_ARGS, "Could not open %s", subreadname);
 			myfree(subreadname);
 			continue;
 		}
#7 lore raw
In reply to Marc MAURICE

contrib/web/php-admin/htdocs/subscribers.php

Quoted 13 lines · Marc MAURICE
contrib/web/php-admin/htdocs/subscribers.php new file +13 -0
+if (isset($_POST["tosubscribe"])) {
+	
+	foreach (preg_split('/\r\n|\n|\r/', $_POST["tosubscribe"]) as $line) {
+		$email = trim($line);
+		if ($email != "") {
+			if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
+				$cmd = "/usr/bin/mlmmj-sub -L '/var/spool/mlmmj/".escapeshellarg($list)."' -a '".escapeshellarg($email)."' 2>&1";
+				exec($cmd, $out, $ret);
+				if ($ret != 0) {
+					$message.= "Subscribe error for $email <!--cmd=$cmd out=".implode($out)." ret=$ret--> <br/>";
+				}
+			} else {
+				$message.= "Email address not valid: $email <br/>";

If $email isn't valid, then it's even more a reason not to display it (eg: unless you want to shoot yourself in the foot with issues like cross site scripting...).

Also, I'm not sure what you are attempting with "displaying" the output of the subscribing command in a HTML comment. Why not displaying it for real, using htmlspecialchars() (which by the way, you didn't use, which is dangerous) and ln2br() in a <pre> tag?

Thomas

#8 lore raw
In reply to Marc MAURICE

Here is the new patch version.

The email should be displayed, otherwise the user will have no clue about which email is wrong if his email list is very long.

I put htmlspecialchars everywhere and errors are now enclosed in <pre> tags. no need for ln2br in <pre> tags no ?

Marc

Quoted 18 lines · Thomas Goirand

Review

Quoted 13 lines · Marc MAURICE
(quoted diff) +13 -0
+if (isset($_POST["tosubscribe"])) {
+	
+	foreach (preg_split('/\r\n|\n|\r/', $_POST["tosubscribe"]) as $line) {
+		$email = trim($line);
+		if ($email != "") {
+			if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
+				$cmd = "/usr/bin/mlmmj-sub -L '/var/spool/mlmmj/".escapeshellarg($list)."' -a '".escapeshellarg($email)."' 2>&1";
+				exec($cmd, $out, $ret);
+				if ($ret !== 0) {
+					$message.= "Subscribe error for $email<!--cmd=$cmd out=".implode($out)." ret=$ret-->  <br/>";
+				}
+			} else {
+				$message.= "Email address not valid: $email<br/>";

If $email isn't valid, then it's even more a reason not to display it (eg: unless you want to shoot yourself in the foot with issues like cross site scripting...).

Quoted 8 lines

Also, I'm not sure what you are attempting with "displaying" the output of the subscribing command in a HTML comment. Why not displaying it for real, using htmlspecialchars() (which by the way, you didn't use, which is dangerous) and ln2br() in a<pre> tag?

Thomas

contrib/web/php-admin/README +11 -0
diff -r 3168aed4b01a contrib/web/php-admin/README
@@ -22,8 +22,19 @@
    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:
 
+     # addgroup mlmmj
+     # adduser wwwrun mlmmj
+     # adduser mailuser mlmmj
      # chgrp -R mlmmj /var/spool/mlmmj/mlmmj-test/subscribers.d/
      # chmod -R g+w /var/spool/mlmmj/mlmmj-test/subscribers.d/
+     # chmod g+s /var/spool/mlmmj/mlmmj-test/subscribers.d/
+
+   setgid flag is needed when the webserver calls mlmmj-sub and creates a file
+   under subscribers.d, to keep the mlmmj group.
+
+   If using the Exim mailserver, you should add initgroups = true in your
+   mlmmj_transport, otherwise it won't be able to write files having write
+   permission to mlmmj group.
 
 5) To enable access control on Apache you have to rename dot.htaccess to
    .htaccess and edit the path inside the file to point to a htpasswd file
contrib/web/php-admin/htdocs/index.php +6 -5
diff -r 3168aed4b01a contrib/web/php-admin/htdocs/index.php
@@ -35,15 +35,16 @@
 
 $lists = "";
 
-$dir = opendir($topdir);
-while ($file = readdir($dir)) {
+# use scandir to have alphabetical order
+foreach (scandir($topdir) as $file) {
     if (!ereg("^\.",$file))
     {
-	$lists .= "<a href=\"edit.php?list=".urlencode($file)."\">".
-	    htmlentities($file)."</a><br />\n";
+	$lists .= "<p>".htmlentities($file)."<br/>
+<a href=\"edit.php?list=".urlencode($file)."\">Config</a> - <a href=\"subscribers.php?list=".urlencode($file)."\">Subscribers</a>
+</p>
+";
     }
 }
-closedir($dir); 
 
 $tpl->assign(array("LISTS" => $lists));
 
contrib/web/php-admin/htdocs/subscribers.php new file +93 -0

93 lines not on this page · raw message

contrib/web/php-admin/templates/subscribers.html new file +38 -0
diff -r 3168aed4b01a contrib/web/php-admin/templates/subscribers.html
@@ -0,0 +1,38 @@
+<html>
+<head>
+<title>mlmmj - {LIST} subscribers</title>
+<style type="text/css">
+#subscribers {
+	float: left;
+}
+
+#addsubscribers {
+        float: left;
+	margin-left: 2em;
+}
+#index {
+	clear: both;
+}
+</style>
+</head>
+<body>
+<h1>{LIST} subscribers</h1>
+
+{MESSAGE}
+
+<table id="subscribers">
+{SUBS}
+</table>
+
+<form method="post" action="subscribers.php?list={LIST}" id="addsubscribers">
+Add subscribers:<br/>
+<textarea name="tosubscribe" rows="5" cols="30">
+</textarea><br/>
+<input type="submit" name="submit" value="Add" />
+</form>
+
+<p id="index">
+<a href="index.php">Index</a>
+</p>
+</body>
+</html>
src/subscriberfuncs.c +1 -0
diff -r 3168aed4b01a src/subscriberfuncs.c
@@ -132,6 +132,7 @@
 		subreadname = concatstr(2, subddirname, dp->d_name);
 		subread = open(subreadname, O_RDONLY);
 		if(subread < 0) {
+	                log_error(LOG_ARGS, "Could not open %s", subreadname);
 			myfree(subreadname);
 			continue;
 		}
#9 lore raw
In reply to Marc MAURICE

Thanks for your contribution. The patch is getting better, but here are some further review comments:

- You have added new files; could they have headers clarifying their license, please?
- /var/spool/mlmmj should not be hardcoded; you should use $topdir.
- You need to unset($out) before calling exec(...,$out,...); see the PHP documentation for exec().
- Please don't ini_set display_errors to true; that could expose details that the server administrator does not want to expose; admins should have their PHP logging set up adequately to give them what they need, or can change ini settings themselves if they need to.
- Could you concatenate strings and use \n for linebreaks, please, maintaining the indent in the PHP script, instead of having string literals that span multiple lines?
- Could you consider extending this slightly to allow subscription of digesters and nomailers? (Update the README, too, to get permissions set correctly on all relevant directories.) This could be a separate patch, or omitted, but it would be nice.

And yes, of course inside <pre> ln2br is unnecessary.

Cheers,

Ben.

Quoted 40 lines · Marc MAURICE

Here is the new patch version.

The email should be displayed, otherwise the user will have no clue about which email is wrong if his email list is very long.

I put htmlspecialchars everywhere and errors are now enclosed in <pre> tags. no need for ln2br in <pre> tags no ?

Marc

Quoted 28 lines · Thomas Goirand
Quoted 7 lines · Marc MAURICE
contrib/web/php-admin/htdocs/subscribers.php new file +7 -0
+if (isset($_POST["tosubscribe"])) {
+
+ foreach (preg_split('/\r\n|\n|\r/', $_POST["tosubscribe"]) as $line) {
+ $email = trim($line);
+ if ($email != "") {
+ if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
+ $cmd = "/usr/bin/mlmmj-sub -L '/var/spool/mlmmj/".escapeshellarg($list)."' -a
Quoted 8 lines

'".escapeshellarg($email)."' 2>&1";
+ exec($cmd, $out, $ret);
+ if ($ret != 0) {
+ $message.= "Subscribe error for $email<!--cmd=$cmd out=".implode($out)." ret=$ret--> <br/>";
+ }
+ } else {
+ $message.= "Email address not valid: $email<br/>";

If $email isn't valid, then it's even more a reason not to display it (eg: unless you want to shoot yourself in the foot with issues like cross site scripting...).

Also, I'm not sure what you are attempting with "displaying" the output of the subscribing command in a HTML comment. Why not displaying it for real, using htmlspecialchars() (which by the way, you didn't use, which is dangerous) and ln2br() in a<pre> tag?

Thomas

#10 lore raw
In reply to Marc MAURICE

Hello Ben,

Here is the new patch.

Quoted 2 lines

- You have added new files; could they have headers clarifying their license, please?

license added to subscribers.php

Quoted 1 line

- /var/spool/mlmmj should not be hardcoded; you should use $topdir.

done

Quoted 2 lines

- You need to unset($out) before calling exec(...,$out,...); see the PHP documentation for exec().

done

Quoted 4 lines

- Please don't ini_set display_errors to true; that could expose details that the server administrator does not want to expose; admins should have their PHP logging set up adequately to give them what they need, or can change ini settings themselves if they need to.

deleted

Quoted 3 lines

- Could you concatenate strings and use \n for linebreaks, please, maintaining the indent in the PHP script, instead of having string literals that span multiple lines?

done in index.php

Quoted 4 lines

- Could you consider extending this slightly to allow subscription of digesters and nomailers? (Update the README, too, to get permissions set correctly on all relevant directories.) This could be a separate patch, or omitted, but it would be nice.

Yes, it would be better in a new patch.
I will try to find some time to work on it next days.

Ho I have on question : what is the main purpose of nomailers ? I understand that those people do not get any list mail.
Is it to be able to post to a list without receiving mail with subonlypost ?

I did not find anything about it in the doc.

Thanks in advance,

Marc

Quoted 40 lines · Marc MAURICE
Quoted 35 lines

Here is the new patch version.

The email should be displayed, otherwise the user will have no clue about which email is wrong if his email list is very long.

I put htmlspecialchars everywhere and errors are now enclosed in <pre> tags. no need for ln2br in <pre> tags no ?

Marc

Quoted 23 lines · Thomas Goirand
Quoted 10 lines · Marc MAURICE
(quoted diff) +3 -0
+if (isset($_POST["tosubscribe"])) {
+
+ foreach (preg_split('/\r\n|\n|\r/', $_POST["tosubscribe"]) as 

$line) {
+ $email = trim($line);
+ if ($email != "") {
+ if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
+ $cmd = "/usr/bin/mlmmj-sub -L '/var/spool/mlmmj/".escapeshellarg($list)."' -a '".escapeshellarg($email)."' 2>&1";

Quoted 8 lines

+ exec($cmd, $out, $ret);
+ if ($ret !== 0) {
+ $message.= "Subscribe error for $email<!--cmd=$cmd out=".implode($out)."
ret=$ret--> <br/>";
+ }
+ } else {
+ $message.= "Email address not valid: $email<br/>";

If $email isn't valid, then it's even more a reason not to display it (eg: unless you want to shoot yourself in the foot with issues like cross site scripting...).

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Also, I'm not sure what you are attempting with "displaying" the output of the subscribing command in a HTML comment. Why not displaying it for real, using htmlspecialchars() (which by the way, you didn't use, which is dangerous) and ln2br() in a<pre> tag?

Thomas

contrib/web/php-admin/README +11 -0
diff -r 3168aed4b01a contrib/web/php-admin/README
@@ -22,8 +22,19 @@
    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:
 
+     # addgroup mlmmj
+     # adduser wwwrun mlmmj
+     # adduser mailuser mlmmj
      # chgrp -R mlmmj /var/spool/mlmmj/mlmmj-test/subscribers.d/
      # chmod -R g+w /var/spool/mlmmj/mlmmj-test/subscribers.d/
+     # chmod g+s /var/spool/mlmmj/mlmmj-test/subscribers.d/
+
+   setgid flag is needed when the webserver calls mlmmj-sub and creates a file
+   under subscribers.d, to keep the mlmmj group.
+
+   If using the Exim mailserver, you should add initgroups = true in your
+   mlmmj_transport, otherwise it won't be able to write files having write
+   permission to mlmmj group.
 
 5) To enable access control on Apache you have to rename dot.htaccess to
    .htaccess and edit the path inside the file to point to a htpasswd file
contrib/web/php-admin/htdocs/index.php +5 -5
diff -r 3168aed4b01a contrib/web/php-admin/htdocs/index.php
@@ -35,15 +35,15 @@
 
 $lists = "";
 
-$dir = opendir($topdir);
-while ($file = readdir($dir)) {
+# use scandir to have alphabetical order
+foreach (scandir($topdir) as $file) {
     if (!ereg("^\.",$file))
     {
-	$lists .= "<a href=\"edit.php?list=".urlencode($file)."\">".
-	    htmlentities($file)."</a><br />\n";
+	$lists .= "<p>".htmlentities($file)."<br/>\n";
+	$lists .= "<a href=\"edit.php?list=".urlencode($file)."\">Config</a> - <a href=\"subscribers.php?list=".urlencode($file)."\">Subscribers</a>\n";
+	$lists .= "</p>\n";
     }
 }
-closedir($dir); 
 
 $tpl->assign(array("LISTS" => $lists));
 
contrib/web/php-admin/htdocs/subscribers.php new file +114 -0

114 lines not on this page · raw message

contrib/web/php-admin/templates/subscribers.html new file +38 -0
diff -r 3168aed4b01a contrib/web/php-admin/templates/subscribers.html
@@ -0,0 +1,38 @@
+<html>
+<head>
+<title>mlmmj - {LIST} subscribers</title>
+<style type="text/css">
+#subscribers {
+	float: left;
+}
+
+#addsubscribers {
+        float: left;
+	margin-left: 2em;
+}
+#index {
+	clear: both;
+}
+</style>
+</head>
+<body>
+<h1>{LIST} subscribers</h1>
+
+{MESSAGE}
+
+<table id="subscribers">
+{SUBS}
+</table>
+
+<form method="post" action="subscribers.php?list={LIST}" id="addsubscribers">
+Add subscribers:<br/>
+<textarea name="tosubscribe" rows="5" cols="30">
+</textarea><br/>
+<input type="submit" name="submit" value="Add" />
+</form>
+
+<p id="index">
+<a href="index.php">Index</a>
+</p>
+</body>
+</html>
src/subscriberfuncs.c +1 -0
diff -r 3168aed4b01a src/subscriberfuncs.c
@@ -132,6 +132,7 @@
 		subreadname = concatstr(2, subddirname, dp->d_name);
 		subread = open(subreadname, O_RDONLY);
 		if(subread < 0) {
+	                log_error(LOG_ARGS, "Could not open %s", subreadname);
 			myfree(subreadname);
 			continue;
 		}
#11 lore raw
In reply to Marc MAURICE
Quoted 4 lines · Marc MAURICE

Ho I have on question : what is the main purpose of nomailers ? I understand that those people do not get any list mail. Is it to be able to post to a list without receiving mail with subonlypost ?

Yes.

Some people read the list and want to post from several addresses, but only want the list delivered in one of their mailboxes.

Signature · 4 lines
Mads Martin Joergensen, http://mmj.dk
"Why make things difficult, when it is possible to make them cryptic
  and totally illogical, with just a little bit more effort?"
                                  -- A. P. J.
#12 lore raw
In reply to Marc MAURICE

Committed. Thank you, Marc.

If you're able to extend it one day to handle digesters and nomailers, just send the patch my way.

Smiles,

Ben.

Quoted 85 lines · Marc MAURICE

Hello Ben,

Here is the new patch.

Quoted 2 lines

- You have added new files; could they have headers clarifying their license, please?

license added to subscribers.php

Quoted 1 line

- /var/spool/mlmmj should not be hardcoded; you should use $topdir.

done

Quoted 2 lines

- You need to unset($out) before calling exec(...,$out,...); see the PHP documentation for exec().

done

Quoted 4 lines

- Please don't ini_set display_errors to true; that could expose details that the server administrator does not want to expose; admins should have their PHP logging set up adequately to give them what they need, or can change ini settings themselves if they need to.

deleted

Quoted 3 lines

- Could you concatenate strings and use \n for linebreaks, please, maintaining the indent in the PHP script, instead of having string literals that span multiple lines?

done in index.php

Quoted 4 lines

- Could you consider extending this slightly to allow subscription of digesters and nomailers? (Update the README, too, to get permissions set correctly on all relevant directories.) This could be a separate patch, or omitted, but it would be nice.

Yes, it would be better in a new patch.
I will try to find some time to work on it next days.

Ho I have on question : what is the main purpose of nomailers ? I understand that those people do not get any list mail.
Is it to be able to post to a list without receiving mail with subonlypost ?

I did not find anything about it in the doc.

Thanks in advance,

Marc

Quoted 45 lines · Marc MAURICE
Quoted 40 lines

Here is the new patch version.

The email should be displayed, otherwise the user will have no clue about which email is wrong if his email list is very long.

I put htmlspecialchars everywhere and errors are now enclosed in <pre> tags. no need for ln2br in <pre> tags no ?

Marc

Quoted 28 lines · Thomas Goirand
Quoted 7 lines · Marc MAURICE
contrib/web/php-admin/htdocs/subscribers.php new file +7 -0
+if (isset($_POST["tosubscribe"])) {
+
+ foreach (preg_split('/\r\n|\n|\r/', $_POST["tosubscribe"]) as $line) {
+ $email = trim($line);
+ if ($email != "") {
+ if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
+ $cmd = "/usr/bin/mlmmj-sub -L '/var/spool/mlmmj/".escapeshellarg($list)."' -a
Quoted 8 lines

'".escapeshellarg($email)."' 2>&1";
+ exec($cmd, $out, $ret);
+ if ($ret != 0) {
+ $message.= "Subscribe error for $email<!--cmd=$cmd out=".implode($out)." ret=$ret--> <br/>";
+ }
+ } else {
+ $message.= "Email address not valid: $email<br/>";

If $email isn't valid, then it's even more a reason not to display it (eg: unless you want to shoot yourself in the foot with issues like cross site scripting...).

Also, I'm not sure what you are attempting with "displaying" the output of the subscribing command in a HTML comment. Why not displaying it for real, using htmlspecialchars() (which by the way, you didn't use, which is dangerous) and ln2br() in a<pre> tag?

Thomas

#13 lore raw
In reply to Marc MAURICE
Quoted 10 lines · Mads Martin Jørgensen
Quoted 4 lines · Marc MAURICE

Ho I have on question : what is the main purpose of nomailers ? I understand that those people do not get any list mail. Is it to be able to post to a list without receiving mail with subonlypost ?

Yes.

Some people read the list and want to post from several addresses, but only want the list delivered in one of their mailboxes.

And it can also be useful just to 'turn off' the list when you're away on holidays instead of needing to fully unsubscribe and subscribe again (and confirm it each time or, in the case of a closed list, bother an administrator).

Ben.