run php-cs-fixer (code reforamt)

pull/229/head
David Goodwin 5 years ago
parent 5eba76ac36
commit 4fcdba9cf4

@ -16,19 +16,18 @@ if (!defined('SM_PATH')) {
$config_file = dirname(__FILE__ ) . '/config.php';
$validate_file = dirname(__FILE__) . '/../include/validate.php';
if(!file_exists($config_file)) {
if (!file_exists($config_file)) {
die("$config_file is missing");
}
include_once($config_file);
include_once(dirname(__FILE__) . '/functions.inc.php');
if(file_exists($validate_file)) {
if (file_exists($validate_file)) {
include_once($validate_file);
}
else {
} else {
$validate_file = SM_PATH . '/src/validate.php';
if(file_exists($validate_file)) {
if (file_exists($validate_file)) {
include_once($validate_file);
}
}

@ -1,6 +1,6 @@
<?php
// vim:ts=4:sw=4:et
if(!defined('SM_PATH')) {
if (!defined('SM_PATH')) {
die("Invalid internal state (don't access file directly)");
}
include_once(SM_PATH . 'functions/i18n.php');

@ -73,7 +73,7 @@ Config::write($CONF);
require_once("$incpath/languages/language.php");
require_once("$incpath/functions.inc.php");
if(extension_loaded('Phar')) {
if (extension_loaded('Phar')) {
require_once("$incpath/lib/random_compat.phar");
}
@ -83,7 +83,7 @@ if (defined('POSTFIXADMIN_CLI')) {
$language = check_language(); # TODO: storing the language only at login instead of calling check_language() on every page would save some processor cycles ;-)
$_SESSION['lang'] = $language;
}
if(!empty($language)) {
if (!empty($language)) {
require_once("$incpath/languages/" . $language . ".lang");
}

@ -173,8 +173,8 @@ function check_language($use_post = true) {
array_unshift($lang_array, safepost('lang')); # but prefer $_POST['lang'] even more
}
foreach($lang_array as $value) {
if(!is_string($value)) {
foreach ($lang_array as $value) {
if (!is_string($value)) {
continue;
}
$lang_next = strtolower(trim($value));
@ -266,7 +266,7 @@ 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');
$domain = escape_string($domain);
$query = "SELECT password_expiry FROM $table_domain WHERE domain='$domain'";
@ -283,7 +283,6 @@ function get_password_expiration_value ($domain) {
* @return string empty if it's a valid email address, otherwise string with the errormessage
*/
function check_email($email) {
$ce_email=$email;
//strip the vacation domain out if we are using it
@ -373,8 +372,7 @@ function escape_string($string) {
* @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])) {
$retval = $_GET[$param];
@ -389,8 +387,7 @@ function safeget($param, $default = "")
* @param string $default (optional) default value (defaults to "")
* @return string|array - value in $_POST[$param] or $default
*/
function safepost($param, $default = "")
{
function safepost($param, $default = "") {
$retval = $default;
if (isset($_POST[$param])) {
$retval = $_POST[$param];
@ -405,8 +402,7 @@ 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];
@ -421,8 +417,7 @@ 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])) {
$retval = $_COOKIE[$param];
@ -437,8 +432,7 @@ 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])) {
$retval = $_SESSION[$param];
@ -702,7 +696,7 @@ function list_domains() {
if ($result['rows'] > 0) {
$i = 0;
while ($row = db_assoc($result['result'])) {
if(is_array($row)) {
if (is_array($row)) {
$list[$i] = $row['domain'];
$i++;
}
@ -893,7 +887,6 @@ function generate_password($length = 12) {
* @return array of error messages, or empty array if the password is ok
*/
function validate_password($password) {
$result = array();
$val_conf = Config::read_array('password_validation');
@ -1490,8 +1483,7 @@ function db_connect_with_errors() {
static $link;
if (isset($link) && $link) {
return array($link, $error_text);
return array($link, $error_text);
}
$link = 0;
@ -1535,7 +1527,7 @@ function db_connect_with_errors() {
$error_text .= ("<p />DEBUG INFORMATION<br />Connect: given database path does not exist, is not writable, or \$CONF['database_name'] is empty.");
} else {
$link = new SQLite3($CONF['database_name']) or $error_text .= ("<p />DEBUG INFORMATION<br />Connect: failed to connect to database. $DEBUG_TEXT");
if($link instanceof SQLite3) {
if ($link instanceof SQLite3) {
$link->createFunction('base64_decode', 'base64_decode');
}
}
@ -1775,7 +1767,7 @@ function db_row($result) {
$row = pg_fetch_row($result);
}
if(!is_array($row)) {
if (!is_array($row)) {
return array();
}
return $row;
@ -1803,7 +1795,7 @@ function db_array($result) {
$row = pg_fetch_array($result);
}
if(!is_array($row)) {
if (!is_array($row)) {
return [];
}
@ -1825,7 +1817,6 @@ function db_assoc($result) {
}
if ($CONF['database_type'] == "mysqli" && $result instanceof mysqli_result) {
$row = mysqli_fetch_assoc($result);
}
if (db_sqlite() && $result instanceof SQLite3Result) {
$row = $result->fetchArray(SQLITE3_ASSOC);
@ -1834,7 +1825,7 @@ function db_assoc($result) {
$row = pg_fetch_assoc($result);
}
if(!is_array($row)) {
if (!is_array($row)) {
$row = [];
}
return $row;
@ -1876,7 +1867,7 @@ function db_delete($table, $where, $delete, $additionalwhere='') {
* @param array $timestamp (optional) - array of fields to set to now() - default: array('created', 'modified')
* @return int - number of inserted rows
*/
function db_insert ($table, array $values, $timestamp = array('created', 'modified') ) {
function db_insert($table, array $values, $timestamp = array('created', 'modified')) {
$table = table_by_key($table);
foreach (array_keys($values) as $key) {
@ -1899,9 +1890,8 @@ function db_insert ($table, array $values, $timestamp = array('created', 'modifi
$password_expiration_value = (int) get_password_expiration_value($domain);
$values['password_expiry'] = "now() + interval " . $password_expiration_value . " day";
}
}
else {
if($_table == 'mailbox') {
} else {
if ($_table == 'mailbox') {
unset($values['password_expiry']);
}
}
@ -1958,7 +1948,6 @@ function db_update_q($table, $where, $values, $timestamp = array('modified')) {
if (Config::bool('password_expiration')) {
if ($table == 'mailbox') {
error_log("db_update_q : " . json_Encode($where));
$where_type = explode('=', $where);
$email = ($where_type[1]);
@ -1972,7 +1961,7 @@ function db_update_q($table, $where, $values, $timestamp = array('modified')) {
$sql="UPDATE $table_key SET " . implode(",", $sql_values) . " WHERE $where";
$result = db_query($sql);
if(array_key_exists('rows', $result)) {
if (array_key_exists('rows', $result)) {
return $result['rows'];
}
return 0;
@ -2022,7 +2011,6 @@ function db_log($domain, $action, $data) {
* @return string
*/
function db_in_clause($field, array $values) {
$v = array_map('escape_string', array_values($values));
return " $field IN ('" . implode("','", $v) . "') ";
}
@ -2079,12 +2067,11 @@ function db_where_clause($condition, $struct, $additional_raw_where = '', $searc
} elseif ($operator == "NOTNULL") {
$querypart = $field . ' IS NOT NULL';
} else {
$querypart = $field . $operator . "'" . escape_string($value) . "'";
// might need other types adding here.
if (db_pgsql() && in_array($struct[$field]['type'], array('ts', 'num')) && $value === '') {
$querypart = $field . $operator . " NULL";
$querypart = $field . $operator . " NULL";
}
}
@ -2154,7 +2141,7 @@ function check_db_version($error_out = true) {
if ($r['rows'] == 1) {
$row = db_assoc($r['result']);
if(isset($row['value'])) {
if (isset($row['value'])) {
$dbversion = (int) $row['value'];
}
} else {
@ -2241,7 +2228,7 @@ function gen_show_status($show_alias) {
// Vacation CHECK
if ( $CONF['show_vacation'] == 'YES' ) {
$stat_result = db_query ("SELECT * FROM ". $CONF['database_tables']['vacation'] ." WHERE email = '" . $show_alias . "' AND active = 1");
$stat_result = db_query("SELECT * FROM ". $CONF['database_tables']['vacation'] ." WHERE email = '" . $show_alias . "' AND active = 1");
if ($stat_result['rows'] == 1) {
$stat_string .= "<span style='background-color:" . $CONF['show_vacation_color'] . "'>" . $CONF['show_status_text'] . "</span>&nbsp;";
} else {
@ -2251,7 +2238,7 @@ function gen_show_status($show_alias) {
// Disabled CHECK
if ( $CONF['show_disabled'] == 'YES' ) {
$stat_result = db_query ("SELECT * FROM ". $CONF['database_tables']['mailbox'] ." WHERE username = '" . $show_alias . "' AND active = 0");
$stat_result = db_query("SELECT * FROM ". $CONF['database_tables']['mailbox'] ." WHERE username = '" . $show_alias . "' AND active = 0");
if ($stat_result['rows'] == 1) {
$stat_string .= "<span style='background-color:" . $CONF['show_disabled_color'] . "'>" . $CONF['show_status_text'] . "</span>&nbsp;";
} else {
@ -2261,7 +2248,7 @@ function gen_show_status($show_alias) {
// Expired CHECK
if ( $CONF['show_expired'] == 'YES' ) {
$stat_result = db_query ("SELECT * FROM ". $CONF['database_tables']['mailbox'] ." WHERE username = '" . $show_alias . "' AND password_expiry <= now()");
$stat_result = db_query("SELECT * FROM ". $CONF['database_tables']['mailbox'] ." WHERE username = '" . $show_alias . "' AND password_expiry <= now()");
if ($stat_result['rows'] == 1) {
$stat_string .= "<span style='background-color:" . $CONF['show_expired_color'] . "'>" . $CONF['show_status_text'] . "</span>&nbsp;";
} else {

@ -5,7 +5,6 @@
*/
class CliDelete extends Shell {
protected $handler_to_use = '';
/**

@ -6,8 +6,7 @@
*
* extends the "Shell" class
*/
class CliEdit extends Shell
{
class CliEdit extends Shell {
public $handler_to_use = "";
public $new = 0;
@ -15,8 +14,7 @@ class CliEdit extends Shell
/**
* Execution method always used for tasks
*/
public function execute()
{
public function execute() {
if (empty($this->args)) {
$this->__interactive();
} else {
@ -29,8 +27,7 @@ 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();
@ -74,8 +71,7 @@ class CliEdit extends Shell
/**
* Interactive mode
*/
private function __interactive()
{
private function __interactive() {
$handler = new $this->handler_to_use($this->new);
$form_fields = $handler->getStruct();
@ -179,8 +175,7 @@ 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);
@ -205,8 +200,7 @@ class CliEdit extends Shell
/**
* Displays help contents
*/
public function help()
{
public function help() {
if ($this->new) {
$cmd = 'add';
$cmdtext = 'Adds';

@ -5,7 +5,6 @@
*/
class CliView extends Shell {
protected $handler_to_use = 'invalid';
/**

@ -75,7 +75,7 @@ final class Config {
public static function read_array($var) {
$stuff = self::read($var);
if(!is_array($stuff)) {
if (!is_array($stuff)) {
trigger_error('In '.__FUNCTION__.": expected config $var to be a boolean, but received a " . gettype($stuff), E_USER_ERROR);
}
@ -89,11 +89,11 @@ final class Config {
public static function read_string($var) {
$stuff = self::read($var);
if($stuff === null) {
if ($stuff === null) {
return '';
}
if(!is_string($stuff)) {
if (!is_string($stuff)) {
trigger_error('In '.__FUNCTION__.": expected config $var to be a string, but received a " . gettype($stuff), E_USER_ERROR);
return '';
}
@ -189,11 +189,11 @@ final class Config {
public static function bool($var) {
$value = self::read($var);
if(is_bool($value)) {
if (is_bool($value)) {
return $value;
}
if(!is_string($value)) {
if (!is_string($value)) {
trigger_error('In '.__FUNCTION__.": expected config $var to be a string, but received a " . gettype($value), E_USER_ERROR);
error_log("config $var should be a string, found: " . json_encode($value));
return false;
@ -233,11 +233,11 @@ final class Config {
public static function lang($var) {
$value = self::read("__LANG.{$var}");
if(is_null($value)) {
if (is_null($value)) {
return '';
}
if(!is_string($value)) {
if (!is_string($value)) {
trigger_error('In '.__FUNCTION__.": expected config $var to be a string , but received a " . gettype($value), E_USER_ERROR);
}
return $value;

@ -217,7 +217,6 @@ class MailboxHandler extends PFAHandler {
protected function beforestore() {
if (isset($this->values['quota']) && $this->values['quota'] != -1) {
$this->values['quota'] = $this->values['quota'] * Config::read_string('quota_multiplier'); # convert quota from MB to bytes
}
@ -452,7 +451,6 @@ class MailboxHandler extends PFAHandler {
* @todo merge with allowed_quota?
*/
protected function check_quota($quota) {
if (!Config::bool('quota')) {
return true; # enforcing quotas is disabled - just allow it
}

@ -730,7 +730,7 @@ abstract class PFAHandler {
$db_result = array();
if ($result['rows'] != 0) {
while ($row = db_assoc($result['result'])) {
if(is_array($row)) {
if (is_array($row)) {
$db_result[$row[$this->id_field]] = $row;
}
}
@ -827,7 +827,7 @@ abstract class PFAHandler {
$result = db_query($query);
if ($result['rows'] == 1) {
$row = db_assoc($result['result']);
if(!is_array($row)) {
if (!is_array($row)) {
return false;
}
$crypt_password = pacrypt($password, $row['password']);
@ -876,7 +876,7 @@ abstract class PFAHandler {
if ($result['rows'] == 1) {
$row = db_assoc($result['result']);
if(!is_array($row)) {
if (!is_array($row)) {
return false;
}
$crypt_token = pacrypt($token, $row['token']);

@ -197,7 +197,7 @@ class VacationHandler extends PFAHandler {
$row = db_assoc($result['result']);
if(!is_array($row)) {
if (!is_array($row)) {
return false;
}
$boolean = ($row['active'] == db_get_boolean(true));

@ -108,7 +108,9 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") {
while ($row = db_assoc($result['result'])) {
$fields = array_keys($row);
$values = array_values($row);
$values = array_map(function($str) { return escape_string($str); }, $values);
$values = array_map(function ($str) {
return escape_string($str);
}, $values);
fwrite($fh, "INSERT INTO ". $tables[$i] . " (". implode(',', $fields) . ") VALUES ('" . implode('\',\'', $values) . "');\n");
$fields = "";

@ -66,7 +66,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
$result = db_query($q);
if ($result['rows'] > 0) {
while ($row = db_assoc($result['result'])) {
if(is_array($row)) {
if (is_array($row)) {
$recipients[] = $row['username'];
}
}

@ -230,7 +230,7 @@ if ($result['rows'] > 0) {
$goto_single_rec_del = "";
while ($row = db_assoc($result['result'])) {
if(!is_array($row)) {
if (!is_array($row)) {
continue;
}
if ($display_mailbox_aliases) {
@ -405,7 +405,7 @@ class cNav_bar {
$highlight_at = 0;
if ($this->limit >= $this->page_size) {
if ($this->limit >= $this->page_size) {
$highlight_at = $this->limit / $this->page_size ;
}

@ -87,7 +87,6 @@ if (count($handler->infomsg)) {
if (safeget('output') == 'csv') {
$out = fopen('php://output', 'w');
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment;filename='.$table.'.csv');
@ -115,7 +114,7 @@ if (safeget('output') == 'csv') {
$fields = array();
foreach ($columns as $column) {
$values = $item[$column];
if(is_array($values)) {
if (is_array($values)) {
$values = implode(',', $values);
}
$fields[] = $values;

@ -76,8 +76,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
error_log("PostfixAdmin admin login failed (username: $fUsername, ip_address: {$_SERVER['REMOTE_ADDR']})");
flash_error($PALANG['pLogin_failed']);
}
}
else {
} else {
session_unset();
session_destroy();
session_start();

@ -50,7 +50,7 @@ $file_config = file_exists(realpath("./../config.inc.php"));
$file_local_config = file_exists(realpath("./../config.local.php"));
// Fall back to looking in /etc/postfixadmin for config.local.php (Debian etc)
if(!$file_local_config && is_dir('/etc/postfixadmin')) {
if (!$file_local_config && is_dir('/etc/postfixadmin')) {
$file_local_config = file_exists('/etc/postfixadmin/config.local.php');
}

@ -3,7 +3,7 @@ if (!defined('POSTFIXADMIN')) {
require_once('common.php');
}
if(!isset($CONF) || !is_array($CONF)) {
if (!isset($CONF) || !is_array($CONF)) {
die("config.inc.php seems invalid");
}
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
@ -1416,7 +1416,7 @@ function upgrade_1284_mysql_pgsql() {
if ($result['rows'] > 0) {
while ($row = db_assoc($result['result'])) {
if(!is_array($row)) {
if (!is_array($row)) {
break;
}
@ -1737,7 +1737,7 @@ function upgrade_1837_sqlite() {
/* https://github.com/postfixadmin/postfixadmin/issues/89 */
# upgrade_1838_mysql() renamed to upgrade_1839() to keep all databases in sync
function upgrade_1839() {
if(!db_sqlite()) {
if (!db_sqlite()) {
return _db_add_field('log', 'id', '{AUTOINCREMENT} {PRIMARY}', 'data');
}
@ -1776,4 +1776,4 @@ function upgrade_1841_sqlite() {
function upgrade_1842() {
_db_add_field('mailbox', 'password_expiry', "{DATETIME}"); // when a specific mailbox password expires
_db_add_field('domain', 'password_expiry', 'int DEFAULT 0'); // expiry applied to mailboxes within that domain
}
}

@ -76,8 +76,8 @@ if ($error != 1) {
}
}
foreach($tLog as $k => $v) {
if(isset($v['action'])) {
foreach ($tLog as $k => $v) {
if (isset($v['action'])) {
$v['action'] = $PALANG['pViewlog_action_' . $v['action']];
$tLog[$k] = $v;
}

@ -10,8 +10,6 @@ define('NTLMSSP_HASH_SIZE', 16);
class DovecotCrypt extends Crypt {
private $errormsg = [];
private $salt_chars = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
@ -109,7 +107,7 @@ class DovecotCrypt extends Crypt {
/**
* @return string
*/
*/
public function custom_hmac($algo, $data, $key, $raw_output = false) {
$algo = strtolower($algo);
$pack = 'H'.strlen($algo('test'));

@ -52,7 +52,6 @@ class PaCryptTest extends \PHPUnit\Framework\TestCase {
'md5' => 'CY9rzUYh03PK3k6DJie09g==',
// crypt requires salt ...
'SHA' => 'qUqP5cyxm6YcTAhz05Hph5gvu9M='] as $flavour => $hash) {
$CONF['authlib_default_flavour'] = $flavour;
$stored = "{" . $flavour . "}$hash";

@ -3,7 +3,6 @@
require_once('common.php');
class ValidatePasswordTest extends \PHPUnit\Framework\TestCase {
public function testBasic() {
$config = Config::getInstance();

Loading…
Cancel
Save