From 5fa76d73d9c97db99038faebcaf937f1dd48ede6 Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Sun, 27 Jul 2008 19:06:55 +0000 Subject: [PATCH] config.inc.php + all files related to alias domains - added $CONF['alias_domain'] switch to disable alias domains (includes lots of whitespace changes in list-virtual.php) functions.php: - added some comments to boolconf() git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@419 a1433add-5e2c-0410-b055-b7f2511e0802 --- config.inc.php | 7 ++++ create-alias-domain.php | 6 ++++ functions.inc.php | 4 ++- list-virtual.php | 73 +++++++++++++++++++------------------- templates/list-virtual.php | 2 +- templates/menu.php | 6 ++-- 6 files changed, 58 insertions(+), 40 deletions(-) diff --git a/config.inc.php b/config.inc.php index f5f79d3f..d0927909 100644 --- a/config.inc.php +++ b/config.inc.php @@ -195,6 +195,13 @@ $CONF['special_alias_control'] = 'NO'; // '0' means no limits. $CONF['alias_goto_limit'] = '0'; +// Alias Domains +// Alias domains allow to "mirror" aliases and mailboxes to another domain. This makes +// configuration easier, but also requires postfix to do more database queries. +// Note: If you update from 2.2.x or earlier, you will have to update your postfix config. +// Set to 'NO' to disable alias domains. +$CONF['alias_domain'] = 'YES'; + // Backup // If you don't want backup tab set this to 'NO'; $CONF['backup'] = 'YES'; diff --git a/create-alias-domain.php b/create-alias-domain.php index d6ca4b6e..ebacc58d 100644 --- a/create-alias-domain.php +++ b/create-alias-domain.php @@ -32,6 +32,12 @@ require_once('common.php'); authentication_require_role('admin'); + +if (!boolconf['alias_domain']) { + header("Location: " . $CONF['postfix_admin_url'] . "/main.php"); + exit; +} + $username = authentication_get_username(); $SESSID_USERNAME = $username; if(authentication_has_role('global-admin')) { diff --git a/functions.inc.php b/functions.inc.php index b630fa7b..7d4963e7 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -2189,6 +2189,7 @@ function create_admin($fUsername, $fPassword, $fPassword2, $fDomains, $no_genera /* Convert $CONF['whatever'] to boolean + (obviously only useful for settings that can be YES or NO) Returns: TRUE (on YES/yes) or FALSE (on NO/no/not set/unknown value) */ @@ -2196,11 +2197,12 @@ function create_admin($fUsername, $fPassword, $fPassword2, $fDomains, $no_genera function boolconf($setting) { global $CONF; if (!isset($CONF[$setting])) { # not set + # TODO: show/log error message on unknown settings? return false; } elseif (strtoupper($CONF[$setting]) == 'YES') { # YES return true; } else { # NO, unknown value - # TODO: show error on unknown value? + # TODO: show/log error message on unknown value? return false; } } diff --git a/list-virtual.php b/list-virtual.php index 64964d30..8ad09040 100644 --- a/list-virtual.php +++ b/list-virtual.php @@ -73,50 +73,51 @@ if (!check_owner(authentication_get_username(), $fDomain)) { } -# Alias-Domains -# first try to get a list of other domains pointing -# to this currently chosen one (aka. alias domains) -$query = "SELECT $table_alias_domain.alias_domain,$table_alias_domain.target_domain,$table_alias_domain.modified,$table_alias_domain.active FROM $table_alias_domain WHERE target_domain='$fDomain' ORDER BY $table_alias_domain.alias_domain LIMIT $fDisplay, $page_size"; -if ('pgsql'==$CONF['database_type']) -{ - $query = "SELECT alias_domain,target_domain,extract(epoch from modified) as modified,active FROM $table_alias_domain WHERE target_domain='$fDomain' ORDER BY alias_domain LIMIT $page_size OFFSET $fDisplay"; -} -$result = db_query ($query); -$tAliasDomains = array(); -if ($result['rows'] > 0) -{ - while ($row = db_array ($result['result'])) +if (boolconf('alias_domain')) { + # Alias-Domains + # first try to get a list of other domains pointing + # to this currently chosen one (aka. alias domains) + $query = "SELECT $table_alias_domain.alias_domain,$table_alias_domain.target_domain,$table_alias_domain.modified,$table_alias_domain.active FROM $table_alias_domain WHERE target_domain='$fDomain' ORDER BY $table_alias_domain.alias_domain LIMIT $fDisplay, $page_size"; + if ('pgsql'==$CONF['database_type']) { - if ('pgsql'==$CONF['database_type']) - { - $row['modified']=gmstrftime('%c %Z',$row['modified']); - $row['active']=('t'==$row['active']) ? 1 : 0; - } - $tAliasDomains[] = $row; + $query = "SELECT alias_domain,target_domain,extract(epoch from modified) as modified,active FROM $table_alias_domain WHERE target_domain='$fDomain' ORDER BY alias_domain LIMIT $page_size OFFSET $fDisplay"; } -} -# now let's see if the current domain itself is an alias for another domain -$query = "SELECT $table_alias_domain.alias_domain,$table_alias_domain.target_domain,$table_alias_domain.modified,$table_alias_domain.active FROM $table_alias_domain WHERE alias_domain='$fDomain'"; -if ('pgsql'==$CONF['database_type']) -{ - $query = "SELECT alias_domain,target_domain,extract(epoch from modified) as modified,active FROM $table_alias_domain WHERE alias_domain='$fDomain'"; -} -$result = db_query ($query); -$tTargetDomain = ""; -if ($result['rows'] > 0) -{ - if($row = db_array ($result['result'])) + $result = db_query ($query); + $tAliasDomains = array(); + if ($result['rows'] > 0) { - if ('pgsql'==$CONF['database_type']) + while ($row = db_array ($result['result'])) { - $row['modified']=gmstrftime('%c %Z',$row['modified']); - $row['active']=('t'==$row['active']) ? 1 : 0; + if ('pgsql'==$CONF['database_type']) + { + $row['modified']=gmstrftime('%c %Z',$row['modified']); + $row['active']=('t'==$row['active']) ? 1 : 0; + } + $tAliasDomains[] = $row; + } + } + # now let's see if the current domain itself is an alias for another domain + $query = "SELECT $table_alias_domain.alias_domain,$table_alias_domain.target_domain,$table_alias_domain.modified,$table_alias_domain.active FROM $table_alias_domain WHERE alias_domain='$fDomain'"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT alias_domain,target_domain,extract(epoch from modified) as modified,active FROM $table_alias_domain WHERE alias_domain='$fDomain'"; + } + $result = db_query ($query); + $tTargetDomain = ""; + if ($result['rows'] > 0) + { + if($row = db_array ($result['result'])) + { + if ('pgsql'==$CONF['database_type']) + { + $row['modified']=gmstrftime('%c %Z',$row['modified']); + $row['active']=('t'==$row['active']) ? 1 : 0; + } + $tTargetDomain = $row; } - $tTargetDomain = $row; } } - $query = "SELECT $table_alias.address,$table_alias.goto,$table_alias.modified,$table_alias.active FROM $table_alias LEFT JOIN $table_mailbox ON $table_alias.address=$table_mailbox.username WHERE $table_alias.domain='$fDomain' AND $table_mailbox.maildir IS NULL ORDER BY $table_alias.address LIMIT $fDisplay, $page_size"; if ('pgsql'==$CONF['database_type']) { diff --git a/templates/list-virtual.php b/templates/list-virtual.php index dbbffed8..f52215b6 100644 --- a/templates/list-virtual.php +++ b/templates/list-virtual.php @@ -72,7 +72,7 @@ if ($tDisplay_next_show == 1) print "\n"; -if ((sizeof ($tAliasDomains) > 0) || is_array ($tTargetDomain)) +if (boolconf('alias_domain') && ((sizeof ($tAliasDomains) > 0) || is_array ($tTargetDomain))) { print "\n"; print " \n"; diff --git a/templates/menu.php b/templates/menu.php index 35a62bf8..8955fa67 100644 --- a/templates/menu.php +++ b/templates/menu.php @@ -16,8 +16,10 @@ $submenu_virtual = _menulink($url, $PALANG['pMenu_create_mailbox']); $url = "create-alias.php"; if (isset ($_GET['domain'])) $url .= "?domain=" . $_GET['domain']; $submenu_virtual .= _menulink($url, $PALANG['pMenu_create_alias']); -$url = "create-alias-domain.php"; if (isset ($_GET['domain'])) $url .= "?target_domain=" . $_GET['domain']; -$submenu_virtual .= _menulink($url, $PALANG['pMenu_create_alias_domain']); +if (boolconf('alias_domain')) { + $url = "create-alias-domain.php"; if (isset ($_GET['domain'])) $url .= "?target_domain=" . $_GET['domain']; + $submenu_virtual .= _menulink($url, $PALANG['pMenu_create_alias_domain']); +} $submenu_admin = _menulink("create-admin.php", $PALANG['pAdminMenu_create_admin']);