diff --git a/functions.inc.php b/functions.inc.php index 6f6aa06c..33d00a5f 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -479,11 +479,11 @@ function pacol($allow_editing, $display_in_form, $display_in_list, $type, $PALAN function get_domain_properties($domain) { $handler = new DomainHandler(); if (!$handler->init($domain)) { - die("Error: " . join("\n", $handler->errormsg)); + throw new Exception("Error: " . join("\n", $handler->errormsg)); } if (!$handler->view()) { - die("Error: " . join("\n", $handler->errormsg)); + throw new Exception("Error: " . join("\n", $handler->errormsg)); } $result = $handler->result(); @@ -509,7 +509,7 @@ function create_page_browser($idxfield, $querypart, $sql_params = []) { $count_results = 0; if ($page_size < 2) { # will break the page browser - die('$CONF[\'page_size\'] must be 2 or more!'); + throw new Exception('$CONF[\'page_size\'] must be 2 or more!'); } # get number of rows @@ -958,7 +958,7 @@ function _pacrypt_authlib($pw, $pw_db) { } elseif (stripos($flavor, 'SHA') === 0) { $password = '{' . $flavor . '}' . base64_encode(sha1($pw, true)); } else { - die("authlib_default_flavor '" . $flavor . "' unknown. Valid flavors are 'md5raw', 'md5', 'SHA' and 'crypt'"); + throw new Exception("authlib_default_flavor '" . $flavor . "' unknown. Valid flavors are 'md5raw', 'md5', 'SHA' and 'crypt'"); } return $password; } @@ -980,16 +980,12 @@ function _pacrypt_dovecot($pw, $pw_db = '') { $method = $method_matches[1]; } if (! preg_match("/^[A-Z0-9.-]+$/", $method)) { - die("invalid dovecot encryption method"); + throw new Exception("invalid dovecot encryption method"); } - # TODO: check against a fixed list? - # if (strtolower($method) == 'md5-crypt') die("\$CONF['encrypt'] = 'dovecot:md5-crypt' will not work because dovecotpw generates a random salt each time. Please use \$CONF['encrypt'] = 'md5crypt' instead."); - # $crypt_method = preg_match ("/.*-CRYPT$/", $method); - # digest-md5 hashes include the username - until someone implements it, let's declare it as unsupported if (strtolower($method) == 'digest-md5') { - die("Sorry, \$CONF['encrypt'] = 'dovecot:digest-md5' is not supported by PostfixAdmin."); + throw new Exception("Sorry, \$CONF['encrypt'] = 'dovecot:digest-md5' is not supported by PostfixAdmin."); } # TODO: add -u option for those hashes, or for everything that is salted (-u was available before dovecot 2.1 -> no problem with backward compatibility ) @@ -1016,7 +1012,7 @@ function _pacrypt_dovecot($pw, $pw_db = '') { $pipe = proc_open("$dovecotpw '-s' $method$dovepasstest", $spec, $pipes); if (!$pipe) { - die("can't proc_open $dovecotpw"); + throw new Exception("can't proc_open $dovecotpw"); } // use dovecot's stdin, it uses getpass() twice (except when using -t) @@ -1035,7 +1031,7 @@ function _pacrypt_dovecot($pw, $pw_db = '') { if (!preg_match('/^\{' . $method . '\}/', $password)) { $stderr_output = stream_get_contents($pipes[2]); error_log('dovecotpw password encryption failed. STDERR output: '. $stderr_output); - die("can't encrypt password with dovecotpw, see error log for details"); + throw new Exception("can't encrypt password with dovecotpw, see error log for details"); } } else { if (!preg_match('(verified)', $password)) { @@ -1129,7 +1125,7 @@ function _php_crypt_generate_crypt_salt($hash_type='SHA512', $hash_difficulty=nu } else { $cost = (int)$hash_difficulty; if ($cost < 4 || $cost > 31) { - die('invalid encrypt difficulty setting "' . $hash_difficulty . '" for ' . $hash_type . ', the valid range is 4-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) { @@ -1148,7 +1144,7 @@ function _php_crypt_generate_crypt_salt($hash_type='SHA512', $hash_difficulty=nu } else { $rounds = (int)$hash_difficulty; if ($rounds < 1000 || $rounds > 999999999) { - die('invalid encrypt difficulty setting "' . $hash_difficulty . '" for ' . $hash_type . ', the valid range is 1000-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); @@ -1165,7 +1161,7 @@ function _php_crypt_generate_crypt_salt($hash_type='SHA512', $hash_difficulty=nu } else { $rounds = (int)$hash_difficulty; if ($rounds < 1000 || $rounds > 999999999) { - die('invalid encrypt difficulty setting "' . $hash_difficulty . '" for ' . $hash_type . ', the valid range is 1000-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); @@ -1175,7 +1171,7 @@ function _php_crypt_generate_crypt_salt($hash_type='SHA512', $hash_difficulty=nu return sprintf('$%s$%s%s', $algorithm, $rounds, $salt); default: - die("unknown hash type: '$hash_type'"); + throw new Exception("unknown hash type: '$hash_type'"); } } @@ -1231,7 +1227,7 @@ function pacrypt($pw, $pw_db="") { return _pacrypt_php_crypt($pw, $pw_db); } - die('unknown/invalid $CONF["encrypt"] setting: ' . $CONF['encrypt']); + throw new Exception('unknown/invalid $CONF["encrypt"] setting: ' . $CONF['encrypt']); } /** @@ -1556,7 +1552,7 @@ function db_connect() { } $dsn = "pgsql:host={$CONF['database_host']};port={$CONF['database_port']};dbname={$CONF['database_name']};options='-c client_encoding=utf8'"; } else { - die("
FATAL Error:
Invalid \$CONF['database_type']! Please fix your config.inc.php!
FATAL Error:
Invalid \$CONF['database_type']! Please fix your config.inc.php!