major refactoring of almost all files
This commit is contained in:
@@ -1,7 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can also view it online at
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
namespace Froxlor\Domain;
|
||||
|
||||
use Froxlor\Cron\Http\LetsEncrypt\AcmeSh;
|
||||
use Froxlor\Database\Database;
|
||||
use Froxlor\FileDir;
|
||||
use Froxlor\FroxlorLogger;
|
||||
use Froxlor\Settings;
|
||||
use PDO;
|
||||
|
||||
class Domain
|
||||
{
|
||||
@@ -22,20 +51,20 @@ class Domain
|
||||
AND dip.id_domain = :domainid
|
||||
GROUP BY i.ip
|
||||
");
|
||||
$sel_param = array(
|
||||
$sel_param = [
|
||||
'domainid' => $domain_id
|
||||
);
|
||||
];
|
||||
} else {
|
||||
// assuming froxlor.vhost (id = 0)
|
||||
$sel_stmt = Database::prepare("
|
||||
SELECT ip FROM `" . TABLE_PANEL_IPSANDPORTS . "`
|
||||
GROUP BY ip
|
||||
");
|
||||
$sel_param = array();
|
||||
$sel_param = [];
|
||||
}
|
||||
Database::pexecute($sel_stmt, $sel_param);
|
||||
$result = array();
|
||||
while ($ip = $sel_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$result = [];
|
||||
while ($ip = $sel_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$result[] = $ip['ip'];
|
||||
}
|
||||
return $result;
|
||||
@@ -51,71 +80,42 @@ class Domain
|
||||
$sql = "SELECT * FROM `" . TABLE_PANEL_REDIRECTCODES . "` WHERE `enabled` = '1' ORDER BY `id` ASC";
|
||||
$result_stmt = Database::query($sql);
|
||||
|
||||
$codes = array();
|
||||
while ($rc = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$codes = [];
|
||||
while ($rc = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$codes[] = $rc;
|
||||
}
|
||||
|
||||
return $codes;
|
||||
}
|
||||
|
||||
/**
|
||||
* return an array of all enabled redirect-codes
|
||||
* for the settings form
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
global $lng;
|
||||
|
||||
$sql = "SELECT * FROM `" . TABLE_PANEL_REDIRECTCODES . "` WHERE `enabled` = '1' ORDER BY `id` ASC";
|
||||
$result_stmt = Database::query($sql);
|
||||
|
||||
$codes = array();
|
||||
while ($rc = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$codes[$rc['id']] = $rc['code'];
|
||||
if ($add_desc) {
|
||||
$codes[$rc['id']] .= ' (' . $lng['redirect_desc'][$rc['desc']] . ')';
|
||||
}
|
||||
}
|
||||
|
||||
return $codes;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the redirect-code for a given
|
||||
* domain-id
|
||||
*
|
||||
* @param integer $domainid
|
||||
* id of the domain
|
||||
*
|
||||
* id of the domain
|
||||
*
|
||||
* @return string redirect-code
|
||||
*/
|
||||
public static function getDomainRedirectCode($domainid = 0)
|
||||
{
|
||||
|
||||
// get system default
|
||||
$default = '301';
|
||||
if (\Froxlor\Settings::Get('customredirect.enabled') == '1') {
|
||||
if (Settings::Get('customredirect.enabled') == '1') {
|
||||
$all_codes = self::getRedirectCodes(false);
|
||||
$_default = $all_codes[\Froxlor\Settings::Get('customredirect.default')];
|
||||
$_default = $all_codes[Settings::Get('customredirect.default')];
|
||||
$default = ($_default == '---') ? $default : $_default;
|
||||
}
|
||||
$code = $default;
|
||||
if ($domainid > 0) {
|
||||
|
||||
$result_stmt = Database::prepare("
|
||||
SELECT `r`.`code` as `redirect`
|
||||
FROM `" . TABLE_PANEL_REDIRECTCODES . "` `r`, `" . TABLE_PANEL_DOMAINREDIRECTS . "` `rc`
|
||||
WHERE `r`.`id` = `rc`.`rid` and `rc`.`did` = :domainid
|
||||
");
|
||||
$result = Database::pexecute_first($result_stmt, array(
|
||||
$result = Database::pexecute_first($result_stmt, [
|
||||
'domainid' => $domainid
|
||||
));
|
||||
]);
|
||||
|
||||
if (is_array($result) && isset($result['redirect'])) {
|
||||
$code = ($result['redirect'] == '---') ? $default : $result['redirect'];
|
||||
@@ -124,13 +124,40 @@ class Domain
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* return an array of all enabled redirect-codes
|
||||
* for the settings form
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
global $lng;
|
||||
|
||||
$sql = "SELECT * FROM `" . TABLE_PANEL_REDIRECTCODES . "` WHERE `enabled` = '1' ORDER BY `id` ASC";
|
||||
$result_stmt = Database::query($sql);
|
||||
|
||||
$codes = [];
|
||||
while ($rc = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$codes[$rc['id']] = $rc['code'];
|
||||
if ($add_desc) {
|
||||
$codes[$rc['id']] .= ' (' . $lng['redirect_desc'][$rc['desc']] . ')';
|
||||
}
|
||||
}
|
||||
|
||||
return $codes;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the redirect-id for a given
|
||||
* domain-id
|
||||
*
|
||||
* @param integer $domainid
|
||||
* id of the domain
|
||||
*
|
||||
* id of the domain
|
||||
*
|
||||
* @return integer redirect-code-id
|
||||
*/
|
||||
public static function getDomainRedirectId($domainid = 0)
|
||||
@@ -142,12 +169,12 @@ class Domain
|
||||
FROM `" . TABLE_PANEL_REDIRECTCODES . "` `r`, `" . TABLE_PANEL_DOMAINREDIRECTS . "` `rc`
|
||||
WHERE `r`.`id` = `rc`.`rid` and `rc`.`did` = :domainid
|
||||
");
|
||||
$result = Database::pexecute_first($result_stmt, array(
|
||||
$result = Database::pexecute_first($result_stmt, [
|
||||
'domainid' => $domainid
|
||||
));
|
||||
]);
|
||||
|
||||
if (is_array($result) && isset($result['redirect'])) {
|
||||
$code = (int) $result['redirect'];
|
||||
$code = (int)$result['redirect'];
|
||||
}
|
||||
}
|
||||
return $code;
|
||||
@@ -157,10 +184,10 @@ class Domain
|
||||
* adds a redirectcode for a domain
|
||||
*
|
||||
* @param integer $domainid
|
||||
* id of the domain to add the code for
|
||||
* id of the domain to add the code for
|
||||
* @param integer $redirect
|
||||
* selected redirect-id
|
||||
*
|
||||
* selected redirect-id
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public static function addRedirectToDomain($domainid = 0, $redirect = 1)
|
||||
@@ -169,10 +196,10 @@ class Domain
|
||||
$ins_stmt = Database::prepare("
|
||||
INSERT INTO `" . TABLE_PANEL_DOMAINREDIRECTS . "` SET `rid` = :rid, `did` = :did
|
||||
");
|
||||
Database::pexecute($ins_stmt, array(
|
||||
Database::pexecute($ins_stmt, [
|
||||
'rid' => $redirect,
|
||||
'did' => $domainid
|
||||
));
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,10 +208,10 @@ class Domain
|
||||
* if redirect-code is false, nothing happens
|
||||
*
|
||||
* @param integer $domainid
|
||||
* id of the domain to update
|
||||
* id of the domain to update
|
||||
* @param integer $redirect
|
||||
* selected redirect-id or false
|
||||
*
|
||||
* selected redirect-id or false
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public static function updateRedirectOfDomain($domainid = 0, $redirect = false)
|
||||
@@ -197,17 +224,17 @@ class Domain
|
||||
$del_stmt = Database::prepare("
|
||||
DELETE FROM `" . TABLE_PANEL_DOMAINREDIRECTS . "` WHERE `did` = :domainid
|
||||
");
|
||||
Database::pexecute($del_stmt, array(
|
||||
Database::pexecute($del_stmt, [
|
||||
'domainid' => $domainid
|
||||
));
|
||||
]);
|
||||
|
||||
$ins_stmt = Database::prepare("
|
||||
INSERT INTO `" . TABLE_PANEL_DOMAINREDIRECTS . "` SET `rid` = :rid, `did` = :did
|
||||
");
|
||||
Database::pexecute($ins_stmt, array(
|
||||
Database::pexecute($ins_stmt, [
|
||||
'rid' => $redirect,
|
||||
'did' => $domainid
|
||||
));
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,8 +243,8 @@ class Domain
|
||||
* #329
|
||||
*
|
||||
* @param int $id
|
||||
* domain-id
|
||||
*
|
||||
* domain-id
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function domainHasMainSubDomains($id = 0)
|
||||
@@ -225,9 +252,9 @@ class Domain
|
||||
$result_stmt = Database::prepare("
|
||||
SELECT COUNT(`id`) as `mainsubs` FROM `" . TABLE_PANEL_DOMAINS . "`
|
||||
WHERE `ismainbutsubto` = :id");
|
||||
$result = Database::pexecute_first($result_stmt, array(
|
||||
$result = Database::pexecute_first($result_stmt, [
|
||||
'id' => $id
|
||||
));
|
||||
]);
|
||||
|
||||
if (isset($result['mainsubs']) && $result['mainsubs'] > 0) {
|
||||
return true;
|
||||
@@ -240,18 +267,18 @@ class Domain
|
||||
* #329
|
||||
*
|
||||
* @param int $id
|
||||
* subof-domain-id
|
||||
*
|
||||
* subof-domain-id
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function domainMainToSubExists($id = 0)
|
||||
{
|
||||
$result_stmt = Database::prepare("
|
||||
SELECT `id` FROM `" . TABLE_PANEL_DOMAINS . "` WHERE `id` = :id");
|
||||
Database::pexecute($result_stmt, array(
|
||||
Database::pexecute($result_stmt, [
|
||||
'id' => $id
|
||||
));
|
||||
$result = $result_stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
]);
|
||||
$result = $result_stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (isset($result['id']) && $result['id'] > 0) {
|
||||
return true;
|
||||
@@ -271,10 +298,10 @@ class Domain
|
||||
$result_stmt = Database::prepare("
|
||||
SELECT `dt`.* FROM `" . TABLE_DOMAINTOIP . "` `dt`, `" . TABLE_PANEL_IPSANDPORTS . "` `iap`
|
||||
WHERE `dt`.`id_ipandports` = `iap`.`id` AND `iap`.`ssl` = '1' AND `dt`.`id_domain` = :domainid;");
|
||||
Database::pexecute($result_stmt, array(
|
||||
Database::pexecute($result_stmt, [
|
||||
'domainid' => $domainid
|
||||
));
|
||||
$result = $result_stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
]);
|
||||
$result = $result_stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (is_array($result) && isset($result['id_ipandports'])) {
|
||||
return true;
|
||||
@@ -287,8 +314,8 @@ class Domain
|
||||
* is the std-subdomain of a customer
|
||||
*
|
||||
* @param
|
||||
* int domain-id
|
||||
*
|
||||
* int domain-id
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isCustomerStdSubdomain($did = 0)
|
||||
@@ -298,9 +325,9 @@ class Domain
|
||||
SELECT `customerid` FROM `" . TABLE_PANEL_CUSTOMERS . "`
|
||||
WHERE `standardsubdomain` = :did
|
||||
");
|
||||
$result = Database::pexecute_first($result_stmt, array(
|
||||
$result = Database::pexecute_first($result_stmt, [
|
||||
'did' => $did
|
||||
));
|
||||
]);
|
||||
|
||||
if (is_array($result) && isset($result['customerid']) && $result['customerid'] > 0) {
|
||||
return true;
|
||||
@@ -312,7 +339,7 @@ class Domain
|
||||
public static function triggerLetsEncryptCSRForAliasDestinationDomain($aliasDestinationDomainID, $log)
|
||||
{
|
||||
if (isset($aliasDestinationDomainID) && $aliasDestinationDomainID > 0) {
|
||||
$log->logAction(\Froxlor\FroxlorLogger::ADM_ACTION, LOG_INFO, "LetsEncrypt CSR triggered for domain ID " . $aliasDestinationDomainID);
|
||||
$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
|
||||
@@ -320,27 +347,27 @@ class Domain
|
||||
WHERE
|
||||
domainid = :domainid
|
||||
");
|
||||
Database::pexecute($upd_stmt, array(
|
||||
Database::pexecute($upd_stmt, [
|
||||
'domainid' => $aliasDestinationDomainID
|
||||
));
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public static function doLetsEncryptCleanUp($domainname = null)
|
||||
{
|
||||
// @ see \Froxlor\Cron\Http\LetsEncrypt\AcmeSh.php
|
||||
$acmesh = \Froxlor\Cron\Http\LetsEncrypt\AcmeSh::getAcmeSh();
|
||||
$acmesh = AcmeSh::getAcmeSh();
|
||||
if (file_exists($acmesh)) {
|
||||
$certificate_folder = \Froxlor\Cron\Http\LetsEncrypt\AcmeSh::getWorkingDirFromEnv($domainname);
|
||||
$certificate_folder = AcmeSh::getWorkingDirFromEnv($domainname);
|
||||
if (file_exists($certificate_folder)) {
|
||||
$params = " --remove -d " . $domainname;
|
||||
if (\Froxlor\Settings::Get('system.leecc') > 0) {
|
||||
if (Settings::Get('system.leecc') > 0) {
|
||||
$params .= " --ecc";
|
||||
}
|
||||
// run remove command
|
||||
\Froxlor\FileDir::safe_exec($acmesh . $params);
|
||||
FileDir::safe_exec($acmesh . $params);
|
||||
// remove certificates directory
|
||||
\Froxlor\FileDir::safe_exec('rm -rf ' . $certificate_folder);
|
||||
FileDir::safe_exec('rm -rf ' . $certificate_folder);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -352,20 +379,19 @@ class Domain
|
||||
* to a line for a open_basedir directive
|
||||
*
|
||||
* @param string $path
|
||||
* the path to check and append
|
||||
* the path to check and append
|
||||
* @param boolean $first
|
||||
* if true, no ':' will be prefixed to the path
|
||||
*
|
||||
* if true, no ':' will be prefixed to the path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function appendOpenBasedirPath($path = '', $first = false)
|
||||
{
|
||||
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 = \Froxlor\FileDir::makeCorrectFile($path);
|
||||
$path = FileDir::makeCorrectFile($path);
|
||||
} else {
|
||||
$path = \Froxlor\FileDir::makeCorrectDir($path);
|
||||
$path = FileDir::makeCorrectDir($path);
|
||||
}
|
||||
|
||||
// check for php-version that requires the trailing
|
||||
@@ -373,9 +399,9 @@ class Domain
|
||||
// of the subfolders 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) == '/') {
|
||||
if (substr($path, -1, 1) == '/') {
|
||||
// remove it
|
||||
$path = substr($path, 0, - 1);
|
||||
$path = substr($path, 0, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can also view it online at
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
namespace Froxlor\Domain;
|
||||
|
||||
use Froxlor\Database\Database;
|
||||
use PDO;
|
||||
|
||||
class IpAddr
|
||||
{
|
||||
@@ -12,11 +37,10 @@ class IpAddr
|
||||
SELECT `id`, `ip`, `port` FROM `" . TABLE_PANEL_IPSANDPORTS . "` ORDER BY `ip` ASC, `port` ASC
|
||||
");
|
||||
|
||||
$system_ipaddress_array = array();
|
||||
$system_ipaddress_array = [];
|
||||
|
||||
while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
|
||||
if (! isset($system_ipaddress_array[$row['ip']]) && ! in_array($row['ip'], $system_ipaddress_array)) {
|
||||
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
if (!isset($system_ipaddress_array[$row['ip']]) && !in_array($row['ip'], $system_ipaddress_array)) {
|
||||
if (filter_var($row['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
||||
$row['ip'] = '[' . $row['ip'] . ']';
|
||||
}
|
||||
@@ -27,21 +51,29 @@ class IpAddr
|
||||
return $system_ipaddress_array;
|
||||
}
|
||||
|
||||
public static function getSslIpPortCombinations()
|
||||
{
|
||||
global $lng;
|
||||
return [
|
||||
'' => $lng['panel']['none_value']
|
||||
] + self::getIpPortCombinations(true);
|
||||
}
|
||||
|
||||
public static function getIpPortCombinations($ssl = false)
|
||||
{
|
||||
global $userinfo;
|
||||
|
||||
$additional_conditions_params = array();
|
||||
$additional_conditions_array = array();
|
||||
$additional_conditions_params = [];
|
||||
$additional_conditions_array = [];
|
||||
|
||||
if ($userinfo['ip'] != '-1') {
|
||||
$admin_ip_stmt = Database::prepare("
|
||||
SELECT `id`, `ip`, `port` FROM `" . TABLE_PANEL_IPSANDPORTS . "` WHERE `id` = IN (:ipid)
|
||||
");
|
||||
$myips = implode(",", json_decode($userinfo['ip'], true));
|
||||
Database::pexecute($admin_ip_stmt, array(
|
||||
Database::pexecute($admin_ip_stmt, [
|
||||
'ipid' => $myips
|
||||
));
|
||||
]);
|
||||
$additional_conditions_array[] = "`ip` IN (:adminips)";
|
||||
$additional_conditions_params['adminips'] = $myips;
|
||||
}
|
||||
@@ -61,9 +93,9 @@ class IpAddr
|
||||
");
|
||||
|
||||
Database::pexecute($result_stmt, $additional_conditions_params);
|
||||
$system_ipaddress_array = array();
|
||||
$system_ipaddress_array = [];
|
||||
|
||||
while ($row = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
if (filter_var($row['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
||||
$row['ip'] = '[' . $row['ip'] . ']';
|
||||
}
|
||||
@@ -72,12 +104,4 @@ class IpAddr
|
||||
|
||||
return $system_ipaddress_array;
|
||||
}
|
||||
|
||||
public static function getSslIpPortCombinations()
|
||||
{
|
||||
global $lng;
|
||||
return array(
|
||||
'' => $lng['panel']['none_value']
|
||||
) + self::getIpPortCombinations(true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user