2018-06-13 20:07:24 +02:00
|
|
|
<?PHP
|
|
|
|
/**
|
|
|
|
* Start page of the backend.
|
|
|
|
* Offers a dashboard.
|
|
|
|
*
|
|
|
|
* @author Joshua Ramon Enslin <joshua@jrenslin.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Require files and ensure environment.
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once __DIR__ . "/inc/functions.php";
|
|
|
|
|
2018-06-18 21:42:14 +02:00
|
|
|
ensureEnvironment(); // Ensure existence of system files.
|
|
|
|
$translations = loadLanguage($settings['defaultLang']); // Load translations.
|
|
|
|
ensureBackendEnv(); // Ensure session is started etc.
|
|
|
|
$pages = loadPages(); // Load overview of pages.
|
2018-06-13 20:07:24 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Load data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Check for vars.
|
2018-06-18 21:42:14 +02:00
|
|
|
loadHttpToGlobals(["subject", "task", "backTo"]);
|
2018-06-13 20:07:24 +02:00
|
|
|
if (!isset($task)) $task = "list";
|
|
|
|
|
|
|
|
define("fileDir", __DIR__ . "/../files");
|
|
|
|
|
|
|
|
if ($task == "list") {
|
|
|
|
|
|
|
|
$files = scanDirConts(fileDir);
|
|
|
|
echo json_encode($files);
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
else if ($task == "upload") {
|
|
|
|
|
2018-06-18 21:42:14 +02:00
|
|
|
$allowedFiletypes = [
|
|
|
|
"image/png",
|
|
|
|
"image/jpeg",
|
|
|
|
];
|
2018-06-13 20:07:24 +02:00
|
|
|
|
|
|
|
$uploaddir = fileDir . '/';
|
2018-06-18 21:42:14 +02:00
|
|
|
$uploadfile = $uploaddir . basename($_FILES['file']['name']);
|
2018-06-13 20:07:24 +02:00
|
|
|
|
2018-06-18 21:42:14 +02:00
|
|
|
// Whitelist of allowed types.
|
|
|
|
if (!in_array($_FILES['file']['type'], $allowedFiletypes)) {
|
|
|
|
printErrorPage($translations['filetypeNotWhitelisted']);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filesize($_FILES['file']['tmp_name']) > 300000) {
|
2018-06-13 20:07:24 +02:00
|
|
|
printErrorPage($translations['fileTooLarge']);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-18 21:42:14 +02:00
|
|
|
if (!(move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile))) {
|
|
|
|
printErrorPage($translations['fileUploadError']);
|
|
|
|
return;
|
2018-06-13 20:07:24 +02:00
|
|
|
}
|
2018-06-18 21:42:14 +02:00
|
|
|
|
|
|
|
$_SESSION["editHistory"] = ["changesStored", $translations['uploadedFile']];
|
|
|
|
|
|
|
|
// Refer back
|
|
|
|
if (isset($backTo)) header('Location: ' . $backTo);
|
|
|
|
else header('Location: ./');
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
else if ($task == "delete") {
|
|
|
|
|
|
|
|
if (!is_file(fileDir . "/$subject")) {
|
|
|
|
printErrorPage($translations['fileDoesNotExist']); return;
|
2018-06-13 20:07:24 +02:00
|
|
|
}
|
|
|
|
|
2018-06-18 21:42:14 +02:00
|
|
|
unlink(fileDir . "/$subject");
|
|
|
|
|
|
|
|
$_SESSION["editHistory"] = ["changesDeleted", $translations['deletedFile'] . " $subject"];
|
|
|
|
|
|
|
|
// Refer back
|
|
|
|
if (isset($backTo)) header('Location: ' . $backTo);
|
|
|
|
else header('Location: ./');
|
|
|
|
return;
|
|
|
|
|
2018-06-13 20:07:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|