<?php
-function abort($status, $body) {
- header("HTTP/1.1 $status");
- print "$body\n";
+ob_clean();
+
+if (empty($User['admin']))
+ abort("geen beheersrechten", '401 unauthorised');
+
+if ($_FILES) {
+ $img = @$_FILES['upload'];
+ if (!$img or $img['error'] !== UPLOAD_ERR_OK)
+ abort('bestand niet goed ontvangen: '.$img['error'], '409 upload error');
+
+ $datadir = 'data/' . date('Y');
+ $target = $datadir.'/'.$img['name'];
+ move_uploaded_file($img['tmp_name'], $target);
+
+ switch (@$_GET['output']) {
+ case 'ckescript':
+ printf('<script>window.parent.CKEDITOR.tools.callFunction(%s)</script>',
+ "{$_GET['CKEditorFuncNum']}, '$target'"
+ );
+ break;
+ default:
+ abort($target);
+ }
exit;
}
-if (!$User['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");
+ abort("niets te doen", '405 post error');
+if (!$Args)
+ abort("geen bestand aangeleverd", '409 input error');
$filename = ltrim($Args, '/').'.html';
+if (preg_match('{^\.}', $filename))
+ abort("ongeldige bestandsnaam: $filename", '403 input error');
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");
+ abort("onwijzigbaar bestand: $filename", '403 input error');
if (!isset($_POST['body']))
- abort('409 input error', "geen inhoud aangeleverd");
+ abort("geen inhoud aangeleverd", '409 input error');
$upload = $_POST['body'];
if (!strlen($upload)) {
if (file_exists($filename) and !unlink($filename))
- abort('500 delete error', "fout bij het verwijderen van $filename");
+ abort("fout bij het verwijderen van $filename", '500 delete error');
- print "Bestand verwijderd";
- exit;
+ abort("Bestand verwijderd");
}
+if (!file_exists(dirname($filename)) and !mkdir(dirname($filename), 0777, TRUE))
+ abort("fout bij aanmaken van map voor $filename", '500 save error');
+
if (!file_put_contents($filename, $upload))
- abort('500 save error', "fout bij schrijven van $filename");
+ abort("fout bij schrijven van $filename", '500 save error');
+
+if (is_writable('../.git')) {
+ $gitmsg = preg_replace('/\.html$/', '', $filename).": edit from {$_SERVER['REMOTE_ADDR']}";
+ $gitcmd = 'git';
+ $gitcmd .= ' -c user.name='.escapeshellarg($User['name']);
+ $gitcmd .= ' -c user.email='.escapeshellarg("{$User['name']}@lijtweg.nl");
+ $gitcmd .= ' commit -q';
+ $gitcmd .= ' -m '.escapeshellarg($gitmsg);
+ $gitcmd .= ' -- '.escapeshellarg($filename);
+ exec("$gitcmd 2>&1", $gitlog, $gitstatus);
+ if ($gitstatus) {
+ trigger_error("git commit failure $gitstatus: ".implode("\n", $gitlog), E_USER_WARNING);
+ }
+}
-print "Bestand opgeslagen";
+abort("Bestand opgeslagen");