exit;
}
+require 'auth.inc.php';
+if (!$Admin)
+ abort('401 unauthorised', "geen beheersrechten");
+
if (!$_POST)
abort('405 post error', "niets te doen");
if (!isset($_SERVER['PATH_INFO']) or strlen($_SERVER['PATH_INFO']) <= 1)
abort('409 input error', "geen bestand aangeleverd");
-$filename = preg_replace('/(?:\.html)?$/', '.html', ltrim($_SERVER['PATH_INFO'], '/'), 1);
+$filename = preg_replace('/(?:\.php)?$/', '.php', ltrim($_SERVER['PATH_INFO'], '/'), 1);
if (file_exists($filename) and !is_writable($filename))
abort('403 input error', "ongeldige bestandsnaam: $filename");
+if (is_executable($filename))
+ abort('403 input error', "onwijzigbaar bestand: $filename");
+
+if (!isset($_POST['body']))
+ abort('409 input error', "geen inhoud aangeleverd");
-$prepend = '<!--#include virtual="/common.html" -->'."\n\n";
-$append = "\n".'<!--#include virtual="/footer.html" -->'."\n";
$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;
+}
+
+$rootpath = str_repeat('../', substr_count($filename, '/'));
+$prepend = "<?php include '${rootpath}head.inc.php'; ?>\n\n";
+$append = "\n";
if (!file_put_contents($filename, $prepend . $upload . $append))
abort('500 save error', "fout bij schrijven van $filename");