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
77 lines
1.7 KiB
PHP
77 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: sendmail.php
|
|
* Used to send an email to a user.
|
|
* Template File: sendmail.tpl
|
|
*
|
|
* Template Variables:
|
|
*
|
|
* tFrom
|
|
* tSubject
|
|
* tBody
|
|
*
|
|
* Form POST \ GET Variables:
|
|
*
|
|
* fTo
|
|
* fSubject
|
|
* fBody
|
|
*/
|
|
|
|
require_once('common.php');
|
|
|
|
authentication_require_role('admin');
|
|
|
|
$CONF = Config::getInstance()->getAll();
|
|
$smarty = PFASmarty::getInstance();
|
|
$PALANG = $CONF['__LANG'];
|
|
|
|
(($CONF['sendmail'] == 'NO') ? header("Location: main.php") && exit : '1');
|
|
|
|
$smtp_from_email = smtp_get_admin_email();
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == "POST") {
|
|
|
|
CsrfToken::assertValid(safepost('CSRF_Token'));
|
|
|
|
$fTo = safepost('fTo');
|
|
$fFrom = $smtp_from_email;
|
|
$fSubject = safepost('fSubject');
|
|
|
|
$tBody = $_POST['fBody'];
|
|
|
|
$error = 0;
|
|
$email_check = check_email($fTo);
|
|
if (empty($fTo) or ($email_check != '')) {
|
|
$error = 1;
|
|
flash_error($PALANG['pSendmail_to_text_error']); # TODO: superfluous?
|
|
flash_error($email_check);
|
|
}
|
|
|
|
if ($error != 1) {
|
|
if (!smtp_mail($fTo, $fFrom, $fSubject, $tBody)) {
|
|
flash_error(Config::lang_f('pSendmail_result_error', $fTo));
|
|
} else {
|
|
flash_info(Config::lang_f('pSendmail_result_success', $fTo));
|
|
}
|
|
}
|
|
}
|
|
$smarty->assign('smtp_from_email', $smtp_from_email);
|
|
$smarty->assign('smarty_template', 'sendmail');
|
|
$smarty->display('index.tpl');
|
|
|
|
|
|
/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
|