edit: restrict to whitelisted ip addresses
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 8 Jul 2014 16:52:24 +0000 (18:52 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 8 Jul 2014 22:53:23 +0000 (00:53 +0200)
Basic security from Apache configuration:

<Files "edit.php">
Deny from all
Allow from 127.0.0.1/32
</Files>

edit.js
edit.php
footer.html

diff --git a/edit.js b/edit.js
index fda6bf95741812e344958417f95e835c7dcb599b..385bba6753ec69bb743f4b7f3844619015e1ae9c 100644 (file)
--- 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 <p>; ENTER_P does it twice
        });
 });
 
index 14bfde092a06c0384fa76d1ade619e037e519026..398581e1e7c6ffbf3578e6b0296f63aa1b844af8 100644 (file)
--- 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 = '<!--#include virtual="common.html" -->'."\n\n";
-$append  = "\n\n".'<!--#include virtual="footer.html" -->'."\n";
+$append  = "\n".'<!--#include virtual="footer.html" -->'."\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";
 
index bd4ca9712e7e553ddec5ad579eb6128477d17345..a6882d1f5c0c4fb42c102ea3dad7ea01333c89af 100644 (file)
@@ -1,5 +1,8 @@
 </div>
-<hr style="clear:both" />
+<hr class="footer" />
+<!--#if expr="-A /edit.php" -->
+<p class="footer">Beheer toegestaan voor <!--#echo var="REMOTE_ADDR" --></p>
 <script src="/ckeditor/ckeditor.js"></script>
 <script src="/edit.js"></script>
+<!--#endif -->
 </body></html>