SF.net SVN: postfixadmin:[520] trunk/functions.inc.php
Brought to you by:
christian_boltz,
gingerdog
From: <Gin...@us...> - 2009-01-15 13:02:28
|
Revision: 520 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=520&view=rev Author: GingerDog Date: 2009-01-15 12:24:36 +0000 (Thu, 15 Jan 2009) Log Message: ----------- functions.inc.php: reindent Modified Paths: -------------- trunk/functions.inc.php Modified: trunk/functions.inc.php =================================================================== --- trunk/functions.inc.php 2009-01-15 12:21:08 UTC (rev 519) +++ trunk/functions.inc.php 2009-01-15 12:24:36 UTC (rev 520) @@ -18,8 +18,8 @@ if (ereg ("functions.inc.php", $_SERVER['PHP_SELF'])) { - header ("Location: login.php"); - exit; + header ("Location: login.php"); + exit; } $version = '2.2.0'; @@ -32,13 +32,13 @@ */ function authentication_get_username() { - global $CONF; - if (!isset($_SESSION['sessid'])) { - header ("Location: " . $CONF['postfix_admin_url'] . "/login.php"); - exit(0); - } - $SESSID_USERNAME = $_SESSION['sessid']['username']; - return $SESSID_USERNAME; + global $CONF; + if (!isset($_SESSION['sessid'])) { + header ("Location: " . $CONF['postfix_admin_url'] . "/login.php"); + exit(0); + } + $SESSID_USERNAME = $_SESSION['sessid']['username']; + return $SESSID_USERNAME; } /** @@ -47,12 +47,12 @@ * @return String admin or user or (boolean) false. */ function authentication_get_usertype() { - if(isset($_SESSION['sessid'])) { - if(isset($_SESSION['sessid']['type'])) { - return $_SESSION['sessid']['type']; - } - } - return false; + if(isset($_SESSION['sessid'])) { + if(isset($_SESSION['sessid']['type'])) { + return $_SESSION['sessid']['type']; + } + } + return false; } /** * @@ -62,15 +62,15 @@ * Note, user < admin < global-admin */ function authentication_has_role($role) { - global $CONF; - if(isset($_SESSION['sessid'])) { - if(isset($_SESSION['sessid']['roles'])) { - if(in_array($role, $_SESSION['sessid']['roles'])) { - return true; - } - } - } - return false; + global $CONF; + if(isset($_SESSION['sessid'])) { + if(isset($_SESSION['sessid']['roles'])) { + if(in_array($role, $_SESSION['sessid']['roles'])) { + return true; + } + } + } + return false; } /** @@ -82,26 +82,26 @@ * Note, user < admin < global-admin */ function authentication_require_role($role) { - global $CONF; - // redirect to appropriate page? - if(authentication_has_role($role)) { - return True; - } - header("Location: " . $CONF['postfix_admin_url'] . "/login.php"); - exit(0); + global $CONF; + // redirect to appropriate page? + if(authentication_has_role($role)) { + return True; + } + header("Location: " . $CONF['postfix_admin_url'] . "/login.php"); + exit(0); } /** * @return boolean TRUE if a admin, FALSE otherwise. */ function authentication_is_admin() { - return authentication_get_usertype() == 'admin'; + return authentication_get_usertype() == 'admin'; } /** * @return boolean TRUE if a user, FALSE otherwise. */ function authentication_is_user() { - return authentication_get_usertype() == 'user'; + return authentication_get_usertype() == 'user'; } @@ -113,7 +113,7 @@ * @see _flash_string() */ function flash_error($string) { - _flash_string('error', $string); + _flash_string('error', $string); } /** @@ -123,19 +123,19 @@ * @see _flash_string() */ function flash_info($string) { - _flash_string('info', $string); + _flash_string('info', $string); } /** * 'Private' method used for flash_info() and flash_error(). */ function _flash_string($type, $string) { - if(!isset($_SESSION['flash'])) { - $_SESSION['flash'] = array(); - } - if(!isset($_SESSION['flash'][$type])) { - $_SESSION['flash'][$type] = array(); - } - $_SESSION['flash'][$type][] = $string; + if(!isset($_SESSION['flash'])) { + $_SESSION['flash'] = array(); + } + if(!isset($_SESSION['flash'][$type])) { + $_SESSION['flash'][$type] = array(); + } + $_SESSION['flash'][$type][] = $string; } // @@ -146,33 +146,33 @@ // function check_language ($use_post = 1) { - global $CONF; - global $supported_languages; # from languages/languages.php + global $CONF; + global $supported_languages; # from languages/languages.php - $lang = $CONF['default_language']; + $lang = $CONF['default_language']; - if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) - { - $lang_array = preg_split ('/(\s*,\s*)/', $_SERVER['HTTP_ACCEPT_LANGUAGE']); - if (safecookie('lang')) { - array_unshift($lang_array, safecookie('lang')); # prefer language from cookie - } - if ( $use_post && safepost('lang')) { - array_unshift($lang_array, safepost('lang')); # but prefer $_POST['lang'] even more - } + if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) + { + $lang_array = preg_split ('/(\s*,\s*)/', $_SERVER['HTTP_ACCEPT_LANGUAGE']); + if (safecookie('lang')) { + array_unshift($lang_array, safecookie('lang')); # prefer language from cookie + } + if ( $use_post && safepost('lang')) { + array_unshift($lang_array, safepost('lang')); # but prefer $_POST['lang'] even more + } - for($i = 0; $i < count($lang_array); $i++) - { - $lang_next = $lang_array[$i]; - $lang_next = strtolower(trim($lang_next)); - if(array_key_exists($lang_next, $supported_languages)) - { - $lang = $lang_next; - break; - } - } - } - return $lang; + for($i = 0; $i < count($lang_array); $i++) + { + $lang_next = $lang_array[$i]; + $lang_next = strtolower(trim($lang_next)); + if(array_key_exists($lang_next, $supported_languages)) + { + $lang = $lang_next; + break; + } + } + } + return $lang; } // @@ -182,22 +182,22 @@ // function language_selector() { - global $supported_languages; # from languages/languages.php + global $supported_languages; # from languages/languages.php - $current_lang = check_language(); + $current_lang = check_language(); - $selector = '<select name="lang" xml:lang="en" dir="ltr">'; + $selector = '<select name="lang" xml:lang="en" dir="ltr">'; - foreach($supported_languages as $lang => $lang_name) { - if ($lang == $current_lang) { - $selected = ' selected="selected"'; - } else { - $selected = ''; - } - $selector .= "<option value='$lang'$selected>$lang_name</option>"; - } - $selector .= "</select>"; - return $selector; + foreach($supported_languages as $lang => $lang_name) { + if ($lang == $current_lang) { + $selected = ' selected="selected"'; + } else { + $selected = ''; + } + $selector .= "<option value='$lang'$selected>$lang_name</option>"; + } + $selector .= "</select>"; + return $selector; } // @@ -207,14 +207,14 @@ // function check_string ($var) { - if (preg_match ('/^([A-Za-z0-9 ]+)+$/', $var)) - { - return true; - } - else - { - return false; - } + if (preg_match ('/^([A-Za-z0-9 ]+)+$/', $var)) + { + return true; + } + else + { + return false; + } } @@ -227,37 +227,37 @@ // TODO: make check_domain able to handle as example .local domains function check_domain ($domain) { - global $CONF; - global $PALANG; + global $CONF; + global $PALANG; - if (!preg_match ('/([-0-9A-Z]+\.)+' . '([0-9A-Z]){2,6}$/i', trim ($domain))) - { - flash_error(sprintf($PALANG['pInvalidDomainRegex'], htmlentities($domain))); - return false; - } + if (!preg_match ('/([-0-9A-Z]+\.)+' . '([0-9A-Z]){2,6}$/i', trim ($domain))) + { + flash_error(sprintf($PALANG['pInvalidDomainRegex'], htmlentities($domain))); + return false; + } - if (isset($CONF['emailcheck_resolve_domain']) && 'YES' == $CONF['emailcheck_resolve_domain'] && 'WINDOWS'!=(strtoupper(substr(php_uname('s'), 0, 7)))) - { + if (isset($CONF['emailcheck_resolve_domain']) && 'YES' == $CONF['emailcheck_resolve_domain'] && 'WINDOWS'!=(strtoupper(substr(php_uname('s'), 0, 7)))) + { - // Look for an AAAA, A, or MX record for the domain + // Look for an AAAA, A, or MX record for the domain - if(function_exists('checkdnsrr')) { - // AAAA (IPv6) is only available in PHP v. >= 5 - if (version_compare(phpversion(), "5.0.0", ">=")) - { - if (checkdnsrr($domain,'AAAA')) return true; - } - if (checkdnsrr($domain,'A')) return true; - if (checkdnsrr($domain,'MX')) return true; - flash_error(sprintf($PALANG['pInvalidDomainDNS'], htmlentities($domain))); - return false; - } - else { - flash_error("emailcheck_resolve_domain is enabled, but function (checkdnsrr) missing!"); - } - } + if(function_exists('checkdnsrr')) { + // AAAA (IPv6) is only available in PHP v. >= 5 + if (version_compare(phpversion(), "5.0.0", ">=")) + { + if (checkdnsrr($domain,'AAAA')) return true; + } + if (checkdnsrr($domain,'A')) return true; + if (checkdnsrr($domain,'MX')) return true; + flash_error(sprintf($PALANG['pInvalidDomainDNS'], htmlentities($domain))); + return false; + } + else { + flash_error("emailcheck_resolve_domain is enabled, but function (checkdnsrr) missing!"); + } + } - return true; + return true; } @@ -270,38 +270,38 @@ */ function check_email ($email) { - global $CONF; - global $PALANG; + global $CONF; + global $PALANG; - $ce_email=$email; + $ce_email=$email; - //strip the vacation domain out if we are using it - //and change from blah#fo...@au... to bl...@fo... - if ($CONF['vacation'] == 'YES') - { - $vacation_domain = $CONF['vacation_domain']; - $ce_email = preg_replace("/@$vacation_domain/", '', $ce_email); - $ce_email = preg_replace("/#/", '@', $ce_email); - } + //strip the vacation domain out if we are using it + //and change from blah#fo...@au... to bl...@fo... + if ($CONF['vacation'] == 'YES') + { + $vacation_domain = $CONF['vacation_domain']; + $ce_email = preg_replace("/@$vacation_domain/", '', $ce_email); + $ce_email = preg_replace("/#/", '@', $ce_email); + } - // Perform non-domain-part sanity checks - if (!preg_match ('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_{|}~]+' . '@' . '[^@]+$/i', trim ($ce_email))) - { - flash_error($PALANG['pInvalidMailRegex']); - return false; - } + // Perform non-domain-part sanity checks + if (!preg_match ('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_{|}~]+' . '@' . '[^@]+$/i', trim ($ce_email))) + { + flash_error($PALANG['pInvalidMailRegex']); + return false; + } - // Determine domain name - $matches=array(); - if (!preg_match('|@(.+)$|',$ce_email,$matches)) - { - flash_error($PALANG['pInvalidMailRegex']); - return false; - } - $domain=$matches[1]; + // Determine domain name + $matches=array(); + if (!preg_match('|@(.+)$|',$ce_email,$matches)) + { + flash_error($PALANG['pInvalidMailRegex']); + return false; + } + $domain=$matches[1]; - # check domain name - return check_domain($domain); + # check domain name + return check_domain($domain); } @@ -316,49 +316,49 @@ */ function escape_string ($string) { - global $CONF; - // if the string is actually an array, do a recursive cleaning. - // Note, the array keys are not cleaned. - if(is_array($string)) { - $clean = array(); - foreach(array_keys($string) as $row) { - $clean[$row] = escape_string($string[$row]); - } - return $clean; - } - if (get_magic_quotes_gpc ()) - { - $string = stripslashes($string); - } - if (!is_numeric($string)) - { - $link = db_connect(); - if ($CONF['database_type'] == "mysql") - { - $escaped_string = mysql_real_escape_string($string, $link); - } - if ($CONF['database_type'] == "mysqli") - { - $escaped_string = mysqli_real_escape_string($link, $string); - } - if ($CONF['database_type'] == "pgsql") - { - // php 5.2+ allows for $link to be specified. - if (version_compare(phpversion(), "5.2.0", ">=")) - { - $escaped_string = pg_escape_string($link, $string); - } - else - { - $escaped_string = pg_escape_string($string); - } - } - } - else - { - $escaped_string = $string; - } - return $escaped_string; + global $CONF; + // if the string is actually an array, do a recursive cleaning. + // Note, the array keys are not cleaned. + if(is_array($string)) { + $clean = array(); + foreach(array_keys($string) as $row) { + $clean[$row] = escape_string($string[$row]); + } + return $clean; + } + if (get_magic_quotes_gpc ()) + { + $string = stripslashes($string); + } + if (!is_numeric($string)) + { + $link = db_connect(); + if ($CONF['database_type'] == "mysql") + { + $escaped_string = mysql_real_escape_string($string, $link); + } + if ($CONF['database_type'] == "mysqli") + { + $escaped_string = mysqli_real_escape_string($link, $string); + } + if ($CONF['database_type'] == "pgsql") + { + // php 5.2+ allows for $link to be specified. + if (version_compare(phpversion(), "5.2.0", ">=")) + { + $escaped_string = pg_escape_string($link, $string); + } + else + { + $escaped_string = pg_escape_string($string); + } + } + } + else + { + $escaped_string = $string; + } + return $escaped_string; } @@ -374,9 +374,9 @@ * @return String */ function safeget ($param, $default="") { - $retval=$default; - if (isset($_GET[$param])) $retval=$_GET[$param]; - return $retval; + $retval=$default; + if (isset($_GET[$param])) $retval=$_GET[$param]; + return $retval; } /** @@ -388,9 +388,9 @@ * same as safeget, but for $_POST */ function safepost ($param, $default="") { - $retval=$default; - if (isset($_POST[$param])) $retval=$_POST[$param]; - return $retval; + $retval=$default; + if (isset($_POST[$param])) $retval=$_POST[$param]; + return $retval; } /** @@ -401,9 +401,9 @@ * @return String value from $_SERVER[$param] or $default */ function safeserver ($param, $default="") { - $retval=$default; - if (isset($_SERVER[$param])) $retval=$_SERVER[$param]; - return $retval; + $retval=$default; + if (isset($_SERVER[$param])) $retval=$_SERVER[$param]; + return $retval; } /** @@ -414,9 +414,9 @@ * @return String value from $_COOKIE[$param] or $default */ function safecookie ($param, $default="") { - $retval=$default; - if (isset($_COOKIE[$param])) $retval=$_COOKIE[$param]; - return $retval; + $retval=$default; + if (isset($_COOKIE[$param])) $retval=$_COOKIE[$param]; + return $retval; } @@ -427,128 +427,128 @@ // function get_domain_properties ($domain) { - global $CONF; - global $table_alias, $table_mailbox, $table_domain; - $list = array (); + global $CONF; + global $table_alias, $table_mailbox, $table_domain; + $list = array (); - $result = db_query ("SELECT COUNT(*) FROM $table_alias WHERE domain='$domain'"); - $row = db_row ($result['result']); - $list['alias_count'] = $row[0]; + $result = db_query ("SELECT COUNT(*) FROM $table_alias WHERE domain='$domain'"); + $row = db_row ($result['result']); + $list['alias_count'] = $row[0]; - $result = db_query ("SELECT COUNT(*) FROM $table_mailbox WHERE domain='$domain'"); - $row = db_row ($result['result']); - $list['mailbox_count'] = $row[0]; + $result = db_query ("SELECT COUNT(*) FROM $table_mailbox WHERE domain='$domain'"); + $row = db_row ($result['result']); + $list['mailbox_count'] = $row[0]; - $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['mailbox_count']; + $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['mailbox_count']; - $list['alias_pgindex']=array (); - $list['mbox_pgindex']=array (); - $list['mbox_pgindex_count'] = 0; - //while loop to figure index names. use page_size and loop of queries - $i=0; - $current=0; - $page_size = $CONF['page_size']; - $tmpstr=""; - $idxlabel=""; - $list['alias_pgindex_count'] = 0; + $list['alias_pgindex']=array (); + $list['mbox_pgindex']=array (); + $list['mbox_pgindex_count'] = 0; + //while loop to figure index names. use page_size and loop of queries + $i=0; + $current=0; + $page_size = $CONF['page_size']; + $tmpstr=""; + $idxlabel=""; + $list['alias_pgindex_count'] = 0; - if ( $list['alias_count'] > $page_size ) - { - while ( $current < $list['alias_count'] ) - { - $limitSql=('pgsql'==$CONF['database_type']) ? "1 OFFSET $current" : "$current, 1"; - $query = "SELECT $table_alias.address 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 ORDER BY $table_alias.address LIMIT $limitSql"; - $result = db_query ("$query"); - $row = db_array ($result['result']); - $tmpstr = $row['address']; - //get first 2 chars - $idxlabel = $tmpstr[0] . $tmpstr[1] . "-"; - ($current + $page_size - 1 <= $list['alias_count']) ? $current = $current + $page_size - 1 : $current = $list['alias_count'] - 1; - $limitSql=('pgsql'==$CONF['database_type']) ? "1 OFFSET $current" : "$current, 1"; - $query = "SELECT $table_alias.address 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 ORDER BY $table_alias.address LIMIT $limitSql"; - $result = db_query ("$query"); - $row = db_array ($result['result']); - $tmpstr = $row['address']; - $idxlabel = $idxlabel . $tmpstr[0] . $tmpstr[1]; + if ( $list['alias_count'] > $page_size ) + { + while ( $current < $list['alias_count'] ) + { + $limitSql=('pgsql'==$CONF['database_type']) ? "1 OFFSET $current" : "$current, 1"; + $query = "SELECT $table_alias.address 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 ORDER BY $table_alias.address LIMIT $limitSql"; + $result = db_query ("$query"); + $row = db_array ($result['result']); + $tmpstr = $row['address']; + //get first 2 chars + $idxlabel = $tmpstr[0] . $tmpstr[1] . "-"; + ($current + $page_size - 1 <= $list['alias_count']) ? $current = $current + $page_size - 1 : $current = $list['alias_count'] - 1; + $limitSql=('pgsql'==$CONF['database_type']) ? "1 OFFSET $current" : "$current, 1"; + $query = "SELECT $table_alias.address 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 ORDER BY $table_alias.address LIMIT $limitSql"; + $result = db_query ("$query"); + $row = db_array ($result['result']); + $tmpstr = $row['address']; + $idxlabel = $idxlabel . $tmpstr[0] . $tmpstr[1]; - $current = $current + 1; + $current = $current + 1; - $list['alias_pgindex'][]=$idxlabel; - $i++; - } - $list['alias_pgindex_count']=$i; - } + $list['alias_pgindex'][]=$idxlabel; + $i++; + } + $list['alias_pgindex_count']=$i; + } - $i=0; - $current=0; - $page_size = $CONF['page_size']; - $tmpstr=""; - $idxlabel=""; + $i=0; + $current=0; + $page_size = $CONF['page_size']; + $tmpstr=""; + $idxlabel=""; - if ( $list['mailbox_count'] > $page_size ) - { - while ( $current < $list['mailbox_count'] ) - { - $limitSql=('pgsql'==$CONF['database_type']) ? "1 OFFSET $current" : "$current, 1"; - $query = "SELECT $table_mailbox.username FROM $table_mailbox WHERE $table_mailbox.domain='$domain' ORDER BY $table_mailbox.username LIMIT $limitSql"; - $result = db_query ("$query"); - $row = db_array ($result['result']); - $tmpstr = $row['username']; - //get first 2 chars - $idxlabel = $tmpstr[0] . $tmpstr[1] . "-"; - ($current + $page_size - 1 <= $list['mailbox_count']) ? $current = $current + $page_size - 1 : $current = $list['mailbox_count'] - 1; - $limitSql=('pgsql'==$CONF['database_type']) ? "1 OFFSET $current" : "$current, 1"; - $query = "SELECT $table_mailbox.username FROM $table_mailbox WHERE $table_mailbox.domain='$domain' ORDER BY $table_mailbox.username LIMIT $limitSql"; - $result = db_query ("$query"); - $row = db_array ($result['result']); - $tmpstr = $row['username']; - $idxlabel = $idxlabel . $tmpstr[0] . $tmpstr[1]; + if ( $list['mailbox_count'] > $page_size ) + { + while ( $current < $list['mailbox_count'] ) + { + $limitSql=('pgsql'==$CONF['database_type']) ? "1 OFFSET $current" : "$current, 1"; + $query = "SELECT $table_mailbox.username FROM $table_mailbox WHERE $table_mailbox.domain='$domain' ORDER BY $table_mailbox.username LIMIT $limitSql"; + $result = db_query ("$query"); + $row = db_array ($result['result']); + $tmpstr = $row['username']; + //get first 2 chars + $idxlabel = $tmpstr[0] . $tmpstr[1] . "-"; + ($current + $page_size - 1 <= $list['mailbox_count']) ? $current = $current + $page_size - 1 : $current = $list['mailbox_count'] - 1; + $limitSql=('pgsql'==$CONF['database_type']) ? "1 OFFSET $current" : "$current, 1"; + $query = "SELECT $table_mailbox.username FROM $table_mailbox WHERE $table_mailbox.domain='$domain' ORDER BY $table_mailbox.username LIMIT $limitSql"; + $result = db_query ("$query"); + $row = db_array ($result['result']); + $tmpstr = $row['username']; + $idxlabel = $idxlabel . $tmpstr[0] . $tmpstr[1]; - $current = $current + 1; + $current = $current + 1; - $list['mbox_pgindex'][]=$idxlabel; - $i++; - } - $list['mbox_pgindex_count']=$i; - } + $list['mbox_pgindex'][]=$idxlabel; + $i++; + } + $list['mbox_pgindex_count']=$i; + } - // end mod + // end mod - $query="SELECT * FROM $table_domain WHERE domain='$domain'"; - if ('pgsql'==$CONF['database_type']) - { - $query=" 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); - $row = db_array ($result['result']); - $list['description'] = $row['description']; - $list['aliases'] = $row['aliases']; - $list['mailboxes'] = $row['mailboxes']; - $list['maxquota'] = $row['maxquota']; - $list['quota'] = $row['quota']; - $list['transport'] = $row['transport']; - $list['backupmx'] = $row['backupmx']; - $list['created'] = $row['created']; - $list['modified'] = $row['modified']; - $list['active'] = $row['active']; + $query="SELECT * FROM $table_domain WHERE domain='$domain'"; + if ('pgsql'==$CONF['database_type']) + { + $query=" 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); + $row = db_array ($result['result']); + $list['description'] = $row['description']; + $list['aliases'] = $row['aliases']; + $list['mailboxes'] = $row['mailboxes']; + $list['maxquota'] = $row['maxquota']; + $list['quota'] = $row['quota']; + $list['transport'] = $row['transport']; + $list['backupmx'] = $row['backupmx']; + $list['created'] = $row['created']; + $list['modified'] = $row['modified']; + $list['active'] = $row['active']; - if ($CONF['database_type'] == "pgsql") - { - $list['active']=('t'==$row['active']) ? 1 : 0; - $list['backupmx']=('t'==$row['backupmx']) ? 1 : 0; - $list['created']= gmstrftime('%c %Z',$row['uts_created']); - $list['modified']= gmstrftime('%c %Z',$row['uts_modified']); - } - else - { - $list['active'] = $row['active']; - $list['backupmx'] = $row['backupmx']; - } + if ($CONF['database_type'] == "pgsql") + { + $list['active']=('t'==$row['active']) ? 1 : 0; + $list['backupmx']=('t'==$row['backupmx']) ? 1 : 0; + $list['created']= gmstrftime('%c %Z',$row['uts_created']); + $list['modified']= gmstrftime('%c %Z',$row['uts_modified']); + } + else + { + $list['active'] = $row['active']; + $list['backupmx'] = $row['backupmx']; + } - return $list; + return $list; } @@ -560,42 +560,42 @@ // function get_mailbox_properties ($username) { - global $CONF; - global $table_mailbox; - $query="SELECT * FROM $table_mailbox WHERE username='$username'"; - if ('pgsql'==$CONF['database_type']) - { - $query=" - SELECT - *, - EXTRACT(epoch FROM created) AS uts_created, - EXTRACT(epoch FROM modified) AS uts_modified - FROM $table_mailbox - WHERE username='$username' - "; - } - $result = db_query ($query); - $row = db_array ($result['result']); - $list['name'] = $row['name']; - $list['maildir'] = $row['maildir']; - $list['quota'] = $row['quota']; - $list['domain'] = $row['domain']; - $list['created'] = $row['created']; - $list['modified'] = $row['modified']; - $list['active'] = $row['active']; + global $CONF; + global $table_mailbox; + $query="SELECT * FROM $table_mailbox WHERE username='$username'"; + if ('pgsql'==$CONF['database_type']) + { + $query=" + SELECT + *, + EXTRACT(epoch FROM created) AS uts_created, + EXTRACT(epoch FROM modified) AS uts_modified + FROM $table_mailbox + WHERE username='$username' + "; + } + $result = db_query ($query); + $row = db_array ($result['result']); + $list['name'] = $row['name']; + $list['maildir'] = $row['maildir']; + $list['quota'] = $row['quota']; + $list['domain'] = $row['domain']; + $list['created'] = $row['created']; + $list['modified'] = $row['modified']; + $list['active'] = $row['active']; - if ($CONF['database_type'] == "pgsql") - { - $list['active']=('t'==$row['active']) ? 1 : 0; - $list['created']= gmstrftime('%c %Z',$row['uts_created']); - $list['modified']= gmstrftime('%c %Z',$row['uts_modified']); - } - else - { - $list['active'] = $row['active']; - } + if ($CONF['database_type'] == "pgsql") + { + $list['active']=('t'==$row['active']) ? 1 : 0; + $list['created']= gmstrftime('%c %Z',$row['uts_created']); + $list['modified']= gmstrftime('%c %Z',$row['uts_modified']); + } + else + { + $list['active'] = $row['active']; + } - return $list; + return $list; } @@ -607,24 +607,24 @@ // function check_alias ($domain) { - $limit = get_domain_properties ($domain); - if ($limit['aliases'] == 0) - { - # 0 = unlimited, -1 = disabled - return true; - } - if ($limit['aliases'] < 0) - { - return false; - } - if ($limit['alias_count'] >= $limit['aliases']) - { - return false; - } - else - { - return true; - } + $limit = get_domain_properties ($domain); + if ($limit['aliases'] == 0) + { + # 0 = unlimited, -1 = disabled + return true; + } + if ($limit['aliases'] < 0) + { + return false; + } + if ($limit['alias_count'] >= $limit['aliases']) + { + return false; + } + else + { + return true; + } } @@ -636,24 +636,24 @@ // function check_mailbox ($domain) { - $limit = get_domain_properties ($domain); - /* -1 = disable, 0 = unlimited */ - if ($limit['mailboxes'] == 0) - { - return true; - } - if ($limit['mailboxes'] < 0) - { - return false; - } - if ($limit['mailbox_count'] >= $limit['mailboxes']) - { - return false; - } - else - { - return true; - } + $limit = get_domain_properties ($domain); + /* -1 = disable, 0 = unlimited */ + if ($limit['mailboxes'] == 0) + { + return true; + } + if ($limit['mailboxes'] < 0) + { + return false; + } + if ($limit['mailbox_count'] >= $limit['mailboxes']) + { + return false; + } + else + { + return true; + } } @@ -665,27 +665,27 @@ // function check_quota ($quota, $domain) { - $limit = get_domain_properties ($domain); - if ($limit['maxquota'] == 0) - { - return true; - } - if (($limit['maxquota'] < 0) and ($quota < 0)) - { - return true; - } - if (($limit['maxquota'] > 0) and ($quota == 0)) - { - return false; - } - if ($quota > $limit['maxquota']) - { - return false; - } - else - { - return true; - } + $limit = get_domain_properties ($domain); + if ($limit['maxquota'] == 0) + { + return true; + } + if (($limit['maxquota'] < 0) and ($quota < 0)) + { + return true; + } + if (($limit['maxquota'] > 0) and ($quota == 0)) + { + return false; + } + if ($quota > $limit['maxquota']) + { + return false; + } + else + { + return true; + } } @@ -697,10 +697,10 @@ // function multiply_quota ($quota) { - global $CONF; - if ($quota == -1) return $quota; - $value = $quota * $CONF['quota_multiplier']; - return $value; + global $CONF; + if ($quota == -1) return $quota; + $value = $quota * $CONF['quota_multiplier']; + return $value; } @@ -712,10 +712,10 @@ // function divide_quota ($quota) { - global $CONF; - if ($quota == -1) return $quota; - $value = round($quota / $CONF['quota_multiplier'],2); - return $value; + global $CONF; + if ($quota == -1) return $quota; + $value = round($quota / $CONF['quota_multiplier'],2); + return $value; } @@ -727,16 +727,16 @@ // function check_owner ($username, $domain) { - global $table_domain_admins; - $result = db_query ("SELECT 1 FROM $table_domain_admins WHERE username='$username' AND (domain='$domain' OR domain='ALL') AND active='1'"); - if ($result['rows'] != 1) - { - return false; - } - else - { - return true; - } + global $table_domain_admins; + $result = db_query ("SELECT 1 FROM $table_domain_admins WHERE username='$username' AND (domain='$domain' OR domain='ALL') AND active='1'"); + if ($result['rows'] != 1) + { + return false; + } + else + { + return true; + } } @@ -748,17 +748,17 @@ // function check_alias_owner ($username, $alias) { - global $CONF; - if (authentication_has_role('global-admin')) return true; - $tmp = preg_split('/\@/', $alias); - if (($CONF['special_alias_control'] == 'NO') && array_key_exists($tmp[0], $CONF['default_aliases'])) - { - return false; - } - else - { - return true; - } + global $CONF; + if (authentication_has_role('global-admin')) return true; + $tmp = preg_split('/\@/', $alias); + if (($CONF['special_alias_control'] == 'NO') && array_key_exists($tmp[0], $CONF['default_aliases'])) + { + return false; + } + else + { + return true; + } } @@ -769,30 +769,30 @@ */ function list_domains_for_admin ($username) { - global $CONF; - global $table_domain, $table_domain_admins; - $list = array (); - // does $username need escaping here? - $active_sql = db_get_boolean(True); - $backupmx_sql = db_get_boolean(False); - $query = "SELECT $table_domain.domain, $table_domain_admins.username FROM $table_domain - LEFT JOIN $table_domain_admins ON $table_domain.domain=$table_domain_admins.domain - WHERE $table_domain_admins.username='$username' - AND $table_domain.active=$active_sql - AND $table_domain.backupmx=$backupmx_sql - ORDER BY $table_domain_admins.domain"; + global $CONF; + global $table_domain, $table_domain_admins; + $list = array (); + // does $username need escaping here? + $active_sql = db_get_boolean(True); + $backupmx_sql = db_get_boolean(False); + $query = "SELECT $table_domain.domain, $table_domain_admins.username FROM $table_domain + LEFT JOIN $table_domain_admins ON $table_domain.domain=$table_domain_admins.domain + WHERE $table_domain_admins.username='$username' + AND $table_domain.active=$active_sql + AND $table_domain.backupmx=$backupmx_sql + ORDER BY $table_domain_admins.domain"; - $result = db_query ($query); - if ($result['rows'] > 0) - { - $i = 0; - while ($row = db_array ($result['result'])) - { - $list[$i] = $row['domain']; - $i++; - } - } - return $list; + $result = db_query ($query); + if ($result['rows'] > 0) + { + $i = 0; + while ($row = db_array ($result['result'])) + { + $list[$i] = $row['domain']; + $i++; + } + } + return $list; } @@ -804,20 +804,20 @@ // function list_domains () { - global $table_domain; - $list = array(); + global $table_domain; + $list = array(); - $result = db_query ("SELECT domain FROM $table_domain WHERE domain!='ALL' ORDER BY domain"); - if ($result['rows'] > 0) - { - $i = 0; - while ($row = db_array ($result['result'])) - { - $list[$i] = $row['domain']; - $i++; - } - } - return $list; + $result = db_query ("SELECT domain FROM $table_domain WHERE domain!='ALL' ORDER BY domain"); + if ($result['rows'] > 0) + { + $i = 0; + while ($row = db_array ($result['result'])) + { + $list[$i] = $row['domain']; + $i++; + } + } + return $list; } @@ -830,15 +830,15 @@ // function admin_exist ($username) { - $result = db_query ("SELECT 1 FROM " . table_by_key ('admin') . " WHERE username='$username'"); - if ($result['rows'] != 1) - { - return false; - } - else - { - return true; - } + $result = db_query ("SELECT 1 FROM " . table_by_key ('admin') . " WHERE username='$username'"); + if ($result['rows'] != 1) + { + return false; + } + else + { + return true; + } } @@ -850,17 +850,17 @@ // function domain_exist ($domain) { - global $table_domain; + global $table_domain; - $result = db_query("SELECT 1 FROM $table_domain WHERE domain='$domain'"); - if ($result['rows'] != 1) - { - return false; - } - else - { - return true; - } + $result = db_query("SELECT 1 FROM $table_domain WHERE domain='$domain'"); + if ($result['rows'] != 1) + { + return false; + } + else + { + return true; + } } @@ -874,20 +874,20 @@ // function list_admins () { - global $table_admin; - $list = ""; + global $table_admin; + $list = ""; - $result = db_query ("SELECT username FROM $table_admin ORDER BY username"); - if ($result['rows'] > 0) - { - $i = 0; - while ($row = db_array ($result['result'])) - { - $list[$i] = $row['username']; - $i++; - } - } - return $list; + $result = db_query ("SELECT username FROM $table_admin ORDER BY username"); + if ($result['rows'] > 0) + { + $i = 0; + while ($row = db_array ($result['result'])) + { + $list[$i] = $row['username']; + $i++; + } + } + return $list; } @@ -899,45 +899,45 @@ // function get_admin_properties ($username) { - global $CONF; - global $table_admin, $table_domain_admins; - $list = array (); + global $CONF; + global $table_admin, $table_domain_admins; + $list = array (); - $result = db_query ("SELECT * FROM $table_domain_admins WHERE username='$username' AND domain='ALL'"); - if ($result['rows'] == 1) - { - $list['domain_count'] = 'ALL'; - } - else - { - $result = db_query ("SELECT COUNT(*) FROM $table_domain_admins WHERE username='$username'"); - $row = db_row ($result['result']); - $list['domain_count'] = $row[0]; - } + $result = db_query ("SELECT * FROM $table_domain_admins WHERE username='$username' AND domain='ALL'"); + if ($result['rows'] == 1) + { + $list['domain_count'] = 'ALL'; + } + else + { + $result = db_query ("SELECT COUNT(*) FROM $table_domain_admins WHERE username='$username'"); + $row = db_row ($result['result']); + $list['domain_count'] = $row[0]; + } - $query = "SELECT * FROM $table_admin WHERE username='$username'"; - if ('pgsql'==$CONF['database_type']) { - $query=" - SELECT - *, - EXTRACT(epoch FROM created) AS uts_created, - EXTRACT (epoch FROM modified) AS uts_modified - FROM $table_admin - WHERE username='$username' - "; - } + $query = "SELECT * FROM $table_admin WHERE username='$username'"; + if ('pgsql'==$CONF['database_type']) { + $query=" + SELECT + *, + EXTRACT(epoch FROM created) AS uts_created, + EXTRACT (epoch FROM modified) AS uts_modified + FROM $table_admin + WHERE username='$username' + "; + } - $result = db_query ($query); - $row = db_array ($result['result']); - $list['created'] = $row['created']; - $list['modified'] = $row['modified']; - $list['active'] = $row['active']; - if ('pgsql'==$CONF['database_type']) { - $list['active'] = ('t'==$row['active']) ? 1 : 0; - $list['created']= gmstrftime('%c %Z',$row['uts_created']); - $list['modified']= gmstrftime('%c %Z',$row['uts_modified']); - } - return $list; + $result = db_query ($query); + $row = db_array ($result['result']); + $list['created'] = $row['created']; + $list['modified'] = $row['modified']; + $list['active'] = $row['active']; + if ('pgsql'==$CONF['database_type']) { + $list['active'] = ('t'==$row['active']) ? 1 : 0; + $list['created']= gmstrftime('%c %Z',$row['uts_created']); + $list['modified']= gmstrftime('%c %Z',$row['uts_modified']); + } + return $list; } @@ -949,143 +949,143 @@ // function encode_header ($string, $default_charset = "utf-8") { - if (strtolower ($default_charset) == 'iso-8859-1') - { - $string = str_replace ("\240",' ',$string); - } + if (strtolower ($default_charset) == 'iso-8859-1') + { + $string = str_replace ("\240",' ',$string); + } - $j = strlen ($string); - $max_l = 75 - strlen ($default_charset) - 7; - $aRet = array (); - $ret = ''; - $iEncStart = $enc_init = false; - $cur_l = $iOffset = 0; + $j = strlen ($string); + $max_l = 75 - strlen ($default_charset) - 7; + $aRet = array (); + $ret = ''; + $iEncStart = $enc_init = false; + $cur_l = $iOffset = 0; - for ($i = 0; $i < $j; ++$i) - { - switch ($string{$i}) - { - case '=': - case '<': - case '>': - case ',': - case '?': - case '_': - if ($iEncStart === false) - { - $iEncStart = $i; - } - $cur_l+=3; - if ($cur_l > ($max_l-2)) - { - $aRet[] = substr ($string,$iOffset,$iEncStart-$iOffset); - $aRet[] = "=?$default_charset?Q?$ret?="; - $iOffset = $i; - $cur_l = 0; - $ret = ''; - $iEncStart = false; - } - else - { - $ret .= sprintf ("=%02X",ord($string{$i})); - } - break; - case '(': - case ')': - if ($iEncStart !== false) - { - $aRet[] = substr ($string,$iOffset,$iEncStart-$iOffset); - $aRet[] = "=?$default_charset?Q?$ret?="; - $iOffset = $i; - $cur_l = 0; - $ret = ''; - $iEncStart = false; - } - break; - case ' ': - if ($iEncStart !== false) - { - $cur_l++; - if ($cur_l > $max_l) + for ($i = 0; $i < $j; ++$i) + { + switch ($string{$i}) + { + case '=': + case '<': + case '>': + case ',': + case '?': + case '_': + if ($iEncStart === false) { - $aRet[] = substr ($string,$iOffset,$iEncStart-$iOffset); - $aRet[] = "=?$default_charset?Q?$ret?="; - $iOffset = $i; - $cur_l = 0; - $ret = ''; - $iEncStart = false; + $iEncStart = $i; } - else + $cur_l+=3; + if ($cur_l > ($max_l-2)) { - $ret .= '_'; + $aRet[] = substr ($string,$iOffset,$iEncStart-$iOffset); + $aRet[] = "=?$default_charset?Q?$ret?="; + $iOffset = $i; + $cur_l = 0; + $ret = ''; + $iEncStart = false; } - } - break; - default: - $k = ord ($string{$i}); - if ($k > 126) - { - if ($iEncStart === false) + else { - // do not start encoding in the middle of a string, also take the rest of the word. - $sLeadString = substr ($string,0,$i); - $aLeadString = explode (' ',$sLeadString); - $sToBeEncoded = array_pop ($aLeadString); - $iEncStart = $i - strlen ($sToBeEncoded); - $ret .= $sToBeEncoded; - $cur_l += strlen ($sToBeEncoded); + $ret .= sprintf ("=%02X",ord($string{$i})); } - $cur_l += 3; - // first we add the encoded string that reached it's max size - if ($cur_l > ($max_l-2)) + break; + case '(': + case ')': + if ($iEncStart !== false) { - $aRet[] = substr ($string,$iOffset,$iEncStart-$iOffset); - $aRet[] = "=?$default_charset?Q?$ret?= "; - $cur_l = 3; - $ret = ''; - $iOffset = $i; - $iEncStart = $i; + $aRet[] = substr ($string,$iOffset,$iEncStart-$iOffset); + $aRet[] = "=?$default_charset?Q?$ret?="; + $iOffset = $i; + $cur_l = 0; + $ret = ''; + $iEncStart = false; } - $enc_init = true; - $ret .= sprintf ("=%02X", $k); - } - else - { + break; + case ' ': if ($iEncStart !== false) { - $cur_l++; - if ($cur_l > $max_l) - { - $aRet[] = substr ($string,$iOffset,$iEncStart-$iOffset); - $aRet[] = "=?$default_charset?Q?$ret?="; - $iEncStart = false; - $iOffset = $i; - $cur_l = 0; - $ret = ''; - } - else - { - $ret .= $string{$i}; - } + $cur_l++; + if ($cur_l > $max_l) + { + $aRet[] = substr ($string,$iOffset,$iEncStart-$iOffset); + $aRet[] = "=?$default_charset?Q?$ret?="; + $iOffset = $i; + $cur_l = 0; + $ret = ''; + $iEncStart = false; + } + else + { + $ret .= '_'; + } } - } - break; - } - } - if ($enc_init) - { - if ($iEncStart !== false) - { - $aRet[] = substr ($string,$iOffset,$iEncStart-$iOffset); - $aRet[] = "=?$default_charset?Q?$ret?="; - } - else - { - $aRet[] = substr ($string,$iOffset); - } - $string = implode ('',$aRet); - } - return $string; + break; + default: + $k = ord ($string{$i}); + if ($k > 126) + { + if ($iEncStart === false) + { + // do not start encoding in the middle of a string, also take the rest of the word. + $sLeadString = substr ($string,0,$i); + $aLeadString = explode (' ',$sLeadString); + $sToBeEncoded = array_pop ($aLeadString); + $iEncStart = $i - strlen ($sToBeEncoded); + $ret .= $sToBeEncoded; + $cur_l += strlen ($sToBeEncoded); + } + $cur_l += 3; + // first we add the encoded string that reached it's max size + if ($cur_l > ($max_l-2)) + { + $aRet[] = substr ($string,$iOffset,$iEncStart-$iOffset); + $aRet[] = "=?$default_charset?Q?$ret?= "; + $cur_l = 3; + $ret = ''; + $iOffset = $i; + $iEncStart = $i; + } + $enc_init = true; + $ret .= sprintf ("=%02X", $k); + } + else + { + if ($iEncStart !== false) + { + $cur_l++; + if ($cur_l > $max_l) + { + $aRet[] = substr ($string,$iOffset,$iEncStart-$iOffset); + $aRet[] = "=?$default_charset?Q?$ret?="; + $iEncStart = false; + $iOffset = $i; + $cur_l = 0; + $ret = ''; + } + else + { + $ret .= $string{$i}; + } + } + } + break; + } + } + if ($enc_init) + { + if ($iEncStart !== false) + { + $aRet[] = substr ($string,$iOffset,$iEncStart-$iOffset); + $aRet[] = "=?$default_charset?Q?$ret?="; + } + else + { + $aRet[] = substr ($string,$iOffset); + } + $string = implode ('',$aRet); + } + return $string; } @@ -1097,8 +1097,8 @@ // function generate_password () { - $password = substr (md5 (mt_rand ()), 0, 8); - return $password; + $password = substr (md5 (mt_rand ()), 0, 8); + return $password; } @@ -1110,44 +1110,44 @@ // function pacrypt ($pw, $pw_db="") { - global $CONF; - $pw = stripslashes($pw); - $password = ""; - $salt = ""; + global $CONF; + $pw = stripslashes($pw); + $password = ""; + $salt = ""; - if ($CONF['encrypt'] == 'md5crypt') { - $split_salt = preg_split ('/\$/', $pw_db); - if (isset ($split_salt[2])) { - $salt = $split_salt[2]; - } - $password = md5crypt ($pw, $salt); - } + if ($CONF['encrypt'] == 'md5crypt') { + $split_salt = preg_split ('/\$/', $pw_db); + if (isset ($split_salt[2])) { + $salt = $split_salt[2]; + } + $password = md5crypt ($pw, $salt); + } - if ($CONF['encrypt'] == 'md5') { - $password = md5($pw); - } + if ($CONF['encrypt'] == 'md5') { + $password = md5($pw); + } - if ($CONF['encrypt'] == 'system') { - if (ereg ("\$1\$", $pw_db)) { - $split_salt = preg_split ('/\$/', $pw_db); - $salt = $split_salt[2]; - } - else { - if (strlen($pw_db) == 0) { - $salt = substr (md5 (mt_rand ()), 0, 2); - } - else { - $salt = substr ($pw_db, 0, 2); - } - } - $password = crypt ($pw, $salt); - } + if ($CONF['encrypt'] == 'system') { + if (ereg ("\$1\$", $pw_db)) { + $split_salt = preg_split ('/\$/', $pw_db); + $salt = $split_salt[2]; + } + else { + if (strlen($pw_db) == 0) { + $salt = substr (md5 (mt_rand ()), 0, 2); + } + else { + $salt = substr ($pw_db, 0, 2); + } + } + $password = crypt ($pw, $salt); + } - if ($CONF['encrypt'] == 'cleartext') { - $password = $pw; - } - $password = escape_string ($password); - return $password; + if ($CONF['encrypt'] == 'cleartext') { + $password = $pw; + } + $password = escape_string ($password); + return $password; } // @@ -1158,101 +1158,101 @@ function md5crypt ($pw, $salt="", $magic="") { - $MAGIC = "$1$"; + $MAGIC = "$1$"; - if ($magic == "") $magic = $MAGIC; - if ($salt == "") $salt = create_salt (); - $slist = explode ("$", $salt); - if ($slist[0] == "1") $salt = $slist[1]; + if ($magic == "") $magic = $MAGIC; + if ($salt == "") $salt = create_salt (); + $slist = explode ("$", $salt); + if ($slist[0] == "1") $salt = $slist[1]; - $salt = substr ($salt, 0, 8); - $ctx = $pw . $magic . $salt; - $final = hex2bin (md5 ($pw . $salt . $pw)); + $salt = substr ($salt, 0, 8); + $ctx = $pw . $magic . $salt; + $final = hex2bin (md5 ($pw . $salt . $pw)); - for ($i=strlen ($pw); $i>0; $i-=16) - { - if ($i > 16) - { - $ctx .= substr ($final,0,16); - } - else - { - $ctx .= substr ($final,0,$i); - } - } - $i = strlen ($pw); + for ($i=strlen ($pw); $i>0; $i-=16) + { + if ($i > 16) + { + $ctx .= substr ($final,0,16); + } + else + { + $ctx .= substr ($final,0,$i); + } + } + $i = strlen ($pw); - while ($i > 0) - { - if ($i & 1) $ctx .= chr (0); - else $ctx .= $pw[0]; - $i = $i >> 1; - } - $final = hex2bin (md5 ($ctx)); + while ($i > 0) + { + if ($i & 1) $ctx .= chr (0); + else $ctx .= $pw[0]; + $i = $i >> 1; + } + $final = hex2bin (md5 ($ctx)); - for ($i=0;$i<1000;$i++) - { - $ctx1 = ""; - if ($i & 1) - { - $ctx1 .= $pw; - } - else - { - $ctx1 .= substr ($final,0,16); - } - if ($i % 3) $ctx1 .= $salt; - if ($i % 7) $ctx1 .= $pw; - if ($i & 1) - { - $ctx1 .= substr ($final,0,16); - } - else - { - $ctx1 .= $pw; - } - $final = hex2bin (md5 ($ctx1)); - } - $passwd = ""; - $passwd .= to64 (((ord ($final[0]) << 16) | (ord ($final[6]) << 8) | (ord ($final[12]))), 4); - $passwd .= to64 (((ord ($final[1]) << 16) | (ord ($final[7]) << 8) | (ord ($final[13]))), 4); - $passwd .= to64 (((ord ($final[2]) << 16) | (ord ($final[8]) << 8) | (ord ($final[14]))), 4); - $passwd .= to64 (((ord ($final[3]) << 16) | (ord ($final[9]) << 8) | (ord ($final[15]))), 4); - $passwd .= to64 (((ord ($final[4]) << 16) | (ord ($final[10]) << 8) | (ord ($final[5]))), 4); - $passwd .= to64 (ord ($final[11]), 2); - return "$magic$salt\$$passwd"; + for ($i=0;$i<1000;$i++) + { + $ctx1 = ""; + if ($i & 1) + { + $ctx1 .= $pw; + } + else + { + $ctx1 .= substr ($final,0,16); + } + if ($i % 3) $ctx1 .= $salt; + if ($i % 7) $ctx1 .= $pw; + if ($i & 1) + { + $ctx1 .= substr ($final,0,16); + } + else + { + $ctx1 .= $pw; + } + $final = hex2bin (md5 ($ctx1)); + } + $passwd = ""; + $passwd .= to64 (((ord ($final[0]) << 16) | (ord ($final[6]) << 8) | (ord ($final[12]))), 4); + $passwd .= to64 (((ord ($final[1]) << 16) | (ord ($final[7]) << 8) | (ord ($final[13]))), 4); + $passwd .= to64 (((ord ($final[2]) << 16) | (ord ($final[8]) << 8) | (ord ($final[14]))), 4); + $passwd .= to64 (((ord ($final[3]) << 16) | (ord ($final[9]) << 8) | (ord ($final[15]))), 4); + $passwd .= to64 (((ord ($final[4]) << 16) | (ord ($final[10]) << 8) | (ord ($final[5]))), 4); + $passwd .= to64 (ord ($final[11]), 2); + return "$magic$salt\$$passwd"; } function create_salt () { - srand ((double) microtime ()*1000000); - $salt = substr (md5 (rand (0,9999999)), 0, 8); - return $salt; + srand ((double) microtime ()*1000000); + $salt = substr (md5 (rand (0,9999999)), 0, 8); + return $salt; } function hex2bin ($str) { - $len = strlen ($str); - $nstr = ""; - for ($i=0;$i<$len;$i+=2) - { - $num = sscanf (substr ($str,$i,2), "%x"); - $nstr.=chr ($num[0]); - } - return $nstr; + $len = strlen ($str); + $nstr = ""; + for ($i=0;$i<$len;$i+=2) + { + $num = sscanf (substr ($str,$i,2), "%x"); + $nstr.=chr ($num[0]); + } + return $nstr; } function to64 ($v, $n) { - $ITOA64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - $ret = ""; - while (($n - 1) >= 0) - { - $n--; - $ret .= $ITOA64[$v & 0x3f]; - $v = $v >> 6; - } - return $ret; + $ITOA64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + $ret = ""; + while (($n - 1) >= 0) + { + $n--; + $ret .= $ITOA64[$v & 0x3f]; + $v = $v >> 6; + } + return $ret; } @@ -1264,37 +1264,37 @@ // function smtp_mail ($to, $from, $data) { - global $CONF; - $smtpd_server = $CONF['smtp_server']; - $smtpd_port = $CONF['smtp_port']; - $smtp_server = $_SERVER["SERVER_NAME"]; - $errno = "0"; - $errstr = "0"; - $timeout = "30"; + global $CONF; + $smtpd_server = $CONF['smtp_server']; + $smtpd_port = $CONF['smtp_port']; + $smtp_server = $_SERVER["SERVER_NAME"]; + $errno = "0"; + $errstr = "0"; + $timeout = "30"; - $fh = @fsockopen ($smtpd_server, $smtpd_port, $errno, $errstr, $timeout); + $fh = @fsockopen ($smtpd_server, $smtpd_port, $errno, $errstr, $timeout); - if (!$fh) - { - return false; - } - else - { - fputs ($fh, "EHLO $smtp_server\r\n"); - $res = smtp_get_response($fh); - fputs ($fh, "MAIL FROM:<$from>\r\n"); - $res = smtp_get_response($fh); - fputs ($fh, "RCPT TO:<$to>\r\n"); - $res = smtp_get_response($fh); - fputs ($fh, "DATA\r\n"); - $res = smtp_get_response($fh); - fputs ($fh, "$data\r\n.\r\n"); - $res = smtp_get_response($fh); - fputs ($fh, "QUIT\r\n"); - $res = smtp_get_response($fh); - fclose ($fh); - } - return true; + if (!$fh) + { + return false; + } + else + { + fputs ($fh, "EHLO $smtp_server\r\n"); + $res = smtp_get_response($fh); + fputs ($fh, "MAIL FROM:<$from>\r\n"); + $res = smtp_get_response($fh); + fputs ($fh, "RCPT TO:<$to>\r\n"); + $res = smtp_get_response($fh); + fputs ($fh, "DATA\r\n"); + $res = smtp_get_response($fh); + fputs ($fh, "$data\r\n.\r\n"); + $res = smtp_get_response($fh); + fputs ($fh, "QUIT\r\n"); + $res = smtp_get_response($fh); + fclose ($fh); + } + return true; } @@ -1306,11 +1306,11 @@ // function smtp_get_response ($fh) { - $res =''; - do + $res =''; + do { - $line = fgets($fh, 256); - $res .= $line; + $line = fgets($fh, 256); + $res .= $line; } while (preg_match("/^\d\d\d\-/", $line)); return $res; @@ -1319,12 +1319,12 @@ $DEBUG_TEXT = "\n - <p />\n - Please check the documentation and website for more information.\n - <p />\n - <a href=\"http://postfixadmin.sf.net/\">Postfix Admin</a><br />\n - <a href='https://sourceforge.net/forum/forum.php?forum_id=676076'>Forums</a> - "; + <p />\n + Please check the documentation and website for more information.\n + <p />\n + <a href=\"http://postfixadmin.sf.net/\">Postfix Admin</a><br />\n + <a href='https://sourceforge.net/forum/forum.php?forum_id=676076'>Forums</a> + "; /** @@ -1342,84 +1342,84 @@ */ function db_connect ($ignore_errors = 0) { - global $CONF; - global $DEBUG_TEXT; - if ($ignore_errors != 0) $DEBUG_TEXT = ''; - $error_text = ''; - $link = 0; + global $CONF; + global $DEBUG_TEXT; + if ($ignore_errors != 0) $DEBUG_TEXT = ''; + $error_text = ''; + $link = 0; - if ($CONF['database_type'] == "mysql") - { - if (function_exists ("mysql_connect")) - { - $link = @mysql_connect ($CONF['database_host'], $CONF['database_user'], $CONF['database_password']) or $error_text .= ("<p />DEBUG INFORMATION:<br />Connect: " . mysql_error () . "$DEBUG_TEXT"); - if ($link) { - @mysql_query("SET CHARACTER SET utf8",$link); - @mysql_query("SET COLLATION_CONNECTION='utf8_general_ci'",$link); - $succes = @mysql_select_db ($CONF['database_name'], $link) or $error_text .= ("<p />DEBUG INFORMATION:<br />MySQL Select Database: " . mysql_error () . "$DEBUG_TEXT"); - } - } - else - { - $error_text .= "<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"; - } - } - elseif ($CONF['database_type'] == "mysqli") - { - if (function_exists ("mysqli_connect")) - { - $link = @mysqli_connect ($CONF['database_host'], $CONF['database_user'], $CONF['database_password']) or $error_text .= ("<p />DEBUG INFORMATION:<br />Connect: " . mysqli_connect_error () . "$DEBUG_TEXT"); - if ($link) { - @mysqli_query($link,"SET CHARACTER SET utf8"); - @mysqli_query($link,"SET COLLATION_CONNECTION='utf8_general_ci'"); - $success = @mysqli_select_db ($link, $CONF['database_name']) or $error_text .= ("<p />DEBUG INFORMATION:<br />MySQLi Select Database: " . mysqli_error ($link) . "$DEBUG_TEXT"); - } - } - else - { - $error_text .= "<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"; - } - } - elseif ($CONF['database_type'] == "pgsql") - { - if (function_exists ("pg_pconnect")) - { - $connect_string = "host=" . $CONF['database_host'] . " dbname=" . $CONF['database_name'] . " user=" . $CONF['database_user'] . " password=" . $CONF['database_password']; - $link = @pg_pconnect ($connect_string) or $error_text .= ("<p />DEBUG INFORMATION:<br />Connect: failed to connect to database. $DEBUG_TEXT"); - if ($link) pg_set_client_encoding($link, 'UNICODE'); - } - else - { - $error_text .= "<p />DEBUG INFORMATION:<br />PostgreSQL functions not available!<br />database_type = 'pgsql' in config.inc.php, are you using a different database? $DEBUG_TEXT"; - } - } - else - { - $error_text = "<p />DEBUG INFORMATION:<br />Invalid \$CONF['database_type']! Please fix your config.inc.php! $DEBUG_TEXT"; - } + if ($CONF['database_type'] == "mysql") + { + if (function_exists ("mysql_connect")) + { + $link = @mysql_connect ($CONF['database_host'], $CONF['database_user'], $CONF['database_password']) or $error_text .= ("<p />DEBUG INFORMATION:<br />Connect: " ... [truncated message content] |