mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2026-11-20 23:43:26 +03:00
Someone wishing to remain anonymous emailed @cboltz a number of security issues, summarised below. 1. fix sql injection bug in getPageBrowser - search keys bypass the field filter, due to2a6f27c3/ #1127 2. when performing a password change, do not start the session before the new password has been validated for compexity etc - as things stand someone with a recovery code gets logged in even if their password gets rejected. Also invalid recovery code on failure. 3. broadcast-message.php was using smtp_mail() with incorrect args, and passing the SMTP password in as the mail body. - probably related to commit7f1d78eand42a664e9c24. a regular (non-admin) user could submit an arbitrary username in the POST data and create/edit a TOTP exception for another user or entire domain PR includes refactoring of the password change code (into PasswordChangeAttempt) to make it easier to test/verify.
124 lines
4.3 KiB
PHP
124 lines
4.3 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: broadcast-message.php
|
|
* Used to send a message to _ALL_ users with mailboxes on this server.
|
|
*
|
|
* Template File: broadcast-message.tpl
|
|
*
|
|
* Template Variables: -none-
|
|
*
|
|
* Form POST \ GET Variables:
|
|
*
|
|
* name
|
|
* subject
|
|
* message
|
|
*/
|
|
|
|
require_once('common.php');
|
|
|
|
if (Config::bool('sendmail_all_admins')) {
|
|
authentication_require_role('admin');
|
|
} else {
|
|
authentication_require_role('global-admin');
|
|
}
|
|
|
|
$CONF = Config::getInstance()->getAll();
|
|
$smarty = PFASmarty::getInstance();
|
|
|
|
if ($CONF['sendmail'] != 'YES') {
|
|
header("Location: main.php");
|
|
exit;
|
|
}
|
|
|
|
$error = 0;
|
|
|
|
$smtp_from_email = smtp_get_admin_email();
|
|
$allowed_domains = list_domains_for_admin(authentication_get_username());
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == "POST") {
|
|
|
|
CsrfToken::assertValid(safepost('CSRF_Token'));
|
|
|
|
if (empty($_POST['subject']) || empty($_POST['message']) || empty($_POST['name']) || empty($_POST['domains']) || !is_array($_POST['domains'])) {
|
|
$error = 1;
|
|
flash_error($PALANG['pBroadcast_error_empty']);
|
|
} else {
|
|
$wanted_domains = array_intersect($allowed_domains, $_POST['domains']);
|
|
|
|
$table_mailbox = table_by_key('mailbox');
|
|
$table_alias = table_by_key('alias');
|
|
|
|
$params = ['active' => true];
|
|
$q = "SELECT username from $table_mailbox WHERE active = :active AND " . db_in_clause("domain", $wanted_domains, $params);
|
|
$result = db_query_all($q, $params);
|
|
$recipients = array_column($result, 'username');
|
|
|
|
if (intval(safepost('mailboxes_only')) == 0) {
|
|
$params2 = ['active' => true];
|
|
$q2 = "SELECT goto FROM $table_alias WHERE active= :active AND " . db_in_clause("domain", $wanted_domains, $params2);
|
|
$result2 = db_query_all($q2, $params2);
|
|
$recipients = array_merge($recipients, array_column($result2, 'goto'));
|
|
}
|
|
|
|
$recipients = array_unique($recipients);
|
|
|
|
if (count($recipients) > 0) {
|
|
mb_internal_encoding("UTF-8");
|
|
$b_name = mb_encode_mimeheader($_POST['name'], 'UTF-8', 'Q');
|
|
$b_subject = mb_encode_mimeheader($_POST['subject'], 'UTF-8', 'Q');
|
|
$b_message = chunk_split(base64_encode($_POST['message']));
|
|
|
|
$serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : php_uname('n'); // ??
|
|
|
|
foreach ($recipients as $rcpt) {
|
|
$fTo = $rcpt;
|
|
$fHeaders = 'To: ' . $fTo . "\n";
|
|
$fHeaders .= 'From: ' . $b_name . ' <' . $smtp_from_email . ">\n";
|
|
$fHeaders .= 'Subject: ' . $b_subject . "\n";
|
|
$fHeaders .= 'MIME-Version: 1.0' . "\n";
|
|
$fHeaders .= 'Content-Type: text/plain; charset=UTF-8' . "\n";
|
|
$fHeaders .= 'Content-Transfer-Encoding: base64' . "\n";
|
|
$fHeaders .= 'Date: ' . date('r', time()) . "\n";
|
|
$fHeaders .= 'Message-ID: <' . ((string)microtime(true)) . '-' . md5($smtp_from_email . $fTo) . "@{$serverName}>\n\n";
|
|
|
|
$data = $fHeaders . $b_message;
|
|
|
|
if (!smtp_mail(to: $fTo, from: $smtp_from_email, subject_or_data: $data)) {
|
|
flash_error(Config::lang_f('pSendmail_result_error', $fTo));
|
|
} else {
|
|
flash_info(Config::lang_f('pSendmail_result_success', $fTo));
|
|
}
|
|
}
|
|
}
|
|
|
|
flash_info($PALANG['pBroadcast_success']);
|
|
$smarty->assign('smarty_template', 'broadcast-message');
|
|
$smarty->display('index.tpl');
|
|
// echo '<p>'.$PALANG['pBroadcast_success'].'</p>';
|
|
}
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == "GET" || $error == 1) {
|
|
$smarty->assign('allowed_domains', $allowed_domains);
|
|
$smarty->assign('smtp_from_email', $smtp_from_email);
|
|
$smarty->assign('error', $error);
|
|
$smarty->assign('smarty_template', 'broadcast-message');
|
|
$smarty->display('index.tpl');
|
|
|
|
// include ("templates/broadcast-message.tpl");
|
|
}
|
|
|
|
/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
|