X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/4f9e4ddecc2bf5d8a60333906b91150db07ed950..d4fc5883a123ce28c56a963e77c700db04e26ac9:/edit.php diff --git a/edit.php b/edit.php old mode 100644 new mode 100755 index 5790696..9532e42 --- a/edit.php +++ b/edit.php @@ -5,14 +5,20 @@ function abort($status, $body) { exit; } +require 'auth.inc.php'; +if (!$editable) + 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"); @@ -27,8 +33,9 @@ if (!strlen($upload)) { exit; } -$prepend = ''."\n\n"; -$append = "\n".''."\n"; +$rootpath = str_repeat('../', substr_count($filename, '/')); +$prepend = "\n\n"; +$append = "\n"; if (!file_put_contents($filename, $prepend . $upload . $append)) abort('500 save error', "fout bij schrijven van $filename");