Minor enhancements and starting to comply with checkstyle

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2018-12-24 09:35:05 +01:00
parent 04e87cce98
commit c3d44b4558
25 changed files with 217 additions and 205 deletions

View File

@@ -16,7 +16,7 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
public function run()
{
$this->_validate();
$this->validate();
}
/**
@@ -24,27 +24,27 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
*
* @throws \Exception
*/
private function _validate()
private function validate()
{
$this->_checkConfigParam(true);
$this->_parseConfig();
$this->checkConfigParam(true);
$this->parseConfig();
require FROXLOR_INSTALL_DIR . '/lib/tables.inc.php';
if (array_key_exists("import-settings", $this->_args)) {
$this->_importSettings();
$this->importSettings();
}
if (array_key_exists("create", $this->_args)) {
$this->_createConfig();
$this->createConfig();
} elseif (array_key_exists("apply", $this->_args)) {
$this->_applyConfig();
$this->applyConfig();
} elseif (array_key_exists("list-daemons", $this->_args) || array_key_exists("daemon", $this->_args)) {
ConfigServicesCmd::printwarn("--list-daemons and --daemon only work together with --apply");
}
}
private function _importSettings()
private function importSettings()
{
if (strtoupper(substr($this->_args["import-settings"], 0, 4)) == 'HTTP') {
echo "Settings file seems to be an URL, trying to download" . PHP_EOL;
@@ -67,7 +67,7 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
ConfigServicesCmd::printsucc("Successfully imported settings from '" . $this->_args["import-settings"] . "'");
}
private function _createConfig()
private function createConfig()
{
$_daemons_config = array(
'distro' => ""
@@ -185,7 +185,7 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
return $dist_display;
}
private function _applyConfig()
private function applyConfig()
{
if (strtoupper(substr($this->_args["apply"], 0, 4)) == 'HTTP') {
echo "Config file seems to be an URL, trying to download" . PHP_EOL;
@@ -238,7 +238,7 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
$config_dir = FROXLOR_INSTALL_DIR . '/lib/configfiles/';
$configfiles = new \Froxlor\Config\ConfigParser($config_dir . '/' . $decoded_config['distro'] . ".xml");
$services = $configfiles->getServices();
$replace_arr = $this->_getReplacerArray();
$replace_arr = $this->getReplacerArray();
foreach ($services as $si => $service) {
echo PHP_EOL . "--- Configuring: " . strtoupper($si) . " ---" . PHP_EOL . PHP_EOL;
@@ -305,7 +305,7 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
}
}
private function _getReplacerArray()
private function getReplacerArray()
{
$customer_tmpdir = '/tmp/';
if (Settings::Get('system.mod_fcgid') == '1' && Settings::Get('system.mod_fcgid_tmpdir') != '') {
@@ -356,7 +356,7 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
return $replace_arr;
}
private function _parseConfig()
private function parseConfig()
{
define('FROXLOR_INSTALL_DIR', $this->_args['froxlor-dir']);
if (! class_exists('\\Froxlor\\Database\\Database')) {
@@ -367,7 +367,7 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
}
}
private function _checkConfigParam($needed = false)
private function checkConfigParam($needed = false)
{
if ($needed) {
if (! isset($this->_args["froxlor-dir"])) {
@@ -399,4 +399,4 @@ class ConfigServicesAction extends \Froxlor\Cli\Action
curl_close($ch);
fclose($fp);
}
}
}

View File

@@ -14,7 +14,7 @@ class SwitchServerIpAction extends \Froxlor\Cli\Action
public function run()
{
$this->_validate();
$this->validate();
}
/**
@@ -22,26 +22,26 @@ class SwitchServerIpAction extends \Froxlor\Cli\Action
*
* @throws \Exception
*/
private function _validate()
private function validate()
{
$need_config = false;
if (array_key_exists("list", $this->_args) || array_key_exists("switch", $this->_args)) {
$need_config = true;
}
$this->_checkConfigParam($need_config);
$this->checkConfigParam($need_config);
$this->_parseConfig();
$this->parseConfig();
if (array_key_exists("list", $this->_args)) {
$this->_listIPs();
$this->listIPs();
}
if (array_key_exists("switch", $this->_args)) {
$this->_switchIPs();
$this->switchIPs();
}
}
private function _listIPs()
private function listIPs()
{
$sel_stmt = Database::prepare("SELECT * FROM panel_ipsandports ORDER BY ip ASC, port ASC");
Database::pexecute($sel_stmt);
@@ -57,7 +57,7 @@ class SwitchServerIpAction extends \Froxlor\Cli\Action
echo PHP_EOL . PHP_EOL;
}
private function _switchIPs()
private function switchIPs()
{
$ip_list = $this->_args['switch'];
@@ -158,7 +158,7 @@ class SwitchServerIpAction extends \Froxlor\Cli\Action
SwitchServerIpCmd::printsucc("IP addresses updated");
}
private function _parseConfig()
private function parseConfig()
{
define('FROXLOR_INSTALL_DIR', $this->_args['froxlor-dir']);
if (! class_exists('\\Froxlor\\Database\\Database')) {
@@ -169,7 +169,7 @@ class SwitchServerIpAction extends \Froxlor\Cli\Action
}
}
private function _checkConfigParam($needed = false)
private function checkConfigParam($needed = false)
{
if ($needed) {
if (! isset($this->_args["froxlor-dir"])) {
@@ -183,4 +183,4 @@ class SwitchServerIpAction extends \Froxlor\Cli\Action
}
}
}
}
}

View File

@@ -59,8 +59,8 @@ abstract class CmdLineHandler
*/
private function __construct($argc, $argv)
{
self::$args = $this->_parseArgs($argv);
$this->_action = $this->_createAction();
self::$args = $this->parseArgs($argv);
$this->_action = $this->createAction();
$this->_action->run();
}
@@ -83,7 +83,7 @@ abstract class CmdLineHandler
*
* @return array
*/
private function _parseArgs($argv)
private function parseArgs($argv)
{
array_shift($argv);
$o = array();
@@ -98,7 +98,7 @@ abstract class CmdLineHandler
$o[$k] = true;
}
}
} else if (substr($a, 0, 1) == '-') {
} elseif (substr($a, 0, 1) == '-') {
if (substr($a, 2, 1) == '=') {
$o[substr($a, 1, 1)] = substr($a, 3);
} else {
@@ -121,7 +121,7 @@ abstract class CmdLineHandler
* @return \Froxlor\Cli\Action
* @throws \Exception
*/
private function _createAction()
private function createAction()
{
// Test for help-switch
@@ -194,23 +194,23 @@ abstract class CmdLineHandler
print $msg . PHP_EOL;
}
private static function _printcolor($msg = "", $color = "0")
private static function printcolor($msg = "", $color = "0")
{
print "\033[" . $color . "m" . $msg . "\033[0m" . PHP_EOL;
}
public static function printerr($msg = "")
{
self::_printcolor($msg, "31");
self::printcolor($msg, "31");
}
public static function printsucc($msg = "")
{
self::_printcolor($msg, "32");
self::printcolor($msg, "32");
}
public static function printwarn($msg = "")
{
self::_printcolor($msg, "33");
self::printcolor($msg, "33");
}
}