major refactoring of almost all files
This commit is contained in:
@@ -11,24 +11,24 @@
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
* http://files.froxlor.org/misc/COPYING.txt
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license http://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
namespace Froxlor\Cli;
|
||||
|
||||
use Froxlor\Froxlor;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Froxlor\Froxlor;
|
||||
|
||||
class CliCommand extends Command
|
||||
{
|
||||
|
||||
@@ -11,31 +11,31 @@
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
* http://files.froxlor.org/misc/COPYING.txt
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license http://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
namespace Froxlor\Cli;
|
||||
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Froxlor\Config\ConfigParser;
|
||||
use Froxlor\Database\Database;
|
||||
use Froxlor\FileDir;
|
||||
use Froxlor\Froxlor;
|
||||
use Froxlor\PhpHelper;
|
||||
use Froxlor\Settings;
|
||||
use Froxlor\SImExporter;
|
||||
use Froxlor\Database\Database;
|
||||
use Froxlor\Config\ConfigParser;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
final class ConfigServices extends CliCommand
|
||||
{
|
||||
@@ -100,21 +100,68 @@ final class ConfigServices extends CliCommand
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function importSettings(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$importFile = $input->getOption('import-settings');
|
||||
|
||||
if (strtoupper(substr($importFile, 0, 4)) == 'HTTP') {
|
||||
$output->writeln("Settings file seems to be an URL, trying to download");
|
||||
$target = "/tmp/froxlor-import-settings-" . time() . ".json";
|
||||
if (@file_exists($target)) {
|
||||
@unlink($target);
|
||||
}
|
||||
$this->downloadFile($importFile, $target);
|
||||
$importFile = $target;
|
||||
}
|
||||
if (!is_file($importFile)) {
|
||||
$output->writeln('<error>Given settings file is not a file</>');
|
||||
return self::INVALID;
|
||||
} elseif (!file_exists($importFile)) {
|
||||
$output->writeln('<error>Given settings file cannot be found (' . $importFile . ')</>');
|
||||
return self::INVALID;
|
||||
} elseif (!is_readable($importFile)) {
|
||||
$output->writeln('<error>Given settings file cannot be read (' . $importFile . ')</>');
|
||||
return self::INVALID;
|
||||
}
|
||||
$imp_content = file_get_contents($importFile);
|
||||
SImExporter::import($imp_content);
|
||||
$output->writeln("<info>Successfully imported settings from '" . $input->getOption('import-settings') . "'</info>");
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
private function downloadFile($src, $dest)
|
||||
{
|
||||
set_time_limit(0);
|
||||
// This is the file where we save the information
|
||||
$fp = fopen($dest, 'w+');
|
||||
// Here is the file we are downloading, replace spaces with %20
|
||||
$ch = curl_init(str_replace(" ", "%20", $src));
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
// write curl response to file
|
||||
curl_setopt($ch, CURLOPT_FILE, $fp);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
// get curl response
|
||||
curl_exec($ch);
|
||||
curl_close($ch);
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
private function createConfig(InputInterface $input, OutputInterface $output, SymfonyStyle $io)
|
||||
{
|
||||
$_daemons_config = array(
|
||||
$_daemons_config = [
|
||||
'distro' => ""
|
||||
);
|
||||
];
|
||||
|
||||
$config_dir = Froxlor::getInstallDir() . '/lib/configfiles/';
|
||||
// show list of available distro's
|
||||
$distros = glob($config_dir . '*.xml');
|
||||
// tmp array
|
||||
$distributions_select_data = array();
|
||||
$distributions_select_data = [];
|
||||
|
||||
//set default os.
|
||||
$os_dist = array('ID' => 'bullseye');
|
||||
$os_version = array('0' => '11');
|
||||
$os_dist = ['ID' => 'bullseye'];
|
||||
$os_version = ['0' => '11'];
|
||||
$os_default = $os_dist['ID'];
|
||||
|
||||
//read os-release
|
||||
@@ -190,7 +237,7 @@ final class ConfigServices extends CliCommand
|
||||
|
||||
$daemons['x'] = 'x';
|
||||
if ($si == 'system') {
|
||||
$_daemons_config[$si] = array();
|
||||
$_daemons_config[$si] = [];
|
||||
// for the system/other services we need a multiple choice possibility
|
||||
$output->writeln("<comment>Select every service you need. Enter empty value when done</>");
|
||||
$sysservice = "";
|
||||
@@ -389,9 +436,9 @@ final class ConfigServices extends CliCommand
|
||||
// ignore invalid responses
|
||||
if (!is_array($nameserver_ips)) {
|
||||
// act like PhpHelper::gethostbynamel6() and return unmodified hostname on error
|
||||
$nameserver_ips = array(
|
||||
$nameserver_ips = [
|
||||
$nameserver
|
||||
);
|
||||
];
|
||||
} else {
|
||||
$known_ns_ips = array_merge($known_ns_ips, $nameserver_ips);
|
||||
}
|
||||
@@ -418,7 +465,7 @@ final class ConfigServices extends CliCommand
|
||||
Database::needSqlData();
|
||||
$sql = Database::getSqlData();
|
||||
|
||||
$replace_arr = array(
|
||||
$replace_arr = [
|
||||
'<SQL_UNPRIVILEGED_USER>' => $sql['user'],
|
||||
'<SQL_UNPRIVILEGED_PASSWORD>' => $sql['passwd'],
|
||||
'<SQL_DB>' => $sql['db'],
|
||||
@@ -439,54 +486,7 @@ final class ConfigServices extends CliCommand
|
||||
'<CUSTOMER_LOGS>' => FileDir::makeCorrectDir(Settings::Get('system.logfiles_directory')),
|
||||
'<FPM_IPCDIR>' => FileDir::makeCorrectDir(Settings::Get('phpfpm.fastcgi_ipcdir')),
|
||||
'<WEBSERVER_GROUP>' => Settings::Get('system.httpgroup')
|
||||
);
|
||||
];
|
||||
return $replace_arr;
|
||||
}
|
||||
|
||||
private function importSettings(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$importFile = $input->getOption('import-settings');
|
||||
|
||||
if (strtoupper(substr($importFile, 0, 4)) == 'HTTP') {
|
||||
$output->writeln("Settings file seems to be an URL, trying to download");
|
||||
$target = "/tmp/froxlor-import-settings-" . time() . ".json";
|
||||
if (@file_exists($target)) {
|
||||
@unlink($target);
|
||||
}
|
||||
$this->downloadFile($importFile, $target);
|
||||
$importFile = $target;
|
||||
}
|
||||
if (!is_file($importFile)) {
|
||||
$output->writeln('<error>Given settings file is not a file</>');
|
||||
return self::INVALID;
|
||||
} elseif (!file_exists($importFile)) {
|
||||
$output->writeln('<error>Given settings file cannot be found (' . $importFile . ')</>');
|
||||
return self::INVALID;
|
||||
} elseif (!is_readable($importFile)) {
|
||||
$output->writeln('<error>Given settings file cannot be read (' . $importFile . ')</>');
|
||||
return self::INVALID;
|
||||
}
|
||||
$imp_content = file_get_contents($importFile);
|
||||
SImExporter::import($imp_content);
|
||||
$output->writeln("<info>Successfully imported settings from '" . $input->getOption('import-settings') . "'</info>");
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
private function downloadFile($src, $dest)
|
||||
{
|
||||
set_time_limit(0);
|
||||
// This is the file where we save the information
|
||||
$fp = fopen($dest, 'w+');
|
||||
// Here is the file we are downloading, replace spaces with %20
|
||||
$ch = curl_init(str_replace(" ", "%20", $src));
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
// write curl response to file
|
||||
curl_setopt($ch, CURLOPT_FILE, $fp);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
// get curl response
|
||||
curl_exec($ch);
|
||||
curl_close($ch);
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,27 +11,27 @@
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
* http://files.froxlor.org/misc/COPYING.txt
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license http://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
namespace Froxlor\Cli;
|
||||
|
||||
use Froxlor\Database\Database;
|
||||
use Froxlor\FileDir;
|
||||
use Froxlor\Settings;
|
||||
use PDO;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Froxlor\Froxlor;
|
||||
use Froxlor\FileDir;
|
||||
use Froxlor\Settings;
|
||||
use Froxlor\Database\Database;
|
||||
|
||||
final class PhpSessionclean extends CliCommand
|
||||
{
|
||||
@@ -48,8 +48,8 @@ final class PhpSessionclean extends CliCommand
|
||||
$result = $this->validateRequirements($input, $output);
|
||||
|
||||
if ($result == self::SUCCESS) {
|
||||
if ((int) Settings::Get('phpfpm.enabled') == 1) {
|
||||
if ($input->hasArgument('max-lifetime') && is_numeric($input->getArgument('max-lifetime')) && $input->getArgument('max-lifetime') > 0) {
|
||||
if ((int)Settings::Get('phpfpm.enabled') == 1) {
|
||||
if ($input->hasArgument('max-lifetime') && is_numeric($input->getArgument('max-lifetime')) && $input->getArgument('max-lifetime') > 0) {
|
||||
$this->cleanSessionfiles((int)$input->getArgument('max-lifetime'));
|
||||
} else {
|
||||
// use default max-lifetime value
|
||||
@@ -72,7 +72,7 @@ final class PhpSessionclean extends CliCommand
|
||||
// get all pool-config directories configured
|
||||
$sel_stmt = Database::prepare("SELECT DISTINCT `config_dir` FROM `" . TABLE_PANEL_FPMDAEMONS . "`");
|
||||
Database::pexecute($sel_stmt);
|
||||
while ($fpmd = $sel_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
while ($fpmd = $sel_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$poolfiles = glob(FileDir::makeCorrectFile($fpmd['config_dir'] . '/*.conf'));
|
||||
foreach ($poolfiles as $cf) {
|
||||
$contents = file_get_contents($cf);
|
||||
|
||||
@@ -11,25 +11,26 @@
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
* http://files.froxlor.org/misc/COPYING.txt
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license http://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
namespace Froxlor\Cli;
|
||||
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Froxlor\Database\Database;
|
||||
use PDO;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Froxlor\Database\Database;
|
||||
|
||||
final class SwitchServerIp extends CliCommand
|
||||
{
|
||||
@@ -56,10 +57,9 @@ final class SwitchServerIp extends CliCommand
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
if ($result == self::SUCCESS && $input->getOption('list')) {
|
||||
|
||||
$sel_stmt = Database::prepare("SELECT * FROM panel_ipsandports ORDER BY ip ASC, port ASC");
|
||||
Database::pexecute($sel_stmt);
|
||||
$ips = $sel_stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$ips = $sel_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$table_rows = [];
|
||||
foreach ($ips as $ipdata) {
|
||||
$table_rows[] = [$ipdata['id'], $ipdata['ip'], $ipdata['port']];
|
||||
@@ -127,18 +127,18 @@ final class SwitchServerIp extends CliCommand
|
||||
foreach ($ips_to_switch as $ip_pair) {
|
||||
$output->writeln('Switching IP <comment>' . $ip_pair[0] . '</> to IP <comment>' . $ip_pair[1] . '</>');
|
||||
|
||||
$ip_check = Database::pexecute_first($check_stmt, array(
|
||||
$ip_check = Database::pexecute_first($check_stmt, [
|
||||
'newip' => $ip_pair[1]
|
||||
));
|
||||
]);
|
||||
if ($ip_check) {
|
||||
$output->writeln('<error>Note: ' . $ip_pair[0] . ' not updated to ' . $ip_pair[1] . ' - IP already exists in froxlor\'s database</>');
|
||||
continue;
|
||||
}
|
||||
|
||||
Database::pexecute($upd_stmt, array(
|
||||
Database::pexecute($upd_stmt, [
|
||||
'newip' => $ip_pair[1],
|
||||
'oldip' => $ip_pair[0]
|
||||
));
|
||||
]);
|
||||
$rows_updated = $upd_stmt->rowCount();
|
||||
|
||||
if ($rows_updated == 0) {
|
||||
@@ -149,9 +149,9 @@ final class SwitchServerIp extends CliCommand
|
||||
// check whether the system.ipaddress needs updating
|
||||
if ($check_sysip['value'] == $ip_pair[0]) {
|
||||
$upd2_stmt = Database::prepare("UPDATE `panel_settings` SET `value` = :newip WHERE `settinggroup` = 'system' and `varname` = 'ipaddress'");
|
||||
Database::pexecute($upd2_stmt, array(
|
||||
Database::pexecute($upd2_stmt, [
|
||||
'newip' => $ip_pair[1]
|
||||
));
|
||||
]);
|
||||
$output->writeln('<info>Updated system-ipaddress from <comment>' . $ip_pair[0] . '</comment> to <comment>' . $ip_pair[1] . '</comment></info>');
|
||||
}
|
||||
|
||||
@@ -159,9 +159,9 @@ final class SwitchServerIp extends CliCommand
|
||||
if (strstr($check_mysqlip['value'], $ip_pair[0]) !== false) {
|
||||
$new_mysqlip = str_replace($ip_pair[0], $ip_pair[1], $check_mysqlip['value']);
|
||||
$upd2_stmt = Database::prepare("UPDATE `panel_settings` SET `value` = :newmysql WHERE `settinggroup` = 'system' and `varname` = 'mysql_access_host'");
|
||||
Database::pexecute($upd2_stmt, array(
|
||||
Database::pexecute($upd2_stmt, [
|
||||
'newmysql' => $new_mysqlip
|
||||
));
|
||||
]);
|
||||
$output->writeln('<info>Updated mysql_access_host from <comment>' . $check_mysqlip['value'] . '</comment> to <comment>' . $new_mysqlip . '</comment></info>');
|
||||
}
|
||||
|
||||
@@ -169,9 +169,9 @@ final class SwitchServerIp extends CliCommand
|
||||
if (strstr($check_axfrip['value'], $ip_pair[0]) !== false) {
|
||||
$new_axfrip = str_replace($ip_pair[0], $ip_pair[1], $check_axfrip['value']);
|
||||
$upd2_stmt = Database::prepare("UPDATE `panel_settings` SET `value` = :newaxfr WHERE `settinggroup` = 'system' and `varname` = 'axfrservers'");
|
||||
Database::pexecute($upd2_stmt, array(
|
||||
Database::pexecute($upd2_stmt, [
|
||||
'newaxfr' => $new_axfrip
|
||||
));
|
||||
]);
|
||||
$output->writeln('<info>Updated axfr-servers from <comment>' . $check_axfrip['value'] . '</comment> to <comment>' . $new_axfrip . '</comment></info>');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user