1
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2025-07-31 10:04:20 +03:00

run php-cs-fixer (code reforamt)

This commit is contained in:
David Goodwin
2018-12-28 19:31:43 +00:00
parent 5eba76ac36
commit 4fcdba9cf4
22 changed files with 63 additions and 91 deletions

View File

@ -25,8 +25,7 @@ include_once(dirname(__FILE__) . '/functions.inc.php');
if (file_exists($validate_file)) { if (file_exists($validate_file)) {
include_once($validate_file); include_once($validate_file);
} } else {
else {
$validate_file = SM_PATH . '/src/validate.php'; $validate_file = SM_PATH . '/src/validate.php';
if (file_exists($validate_file)) { if (file_exists($validate_file)) {
include_once($validate_file); include_once($validate_file);

View File

@ -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 * @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; $ce_email=$email;
//strip the vacation domain out if we are using it //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. * @param string $default (optional) - default value if key is not set.
* @return string * @return string
*/ */
function safeget($param, $default = "") function safeget($param, $default = "") {
{
$retval = $default; $retval = $default;
if (isset($_GET[$param])) { if (isset($_GET[$param])) {
$retval = $_GET[$param]; $retval = $_GET[$param];
@ -389,8 +387,7 @@ function safeget($param, $default = "")
* @param string $default (optional) default value (defaults to "") * @param string $default (optional) default value (defaults to "")
* @return string|array - value in $_POST[$param] or $default * @return string|array - value in $_POST[$param] or $default
*/ */
function safepost($param, $default = "") function safepost($param, $default = "") {
{
$retval = $default; $retval = $default;
if (isset($_POST[$param])) { if (isset($_POST[$param])) {
$retval = $_POST[$param]; $retval = $_POST[$param];
@ -405,8 +402,7 @@ function safepost($param, $default = "")
* @param string $default (optional) * @param string $default (optional)
* @return string value from $_SERVER[$param] or $default * @return string value from $_SERVER[$param] or $default
*/ */
function safeserver($param, $default = "") function safeserver($param, $default = "") {
{
$retval = $default; $retval = $default;
if (isset($_SERVER[$param])) { if (isset($_SERVER[$param])) {
$retval = $_SERVER[$param]; $retval = $_SERVER[$param];
@ -421,8 +417,7 @@ function safeserver($param, $default = "")
* @param string $default (optional) * @param string $default (optional)
* @return string value from $_COOKIE[$param] or $default * @return string value from $_COOKIE[$param] or $default
*/ */
function safecookie($param, $default = "") function safecookie($param, $default = "") {
{
$retval = $default; $retval = $default;
if (isset($_COOKIE[$param])) { if (isset($_COOKIE[$param])) {
$retval = $_COOKIE[$param]; $retval = $_COOKIE[$param];
@ -437,8 +432,7 @@ function safecookie($param, $default = "")
* @param string $default (optional) * @param string $default (optional)
* @return string value from $_SESSION[$param] or $default * @return string value from $_SESSION[$param] or $default
*/ */
function safesession($param, $default = "") function safesession($param, $default = "") {
{
$retval = $default; $retval = $default;
if (isset($_SESSION[$param])) { if (isset($_SESSION[$param])) {
$retval = $_SESSION[$param]; $retval = $_SESSION[$param];
@ -893,7 +887,6 @@ function generate_password($length = 12) {
* @return array of error messages, or empty array if the password is ok * @return array of error messages, or empty array if the password is ok
*/ */
function validate_password($password) { function validate_password($password) {
$result = array(); $result = array();
$val_conf = Config::read_array('password_validation'); $val_conf = Config::read_array('password_validation');
@ -1491,7 +1484,6 @@ function db_connect_with_errors() {
static $link; static $link;
if (isset($link) && $link) { if (isset($link) && $link) {
return array($link, $error_text); return array($link, $error_text);
} }
$link = 0; $link = 0;
@ -1825,7 +1817,6 @@ function db_assoc($result) {
} }
if ($CONF['database_type'] == "mysqli" && $result instanceof mysqli_result) { if ($CONF['database_type'] == "mysqli" && $result instanceof mysqli_result) {
$row = mysqli_fetch_assoc($result); $row = mysqli_fetch_assoc($result);
} }
if (db_sqlite() && $result instanceof SQLite3Result) { if (db_sqlite() && $result instanceof SQLite3Result) {
$row = $result->fetchArray(SQLITE3_ASSOC); $row = $result->fetchArray(SQLITE3_ASSOC);
@ -1899,8 +1890,7 @@ function db_insert ($table, array $values, $timestamp = array('created', 'modifi
$password_expiration_value = (int) get_password_expiration_value($domain); $password_expiration_value = (int) get_password_expiration_value($domain);
$values['password_expiry'] = "now() + interval " . $password_expiration_value . " day"; $values['password_expiry'] = "now() + interval " . $password_expiration_value . " day";
} }
} } else {
else {
if ($_table == 'mailbox') { if ($_table == 'mailbox') {
unset($values['password_expiry']); unset($values['password_expiry']);
} }
@ -1958,7 +1948,6 @@ function db_update_q($table, $where, $values, $timestamp = array('modified')) {
if (Config::bool('password_expiration')) { if (Config::bool('password_expiration')) {
if ($table == 'mailbox') { if ($table == 'mailbox') {
error_log("db_update_q : " . json_Encode($where)); error_log("db_update_q : " . json_Encode($where));
$where_type = explode('=', $where); $where_type = explode('=', $where);
$email = ($where_type[1]); $email = ($where_type[1]);
@ -2022,7 +2011,6 @@ function db_log($domain, $action, $data) {
* @return string * @return string
*/ */
function db_in_clause($field, array $values) { function db_in_clause($field, array $values) {
$v = array_map('escape_string', array_values($values)); $v = array_map('escape_string', array_values($values));
return " $field IN ('" . implode("','", $v) . "') "; return " $field IN ('" . implode("','", $v) . "') ";
} }
@ -2079,7 +2067,6 @@ function db_where_clause($condition, $struct, $additional_raw_where = '', $searc
} elseif ($operator == "NOTNULL") { } elseif ($operator == "NOTNULL") {
$querypart = $field . ' IS NOT NULL'; $querypart = $field . ' IS NOT NULL';
} else { } else {
$querypart = $field . $operator . "'" . escape_string($value) . "'"; $querypart = $field . $operator . "'" . escape_string($value) . "'";
// might need other types adding here. // might need other types adding here.

View File

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

View File

@ -6,8 +6,7 @@
* *
* extends the "Shell" class * extends the "Shell" class
*/ */
class CliEdit extends Shell class CliEdit extends Shell {
{
public $handler_to_use = ""; public $handler_to_use = "";
public $new = 0; public $new = 0;
@ -15,8 +14,7 @@ class CliEdit extends Shell
/** /**
* Execution method always used for tasks * Execution method always used for tasks
*/ */
public function execute() public function execute() {
{
if (empty($this->args)) { if (empty($this->args)) {
$this->__interactive(); $this->__interactive();
} else { } else {
@ -29,8 +27,7 @@ class CliEdit extends Shell
* read, check and handle all --* parameters * read, check and handle all --* parameters
* The list of allowed params is based on $handler->struct * 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); $handler = new $this->handler_to_use($this->new);
$form_fields = $handler->getStruct(); $form_fields = $handler->getStruct();
$id_field = $handler->getId_field(); $id_field = $handler->getId_field();
@ -74,8 +71,7 @@ class CliEdit extends Shell
/** /**
* Interactive mode * Interactive mode
*/ */
private function __interactive() private function __interactive() {
{
$handler = new $this->handler_to_use($this->new); $handler = new $this->handler_to_use($this->new);
$form_fields = $handler->getStruct(); $form_fields = $handler->getStruct();
@ -179,8 +175,7 @@ class CliEdit extends Shell
/** /**
* (try to) store values * (try to) store values
*/ */
private function __handle($id, $values) private function __handle($id, $values) {
{
$handler = new $this->handler_to_use($this->new); $handler = new $this->handler_to_use($this->new);
if (!$handler->init($id)) { if (!$handler->init($id)) {
$this->err($handler->errormsg); $this->err($handler->errormsg);
@ -205,8 +200,7 @@ class CliEdit extends Shell
/** /**
* Displays help contents * Displays help contents
*/ */
public function help() public function help() {
{
if ($this->new) { if ($this->new) {
$cmd = 'add'; $cmd = 'add';
$cmdtext = 'Adds'; $cmdtext = 'Adds';

View File

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

View File

@ -217,7 +217,6 @@ class MailboxHandler extends PFAHandler {
protected function beforestore() { protected function beforestore() {
if (isset($this->values['quota']) && $this->values['quota'] != -1) { 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 $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? * @todo merge with allowed_quota?
*/ */
protected function check_quota($quota) { protected function check_quota($quota) {
if (!Config::bool('quota')) { if (!Config::bool('quota')) {
return true; # enforcing quotas is disabled - just allow it return true; # enforcing quotas is disabled - just allow it
} }

View File

@ -108,7 +108,9 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") {
while ($row = db_assoc($result['result'])) { while ($row = db_assoc($result['result'])) {
$fields = array_keys($row); $fields = array_keys($row);
$values = array_values($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"); fwrite($fh, "INSERT INTO ". $tables[$i] . " (". implode(',', $fields) . ") VALUES ('" . implode('\',\'', $values) . "');\n");
$fields = ""; $fields = "";

View File

@ -87,7 +87,6 @@ if (count($handler->infomsg)) {
if (safeget('output') == 'csv') { if (safeget('output') == 'csv') {
$out = fopen('php://output', 'w'); $out = fopen('php://output', 'w');
header('Content-Type: text/csv; charset=utf-8'); header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment;filename='.$table.'.csv'); header('Content-Disposition: attachment;filename='.$table.'.csv');

View File

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

View File

@ -10,8 +10,6 @@ define('NTLMSSP_HASH_SIZE', 16);
class DovecotCrypt extends Crypt { class DovecotCrypt extends Crypt {
private $errormsg = []; private $errormsg = [];
private $salt_chars = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; private $salt_chars = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

View File

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

View File

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