0
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2024-09-19 19:22:14 +02:00

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.



git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@652 a1433add-5e2c-0410-b055-b7f2511e0802
This commit is contained in:
Christian Boltz 2009-05-07 23:23:21 +00:00
parent ab1162ca84
commit a9d9e3d96a
4 changed files with 47 additions and 153 deletions

View File

@ -117,15 +117,14 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
$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 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
$sqlActive = db_get_boolean(False);
}
$success = false;
/* Alias (or mailbox) already present, let's add the destination to that row */
if ($append_alias) {
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 ($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";
}
@ -168,6 +151,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
$tMessage = $PALANG['pCreate_alias_result_success'] . "<br />($fAddress -> $fGoto)<br />\n";
}
}
}
include ("templates/header.php");
include ("templates/menu.php");

View File

@ -43,58 +43,6 @@ $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. foo@example.com)
*/
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 @@ elseif ($fTable == "alias_domain")
}
} # ($fTable == "alias_domain")
elseif ($fTable == "mailbox")
elseif ($fTable == "alias" or $fTable == "mailbox")
{
if (!check_owner ($SESSID_USERNAME, $fDomain))
@ -166,10 +114,13 @@ elseif ($fTable == "mailbox")
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)
@ -205,21 +156,9 @@ elseif ($fTable == "mailbox")
header ("Location: list-virtual.php?domain=$fDomain");
exit;
} else {
$tMessage = $PALANG['pDelete_delete_error'] . "<b>$fDelete</b> (physical mail)!</span>";
$tMessage .= $PALANG['pDelete_delete_error'] . "<b>$fDelete</b> (physical mail)!</span>";
if ($CONF['database_type'] == "pgsql") db_query('ROLLBACK');
}
} # ($fTable == "mailbox")
}
elseif ($fTable == "alias") {
$error = delete_alias ($fDelete, $fDomain) ? 0 : 1;
if ($error != 1)
{
header ("Location: list-virtual.php?domain=$fDomain");
exit;
} else {
$tMessage = $PALANG['pDelete_delete_error'] . "<b>$fDelete</b> (alias)!</span>";
}
}
else
{

View File

@ -431,14 +431,7 @@ function get_domain_properties ($domain)
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 @@ function get_domain_properties ($domain)
$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 @@ function get_domain_properties ($domain)
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 @@ function get_domain_properties ($domain)
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']);

View File

@ -123,22 +123,15 @@ $query = "SELECT $table_alias.address,
$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);
@ -154,13 +147,6 @@ if ($result['rows'] > 0)
$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;
}
}
@ -242,5 +228,5 @@ include ("templates/menu.php");
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: */
?>