edit: drop executable bits to mark non-editable
[minimedit.git] / edit.php
old mode 100755 (executable)
new mode 100644 (file)
index 1091da4..80a49eb
--- a/edit.php
+++ b/edit.php
@@ -15,12 +15,21 @@ $filename = preg_replace('/(?:\.html)?$/', '.html', ltrim($_SERVER['PATH_INFO'],
 if (file_exists($filename) and !is_writable($filename))
        abort('403 input error', "ongeldige bestandsnaam: $filename");
 
-$prepend = '<!--#include virtual="/common.html" -->'."\n\n";
-$append  = "\n".'<!--#include virtual="/footer.html" -->'."\n";
+if (!isset($_POST['body']))
+       abort('409 input error', "geen inhoud aangeleverd");
+
 $upload = $_POST['body'];
 
-if (!$upload)
-       abort('409 input error', "leeg bestand aangeleverd");
+if (!strlen($upload)) {
+       if (file_exists($filename) and !unlink($filename))
+               abort('500 delete error', "fout bij het verwijderen van $filename");
+
+       print "Bestand verwijderd";
+       exit;
+}
+
+$prepend = '<!--#include virtual="/head.inc.html" -->'."\n\n";
+$append  = "\n".'<!--#include virtual="/foot.inc.html" -->'."\n";
 
 if (!file_put_contents($filename, $prepend . $upload . $append))
        abort('500 save error', "fout bij schrijven van $filename");