diff --git a/common.php b/common.php index 8f7479be..99b4c943 100644 --- a/common.php +++ b/common.php @@ -20,11 +20,10 @@ require_once(dirname(__FILE__) . '/vendor/autoload.php'); // See: https://github.com/postfixadmin/postfixadmin/pull/541 - try and check if the user has a turkish locale and warn? $old = setlocale(LC_ALL, 'C'); -if(preg_match('/_TR/i', $old)) { +if (preg_match('/_TR/i', $old)) { error_log("WARNING: You may have a Turkish locale set; this breaks the loading of some libraries (Smarty) we depend upon."); - // don't revert back to $old? -} -else { +// don't revert back to $old? +} else { setlocale(LC_ALL, $old); // revert back. } diff --git a/functions.inc.php b/functions.inc.php index 3c83e3f9..2c51a630 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1197,72 +1197,72 @@ function _php_crypt_generate_crypt_salt($hash_type='SHA512', $hash_difficulty=nu $alphabet = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; switch ($hash_type) { - case 'DES': - $alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; - $length = 2; - $salt = _php_crypt_random_string($alphabet, $length); - return $salt; + case 'DES': + $alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; + $length = 2; + $salt = _php_crypt_random_string($alphabet, $length); + return $salt; - case 'MD5': - $length = 12; - $algorithm = '1'; - $salt = _php_crypt_random_string($alphabet, $length); - return sprintf('$%s$%s', $algorithm, $salt); + case 'MD5': + $length = 12; + $algorithm = '1'; + $salt = _php_crypt_random_string($alphabet, $length); + return sprintf('$%s$%s', $algorithm, $salt); - case 'BLOWFISH': - $length = 22; - if (empty($hash_difficulty)) { - $cost = 10; - } else { - $cost = (int)$hash_difficulty; - if ($cost < 4 || $cost > 31) { - throw new Exception('invalid encrypt difficulty setting "' . $hash_difficulty . '" for ' . $hash_type . ', the valid range is 4-31'); + case 'BLOWFISH': + $length = 22; + if (empty($hash_difficulty)) { + $cost = 10; + } else { + $cost = (int)$hash_difficulty; + if ($cost < 4 || $cost > 31) { + throw new Exception('invalid encrypt difficulty setting "' . $hash_difficulty . '" for ' . $hash_type . ', the valid range is 4-31'); + } } - } - if (version_compare(PHP_VERSION, '5.3.7') >= 0) { - $algorithm = '2y'; // bcrypt, with fixed unicode problem - } else { - $algorithm = '2a'; // bcrypt - } - $salt = _php_crypt_random_string($alphabet, $length); - return sprintf('$%s$%02d$%s', $algorithm, $cost, $salt); - - case 'SHA256': - $length = 16; - $algorithm = '5'; - if (empty($hash_difficulty)) { - $rounds = ''; - } else { - $rounds = (int)$hash_difficulty; - if ($rounds < 1000 || $rounds > 999999999) { - throw new Exception('invalid encrypt difficulty setting "' . $hash_difficulty . '" for ' . $hash_type . ', the valid range is 1000-999999999'); + if (version_compare(PHP_VERSION, '5.3.7') >= 0) { + $algorithm = '2y'; // bcrypt, with fixed unicode problem + } else { + $algorithm = '2a'; // bcrypt } - } - $salt = _php_crypt_random_string($alphabet, $length); - if (!empty($rounds)) { - $rounds = sprintf('rounds=%d$', $rounds); - } - return sprintf('$%s$%s%s', $algorithm, $rounds, $salt); + $salt = _php_crypt_random_string($alphabet, $length); + return sprintf('$%s$%02d$%s', $algorithm, $cost, $salt); - case 'SHA512': - $length = 16; - $algorithm = '6'; - if (empty($hash_difficulty)) { - $rounds = ''; - } else { - $rounds = (int)$hash_difficulty; - if ($rounds < 1000 || $rounds > 999999999) { - throw new Exception('invalid encrypt difficulty setting "' . $hash_difficulty . '" for ' . $hash_type . ', the valid range is 1000-999999999'); + case 'SHA256': + $length = 16; + $algorithm = '5'; + if (empty($hash_difficulty)) { + $rounds = ''; + } else { + $rounds = (int)$hash_difficulty; + if ($rounds < 1000 || $rounds > 999999999) { + throw new Exception('invalid encrypt difficulty setting "' . $hash_difficulty . '" for ' . $hash_type . ', the valid range is 1000-999999999'); + } } - } - $salt = _php_crypt_random_string($alphabet, $length); - if (!empty($rounds)) { - $rounds = sprintf('rounds=%d$', $rounds); - } - return sprintf('$%s$%s%s', $algorithm, $rounds, $salt); + $salt = _php_crypt_random_string($alphabet, $length); + if (!empty($rounds)) { + $rounds = sprintf('rounds=%d$', $rounds); + } + return sprintf('$%s$%s%s', $algorithm, $rounds, $salt); - default: - throw new Exception("unknown hash type: '$hash_type'"); + case 'SHA512': + $length = 16; + $algorithm = '6'; + if (empty($hash_difficulty)) { + $rounds = ''; + } else { + $rounds = (int)$hash_difficulty; + if ($rounds < 1000 || $rounds > 999999999) { + throw new Exception('invalid encrypt difficulty setting "' . $hash_difficulty . '" for ' . $hash_type . ', the valid range is 1000-999999999'); + } + } + $salt = _php_crypt_random_string($alphabet, $length); + if (!empty($rounds)) { + $rounds = sprintf('rounds=%d$', $rounds); + } + return sprintf('$%s$%s%s', $algorithm, $rounds, $salt); + + default: + throw new Exception("unknown hash type: '$hash_type'"); } } @@ -1316,7 +1316,7 @@ function pacrypt($pw, $pw_db = "") if (!empty($pw_db) && preg_match('/^{([0-9a-z-\.]+)}/i', $pw_db, $matches)) { $method_in_hash = $matches[1]; if ('COURIER:' . strtoupper($method_in_hash) == $mechanism) { - // don't try and be clever. + // don't try and be clever. } elseif ($mechanism != $method_in_hash) { error_log("PostfixAdmin: configured to use $mechanism, but asked to crypt password using {$method_in_hash}; are you migrating algorithm/mechanism or is something wrong?"); $mechanism = $method_in_hash; @@ -1742,7 +1742,7 @@ function db_connect() $username_password = false; } elseif (db_pgsql()) { - // nothing to do. + // nothing to do. } else { throw new Exception("

