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

Remove whitespace

This commit is contained in:
Christian Schrötter 2017-03-21 17:43:27 +01:00
parent 0b82dec825
commit 2dea9fadd4
No known key found for this signature in database
GPG Key ID: 8038DEBE14AD09A4

View File

@ -1,16 +1,16 @@
<?php <?php
/** /**
* Postfix Admin * Postfix Admin
* *
* LICENSE * LICENSE
* This source file is subject to the GPL license that is bundled with * This source file is subject to the GPL license that is bundled with
* this package in the file LICENSE.TXT. * this package in the file LICENSE.TXT.
* *
* Further details on the project are available at http://postfixadmin.sf.net * Further details on the project are available at http://postfixadmin.sf.net
* *
* @version $Id$ * @version $Id$
* @license GNU GPL v2 or later. * @license GNU GPL v2 or later.
* *
* File: functions.inc.php * File: functions.inc.php
* Contains re-usable code. * Contains re-usable code.
*/ */
@ -42,7 +42,7 @@ function authentication_get_username() {
} }
/** /**
* Returns the type of user - either 'user' or 'admin' * Returns the type of user - either 'user' or 'admin'
* Returns false if neither (E.g. if not logged in) * Returns false if neither (E.g. if not logged in)
* @return String admin or user or (boolean) false. * @return String admin or user or (boolean) false.
*/ */
@ -73,7 +73,7 @@ function authentication_has_role($role) {
} }
/** /**
* Used to enforce that $user has a particular role when * Used to enforce that $user has a particular role when
* viewing a page. * viewing a page.
* If they are lacking a role, redirect them to login.php * If they are lacking a role, redirect them to login.php
* *
@ -92,7 +92,7 @@ function authentication_require_role($role) {
/** /**
* Add an error message for display on the next page that is rendered. * Add an error message for display on the next page that is rendered.
* @param String/Array message(s) to show. * @param String/Array message(s) to show.
* *
* Stores string in session. Flushed through header template. * Stores string in session. Flushed through header template.
* @see _flash_string() * @see _flash_string()
@ -103,7 +103,7 @@ function flash_error($string) {
/** /**
* Used to display an info message on successful update. * Used to display an info message on successful update.
* @param String/Array message(s) to show. * @param String/Array message(s) to show.
* Stores data in session. * Stores data in session.
* @see _flash_string() * @see _flash_string()
*/ */
@ -191,7 +191,7 @@ function language_selector() {
/** /**
* Checks if a domain is valid * Checks if a domain is valid
* @param string $domain * @param string $domain
* @return empty string if the domain is valid, otherwise string with the errormessage * @return empty string if the domain is valid, otherwise string with the errormessage
* *
@ -249,7 +249,7 @@ function check_email ($email) {
//strip the vacation domain out if we are using it //strip the vacation domain out if we are using it
//and change from blah#foo.com@autoreply.foo.com to blah@foo.com //and change from blah#foo.com@autoreply.foo.com to blah@foo.com
if (Config::bool('vacation')) { if (Config::bool('vacation')) {
$vacation_domain = Config::read('vacation_domain'); $vacation_domain = Config::read('vacation_domain');
$ce_email = preg_replace("/@$vacation_domain\$/", '', $ce_email); $ce_email = preg_replace("/@$vacation_domain\$/", '', $ce_email);
$ce_email = preg_replace("/#/", '@', $ce_email); $ce_email = preg_replace("/#/", '@', $ce_email);
@ -337,7 +337,7 @@ function escape_string ($string, $db_conn = null) {
* *
* @param String parameter name. * @param String parameter name.
* @param String (optional) - default value if key is not set. * @param String (optional) - default value if key is not set.
* @return String * @return String
*/ */
function safeget ($param, $default="") { function safeget ($param, $default="") {
$retval=$default; $retval=$default;
@ -362,7 +362,7 @@ function safepost ($param, $default="") {
/** /**
* safeserver * safeserver
* @see safeget() * @see safeget()
* @param String $param * @param String $param
* @param String $default (optional) * @param String $default (optional)
* @return String value from $_SERVER[$param] or $default * @return String value from $_SERVER[$param] or $default
*/ */
@ -375,7 +375,7 @@ function safeserver ($param, $default="") {
/** /**
* safecookie * safecookie
* @see safeget() * @see safeget()
* @param String $param * @param String $param
* @param String $default (optional) * @param String $default (optional)
* @return String value from $_COOKIE[$param] or $default * @return String value from $_COOKIE[$param] or $default
*/ */
@ -388,7 +388,7 @@ function safecookie ($param, $default="") {
/** /**
* safesession * safesession
* @see safeget() * @see safeget()
* @param String $param * @param String $param
* @param String $default (optional) * @param String $default (optional)
* @return String value from $_SESSION[$param] or $default * @return String value from $_SESSION[$param] or $default
*/ */
@ -471,7 +471,7 @@ function get_domain_properties ($domain) {
* *
* @param String idxfield - database field name to use as title * @param String idxfield - database field name to use as title
* @param String query - core part of the query (starting at "FROM") * @param String query - core part of the query (starting at "FROM")
* @return String * @return String
*/ */
function create_page_browser($idxfield, $querypart) { function create_page_browser($idxfield, $querypart) {
global $CONF; global $CONF;
@ -509,16 +509,16 @@ function create_page_browser($idxfield, $querypart) {
$page_size_zerobase = $page_size - 1; $page_size_zerobase = $page_size - 1;
$query = " $query = "
SELECT * FROM ( SELECT * FROM (
SELECT $idxfield AS label, @row := @row + 1 AS row $querypart SELECT $idxfield AS label, @row := @row + 1 AS row $querypart
) idx WHERE MOD(idx.row, $page_size) IN (0,$page_size_zerobase) OR idx.row = $count_results ) idx WHERE MOD(idx.row, $page_size) IN (0,$page_size_zerobase) OR idx.row = $count_results
"; ";
if (db_pgsql()) { if (db_pgsql()) {
$query = " $query = "
SELECT * FROM ( SELECT * FROM (
SELECT $idxfield AS label, nextval('rowcount') AS row $querypart SELECT $idxfield AS label, nextval('rowcount') AS row $querypart
) idx WHERE MOD(idx.row, $page_size) IN (0,$page_size_zerobase) OR idx.row = $count_results ) idx WHERE MOD(idx.row, $page_size) IN (0,$page_size_zerobase) OR idx.row = $count_results
"; ";
} }
if (db_sqlite()) { if (db_sqlite()) {
@ -533,7 +533,7 @@ function create_page_browser($idxfield, $querypart) {
# TODO: $query is MySQL-specific # TODO: $query is MySQL-specific
# PostgreSQL: # PostgreSQL:
# http://www.postgresql.org/docs/8.1/static/sql-createsequence.html # http://www.postgresql.org/docs/8.1/static/sql-createsequence.html
# http://www.postgresonline.com/journal/archives/79-Simulating-Row-Number-in-PostgreSQL-Pre-8.4.html # http://www.postgresonline.com/journal/archives/79-Simulating-Row-Number-in-PostgreSQL-Pre-8.4.html
# http://www.pg-forum.de/sql/1518-nummerierung-der-abfrageergebnisse.html # http://www.pg-forum.de/sql/1518-nummerierung-der-abfrageergebnisse.html
@ -604,7 +604,7 @@ function check_owner ($username, $domain) {
/** /**
* List domains for an admin user. * List domains for an admin user.
* @param String $username * @param String $username
* @return array of domain names. * @return array of domain names.
*/ */
@ -863,8 +863,8 @@ function validate_password($password) {
/** /**
* Encrypt a password, using the apparopriate hashing mechanism as defined in * Encrypt a password, using the apparopriate hashing mechanism as defined in
* config.inc.php ($CONF['encrypt']). * config.inc.php ($CONF['encrypt']).
* When wanting to compare one pw to another, it's necessary to provide the salt used - hence * When wanting to compare one pw to another, it's necessary to provide the salt used - hence
* the second parameter ($pw_db), which is the existing hash from the DB. * the second parameter ($pw_db), which is the existing hash from the DB.
* *
@ -914,17 +914,17 @@ function pacrypt ($pw, $pw_db="") {
$l = db_row($res["result"]); $l = db_row($res["result"]);
$password = $l[0]; $password = $l[0];
} }
elseif ($CONF['encrypt'] == 'authlib') { elseif ($CONF['encrypt'] == 'authlib') {
$flavor = $CONF['authlib_default_flavor']; $flavor = $CONF['authlib_default_flavor'];
$salt = substr(create_salt(), 0, 2); # courier-authlib supports only two-character salts $salt = substr(create_salt(), 0, 2); # courier-authlib supports only two-character salts
if(preg_match('/^{.*}/', $pw_db)) { if(preg_match('/^{.*}/', $pw_db)) {
// we have a flavor in the db -> use it instead of default flavor // we have a flavor in the db -> use it instead of default flavor
$result = preg_split('/[{}]/', $pw_db, 3); # split at { and/or } $result = preg_split('/[{}]/', $pw_db, 3); # split at { and/or }
$flavor = $result[1]; $flavor = $result[1];
$salt = substr($result[2], 0, 2); $salt = substr($result[2], 0, 2);
} }
if(stripos($flavor, 'md5raw') === 0) { if(stripos($flavor, 'md5raw') === 0) {
$password = '{' . $flavor . '}' . md5($pw); $password = '{' . $flavor . '}' . md5($pw);
} elseif(stripos($flavor, 'md5') === 0) { } elseif(stripos($flavor, 'md5') === 0) {
@ -937,14 +937,14 @@ function pacrypt ($pw, $pw_db="") {
die("authlib_default_flavor '" . $flavor . "' unknown. Valid flavors are 'md5raw', 'md5', 'SHA' and 'crypt'"); die("authlib_default_flavor '" . $flavor . "' unknown. Valid flavors are 'md5raw', 'md5', 'SHA' and 'crypt'");
} }
} }
elseif (preg_match("/^dovecot:/", $CONF['encrypt'])) { elseif (preg_match("/^dovecot:/", $CONF['encrypt'])) {
$split_method = preg_split ('/:/', $CONF['encrypt']); $split_method = preg_split ('/:/', $CONF['encrypt']);
$method = strtoupper($split_method[1]); $method = strtoupper($split_method[1]);
# If $pw_db starts with {method}, change $method accordingly # If $pw_db starts with {method}, change $method accordingly
if (!empty($pw_db) && preg_match('/^\{([A-Z0-9.-]+)\}.+/', $pw_db, $method_matches)) { $method = $method_matches[1]; } if (!empty($pw_db) && preg_match('/^\{([A-Z0-9.-]+)\}.+/', $pw_db, $method_matches)) { $method = $method_matches[1]; }
if (! preg_match("/^[A-Z0-9.-]+$/", $method)) { die("invalid dovecot encryption method"); } # TODO: check against a fixed list? if (! preg_match("/^[A-Z0-9.-]+$/", $method)) { die("invalid dovecot encryption method"); } # TODO: check against a fixed list?
# if (strtolower($method) == 'md5-crypt') die("\$CONF['encrypt'] = 'dovecot:md5-crypt' will not work because dovecotpw generates a random salt each time. Please use \$CONF['encrypt'] = 'md5crypt' instead."); # if (strtolower($method) == 'md5-crypt') die("\$CONF['encrypt'] = 'dovecot:md5-crypt' will not work because dovecotpw generates a random salt each time. Please use \$CONF['encrypt'] = 'md5crypt' instead.");
# $crypt_method = preg_match ("/.*-CRYPT$/", $method); # $crypt_method = preg_match ("/.*-CRYPT$/", $method);
# digest-md5 and SCRAM-SHA-1 hashes include the username - until someone implements it, let's declare it as unsupported # digest-md5 and SCRAM-SHA-1 hashes include the username - until someone implements it, let's declare it as unsupported
@ -1154,7 +1154,7 @@ function smtp_mail ($to, $from, $data, $body = "") {
$timeout = "30"; $timeout = "30";
if ($body != "") { if ($body != "") {
$maildata = $maildata =
"To: " . $to . "\n" "To: " . $to . "\n"
. "From: " . $from . "\n" . "From: " . $from . "\n"
. "Subject: " . encode_header ($data) . "\n" . "Subject: " . encode_header ($data) . "\n"
@ -1253,7 +1253,6 @@ function db_connect ($ignore_errors = false) {
global $DEBUG_TEXT; global $DEBUG_TEXT;
if ($ignore_errors != 0) $DEBUG_TEXT = ''; if ($ignore_errors != 0) $DEBUG_TEXT = '';
$error_text = ''; $error_text = '';
$link = 0;
if ($CONF['database_type'] == "mysql") { if ($CONF['database_type'] == "mysql") {
if (function_exists ("mysql_connect")) { if (function_exists ("mysql_connect")) {
@ -1336,12 +1335,12 @@ function db_get_boolean($bool) {
// return either true or false (unquoted strings) // return either true or false (unquoted strings)
if($bool) { if($bool) {
return 't'; return 't';
} }
return 'f'; return 'f';
} elseif(Config::Read('database_type') == 'mysql' || Config::Read('database_type') == 'mysqli' || db_sqlite()) { } elseif(Config::Read('database_type') == 'mysql' || Config::Read('database_type') == 'mysqli' || db_sqlite()) {
if($bool) { if($bool) {
return 1; return 1;
} }
return 0; return 0;
} else { } else {
die('Unknown value in $CONF[database_type]'); die('Unknown value in $CONF[database_type]');
@ -1428,14 +1427,14 @@ function db_query ($query, $ignore_errors = 0) {
# mysql and pgsql $link are resources, mysqli $link is an object # mysql and pgsql $link are resources, mysqli $link is an object
if (! (is_resource($link) || is_object($link) ) ) $link = db_connect (); if (! (is_resource($link) || is_object($link) ) ) $link = db_connect ();
if ($CONF['database_type'] == "mysql") $result = @mysql_query ($query, $link) if ($CONF['database_type'] == "mysql") $result = @mysql_query ($query, $link)
or $error_text = "Invalid query: " . mysql_error($link); or $error_text = "Invalid query: " . mysql_error($link);
if ($CONF['database_type'] == "mysqli") $result = @mysqli_query ($link, $query) if ($CONF['database_type'] == "mysqli") $result = @mysqli_query ($link, $query)
or $error_text = "Invalid query: " . mysqli_error($link); or $error_text = "Invalid query: " . mysqli_error($link);
if (db_sqlite()) $result = @$link->query($query) if (db_sqlite()) $result = @$link->query($query)
or $error_text = "Invalid query: " . $link->lastErrorMsg(); or $error_text = "Invalid query: " . $link->lastErrorMsg();
if (db_pgsql()) { if (db_pgsql()) {
$result = @pg_query ($link, $query) $result = @pg_query ($link, $query)
or $error_text = "Invalid query: " . pg_last_error(); or $error_text = "Invalid query: " . pg_last_error();
} }
if ($error_text != "" && $ignore_errors == 0) { if ($error_text != "" && $ignore_errors == 0) {
@ -1700,7 +1699,7 @@ function db_in_clause($field, $values) {
* param array $condition: array('field' => 'value', 'field2' => 'value2, ...) * param array $condition: array('field' => 'value', 'field2' => 'value2, ...)
* param array $struct - field structure, used for automatic bool conversion * param array $struct - field structure, used for automatic bool conversion
* param string $additional_raw_where - raw sniplet to include in the WHERE part - typically needs to start with AND * param string $additional_raw_where - raw sniplet to include in the WHERE part - typically needs to start with AND
* param array $searchmode - operators to use (=, <, > etc.) - defaults to = if not specified for a field (see * param array $searchmode - operators to use (=, <, > etc.) - defaults to = if not specified for a field (see
* $allowed_operators for available operators) * $allowed_operators for available operators)
* Note: the $searchmode operator will only be used if a $condition for that field is set. * Note: the $searchmode operator will only be used if a $condition for that field is set.
* This also means you'll need to set a (dummy) condition for NULL and NOTNULL. * This also means you'll need to set a (dummy) condition for NULL and NOTNULL.
@ -1711,7 +1710,7 @@ function db_where_clause($condition, $struct, $additional_raw_where = '', $searc
} elseif(!is_array($searchmode)) { } elseif(!is_array($searchmode)) {
die('db_where_cond: parameter $searchmode is not an array!'); die('db_where_cond: parameter $searchmode is not an array!');
} elseif (count($condition) == 0 && trim($additional_raw_where) == '') { } elseif (count($condition) == 0 && trim($additional_raw_where) == '') {
die("db_where_cond: parameter is an empty array!"); # die() might sound harsh, but can prevent information leaks die("db_where_cond: parameter is an empty array!"); # die() might sound harsh, but can prevent information leaks
} elseif(!is_array($struct)) { } elseif(!is_array($struct)) {
die('db_where_cond: parameter $struct is not an array!'); die('db_where_cond: parameter $struct is not an array!');
} }
@ -1840,9 +1839,9 @@ function alias_domain_postdeletion($alias_domain) {
// //
// gen_show_status // gen_show_status
// Action: Return a string of colored &nbsp;'s that indicate // Action: Return a string of colored &nbsp;'s that indicate
// the if an alias goto has an error or is sent to // the if an alias goto has an error or is sent to
// addresses list in show_custom_domains // addresses list in show_custom_domains
// Call: gen_show_status (string alias_address) // Call: gen_show_status (string alias_address)
// //
function gen_show_status ($show_alias) { function gen_show_status ($show_alias) {
@ -1893,7 +1892,7 @@ function gen_show_status ($show_alias) {
"'>" . $CONF['show_status_text'] . "</span>&nbsp;"; "'>" . $CONF['show_status_text'] . "</span>&nbsp;";
} else { } else {
$stat_string .= $CONF['show_status_text'] . "&nbsp;"; $stat_string .= $CONF['show_status_text'] . "&nbsp;";
} }
} }
// POP/IMAP CHECK // POP/IMAP CHECK
@ -1910,7 +1909,7 @@ function gen_show_status ($show_alias) {
"'>" . $CONF['show_status_text'] . "</span>&nbsp;"; "'>" . $CONF['show_status_text'] . "</span>&nbsp;";
} else { } else {
$stat_string .= $CONF['show_status_text'] . "&nbsp;"; $stat_string .= $CONF['show_status_text'] . "&nbsp;";
} }
} }
// CUSTOM DESTINATION CHECK // CUSTOM DESTINATION CHECK
@ -1921,11 +1920,11 @@ function gen_show_status ($show_alias) {
"'>" . $CONF['show_status_text'] . "</span>&nbsp;"; "'>" . $CONF['show_status_text'] . "</span>&nbsp;";
} else { } else {
$stat_string .= $CONF['show_status_text'] . "&nbsp;"; $stat_string .= $CONF['show_status_text'] . "&nbsp;";
} }
} }
} else { } else {
$stat_string .= ";&nbsp;"; $stat_string .= ";&nbsp;";
} }
// $stat_string .= "<span style='background-color:green'> &nbsp; </span> &nbsp;" . // $stat_string .= "<span style='background-color:green'> &nbsp; </span> &nbsp;" .
// "<span style='background-color:blue'> &nbsp; </span> &nbsp;"; // "<span style='background-color:blue'> &nbsp; </span> &nbsp;";
@ -1934,7 +1933,7 @@ function gen_show_status ($show_alias) {
function getRemoteAddr() { function getRemoteAddr() {
$REMOTE_ADDR = 'localhost'; $REMOTE_ADDR = 'localhost';
if (isset($_SERVER['REMOTE_ADDR'])) if (isset($_SERVER['REMOTE_ADDR']))
$REMOTE_ADDR = $_SERVER['REMOTE_ADDR']; $REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
return $REMOTE_ADDR; return $REMOTE_ADDR;
} }