Improve remove.php, add remove-key.php for removing keys

This commit is contained in:
Jacob 2023-09-30 19:01:41 +02:00
parent 89bd9b827f
commit 6f55b8b3f6
2 changed files with 162 additions and 64 deletions

93
remove-key.php Normal file
View file

@ -0,0 +1,93 @@
<?php
/* curload
* Simple file uploading using POST requests and temporary keys
* Licensed under the GNU Affero General Public License version 3.0
*/
include "config.php";
include "create-table.php";
if (isset($_REQUEST['key'])) {
$Key = $_REQUEST['key'];
} else {
print "No key specified.";
die();
}
if (isset($_REQUEST['id'])) {
$id = $_REQUEST['id'];
} else {
print "No ID specified.";
die();
}
$AdminIsPrimary = 0;
$KeyIsPrimary = 0;
$AuthorizedRemoval = 0;
$Removed = 0;
$Database = createTables($sqlDB);
// check if the key we passed is an admin key and if it's a primary admin key
$DatabaseQuery = $Database->query('SELECT * FROM admins');
while ($line = $DatabaseQuery->fetchArray()) {
if ($Key == $line['key']) {
if ($line['primaryadmin'] == 1) {
$AdminIsPrimary = 1;
}
$AuthorizedRemoval = 1;
break;
}
}
$DatabaseQuery = $Database->query('SELECT * FROM keys');
while ($line = $DatabaseQuery->fetchArray()) {
if ($line['id'] == $id && $line['id'] != "" && $id != "") { // passed ID is a key that exists
if ($AuthorizedRemoval == 1) {
$Database->exec("DELETE FROM keys WHERE id='$id'");
$Removed = 1;
} else {
print "You aren't authorized to perform this action.";
die();
}
break;
}
}
$DatabaseQuery = $Database->query('SELECT * FROM tkeys');
while ($line = $DatabaseQuery->fetchArray()) {
if ($line['id'] == $id && $line['id'] != "" && $id != "" && $Removed != 1) { // passed ID is a key that exists
if ($AuthorizedRemoval == 1) {
$Database->exec("DELETE FROM tkeys WHERE id='$id'");
$Removed = 1;
} else {
print "You aren't authorized to perform this action.";
die();
}
break;
}
}
$DatabaseQuery = $Database->query('SELECT * FROM admins');
while ($line = $DatabaseQuery->fetchArray()) {
if ($line['id'] == $id && $line['id'] != "" && $id != "" && $Removed != 1 && $line['primaryadmin'] != 1) { // passed ID is a key that exists
if ($AuthorizedRemoval == 1 && $AdminIsPrimary == 1) { // in order to delete an admin key you must be a primary admin
$Database->exec("DELETE FROM admins WHERE id='$id'");
$Removed = 1;
} else {
print "You aren't authorized to perform this action.";
die();
}
break;
}
}
if ($AuthorizedRemoval != 1) {
print "You aren't authorized to perform this action.";
die();
}
?>

View file

@ -1,4 +1,9 @@
<?php <?php
/* curload
* Simple file uploading using POST requests and temporary keys
* Licensed under the GNU Affero General Public License version 3.0
*/
include "config.php"; include "config.php";
include "create-table.php"; include "create-table.php";