diff --git a/lib/Froxlor/CurrentUser.php b/lib/Froxlor/CurrentUser.php
index af635727..22a62082 100644
--- a/lib/Froxlor/CurrentUser.php
+++ b/lib/Froxlor/CurrentUser.php
@@ -63,9 +63,10 @@ class CurrentUser
/**
* re-read in the user data if a valid session exists
*
- * @return boolean
+ * @return bool
+ * @throws \Exception
*/
- public static function reReadUserData()
+ public static function reReadUserData(): bool
{
$table = self::isAdmin() ? TABLE_PANEL_ADMINS : TABLE_PANEL_CUSTOMERS;
$userinfo_stmt = Database::prepare("
@@ -75,7 +76,7 @@ class CurrentUser
"loginname" => self::getField('loginname')
]);
if ($userinfo) {
- // dont just set the data, we need to merge with current data
+ // don't just set the data, we need to merge with current data
// array_merge is a right-reduction - value existing in getData() will be overwritten with $userinfo,
// other than the union-operator (+) which would keep the values already existing from getData()
$newuserinfo = array_merge(self::getData(), $userinfo);
@@ -107,7 +108,7 @@ class CurrentUser
*/
public static function getField(string $index)
{
- return isset($_SESSION['userinfo'][$index]) ? $_SESSION['userinfo'][$index] : "";
+ return $_SESSION['userinfo'][$index] ?? "";
}
/**
@@ -130,6 +131,11 @@ class CurrentUser
$_SESSION['userinfo'] = $data;
}
+ /**
+ * @param string $resource
+ * @return bool
+ * @throws \Exception
+ */
public static function canAddResource(string $resource): bool
{
$addition = true;
@@ -145,14 +151,15 @@ class CurrentUser
]);
$addition = $result['emaildomains'] != 0;
} elseif ($resource == 'subdomains') {
- $parentDomainCollection = (new Collection(SubDomains::class, $_SESSION['userinfo'], ['sql_search' => ['d.parentdomainid' => 0]]));
+ $parentDomainCollection = (new Collection(SubDomains::class, $_SESSION['userinfo'],
+ ['sql_search' => ['d.parentdomainid' => 0]]));
$addition = $parentDomainCollection != 0;
} elseif ($resource == 'domains') {
$customerCollection = (new Collection(Customers::class, $_SESSION['userinfo']));
$addition = $customerCollection != 0;
}
- return ($_SESSION['userinfo'][$resource.'_used'] < $_SESSION['userinfo'][$resource] || $_SESSION['userinfo'][$resource] == '-1') && $addition;
+ return ($_SESSION['userinfo'][$resource . '_used'] < $_SESSION['userinfo'][$resource] || $_SESSION['userinfo'][$resource] == '-1') && $addition;
}
}
diff --git a/lib/Froxlor/Customer/Customer.php b/lib/Froxlor/Customer/Customer.php
index 7e81a348..27581d1c 100644
--- a/lib/Froxlor/Customer/Customer.php
+++ b/lib/Froxlor/Customer/Customer.php
@@ -31,7 +31,15 @@ use PDO;
class Customer
{
- public static function getCustomerDetail($customerid, $varname)
+ /**
+ * Get value of a a specific field from a given customer
+ *
+ * @param int $customerid
+ * @param string $varname
+ * @return false|mixed
+ * @throws \Exception
+ */
+ public static function getCustomerDetail(int $customerid, string $varname)
{
$customer_stmt = Database::prepare("
SELECT `" . $varname . "` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `customerid` = :customerid
@@ -42,20 +50,19 @@ class Customer
if (isset($customer[$varname])) {
return $customer[$varname];
- } else {
- return false;
}
+ return false;
}
/**
* returns the loginname of a customer by given uid
*
- * @param int $uid
- * uid of customer
+ * @param int $uid uid of customer
*
* @return string customers loginname
+ * @throws \Exception
*/
- public static function getLoginNameByUid($uid = null)
+ public static function getLoginNameByUid(int $uid)
{
$result_stmt = Database::prepare("
SELECT `loginname` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `guid` = :guid
@@ -64,7 +71,7 @@ class Customer
'guid' => $uid
]);
- if (is_array($result) && isset($result['loginname'])) {
+ if ($result && isset($result['loginname'])) {
return $result['loginname'];
}
return false;
@@ -76,23 +83,22 @@ class Customer
* returns true or false whether perl is
* enabled for the given customer
*
- * @param
- * int customer-id
+ * @param int $cid customer-id
*
- * @return boolean
+ * @return bool
+ * @throws \Exception
*/
- public static function customerHasPerlEnabled($cid = 0)
+ public static function customerHasPerlEnabled(int $cid = 0)
{
if ($cid > 0) {
$result_stmt = Database::prepare("
SELECT `perlenabled` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `customerid` = :cid");
- Database::pexecute($result_stmt, [
+ $result = Database::pexecute_first($result_stmt, [
'cid' => $cid
]);
- $result = $result_stmt->fetch(PDO::FETCH_ASSOC);
- if (is_array($result) && isset($result['perlenabled'])) {
- return $result['perlenabled'] == '1';
+ if ($result && isset($result['perlenabled'])) {
+ return (bool)$result['perlenabled'];
}
}
return false;
diff --git a/lib/Froxlor/Database/Database.php b/lib/Froxlor/Database/Database.php
index 2157e5ee..2e76b075 100644
--- a/lib/Froxlor/Database/Database.php
+++ b/lib/Froxlor/Database/Database.php
@@ -83,19 +83,21 @@ class Database
private static $need_dbname = true;
/**
- * Wrapper for PDOStatement::execute so we can catch the PDOException
+ * Wrapper for PDOStatement::execute, so we can catch the PDOException
* and display the error nicely on the panel - also fetches the
* result from the statement and returns the resulting array
*
* @param PDOStatement $stmt
- * @param array $params
+ * @param array|null $params
* (optional)
* @param bool $showerror
- * suppress errordisplay (default true)
+ * suppress error display (default true)
+ * @param bool $json_response
*
* @return array
+ * @throws Exception
*/
- public static function pexecute_first(&$stmt, $params = null, $showerror = true, $json_response = false)
+ public static function pexecute_first(PDOStatement &$stmt, $params = null, bool $showerror = true, bool $json_response = false): array
{
self::pexecute($stmt, $params, $showerror, $json_response);
return $stmt->fetch(PDO::FETCH_ASSOC);
@@ -106,12 +108,15 @@ class Database
* and display the error nicely on the panel
*
* @param PDOStatement $stmt
- * @param array $params
+ * @param array|null $params
* (optional)
* @param bool $showerror
- * suppress errordisplay (default true)
+ * suppress error display (default true)
+ * @param bool $json_response
+ *
+ * @throws Exception
*/
- public static function pexecute(&$stmt, $params = null, $showerror = true, $json_response = false)
+ public static function pexecute(PDOStatement &$stmt, $params = null, bool $showerror = true, bool $json_response = false)
{
try {
$stmt->execute($params);
@@ -125,9 +130,10 @@ class Database
*
* @param PDOException $error
* @param bool $showerror
- * if set to false, the error will be logged but we go on
+ * if set to false, the error will be logged, but we go on
+ * @throws Exception
*/
- private static function showerror($error, $showerror = true, $json_response = false, PDOStatement $stmt = null)
+ private static function showerror(Exception $error, bool $showerror = true, bool $json_response = false, PDOStatement $stmt = null)
{
global $userinfo, $theme, $linker;
@@ -143,7 +149,7 @@ class Database
0 => [
'caption' => 'Default',
'host' => $sql['host'],
- 'socket' => (isset($sql['socket']) ? $sql['socket'] : null),
+ 'socket' => ($sql['socket'] ?? null),
'user' => $sql['root_user'],
'password' => $sql['root_password']
]
@@ -159,8 +165,8 @@ class Database
$substitutions = [
$sql['password'] => 'DB_UNPRIV_PWD',
];
- foreach ($sql_root as $dbserver => $sql_root_data) {
- $substitutions[$sql_root_data[$dbserver]]['password'] = 'DB_ROOT_PWD';
+ foreach ($sql_root as $sql_root_data) {
+ $substitutions[$sql_root_data['password']] = 'DB_ROOT_PWD';
}
// hide username/password in messages
@@ -254,7 +260,7 @@ class Database
* @param int $minLength
* @return string
*/
- private static function substitute($content, array $substitutions, $minLength = 6)
+ private static function substitute(string $content, array $substitutions, int $minLength = 6): string
{
$replacements = [];
@@ -262,9 +268,7 @@ class Database
$replacements += self::createShiftedSubstitutions($search, $replace, $minLength);
}
- $content = str_replace(array_keys($replacements), array_values($replacements), $content);
-
- return $content;
+ return str_replace(array_keys($replacements), array_values($replacements), $content);
}
/**
@@ -284,7 +288,7 @@ class Database
* @param int $minLength
* @return array
*/
- private static function createShiftedSubstitutions($search, $replace, $minLength)
+ private static function createShiftedSubstitutions(string $search, string $replace, int $minLength): array
{
$substitutions = [];
$length = strlen($search);
@@ -303,8 +307,9 @@ class Database
*
* @param int $length
* @return string
+ * @throws Exception
*/
- private static function genUniqueToken(int $length = 16)
+ private static function genUniqueToken(int $length = 16): string
{
if (intval($length) <= 8) {
$length = 16;
@@ -327,7 +332,7 @@ class Database
*
* @return int
*/
- public static function num_rows()
+ public static function num_rows(): int
{
return Database::query("SELECT FOUND_ROWS()")->fetchColumn();
}
@@ -337,7 +342,7 @@ class Database
*
* @return string
*/
- public static function getDbName()
+ public static function getDbName(): ?string
{
return self::$dbname;
}
@@ -349,8 +354,8 @@ class Database
* the 'normal' database-connection
*
* @param bool $needroot
- * @param int $dbserver
- * optional
+ * @param int $dbserver optional
+ * @param bool $need_db
*/
public static function needRoot(bool $needroot = false, int $dbserver = 0, bool $need_db = true)
{
@@ -366,7 +371,7 @@ class Database
*
* @param int $dbserver
*/
- private static function setServer($dbserver = 0)
+ private static function setServer(int $dbserver = 0)
{
self::$dbserver = $dbserver;
self::$link = null;
@@ -397,17 +402,16 @@ class Database
* function that will be called on every static call
* which connects to the database if necessary
*
- * @param bool $root
- *
* @return object
+ * @throws Exception
*/
private static function getDB()
{
- if (!extension_loaded('pdo') || in_array("mysql", PDO::getAvailableDrivers()) == false) {
+ if (!extension_loaded('pdo') || !in_array("mysql", PDO::getAvailableDrivers())) {
self::showerror(new Exception("The php PDO extension or PDO-MySQL driver is not available"));
}
- // do we got a connection already?
+ // do we have a connection already?
if (self::$link) {
// return it
return self::$link;
@@ -422,7 +426,7 @@ class Database
0 => [
'caption' => 'Default',
'host' => $sql['host'],
- 'socket' => (isset($sql['socket']) ? $sql['socket'] : null),
+ 'socket' => ($sql['socket'] ?? null),
'user' => $sql['root_user'],
'password' => $sql['root_password']
]
@@ -441,8 +445,8 @@ class Database
$user = $sql_root[self::$dbserver]['user'];
$password = $sql_root[self::$dbserver]['password'];
$host = $sql_root[self::$dbserver]['host'];
- $socket = isset($sql_root[self::$dbserver]['socket']) ? $sql_root[self::$dbserver]['socket'] : null;
- $port = isset($sql_root[self::$dbserver]['port']) ? $sql_root[self::$dbserver]['port'] : '3306';
+ $socket = $sql_root[self::$dbserver]['socket'] ?? null;
+ $port = $sql_root[self::$dbserver]['port'] ?? '3306';
$sslCAFile = $sql_root[self::$dbserver]['ssl']['caFile'] ?? "";
$sslVerifyServerCertificate = $sql_root[self::$dbserver]['ssl']['verifyServerCertificate'] ?? false;
} else {
@@ -450,8 +454,8 @@ class Database
$user = $sql["user"];
$password = $sql["password"];
$host = $sql["host"];
- $socket = isset($sql['socket']) ? $sql['socket'] : null;
- $port = isset($sql['port']) ? $sql['port'] : '3306';
+ $socket = $sql['socket'] ?? null;
+ $port = $sql['port'] ?? '3306';
$sslCAFile = $sql['ssl']['caFile'] ?? "";
$sslVerifyServerCertificate = $sql['ssl']['verifyServerCertificate'] ?? false;
}
@@ -556,14 +560,14 @@ class Database
*
* @return int
*/
- public static function getSqlUsernameLength()
+ public static function getSqlUsernameLength(): int
{
- // MariaDB supports up to 80 characters but only 64 for databases and as we use the loginname also for
+ // MariaDB supports up to 80 characters but only 64 for databases and as we use the login-name also for
// database names, we set the limit to 64 here
if (strpos(strtolower(Database::getAttribute(\PDO::ATTR_SERVER_VERSION)), "mariadb") !== false) {
$mysql_max = 64;
} else {
- // MySQL user names can be up to 32 characters long (16 characters before MySQL 5.7.8).
+ // MySQL user-names can be up to 32 characters long (16 characters before MySQL 5.7.8).
$mysql_max = 32;
if (version_compare(Database::getAttribute(\PDO::ATTR_SERVER_VERSION), '5.7.8', '<')) {
$mysql_max = 16;
@@ -573,15 +577,16 @@ class Database
}
/**
- * let's us interact with the PDO-Object by using static
+ * Lets us interact with the PDO-Object by using static
* call like "Database::function()"
*
* @param string $name
* @param mixed $args
*
* @return mixed
+ * @throws Exception
*/
- public static function __callStatic($name, $args)
+ public static function __callStatic(string $name, $args)
{
$callback = [
self::getDB(),
diff --git a/lib/Froxlor/Database/DbManager.php b/lib/Froxlor/Database/DbManager.php
index d57ee558..2c289a59 100644
--- a/lib/Froxlor/Database/DbManager.php
+++ b/lib/Froxlor/Database/DbManager.php
@@ -77,7 +77,15 @@ class DbManager
$this->manager = new DbManagerMySQL($this->log);
}
- public static function correctMysqlUsers($mysql_access_host_array)
+ /**
+ * function called when the mysql-access-host setting changes
+ *
+ * @param array $mysql_access_host_array
+ *
+ * @return void
+ * @throws \Exception
+ */
+ public static function correctMysqlUsers(array $mysql_access_host_array)
{
// get all databases for all dbservers
$databases = [];
@@ -136,13 +144,14 @@ class DbManager
* DB-name and user-name are being generated and
* the password for the user will be set
*
- * @param string $loginname
- * @param string $password
+ * @param ?string $loginname
+ * @param ?string $password
+ * @param int $dbserver
* @param int $last_accnumber
*
* @return string|bool $username if successful or false of username is equal to the password
*/
- public function createDatabase($loginname = null, $password = null, int $dbserver = 0, $last_accnumber = 0)
+ public function createDatabase(string $loginname = null, string $password = null, int $dbserver = 0, int $last_accnumber = 0)
{
Database::needRoot(true, $dbserver, false);
diff --git a/lib/Froxlor/Database/IntegrityCheck.php b/lib/Froxlor/Database/IntegrityCheck.php
index 7972f8f7..a432af15 100644
--- a/lib/Froxlor/Database/IntegrityCheck.php
+++ b/lib/Froxlor/Database/IntegrityCheck.php
@@ -85,21 +85,22 @@ class IntegrityCheck
/**
* check whether the froxlor database and its tables are in utf-8 character-set
*
- * @param bool $fix
- * fix db charset/collation if not utf8
+ * @param bool $fix fix db charset/collation if not utf8
*
- * @return boolean
+ * @return bool
+ * @throws \Exception
*/
- public function databaseCharset($fix = false)
+ public function databaseCharset(bool $fix = false): bool
{
- // get characterset
+ // get character-set
$cs_stmt = Database::prepare('SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = :dbname');
$resp = Database::pexecute_first($cs_stmt, [
'dbname' => Database::getDbName()
]);
- $charset = isset($resp['default_character_set_name']) ? $resp['default_character_set_name'] : null;
+ $charset = $resp['default_character_set_name'] ?? null;
if (!empty($charset) && substr(strtolower($charset), 0, 4) != 'utf8') {
- $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "database charset seems to be different from UTF-8, integrity-check can fix that");
+ $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE,
+ "database charset seems to be different from UTF-8, integrity-check can fix that");
if ($fix) {
// fix database
Database::query('ALTER DATABASE `' . Database::getDbName() . '` CHARACTER SET utf8 COLLATE utf8_general_ci');
@@ -109,7 +110,8 @@ class IntegrityCheck
$table = $row[0];
Database::query('ALTER TABLE `' . $table . '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;');
}
- $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_WARNING, "database charset was different from UTF-8, integrity-check fixed that");
+ $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_WARNING,
+ "database charset was different from UTF-8, integrity-check fixed that");
} else {
return false;
}
@@ -124,10 +126,12 @@ class IntegrityCheck
/**
* Check the integrity of the domain to ip/port - association
*
- * @param bool $fix
- * Fix everything found directly
+ * @param bool $fix fix everything found directly
+ *
+ * @return bool
+ * @throws \Exception
*/
- public function domainIpTable($fix = false)
+ public function domainIpTable(bool $fix = false): bool
{
$ips = [];
$domains = [];
@@ -184,9 +188,11 @@ class IntegrityCheck
'domainid' => $row['id_domain'],
'ipandportid' => $row['id_ipandports']
]);
- $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_WARNING, "found an ip/port-id in domain <> ip table which does not exist, integrity check fixed this");
+ $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_WARNING,
+ "found an ip/port-id in domain <> ip table which does not exist, integrity check fixed this");
} else {
- $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "found an ip/port-id in domain <> ip table which does not exist, integrity check can fix this");
+ $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE,
+ "found an ip/port-id in domain <> ip table which does not exist, integrity check can fix this");
return false;
}
}
@@ -196,9 +202,11 @@ class IntegrityCheck
'domainid' => $row['id_domain'],
'ipandportid' => $row['id_ipandports']
]);
- $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_WARNING, "found a domain-id in domain <> ip table which does not exist, integrity check fixed this");
+ $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_WARNING,
+ "found a domain-id in domain <> ip table which does not exist, integrity check fixed this");
} else {
- $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "found a domain-id in domain <> ip table which does not exist, integrity check can fix this");
+ $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE,
+ "found a domain-id in domain <> ip table which does not exist, integrity check can fix this");
return false;
}
}
@@ -216,9 +224,11 @@ class IntegrityCheck
'ipandportid' => $defaultip
]);
}
- $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_WARNING, "found a domain-id with no entry in domain <> ip table, integrity check fixed this");
+ $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_WARNING,
+ "found a domain-id with no entry in domain <> ip table, integrity check fixed this");
} else {
- $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "found a domain-id with no entry in domain <> ip table, integrity check can fix this");
+ $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE,
+ "found a domain-id with no entry in domain <> ip table, integrity check can fix this");
return false;
}
}
@@ -226,18 +236,19 @@ class IntegrityCheck
if ($fix) {
return $this->domainIpTable();
- } else {
- return true;
}
+ return true;
}
/**
* Check if all subdomains have ssl-redirect = 0 if domain has no ssl-port
*
- * @param bool $fix
- * Fix everything found directly
+ * @param bool $fix fix everything found directly
+ *
+ * @return bool
+ * @throws \Exception
*/
- public function subdomainSslRedirect($fix = false)
+ public function subdomainSslRedirect(bool $fix = false): bool
{
$ips = [];
$parentdomains = [];
@@ -300,28 +311,31 @@ class IntegrityCheck
Database::pexecute($upd_stmt, [
'domainid' => $id
]);
- $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_WARNING, "found a subdomain with ssl_redirect=1 but parent-domain has ssl=0, integrity check fixed this");
+ $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_WARNING,
+ "found a subdomain with ssl_redirect=1 but parent-domain has ssl=0, integrity check fixed this");
} else {
// It's just the check, let the function fail
- $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "found a subdomain with ssl_redirect=1 but parent-domain has ssl=0, integrity check can fix this");
+ $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE,
+ "found a subdomain with ssl_redirect=1 but parent-domain has ssl=0, integrity check can fix this");
return false;
}
}
if ($fix) {
return $this->subdomainSslRedirect();
- } else {
- return true;
}
+ return true;
}
/**
* Check if all subdomain have letsencrypt = 0 if domain has no ssl-port
*
- * @param bool $fix
- * Fix everything found directly
+ * @param bool $fix fix everything found directly
+ *
+ * @return bool
+ * @throws \Exception
*/
- public function subdomainLetsencrypt($fix = false)
+ public function subdomainLetsencrypt(bool $fix = false): bool
{
$ips = [];
$parentdomains = [];
@@ -384,31 +398,32 @@ class IntegrityCheck
Database::pexecute($upd_stmt, [
'domainid' => $id
]);
- $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_WARNING, "found a subdomain with letsencrypt=1 but parent-domain has ssl=0, integrity check fixed this");
+ $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_WARNING,
+ "found a subdomain with letsencrypt=1 but parent-domain has ssl=0, integrity check fixed this");
} else {
// It's just the check, let the function fail
- $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "found a subdomain with letsencrypt=1 but parent-domain has ssl=0, integrity check can fix this");
+ $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE,
+ "found a subdomain with letsencrypt=1 but parent-domain has ssl=0, integrity check can fix this");
return false;
}
}
if ($fix) {
return $this->subdomainLetsencrypt();
- } else {
- return true;
}
+ return true;
}
/**
* check whether the webserveruser is in
* the customers groups when fcgid / php-fpm is used
*
- * @param bool $fix
- * fix member/groups
+ * @param bool $fix fix member/groups
*
- * @return boolean
+ * @return bool
+ * @throws \Exception
*/
- public function webserverGroupMemberForFcgidPhpFpm($fix = false)
+ public function webserverGroupMemberForFcgidPhpFpm(bool $fix = false): bool
{
if (Settings::Get('system.mod_fcgid') == 0 && Settings::Get('phpfpm.enabled') == 0) {
return true;
@@ -423,7 +438,8 @@ class IntegrityCheck
]);
if ($cwg_stmt->rowCount() > 0) {
- $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "Customers are missing the webserver-user as group-member, integrity-check can fix that");
+ $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE,
+ "Customers are missing the webserver-user as group-member, integrity-check can fix that");
if ($fix) {
// prepare update statement
$upd_stmt = Database::prepare("
@@ -438,7 +454,8 @@ class IntegrityCheck
$upd_data['id'] = $cwg_row['id'];
Database::pexecute($upd_stmt, $upd_data);
}
- $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "Customers were missing the webserver-user as group-member, integrity-check fixed that");
+ $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE,
+ "Customers were missing the webserver-user as group-member, integrity-check fixed that");
} else {
return false;
}
@@ -455,12 +472,12 @@ class IntegrityCheck
* the customers groups when fcgid / php-fpm and
* fcgid/fpm in froxlor vhost is used
*
- * @param bool $fix
- * fix member/groups
+ * @param bool $fix fix member/groups
*
- * @return boolean
+ * @return bool
+ * @throws \Exception
*/
- public function froxlorLocalGroupMemberForFcgidPhpFpm($fix = false)
+ public function froxlorLocalGroupMemberForFcgidPhpFpm(bool $fix = false): bool
{
if (Settings::Get('system.mod_fcgid') == 0 && Settings::Get('phpfpm.enabled') == 0) {
return true;
@@ -491,7 +508,8 @@ class IntegrityCheck
]);
if ($cwg_stmt->rowCount() > 0) {
- $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "Customers are missing the local froxlor-user as group-member, integrity-check can fix that");
+ $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE,
+ "Customers are missing the local froxlor-user as group-member, integrity-check can fix that");
if ($fix) {
// prepare update statement
$upd_stmt = Database::prepare("
@@ -506,7 +524,8 @@ class IntegrityCheck
$upd_data['id'] = $cwg_row['id'];
Database::pexecute($upd_stmt, $upd_data);
}
- $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "Customers were missing the local froxlor-user as group-member, integrity-check fixed that");
+ $this->log->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE,
+ "Customers were missing the local froxlor-user as group-member, integrity-check fixed that");
} else {
return false;
}
diff --git a/lib/Froxlor/Database/Manager/DbManagerMySQL.php b/lib/Froxlor/Database/Manager/DbManagerMySQL.php
index 3114d02e..470daa87 100644
--- a/lib/Froxlor/Database/Manager/DbManagerMySQL.php
+++ b/lib/Froxlor/Database/Manager/DbManagerMySQL.php
@@ -48,7 +48,7 @@ class DbManagerMySQL
/**
* main constructor
*
- * @param FroxlorLogger $log
+ * @param FroxlorLogger|null $log
*/
public function __construct(&$log = null)
{
@@ -58,9 +58,9 @@ class DbManagerMySQL
/**
* creates a database
*
- * @param string $dbname
+ * @param string|null $dbname
*/
- public function createDatabase($dbname = null)
+ public function createDatabase(string $dbname = null)
{
Database::query("CREATE DATABASE `" . $dbname . "`");
}
@@ -71,13 +71,14 @@ class DbManagerMySQL
*
* @param string $username
* @param string|array $password
- * @param string $access_host
+ * @param ?string $access_host
* @param bool $p_encrypted
* optional, whether the password is encrypted or not, default false
* @param bool $update
* optional, whether to update the password only (not create user)
+ * @throws \Exception
*/
- public function grantPrivilegesTo($username = null, $password = null, $access_host = null, $p_encrypted = false, $update = false)
+ public function grantPrivilegesTo(string $username, $password, string $access_host = null, bool $p_encrypted = false, bool $update = false)
{
$pwd_plugin = 'mysql_native_password';
if (is_array($password) && count($password) == 2) {
@@ -141,8 +142,9 @@ class DbManagerMySQL
* takes away any privileges from a user to that db
*
* @param string $dbname
+ * @throws \Exception
*/
- public function deleteDatabase($dbname = null)
+ public function deleteDatabase(string $dbname)
{
if (version_compare(Database::getAttribute(PDO::ATTR_SERVER_VERSION), '5.0.2', '<')) {
// failsafe if user has been deleted manually (requires MySQL 4.1.2+)
@@ -178,8 +180,9 @@ class DbManagerMySQL
*
* @param string $username
* @param string $host
+ * @throws \Exception
*/
- public function deleteUser($username = null, $host = null)
+ public function deleteUser(string $username, string $host)
{
if (Database::getAttribute(PDO::ATTR_SERVER_VERSION) < '5.0.2') {
// Revoke privileges (only required for MySQL 4.1.2 - 5.0.1)
@@ -203,9 +206,9 @@ class DbManagerMySQL
*
* @param string $username
* @param string $host
- * (unused in mysql)
+ * @throws \Exception
*/
- public function disableUser($username = null, $host = null)
+ public function disableUser(string $username, string $host)
{
$stmt = Database::prepare('REVOKE ALL PRIVILEGES, GRANT OPTION FROM `' . $username . '`@`' . $host . '`');
Database::pexecute($stmt, [], false);
@@ -216,8 +219,9 @@ class DbManagerMySQL
*
* @param string $username
* @param string $host
+ * @throws \Exception
*/
- public function enableUser($username = null, $host = null)
+ public function enableUser(string $username, string $host)
{
// check whether user exists to avoid errors
$exist_check_stmt = Database::prepare("SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = '" . $username . "' AND host = '" . $host . "')");
@@ -239,14 +243,14 @@ class DbManagerMySQL
/**
* return an array of all usernames used in that DBMS
*
- * @param bool $user_only
- * if false, * will be selected from mysql.user and slightly different array will be generated
+ * @param bool $user_only if false, will be selected from mysql.user and slightly different array will be generated
*
* @return array
+ * @throws \Exception
*/
- public function getAllSqlUsers($user_only = true)
+ public function getAllSqlUsers(bool $user_only = true): array
{
- if ($user_only == false) {
+ if (!$user_only) {
$result_stmt = Database::prepare('SELECT * FROM mysql.user');
} else {
$result_stmt = Database::prepare('SELECT `User` FROM mysql.user');
diff --git a/lib/Froxlor/Dns/Dns.php b/lib/Froxlor/Dns/Dns.php
index 951fa050..7ed025a6 100644
--- a/lib/Froxlor/Dns/Dns.php
+++ b/lib/Froxlor/Dns/Dns.php
@@ -33,7 +33,15 @@ use PDO;
class Dns
{
- public static function getAllowedDomainEntry($domain_id, $area = 'customer', $userinfo = [])
+ /**
+ * @param int $domain_id
+ * @param string $area
+ * @param array $userinfo
+ *
+ * @return string|void
+ * @throws \Exception
+ */
+ public static function getAllowedDomainEntry(int $domain_id, string $area = 'customer', array $userinfo = [])
{
$dom_data = [
'did' => $domain_id
@@ -67,7 +75,15 @@ class Dns
Response::standardError('dns_notfoundorallowed');
}
- public static function createDomainZone($domain_id, $froxlorhostname = false, $isMainButSubTo = false)
+ /**
+ * @param int|array $domain_id id of domain or in case of froxlorhostname, a domain-array with the needed data
+ * @param bool $froxlorhostname
+ * @param bool $isMainButSubTo
+ *
+ * @return DnsZone|void
+ * @throws \Exception
+ */
+ public static function createDomainZone($domain_id, bool $froxlorhostname = false, bool $isMainButSubTo = false)
{
if (!$froxlorhostname) {
// get domain-name
@@ -146,16 +162,22 @@ class Dns
while ($subdomain = $subdomains_stmt->fetch(PDO::FETCH_ASSOC)) {
// Listing domains is enough as there currently is no support for choosing
// different ips for a subdomain => use same IPs as toplevel
- self::addRequiredEntry(str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'A', $required_entries);
- self::addRequiredEntry(str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'AAAA', $required_entries);
+ self::addRequiredEntry(str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'A',
+ $required_entries);
+ self::addRequiredEntry(str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'AAAA',
+ $required_entries);
// Check whether to add a www.-prefix
if ($subdomain['iswildcarddomain'] == '1') {
- self::addRequiredEntry('*.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'A', $required_entries);
- self::addRequiredEntry('*.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'AAAA', $required_entries);
+ self::addRequiredEntry('*.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'A',
+ $required_entries);
+ self::addRequiredEntry('*.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']),
+ 'AAAA', $required_entries);
} elseif ($subdomain['wwwserveralias'] == '1') {
- self::addRequiredEntry('www.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'A', $required_entries);
- self::addRequiredEntry('www.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'AAAA', $required_entries);
+ self::addRequiredEntry('www.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']), 'A',
+ $required_entries);
+ self::addRequiredEntry('www.' . str_replace('.' . $domain['domain'], '', $subdomain['domain']),
+ 'AAAA', $required_entries);
}
}
}
@@ -200,14 +222,17 @@ class Dns
// now generate all records and unset the required entries we have
foreach ($dom_entries as $entry) {
- if (array_key_exists($entry['type'], $required_entries) && array_key_exists(md5($entry['record']), $required_entries[$entry['type']])) {
+ if (array_key_exists($entry['type'], $required_entries) && array_key_exists(md5($entry['record']),
+ $required_entries[$entry['type']])) {
unset($required_entries[$entry['type']][md5($entry['record'])]);
}
- if (Settings::Get('system.dns_createcaaentry') == '1' && $entry['type'] == 'CAA' && strtolower(substr($entry['content'], 0, 7)) == '"v=caa1') {
+ if (Settings::Get('system.dns_createcaaentry') == '1' && $entry['type'] == 'CAA' && strtolower(substr($entry['content'],
+ 0, 7)) == '"v=caa1') {
// unset special CAA required-entry
unset($required_entries[$entry['type']][md5("@CAA@")]);
}
- if (Settings::Get('spf.use_spf') == '1' && $entry['type'] == 'TXT' && $entry['record'] == '@' && (strtolower(substr($entry['content'], 0, 7)) == '"v=spf1' || strtolower(substr($entry['content'], 0, 6)) == 'v=spf1')) {
+ if (Settings::Get('spf.use_spf') == '1' && $entry['type'] == 'TXT' && $entry['record'] == '@' && (strtolower(substr($entry['content'],
+ 0, 7)) == '"v=spf1' || strtolower(substr($entry['content'], 0, 6)) == 'v=spf1')) {
// unset special spf required-entry
unset($required_entries[$entry['type']][md5("@SPF@")]);
}
@@ -223,7 +248,8 @@ class Dns
'*'
] as $crecord
) {
- if ($entry['type'] == 'CNAME' && $entry['record'] == '@' && (array_key_exists(md5($crecord), $required_entries['A']) || array_key_exists(md5($crecord), $required_entries['AAAA']))) {
+ if ($entry['type'] == 'CNAME' && $entry['record'] == '@' && (array_key_exists(md5($crecord),
+ $required_entries['A']) || array_key_exists(md5($crecord), $required_entries['AAAA']))) {
unset($required_entries['A'][md5($crecord)]);
unset($required_entries['AAAA'][md5($crecord)]);
}
@@ -238,13 +264,16 @@ class Dns
'smtp'
] as $crecord
) {
- if ($entry['type'] == 'CNAME' && $entry['record'] == $crecord && (array_key_exists(md5($crecord), $required_entries['A']) || array_key_exists(md5($crecord), $required_entries['AAAA']))) {
+ if ($entry['type'] == 'CNAME' && $entry['record'] == $crecord && (array_key_exists(md5($crecord),
+ $required_entries['A']) || array_key_exists(md5($crecord),
+ $required_entries['AAAA']))) {
unset($required_entries['A'][md5($crecord)]);
unset($required_entries['AAAA'][md5($crecord)]);
}
}
}
- $zonerecords[] = new DnsEntry($entry['record'], $entry['type'], $entry['content'], $entry['prio'], $entry['ttl']);
+ $zonerecords[] = new DnsEntry($entry['record'], $entry['type'], $entry['content'], $entry['prio'],
+ $entry['ttl']);
}
// add missing required entries
@@ -275,7 +304,8 @@ class Dns
foreach ($records as $record) {
if ($type == 'A' && filter_var($ip['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false) {
$zonerecords[] = new DnsEntry($record, 'A', $ip['ip']);
- } elseif ($type == 'AAAA' && filter_var($ip['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) {
+ } elseif ($type == 'AAAA' && filter_var($ip['ip'], FILTER_VALIDATE_IP,
+ FILTER_FLAG_IPV6) !== false) {
$zonerecords[] = new DnsEntry($record, 'AAAA', $ip['ip']);
}
}
@@ -356,7 +386,8 @@ class Dns
if (substr($dkim_entries[0], 0, 1) == '(') {
$multiline = true;
}
- $zonerecords[] = new DnsEntry($record, 'TXT', self::encloseTXTContent($dkim_entries[0], $multiline));
+ $zonerecords[] = new DnsEntry($record, 'TXT',
+ self::encloseTXTContent($dkim_entries[0], $multiline));
}
}
}
@@ -416,7 +447,8 @@ class Dns
if (!$isMainButSubTo) {
$date = date('Ymd');
- $domain['bindserial'] = (preg_match('/^' . $date . '/', $domain['bindserial']) ? $domain['bindserial'] + 1 : $date . '00');
+ $domain['bindserial'] = (preg_match('/^' . $date . '/',
+ $domain['bindserial']) ? $domain['bindserial'] + 1 : $date . '00');
if (!$froxlorhostname) {
$upd_stmt = Database::prepare("
UPDATE `" . TABLE_PANEL_DOMAINS . "` SET
@@ -443,12 +475,19 @@ class Dns
array_unshift($zonerecords, $soa_record);
}
- $zone = new DnsZone((int)Settings::Get('system.defaultttl'), $domain['domain'], $domain['bindserial'], $zonerecords);
+ $zone = new DnsZone((int)Settings::Get('system.defaultttl'), $domain['domain'], $domain['bindserial'],
+ $zonerecords);
return $zone;
}
- private static function addRequiredEntry($record = '@', $type = 'A', &$required = [])
+ /**
+ * @param string $record
+ * @param string $type
+ * @param array $required
+ * @return void
+ */
+ private static function addRequiredEntry(string $record = '@', string $type = 'A', array &$required = [])
{
if (!isset($required[$type])) {
$required[$type] = [];
@@ -456,7 +495,11 @@ class Dns
$required[$type][md5($record)] = $record;
}
- private static function generateDkimEntries($domain)
+ /**
+ * @param array $domain
+ * @return array
+ */
+ private static function generateDkimEntries(array $domain): array
{
$zone_dkim = [];
@@ -486,7 +529,8 @@ class Dns
}
// key
- $dkim_txt .= 'k=rsa;p=' . trim(preg_replace('/-----BEGIN PUBLIC KEY-----(.+)-----END PUBLIC KEY-----/s', '$1', str_replace("\n", '', $domain['dkim_pubkey']))) . ';';
+ $dkim_txt .= 'k=rsa;p=' . trim(preg_replace('/-----BEGIN PUBLIC KEY-----(.+)-----END PUBLIC KEY-----/s',
+ '$1', str_replace("\n", '', $domain['dkim_pubkey']))) . ';';
// service-type
if (Settings::Get('dkim.dkim_servicetype') == '1') {
@@ -503,10 +547,15 @@ class Dns
return $zone_dkim;
}
- public static function encloseTXTContent($txt_content, $isMultiLine = false)
+ /**
+ * @param string $txt_content
+ * @param bool $isMultiLine
+ * @return string
+ */
+ public static function encloseTXTContent(string $txt_content, bool $isMultiLine = false): string
{
// check that TXT content is enclosed in " "
- if ($isMultiLine == false && Settings::Get('system.dns_server') != 'PowerDNS') {
+ if (!$isMultiLine && Settings::Get('system.dns_server') != 'PowerDNS') {
if (substr($txt_content, 0, 1) != '"') {
$txt_content = '"' . $txt_content;
}
@@ -526,10 +575,13 @@ class Dns
return $txt_content;
}
- private static function escapeSoaAdminMail($email)
+ /**
+ * @param string $email
+ * @return string
+ */
+ private static function escapeSoaAdminMail(string $email): string
{
$mail_parts = explode("@", $email);
- $escpd_mail = str_replace(".", "\.", $mail_parts[0]) . "." . $mail_parts[1] . ".";
- return $escpd_mail;
+ return str_replace(".", "\.", $mail_parts[0]) . "." . $mail_parts[1] . ".";
}
}
diff --git a/lib/Froxlor/Dns/DnsEntry.php b/lib/Froxlor/Dns/DnsEntry.php
index e2e8c8f3..ade8f570 100644
--- a/lib/Froxlor/Dns/DnsEntry.php
+++ b/lib/Froxlor/Dns/DnsEntry.php
@@ -29,14 +29,22 @@ use Froxlor\Settings;
class DnsEntry
{
- public $record;
- public $ttl;
- public $class = 'IN';
- public $type;
- public $priority;
- public $content;
+ public string $record;
+ public int $ttl;
+ public string $class = 'IN';
+ public string $type;
+ public int $priority;
+ public ?string $content;
- public function __construct($record = '', $type = 'A', $content = null, $prio = 0, $ttl = 0, $class = 'IN')
+ /**
+ * @param string $record
+ * @param string $type
+ * @param string|null $content
+ * @param int $prio
+ * @param int $ttl
+ * @param string $class
+ */
+ public function __construct(string $record = '', string $type = 'A', string $content = null, int $prio = 0, int $ttl = 0, string $class = 'IN')
{
$this->record = $record;
$this->type = $type;
@@ -72,7 +80,6 @@ class DnsEntry
// last line
$_content .= "\t\t\t\t" . '"' . $_l . '")';
}
- $result = $this->record . "\t" . $this->ttl . "\t" . $this->class . "\t" . $this->type . "\t" . (($this->priority >= 0 && ($this->type == 'MX' || $this->type == 'SRV')) ? $this->priority . "\t" : "") . $_content . PHP_EOL;
- return $result;
+ return $this->record . "\t" . $this->ttl . "\t" . $this->class . "\t" . $this->type . "\t" . (($this->priority >= 0 && ($this->type == 'MX' || $this->type == 'SRV')) ? $this->priority . "\t" : "") . $_content . PHP_EOL;
}
}
diff --git a/lib/Froxlor/Dns/DnsZone.php b/lib/Froxlor/Dns/DnsZone.php
index 5fb4d22b..3e4eea46 100644
--- a/lib/Froxlor/Dns/DnsZone.php
+++ b/lib/Froxlor/Dns/DnsZone.php
@@ -29,12 +29,18 @@ use Froxlor\Settings;
class DnsZone
{
- public $ttl;
- public $origin;
- public $serial;
- public $records;
+ public int $ttl;
+ public string $origin;
+ public string $serial;
+ public ?array $records;
- public function __construct($ttl = 0, $origin = '', $serial = '', $records = null)
+ /**
+ * @param int $ttl
+ * @param string $origin
+ * @param string $serial
+ * @param array|null $records
+ */
+ public function __construct(int $ttl = 0, string $origin = '', string $serial = '', array $records = null)
{
$this->ttl = ($ttl <= 0 ? Settings::Get('system.defaultttl') : $ttl);
$this->origin = $origin;
@@ -44,13 +50,13 @@ class DnsZone
public function __toString()
{
- $_zonefile = "\$TTL " . $this->ttl . PHP_EOL;
- $_zonefile .= "\$ORIGIN " . $this->origin . "." . PHP_EOL;
+ $zone_file = "\$TTL " . $this->ttl . PHP_EOL;
+ $zone_file .= "\$ORIGIN " . $this->origin . "." . PHP_EOL;
if (!empty($this->records)) {
foreach ($this->records as $record) {
- $_zonefile .= (string)$record;
+ $zone_file .= (string)$record;
}
}
- return $_zonefile;
+ return $zone_file;
}
}
diff --git a/lib/Froxlor/Dns/PowerDNS.php b/lib/Froxlor/Dns/PowerDNS.php
index 33c864eb..f1a3aef1 100644
--- a/lib/Froxlor/Dns/PowerDNS.php
+++ b/lib/Froxlor/Dns/PowerDNS.php
@@ -37,9 +37,9 @@ class PowerDNS
/**
* remove all records and entries of a given domain
*
- * @param array $domain
+ * @param array|null $domain
*/
- public static function cleanDomainZone($domain = null)
+ public static function cleanDomainZone(array $domain = null)
{
if (is_array($domain) && isset($domain['domain'])) {
$pdns_domains_stmt = self::getDB()->prepare("SELECT `id`, `name` FROM `domains` WHERE `name` = :domain");
@@ -67,16 +67,19 @@ class PowerDNS
/**
* get pdo database connection to powerdns database
*
- * @return PDO
+ * @return \PDO
*/
- public static function getDB()
+ public static function getDB(): \PDO
{
- if (!isset(self::$pdns_db) || (self::$pdns_db instanceof PDO) == false) {
+ if (!isset(self::$pdns_db) || !(self::$pdns_db instanceof PDO)) {
self::connectToPdnsDb();
}
return self::$pdns_db;
}
+ /**
+ * @return void
+ */
private static function connectToPdnsDb()
{
// get froxlor pdns config
diff --git a/lib/Froxlor/Domain/Domain.php b/lib/Froxlor/Domain/Domain.php
index c5dd7f9d..ebc16eb0 100644
--- a/lib/Froxlor/Domain/Domain.php
+++ b/lib/Froxlor/Domain/Domain.php
@@ -41,8 +41,9 @@ class Domain
*
* @param int $domain_id
* @return array
+ * @throws \Exception
*/
- public static function getIpsOfDomain($domain_id)
+ public static function getIpsOfDomain(int $domain_id = 0): array
{
if ($domain_id > 0) {
$sel_stmt = Database::prepare("
@@ -75,7 +76,7 @@ class Domain
*
* @return array array of enabled redirect-codes
*/
- public static function getRedirectCodesArray()
+ public static function getRedirectCodesArray(): array
{
$sql = "SELECT * FROM `" . TABLE_PANEL_REDIRECTCODES . "` WHERE `enabled` = '1' ORDER BY `id` ASC";
$result_stmt = Database::query($sql);
@@ -92,12 +93,12 @@ class Domain
* returns the redirect-code for a given
* domain-id
*
- * @param integer $domainid
- * id of the domain
+ * @param int $domainid id of the domain
*
* @return string redirect-code
+ * @throws \Exception
*/
- public static function getDomainRedirectCode($domainid = 0)
+ public static function getDomainRedirectCode(int $domainid = 0): string
{
// get system default
$default = '301';
@@ -128,12 +129,11 @@ class Domain
* return an array of all enabled redirect-codes
* for the settings form
*
- * @param bool $add_desc
- * optional, default true, add the code-description
+ * @param bool $add_desc optional, default true, add the code-description
*
* @return array array of enabled redirect-codes
*/
- public static function getRedirectCodes($add_desc = true)
+ public static function getRedirectCodes(bool $add_desc = true): array
{
$sql = "SELECT * FROM `" . TABLE_PANEL_REDIRECTCODES . "` WHERE `enabled` = '1' ORDER BY `id` ASC";
$result_stmt = Database::query($sql);
@@ -153,12 +153,12 @@ class Domain
* returns the redirect-id for a given
* domain-id
*
- * @param integer $domainid
- * id of the domain
+ * @param int $domainid id of the domain
*
- * @return integer redirect-code-id
+ * @return int redirect-code-id
+ * @throws \Exception
*/
- public static function getDomainRedirectId($domainid = 0)
+ public static function getDomainRedirectId(int $domainid = 0): int
{
$code = 1;
if ($domainid > 0) {
@@ -171,7 +171,7 @@ class Domain
'domainid' => $domainid
]);
- if (is_array($result) && isset($result['redirect'])) {
+ if ($result && isset($result['redirect'])) {
$code = (int)$result['redirect'];
}
}
@@ -179,16 +179,15 @@ class Domain
}
/**
- * adds a redirectcode for a domain
+ * adds a redirect-code for a domain
*
- * @param integer $domainid
- * id of the domain to add the code for
- * @param integer $redirect
- * selected redirect-id
+ * @param int $domainid id of the domain to add the code for
+ * @param int $redirect selected redirect-id
*
* @return null
+ * @throws \Exception
*/
- public static function addRedirectToDomain($domainid = 0, $redirect = 1)
+ public static function addRedirectToDomain(int $domainid = 0, int $redirect = 1)
{
if ($domainid > 0) {
$ins_stmt = Database::prepare("
@@ -202,19 +201,18 @@ class Domain
}
/**
- * updates the redirectcode of a domain
+ * updates the redirect-code of a domain
* if redirect-code is false, nothing happens
*
- * @param integer $domainid
- * id of the domain to update
- * @param integer $redirect
- * selected redirect-id or false
+ * @param int $domainid id of the domain to update
+ * @param int $redirect selected redirect-id
*
* @return null
+ * @throws \Exception
*/
- public static function updateRedirectOfDomain($domainid = 0, $redirect = false)
+ public static function updateRedirectOfDomain(int $domainid = 0, int $redirect = 0)
{
- if ($redirect == false) {
+ if (!$redirect) {
return;
}
@@ -240,12 +238,12 @@ class Domain
* check whether a domain has subdomains added as full-domains
* #329
*
- * @param int $id
- * domain-id
+ * @param int $id domain-id
*
- * @return boolean
+ * @return bool
+ * @throws \Exception
*/
- public static function domainHasMainSubDomains($id = 0)
+ public static function domainHasMainSubDomains(int $id): bool
{
$result_stmt = Database::prepare("
SELECT COUNT(`id`) as `mainsubs` FROM `" . TABLE_PANEL_DOMAINS . "`
@@ -254,8 +252,8 @@ class Domain
'id' => $id
]);
- if (isset($result['mainsubs']) && $result['mainsubs'] > 0) {
- return true;
+ if ($result && isset($result['mainsubs'])) {
+ return $result['mainsubs'] > 0;
}
return false;
}
@@ -264,12 +262,12 @@ class Domain
* check whether a subof-domain exists
* #329
*
- * @param int $id
- * subof-domain-id
+ * @param int $id subof-domain-id
*
- * @return boolean
+ * @return bool
+ * @throws \Exception
*/
- public static function domainMainToSubExists($id = 0)
+ public static function domainMainToSubExists(int $id): bool
{
$result_stmt = Database::prepare("
SELECT `id` FROM `" . TABLE_PANEL_DOMAINS . "` WHERE `id` = :id");
@@ -278,8 +276,8 @@ class Domain
]);
$result = $result_stmt->fetch(PDO::FETCH_ASSOC);
- if (isset($result['id']) && $result['id'] > 0) {
- return true;
+ if ($result && isset($result['id'])) {
+ return $result['id'] > 0;
}
return false;
}
@@ -289,9 +287,10 @@ class Domain
*
* @param int $domainid
*
- * @return boolean
+ * @return bool
+ * @throws \Exception
*/
- public static function domainHasSslIpPort($domainid = 0)
+ public static function domainHasSslIpPort(int $domainid): bool
{
$result_stmt = Database::prepare("
SELECT `dt`.* FROM `" . TABLE_DOMAINTOIP . "` `dt`, `" . TABLE_PANEL_IPSANDPORTS . "` `iap`
@@ -301,7 +300,7 @@ class Domain
]);
$result = $result_stmt->fetch(PDO::FETCH_ASSOC);
- if (is_array($result) && isset($result['id_ipandports'])) {
+ if ($result && isset($result['id_ipandports'])) {
return true;
}
return false;
@@ -311,12 +310,12 @@ class Domain
* returns true or false whether a given domain id
* is the std-subdomain of a customer
*
- * @param
- * int domain-id
+ * @param int $did domain-id
*
- * @return boolean
+ * @return bool
+ * @throws \Exception
*/
- public static function isCustomerStdSubdomain($did = 0)
+ public static function isCustomerStdSubdomain(int $did): bool
{
if ($did > 0) {
$result_stmt = Database::prepare("
@@ -327,17 +326,27 @@ class Domain
'did' => $did
]);
- if (is_array($result) && isset($result['customerid']) && $result['customerid'] > 0) {
- return true;
+ if ($result && isset($result['customerid'])) {
+ return $result['customerid'] > 0;
}
}
return false;
}
- public static function triggerLetsEncryptCSRForAliasDestinationDomain($aliasDestinationDomainID, $log)
- {
- if (isset($aliasDestinationDomainID) && $aliasDestinationDomainID > 0) {
- $log->logAction(FroxlorLogger::ADM_ACTION, LOG_INFO, "LetsEncrypt CSR triggered for domain ID " . $aliasDestinationDomainID);
+ /**
+ * @param int $aliasDestinationDomainID
+ * @param FroxlorLogger $log
+ *
+ * @return void
+ * @throws \Exception
+ */
+ public static function triggerLetsEncryptCSRForAliasDestinationDomain(
+ int $aliasDestinationDomainID,
+ FroxlorLogger $log
+ ) {
+ if ($aliasDestinationDomainID > 0) {
+ $log->logAction(FroxlorLogger::ADM_ACTION, LOG_INFO,
+ "LetsEncrypt CSR triggered for domain ID " . $aliasDestinationDomainID);
$upd_stmt = Database::prepare("UPDATE
`" . TABLE_PANEL_DOMAIN_SSL_SETTINGS . "`
SET
@@ -351,7 +360,11 @@ class Domain
}
}
- public static function doLetsEncryptCleanUp($domainname = null)
+ /**
+ * @param string $domainname
+ * @return true
+ */
+ public static function doLetsEncryptCleanUp(string $domainname): bool
{
// @ see \Froxlor\Cron\Http\LetsEncrypt\AcmeSh.php
$acmesh = AcmeSh::getAcmeSh();
@@ -374,18 +387,19 @@ class Domain
/**
* checks give path for security issues
* and returns a string that can be appended
- * to a line for a open_basedir directive
+ * to a line for an open_basedir directive
*
- * @param string $path
- * the path to check and append
- * @param boolean $first
- * if true, no ':' will be prefixed to the path
+ * @param string $path the path to check and append
+ * @param bool $first if true, no ':' will be prefixed to the path
*
* @return string
+ * @throws \Exception
*/
- public static function appendOpenBasedirPath($path = '', $first = false)
+ public static function appendOpenBasedirPath(string $path = '', bool $first = false): string
{
- if ($path != '' && $path != '/' && (!preg_match("#^/dev#i", $path) || preg_match("#^/dev/urandom#i", $path)) && !preg_match("#^/proc#i", $path) && !preg_match("#^/etc#i", $path) && !preg_match("#^/sys#i", $path) && !preg_match("#:#", $path)) {
+ if ($path != '' && $path != '/' && (!preg_match("#^/dev#i", $path) || preg_match("#^/dev/urandom#i",
+ $path)) && !preg_match("#^/proc#i", $path) && !preg_match("#^/etc#i",
+ $path) && !preg_match("#^/sys#i", $path) && !preg_match("#:#", $path)) {
if (preg_match("#^/dev/urandom#i", $path)) {
$path = FileDir::makeCorrectFile($path);
} else {
@@ -394,7 +408,7 @@ class Domain
// check for php-version that requires the trailing
// slash to be removed as it does not allow the usage
- // of the subfolders within the given folder, fixes #797
+ // of the sub-folders within the given folder, fixes #797
if ((PHP_MINOR_VERSION == 2 && PHP_VERSION_ID >= 50216) || PHP_VERSION_ID >= 50304) {
// check trailing slash
if (substr($path, -1, 1) == '/') {
diff --git a/lib/Froxlor/Domain/IpAddr.php b/lib/Froxlor/Domain/IpAddr.php
index 5bc76f44..1c6f5cdf 100644
--- a/lib/Froxlor/Domain/IpAddr.php
+++ b/lib/Froxlor/Domain/IpAddr.php
@@ -30,8 +30,10 @@ use PDO;
class IpAddr
{
-
- public static function getIpAddresses()
+ /**
+ * @return array
+ */
+ public static function getIpAddresses(): array
{
$result_stmt = Database::query("
SELECT `id`, `ip`, `port` FROM `" . TABLE_PANEL_IPSANDPORTS . "` ORDER BY `ip` ASC, `port` ASC
@@ -51,14 +53,22 @@ class IpAddr
return $system_ipaddress_array;
}
- public static function getSslIpPortCombinations()
+ /**
+ * @return array
+ */
+ public static function getSslIpPortCombinations(): array
{
return [
'' => lng('panel.none_value')
] + self::getIpPortCombinations(true);
}
- public static function getIpPortCombinations($ssl = false)
+ /**
+ * @param bool $ssl
+ * @return array
+ * @throws \Exception
+ */
+ public static function getIpPortCombinations(bool $ssl = false): array
{
global $userinfo;
diff --git a/lib/Froxlor/FileDir.php b/lib/Froxlor/FileDir.php
index 37f2af2c..79f60b75 100644
--- a/lib/Froxlor/FileDir.php
+++ b/lib/Froxlor/FileDir.php
@@ -38,30 +38,24 @@ class FileDir
* which had to be created below with correct Owner/Group
* (Copied from cron_tasks.php:rev1189 as we'll need this more often in future)
*
- * @param string $homeDir
- * The homedir of the user
- * @param string $dirToCreate
- * The dir which should be created
- * @param int $uid
- * The uid of the user
- * @param int $gid
- * The gid of the user
- * @param bool $placeindex
- * Place standard-index.html into the new folder
- * @param bool $allow_notwithinhomedir
- * Allow creating a directory out of the customers docroot
+ * @param string $homeDir The homedir of the user
+ * @param string $dirToCreate The dir which should be created
+ * @param int $uid The uid of the user
+ * @param int $gid The gid of the user
+ * @param bool $placeindex Place standard-index.html into the new folder
+ * @param bool $allow_notwithinhomedir Allow creating a directory out of the customers docroot
*
* @return bool true if everything went okay, false if something went wrong
* @throws Exception
*/
public static function mkDirWithCorrectOwnership(
- $homeDir,
- $dirToCreate,
- $uid,
- $gid,
- $placeindex = false,
- $allow_notwithinhomedir = false
- ) {
+ string $homeDir,
+ string $dirToCreate,
+ int $uid,
+ int $gid,
+ bool $placeindex = false,
+ bool $allow_notwithinhomedir = false
+ ): bool {
if ($homeDir != '' && $dirToCreate != '') {
$homeDir = self::makeCorrectDir($homeDir);
$dirToCreate = self::makeCorrectDir($dirToCreate);
@@ -116,15 +110,14 @@ class FileDir
* Function which returns a correct dirname, means to add slashes at the beginning and at the end if there weren't
* some
*
- * @param string $path
- * the path to correct
+ * @param string $dir the path to correct
*
* @return string the corrected path
* @throws Exception
*/
- public static function makeCorrectDir($dir)
+ public static function makeCorrectDir(string $dir): string
{
- if (is_string($dir) && strlen($dir) > 0) {
+ if (strlen($dir) > 0) {
$dir = trim($dir);
if (substr($dir, -1, 1) != '/') {
$dir .= '/';
@@ -140,12 +133,11 @@ class FileDir
/**
* Function which returns a secure path, means to remove all multiple dots and slashes
*
- * @param string $path
- * the path to secure
+ * @param string $path the path to secure
*
* @return string the corrected path
*/
- public static function makeSecurePath($path)
+ public static function makeSecurePath(string $path): string
{
// check for bad characters, some are allowed with escaping,
// but we generally don't want them in our directory-names,
@@ -191,16 +183,13 @@ class FileDir
/**
* Wrapper around the exec command.
*
- * @param string $exec_string
- * command to be executed
- * @param string $return_value
- * referenced variable where the output is stored
- * @param array $allowedChars
- * optional array of allowed characters in path/command
+ * @param string $exec_string command to be executed
+ * @param mixed $return_value referenced variable where the output is stored
+ * @param ?array $allowedChars optional array of allowed characters in path/command
*
* @return array result of exec()
*/
- public static function safe_exec($exec_string, &$return_value = false, $allowedChars = null)
+ public static function safe_exec(string $exec_string, &$return_value = false, $allowedChars = null)
{
$disallowed = [
';',
@@ -245,19 +234,20 @@ class FileDir
/**
* store the default index-file in a given destination folder
*
- * @param string $loginname
- * customers loginname
- * @param string $destination
- * path where to create the file
- * @param object $logger
- * FroxlorLogger object
- * @param boolean $force
- * force creation whatever the settings say (needed for task #2, create new user)
+ * @param string $loginname customers loginname
+ * @param string $destination path where to create the file
+ * @param object $logger FroxlorLogger object
+ * @param bool $force force creation whatever the settings say (needed for task #2, create new user)
*
- * @return null
+ * @return void
+ * @throws Exception
*/
- public static function storeDefaultIndex($loginname = null, $destination = null, $logger = null, $force = false)
- {
+ public static function storeDefaultIndex(
+ string $loginname,
+ string $destination,
+ $logger = null,
+ bool $force = false
+ ) {
if ($force || (int)Settings::Get('system.store_index_file_subs') == 1) {
$result_stmt = Database::prepare("
SELECT `t`.`value`, `c`.`email` AS `customer_email`, `a`.`email` AS `admin_email`, `c`.`loginname` AS `customer_login`, `a`.`loginname` AS `admin_login`
@@ -306,18 +296,16 @@ class FileDir
self::safe_exec('cp -a ' . Froxlor::getInstallDir() . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination));
}
}
- return;
}
/**
* Function which returns a correct filename, means to add a slash at the beginning if there wasn't one
*
- * @param string $filename
- * the filename
+ * @param string $filename the filename
*
* @return string the corrected filename
*/
- public static function makeCorrectFile(string $filename)
+ public static function makeCorrectFile(string $filename): string
{
if (trim($filename) == '') {
$error = 'Given filename for function ' . __FUNCTION__ . ' is empty.' . "\n";
@@ -333,21 +321,19 @@ class FileDir
$filename = '/' . $filename;
}
- $filename = self::makeSecurePath($filename);
- return $filename;
+ return self::makeSecurePath($filename);
}
/**
* checks a directory against disallowed paths which could
* lead to a damaged system if you use them
*
- * @param string $fieldname
- * @param array $fielddata
- * @param mixed $newfieldvalue
+ * @param string|null $path
*
- * @return boolean|array
+ * @return bool
+ * @throws Exception
*/
- public static function checkDisallowedPaths($path = null)
+ public static function checkDisallowedPaths(string $path): bool
{
/*
* disallow base-directories and /
@@ -385,12 +371,11 @@ class FileDir
/**
* Function which returns a correct destination for Postfix Virtual Table
*
- * @param
- * string The destinations
+ * @param string $destination The destinations
+ *
* @return string the corrected destinations
- * @author Florian Lippert ';
$debug = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
foreach ($debug as $dline) {
- $err_display .= $dline['function'] . '() called at [' . str_replace(Froxlor::getInstallDir(), '', ($dline['file'] ?? 'unknown')) . ':' . ($dline['line'] ?? 0) . ']
';
+ $err_display .= $dline['function'] . '() called at [' . str_replace(Froxlor::getInstallDir(), '',
+ ($dline['file'] ?? 'unknown')) . ':' . ($dline['line'] ?? 0) . ']
';
}
$err_display .= '