Add removal of files as well

This commit is contained in:
Jacob 2023-10-01 01:31:38 +02:00
parent 335c00bf37
commit 832ae4b3e6
2 changed files with 34 additions and 4 deletions

View file

@ -105,6 +105,7 @@ if ($Action == "files") {
$html .= "\t\t\t\t\t\t<td class=\"adminUploadDate\">$uploadDate</td>\n";
$html .= "\t\t\t\t\t\t<td class=\"adminKeyID\">$keyID</td>\n";
$html .= "\t\t\t\t\t\t<td class=\"adminKeyType\">$keyType</td>\n";
$html .= "\t\t\t\t\t\t<td class=\"adminRemove\"><a href=\"/remove.php?redir=admin&id=$ID\">Remove</a></td>\n";
$html .= "\t\t\t\t\t</tr>\n";
}

View file

@ -7,10 +7,11 @@
include "config.php";
include "create-table.php";
if (isset($_REQUEST['key'])) {
$Key = $_REQUEST['key'];
} else {
print "No key specified.";
if (!isset($_COOKIE[$cookieName]) || !isset($_COOKIE[$cookieTypeName])) {
header('Location: login.php?redir=admin');
die();
} else if ($_COOKIE[$cookieTypeName] != 2) { // not allowed
header('Location: /');
die();
}
@ -26,11 +27,32 @@ if (!$enableUploadRemoval || $enableUploadRemoval == "false") {
die();
}
$Redirect = "";
$FileToRemove = "";
$AuthorizedRemoval = 0;
$fileUploadedByPrimary = 0;
if (isset($_REQUEST['redir'])) {
$Redirect = $_REQUEST['redir'];
}
$Database = createTables($sqlDB);
$DatabaseQuery = $Database->query('SELECT * FROM admins');
while ($line = $DatabaseQuery->fetchArray()) {
if ($line['key'] == $_COOKIE[$cookieName] && $_COOKIE[$cookieName] != "" && $line['key'] != "" && ($enableKeys || $enableKeys == "true")) {
$AuthorizedRemoval = 1;
$AdminIsPrimary = $line['primaryadmin'];
break;
}
}
// not authorized
if ($AuthorizedRemoval != 1) {
header('Location: /');
die();
}
$DatabaseQuery = $Database->query('SELECT * FROM uploads');
while ($line = $DatabaseQuery->fetchArray()) {
@ -84,4 +106,11 @@ if ($AuthorizedRemoval != 1) {
$Database->exec("DELETE FROM uploads WHERE id='$fileID'");
unlink(ltrim($FileToRemove, '/'));
if ($Redirect == "admin") {
header("Location: admin.php?action=files");
} else {
header("Location: /");
}
?>