4 if (empty($User['admin']))
5 abort("geen beheersrechten", '401 unauthorised');
9 $img = @$_FILES['upload'];
10 if (!$img or $img['error'] !== UPLOAD_ERR_OK)
11 throw new Exception('bestand niet goed ontvangen: '.$img['error']);
13 $datadir = implode('/', ['data', date('Y')]);
14 if (!file_exists($datadir) and !@mkdir($datadir, 0777, TRUE)) {
15 throw new Exception("bestand kon niet geplaatst worden in $datadir");
18 $target = $datadir.'/'.$img['name'];
19 if (!@move_uploaded_file($img['tmp_name'], $target)) {
20 throw new Exception('bestand kon niet worden opgeslagen');
23 catch (Exception $e) {
24 abort($e->getMessage(), '409 upload error');
27 switch (@$_GET['output']) {
29 printf('<script>window.parent.CKEDITOR.tools.callFunction(%s)</script>',
30 "{$_GET['CKEditorFuncNum']}, '$target'"
40 abort("niets te doen", '405 post error');
42 abort("geen bestand aangeleverd", '409 input error');
44 $filename = ltrim($Args, '/').'.html';
45 if (preg_match('{^\.}', $filename))
46 abort("ongeldige bestandsnaam: $filename", '403 input error');
47 if (file_exists($filename) and !is_writable($filename))
48 abort("onwijzigbaar bestand: $filename", '403 input error');
50 if (!isset($_POST['body']))
51 abort("geen inhoud aangeleverd", '409 input error');
53 $upload = $_POST['body'];
55 if (!strlen($upload)) {
56 if (file_exists($filename) and !unlink($filename))
57 abort("fout bij het verwijderen van $filename", '500 delete error');
59 abort("Bestand verwijderd");
62 if (!file_exists(dirname($filename)) and !mkdir(dirname($filename), 0777, TRUE))
63 abort("fout bij aanmaken van map voor $filename", '500 save error');
65 if (!file_put_contents($filename, $upload))
66 abort("fout bij schrijven van $filename", '500 save error');
68 if (is_writable('../.git')) {
69 $gitmsg = preg_replace('/\.html$/', '', $filename).": edit from {$_SERVER['REMOTE_ADDR']}";
71 $gitcmd .= ' -c user.name='.escapeshellarg($User['name']);
72 $gitcmd .= ' -c user.email='.escapeshellarg("{$User['name']}@lijtweg.nl");
73 $gitcmd .= ' commit -q';
74 $gitcmd .= ' -m '.escapeshellarg($gitmsg);
75 $gitcmd .= ' -- '.escapeshellarg($filename);
76 exec("$gitcmd 2>&1", $gitlog, $gitstatus);
78 trigger_error("git commit failure $gitstatus: ".implode("\n", $gitlog), E_USER_WARNING);
82 abort("Bestand opgeslagen");