From: Mischa POSLAWSKY Date: Tue, 8 Jul 2014 16:52:24 +0000 (+0200) Subject: edit: restrict to whitelisted ip addresses X-Git-Tag: v1.0~3 X-Git-Url: http://git.shiar.net/minimedit.git/commitdiff_plain/848f9155e138a0c13a0ecab423f165d5b4ba6d4d edit: restrict to whitelisted ip addresses Basic security from Apache configuration: Deny from all Allow from 127.0.0.1/32 --- diff --git a/edit.js b/edit.js index fda6bf9..385bba6 100644 --- a/edit.js +++ b/edit.js @@ -41,7 +41,6 @@ CKEDITOR.on('instanceCreated', function (event) { ['Bold', 'Italic', 'Underline', 'Strike', '-', 'Link'], ['HorizontalRule', 'Table', 'Image'], ]; - config.enterMode = CKEDITOR.ENTER_BR; // results in

; ENTER_P does it twice }); }); diff --git a/edit.php b/edit.php index 14bfde0..398581e 100644 --- a/edit.php +++ b/edit.php @@ -5,20 +5,24 @@ function abort($status, $body) { exit; } -$filename = $_POST['page']; -$filename = ltrim($filename, '/'); -if (!preg_match('/^[a-z]+\.html$/', $filename)) - abort('403 input error', "Ongeldige bestandsnaam: $filename"); +if (!$_POST) + abort('405 post error', "niets te doen"); +if (!isset($_POST['page'])) + abort('409 input error', "geen bestand aangeleverd"); + +$filename = preg_replace('/(?:\.html)?$/', '.html', ltrim($_POST['page'], '/'), 1); +if (file_exists($filename) and !is_writable($filename)) + abort('403 input error', "ongeldige bestandsnaam: $filename"); $prepend = ''."\n\n"; -$append = "\n\n".''."\n"; +$append = "\n".''."\n"; $upload = $_POST['body']; if (!$upload) abort('409 input error', "leeg bestand aangeleverd"); if (!file_put_contents($filename, $prepend . $upload . $append)) - abort('500 save error', "kon bestand niet overschrijven"); + abort('500 save error', "fout bij schrijven van $filename"); print "Bestand opgeslagen"; diff --git a/footer.html b/footer.html index bd4ca97..a6882d1 100644 --- a/footer.html +++ b/footer.html @@ -1,5 +1,8 @@ -


+ + + +