# HG changeset patch # User Ben Schmidt # Date 1289815670 -39600 # Node ID 1311f31713baf02679d7c363c215b9143222ba49 # Parent 563b513fae210c03ce78c0244051ce3a26c6de1f Better EOL handling and error reporting in php-admin (Franky Van Liedekerke) diff -r 563b513fae21 -r 1311f31713ba ChangeLog --- a/ChangeLog Mon Nov 15 11:12:50 2010 +1100 +++ b/ChangeLog Mon Nov 15 21:07:50 2010 +1100 @@ -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 diff -r 563b513fae21 -r 1311f31713ba contrib/web/php-admin/htdocs/edit.php --- a/contrib/web/php-admin/htdocs/edit.php Mon Nov 15 11:12:50 2010 +1100 +++ b/contrib/web/php-admin/htdocs/edit.php Mon Nov 15 21:07:50 2010 +1100 @@ -58,6 +58,9 @@ $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), "TEXT" => htmlentities($text), @@ -76,6 +79,10 @@ 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), diff -r 563b513fae21 -r 1311f31713ba contrib/web/php-admin/htdocs/save.php --- a/contrib/web/php-admin/htdocs/save.php Mon Nov 15 11:12:50 2010 +1100 +++ b/contrib/web/php-admin/htdocs/save.php Mon Nov 15 21:07:50 2010 +1100 @@ -43,7 +43,10 @@ die("Couldn't chmod ".$file); } else { - @unlink($file); + if (file_exists($file)) { + if (!unlink($file)) + die("Couldn't unlink ".$file); + } } } @@ -58,21 +61,34 @@ $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)