diff --git a/.php_cs.dist b/.php_cs.dist index 018cbf5c..0ecca539 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -13,9 +13,6 @@ return PhpCsFixer\Config::create() ->setFinder($finder) ->setRules(array( '@PSR2' => true, - 'braces' => array( - 'position_after_functions_and_oop_constructs' => 'same', - ), 'method_argument_space' => false, # don't break formatting in initStruct() 'no_spaces_inside_parenthesis' => false, # don't break formatting in initStruct() )); diff --git a/ADDITIONS/squirrelmail-plugin/functions.inc.php b/ADDITIONS/squirrelmail-plugin/functions.inc.php index c15ff33b..0a10aaa0 100644 --- a/ADDITIONS/squirrelmail-plugin/functions.inc.php +++ b/ADDITIONS/squirrelmail-plugin/functions.inc.php @@ -6,16 +6,19 @@ */ -function do_header() { +function do_header() +{ global $color; displayPageHeader($color, 'None'); } -function do_footer() { +function do_footer() +{ echo ""; } -function _display_password_form() { +function _display_password_form() +{ bindtextdomain('postfixadmin', SM_PATH . 'plugins/postfixadmin/locale'); textdomain('postfixadmin'); do_header('Postfixadmin Squirrelmail - Login'); @@ -31,7 +34,8 @@ function _display_password_form() { /** * This returns a Zend_XmlRpc_Client instance - unless we can't log you in... */ -function get_xmlrpc() { +function get_xmlrpc() +{ global $CONF; require_once('Zend/XmlRpc/Client.php'); $client = new Zend_XmlRpc_Client($CONF['xmlrpc_url']); @@ -73,7 +77,8 @@ function get_xmlrpc() { return $client; } -function include_if_exists($filename) { +function include_if_exists($filename) +{ if (file_exists($filename)) { include_once($filename); } @@ -87,7 +92,8 @@ $optmode = 'display'; // Action: Checks if email is valid and returns TRUE if this is the case. // Call: check_email (string email) // -function check_email($email) { +function check_email($email) +{ $return = filter_var($email, FILTER_VALIDATE_EMAIL); if ($return === false) { return false; diff --git a/ADDITIONS/squirrelmail-plugin/setup.php b/ADDITIONS/squirrelmail-plugin/setup.php index 95abdb62..ab36af79 100644 --- a/ADDITIONS/squirrelmail-plugin/setup.php +++ b/ADDITIONS/squirrelmail-plugin/setup.php @@ -5,18 +5,21 @@ if (!defined('SM_PATH')) { } include_once(SM_PATH . 'functions/i18n.php'); -function squirrelmail_plugin_init_postfixadmin() { +function squirrelmail_plugin_init_postfixadmin() +{ include(dirname(__FILE__) . '/config.php'); global $squirrelmail_plugin_hooks; $squirrelmail_plugin_hooks['optpage_register_block']['postfixadmin'] = 'postfixadmin_optpage_register_block'; } -function postfixadmin_version() { +function postfixadmin_version() +{ return '2.3.0'; } -function postfixadmin_optpage_register_block() { +function postfixadmin_optpage_register_block() +{ // Gets added to the user's OPTIONS page. global $optpage_blocks; global $AllowVacation; diff --git a/ADDITIONS/virtualmaildel.php b/ADDITIONS/virtualmaildel.php index 31898e65..5adce997 100644 --- a/ADDITIONS/virtualmaildel.php +++ b/ADDITIONS/virtualmaildel.php @@ -46,7 +46,8 @@ if (! is_dir($homedir)) { // // Recursive Delete Function // -function deldir($dir) { +function deldir($dir) +{ $current_dir = opendir($dir); while ($entryname = readdir($current_dir)) { if (is_dir("$dir/$entryname") and ($entryname != "." and $entryname!="..")) { diff --git a/common.php b/common.php index c57e20c6..b82228aa 100644 --- a/common.php +++ b/common.php @@ -36,7 +36,8 @@ $incpath = dirname(__FILE__); * @param string $class * __autoload implementation, for use with spl_autoload_register(). */ -function postfixadmin_autoload($class) { +function postfixadmin_autoload($class) +{ $PATH = dirname(__FILE__) . '/model/' . $class . '.php'; if (is_file($PATH)) { diff --git a/functions.inc.php b/functions.inc.php index 9614d796..61a28dff 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -23,7 +23,8 @@ $min_db_version = 1843; # update (at least) before a release with the latest fu * Call: check_session () * @return String username (e.g. foo@example.com) */ -function authentication_get_username() { +function authentication_get_username() +{ if (defined('POSTFIXADMIN_CLI')) { return 'CLI'; } @@ -45,7 +46,8 @@ function authentication_get_username() { * Returns false if neither (E.g. if not logged in) * @return string|bool admin or user or (boolean) false. */ -function authentication_get_usertype() { +function authentication_get_usertype() +{ if (isset($_SESSION['sessid'])) { if (isset($_SESSION['sessid']['type'])) { return $_SESSION['sessid']['type']; @@ -60,7 +62,8 @@ function authentication_get_usertype() { * @return boolean True if they have the requested role in their session. * Note, user < admin < global-admin */ -function authentication_has_role($role) { +function authentication_has_role($role) +{ if (isset($_SESSION['sessid'])) { if (isset($_SESSION['sessid']['roles'])) { if (in_array($role, $_SESSION['sessid']['roles'])) { @@ -80,7 +83,8 @@ function authentication_has_role($role) { * @param string $role * @return bool */ -function authentication_require_role($role) { +function authentication_require_role($role) +{ // redirect to appropriate page? if (authentication_has_role($role)) { return true; @@ -97,7 +101,8 @@ function authentication_require_role($role) { * @param boolean $is_admin true if the user is an admin, false otherwise * @return boolean true on success */ -function init_session($username, $is_admin = false) { +function init_session($username, $is_admin = false) +{ $status = session_regenerate_id(true); $_SESSION['sessid'] = array(); $_SESSION['sessid']['roles'] = array(); @@ -116,7 +121,8 @@ function init_session($username, $is_admin = false) { * @see _flash_string() * @return void */ -function flash_error($string) { +function flash_error($string) +{ _flash_string('error', $string); } @@ -127,7 +133,8 @@ function flash_error($string) { * @see _flash_string() * @return void */ -function flash_info($string) { +function flash_info($string) +{ _flash_string('info', $string); } /** @@ -136,7 +143,8 @@ function flash_info($string) { * @param array|string $string * @retrn void */ -function _flash_string($type, $string) { +function _flash_string($type, $string) +{ if (is_array($string)) { foreach ($string as $singlestring) { _flash_string($type, $singlestring); @@ -158,7 +166,8 @@ function _flash_string($type, $string) { * @return string e.g en * Try to figure out what language the user wants based on browser / cookie */ -function check_language($use_post = true) { +function check_language($use_post = true) +{ global $supported_languages; # from languages/languages.php // prefer a $_POST['lang'] if present @@ -199,7 +208,8 @@ function check_language($use_post = true) { * * */ -function language_selector() { +function language_selector() +{ global $supported_languages; # from languages/languages.php $current_lang = check_language(); @@ -229,7 +239,8 @@ function language_selector() { * @todo make check_domain able to handle as example .local domains * @todo skip DNS check if the domain exists in PostfixAdmin? */ -function check_domain($domain) { +function check_domain($domain) +{ if (!preg_match('/^([-0-9A-Z]+\.)+' . '([-0-9A-Z]){1,13}$/i', ($domain))) { return sprintf(Config::lang('pInvalidDomainRegex'), htmlentities($domain)); } @@ -275,7 +286,8 @@ function check_domain($domain) { * @param string $domain - a string that may be a domain * @return int password expiration value for this domain (DAYS, or zero if not enabled) */ -function get_password_expiration_value($domain) { +function get_password_expiration_value($domain) +{ $table_domain = table_by_key('domain'); $query = "SELECT password_expiry FROM $table_domain WHERE domain= :domain"; @@ -293,7 +305,8 @@ function get_password_expiration_value($domain) { * @param string $email - a string that may be an email address. * @return string empty if it's a valid email address, otherwise string with the errormessage */ -function check_email($email) { +function check_email($email) +{ $ce_email=$email; //strip the vacation domain out if we are using it @@ -345,7 +358,8 @@ function check_email($email) { * @param int|string $string_or_int parameters to escape * @return string cleaned data, suitable for use within an SQL statement. */ -function escape_string($string_or_int) { +function escape_string($string_or_int) +{ $link = db_connect(); $string_or_int = (string) $string_or_int; $quoted = $link->quote($string_or_int); @@ -364,7 +378,8 @@ function escape_string($string_or_int) { * @param string $default (optional) - default value if key is not set. * @return string */ -function safeget($param, $default = "") { +function safeget($param, $default = "") +{ $retval = $default; if (isset($_GET[$param]) && is_string($_GET[$param])) { $retval = $_GET[$param]; @@ -379,7 +394,8 @@ function safeget($param, $default = "") { * @param string $default (optional) default value (defaults to "") * @return string - value in $_POST[$param] or $default */ -function safepost($param, $default = "") { +function safepost($param, $default = "") +{ $retval = $default; if (isset($_POST[$param]) && is_string($_POST[$param])) { $retval = $_POST[$param]; @@ -394,7 +410,8 @@ function safepost($param, $default = "") { * @param string $default (optional) * @return string value from $_SERVER[$param] or $default */ -function safeserver($param, $default = "") { +function safeserver($param, $default = "") +{ $retval = $default; if (isset($_SERVER[$param])) { $retval = $_SERVER[$param]; @@ -409,7 +426,8 @@ function safeserver($param, $default = "") { * @param string $default (optional) * @return string value from $_COOKIE[$param] or $default */ -function safecookie($param, $default = "") { +function safecookie($param, $default = "") +{ $retval = $default; if (isset($_COOKIE[$param]) && is_string($_COOKIE[$param])) { $retval = $_COOKIE[$param]; @@ -424,7 +442,8 @@ function safecookie($param, $default = "") { * @param string $default (optional) * @return string value from $_SESSION[$param] or $default */ -function safesession($param, $default = "") { +function safesession($param, $default = "") +{ $retval = $default; if (isset($_SESSION[$param]) && is_string($_SESSION[$param])) { $retval = $_SESSION[$param]; @@ -446,7 +465,8 @@ function safesession($param, $default = "") { * @param int or $not_in_db - if array, can contain the remaining parameters as associated array. Otherwise counts as $not_in_db * @return array for $struct */ -function pacol($allow_editing, $display_in_form, $display_in_list, $type, $PALANG_label, $PALANG_desc, $default = "", $options = array(), $multiopt=0, $dont_write_to_db=0, $select="", $extrafrom="", $linkto="") { +function pacol($allow_editing, $display_in_form, $display_in_list, $type, $PALANG_label, $PALANG_desc, $default = "", $options = array(), $multiopt=0, $dont_write_to_db=0, $select="", $extrafrom="", $linkto="") +{ if ($PALANG_label != '') { $PALANG_label = Config::lang($PALANG_label); } @@ -485,7 +505,8 @@ function pacol($allow_editing, $display_in_form, $display_in_list, $type, $PALAN * @param string $domain * @return array */ -function get_domain_properties($domain) { +function get_domain_properties($domain) +{ $handler = new DomainHandler(); if (!$handler->init($domain)) { throw new Exception("Error: " . join("\n", $handler->errormsg)); @@ -508,7 +529,8 @@ function get_domain_properties($domain) { * @param string $querypart - core part of the query (starting at "FROM") e.g. FROM alias WHERE address like ... * @return array */ -function create_page_browser($idxfield, $querypart, $sql_params = []) { +function create_page_browser($idxfield, $querypart, $sql_params = []) +{ global $CONF; $page_size = (int) $CONF['page_size']; $label_len = 2; @@ -599,7 +621,8 @@ function create_page_browser($idxfield, $querypart, $sql_params = []) { * @param int $quota * @return float */ -function divide_quota($quota) { +function divide_quota($quota) +{ if ($quota == -1) { return $quota; } @@ -614,7 +637,8 @@ function divide_quota($quota) { * @param string $domain * @return bool */ -function check_owner($username, $domain) { +function check_owner($username, $domain) +{ $table_domain_admins = table_by_key('domain_admins'); $result = db_query_all( @@ -641,7 +665,8 @@ function check_owner($username, $domain) { * @param string $username * @return array of domain names. */ -function list_domains_for_admin($username) { +function list_domains_for_admin($username) +{ $table_domain = table_by_key('domain'); $table_domain_admins = table_by_key('domain_admins'); @@ -679,7 +704,8 @@ function list_domains_for_admin($username) { * * @return array */ -function list_domains() { +function list_domains() +{ $list = array(); $table_domain = table_by_key('domain'); @@ -702,7 +728,8 @@ function list_domains() { // // was admin_list_admins // -function list_admins() { +function list_admins() +{ $handler = new AdminHandler(); $handler->getList(''); @@ -717,7 +744,8 @@ function list_admins() { // Action: Encode a string according to RFC 1522 for use in headers if it contains 8-bit characters. // Call: encode_header (string header, string charset) // -function encode_header($string, $default_charset = "utf-8") { +function encode_header($string, $default_charset = "utf-8") +{ if (strtolower($default_charset) == 'iso-8859-1') { $string = str_replace("\240", ' ', $string); } @@ -841,7 +869,8 @@ function encode_header($string, $default_charset = "utf-8") { * @return string * */ -function generate_password($length = 12) { +function generate_password($length = 12) +{ // define possible characters $possible = "2345678923456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ"; # skip 0 and 1 to avoid confusion with O and l @@ -868,7 +897,8 @@ function generate_password($length = 12) { * @param string $password * @return array of error messages, or empty array if the password is ok */ -function validate_password($password) { +function validate_password($password) +{ $result = array(); $val_conf = Config::read_array('password_validation'); @@ -906,7 +936,8 @@ function validate_password($password) { * @param string $pw_db - encrypted hash * @return string crypt'ed password, should equal $pw_db if $pw matches the original */ -function _pacrypt_md5crypt($pw, $pw_db = '') { +function _pacrypt_md5crypt($pw, $pw_db = '') +{ if ($pw_db) { $split_salt = preg_split('/\$/', $pw_db); if (isset($split_salt[2])) { @@ -921,7 +952,8 @@ function _pacrypt_md5crypt($pw, $pw_db = '') { /** * @todo fix this to not throw an E_NOTICE or deprecate/remove. */ -function _pacrypt_crypt($pw, $pw_db = '') { +function _pacrypt_crypt($pw, $pw_db = '') +{ if ($pw_db) { return crypt($pw, $pw_db); } @@ -936,7 +968,8 @@ function _pacrypt_crypt($pw, $pw_db = '') { * @param string $pw_db (hashed password) * @return string if $pw_db and the return value match then $pw matches the original password. */ -function _pacrypt_mysql_encrypt($pw, $pw_db = '') { +function _pacrypt_mysql_encrypt($pw, $pw_db = '') +{ // See https://sourceforge.net/tracker/?func=detail&atid=937966&aid=1793352&group_id=191583 // this is apparently useful for pam_mysql etc. @@ -959,7 +992,8 @@ function _pacrypt_mysql_encrypt($pw, $pw_db = '') { * @param string $pw_db (optional) * @return string crypted password - contains {xxx} prefix to identify mechanism. */ -function _pacrypt_authlib($pw, $pw_db) { +function _pacrypt_authlib($pw, $pw_db) +{ global $CONF; $flavor = $CONF['authlib_default_flavor']; $salt = substr(create_salt(), 0, 2); # courier-authlib supports only two-character salts @@ -991,7 +1025,8 @@ function _pacrypt_authlib($pw, $pw_db) { * @param string $pw_db - encrypted password, or '' for generation. * @return string crypted password */ -function _pacrypt_dovecot($pw, $pw_db = '') { +function _pacrypt_dovecot($pw, $pw_db = '') +{ global $CONF; $split_method = preg_split('/:/', $CONF['encrypt']); @@ -1093,7 +1128,8 @@ function _pacrypt_dovecot($pw, $pw_db = '') { * @param string $pw_db (can be empty if setting a new password) * @return string crypt'ed password; if it matches $pw_db then $pw is the original password. */ -function _pacrypt_php_crypt($pw, $pw_db) { +function _pacrypt_php_crypt($pw, $pw_db) +{ $configEncrypt = Config::read_string('encrypt'); // use PHPs crypt(), which uses the system's crypt() @@ -1148,7 +1184,8 @@ function _pacrypt_php_crypt($pw, $pw_db) { * @param int hash difficulty * @return string */ -function _php_crypt_generate_crypt_salt($hash_type='SHA512', $hash_difficulty=null) { +function _php_crypt_generate_crypt_salt($hash_type='SHA512', $hash_difficulty=null) +{ // generate a salt (with magic matching chosen hash algorithm) for the PHP crypt() function // most commonly used alphabet @@ -1230,7 +1267,8 @@ function _php_crypt_generate_crypt_salt($hash_type='SHA512', $hash_difficulty=nu * @param int $length * @return string of given $length */ -function _php_crypt_random_string($characters, $length) { +function _php_crypt_random_string($characters, $length) +{ $string = ''; for ($p = 0; $p < $length; $p++) { $string .= $characters[random_int(0, strlen($characters) -1)]; @@ -1250,7 +1288,8 @@ function _php_crypt_random_string($characters, $length) { * @param string $pw_db optional encrypted password * @return string encrypted password - if this matches $pw_db then the original password is $pw. */ -function pacrypt($pw, $pw_db="") { +function pacrypt($pw, $pw_db="") +{ global $CONF; switch ($CONF['encrypt']) { @@ -1284,7 +1323,8 @@ function pacrypt($pw, $pw_db="") { /** * @see https://github.com/postfixadmin/postfixadmin/issues/58 */ -function _pacrypt_sha512_b64($pw, $pw_db="") { +function _pacrypt_sha512_b64($pw, $pw_db="") +{ if (!function_exists('random_bytes') || !function_exists('crypt') || !defined('CRYPT_SHA512') || !function_exists('mb_substr')) { throw new Exception("sha512.b64 not supported!"); } @@ -1318,7 +1358,8 @@ function _pacrypt_sha512_b64($pw, $pw_db="") { * @param string $magic (optional) * @return string hashed password in crypt format. */ -function md5crypt($pw, $salt="", $magic="") { +function md5crypt($pw, $salt="", $magic="") +{ $MAGIC = "$1$"; if ($magic == "") { @@ -1388,7 +1429,8 @@ function md5crypt($pw, $salt="", $magic="") { /** * @return string - should be random, 8 chars long */ -function create_salt() { +function create_salt() +{ srand((int) microtime()*1000000); $salt = substr(md5("" . rand(0, 9999999)), 0, 8); return $salt; @@ -1397,7 +1439,8 @@ function create_salt() { /* * remove item $item from array $array */ -function remove_from_array($array, $item) { +function remove_from_array($array, $item) +{ # array_diff might be faster, but doesn't provide an easy way to know if the value was found or not # return array_diff($array, array($item)); $ret = array_search($item, $array); @@ -1410,7 +1453,8 @@ function remove_from_array($array, $item) { return array($found, $array); } -function to64($v, $n) { +function to64($v, $n) +{ $ITOA64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; $ret = ""; while (($n - 1) >= 0) { @@ -1436,7 +1480,8 @@ function to64($v, $n) { * @return bool - true on success, otherwise false * TODO: Replace this with something decent like PEAR::Mail or Zend_Mail. */ -function smtp_mail($to, $from, $data, $password = "", $body = "") { +function smtp_mail($to, $from, $data, $password = "", $body = "") +{ global $CONF; $smtpd_server = $CONF['smtp_server']; @@ -1516,7 +1561,8 @@ function smtp_mail($to, $from, $data, $password = "", $body = "") { * Call: smtp_get_admin_email * @return string - username/mail address */ -function smtp_get_admin_email() { +function smtp_get_admin_email() +{ $admin_email = Config::read_string('admin_email'); if (!empty($admin_email)) { return $admin_email; @@ -1531,7 +1577,8 @@ function smtp_get_admin_email() { * Call: smtp_get_admin_password * @return string - admin smtp password */ -function smtp_get_admin_password() { +function smtp_get_admin_password() +{ return Config::read_string('admin_smtp_password'); } @@ -1541,7 +1588,8 @@ function smtp_get_admin_password() { // Action: Get response from mail server // Call: smtp_get_response (string FileHandle) // -function smtp_get_response($fh) { +function smtp_get_response($fh) +{ $res =''; do { $line = fgets($fh, 256); @@ -1565,7 +1613,8 @@ EOF; * @return string - PDO DSN for PHP. * @throws Exception */ -function db_connection_string() { +function db_connection_string() +{ global $CONF; $dsn = null; if (db_mysql()) { @@ -1610,7 +1659,8 @@ function db_connection_string() { * * @return \PDO */ -function db_connect() { +function db_connect() +{ global $CONF; /* some attempt at not reopening an existing connection */ @@ -1697,7 +1747,8 @@ function db_connect() { * @param bool|string $bool * @return string|int as appropriate for underlying db platform */ -function db_get_boolean($bool) { +function db_get_boolean($bool) +{ if (! (is_bool($bool) || $bool == '0' || $bool == '1')) { error_log("Invalid usage of 'db_get_boolean($bool)'"); throw new Exception("Invalid usage of 'db_get_boolean($bool)'"); @@ -1726,7 +1777,8 @@ function db_get_boolean($bool) { * @param string column that will contain "x / y" * @return string */ -function db_quota_text($count, $quota, $fieldname) { +function db_quota_text($count, $quota, $fieldname) +{ if (db_pgsql() || db_sqlite()) { // SQLite and PostgreSQL use || to concatenate strings return " CASE $quota @@ -1750,7 +1802,8 @@ function db_quota_text($count, $quota, $fieldname) { * @param string column that will contain "x / y" * @return string */ -function db_quota_percent($count, $quota, $fieldname) { +function db_quota_percent($count, $quota, $fieldname) +{ return " CASE $quota WHEN '-1' THEN -1 WHEN '0' THEN -1 @@ -1761,7 +1814,8 @@ function db_quota_percent($count, $quota, $fieldname) { /** * @return boolean true if it's a MySQL database variant. */ -function db_mysql() { +function db_mysql() +{ $type = Config::Read('database_type'); if ($type == 'mysql' || $type == 'mysqli') { @@ -1773,14 +1827,16 @@ function db_mysql() { /** * @return bool true if PostgreSQL is used, false otherwise */ -function db_pgsql() { +function db_pgsql() +{ return Config::read_string('database_type') == 'pgsql'; } /** * returns true if SQLite is used, false otherwise */ -function db_sqlite() { +function db_sqlite() +{ if (Config::Read('database_type')=='sqlite') { return true; } else { @@ -1793,7 +1849,8 @@ function db_sqlite() { * @param array $values * @return array */ -function db_query_all($sql, array $values = []) { +function db_query_all($sql, array $values = []) +{ $r = db_query($sql, $values); return $r['result']->fetchAll(PDO::FETCH_ASSOC); } @@ -1803,7 +1860,8 @@ function db_query_all($sql, array $values = []) { * @param array $values * @return array */ -function db_query_one($sql, array $values = []) { +function db_query_one($sql, array $values = []) +{ $r = db_query($sql, $values); return $r['result']->fetch(PDO::FETCH_ASSOC); } @@ -1815,7 +1873,8 @@ function db_query_one($sql, array $values = []) { * @param bool $throw_exceptions * @return int number of rows affected by the query */ -function db_execute($sql, array $values = [], $throw_exceptions = false) { +function db_execute($sql, array $values = [], $throw_exceptions = false) +{ $link = db_connect(); try { @@ -1840,7 +1899,8 @@ function db_execute($sql, array $values = [], $throw_exceptions = false) { * @param bool $ignore_errors - set to true to ignore errors. * @return array e.g. ['result' => PDOStatement, 'error' => string ] */ -function db_query($sql, array $values = array(), $ignore_errors = false) { +function db_query($sql, array $values = array(), $ignore_errors = false) +{ $link = db_connect(); $error_text = ''; @@ -1880,7 +1940,8 @@ function db_query($sql, array $values = array(), $ignore_errors = false) { * @param string $additionalwhere (default ''). * @return int|mixed rows deleted. */ -function db_delete($table, $where, $delete, $additionalwhere='') { +function db_delete($table, $where, $delete, $additionalwhere='') +{ $table = table_by_key($table); $query = "DELETE FROM $table WHERE $where = ? $additionalwhere"; @@ -1901,7 +1962,8 @@ function db_delete($table, $where, $delete, $additionalwhere='') { * @param boolean $throw_exceptions * @return int - number of inserted rows */ -function db_insert(string $table, array $values, array $timestamp = array('created', 'modified'), bool $throw_exceptions = false) : int { +function db_insert(string $table, array $values, array $timestamp = array('created', 'modified'), bool $throw_exceptions = false) : int +{ $table = table_by_key($table); foreach ($timestamp as $key) { @@ -1944,7 +2006,8 @@ function db_insert(string $table, array $values, array $timestamp = array('creat * @param array $timestamp (optional) - array of fields to set to now() - default: array('modified') * @return int - number of updated rows */ -function db_update(string $table, string $where_col, string $where_value, array $values, array $timestamp = array('modified'), bool $throw_exceptions = false):int { +function db_update(string $table, string $where_col, string $where_value, array $values, array $timestamp = array('modified'), bool $throw_exceptions = false):int +{ $table_key = table_by_key($table); $pvalues = array(); @@ -1986,7 +2049,8 @@ function db_update(string $table, string $where_col, string $where_value, array * Call: db_log (string domain, string action, string data) * Possible actions are defined in $LANG["pViewlog_action_$action"] */ -function db_log($domain, $action, $data) { +function db_log($domain, $action, $data) +{ if (!Config::bool('logging')) { return true; } @@ -2022,7 +2086,8 @@ function db_log($domain, $action, $data) { * @param array $values * @return string */ -function db_in_clause($field, array $values) { +function db_in_clause($field, array $values) +{ $v = array_map('escape_string', array_values($values)); return " $field IN ('" . implode("','", $v) . "') "; } @@ -2039,7 +2104,8 @@ function db_in_clause($field, array $values) { * 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. */ -function db_where_clause(array $condition, array $struct, $additional_raw_where = '', array $searchmode = array()) { +function db_where_clause(array $condition, array $struct, $additional_raw_where = '', array $searchmode = array()) +{ if (count($condition) == 0 && trim($additional_raw_where) == '') { throw new Exception("db_where_cond: parameter is an empty array!"); } @@ -2109,7 +2175,8 @@ function db_where_clause(array $condition, array $struct, $additional_raw_where * @param string database table name. * @return string - database table name with appropriate prefix (and quoting if MySQL) */ -function table_by_key($table_key) { +function table_by_key($table_key) +{ global $CONF; $table = $table_key; @@ -2135,7 +2202,8 @@ function table_by_key($table_key) { * @param bool $error_out * @return int */ -function check_db_version($error_out = true) { +function check_db_version($error_out = true) +{ global $min_db_version; $table = table_by_key('config'); @@ -2167,7 +2235,8 @@ function check_db_version($error_out = true) { * @param string $show_alias * @return string */ -function gen_show_status($show_alias) { +function gen_show_status($show_alias) +{ global $CONF; $table_alias = table_by_key('alias'); $stat_string = ""; @@ -2314,7 +2383,8 @@ function gen_show_status($show_alias) { /** * @return string */ -function getRemoteAddr() { +function getRemoteAddr() +{ $REMOTE_ADDR = 'localhost'; if (isset($_SERVER['REMOTE_ADDR'])) { $REMOTE_ADDR = $_SERVER['REMOTE_ADDR']; @@ -2328,7 +2398,8 @@ function getRemoteAddr() { * @param array $server * @return string URL to Postfixadmin - will always end in a '/' */ -function getSiteUrl(array $server = []): string { +function getSiteUrl(array $server = []): string +{ if (Config::has('site_url')) { $url = Config::read_string('site_url'); if (!empty($url)) { diff --git a/model/AdminHandler.php b/model/AdminHandler.php index 25b7753e..13ac403e 100644 --- a/model/AdminHandler.php +++ b/model/AdminHandler.php @@ -6,7 +6,8 @@ class AdminHandler extends PFAHandler protected $db_table = 'admin'; protected $id_field = 'username'; - protected function validate_new_id() { + protected function validate_new_id() + { $email_check = check_email($this->id); if ($email_check == '') { @@ -18,12 +19,14 @@ class AdminHandler extends PFAHandler } } - protected function no_domain_field() { + protected function no_domain_field() + { # PFAHandler die()s if domain field is not set. Disable this behaviour for AdminHandler. } # init $this->struct, $this->db_table and $this->id_field - protected function initStruct() { + protected function initStruct() + { # NOTE: There are dependencies between domains and domain_count # NOTE: If you disable "display in list" for domain_count, the SQL query for domains might break. # NOTE: (Disabling both shouldn't be a problem.) @@ -90,7 +93,8 @@ class AdminHandler extends PFAHandler ); } - protected function initMsg() { + protected function initMsg() + { $this->msg['error_already_exists'] = 'admin_already_exists'; $this->msg['error_does_not_exist'] = 'admin_does_not_exist'; $this->msg['confirm_delete'] = 'confirm_delete_admin'; @@ -106,7 +110,8 @@ class AdminHandler extends PFAHandler } } - public function webformConfig() { + public function webformConfig() + { return array( # $PALANG labels 'formtitle_create' => 'pAdminCreate_admin_welcome', @@ -124,7 +129,8 @@ class AdminHandler extends PFAHandler * called by $this->store() after storing $this->values in the database * can be used to update additional tables, call scripts etc. */ - protected function postSave() : bool { + protected function postSave() : bool + { # store list of allowed domains in the domain_admins table if (isset($this->values['domains'])) { if (is_array($this->values['domains'])) { @@ -168,7 +174,8 @@ class AdminHandler extends PFAHandler return true; # TODO: don't hardcode } - protected function read_from_db_postprocess($db_result) { + protected function read_from_db_postprocess($db_result) + { foreach ($db_result as $key => $row) { # convert 'domains' field to an array if ($row['domains'] == '') { @@ -186,7 +193,8 @@ class AdminHandler extends PFAHandler /** * @return bool */ - public function delete() { + public function delete() + { if (! $this->view()) { $this->errormsg[] = Config::Lang($this->msg['error_does_not_exist']); return false; @@ -208,7 +216,8 @@ class AdminHandler extends PFAHandler * compare password / password2 field * error message will be displayed at the password2 field */ - protected function _validate_password2($field, $val) { + protected function _validate_password2($field, $val) + { return $this->compare_password_fields('password', 'password2'); } } diff --git a/model/AdminpasswordHandler.php b/model/AdminpasswordHandler.php index d4f7d4c6..5022830b 100644 --- a/model/AdminpasswordHandler.php +++ b/model/AdminpasswordHandler.php @@ -9,16 +9,19 @@ class AdminpasswordHandler extends PFAHandler # do not skip empty password fields protected $skip_empty_pass = false; - protected function no_domain_field() { + protected function no_domain_field() + { return true; } - protected function validate_new_id() { + protected function validate_new_id() + { return true; } # init $this->struct, $this->db_table and $this->id_field - protected function initStruct() { + protected function initStruct() + { # TODO: shorter PALANG labels ;-) $this->struct=array( @@ -36,7 +39,8 @@ class AdminpasswordHandler extends PFAHandler ); } - public function init($id) :bool { + public function init($id) :bool + { # hardcode to logged in admin if ($this->admin_username == '') { die("No admin logged in"); @@ -51,7 +55,8 @@ class AdminpasswordHandler extends PFAHandler return parent::init($this->id); } - public function initMsg() { + public function initMsg() + { $this->msg['error_already_exists'] = 'admin_already_exists'; # probably unused $this->msg['error_does_not_exist'] = 'admin_does_not_exist'; # probably unused $this->msg['confirm_delete'] = 'confirm_delete_admin'; # probably unused @@ -61,7 +66,8 @@ class AdminpasswordHandler extends PFAHandler $this->msg['successmessage'] = 'pPassword_result_success'; } - public function webformConfig() { + public function webformConfig() + { return array( # $PALANG labels 'formtitle_create' => 'pPassword_welcome', @@ -80,7 +86,8 @@ class AdminpasswordHandler extends PFAHandler /** * check if old password is correct */ - protected function _validate_oldpass($field, $val) { + protected function _validate_oldpass($field, $val) + { $l = new Login('admin'); if ($l->login($this->id, $val)) { return true; @@ -93,7 +100,8 @@ class AdminpasswordHandler extends PFAHandler /** * skip default validation (check if password is good enough) for old password */ - protected function _inp_pass($field, $val) { + protected function _inp_pass($field, $val) + { if ($field == 'oldpass') { return true; } @@ -105,7 +113,8 @@ class AdminpasswordHandler extends PFAHandler * compare password / password2 field * error message will be displayed at the password2 field */ - protected function _validate_password2($field, $val) { + protected function _validate_password2($field, $val) + { return $this->compare_password_fields('password', 'password2'); } } diff --git a/model/AliasHandler.php b/model/AliasHandler.php index 5554ca29..267c6986 100644 --- a/model/AliasHandler.php +++ b/model/AliasHandler.php @@ -17,7 +17,8 @@ class AliasHandler extends PFAHandler */ public $return = null; - protected function initStruct() { + protected function initStruct() + { # hide 'goto_mailbox' if $this->new # (for existing aliases, init() hides it for non-mailbox aliases) $mbgoto = 1 - $this->new; @@ -69,7 +70,8 @@ class AliasHandler extends PFAHandler * When using this function to optimize the is_mailbox extrafrom, don't forget to reset it to the default value * (all domains for this admin) afterwards. */ - private function set_is_mailbox_extrafrom($condition=array(), $searchmode=array()) { + private function set_is_mailbox_extrafrom($condition=array(), $searchmode=array()) + { $extrafrom = 'LEFT JOIN ( ' . ' SELECT 1 as __is_mailbox, username as __mailbox_username ' . ' FROM ' . table_by_key('mailbox') . @@ -89,7 +91,8 @@ class AliasHandler extends PFAHandler } - protected function initMsg() { + protected function initMsg() + { $this->msg['error_already_exists'] = 'email_address_already_exists'; $this->msg['error_does_not_exist'] = 'alias_does_not_exist'; $this->msg['confirm_delete'] = 'confirm_delete_alias'; @@ -107,7 +110,8 @@ class AliasHandler extends PFAHandler } - public function webformConfig() { + public function webformConfig() + { if ($this->new) { # the webform will display a localpart field + domain dropdown on $new $this->struct['address']['display_in_form'] = 0; $this->struct['localpart']['display_in_form'] = 1; @@ -137,7 +141,8 @@ class AliasHandler extends PFAHandler * AliasHandler needs some special handling in init() and therefore overloads the function. * It also calls parent::init() */ - public function init(string $id) : bool { + public function init(string $id) : bool + { $bits = explode('@', $id); if (sizeof($bits) == 2) { $local_part = $bits[0]; @@ -175,12 +180,14 @@ class AliasHandler extends PFAHandler return $retval; } - protected function domain_from_id() { + protected function domain_from_id() + { list(/*NULL*/, $domain) = explode('@', $this->id); return $domain; } - protected function validate_new_id() { + protected function validate_new_id() + { if ($this->id == '') { $this->errormsg[$this->id_field] = Config::lang('pCreate_alias_address_text_error1'); return false; @@ -217,7 +224,8 @@ class AliasHandler extends PFAHandler /** * check number of existing aliases for this domain - is one more allowed? */ - private function create_allowed($domain) { + private function create_allowed($domain) + { if ($this->called_by == 'MailboxHandler') { return true; } # always allow creating an alias for a mailbox @@ -241,7 +249,8 @@ class AliasHandler extends PFAHandler * merge localpart and domain to address * called by edit.php (if id_field is editable and hidden in editform) _before_ ->init */ - public function mergeId($values) { + public function mergeId($values) + { if ($this->struct['localpart']['display_in_form'] == 1 && $this->struct['domain']['display_in_form']) { # webform mode - combine to 'address' field if (empty($values['localpart']) || empty($values['domain'])) { # localpart or domain not set return ""; @@ -255,7 +264,8 @@ class AliasHandler extends PFAHandler } } - protected function setmore(array $values) { + protected function setmore(array $values) + { if ($this->new) { if ($this->struct['address']['display_in_form'] == 1) { # default mode - split off 'domain' field from 'address' # TODO: do this unconditional? list(/*NULL*/, $domain) = explode('@', $values['address']); @@ -304,12 +314,14 @@ class AliasHandler extends PFAHandler $this->values['goto'] = join(',', $values['goto']); } - protected function postSave() : bool { + protected function postSave() : bool + { # TODO: if alias belongs to a mailbox, update mailbox active status return true; } - protected function read_from_db_postprocess($db_result) { + protected function read_from_db_postprocess($db_result) + { foreach ($db_result as $key => $value) { # split comma-separated 'goto' into an array $goto = $db_result[$key]['goto'] ?? null; @@ -344,7 +356,8 @@ class AliasHandler extends PFAHandler return $db_result; } - private function condition_ignore_mailboxes($condition, $searchmode) { + private function condition_ignore_mailboxes($condition, $searchmode) + { # only list aliases that do not belong to mailboxes if (is_array($condition)) { $condition['__mailbox_username'] = 1; @@ -358,7 +371,8 @@ class AliasHandler extends PFAHandler return array($condition, $searchmode); } - public function getList($condition, $searchmode = array(), $limit=-1, $offset=-1) : bool { + public function getList($condition, $searchmode = array(), $limit=-1, $offset=-1) : bool + { list($condition, $searchmode) = $this->condition_ignore_mailboxes($condition, $searchmode); $this->set_is_mailbox_extrafrom($condition, $searchmode); $result = parent::getList($condition, $searchmode, $limit, $offset); @@ -366,7 +380,8 @@ class AliasHandler extends PFAHandler return $result; } - public function getPagebrowser($condition, $searchmode = array()) { + public function getPagebrowser($condition, $searchmode = array()) + { list($condition, $searchmode) = $this->condition_ignore_mailboxes($condition, $searchmode); $this->set_is_mailbox_extrafrom($condition, $searchmode); $result = parent::getPagebrowser($condition, $searchmode); @@ -376,7 +391,8 @@ class AliasHandler extends PFAHandler - protected function _validate_goto($field, $val) { + protected function _validate_goto($field, $val) + { if (count($val) == 0) { # empty is ok for mailboxes - this is checked in setmore() which can clear the error message $this->errormsg[$field] = Config::lang('pEdit_alias_goto_text_error1'); @@ -420,7 +436,8 @@ class AliasHandler extends PFAHandler /** * on $this->new, set localpart based on address */ - protected function _missing_localpart($field) { + protected function _missing_localpart($field) + { if (isset($this->RAWvalues['address'])) { $parts = explode('@', $this->RAWvalues['address']); if (count($parts) == 2) { @@ -432,7 +449,8 @@ class AliasHandler extends PFAHandler /** * on $this->new, set domain based on address */ - protected function _missing_domain($field) { + protected function _missing_domain($field) + { if (isset($this->RAWvalues['address'])) { $parts = explode('@', $this->RAWvalues['address']); if (count($parts) == 2) { @@ -449,7 +467,8 @@ class AliasHandler extends PFAHandler * * @return string an email alias. */ - protected function getVacationAlias() { + protected function getVacationAlias() + { $vacation_goto = str_replace('@', '#', $this->id); return $vacation_goto . '@' . Config::read_string('vacation_domain'); } @@ -457,7 +476,8 @@ class AliasHandler extends PFAHandler /** * @return boolean */ - public function delete() { + public function delete() + { if (! $this->view()) { $this->errormsg[] = Config::Lang('alias_does_not_exist'); return false; diff --git a/model/AliasdomainHandler.php b/model/AliasdomainHandler.php index d87cce9b..e6ef3fc8 100644 --- a/model/AliasdomainHandler.php +++ b/model/AliasdomainHandler.php @@ -11,7 +11,8 @@ class AliasdomainHandler extends PFAHandler protected $domain_field = 'alias_domain'; protected $searchfields = array('alias_domain', 'target_domain'); - protected function initStruct() { + protected function initStruct() + { $this->struct=array( # field name allow display in... type $PALANG label $PALANG description default / options / ... # editing? form list @@ -52,7 +53,8 @@ class AliasdomainHandler extends PFAHandler } } - public function init($id) : bool { + public function init($id) : bool + { $success = parent::init($id); if ($success) { if (count($this->struct['alias_domain']['options']) == 0 && $this->new) { @@ -64,7 +66,8 @@ class AliasdomainHandler extends PFAHandler return $success; } - protected function initMsg() { + protected function initMsg() + { $this->msg['error_already_exists'] = 'alias_domain_already_exists'; $this->msg['error_does_not_exist'] = 'alias_domain_does_not_exist'; $this->msg['confirm_delete'] = 'confirm_delete_aliasdomain'; @@ -80,7 +83,8 @@ class AliasdomainHandler extends PFAHandler } } - public function webformConfig() { + public function webformConfig() + { return array( # $PALANG labels 'formtitle_create' => 'pCreate_alias_domain_welcome', @@ -95,7 +99,8 @@ class AliasdomainHandler extends PFAHandler ); } - protected function validate_new_id() { + protected function validate_new_id() + { return true; # alias_domain is enum, so we don't need to check its syntax etc. } @@ -103,7 +108,8 @@ class AliasdomainHandler extends PFAHandler /** * @return boolean */ - public function delete() { + public function delete() + { if (! $this->view()) { $this->errormsg[] = 'An alias domain with that name does not exist!'; # TODO: make translatable? (will a user ever see this?) return false; @@ -121,7 +127,8 @@ class AliasdomainHandler extends PFAHandler * validate target_domain field - it must be != $this->id to avoid a loop * @return boolean */ - protected function _validate_target_domain($field, $val) { + protected function _validate_target_domain($field, $val) + { if ($val == $this->id) { $this->errormsg[$field] = Config::lang('alias_domain_to_itsself'); return false; diff --git a/model/CliDelete.php b/model/CliDelete.php index 19548c20..19bf88f5 100644 --- a/model/CliDelete.php +++ b/model/CliDelete.php @@ -10,7 +10,8 @@ class CliDelete extends Shell /** * Execution method always used for tasks */ - public function execute() { + public function execute() + { if (empty($this->args)) { return $this->__interactive(); } @@ -23,7 +24,8 @@ class CliDelete extends Shell /** * Interactive mode */ - protected function __interactive() { + protected function __interactive() + { $module = preg_replace('/Handler$/', '', $this->handler_to_use); $module = strtolower($module); @@ -43,7 +45,8 @@ class CliDelete extends Shell * * @param string address to delete */ - protected function __handle($address) { + protected function __handle($address) + { $handler = new $this->handler_to_use($this->new); if (!$handler->init($address)) { @@ -64,7 +67,8 @@ class CliDelete extends Shell * * @access public */ - public function help() { + public function help() + { $module = preg_replace('/Handler$/', '', $this->handler_to_use); $module = strtolower($module); diff --git a/model/CliEdit.php b/model/CliEdit.php index 37562090..b4526a85 100644 --- a/model/CliEdit.php +++ b/model/CliEdit.php @@ -15,7 +15,8 @@ class CliEdit extends Shell /** * Execution method always used for tasks */ - public function execute() { + public function execute() + { if (empty($this->args)) { return $this->__interactive(); } else { @@ -28,7 +29,8 @@ class CliEdit extends Shell * read, check and handle all --* parameters * The list of allowed params is based on $handler->struct */ - private function __handle_params() { + private function __handle_params() + { $handler = new $this->handler_to_use($this->new); $form_fields = $handler->getStruct(); $id_field = $handler->getId_field(); @@ -69,7 +71,8 @@ class CliEdit extends Shell /** * Interactive mode */ - private function __interactive() { + private function __interactive() + { $handler = new $this->handler_to_use($this->new); $form_fields = $handler->getStruct(); @@ -175,7 +178,8 @@ class CliEdit extends Shell /** * (try to) store values */ - private function __handle($id, $values) { + private function __handle($id, $values) + { $handler = new $this->handler_to_use($this->new); if (!$handler->init($id)) { $this->err($handler->errormsg); @@ -201,7 +205,8 @@ class CliEdit extends Shell /** * Displays help contents */ - public function help() { + public function help() + { if ($this->new) { $cmd = 'add'; $cmdtext = 'Adds'; diff --git a/model/CliHelp.php b/model/CliHelp.php index 7beff060..664e3594 100644 --- a/model/CliHelp.php +++ b/model/CliHelp.php @@ -10,11 +10,13 @@ class CliHelp extends Shell * * @access public */ - public function execute() { + public function execute() + { $this->help(); } - public function help() { + public function help() + { $handler = new $this->handler_to_use; # TODO: adjust help text according to $handler->taskNames diff --git a/model/CliScheme.php b/model/CliScheme.php index e68a0251..ddd9135c 100644 --- a/model/CliScheme.php +++ b/model/CliScheme.php @@ -15,7 +15,8 @@ class CliScheme extends Shell /** * Execution method always used for tasks */ - public function execute() { + public function execute() + { $module = preg_replace('/Handler$/', '', $this->handler_to_use); $module = strtolower($module); @@ -82,7 +83,8 @@ class CliScheme extends Shell /** * Displays help contents */ - public function help() { + public function help() + { $module = preg_replace('/Handler$/', '', $this->handler_to_use); $module = strtolower($module); diff --git a/model/CliView.php b/model/CliView.php index 9b25cf3d..8c0df2a2 100644 --- a/model/CliView.php +++ b/model/CliView.php @@ -10,7 +10,8 @@ class CliView extends Shell /** * Execution method always used for tasks */ - public function execute() { + public function execute() + { if (empty($this->args)) { return $this->__interactive(); } @@ -23,7 +24,8 @@ class CliView extends Shell /** * Interactive mode */ - protected function __interactive() { + protected function __interactive() + { $module = preg_replace('/Handler$/', '', $this->handler_to_use); $module = strtolower($module); @@ -38,7 +40,8 @@ class CliView extends Shell * * @param string address to view */ - protected function __handle($address) { + protected function __handle($address) + { $handler = new $this->handler_to_use($this->new); if (!$handler->init($address)) { @@ -88,7 +91,8 @@ class CliView extends Shell * * @access public */ - public function help() { + public function help() + { $module = preg_replace('/Handler$/', '', $this->handler_to_use); $module = strtolower($module); diff --git a/model/Config.php b/model/Config.php index 30025894..f33c4cee 100644 --- a/model/Config.php +++ b/model/Config.php @@ -21,7 +21,8 @@ final class Config * Return a singleton instance of Config * @return Config */ - public static function getInstance() { + public static function getInstance() + { if (self::$instance == null) { self::$instance = new self(); } @@ -35,7 +36,8 @@ final class Config * @param mixed $value to set for key. * @return void */ - public static function write(string $key, $value = null) { + public static function write(string $key, $value = null) + { $_this = self::getInstance(); $newConfig = $_this->getAll(); $newConfig[$key] = $value; @@ -46,7 +48,8 @@ final class Config * @param string $var * @return array */ - public static function read_array(string $var) : array { + public static function read_array(string $var) : array + { $stuff = self::read($var); if (!is_array($stuff)) { @@ -56,7 +59,8 @@ final class Config return $stuff; } - public static function has(string $var) : bool { + public static function has(string $var) : bool + { $x = self::getInstance()->getAll(); return array_key_exists($var, $x); } @@ -64,7 +68,8 @@ final class Config * @param string $var * @return string */ - public static function read_string(string $var) : string { + public static function read_string(string $var) : string + { $stuff = self::read($var); if ($stuff === null) { @@ -83,7 +88,8 @@ final class Config * @param string $var Variable to obtain * @return callable|array|string|null|bool some value */ - public static function read(string $var) { + public static function read(string $var) + { $_this = self::getInstance(); $config = $_this->getAll(); @@ -111,7 +117,8 @@ final class Config * @param string $value Value to use as sprintf parameter * @return string value of Config::$var, parsed by sprintf */ - public static function read_f(string $var, string $value) : string { + public static function read_f(string $var, string $value) : string + { $text = self::read_string($var); $newtext = sprintf($text, $value); @@ -134,7 +141,8 @@ final class Config * @param string $var Variable to obtain * @return bool value of Configure::$var (TRUE (on YES/yes) or FALSE (on NO/no/not set/unknown value) */ - public static function bool(string $var) : bool { + public static function bool(string $var) : bool + { $value = self::read($var); if (is_bool($value)) { @@ -165,7 +173,8 @@ final class Config * Used to read Config::$var, converted to bool, returned as integer (0 or 1) * @see bool() */ - public static function intbool($var) : int { + public static function intbool($var) : int + { return Config::bool($var) ? 1 : 0; } @@ -178,7 +187,8 @@ final class Config * @return string value of $PALANG[$var] * @access public */ - public static function lang(string $var) : string { + public static function lang(string $var) : string + { $languages = self::read_array('__LANG'); $value = $languages[$var] ?? ''; @@ -198,7 +208,8 @@ final class Config * @param string $value Value to use as sprintf parameter * @return string value of $PALANG[$var], parsed by sprintf */ - public static function lang_f(string $var, $value) : string { + public static function lang_f(string $var, $value) : string + { $all = self::read_array('__LANG'); $text = $all[$var] ?? ''; @@ -216,14 +227,16 @@ final class Config /** * @return array */ - public function getAll() : array { + public function getAll() : array + { return $this->config; } /** * @param array $config */ - public function setAll(array $config) { + public function setAll(array $config) + { $this->config = $config; } } diff --git a/model/DomainHandler.php b/model/DomainHandler.php index 15c10e4e..7cf1e756 100644 --- a/model/DomainHandler.php +++ b/model/DomainHandler.php @@ -10,7 +10,8 @@ class DomainHandler extends PFAHandler protected $id_field = 'domain'; protected $domain_field = 'domain'; - protected function validate_new_id() { + protected function validate_new_id() + { $domain_check = check_domain($this->id); if ($domain_check != '') { @@ -27,7 +28,8 @@ class DomainHandler extends PFAHandler return true; } - protected function initStruct() { + protected function initStruct() + { # TODO: shorter PALANG labels ;-) $super = $this->is_superadmin; @@ -117,7 +119,8 @@ class DomainHandler extends PFAHandler ); } - protected function initMsg() { + protected function initMsg() + { $this->msg['error_already_exists'] = 'pAdminCreate_domain_domain_text_error'; $this->msg['error_does_not_exist'] = 'domain_does_not_exist'; $this->msg['confirm_delete'] = 'confirm_delete_domain'; @@ -134,7 +137,8 @@ class DomainHandler extends PFAHandler $this->msg['can_create'] = $this->is_superadmin; } - public function webformConfig() { + public function webformConfig() + { return array( # $PALANG labels 'formtitle_create' => 'pAdminCreate_domain_welcome', @@ -149,7 +153,8 @@ class DomainHandler extends PFAHandler } - protected function preSave() : bool { + protected function preSave() : bool + { # TODO: is this function superfluous? _can_edit should already cover this if ($this->is_superadmin) { return true; @@ -162,7 +167,8 @@ class DomainHandler extends PFAHandler * called by $this->store() after storing $this->values in the database * can be used to update additional tables, call scripts etc. */ - protected function postSave() : bool { + protected function postSave() : bool + { if ($this->new && $this->values['default_aliases']) { foreach (Config::read_array('default_aliases') as $address=>$goto) { $address = $address . "@" . $this->id; @@ -194,7 +200,8 @@ class DomainHandler extends PFAHandler /** * @return bool */ - public function delete() { + public function delete() + { # TODO: check for _can_delete instead if (! $this->is_superadmin) { $this->errormsg[] = Config::Lang_f('no_delete_permissions', $this->id); @@ -256,13 +263,16 @@ class DomainHandler extends PFAHandler * * @param array values of current item */ - public function _formatted_aliases($item) { + public function _formatted_aliases($item) + { return $item['alias_count'] . ' / ' . $item['aliases'] ; } - public function _formatted_mailboxes($item) { + public function _formatted_mailboxes($item) + { return $item['mailbox_count'] . ' / ' . $item['mailboxes']; } - public function _formatted_quota($item) { + public function _formatted_quota($item) + { return $item['total_quota'] . ' / ' . $item['quota'] ; } @@ -271,7 +281,8 @@ class DomainHandler extends PFAHandler * * @return boolean */ - protected function domain_postcreation() { + protected function domain_postcreation() + { $script=Config::read_string('domain_postcreation_script'); if (empty($script)) { @@ -303,7 +314,8 @@ class DomainHandler extends PFAHandler * * @return boolean */ - protected function domain_postdeletion() { + protected function domain_postdeletion() + { $script=Config::read_string('domain_postdeletion_script'); if (empty($script)) { diff --git a/model/FetchmailHandler.php b/model/FetchmailHandler.php index c223e430..77e7f353 100644 --- a/model/FetchmailHandler.php +++ b/model/FetchmailHandler.php @@ -12,7 +12,8 @@ class FetchmailHandler extends PFAHandler protected $order_by = 'domain, mailbox'; - protected function initStruct() { + protected function initStruct() + { $src_auth_options = array('password','kerberos_v5','kerberos','kerberos_v4','gssapi','cram-md5','otp','ntlm','msn','ssh','any'); $src_protocol_options = array('POP3','IMAP','POP2','ETRN','AUTO'); @@ -54,7 +55,8 @@ class FetchmailHandler extends PFAHandler $this->struct['mailbox']['options'] = array_keys($handler->result); } - protected function initMsg() { + protected function initMsg() + { $this->msg['error_already_exists'] = 'fetchmail_already_exists'; $this->msg['error_does_not_exist'] = 'fetchmail_does_not_exist'; $this->msg['confirm_delete'] = 'confirm_delete_fetchmail'; @@ -70,7 +72,8 @@ class FetchmailHandler extends PFAHandler } } - public function webformConfig() { + public function webformConfig() + { return array( # $PALANG labels 'formtitle_create' => 'pMenu_fetchmail', @@ -86,7 +89,8 @@ class FetchmailHandler extends PFAHandler } - protected function setmore(array $values) { + protected function setmore(array $values) + { # set domain based on the target mailbox if ($this->new || isset($values['mailbox'])) { list(/*NULL*/, $domain) = explode('@', $values['mailbox']); @@ -95,7 +99,8 @@ class FetchmailHandler extends PFAHandler } } - protected function validate_new_id() { + protected function validate_new_id() + { # auto_increment - any non-empty ID is an error if ($this->id != '') { $this->errormsg[$this->id_field] = 'auto_increment value, you must pass an empty string!'; @@ -110,7 +115,8 @@ class FetchmailHandler extends PFAHandler /** * @return boolean */ - public function delete() { + public function delete() + { if (! $this->view()) { $this->errormsg[] = Config::lang($this->msg['error_does_not_exist']); return false; @@ -128,7 +134,8 @@ class FetchmailHandler extends PFAHandler /** * validate src_server - must be non-empty and survive check_domain() */ - protected function _validate_src_server($field, $val) { + protected function _validate_src_server($field, $val) + { if ($val == '') { $msg = Config::Lang('pFetchmail_server_missing'); } else { @@ -148,7 +155,8 @@ class FetchmailHandler extends PFAHandler * (we can't assume anything about valid usernames and passwords on remote * servers, so the validation can't be more strict) */ - protected function _validate_src_user($field, $val) { + protected function _validate_src_user($field, $val) + { if ($val == '') { $this->errormsg[$field] = Config::lang('pFetchmail_user_missing'); return false; @@ -156,7 +164,8 @@ class FetchmailHandler extends PFAHandler return true; } - protected function _validate_src_password($field, $val) { + protected function _validate_src_password($field, $val) + { if ($val == '') { $this->errormsg[$field] = Config::lang('pFetchmail_password_missing'); return false; @@ -167,7 +176,8 @@ class FetchmailHandler extends PFAHandler /** * validate poll interval - must be numeri and > 0 */ - protected function _validate_poll_time($field, $val) { + protected function _validate_poll_time($field, $val) + { # must be > 0 if ($val < 1) { $this->errormsg[$field] = Config::Lang_f('must_be_numeric_bigger_than_null', $field); @@ -176,7 +186,8 @@ class FetchmailHandler extends PFAHandler return true; } - public function domain_from_id() { + public function domain_from_id() + { return ''; } } diff --git a/model/Login.php b/model/Login.php index d14ab6c8..4018d867 100644 --- a/model/Login.php +++ b/model/Login.php @@ -5,7 +5,8 @@ class Login private $key_table; private $table; - public function __construct(string $tableName) { + public function __construct(string $tableName) + { $ok = ['mailbox', 'admin']; if (!in_array($tableName, $ok)) { @@ -22,7 +23,8 @@ class Login * @param string $password * @return boolean true on successful login (i.e. password matches etc) */ - public function login($username, $password): bool { + public function login($username, $password): bool + { $active = db_get_boolean(true); $query = "SELECT password FROM {$this->key_table} WHERE username = :username AND active = :active"; @@ -62,7 +64,8 @@ class Login * @return false|string * @throws Exception */ - public function generatePasswordRecoveryCode(string $username) { + public function generatePasswordRecoveryCode(string $username) + { $sql = "SELECT count(1) FROM {$this->key_table} WHERE username = :username AND active = :active"; $active = db_get_boolean(true); @@ -100,7 +103,8 @@ class Login * @return boolean true on success; false on failure * @throws \Exception if invalid user, or db update fails. */ - public function changePassword($username, $new_password, $old_password): bool { + public function changePassword($username, $new_password, $old_password): bool + { list(/*NULL*/, $domain) = explode('@', $username); if (!$this->login($username, $old_password)) { diff --git a/model/MailboxHandler.php b/model/MailboxHandler.php index cded14be..e907eb0f 100644 --- a/model/MailboxHandler.php +++ b/model/MailboxHandler.php @@ -12,7 +12,8 @@ class MailboxHandler extends PFAHandler protected $searchfields = array('username'); # init $this->struct, $this->db_table and $this->id_field - protected function initStruct() { + protected function initStruct() + { $passwordReset = (int) ( Config::bool('forgotten_user_password_reset') && !Config::read('mailbox_postpassword_script') ); $reset_by_sms = 0; if ($passwordReset && Config::read_string('sms_send_function')) { @@ -65,7 +66,8 @@ class MailboxHandler extends PFAHandler } } - public function init($id) : bool { + public function init($id) : bool + { if (!parent::init($id)) { return false; } @@ -81,7 +83,8 @@ class MailboxHandler extends PFAHandler return true; # still here? good. } - protected function domain_from_id() { + protected function domain_from_id() + { list(/*NULL*/, $domain) = explode('@', $this->id); return $domain; } @@ -91,7 +94,8 @@ class MailboxHandler extends PFAHandler * @param string - domain * @param int - current quota */ - protected function updateMaxquota($domain, $currentquota) { + protected function updateMaxquota($domain, $currentquota) + { if ($domain == '') { return false; } @@ -107,7 +111,8 @@ class MailboxHandler extends PFAHandler } } - protected function initMsg() { + protected function initMsg() + { $this->msg['error_already_exists'] = 'email_address_already_exists'; $this->msg['error_does_not_exist'] = 'pCreate_mailbox_username_text_error1'; $this->msg['confirm_delete'] = 'confirm_delete_mailbox'; @@ -123,7 +128,8 @@ class MailboxHandler extends PFAHandler } } - public function webformConfig() { + public function webformConfig() + { if ($this->new) { # the webform will display a local_part field + domain dropdown on $new $this->struct['username']['display_in_form'] = 0; $this->struct['local_part']['display_in_form'] = 1; @@ -145,7 +151,8 @@ class MailboxHandler extends PFAHandler } - protected function validate_new_id() { + protected function validate_new_id() + { if ($this->id == '') { $this->errormsg[$this->id_field] = Config::lang('pCreate_mailbox_username_text_error1'); return false; @@ -180,7 +187,8 @@ class MailboxHandler extends PFAHandler /** * check number of existing mailboxes for this domain - is one more allowed? */ - private function create_allowed($domain) { + private function create_allowed($domain) + { $limit = get_domain_properties($domain); if ($limit['mailboxes'] == 0) { @@ -199,7 +207,8 @@ class MailboxHandler extends PFAHandler * merge local_part and domain to address * called by edit.php (if id_field is editable and hidden in editform) _before_ ->init */ - public function mergeId($values) { + public function mergeId($values) + { if ($this->struct['local_part']['display_in_form'] == 1 && $this->struct['domain']['display_in_form']) { # webform mode - combine to 'address' field return $values['local_part'] . '@' . $values['domain']; } else { @@ -208,7 +217,8 @@ class MailboxHandler extends PFAHandler } - protected function read_from_db_postprocess($db_result) { + protected function read_from_db_postprocess($db_result) + { foreach ($db_result as $key => $row) { if (isset($row['quota']) && is_numeric($row['quota']) && $row['quota'] > -1) { # quota could be disabled in $struct $db_result[$key]['quotabytes'] = $row['quota']; @@ -222,7 +232,8 @@ class MailboxHandler extends PFAHandler } - protected function preSave() : bool { + protected function preSave() : bool + { if (isset($this->values['quota']) && $this->values['quota'] != -1 && is_numeric($this->values['quota'])) { $multiplier = Config::read_string('quota_multiplier'); if ($multiplier == 0 || !is_numeric($multiplier)) { // or empty string, or null, or false... @@ -280,14 +291,16 @@ class MailboxHandler extends PFAHandler return true; } - protected function setmore(array $values) { + protected function setmore(array $values) + { if (array_key_exists('quota', $this->values)) { $this->values['quota'] = (int)$this->values['quota']; } } // Could perhaps also use _validate_local_part($new_value) { .... } - public function set(array $values) { + public function set(array $values) + { // See: https://github.com/postfixadmin/postfixadmin/issues/282 - ensure the 'local_part' does not contain an @ sign. $ok = true; if (isset($values['local_part']) && strpos($values['local_part'], '@')) { @@ -297,7 +310,8 @@ class MailboxHandler extends PFAHandler return $ok && parent::set($values); } - protected function postSave() : bool { + protected function postSave() : bool + { if ($this->new) { if (!$this->mailbox_post_script()) { # return false; # TODO: should this be fatal? @@ -343,7 +357,8 @@ class MailboxHandler extends PFAHandler return true; # even if a hook failed, mark the overall operation as OK } - public function delete() { + public function delete() + { if (! $this->view()) { $this->errormsg[] = Config::Lang('pFetchmail_invalid_mailbox'); # TODO: can users hit this message at all? init() should already fail... return false; @@ -373,7 +388,8 @@ class MailboxHandler extends PFAHandler - protected function _prefill_domain($field, $val) { + protected function _prefill_domain($field, $val) + { if (in_array($val, $this->struct[$field]['options'])) { $this->struct[$field]['default'] = $val; $this->updateMaxquota($val, 0); @@ -383,7 +399,8 @@ class MailboxHandler extends PFAHandler /** * check if quota is allowed */ - protected function _validate_quota($field, $val) { + protected function _validate_quota($field, $val) + { if (!$this->check_quota($val)) { $this->errormsg[$field] = Config::lang('pEdit_mailbox_quota_text_error'); return false; @@ -396,7 +413,8 @@ class MailboxHandler extends PFAHandler * - autogenerate password if enabled in config and $new * - display password on $new if enabled in config or autogenerated */ - protected function _validate_password($field, $val) { + protected function _validate_password($field, $val) + { if (!$this->_validate_password2($field, $val)) { return false; } @@ -419,14 +437,16 @@ class MailboxHandler extends PFAHandler * compare password / password2 field * error message will be displayed at the password2 field */ - protected function _validate_password2($field, $val) { + protected function _validate_password2($field, $val) + { return $this->compare_password_fields('password', 'password2'); } /** * on $this->new, set localpart based on address */ - protected function _missing_local_part($field) { + protected function _missing_local_part($field) + { list($local_part, $domain) = explode('@', $this->id); $this->RAWvalues['local_part'] = $local_part; } @@ -434,7 +454,8 @@ class MailboxHandler extends PFAHandler /** * on $this->new, set domain based on address */ - protected function _missing_domain($field) { + protected function _missing_domain($field) + { list($local_part, $domain) = explode('@', $this->id); $this->RAWvalues['domain'] = $domain; } @@ -447,7 +468,8 @@ class MailboxHandler extends PFAHandler /** * calculate maildir path for the mailbox */ - protected function _missing_maildir($field) { + protected function _missing_maildir($field) + { list($local_part, $domain) = explode('@', $this->id); $maildir_name_hook = Config::read('maildir_name_hook'); @@ -468,7 +490,8 @@ class MailboxHandler extends PFAHandler $this->RAWvalues['maildir'] = $maildir; } - private function send_welcome_mail() { + private function send_welcome_mail() + { $fTo = $this->id; $fFrom = smtp_get_admin_email(); if (empty($fFrom) || $fFrom == 'CLI') { @@ -493,7 +516,8 @@ class MailboxHandler extends PFAHandler * @return boolean - true if requested quota is OK, otherwise false * @todo merge with allowed_quota? */ - protected function check_quota($quota) { + protected function check_quota($quota) + { if (!Config::bool('quota')) { return true; # enforcing quotas is disabled - just allow it } @@ -547,7 +571,8 @@ class MailboxHandler extends PFAHandler * @param int $current_user_quota (in bytes) * @return int allowed maximum quota (in MB) */ - protected function allowed_quota($domain, $current_user_quota) { + protected function allowed_quota($domain, $current_user_quota) + { if (!Config::bool('quota')) { return 0; # quota disabled means no limits - no need for more checks } @@ -575,7 +600,8 @@ class MailboxHandler extends PFAHandler * * @return boolean success/failure status */ - protected function mailbox_post_script() { + protected function mailbox_post_script() + { if ($this->new) { $cmd = Config::read_string('mailbox_postcreation_script'); $warnmsg = Config::Lang('mailbox_postcreate_failed'); @@ -647,7 +673,8 @@ class MailboxHandler extends PFAHandler * @return boolean true on success, false on failure * also adds a detailed error message to $this->errormsg[] */ - protected function mailbox_postdeletion() { + protected function mailbox_postdeletion() + { $cmd = Config::read_string('mailbox_postdeletion_script'); if (empty($cmd)) { @@ -695,7 +722,8 @@ class MailboxHandler extends PFAHandler * * @return boolean TRUE if everything succeeds, FALSE on all errors */ - protected function create_mailbox_subfolders() { + protected function create_mailbox_subfolders() + { $create_mailbox_subdirs = Config::read('create_mailbox_subdirs'); if (empty($create_mailbox_subdirs)) { return true; diff --git a/model/PFAHandler.php b/model/PFAHandler.php index 04ae346f..a8a68e39 100644 --- a/model/PFAHandler.php +++ b/model/PFAHandler.php @@ -167,7 +167,8 @@ abstract class PFAHandler * @param string $username - if an admin_username is specified, permissions will be restricted to the domains this admin may manage * @param int $is_admin - 0 if logged in as user, 1 if logged in as admin or superadmin */ - public function __construct($new = 0, $username = "", $is_admin = 1) { + public function __construct($new = 0, $username = "", $is_admin = 1) + { # set label_field if not explicitely set if (empty($this->id_field)) { throw new \InvalidArgumentException("id_field must be defined"); @@ -253,7 +254,8 @@ abstract class PFAHandler * * to intentionally disable the check if $this->domain_field is empty, override this function */ - protected function no_domain_field() { + protected function no_domain_field() + { if ($this->admin_username != "") { die('Attemp to restrict domains without setting $this->domain_field!'); } @@ -264,7 +266,8 @@ abstract class PFAHandler * * to intentionally disable the check if $this->user_field is empty, override this function */ - protected function no_user_field() { + protected function no_user_field() + { if ($this->username != '') { die('Attemp to restrict users without setting $this->user_field!'); } @@ -330,7 +333,8 @@ abstract class PFAHandler * * @param string calling class */ - public function calledBy($calling_class) { + public function calledBy($calling_class) + { $this->called_by = $calling_class; } @@ -338,7 +342,8 @@ abstract class PFAHandler * initialize with $id and check if it is valid * @param string $id */ - public function init(string $id) : bool { + public function init(string $id) : bool + { // postfix treats address lookups (aliases, mailboxes) as if they were lowercase. // MySQL is normally case insenstive, PostgreSQL is case sensitive. @@ -388,7 +393,8 @@ abstract class PFAHandler * must be overridden if $id_field != $domain_field * @return string the domain to use for logging */ - protected function domain_from_id() { + protected function domain_from_id() + { if ($this->id_field == $this->domain_field) { return $this->id; } elseif ($this->domain_field == "") { @@ -404,7 +410,8 @@ abstract class PFAHandler * @param string $field - field * @param string $val - prefill value */ - public function prefill($field, $val) { + public function prefill($field, $val) + { $func="_prefill_".$field; if (method_exists($this, $func)) { $this->{$func}($field, $val); # call _missing_$fieldname() @@ -419,7 +426,8 @@ abstract class PFAHandler * @return bool - true if all values are valid, otherwise false * error messages (if any) are stored in $this->errormsg */ - public function set(array $values) { + public function set(array $values) + { if (!$this->can_edit) { $this->errormsg[] = Config::Lang_f('edit_not_allowed', $this->label); return false; @@ -522,7 +530,8 @@ abstract class PFAHandler * can be used to update additional columns etc. * hint: modify $this->values and $this->errormsg directly as needed */ - protected function setmore(array $values) { + protected function setmore(array $values) + { # do nothing } @@ -535,7 +544,8 @@ abstract class PFAHandler * @return bool - true if all values were stored in the database, otherwise false * error messages (if any) are stored in $this->errormsg */ - public function save() : bool { + public function save() : bool + { # backwards compability: save() was once (up to 3.2.x) named store(). If a child class still uses the old name, let it override save(). if (method_exists($this, 'store')) { error_log('store() is deprecated, please rename it to save()'); @@ -609,7 +619,8 @@ abstract class PFAHandler * called by $this->save() before storing the values in the database * @return bool - if false, save() will abort */ - protected function preSave() : bool { + protected function preSave() : bool + { # backwards compability: preSave() was once (up to 3.2.x) named beforestore(). If a child class still uses the old name, let it override preSave(). # Note: if a child class also has preSave(), it will override this function and obviously also the compability code. if (method_exists($this, 'beforestore')) { @@ -624,7 +635,8 @@ abstract class PFAHandler * called by $this->save() after storing $this->values in the database * can be used to update additional tables, call scripts etc. */ - protected function postSave() : bool { + protected function postSave() : bool + { # backwards compability: postSave() was once (up to 3.2.x) named storemore(). If a child class still uses the old name, let it override postSave(). # Note: if a child class also has postSave(), it will override this function and obviously also the compability code. if (method_exists($this, 'storemore')) { @@ -648,7 +660,8 @@ abstract class PFAHandler * @param array searchmode - operators to use (=, <, >) if $condition is an array. Defaults to = if not specified for a field. * @return array - contains query parts */ - protected function build_select_query($condition, $searchmode) { + protected function build_select_query($condition, $searchmode) + { $select_cols = array(); $yes = escape_string(Config::lang('YES')); @@ -737,7 +750,8 @@ abstract class PFAHandler * @param array searchmode - (see build_select_query() for details) * @return array - pagebrowser keys ("aa-cz", "de-pf", ...) */ - public function getPagebrowser($condition, $searchmode) { + public function getPagebrowser($condition, $searchmode) + { $queryparts = $this->build_select_query($condition, $searchmode); return create_page_browser($this->label_field, $queryparts['from_where_order']); } @@ -756,7 +770,8 @@ abstract class PFAHandler * @param int $offset - number of first row to return * @return array - rows (as associative array, with the ID as key) */ - protected function read_from_db($condition, $searchmode = array(), $limit=-1, $offset=-1) : array { + protected function read_from_db($condition, $searchmode = array(), $limit=-1, $offset=-1) : array + { $queryparts = $this->build_select_query($condition, $searchmode); $query = $queryparts['select_cols'] . $queryparts['from_where_order']; @@ -785,7 +800,8 @@ abstract class PFAHandler * @param array $db_result * @return array */ - protected function read_from_db_postprocess($db_result) { + protected function read_from_db_postprocess($db_result) + { return $db_result; } @@ -797,7 +813,8 @@ abstract class PFAHandler * The data is stored in $this->result (as associative array of column => value) * error messages (if any) are stored in $this->errormsg */ - public function view($errors=true) { + public function view($errors=true) + { $result = $this->read_from_db(array($this->id_field => $this->id)); if (count($result) == 1) { $this->result = reset($result); @@ -821,7 +838,8 @@ abstract class PFAHandler * @return bool - always true, no need to check ;-) (if $result is not an array, getList die()s) * The data is stored in $this->result (as array of rows, each row is an associative array of column => value) */ - public function getList($condition, $searchmode = array(), $limit=-1, $offset=-1) : bool { + public function getList($condition, $searchmode = array(), $limit=-1, $offset=-1) : bool + { if (is_array($condition)) { $real_condition = array(); foreach ($condition as $key => $value) { @@ -849,7 +867,8 @@ abstract class PFAHandler * @param string $token * @return boolean true on success (i.e. code matches etc) */ - public function checkPasswordRecoveryCode($username, $token) { + public function checkPasswordRecoveryCode($username, $token) + { $table = table_by_key($this->db_table); $active = db_get_boolean(true); @@ -878,22 +897,26 @@ abstract class PFAHandler /************************************************************************** * functions to read protected variables */ - public function getStruct() { + public function getStruct() + { return $this->struct; } - public function getMsg() { + public function getMsg() + { return $this->msg; } - public function getId_field() { + public function getId_field() + { return $this->id_field; } /** * @return mixed return value of previously called method */ - public function result() { + public function result() + { return $this->result; } @@ -904,7 +927,8 @@ abstract class PFAHandler * @param string $field1 - "password" field * @param string $field2 - "repeat password" field */ - protected function compare_password_fields($field1, $field2) { + protected function compare_password_fields($field1, $field2) + { if ($this->RAWvalues[$field1] == $this->RAWvalues[$field2]) { unset($this->errormsg[$field2]); # no need to warn about too short etc. passwords - it's enough to display this message at the 'password' field return true; @@ -919,7 +943,8 @@ abstract class PFAHandler * @param string $field - fieldname * @return void */ - protected function set_default_value($field) { + protected function set_default_value($field) + { if (isset($this->struct[$field]['default'])) { $this->RAWvalues[$field] = $this->struct[$field]['default']; } @@ -939,7 +964,8 @@ abstract class PFAHandler * @param string $val * @return boolean */ - protected function _inp_num($field, $val) { + protected function _inp_num($field, $val) + { $valid = is_numeric($val); if ($val < -1) { $valid = false; @@ -957,7 +983,8 @@ abstract class PFAHandler * @param string $val * @return boolean */ - protected function _inp_bool($field, $val) { + protected function _inp_bool($field, $val) + { if ($val == "0" || $val == "1") { return true; } @@ -972,7 +999,8 @@ abstract class PFAHandler * @param string $val * @return boolean */ - protected function _inp_enum($field, $val) { + protected function _inp_enum($field, $val) + { if (in_array($val, $this->struct[$field]['options'])) { return true; } @@ -986,7 +1014,8 @@ abstract class PFAHandler * @param string $val * @return boolean */ - protected function _inp_enma($field, $val) { + protected function _inp_enma($field, $val) + { if (array_key_exists($val, $this->struct[$field]['options'])) { return true; } @@ -1000,7 +1029,8 @@ abstract class PFAHandler * @param string $val * @return boolean */ - protected function _inp_pass($field, $val) { + protected function _inp_pass($field, $val) + { $validpass = validate_password($val); # returns array of error messages, or empty array on success if (count($validpass) == 0) { diff --git a/model/PFASmarty.php b/model/PFASmarty.php index 9fb394d7..1a29fe40 100644 --- a/model/PFASmarty.php +++ b/model/PFASmarty.php @@ -11,7 +11,8 @@ class PFASmarty */ protected $template; - public static function getInstance() { + public static function getInstance() + { if (self::$instance) { return self::$instance; } @@ -21,7 +22,8 @@ class PFASmarty } - private function __construct() { + private function __construct() + { $CONF = Config::getInstance()->getAll(); $theme = ''; @@ -57,7 +59,8 @@ class PFASmarty /** * @param string $rel_path - relative path for referenced css etc dependencies - e.g. users/edit.php needs '../' else, it's ''. */ - public function configureTheme(string $rel_path = '') { + public function configureTheme(string $rel_path = '') + { $CONF = Config::getInstance()->getAll(); // see: https://github.com/postfixadmin/postfixadmin/issues/410 @@ -87,7 +90,8 @@ class PFASmarty * @param mixed $value * @param bool $sanitise */ - public function assign($key, $value, $sanitise = true) { + public function assign($key, $value, $sanitise = true) + { $this->template->assign("RAW_$key", $value); if ($sanitise == false) { return $this->template->assign($key, $value); @@ -101,7 +105,8 @@ class PFASmarty * @param string $template * @return void */ - public function display($template) { + public function display($template) + { $CONF = Config::getInstance()->getAll(); $this->assign('PALANG', $CONF['__LANG'] ?? []); @@ -129,7 +134,8 @@ class PFASmarty * @param mixed $data - array or primitive type; objects not supported. * @return mixed $data * */ - public function sanitise($data) { + public function sanitise($data) + { if (is_object($data)) { return $data; // can't handle } diff --git a/model/Shell.php b/model/Shell.php index fbc18ab6..0021491a 100644 --- a/model/Shell.php +++ b/model/Shell.php @@ -103,7 +103,8 @@ class Shell * Constructs this Shell instance. * */ - public function __construct(&$dispatch) { + public function __construct(&$dispatch) + { $vars = array('params', 'args', 'shell', 'shellCommand'=> 'command'); foreach ($vars as $key => $var) { if (is_string($key)) { @@ -129,7 +130,8 @@ class Shell * * @access public */ - public function startup() { + public function startup() + { if (empty($this->params['q'])) { $this->_welcome(); } @@ -139,7 +141,8 @@ class Shell * * @access protected */ - public function _welcome() { + public function _welcome() + { $this->out("\nWelcome to Postfixadmin-CLI v" . $this->Dispatch->version); $this->hr(); } @@ -152,7 +155,8 @@ class Shell * @param string $default Default input value. * @return string either the default value, or the user-provided input. */ - public function in($prompt, $options = null, $default = '') { + public function in($prompt, $options = null, $default = '') + { if (!$this->interactive) { return $default; } @@ -185,7 +189,8 @@ class Shell * @param string|array $string String to output. * @param boolean $newline If true, the outputs gets an added newline. */ - public function out($string, $newline = true) { + public function out($string, $newline = true) + { if (is_array($string)) { $str = ''; foreach ($string as $message) { @@ -201,7 +206,8 @@ class Shell * @param string|array $string Error text to output. * @access public */ - public function err($string) { + public function err($string) + { if (is_array($string)) { $str = ''; foreach ($string as $message) { @@ -217,7 +223,8 @@ class Shell * @param boolean $newline If true, the outputs gets an added newline. * @access public */ - public function hr($newline = false) { + public function hr($newline = false) + { if ($newline) { $this->out("\n"); } @@ -233,7 +240,8 @@ class Shell * @param string $msg Error message * @access public */ - public function error($title, $msg) { + public function error($title, $msg) + { $out = "$title\n"; $out .= "$msg\n"; $out .= "\n"; @@ -245,7 +253,8 @@ class Shell * * @access public */ - public function help() { + public function help() + { if ($this->command != null) { $this->err("Unknown {$this->name} command '$this->command'.\nFor usage, try 'postfixadmin-cli {$this->shell} help'.\n\n"); } else { @@ -259,7 +268,8 @@ class Shell * @return void * @access public */ - public function _stop($status = 0) { + public function _stop($status = 0) + { exit($status); } } diff --git a/model/VacationHandler.php b/model/VacationHandler.php index c479f57e..73d6b91b 100644 --- a/model/VacationHandler.php +++ b/model/VacationHandler.php @@ -19,14 +19,16 @@ class VacationHandler extends PFAHandler */ protected $domain_field = 'domain'; - public function init($id) : bool { + public function init($id) : bool + { throw new \Exception('VacationHandler is not yet ready to be used with *Handler methods'); } /** * @return void */ - protected function initStruct() { + protected function initStruct() + { $this->struct=array( # field name allow display in... type $PALANG label $PALANG description default / options / ... # editing? form list @@ -50,7 +52,8 @@ class VacationHandler extends PFAHandler /** * @return void */ - protected function initMsg() { + protected function initMsg() + { $this->msg['error_already_exists'] = 'pCreate_mailbox_username_text_error1'; # TODO: better error message $this->msg['error_does_not_exist'] = 'pCreate_mailbox_username_text_error1'; # TODO: better error message $this->msg['confirm_delete'] = 'confirm_delete_vacation'; # unused? @@ -69,7 +72,8 @@ class VacationHandler extends PFAHandler /** * @return array */ - public function webformConfig() { + public function webformConfig() + { return array( # $PALANG labels 'formtitle_create' => 'pUsersVacation_welcome', @@ -83,7 +87,8 @@ class VacationHandler extends PFAHandler ); } - protected function validate_new_id() { + protected function validate_new_id() + { # vacation can only be enabled if a mailbox with this name exists if ($this->is_admin) { $handler = new MailboxHandler(0, $this->admin_username); @@ -104,7 +109,8 @@ class VacationHandler extends PFAHandler /** * @return bool */ - public function delete() { + public function delete() + { $this->errormsg[] = '*** deletion not implemented yet ***'; return false; # XXX function aborts here! XXX } @@ -120,7 +126,8 @@ class VacationHandler extends PFAHandler /** * @param string $username */ - public function __construct($username) { + public function __construct($username) + { $this->username = $username; $this->id = $username; } @@ -130,7 +137,8 @@ class VacationHandler extends PFAHandler * set the vacation table record to false. * @return boolean true on success. */ - public function remove() { + public function remove() + { if (!$this->updateAlias(0)) { return false; } @@ -149,7 +157,8 @@ class VacationHandler extends PFAHandler /** * @return boolean true indicates this server supports vacation messages, and users are able to change their own. */ - public function vacation_supported() { + public function vacation_supported() + { return Config::bool('vacation') && Config::bool('vacation_control'); } @@ -157,7 +166,8 @@ class VacationHandler extends PFAHandler * @return boolean true if on vacation, otherwise false * Why do we bother storing true/false in the vacation table if the alias dictates it anyway? */ - public function check_vacation() { + public function check_vacation() + { $handler = new AliasHandler(); if (!$handler->init($this->id)) { @@ -183,7 +193,8 @@ class VacationHandler extends PFAHandler * @return array|boolean stored information on vacation - array(subject - string, message - string, active - boolean, activeFrom - date, activeUntil - date) * will return false if no existing data */ - public function get_details() { + public function get_details() + { $table_vacation = table_by_key('vacation'); $sql = "SELECT * FROM $table_vacation WHERE email = :username"; @@ -216,7 +227,8 @@ class VacationHandler extends PFAHandler * @param string $activeUntil - something strtotime understands * @return boolean */ - public function set_away($subject, $body, $interval_time, $activeFrom, $activeUntil) { + public function set_away($subject, $body, $interval_time, $activeFrom, $activeUntil) + { $this->remove(); // clean out any notifications that might already have been sent. $E_username = escape_string($this->username); @@ -258,7 +270,8 @@ class VacationHandler extends PFAHandler * @param int $vacationActive * @return boolean */ - protected function updateAlias($vacationActive) { + protected function updateAlias($vacationActive) + { $handler = new AliasHandler(); if (!$handler->init($this->id)) { diff --git a/public/list-virtual.php b/public/list-virtual.php index 20aad557..8858d991 100644 --- a/public/list-virtual.php +++ b/public/list-virtual.php @@ -366,7 +366,8 @@ class cNav_bar protected $arr_top; //* internal protected $anchor; - public function __construct($aTitle, $aLimit, $aPage_size, $aPages, $aSearch) { + public function __construct($aTitle, $aLimit, $aPage_size, $aPages, $aSearch) + { $this->count = count($aPages); $this->title = $aTitle; $this->limit = $aLimit; @@ -379,7 +380,8 @@ class cNav_bar } } - private function init() { + private function init() + { $this->anchor = 'a'.substr($this->title, 3); $this->append_to_url .= '#'.$this->anchor; ($this->limit >= $this->page_size) ? $this->arr_prev = ' '.$GLOBALS ['PALANG']['pOverview_left_arrow'].' ' : $this->arr_prev = ''; @@ -388,7 +390,8 @@ class cNav_bar $this->have_run_init = true; } - private function display_pre() { + private function display_pre() + { $ret_val = '