]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
Better EOL handling and error reporting in php-admin (Franky Van Liedekerke)
authorBen Schmidt <none@none>
Mon, 15 Nov 2010 10:07:50 +0000 (21:07 +1100)
committerBen Schmidt <none@none>
Mon, 15 Nov 2010 10:07:50 +0000 (21:07 +1100)
ChangeLog
contrib/web/php-admin/htdocs/edit.php
contrib/web/php-admin/htdocs/save.php

index 8f76c404adb99f4acfdc175a90acf089388a71e3..313deeb9c37c174f47fd36516c6260c3cd7c04a1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,5 @@
+ o Better end-of-line handling and error reporting in php-admin (Franky Van
+   Liedekerke)
  o Avoid losing mail when connecting to relayhost fails
  o Improved and more consistent closing of SMTP sessions in error cases
  o Check the relayhost gives a reply before reading it to avoid a crash
index 7787146828a69e5e88afc38fe43d0f2df8b25e8b..2179182831da8ce9b8e04a6ecd57cfe82e064435 100644 (file)
@@ -57,6 +57,9 @@ function mlmmj_string($name, $nicename, $text)
        $lines = file($file);
        $value = $lines[0];
     }
+
+    // remove trailing \n if any, just to be sure
+    $value = preg_replace('/\n$/',"",$value);
     
     $tpl->assign(array("NAME" => htmlentities($name),
                       "NICENAME" => htmlentities($nicename),
@@ -76,6 +79,10 @@ function mlmmj_list($name, $nicename, $text)
     if(is_file($file))
        $value = file_get_contents($file);
 
+    // the last \n would result in an extra empty line in the list box,
+    // so we remove it
+    $value = preg_replace('/\n$/',"",$value);
+
     $tpl->assign(array("NAME" => htmlentities($name),
                       "NICENAME" => htmlentities($nicename),
                       "TEXT" => htmlentities($text),
index 2867eea14ae17692239af4e3d66e9c486d34235e..73f249f60492c715fd2c233d6e53775d08ff8a2e 100644 (file)
@@ -43,14 +43,17 @@ function mlmmj_boolean($name, $nicename, $text)
           die("Couldn't chmod ".$file);
     }
     else {
-       @unlink($file);
+       if (file_exists($file)) {
+          if (!unlink($file))
+             die("Couldn't unlink ".$file);
+       }
     }
 }
 
 function mlmmj_string ($name, $nicename, $text) 
 {
     mlmmj_list($name, $nicename, $text);
-}   
+}
 
 function mlmmj_list($name, $nicename, $text) 
 {
@@ -58,21 +61,34 @@ function mlmmj_list($name, $nicename, $text)
 
     $file = $topdir."/".$list."/control/".$name;
     
-    if(isset($_POST[$name]) && !empty($_POST[$name]))
+    if(isset($_POST[$name]) && !empty($_POST[$name]) && !preg_match('/^\s*$/',$_POST[$name]))
     {
+       // remove all \r
+       $_POST[$name]=preg_replace('/\r/',"",$_POST[$name]);
+
+       // no trailing \n?, then we add one
+       if (!preg_match('/\n$/',$_POST[$name]))
+          $_POST[$name].="\n";
+
+       // we don't like whitespace before a \n
+       $_POST[$name]=preg_replace('/\s*\n/',"\n",$_POST[$name]);
+
        if (!$fp = fopen($file, "w"))
           die("Couldn't open ".$file." for writing");
 
-       fwrite($fp, preg_replace('/\\r/',"",$_POST[$name]));
+       // write the result in a file
+       fwrite($fp, $_POST[$name]);
        fclose($fp);
 
        if (!chmod($file, 0644))
           die("Couldn't chmod ".$file);
     }
     else {
-       @unlink($file);
+       if (file_exists($file)) {
+          if (!unlink($file))
+             die("Couldn't unlink ".$file);
+       }
     }
-    
 }
 
 // Perl's encode_entities (to be able to use tunables.pl)