SF.net SVN: postfixadmin:[652] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2009-05-07 23:23:36
|
Revision: 652 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=652&view=rev Author: christian_boltz Date: 2009-05-07 23:23:21 +0000 (Thu, 07 May 2009) Log Message: ----------- reverting most changes from SVN r572 aka https://sourceforge.net/tracker/index.php?func=detail&aid=2567466&group_id=191583&atid=937966 because - it undermines the $CONF[*alias_control*] settings more or less - mailbox aliases with non-default targets are always shown in the "Aliases" section - see comment from 2009-05-04 on https://sourceforge.net/tracker/?func=detail&aid=1902476&group_id=191583&atid=937964 - it introduced some "funny" bugs - a nice example is http://sourceforge.net/tracker/?func=detail&aid=2786284&group_id=191583&atid=937964 Files / sections affected by the revert: - list-virtual.php: all numbers (alias count etc.) correct? (the changes in this file are the largest ones) - functions.inc.php: SQL queries in get_domain_properties() - delete.php: the only change since r572 affected code that was inserted in r572 (and is now deleted again) - nothing should break here - create-alias.php: had no changes since r572 - therefore nothing should break here Exceptions (not reverted): - edit-alias: this change looks useful (hide mailbox alias target from admins if they don't have permissions to change it). The actual code has changed in the meantime, but the functionality stays. Additionally, reverting this would be very hard or throw useful later changes away. BUT: shouldn't the page completely forbid to edit a mailbox alias if the admin doesn't have permissions for it? - functions.inc.php: comment for pacrypt() ;-) - linebreaks in long SQL queries Please check if everything is still working as expected (especially the domain list and the virtual list) - I did only some quick tests. Modified Paths: -------------- trunk/create-alias.php trunk/delete.php trunk/functions.inc.php trunk/list-virtual.php Modified: trunk/create-alias.php =================================================================== --- trunk/create-alias.php 2009-05-06 20:24:05 UTC (rev 651) +++ trunk/create-alias.php 2009-05-07 23:23:21 UTC (rev 652) @@ -117,15 +117,14 @@ $fAddress = "@" . escape_string ($_POST['fDomain']); } - $append_alias = false; - $result = db_query ("SELECT * FROM $table_alias WHERE address='$fAddress'"); if ($result['rows'] == 1) { - $append_alias = true; + $error = 1; $tAddress = escape_string ($_POST['fAddress']); $tGoto = $fGoto; $tDomain = $fDomain; + $pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error2']; } if ($fActive == "on") { @@ -135,29 +134,13 @@ $sqlActive = db_get_boolean(False); } - $success = false; - /* Alias (or mailbox) already present, let's add the destination to that row */ - if ($append_alias) { + if ($error != 1) { if (preg_match('/^\*@(.*)$/', $fGoto, $match)) { $fGoto = "@" . $match[1]; } - $array = db_array ($result['result']); - - $values ['goto'] = $array['goto'] . ',' . $fGoto; - $result = db_update ($table_alias, "address = '$fAddress'", $values, array ('modified')); - $success = ($result == 1); - - } elseif ($error != 1) { - if (preg_match('/^\*@(.*)$/', $fGoto, $match)) { - $fGoto = "@" . $match[1]; - } - $result = db_query ("INSERT INTO $table_alias (address,goto,domain,created,modified,active) VALUES ('$fAddress','$fGoto','$fDomain',NOW(),NOW(),'$sqlActive')"); - $success = ($result['rows'] == 1); - } - - if (! $success) { + if ($result['rows'] != 1) { $tDomain = $fDomain; $tMessage = $PALANG['pCreate_alias_result_error'] . "<br />($fAddress -> $fGoto)<br />\n"; } @@ -167,6 +150,7 @@ $tDomain = $fDomain; $tMessage = $PALANG['pCreate_alias_result_success'] . "<br />($fAddress -> $fGoto)<br />\n"; } + } } include ("templates/header.php"); Modified: trunk/delete.php =================================================================== --- trunk/delete.php 2009-05-06 20:24:05 UTC (rev 651) +++ trunk/delete.php 2009-05-07 23:23:21 UTC (rev 652) @@ -37,64 +37,12 @@ $SESSID_USERNAME = authentication_get_username(); $error = 0; -$fTable = escape_string(safeget('table')); # see the if blocks below for valid values -$fDelete = escape_string(safeget('delete')); -$fDomain = escape_string(safeget('domain')); +$fTable = escape_string (safeget('table') ); # see the if blocks below for valid values +$fDelete = escape_string (safeget('delete')); +$fDomain = escape_string (safeget('domain')); $error=0; -/** - * delete_alias - * Action: Delete an alias - * @param String $alias alias to delete. - * @param String $domain domain of the alias - * @param boolean $force_delete - deletes the alias from the table if true, - * checks if the alias is real and act accordlying if false. - * Default is false. - * @return String username (e.g. fo...@ex...) - */ -function delete_alias($alias, $domain, $force_delete = false) -{ - global $table_alias, $table_mailbox; - $SESSID_USERNAME = authentication_get_username(); - $real_alias = true; - - if (! $force_delete) - { - $result = db_query ("SELECT 1 FROM $table_mailbox - WHERE username='$alias' AND domain='$domain'"); - if ($result['rows'] != 0) - { - /* If the alias is a real mailbox as well, remove all its real aliases and keep - * only the address */ - $real_alias = false; - } - } - - if ($force_delete or $real_alias) - { - $result = db_query ("DELETE FROM $table_alias WHERE address='$alias' AND domain='$domain'"); - } - else - { - $result = db_query ("UPDATE $table_alias SET goto='$alias',modified=NOW() - WHERE address='$alias' AND domain='$domain'"); - } - - if ($result['rows'] != 1) - { - $tMessage = $PALANG['pDelete_delete_error'] . "<b>$alias</b> (alias)!</span>"; - - return false; - } - else - { - db_log ($SESSID_USERNAME, $domain, 'delete_alias', $alias); - } - - return true; -} - if ($fTable == "admin") { authentication_require_role('global-admin'); @@ -150,7 +98,7 @@ } } # ($fTable == "alias_domain") -elseif ($fTable == "mailbox") +elseif ($fTable == "alias" or $fTable == "mailbox") { if (!check_owner ($SESSID_USERNAME, $fDomain)) @@ -166,59 +114,50 @@ else { if ($CONF['database_type'] == "pgsql") db_query('BEGIN'); + /* there may be no aliases to delete */ + $result = db_query("SELECT * FROM $table_alias WHERE address = '$fDelete' AND domain = '$fDomain'"); + if($result['rows'] == 1) { + $result = db_query ("DELETE FROM $table_alias WHERE address='$fDelete' AND domain='$fDomain'"); + db_log ($SESSID_USERNAME, $fDomain, 'delete_alias', $fDelete); + } - $error = delete_alias ($fDelete, $fDomain, $force_delete = true) ? 0 : 1; - if (! $error) + /* is there a mailbox? if do delete it from orbit; it's the only way to be sure */ + $result = db_query ("SELECT * FROM $table_mailbox WHERE username='$fDelete' AND domain='$fDomain'"); + if ($result['rows'] == 1) { - /* is there a mailbox? if do delete it from orbit; it's the only way to be sure */ - $result = db_query ("SELECT * FROM $table_mailbox WHERE username='$fDelete' AND domain='$fDomain'"); - if ($result['rows'] == 1) + $result = db_query ("DELETE FROM $table_mailbox WHERE username='$fDelete' AND domain='$fDomain'"); + $postdel_res=mailbox_postdeletion($fDelete,$fDomain); + if ($result['rows'] != 1 || !$postdel_res) { - $result = db_query ("DELETE FROM $table_mailbox WHERE username='$fDelete' AND domain='$fDomain'"); - $postdel_res=mailbox_postdeletion($fDelete,$fDomain); - if ($result['rows'] != 1 || !$postdel_res) + $error = 1; + $tMessage = $PALANG['pDelete_delete_error'] . "<b>$fDelete</b> ("; + if ($result['rows']!=1) { - $error = 1; - $tMessage = $PALANG['pDelete_delete_error'] . "<b>$fDelete</b> ("; - if ($result['rows']!=1) - { - $tMessage.='mailbox'; - if (!$postdel_res) $tMessage.=', '; - } - if (!$postdel_res) - { - $tMessage.='post-deletion'; - } - $tMessage.=')</span>'; + $tMessage.='mailbox'; + if (!$postdel_res) $tMessage.=', '; } + if (!$postdel_res) + { + $tMessage.='post-deletion'; + } + $tMessage.=')</span>'; } - $result = db_query("SELECT * FROM $table_vacation WHERE email = '$fDelete' AND domain = '$fDomain'"); - if($result['rows'] == 1) { - db_query ("DELETE FROM $table_vacation WHERE email='$fDelete' AND domain='$fDomain'"); - db_query ("DELETE FROM $table_vacation_notification WHERE on_vacation ='$fDelete' "); /* should be caught by cascade, if PgSQL */ - } } - - if ($error != 1) - { - if ($CONF['database_type'] == "pgsql") db_query('COMMIT'); - header ("Location: list-virtual.php?domain=$fDomain"); - exit; - } else { - $tMessage = $PALANG['pDelete_delete_error'] . "<b>$fDelete</b> (physical mail)!</span>"; - if ($CONF['database_type'] == "pgsql") db_query('ROLLBACK'); + $result = db_query("SELECT * FROM $table_vacation WHERE email = '$fDelete' AND domain = '$fDomain'"); + if($result['rows'] == 1) { + db_query ("DELETE FROM $table_vacation WHERE email='$fDelete' AND domain='$fDomain'"); + db_query ("DELETE FROM $table_vacation_notification WHERE on_vacation ='$fDelete' "); /* should be caught by cascade, if PgSQL */ } - } # ($fTable == "mailbox") -} -elseif ($fTable == "alias") { - $error = delete_alias ($fDelete, $fDomain) ? 0 : 1; + } if ($error != 1) { + if ($CONF['database_type'] == "pgsql") db_query('COMMIT'); header ("Location: list-virtual.php?domain=$fDomain"); exit; } else { - $tMessage = $PALANG['pDelete_delete_error'] . "<b>$fDelete</b> (alias)!</span>"; + $tMessage .= $PALANG['pDelete_delete_error'] . "<b>$fDelete</b> (physical mail)!</span>"; + if ($CONF['database_type'] == "pgsql") db_query('ROLLBACK'); } } else Modified: trunk/functions.inc.php =================================================================== --- trunk/functions.inc.php 2009-05-06 20:24:05 UTC (rev 651) +++ trunk/functions.inc.php 2009-05-07 23:23:21 UTC (rev 652) @@ -431,14 +431,7 @@ global $table_alias, $table_mailbox, $table_domain; $list = array (); - $result = db_query ("SELECT COUNT(*) FROM $table_alias - LEFT JOIN $table_mailbox ON $table_alias.address=$table_mailbox.username - WHERE ($table_alias.domain='$domain' AND $table_mailbox.maildir IS NULL) - OR - ($table_alias.domain='$domain' - AND $table_alias.goto LIKE '%,%' - AND $table_mailbox.maildir IS NOT NULL)"); - + $result = db_query ("SELECT COUNT(*) FROM $table_alias WHERE domain='$domain'"); $row = db_row ($result['result']); $list['alias_count'] = $row[0]; @@ -449,7 +442,7 @@ $result = db_query ("SELECT SUM(quota) FROM $table_mailbox WHERE domain='$domain'"); $row = db_row ($result['result']); $list['quota_sum'] = $row[0]; - $list['alias_count'] = $list['alias_count']; + $list['alias_count'] = $list['alias_count'] - $list['mailbox_count']; $list['alias_pgindex']=array (); $list['mbox_pgindex']=array (); @@ -471,10 +464,6 @@ FROM $table_alias LEFT JOIN $table_mailbox ON $table_alias.address=$table_mailbox.username WHERE ($table_alias.domain='$domain' AND $table_mailbox.maildir IS NULL) - OR - ($table_alias.domain='$domain' - AND $table_alias.goto LIKE '%,%' - AND $table_mailbox.maildir IS NOT NULL) ORDER BY $table_alias.address LIMIT $limitSql"; $result = db_query ("$query"); $row = db_array ($result['result']); @@ -487,10 +476,6 @@ FROM $table_alias LEFT JOIN $table_mailbox ON $table_alias.address=$table_mailbox.username WHERE ($table_alias.domain='$domain' AND $table_mailbox.maildir IS NULL) - OR - ($table_alias.domain='$domain' - AND $table_alias.goto LIKE '%,%' - AND $table_mailbox.maildir IS NOT NULL) ORDER BY $table_alias.address LIMIT $limitSql"; $result = db_query ("$query"); $row = db_array ($result['result']); Modified: trunk/list-virtual.php =================================================================== --- trunk/list-virtual.php 2009-05-06 20:24:05 UTC (rev 651) +++ trunk/list-virtual.php 2009-05-07 23:23:21 UTC (rev 652) @@ -123,22 +123,15 @@ $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) - OR - ($table_alias.domain='$fDomain' - AND $table_alias.goto LIKE '%,%' - AND $table_mailbox.maildir IS NOT NULL) ORDER BY $table_alias.address LIMIT $fDisplay, $page_size"; - if ('pgsql'==$CONF['database_type']) { $query = "SELECT address, goto, - modified, + extract(epoch from modified) as modified, active - FROM $table_alias WHERE domain='$fDomain' - AND NOT EXISTS(SELECT 1 FROM $table_mailbox - WHERE username=$table_alias.address - AND $table_alias.goto NOT LIKE '%,%') + FROM $table_alias + WHERE domain='$fDomain' AND NOT EXISTS(SELECT 1 FROM $table_mailbox WHERE username=$table_alias.address) ORDER BY address LIMIT $page_size OFFSET $fDisplay"; } $result = db_query ($query); @@ -147,20 +140,13 @@ while ($row = db_array ($result['result'])) { if ('pgsql'==$CONF['database_type']) - { + { //. at least in my database, $row['modified'] already looks like : 2009-04-11 21:38:10.75586+01, // while gmstrftime expects an integer value. strtotime seems happy though. //$row['modified']=gmstrftime('%c %Z',$row['modified']); $row['modified'] = date('Y-m-d H:i', strtotime($row['modified'])); $row['active']=('t'==$row['active']) ? 1 : 0; } - - /* Has a real mailbox as well? Remove the address from $row['goto'] in order to edit just the real aliases */ - if (strstr ($row['goto'], ',') != FALSE) - { - $row['goto'] = preg_replace ('/\s*,*\s*' . $row['address'] . '\s*,*\s*/', '', $row['goto']); - } - $tAlias[] = $row; } } @@ -213,7 +199,7 @@ } if (($limit['alias_count'] > $page_size) or ($limit['mailbox_count'] > $page_size)) { $tDisplay_up_show = 1; - } + } if ((($fDisplay + $page_size) < $limit['alias_count']) or (($fDisplay + $page_size) < $limit['mailbox_count'])) { @@ -242,5 +228,5 @@ include ("templates/list-virtual.php"); include ("templates/footer.php"); -/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ +/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |