mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2026-11-20 23:43:26 +03:00
The administrator list shows a translated Yes/No MFA column immediately after Active. Domains display an MFA badge only when at least one mailbox has a configured secret. Add resetmfa task for the postfixadmin-cli command. ( postfixadmin-cli admin resetmfa <address> and postfixadmin-cli mailbox resetmfa <address> ) thanks @TrapoSAMA
482 lines
16 KiB
PHP
482 lines
16 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: list-virtual.php
|
|
* List virtual users for a domain.
|
|
*
|
|
* Template File:
|
|
* list-virutal.tpl
|
|
* list-virtual-alias.tpl which incl list-virtual.tpl
|
|
* list-virtual-alias_domains.tpl which incl list-virtual.tpl
|
|
* list-virtual_mailbox.tpl
|
|
*
|
|
* Form POST \ GET Variables:
|
|
*
|
|
* fDomain
|
|
* fDisplay
|
|
* search
|
|
*/
|
|
require_once('common.php');
|
|
|
|
|
|
authentication_require_role('admin');
|
|
|
|
$admin_username = authentication_get_username();
|
|
|
|
$list_domains = list_domains_for_admin($admin_username);
|
|
|
|
$CONF = Config::getInstance()->getAll();
|
|
$smarty = PFASmarty::getInstance();
|
|
|
|
$page_size = $CONF['page_size'];
|
|
$smarty->assign('dns_check_mode', DomainDnsStatus::configuredMode());
|
|
|
|
$fDomain = safepost('fDomain', safeget('domain', safesession('list-virtual:domain')));
|
|
if (safesession('list-virtual:domain') != $fDomain) {
|
|
unset($_SESSION['list-virtual:limit']);
|
|
}
|
|
$fDisplay = (int)safepost('limit', safeget('limit', safesession('list-virtual:limit')));
|
|
$search = [];
|
|
|
|
if (isset($_POST['search']) && is_array($_POST['search'])) {
|
|
$search = $_POST['search'];
|
|
} elseif (isset($_GET['search']) && is_array($_GET['search'])) {
|
|
$search = $_GET['search'];
|
|
}
|
|
|
|
// Active-status filter for the alias list (all|active|inactive). Persisted in
|
|
// $_SESSION like the 'tab' selector below, so it survives pagination (whose
|
|
// links only carry &limit=...).
|
|
|
|
|
|
$fAliasActive = safeget('alias_active', safesession('list-virtual:alias_active', 'all'));
|
|
if (!in_array($fAliasActive, ['all', 'active', 'inactive'], true)) {
|
|
$fAliasActive = 'all';
|
|
}
|
|
$_SESSION['list-virtual:alias_active'] = $fAliasActive;
|
|
|
|
if (count($list_domains) == 0) {
|
|
if (authentication_has_role('global-admin')) {
|
|
flash_error($PALANG['no_domains_exist']);
|
|
} else {
|
|
flash_error($PALANG['no_domains_for_this_admin']);
|
|
}
|
|
header("Location: list.php?table=domain"); # no domains (for this admin at least) - redirect to domain list
|
|
exit;
|
|
}
|
|
|
|
if (empty($fDomain)) {
|
|
$fDomain = $list_domains[0];
|
|
}
|
|
|
|
|
|
if (!is_string($fDomain)) {
|
|
throw new InvalidArgumentException(Config::Lang('invalid_parameter'));
|
|
}
|
|
|
|
if (!in_array($fDomain, $list_domains)) {
|
|
flash_error($PALANG['invalid_parameter']);
|
|
unset($_SESSION['list-virtual:domain']);
|
|
header("Location: list.php?table=domain"); # invalid domain, or not owned by this admin
|
|
exit(0);
|
|
}
|
|
|
|
if (!check_owner(authentication_get_username(), $fDomain)) {
|
|
flash_error($PALANG['invalid_parameter'] . " If you see this message, please open a bugreport"); # this check is most probably obsoleted by the in_array() check above
|
|
unset($_SESSION['list-virtual:domain']);
|
|
header("Location: list.php?table=domain"); # domain not owned by this admin
|
|
exit(0);
|
|
}
|
|
|
|
$domain_handler = new DomainHandler(0, $admin_username);
|
|
$smarty->assign('domain_dns_status', DomainDnsStatus::configuredMode() > 0
|
|
? $domain_handler->dnsStatus($fDomain) : []);
|
|
|
|
// store domain and page browser offset in $_SESSION so after adding/editing aliases/mailboxes we can
|
|
// take the user back to the appropriate domain listing.
|
|
$_SESSION['list-virtual:domain'] = $fDomain;
|
|
$_SESSION['prefill:alias:domain'] = $fDomain;
|
|
$_SESSION['prefill:mailbox:domain'] = $fDomain;
|
|
$_SESSION['prefill:aliasdomain:target_domain'] = $fDomain;
|
|
|
|
$_SESSION['list-virtual:limit'] = $fDisplay;
|
|
|
|
$tAliasDomains = [];
|
|
$aliasdomain_data = [];
|
|
|
|
#
|
|
# alias domain
|
|
#
|
|
|
|
if (Config::bool('alias_domain')) {
|
|
$handler = new AliasdomainHandler(0, $admin_username);
|
|
$formconf = $handler->webformConfig(); # might change struct
|
|
$aliasdomain_data = array(
|
|
'struct' => $handler->getStruct(),
|
|
'msg' => $handler->getMsg(),
|
|
'formconf' => $formconf,
|
|
);
|
|
$aliasdomain_data['msg']['show_simple_search'] = false; # hide search box
|
|
|
|
$aliasdomain_data['msg']['can_create'] = 1;
|
|
|
|
# hide create button if all domains (of this admin) are already used as alias domains
|
|
$handler->getList("");
|
|
if (count($handler->result()) + 1 >= count($list_domains)) {
|
|
$aliasdomain_data['msg']['can_create'] = 0;
|
|
} # all domains (of this admin) are already alias domains
|
|
|
|
# get the really requested list
|
|
if (count($search) == 0) {
|
|
$list_param = "alias_domain='$fDomain' OR target_domain='$fDomain'";
|
|
} else {
|
|
$list_param = $search;
|
|
}
|
|
|
|
$handler->getList($list_param);
|
|
$tAliasDomains = $handler->result();
|
|
|
|
foreach ($tAliasDomains as $row) {
|
|
if ($row['alias_domain'] == $fDomain) {
|
|
$aliasdomain_data['struct']['target_domain']['linkto'] = 'target';
|
|
if (count($search) == 0) {
|
|
$aliasdomain_data['struct']['alias_domain']['linkto'] = '';
|
|
$aliasdomain_data['msg']['can_create'] = 0; # domain is already an alias domain
|
|
}
|
|
}
|
|
}
|
|
|
|
if (count($search) > 0) {
|
|
$aliasdomain_data['struct']['target_domain']['linkto'] = 'target';
|
|
}
|
|
}
|
|
|
|
#
|
|
# aliases
|
|
#
|
|
|
|
$table_alias = table_by_key('alias');
|
|
$table_domain = table_by_key('domain');
|
|
$table_mailbox = table_by_key('mailbox');
|
|
|
|
if (count($search) == 0 || !isset($search['_'])) {
|
|
$search_alias = array('domain' => $fDomain);
|
|
} else {
|
|
$search_alias = array('_' => $search['_']);
|
|
}
|
|
|
|
// Restrict the alias list to (in)active entries when the filter is set. 'active'
|
|
// is a bool field in the struct, so db_where_clause() parameterises it for us.
|
|
if ($fAliasActive === 'active') {
|
|
$search_alias['active'] = 1;
|
|
} elseif ($fAliasActive === 'inactive') {
|
|
$search_alias['active'] = 0;
|
|
}
|
|
|
|
$handler = new AliasHandler(0, $admin_username);
|
|
$formconf = $handler->webformConfig(); # might change struct
|
|
$alias_data = array(
|
|
'formconf' => $formconf,
|
|
'struct' => $handler->getStruct(),
|
|
'msg' => $handler->getMsg(),
|
|
);
|
|
$alias_data['struct']['goto_mailbox']['display_in_list'] = 0; # not useful/defined for non-mailbox aliases
|
|
$alias_data['struct']['on_vacation']['display_in_list'] = 0;
|
|
$alias_data['msg']['show_simple_search'] = false; # hide search box
|
|
|
|
$handler->getList($search_alias, array(), $page_size, $fDisplay);
|
|
$pagebrowser_alias = $handler->getPagebrowser($search_alias, array());
|
|
$tAlias = $handler->result();
|
|
|
|
|
|
#
|
|
# mailboxes
|
|
#
|
|
|
|
$display_mailbox_aliases = Config::bool('alias_control_admin');
|
|
$password_expiration = Config::bool('password_expiration');
|
|
|
|
# build the sql query
|
|
$sql_select = "SELECT $table_mailbox.* ";
|
|
$sql_from = " FROM $table_mailbox ";
|
|
$sql_join = "";
|
|
$sql_where = " WHERE ";
|
|
$sql_order = " ORDER BY $table_mailbox.username ";
|
|
$sql_limit = " LIMIT $page_size OFFSET $fDisplay";
|
|
$sql_params = [];
|
|
|
|
if (count($search) == 0 || !isset($search['_'])) {
|
|
$sql_where .= " $table_mailbox.domain= :domain ";
|
|
$sql_params['domain'] = $fDomain;
|
|
} else {
|
|
$searchterm = $search['_'];
|
|
$sql_where .= db_in_clause("$table_mailbox.domain", $list_domains, $sql_params) . " ";
|
|
$sql_where .= " AND ( $table_mailbox.username LIKE :searchterm OR $table_mailbox.name LIKE :searchterm ";
|
|
$sql_params['searchterm'] = "%$searchterm%";
|
|
|
|
if ($display_mailbox_aliases) {
|
|
$sql_where .= " OR $table_alias.goto LIKE :searchterm ";
|
|
}
|
|
$sql_where .= " ) ";
|
|
}
|
|
if ($display_mailbox_aliases) {
|
|
$sql_select .= ", $table_alias.goto ";
|
|
$sql_join .= " LEFT JOIN $table_alias ON $table_mailbox.username=$table_alias.address ";
|
|
}
|
|
|
|
if ($password_expiration) {
|
|
$sql_select .= ", $table_mailbox.password_expiry as password_expiration, $table_domain.password_expiry as domain_password_expiration ";
|
|
$sql_join .= " LEFT JOIN $table_domain ON $table_mailbox.domain=$table_domain.domain ";
|
|
}
|
|
|
|
if (Config::bool('vacation_control_admin')) {
|
|
$table_vacation = table_by_key('vacation');
|
|
$sql_select .= ", $table_vacation.active AS v_active ";
|
|
$sql_join .= " LEFT JOIN $table_vacation ON $table_mailbox.username=$table_vacation.email ";
|
|
}
|
|
|
|
if (Config::bool('used_quotas') && Config::bool('new_quota_table')) {
|
|
$table_quota2 = table_by_key('quota2');
|
|
$sql_select .= ", $table_quota2.bytes as current ";
|
|
$sql_join .= " LEFT JOIN $table_quota2 ON $table_mailbox.username=$table_quota2.username ";
|
|
}
|
|
|
|
if (Config::bool('used_quotas') && (!Config::bool('new_quota_table'))) {
|
|
$table_quota = table_by_key('quota');
|
|
$sql_select .= ", $table_quota.current ";
|
|
$sql_join .= " LEFT JOIN $table_quota ON $table_mailbox.username=$table_quota.username ";
|
|
$sql_where .= " AND ( $table_quota.path='quota/storage' OR $table_quota.path IS NULL ) ";
|
|
}
|
|
|
|
// Check the complete authorized result set, before pagination.
|
|
$show_mailbox_mfa = false;
|
|
if (db_query_one("SELECT 1 $sql_from $sql_join $sql_where AND $table_mailbox.totp_secret IS NOT NULL AND $table_mailbox.totp_secret <> '' LIMIT 1", $sql_params)) {
|
|
$show_mailbox_mfa = true;
|
|
}
|
|
$smarty->assign('show_mailbox_mfa', $show_mailbox_mfa);
|
|
|
|
$mailbox_pagebrowser_query = "$sql_from\n$sql_join\n$sql_where\n$sql_order";
|
|
|
|
$query = "$sql_select\n$mailbox_pagebrowser_query\n$sql_limit";
|
|
|
|
$result = db_query_all($query, $sql_params);
|
|
|
|
$tMailbox = array();
|
|
|
|
|
|
foreach ($result as $row) {
|
|
$row['mfa'] = isset($row['totp_secret']) && $row['totp_secret'] !== '';
|
|
unset($row['totp_secret']);
|
|
if ($password_expiration) {
|
|
$password_expiration_timestamp = strtotime((string)$row['password_expiration']);
|
|
$row['password_expiration_never'] = mailbox_password_expiration_is_never(
|
|
$row['password_expiration'],
|
|
$row['domain_password_expiration']
|
|
);
|
|
$row['password_expiration_expired'] = !$row['password_expiration_never']
|
|
&& $password_expiration_timestamp !== false
|
|
&& $password_expiration_timestamp <= time();
|
|
|
|
if ($password_expiration_timestamp !== false) {
|
|
$row['password_expiration'] = date('Y-m-d H:i', $password_expiration_timestamp);
|
|
}
|
|
}
|
|
|
|
if ($display_mailbox_aliases) {
|
|
$goto_split = explode(",", $row['goto'] ?? '');
|
|
$row['goto_mailbox'] = 0;
|
|
$row['goto_other'] = array();
|
|
|
|
foreach ($goto_split as $goto_single) {
|
|
$goto_single_rec_del = recipient_delimiter_base_address(
|
|
$goto_single,
|
|
$CONF['recipient_delimiter']
|
|
);
|
|
|
|
if ($goto_single == $row['username'] || $goto_single_rec_del == $row['username']) { # delivers to mailbox
|
|
$row['goto_mailbox'] = 1;
|
|
} elseif (Config::bool('vacation') && strstr($goto_single, '@' . $CONF['vacation_domain'])) { # vacation alias - TODO: check for full vacation alias
|
|
# skip the vacation alias, vacation status is detected otherwise
|
|
} else { # forwarding to other alias
|
|
$row['goto_other'][] = $goto_single;
|
|
}
|
|
}
|
|
}
|
|
if (db_pgsql()) {
|
|
$row['modified'] = date('Y-m-d H:i', strtotime($row['modified']));
|
|
$row['created'] = date('Y-m-d H:i', strtotime($row['created']));
|
|
$row['active'] = ('t' == $row['active']) ? 1 : 0;
|
|
|
|
if (Config::bool('vacation_control_admin')) {
|
|
if ($row['v_active'] == null) {
|
|
$row['v_active'] = 'f';
|
|
}
|
|
$row['v_active'] = ('t' == $row['v_active']) ? 1 : 0;
|
|
}
|
|
}
|
|
$tMailbox[] = $row;
|
|
}
|
|
|
|
|
|
$alias_data['msg']['can_create'] = false;
|
|
$tCanAddMailbox = false;
|
|
|
|
$limit = get_domain_properties($fDomain);
|
|
|
|
if (isset($limit)) {
|
|
if ($limit['aliases'] == 0) {
|
|
$alias_data['msg']['can_create'] = true;
|
|
} elseif ($limit['alias_count'] < $limit['aliases']) {
|
|
$alias_data['msg']['can_create'] = true;
|
|
}
|
|
|
|
if ($limit['mailboxes'] == 0) {
|
|
$tCanAddMailbox = true;
|
|
} elseif ($limit['mailbox_count'] < $limit['mailboxes']) {
|
|
$tCanAddMailbox = true;
|
|
}
|
|
|
|
$limit ['aliases'] = eval_size($limit ['aliases']);
|
|
$limit ['mailboxes'] = eval_size($limit ['mailboxes']);
|
|
if (Config::bool('quota')) {
|
|
$limit ['maxquota'] = eval_size($limit ['maxquota']);
|
|
}
|
|
}
|
|
|
|
$gen_show_status_mailbox = array();
|
|
$divide_quota = array('current' => [], 'quota' => [], 'percent' => [], 'quota_width' => []);
|
|
|
|
for ($i = 0; $i < sizeof($tMailbox); $i++) {
|
|
$gen_show_status_mailbox[$i] = gen_show_status($tMailbox[$i]['username'], $list_domains);
|
|
|
|
$divide_quota['current'][$i] = Config::Lang('unknown');
|
|
$divide_quota['quota_width'][$i] = 0;
|
|
$divide_quota['percent'][$i] = null;
|
|
$divide_quota['quota'][$i] = Config::Lang('unknown');
|
|
|
|
if (isset($tMailbox[$i]['current'])) {
|
|
$divide_quota['current'][$i] = divide_quota($tMailbox[$i]['current']);
|
|
}
|
|
if (isset($tMailbox[$i]['quota'])) {
|
|
$divide_quota['quota'][$i] = divide_quota($tMailbox[$i]['quota']);
|
|
}
|
|
if (isset($tMailbox[$i]['quota']) && isset($tMailbox[$i]['current'])) {
|
|
/**
|
|
* @psalm-suppress InvalidOperand
|
|
*/
|
|
$divide_quota['percent'][$i] = min(100, round(($divide_quota['current'][$i] / max(1, $divide_quota ['quota'][$i])) * 100));
|
|
/**
|
|
* @psalm-suppress InvalidOperand
|
|
*/
|
|
$divide_quota['quota_width'][$i] = ($divide_quota['percent'][$i] / 100) * 120; // because 100px wasn't wide enough?
|
|
}
|
|
}
|
|
|
|
|
|
$pagebrowser_mailbox = create_page_browser("$table_mailbox.username", $mailbox_pagebrowser_query, $sql_params);
|
|
|
|
$pagination_params = ['domain' => $fDomain];
|
|
if (isset($search['_']) && $search['_'] !== '') {
|
|
$pagination_params['search'] = ['_' => $search['_']];
|
|
}
|
|
$pagination_labels = [
|
|
'first' => $PALANG['pOverview_up_arrow'],
|
|
'previous' => $PALANG['pOverview_left_arrow'],
|
|
'next' => $PALANG['pOverview_right_arrow'],
|
|
];
|
|
$pagination_alias = page_browser_pagination(
|
|
$pagebrowser_alias,
|
|
$fDisplay,
|
|
$page_size,
|
|
$pagination_params,
|
|
'aliases',
|
|
$pagination_labels
|
|
);
|
|
$pagination_mailbox = page_browser_pagination(
|
|
$pagebrowser_mailbox,
|
|
$fDisplay,
|
|
$page_size,
|
|
$pagination_params,
|
|
'mailboxes',
|
|
$pagination_labels
|
|
);
|
|
|
|
|
|
if (empty($_GET['domain'])) {
|
|
$_GET['domain'] = '';
|
|
}
|
|
$smarty->assign('admin_list', array());
|
|
$smarty->assign('domain_list', $list_domains);
|
|
$smarty->assign('domain_selected', $fDomain);
|
|
$smarty->assign('pagination_alias', $pagination_alias);
|
|
$smarty->assign('pagination_mailbox', $pagination_mailbox);
|
|
|
|
$smarty->assign('fDomain', $fDomain);
|
|
|
|
$smarty->assign('search', $search);
|
|
|
|
$smarty->assign('list_domains', $list_domains);
|
|
$smarty->assign('limit', $limit);
|
|
|
|
if (Config::bool('alias_domain')) {
|
|
$smarty->assign('tAliasDomains', $tAliasDomains);
|
|
$smarty->assign('aliasdomain_data', $aliasdomain_data);
|
|
}
|
|
|
|
$smarty->assign('tAlias', $tAlias);
|
|
$smarty->assign('alias_data', $alias_data);
|
|
$smarty->assign('alias_active', $fAliasActive);
|
|
|
|
$smarty->assign('tMailbox', $tMailbox);
|
|
$smarty->assign('password_expiration', $password_expiration);
|
|
$password_expiration_on_label = Config::lang('password_expiration_on');
|
|
if ($password_expiration_on_label === '') {
|
|
$password_expiration_on_label = Config::lang('password_expiration');
|
|
}
|
|
$password_expiration_never_label = Config::lang('password_expiration_never');
|
|
if ($password_expiration_never_label === '') {
|
|
$password_expiration_never_label = Config::lang('pOverview_unlimited');
|
|
}
|
|
$smarty->assign('password_expiration_on_label', $password_expiration_on_label);
|
|
$smarty->assign('password_expiration_never_label', $password_expiration_never_label);
|
|
$smarty->assign('gen_show_status_mailbox', $gen_show_status_mailbox, TemplateEscape::RAW);
|
|
$smarty->assign('boolconf_used_quotas', Config::bool('used_quotas'));
|
|
$smarty->assign('divide_quota', $divide_quota);
|
|
$smarty->assign('tCanAddMailbox', $tCanAddMailbox);
|
|
$smarty->assign('display_mailbox_aliases', $display_mailbox_aliases);
|
|
if (isset($_GET ['tab'])) {
|
|
$_SESSION ['tab'] = $_GET ['tab'];
|
|
}
|
|
//if (empty ($_GET ['tab']))
|
|
// unset ($_SESSION ['tab']);
|
|
if (!isset($_SESSION ['tab'])) {
|
|
$_SESSION ['tab'] = 'all';
|
|
}
|
|
$smarty->assign('tab', $_SESSION ['tab']);
|
|
$smarty->assign('smarty_template', 'list-virtual');
|
|
$smarty->display('index.tpl');
|
|
|
|
function eval_size($aSize)
|
|
{
|
|
if ($aSize == 0) {
|
|
$ret_val = Config::Lang('pOverview_unlimited');
|
|
} elseif ($aSize < 0) {
|
|
$ret_val = Config::Lang('pOverview_disabled');
|
|
} else {
|
|
$ret_val = $aSize;
|
|
}
|
|
return $ret_val;
|
|
}
|
|
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
|