2 function abort($status, $body) {
3 header("HTTP/1.1 $status");
8 require 'auth.inc.php';
10 abort('401 unauthorised', "geen beheersrechten");
13 abort('405 post error', "niets te doen");
14 if (!isset($_SERVER['PATH_INFO']) or strlen($_SERVER['PATH_INFO']) <= 1)
15 abort('409 input error', "geen bestand aangeleverd");
17 $filename = preg_replace('/(?:\.php)?$/', '.php', ltrim($_SERVER['PATH_INFO'], '/'), 1);
18 if (file_exists($filename) and !is_writable($filename))
19 abort('403 input error', "ongeldige bestandsnaam: $filename");
20 if (is_executable($filename))
21 abort('403 input error', "onwijzigbaar bestand: $filename");
23 if (!isset($_POST['body']))
24 abort('409 input error', "geen inhoud aangeleverd");
26 $upload = $_POST['body'];
28 if (!strlen($upload)) {
29 if (file_exists($filename) and !unlink($filename))
30 abort('500 delete error', "fout bij het verwijderen van $filename");
32 print "Bestand verwijderd";
36 $rootpath = str_repeat('../', substr_count($filename, '/'));
37 $prepend = "<?php include '${rootpath}head.inc.php'; ?>\n\n";
40 if (!file_put_contents($filename, $prepend . $upload . $append))
41 abort('500 save error', "fout bij schrijven van $filename");
43 print "Bestand opgeslagen";