1
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2025-08-07 17:42:53 +03:00

functions.inc.php: reindent, ensure alias_pgindex_count is initialised in get_domain_details()

git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@21 a1433add-5e2c-0410-b055-b7f2511e0802
This commit is contained in:
David Goodwin
2007-08-17 15:10:59 +00:00
parent b933b9186c
commit fc6013cb2a

View File

@@ -57,11 +57,14 @@ function check_user_session ()
// //
function session_fixid () function session_fixid ()
{ {
if (!isset($_SESSION['exist'])) if (!isset($_SESSION['exist']))
{ {
if ( !session_regenerate_id() ) die("Couldn't regenerate your session id."); if ( !session_regenerate_id() )
$_SESSION['exist'] = true; {
} die("Couldn't regenerate your session id.");
}
$_SESSION['exist'] = true;
}
} }
@@ -84,7 +87,7 @@ function check_language ()
$lang_next = $lang_array[$i]; $lang_next = $lang_array[$i];
$lang_next = strtolower(substr(trim($lang_next), 0, 2)); $lang_next = strtolower(substr(trim($lang_next), 0, 2));
if(in_array($lang_next, $supported_languages)) if(in_array($lang_next, $supported_languages))
{ {
$lang = $lang_next; $lang = $lang_next;
break; break;
} }
@@ -157,35 +160,35 @@ function check_email ($email)
isset($CONF['emailcheck_resolve_domain']) isset($CONF['emailcheck_resolve_domain'])
&& 'YES'==$CONF['emailcheck_resolve_domain'] && 'YES'==$CONF['emailcheck_resolve_domain']
&& 'WINDOWS'!=(strtoupper(substr(php_uname('s'), 0, 7))) && 'WINDOWS'!=(strtoupper(substr(php_uname('s'), 0, 7)))
) { ) {
// Perform non-domain-part sanity checks // Perform non-domain-part sanity checks
if (!preg_match ('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_{|}~]+' . '@' . '[^@]+$/i', trim ($ce_email))) if (!preg_match ('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_{|}~]+' . '@' . '[^@]+$/i', trim ($ce_email)))
{ {
return false; return false;
} }
// Determine domain name // Determine domain name
$matches=array(); $matches=array();
if (!preg_match('|@(.+)$|',$ce_email,$matches)) if (!preg_match('|@(.+)$|',$ce_email,$matches))
{ {
return false; return false;
} }
$domain=$matches[1]; $domain=$matches[1];
// Look for an AAAA, A, or MX record for the domain // Look for an AAAA, A, or MX record for the domain
// AAAA (IPv6) is only available in PHP v. >= 5 // AAAA (IPv6) is only available in PHP v. >= 5
if (version_compare(phpversion(), "5.0.0", ">=")) if (version_compare(phpversion(), "5.0.0", ">="))
{ {
if (checkdnsrr($domain,'AAAA')) return true; if (checkdnsrr($domain,'AAAA')) return true;
} }
if (checkdnsrr($domain,'A')) return true; if (checkdnsrr($domain,'A')) return true;
if (checkdnsrr($domain,'MX')) return true; if (checkdnsrr($domain,'MX')) return true;
return false; return false;
} }
if (preg_match ('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_{|}~]+' . '@' . '([-0-9A-Z]+\.)+' . '([0-9A-Z]){2,6}$/i', trim ($ce_email))) if (preg_match ('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_{|}~]+' . '@' . '([-0-9A-Z]+\.)+' . '([0-9A-Z]){2,6}$/i', trim ($ce_email)))
{ {
@@ -209,7 +212,7 @@ function check_email ($email)
function escape_string ($string) function escape_string ($string)
{ {
global $CONF; global $CONF;
if (get_magic_quotes_gpc ()) if (get_magic_quotes_gpc ())
{ {
$string = stripslashes($string); $string = stripslashes($string);
} }
@@ -217,19 +220,19 @@ function escape_string ($string)
{ {
if ($CONF['database_type'] == "mysql") if ($CONF['database_type'] == "mysql")
{ {
$link = db_connect(); $link = db_connect();
$escaped_string = mysql_real_escape_string($string, $link); $escaped_string = mysql_real_escape_string($string, $link);
} }
if ($CONF['database_type'] == "mysqli") if ($CONF['database_type'] == "mysqli")
{ {
$link = db_connect(); $link = db_connect();
$escaped_string = mysqli_real_escape_string($link, $string); $escaped_string = mysqli_real_escape_string($link, $string);
} }
if ($CONF['database_type'] == "pgsql") $escaped_string = pg_escape_string($string); if ($CONF['database_type'] == "pgsql") $escaped_string = pg_escape_string($string);
} }
else else
{ {
$escaped_string = $string; $escaped_string = $string;
} }
return $escaped_string; return $escaped_string;
} }
@@ -262,13 +265,14 @@ function get_domain_properties ($domain)
$list['alias_pgindex']=array (); $list['alias_pgindex']=array ();
$list['mbox_pgindex']=array (); $list['mbox_pgindex']=array ();
$list['mbox_pgindex_count'] = 0;
//while loop to figure index names. use page_size and loop of queries //while loop to figure index names. use page_size and loop of queries
$i=0; $i=0;
$current=0; $current=0;
$page_size = $CONF['page_size']; $page_size = $CONF['page_size'];
$tmpstr=""; $tmpstr="";
$idxlabel=""; $idxlabel="";
$list['alias_pgindex_count'] = 0;
if ( $list['alias_count'] > $page_size ) if ( $list['alias_count'] > $page_size )
{ {
@@ -330,19 +334,12 @@ function get_domain_properties ($domain)
$list['mbox_pgindex_count']=$i; $list['mbox_pgindex_count']=$i;
} }
// end mod // end mod
$query="SELECT * FROM $table_domain WHERE domain='$domain'"; $query="SELECT * FROM $table_domain WHERE domain='$domain'";
if ('pgsql'==$CONF['database_type']) if ('pgsql'==$CONF['database_type'])
{ {
$query=" $query=" SELECT *, EXTRACT(epoch FROM created) AS uts_created, EXTRACT(epoch FROM modified) AS uts_modified FROM $table_domain WHERE domain='$domain' ";
SELECT
*,
EXTRACT(epoch FROM created) AS uts_created,
EXTRACT(epoch FROM modified) AS uts_modified
FROM $table_domain
WHERE domain='$domain'
";
} }
$result = db_query ($query); $result = db_query ($query);
$row = db_array ($result['result']); $row = db_array ($result['result']);
@@ -389,12 +386,12 @@ function get_mailbox_properties ($username)
{ {
$query=" $query="
SELECT SELECT
*, *,
EXTRACT(epoch FROM created) AS uts_created, EXTRACT(epoch FROM created) AS uts_created,
EXTRACT(epoch FROM modified) AS uts_modified EXTRACT(epoch FROM modified) AS uts_modified
FROM $table_mailbox FROM $table_mailbox
WHERE username='$username' WHERE username='$username'
"; ";
} }
$result = db_query ($query); $result = db_query ($query);
$row = db_array ($result['result']); $row = db_array ($result['result']);
@@ -761,12 +758,12 @@ function get_admin_properties ($username)
if ('pgsql'==$CONF['database_type']) { if ('pgsql'==$CONF['database_type']) {
$query=" $query="
SELECT SELECT
*, *,
EXTRACT(epoch FROM created) AS uts_created, EXTRACT(epoch FROM created) AS uts_created,
EXTRACT (epoch FROM modified) AS uts_modified EXTRACT (epoch FROM modified) AS uts_modified
FROM $table_admin FROM $table_admin
WHERE username='$username' WHERE username='$username'
"; ";
} }
$result = db_query ($query); $result = db_query ($query);
@@ -807,12 +804,12 @@ function encode_header ($string, $default_charset)
{ {
switch ($string{$i}) switch ($string{$i})
{ {
case '=': case '=':
case '<': case '<':
case '>': case '>':
case ',': case ',':
case '?': case '?':
case '_': case '_':
if ($iEncStart === false) if ($iEncStart === false)
{ {
$iEncStart = $i; $iEncStart = $i;
@@ -832,8 +829,8 @@ function encode_header ($string, $default_charset)
$ret .= sprintf ("=%02X",ord($string{$i})); $ret .= sprintf ("=%02X",ord($string{$i}));
} }
break; break;
case '(': case '(':
case ')': case ')':
if ($iEncStart !== false) if ($iEncStart !== false)
{ {
$aRet[] = substr ($string,$iOffset,$iEncStart-$iOffset); $aRet[] = substr ($string,$iOffset,$iEncStart-$iOffset);
@@ -844,7 +841,7 @@ function encode_header ($string, $default_charset)
$iEncStart = false; $iEncStart = false;
} }
break; break;
case ' ': case ' ':
if ($iEncStart !== false) if ($iEncStart !== false)
{ {
$cur_l++; $cur_l++;
@@ -863,7 +860,7 @@ function encode_header ($string, $default_charset)
} }
} }
break; break;
default: default:
$k = ord ($string{$i}); $k = ord ($string{$i});
if ($k > 126) if ($k > 126)
{ {
@@ -890,9 +887,9 @@ function encode_header ($string, $default_charset)
} }
$enc_init = true; $enc_init = true;
$ret .= sprintf ("=%02X", $k); $ret .= sprintf ("=%02X", $k);
} }
else else
{ {
if ($iEncStart !== false) if ($iEncStart !== false)
{ {
$cur_l++; $cur_l++;
@@ -904,29 +901,29 @@ function encode_header ($string, $default_charset)
$iOffset = $i; $iOffset = $i;
$cur_l = 0; $cur_l = 0;
$ret = ''; $ret = '';
} }
else else
{ {
$ret .= $string{$i}; $ret .= $string{$i};
}
} }
} }
break;
} }
break;
} }
if ($enc_init) }
if ($enc_init)
{
if ($iEncStart !== false)
{ {
if ($iEncStart !== false) $aRet[] = substr ($string,$iOffset,$iEncStart-$iOffset);
{ $aRet[] = "=?$default_charset?Q?$ret?=";
$aRet[] = substr ($string,$iOffset,$iEncStart-$iOffset);
$aRet[] = "=?$default_charset?Q?$ret?=";
}
else
{
$aRet[] = substr ($string,$iOffset);
}
$string = implode ('',$aRet);
} }
else
{
$aRet[] = substr ($string,$iOffset);
}
$string = implode ('',$aRet);
}
return $string; return $string;
} }
@@ -953,7 +950,7 @@ function generate_password ()
function pacrypt ($pw, $pw_db="") function pacrypt ($pw, $pw_db="")
{ {
global $CONF; global $CONF;
$pw = stripslashes($pw); $pw = stripslashes($pw);
$password = ""; $password = "";
$salt = ""; $salt = "";
@@ -975,13 +972,13 @@ function pacrypt ($pw, $pw_db="")
else else
{ {
if (strlen($pw_db) == 0) if (strlen($pw_db) == 0)
{ {
$salt = substr (md5 (mt_rand ()), 0, 2); $salt = substr (md5 (mt_rand ()), 0, 2);
} }
else else
{ {
$salt = substr ($pw_db, 0, 2); $salt = substr ($pw_db, 0, 2);
} }
} }
$password = crypt ($pw, $salt); $password = crypt ($pw, $salt);
} }
@@ -1156,23 +1153,23 @@ function smtp_get_response ($fh)
{ {
$res =''; $res ='';
do do
{ {
$line = fgets($fh, 256); $line = fgets($fh, 256);
$res .= $line; $res .= $line;
} }
while (preg_match("/^\d\d\d\-/", $line)); while (preg_match("/^\d\d\d\-/", $line));
return $res; return $res;
} }
$DEBUG_TEXT = "\n $DEBUG_TEXT = "\n
<p />\n <p />\n
Please check the documentation and website for more information.\n Please check the documentation and website for more information.\n
<p />\n <p />\n
<a href=\"http://high5.net/postfixadmin/\">Postfix Admin</a><br />\n <a href=\"http://high5.net/postfixadmin/\">Postfix Admin</a><br />\n
<a href=\"http://forums.high5.net/index.php?showforum=7\">Knowledge Base</a>\n <a href=\"http://forums.high5.net/index.php?showforum=7\">Knowledge Base</a>\n
"; ";
@@ -1196,7 +1193,7 @@ function db_connect ()
else else
{ {
print "<p />DEBUG INFORMATION:<br />MySQL 3.x / 4.0 functions not available!<br />database_type = 'mysql' in config.inc.php, are you using a different database? $DEBUG_TEXT"; print "<p />DEBUG INFORMATION:<br />MySQL 3.x / 4.0 functions not available!<br />database_type = 'mysql' in config.inc.php, are you using a different database? $DEBUG_TEXT";
die; die();
} }
} }
@@ -1210,7 +1207,7 @@ function db_connect ()
else else
{ {
print "<p />DEBUG INFORMATION:<br />MySQL 4.1 functions not available!<br />database_type = 'mysqli' in config.inc.php, are you using a different database? $DEBUG_TEXT"; print "<p />DEBUG INFORMATION:<br />MySQL 4.1 functions not available!<br />database_type = 'mysqli' in config.inc.php, are you using a different database? $DEBUG_TEXT";
die; die();
} }
} }
@@ -1224,7 +1221,7 @@ function db_connect ()
else else
{ {
print "<p />DEBUG INFORMATION:<br />PostgreSQL functions not available!<br />database_type = 'pgsql' in config.inc.php, are you using a different database? $DEBUG_TEXT"; print "<p />DEBUG INFORMATION:<br />PostgreSQL functions not available!<br />database_type = 'pgsql' in config.inc.php, are you using a different database? $DEBUG_TEXT";
die; die();
} }
} }
@@ -1239,7 +1236,7 @@ function db_connect ()
print "<br />\n"; print "<br />\n";
print "Make sure that you have set the correct database type in the config.inc.php file<br />\n"; print "Make sure that you have set the correct database type in the config.inc.php file<br />\n";
print $DEBUG_TEXT; print $DEBUG_TEXT;
die; die();
} }
} }
@@ -1422,7 +1419,7 @@ function table_by_pos ($pos)
/* /*
Called after a mailbox has been created in the DBMS. Called after a mailbox has been created in the DBMS.
Returns: boolean. Returns: boolean.
*/ */
function mailbox_postcreation($username,$domain,$maildir) function mailbox_postcreation($username,$domain,$maildir)
{ {
if (empty($username) || empty($domain) || empty($maildir)) if (empty($username) || empty($domain) || empty($maildir))
@@ -1457,7 +1454,7 @@ function mailbox_postcreation($username,$domain,$maildir)
/* /*
Called after a mailbox has been deleted in the DBMS. Called after a mailbox has been deleted in the DBMS.
Returns: boolean. Returns: boolean.
*/ */
function mailbox_postdeletion($username,$domain) function mailbox_postdeletion($username,$domain)
{ {
global $CONF; global $CONF;
@@ -1494,7 +1491,7 @@ function mailbox_postdeletion($username,$domain)
/* /*
Called after a domain has been deleted in the DBMS. Called after a domain has been deleted in the DBMS.
Returns: boolean. Returns: boolean.
*/ */
function domain_postdeletion($domain) function domain_postdeletion($domain)
{ {
global $CONF; global $CONF;
@@ -1543,7 +1540,7 @@ function domain_postdeletion($domain)
Doesn't clean up, if only some of the folders could be Doesn't clean up, if only some of the folders could be
created. created.
*/ */
function create_mailbox_subfolders($login,$cleartext_password) function create_mailbox_subfolders($login,$cleartext_password)
{ {
global $CONF; global $CONF;
@@ -1575,17 +1572,17 @@ function create_mailbox_subfolders($login,$cleartext_password)
if ( if (
isset($CONF['create_mailbox_subdirs_hostoptions']) isset($CONF['create_mailbox_subdirs_hostoptions'])
&& !empty($CONF['create_mailbox_subdirs_hostoptions']) && !empty($CONF['create_mailbox_subdirs_hostoptions'])
) { ) {
if (!is_array($CONF['create_mailbox_subdirs_hostoptions'])) if (!is_array($CONF['create_mailbox_subdirs_hostoptions']))
{ {
trigger_error('The $CONF["create_mailbox_subdirs_hostoptions"] parameter must be an array',E_USER_ERROR); trigger_error('The $CONF["create_mailbox_subdirs_hostoptions"] parameter must be an array',E_USER_ERROR);
return FALSE; return FALSE;
} }
foreach ($CONF['create_mailbox_subdirs_hostoptions'] as $o) foreach ($CONF['create_mailbox_subdirs_hostoptions'] as $o)
{ {
$s_options.='/'.$o; $s_options.='/'.$o;
} }
} }
if (isset($CONF['create_mailbox_subdirs_hostport']) && !empty($CONF['create_mailbox_subdirs_hostport'])) if (isset($CONF['create_mailbox_subdirs_hostport']) && !empty($CONF['create_mailbox_subdirs_hostport']))
{ {