<?php
ob_clean();
-function abort($body, $status = NULL) {
- if ($status) header("HTTP/1.1 $status");
- print "$body\n";
- exit;
-}
-
-if (!@$User['admin'])
+if (empty($User['admin']))
abort("geen beheersrechten", '401 unauthorised');
if ($_FILES) {
abort("Bestand verwijderd");
}
-if (!file_exists(dirname($filename)) and !mkdir(dirname($filename)))
+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("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);
+ }
+}
+
abort("Bestand opgeslagen");