4 function abort($body, $status = NULL) {
5 if ($status) header("HTTP/1.1 $status");
10 if (empty($User['admin']))
11 abort("geen beheersrechten", '401 unauthorised');
14 $img = @$_FILES['upload'];
15 if (!$img or $img['error'] !== UPLOAD_ERR_OK)
16 abort('bestand niet goed ontvangen: '.$img['error'], '409 upload error');
18 $datadir = 'data/' . date('Y');
19 $target = $datadir.'/'.$img['name'];
20 move_uploaded_file($img['tmp_name'], $target);
22 switch (@$_GET['output']) {
24 printf('<script>window.parent.CKEDITOR.tools.callFunction(%s)</script>',
25 "{$_GET['CKEditorFuncNum']}, '$target'"
35 abort("niets te doen", '405 post error');
37 abort("geen bestand aangeleverd", '409 input error');
39 $filename = ltrim($Args, '/').'.html';
40 if (preg_match('{^\.}', $filename))
41 abort("ongeldige bestandsnaam: $filename", '403 input error');
42 if (file_exists($filename) and !is_writable($filename))
43 abort("onwijzigbaar bestand: $filename", '403 input error');
45 if (!isset($_POST['body']))
46 abort("geen inhoud aangeleverd", '409 input error');
48 $upload = $_POST['body'];
50 if (!strlen($upload)) {
51 if (file_exists($filename) and !unlink($filename))
52 abort("fout bij het verwijderen van $filename", '500 delete error');
54 abort("Bestand verwijderd");
57 if (!file_exists(dirname($filename)) and !mkdir(dirname($filename), 0777, TRUE))
58 abort("fout bij aanmaken van map voor $filename", '500 save error');
60 if (!file_put_contents($filename, $upload))
61 abort("fout bij schrijven van $filename", '500 save error');
63 if (is_writable('../.git')) {
64 $gitmsg = preg_replace('/\.html$/', '', $filename).": edit from {$_SERVER['REMOTE_ADDR']}";
66 $gitcmd .= ' -c user.name='.escapeshellarg($User['name']);
67 $gitcmd .= ' -c user.email='.escapeshellarg("{$User['name']}@lijtweg.nl");
68 $gitcmd .= ' commit -q';
69 $gitcmd .= ' -m '.escapeshellarg($gitmsg);
70 $gitcmd .= ' -- '.escapeshellarg($filename);
71 exec("$gitcmd 2>&1", $gitlog, $gitstatus);
73 trigger_error("git commit failure $gitstatus: ".implode("\n", $gitlog), E_USER_WARNING);
77 abort("Bestand opgeslagen");