FATAL Error:
Invalid \$CONF['database_type']! Please fix your config.inc.php!

"); } diff --git a/model/AdminHandler.php b/model/AdminHandler.php index 24e89bc1..62ddb704 100644 --- a/model/AdminHandler.php +++ b/model/AdminHandler.php @@ -59,30 +59,30 @@ class AdminHandler extends PFAHandler ), 'superadmin' => pacol(1, 1, 0, 'bool', 'super_admin' , 'super_admin_desc' , 0 -# TODO: (finally) replace the ALL domain with a column in the admin table -# TODO: current status: 'superadmin' column exists and is written when storing an admin with AdminHandler, -# TODO: but the superadmin status is still (additionally) stored in the domain_admins table ("ALL" dummy domain) -# TODO: to keep the database backwards-compatible with 2.3.x. -# TODO: Note: superadmins created with 2.3.x after running upgrade_1284() will not work until you re-run upgrade_1284() -# TODO: Create them with the trunk version to avoid this problem. + # TODO: (finally) replace the ALL domain with a column in the admin table + # TODO: current status: 'superadmin' column exists and is written when storing an admin with AdminHandler, + # TODO: but the superadmin status is still (additionally) stored in the domain_admins table ("ALL" dummy domain) + # TODO: to keep the database backwards-compatible with 2.3.x. + # TODO: Note: superadmins created with 2.3.x after running upgrade_1284() will not work until you re-run upgrade_1284() + # TODO: Create them with the trunk version to avoid this problem. ), 'domains' => pacol(1, 1, 0, 'list', 'domain' , '' , array(), list_domains(), - /*not_in_db*/ 0, - /*dont_write_to_db*/ 1, - /*select*/ "coalesce(domains,'') as domains" - /*extrafrom set in domain_count*/ + /*not_in_db*/ 0, + /*dont_write_to_db*/ 1, + /*select*/ "coalesce(domains,'') as domains" + /*extrafrom set in domain_count*/ ), 'domain_count' => pacol(0, 0, 1, 'vnum', 'pAdminList_admin_count', '' , '', array(), - /*not_in_db*/ 0, - /*dont_write_to_db*/ 1, - /*select*/ 'coalesce(__domain_count,0) as domain_count', - /*extrafrom*/ 'LEFT JOIN ( ' . - ' SELECT count(*) AS __domain_count, ' . $domains_grouped . ' AS domains, username AS __domain_username ' . - ' FROM ' . table_by_key('domain_admins') . - " WHERE domain != 'ALL' GROUP BY username " . - ' ) AS __domain on username = __domain_username'), + /*not_in_db*/ 0, + /*dont_write_to_db*/ 1, + /*select*/ 'coalesce(__domain_count,0) as domain_count', + /*extrafrom*/ 'LEFT JOIN ( ' . + ' SELECT count(*) AS __domain_count, ' . $domains_grouped . ' AS domains, username AS __domain_username ' . + ' FROM ' . table_by_key('domain_admins') . + " WHERE domain != 'ALL' GROUP BY username " . + ' ) AS __domain on username = __domain_username'), 'active' => pacol(1, 1, 1, 'bool', 'active' , '' , 1 ), 'phone' => pacol(1, $reset_by_sms, 0, 'text', 'pCreate_mailbox_phone', 'pCreate_mailbox_phone_desc', ''), diff --git a/model/CliDelete.php b/model/CliDelete.php index f0ac66be..10f5583b 100644 --- a/model/CliDelete.php +++ b/model/CliDelete.php @@ -73,7 +73,7 @@ class CliDelete extends Shell $module = strtolower($module); $this->out( -"Usage: + "Usage: postfixadmin-cli $module delete diff --git a/model/CliHelp.php b/model/CliHelp.php index 282e676a..f3ade202 100644 --- a/model/CliHelp.php +++ b/model/CliHelp.php @@ -25,7 +25,7 @@ class CliHelp extends Shell $module = strtolower($module); $this->out( -"Usage: + "Usage: postfixadmin-cli $module [
] [--option value] " diff --git a/model/CliScheme.php b/model/CliScheme.php index cf4b5736..56535b4a 100644 --- a/model/CliScheme.php +++ b/model/CliScheme.php @@ -90,7 +90,7 @@ class CliScheme extends Shell $module = strtolower($module); $this->out( -"Usage: + "Usage: postfixadmin-cli $module scheme diff --git a/model/CliView.php b/model/CliView.php index c56abd71..42230c47 100644 --- a/model/CliView.php +++ b/model/CliView.php @@ -64,7 +64,7 @@ class CliView extends Shell } if ($struct[$field]['display_in_list'] == 0) { - # do nothing + # do nothing } else { $value = $result[$field]; @@ -76,7 +76,7 @@ class CliView extends Shell if ($struct[$field]['type'] == 'txtl') { # $value = join("\n" . str_repeat(" ", 20 + 2), $value); # multiline, one item per line - $value = join(", ", $value); # one line, comma-separated + $value = join(", ", $value); # one line, comma-separated } elseif ($struct[$field]['type'] == 'bool') { $value = Config::Lang($value ? 'YES' : 'NO'); } @@ -97,7 +97,7 @@ class CliView extends Shell $module = strtolower($module); $this->out( -"Usage: + "Usage: postfixadmin-cli $module view diff --git a/model/PFAHandler.php b/model/PFAHandler.php index 3f70a7b7..f943a00c 100644 --- a/model/PFAHandler.php +++ b/model/PFAHandler.php @@ -225,7 +225,7 @@ abstract class PFAHandler /*not_in_db*/ 0, /*dont_write_to_db*/ 1, /*select*/ '1 as _can_edit' - ); + ); } /** @@ -236,7 +236,7 @@ abstract class PFAHandler /*not_in_db*/ 0, /*dont_write_to_db*/ 1, /*select*/ '1 as _can_delete' - ); + ); } $struct_hook = Config::read($this->db_table . '_struct_hook'); diff --git a/public/setup.php b/public/setup.php index 9eb7b211..15ff6ab6 100644 --- a/public/setup.php +++ b/public/setup.php @@ -119,16 +119,16 @@ $tick = ' ✅ '; } else { echo $todo . " You need to have a setup_pasword hash configured in a config.local.php file"; } - ?> +?>
  • +if ($authenticated) { + echo $tick . " You are logged in with the setup_password, some environment and hosting checks are displayed below."; +} else { + echo $todo . " You need to authenticate using the setup_password before you can perform some environment and hosting checks."; +} +?>
  • @@ -289,42 +289,42 @@ EOF; Information"; - } +if ($authenticated) { + if (!empty($check['info'])) { + echo "

    Information

    "; + } - if (!empty($check['warn'])) { - echo "

    Warnings

    "; - } - if (!empty($check['error'])) { - echo "

    Errors (MUST be fixed)

    "; - } + if (!empty($check['warn'])) { + echo "

    Warnings

    "; + } + if (!empty($check['error'])) { + echo "

    Errors (MUST be fixed)

    "; + } - $php_error_log = ini_get('error_log'); - } else { - if (!empty($check['error'])) { - echo '

    Hosting Environment errors found. Login to see details.

    '; - } + $php_error_log = ini_get('error_log'); +} else { + if (!empty($check['error'])) { + echo '

    Hosting Environment errors found. Login to see details.

    '; + } - if (!empty($check['warn'])) { - echo '

    Hosting Environment warnings found. Login to see details.

    '; - } - } + if (!empty($check['warn'])) { + echo '

    Hosting Environment warnings found. Login to see details.

    '; + } +} - ?> +?> @@ -334,29 +334,29 @@ EOF;

    Database Update

    Something went wrong while trying to connect to the database. A message should be logged - check PHP's error_log (" . ini_get('error_log') . ')

    \n'; - error_log("Couldn't perform PostfixAdmin database update - failed to connect to db? " . $e->getMessage() . " Trace: " . $e->getTraceAsString()); - } + $db = false; +try { + $db = db_connect(); +} catch (\Exception $e) { + echo "

    Something went wrong while trying to connect to the database. A message should be logged - check PHP's error_log (" . ini_get('error_log') . ')

    \n'; + error_log("Couldn't perform PostfixAdmin database update - failed to connect to db? " . $e->getMessage() . " Trace: " . $e->getTraceAsString()); +} - if ($db) { - echo "

    Everything seems fine... attempting to create/update database structure

    \n"; - try { - require_once(dirname(__FILE__) . '/upgrade.php'); - } catch (\Exception $e) { - if ($authenticated) { - echo "

    Exception message: {$e->getMessage()} - check logs!

    "; - } - echo "

    Something went wrong while trying to apply database updates, a message should be logged - check PHP's error_log (" . ini_get('error_log') . ')

    \n'; - error_log("Couldn't perform PostfixAdmin database update via upgrade.php - " . $e->getMessage() . " Trace: " . $e->getTraceAsString()); - } - } else { - echo "

    Could not connect to database to perform updates; check PHP error log.

    "; - } - ?> +if ($db) { + echo "

    Everything seems fine... attempting to create/update database structure

    \n"; + try { + require_once(dirname(__FILE__) . '/upgrade.php'); + } catch (\Exception $e) { + if ($authenticated) { + echo "

    Exception message: {$e->getMessage()} - check logs!

    "; + } + echo "

    Something went wrong while trying to apply database updates, a message should be logged - check PHP's error_log (" . ini_get('error_log') . ')

    \n'; + error_log("Couldn't perform PostfixAdmin database update via upgrade.php - " . $e->getMessage() . " Trace: " . $e->getTraceAsString()); + } +} else { + echo "

    Could not connect to database to perform updates; check PHP error log.

    "; +} +?> @@ -417,7 +417,7 @@ EOF; foreach ($admins as $row) { echo "
  • {$row['username']}
  • "; } - ?> + ?> @@ -500,7 +500,7 @@ EOF; +?> @@ -673,10 +673,10 @@ function do_software_environment_check() if (is_writeable($error_log_file)) { $err = "Possibly helpful error_log messages - " . htmlspecialchars( - implode("", - array_slice(file($error_log_file), -4, 3) // last three lines, might fail miserably if error_log is large. - ) - ); + implode("", + array_slice(file($error_log_file), -4, 3) // last three lines, might fail miserably if error_log is large. + ) + ); $error[] = nl2br($err); } diff --git a/public/upgrade.php b/public/upgrade.php index d397ec1d..a94c15f6 100644 --- a/public/upgrade.php +++ b/public/upgrade.php @@ -110,7 +110,7 @@ function _db_add_field($table, $field, $fieldtype, $after = '') function echo_out($text) { if (defined('PHPUNIT_TEST')) { - //error_log("" . $text); + //error_log("" . $text); } else { echo $text . "\n"; }