0
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2024-09-19 11:12:15 +02:00

Automatic code style fixes

This commit is contained in:
Adrien Crivelli 2022-07-15 11:29:55 +02:00
parent 315ac19963
commit a97771adfd
No known key found for this signature in database
GPG Key ID: 16D79B903B4B5874
10 changed files with 158 additions and 159 deletions

View File

@ -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.
}

View File

@ -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("<p style='color: red'>FATAL Error:<br />Invalid \$CONF['database_type']! Please fix your config.inc.php!</p>");
}

View File

@ -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', ''),

View File

@ -73,7 +73,7 @@ class CliDelete extends Shell
$module = strtolower($module);
$this->out(
"Usage:
"Usage:
postfixadmin-cli $module delete

View File

@ -25,7 +25,7 @@ class CliHelp extends Shell
$module = strtolower($module);
$this->out(
"Usage:
"Usage:
postfixadmin-cli $module <task> [<address>] [--option value]
"

View File

@ -90,7 +90,7 @@ class CliScheme extends Shell
$module = strtolower($module);
$this->out(
"Usage:
"Usage:
postfixadmin-cli $module scheme

View File

@ -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

View File

@ -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');

View File

@ -119,16 +119,16 @@ $tick = ' ✅ ';
} else {
echo $todo . " You need to have a setup_pasword hash configured in a <code>config.local.php</code> file";
}
?>
?>
</li>
<li>
<?php
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.";
}
?>
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.";
}
?>
</li>
</ul>
@ -289,42 +289,42 @@ EOF;
<?php
$check = do_software_environment_check();
if ($authenticated) {
if (!empty($check['info'])) {
echo "<h3>Information</h3><ul>";
foreach ($check['info'] as $msg) {
echo "<li>{$tick} {$msg}</li>";
}
echo "</ul>";
}
if ($authenticated) {
if (!empty($check['info'])) {
echo "<h3>Information</h3><ul>";
foreach ($check['info'] as $msg) {
echo "<li>{$tick} {$msg}</li>";
}
echo "</ul>";
}
if (!empty($check['warn'])) {
echo "<h3>Warnings</h3><ul>";
foreach ($check['warn'] as $msg) {
echo "<li class='text-warning'>⚠ {$msg}</li>";
}
echo "</ul>";
}
if (!empty($check['error'])) {
echo "<h3>Errors (MUST be fixed)</h3><ul>";
foreach ($check['error'] as $msg) {
echo "<li class='text-danger'>⛔{$msg}</li>";
}
echo "</ul>";
}
if (!empty($check['warn'])) {
echo "<h3>Warnings</h3><ul>";
foreach ($check['warn'] as $msg) {
echo "<li class='text-warning'>⚠ {$msg}</li>";
}
echo "</ul>";
}
if (!empty($check['error'])) {
echo "<h3>Errors (MUST be fixed)</h3><ul>";
foreach ($check['error'] as $msg) {
echo "<li class='text-danger'>⛔{$msg}</li>";
}
echo "</ul>";
}
$php_error_log = ini_get('error_log');
} else {
if (!empty($check['error'])) {
echo '<h3 class="text-danger">Hosting Environment errors found. Login to see details.</h3>';
}
$php_error_log = ini_get('error_log');
} else {
if (!empty($check['error'])) {
echo '<h3 class="text-danger">Hosting Environment errors found. Login to see details.</h3>';
}
if (!empty($check['warn'])) {
echo '<h3 class="text-warning">Hosting Environment warnings found. Login to see details.</h3>';
}
}
if (!empty($check['warn'])) {
echo '<h3 class="text-warning">Hosting Environment warnings found. Login to see details.</h3>';
}
}
?>
?>
</div>
</div>
@ -334,29 +334,29 @@ EOF;
<h2 class="h2">Database Update</h2>
<?php
$db = false;
try {
$db = db_connect();
} catch (\Exception $e) {
echo "<p class='h3 text-danger'>Something went wrong while trying to connect to the database. A message should be logged - check PHP's error_log (" . ini_get('error_log') . ')</p>\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 "<p class='h3 text-danger'>Something went wrong while trying to connect to the database. A message should be logged - check PHP's error_log (" . ini_get('error_log') . ')</p>\n';
error_log("Couldn't perform PostfixAdmin database update - failed to connect to db? " . $e->getMessage() . " Trace: " . $e->getTraceAsString());
}
if ($db) {
echo "<p>Everything seems fine... attempting to create/update database structure</p>\n";
try {
require_once(dirname(__FILE__) . '/upgrade.php');
} catch (\Exception $e) {
if ($authenticated) {
echo "<p class='h3 text-danger'>Exception message: {$e->getMessage()} - check logs!</p>";
}
echo "<p class='h3 text-danger'>Something went wrong while trying to apply database updates, a message should be logged - check PHP's error_log (" . ini_get('error_log') . ')</p>\n';
error_log("Couldn't perform PostfixAdmin database update via upgrade.php - " . $e->getMessage() . " Trace: " . $e->getTraceAsString());
}
} else {
echo "<h3 class='h3 text-danger'>Could not connect to database to perform updates; check PHP error log.</h3>";
}
?>
if ($db) {
echo "<p>Everything seems fine... attempting to create/update database structure</p>\n";
try {
require_once(dirname(__FILE__) . '/upgrade.php');
} catch (\Exception $e) {
if ($authenticated) {
echo "<p class='h3 text-danger'>Exception message: {$e->getMessage()} - check logs!</p>";
}
echo "<p class='h3 text-danger'>Something went wrong while trying to apply database updates, a message should be logged - check PHP's error_log (" . ini_get('error_log') . ')</p>\n';
error_log("Couldn't perform PostfixAdmin database update via upgrade.php - " . $e->getMessage() . " Trace: " . $e->getTraceAsString());
}
} else {
echo "<h3 class='h3 text-danger'>Could not connect to database to perform updates; check PHP error log.</h3>";
}
?>
</div>
</div>
@ -417,7 +417,7 @@ EOF;
foreach ($admins as $row) {
echo "<li>{$row['username']}</li>";
}
?>
?>
</ul>
</div>
</div>
@ -500,7 +500,7 @@ EOF;
<?php
}
?>
?>
</div>
@ -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);
}

View File

@ -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";
}