mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2026-11-20 23:43:26 +03:00
possible fix for https://github.com/postfixadmin/postfixadmin/issues/967 CSRF Token changes : rather than have one PFA_Token value in $_SESSION, store a list of them, where each value has a time stamp it was issued on. The aim is to allow the user to have multiple browser tabs open at once - and not have the last tab that loaded trample on others. Tokens expire after 1 hour. Adds a Smarty helper function `{CSRF_Token}` which will output `<input type=hidden name=CSRF_Token value=asdf123>` or `{CSRF_Token type=url}` which outputs a literal string like 'asdf123' suitable for placing in a URL. Adds a PHP exception handler in public/common.php, which could be used to display a more friendly error message/response (but at the moment is fairly minimal). Removes most uses of `die()` within the codebase, and instead moves to throw an exception
69 lines
1.7 KiB
PHP
69 lines
1.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Postfix Admin
|
|
*
|
|
* LICENSE
|
|
* This source file is subject to the GPL license that is bundled with
|
|
* this package in the file LICENSE.TXT.
|
|
*
|
|
* Further details on the project are available at https://github.com/postfixadmin/postfixadmin
|
|
*
|
|
* @version $Id$
|
|
* @license GNU GPL v2 or later.
|
|
*
|
|
* File: delete.php
|
|
* Used to delete admins, domains, mailboxes, aliases etc.
|
|
*
|
|
* Template File: none
|
|
*/
|
|
|
|
require_once('common.php');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
|
|
header('Location: main.php');
|
|
exit(0);
|
|
}
|
|
|
|
CsrfToken::assertValid(safepost('CSRF_Token'));
|
|
|
|
$username = authentication_get_username(); # enforce login
|
|
|
|
$id = safepost('delete');
|
|
$table = safepost('table');
|
|
|
|
if (empty($table)) {
|
|
throw new \InvalidArgumentException('Invalid usage');
|
|
}
|
|
|
|
$handlerclass = ucfirst($table) . 'Handler';
|
|
|
|
if (!preg_match('/^[a-z]+$/', $table) || !file_exists(dirname(__FILE__) . "/../model/$handlerclass.php")) { # validate $table
|
|
throw new \InvalidArgumentException("Invalid table name given!");
|
|
}
|
|
|
|
$is_admin = authentication_has_role('admin');
|
|
|
|
$handler = new $handlerclass(0, $username, $is_admin);
|
|
$formconf = $handler->webformConfig();
|
|
|
|
if ($is_admin) {
|
|
authentication_require_role($formconf['required_role']);
|
|
} else {
|
|
if (empty($formconf['user_hardcoded_field'])) {
|
|
throw new \InvalidArgumentException($handlerclass . ' is not available for users');
|
|
}
|
|
}
|
|
|
|
if ($handler->init($id)) { # errors will be displayed as last step anyway, no need for duplicated code ;-)
|
|
$handler->delete();
|
|
}
|
|
|
|
flash_error($handler->errormsg);
|
|
flash_info($handler->infomsg);
|
|
|
|
header("Location: " . $formconf['listview']);
|
|
exit;
|
|
|
|
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
|