From ad784311c1735812a5aeb57746b8cff8983f9291 Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 16 Dec 2023 20:58:52 -0500 Subject: [PATCH] phpcs --- app/init_systems/open_rc.php | 8 +- app/init_systems/runit.php | 4 +- app/init_systems/sys_v_init.php | 8 +- app/init_systems/systemd.php | 8 +- app/neato.php | 83 +++++--- app/neato_auto_loader.php | 248 +++++++++++++---------- app/neato_colors.php | 154 +++++++++------ app/neato_common.php | 32 +-- app/neato_danger_checker.php | 4 +- app/neato_enc.php | 2 +- app/neato_fns.php | 262 ++++++++++++++++++------- app/neato_init.php | 124 +++++++++--- app/neato_logger.php | 221 ++++++++++++--------- app/neato_registry.php | 209 +++++++++++++++----- app/package_managers/apk.php | 22 +-- app/package_managers/apt.php | 30 +-- app/package_managers/apt_get.php | 30 +-- app/package_managers/dnf.php | 24 +-- app/package_managers/flatpak.php | 18 +- app/package_managers/nala.php | 32 +-- app/package_managers/pacman.php | 24 +-- app/package_managers/snap.php | 22 +-- app/package_managers/yum.php | 24 +-- app/traits/linux_core.php | 62 +++--- app/utils/apache.php | 36 ++-- app/utils/curl.php | 6 +- app/utils/keygen.php | 13 +- app/utils/mysql.php | 16 +- app/utils/npm.php | 16 +- app/utils/php.php | 14 +- app/utils/php_composer.php | 42 ++-- app/utils/sed.php | 10 +- app/utils/ufw.php | 4 +- app/utils/wget.php | 4 +- deploy_files/deploy_example.php | 4 +- deploy_files/deploy_mysql_ex1.php | 8 +- deploy_files/deploy_mysql_ex2.php | 4 +- deploy_files/deploy_podman.php | 10 +- deploy_files/deploy_security_audit.php | 14 +- deploy_files/deploy_sshd.php | 8 +- deploy_files/deploy_test1.php | 10 +- make-installer.sh | 2 +- 42 files changed, 1164 insertions(+), 712 deletions(-) diff --git a/app/init_systems/open_rc.php b/app/init_systems/open_rc.php index abeedff..af73c38 100644 --- a/app/init_systems/open_rc.php +++ b/app/init_systems/open_rc.php @@ -28,16 +28,16 @@ private static function get_valid_action_for_service(string $action): string|fal public static function service($name, $action = 'restart') { $my_action = self::get_valid_action_for_service($action); - exec(\neato::get_super_user_bin . 'rc-service ' . safe_cmd($name, $action), $output, $exit_code); + exec(\neato::get_super_user_bin . 'rc-service ' . safeCmd($name, $action), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to {$action} Service called: {$name}"); + checkForError($exit_code, "Unable to {$action} Service called: {$name}"); return $exit_code; } public static function systemctl($name, $action = 'add') { $my_action = self::get_valid_action_for_system_ctl($action); - exec(\neato::get_super_bin . 'rc-update ' . safe_cmd($action, $name), $output, $exit_code); - check_for_error($exit_code, "Unable to {$action} Service called: {$name}"); + exec(\neato::get_super_bin . 'rc-update ' . safeCmd($action, $name), $output, $exit_code); + checkForError($exit_code, "Unable to {$action} Service called: {$name}"); return $exit_code; } diff --git a/app/init_systems/runit.php b/app/init_systems/runit.php index fb64e26..b0d068a 100644 --- a/app/init_systems/runit.php +++ b/app/init_systems/runit.php @@ -21,9 +21,9 @@ class runit { public static function service(string $name, string $action = 'restart') { $my_action = self::get_valid_action($action); - exec(\neato::get_super_user_bin . 'sv ' . safe_cmd($my_action, $name), $output, $exit_code); + exec(\neato::get_super_user_bin . 'sv ' . safeCmd($my_action, $name), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to {$action} Service called: {$name}"); + checkForError($exit_code, "Unable to {$action} Service called: {$name}"); return $exit_code; } diff --git a/app/init_systems/sys_v_init.php b/app/init_systems/sys_v_init.php index b87d727..a073d7d 100644 --- a/app/init_systems/sys_v_init.php +++ b/app/init_systems/sys_v_init.php @@ -28,16 +28,16 @@ class sys_v_init { public static function service(string $name, string $action = 'restart') { $my_action = self::get_valid_action_for_service($action); - exec(\neato::get_super_user_bin . '/etc/init.d/' . safe_cmd($name, $my_action), $output, $exit_code); + exec(\neato::get_super_user_bin . '/etc/init.d/' . safeCmd($name, $my_action), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to {$action} Service called: {$name}"); + checkForError($exit_code, "Unable to {$action} Service called: {$name}"); return $exit_code; } public static function systemctl(string $name, string $action = 'on') { $my_action = self::get_valid_action_for_system_ctl($action); - exec(\neato::get_bin . 'chkconfig ' . safe_cmd($action, $name), $output, $exit_code); - check_for_error($exit_code, "Unable to {$action} Service called: {$name}"); + exec(\neato::get_bin . 'chkconfig ' . safeCmd($action, $name), $output, $exit_code); + checkForError($exit_code, "Unable to {$action} Service called: {$name}"); return $exit_code; } diff --git a/app/init_systems/systemd.php b/app/init_systems/systemd.php index b0c0224..9a0b996 100644 --- a/app/init_systems/systemd.php +++ b/app/init_systems/systemd.php @@ -43,16 +43,16 @@ class systemd { public static function service(string $name, string $action = 'restart') { $my_action = self::get_valid_action_for_service($action); - exec(\neato::get_super_user_bin . 'service ' . safe_cmd($name, $my_action), $output, $exit_code); + exec(\neato::get_super_user_bin . 'service ' . safeCmd($name, $my_action), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to {$action} Service called: {$name}"); + checkForError($exit_code, "Unable to {$action} Service called: {$name}"); return $exit_code; } public static function systemctl(string $name, string $action = 'enable') { $my_action = self::get_valid_action_for_system_ctl($action); - exec(\neato::get_bin . 'systemctl ' . safe_cmd($my_action, $name), $output, $exit_code); - check_for_error($exit_code, "Unable to {$action} Service called: {$name}"); + exec(\neato::get_bin . 'systemctl ' . safeCmd($my_action, $name), $output, $exit_code); + checkForError($exit_code, "Unable to {$action} Service called: {$name}"); return $exit_code; } diff --git a/app/neato.php b/app/neato.php index 1ef071a..2218d27 100644 --- a/app/neato.php +++ b/app/neato.php @@ -1,5 +1,15 @@ + * @license https://mit-license.org/ MIT License + * @link https://git.mysnippetsofcode.com/tts/neatoDeploy + */ ini_set('display_errors', 1); error_reporting(E_ALL); @@ -23,13 +33,17 @@ if (!isset($argv[1])) { exit(1); } -define('CONFIG_FILE', basename($argv[1]) ); +define('CONFIG_FILE', basename($argv[1])); require "neato_common.php"; -/** @phpstan-ignore-next-line Variable $os_like might not be defined */ +/** + * Tell php stan $os_like is from another file + * + * @phpstan-ignore-next-line Variable $os_like might not be defined +*/ if ($os_like == 'debian') { - putenv("DEBIAN_FRONTEND=noninteractive"); + putenv("DEBIAN_FRONTEND=noninteractive"); } if (isset($os['id']) && file_exists('OS/neato_' . ucfirst($os['id']) . '.php')) { @@ -40,7 +54,15 @@ if (isset($os['id']) && file_exists('OS/neato_' . ucfirst($os['id']) . '.php')) include $generic_OS_file; } -function clean_file_name(string & $file) { +/** + * Clean up the file name, so user has a better time. + * + * @param string $file (passed by Reference) deployment file to be prettier + * + * @return void + */ +function Clean_File_name(string & $file): void +{ $file = str_replace("deploy_", "", $file); $file = str_replace(".php", "", $file); } @@ -49,32 +71,45 @@ $auto = (in_array('-y', $argv)) ? true : false; $mark = (in_array('-marksafe', $argv)) ? true : false; $skipdeploy = (in_array('-skipdeploy', $argv)) ? true : false; $file = $argv[1]; -clean_file_name($file); +Clean_File_name($file); -if (is_string_found($argv[1], 'http://') || is_string_found($argv[1], 'https://')) { - if ( isset($argv[2]) && $argv[2] !== "-y" ) { +if (isStringFound($argv[1], 'http://') || isStringFound($argv[1], 'https://')) { + if (isset($argv[2]) && $argv[2] !== "-y" ) { $file = $argv[2]; - clean_file_name($file); + Clean_File_name($file); } else { $pos = strrpos($argv[1], '/'); $file = substr($argv[1], $pos + 1); $file = str_replace(".txt", "", $file); - clean_file_name($file); + Clean_File_name($file); } \utils\curl::save($argv[1], "/deploy_files/deploy_{$file}.php"); } - -function save_sha($shasum) { +/** + * Make SHA sum files + * + * @param mixed $shasum plan hash of file + * + * @return void + */ +function Save_sha($shasum): void +{ $xor = xor_encrypt($shasum, $GLOBALS['pk']); file_put_contents($GLOBALS['cwd'] . '/sums/deploy_' . $GLOBALS['file'].'.sum', $xor); } - -function do_harm_checker($shasum) { - require 'neato_danger_checker.php'; - if ( is_file_dangerious($GLOBALS['cwd'] . '/deploy_files/deploy_' . $GLOBALS['file'].'.php') ) { +/** + * Check for dangerous stuff and ask if ok to run + * bails on dangerous files if not accepted + * + * @return void + */ +function Do_Harm_checker(): void +{ + include 'neato_danger_checker.php'; + if (is_file_dangerious($GLOBALS['cwd'] . '/deploy_files/deploy_' . $GLOBALS['file'].'.php') ) { if (! $GLOBALS['auto']) { $answer = readline("Do you wish to execute this Script, anyways!! ? "); - if ( strtolower( trim($answer) ) === "yes" ) { + if (strtolower(trim($answer)) === "yes" ) { echo "Okay...!" . PHP_EOL; } else { exit(1); @@ -88,8 +123,8 @@ if (file_exists($cwd . '/deploy_files/deploy_' . $file.'.php')) { $check_for_harm = true; $shasum = shasum($cwd . '/deploy_files/deploy_' . $file.'.php'); if ($shasum === false) { - echo "Unable to SHA sum script!"; - exit(1); + echo "Unable to SHA sum script!"; + exit(1); } if (file_exists($cwd . '/sums/deploy_' . $file.'.sum')) { @@ -107,7 +142,7 @@ if (file_exists($cwd . '/deploy_files/deploy_' . $file.'.php')) { } if ($mark) { - save_sha($shasum); + Save_sha($shasum); } if ($skipdeploy) { @@ -116,13 +151,13 @@ if (file_exists($cwd . '/deploy_files/deploy_' . $file.'.php')) { } if ($check_for_harm) { - do_harm_checker($shasum); + Do_Harm_checker(); } - require($cwd . '/deploy_files/deploy_' . $file.'.php'); + include $cwd . '/deploy_files/deploy_' . $file.'.php'; } else { - echo 'PHP Script deploy_files/deploy_'. $file . '.php does not exist!!' . PHP_EOL; - exit(1); + echo 'PHP Script deploy_files/deploy_'. $file . '.php does not exist!!' . PHP_EOL; + exit(1); } echo PHP_EOL; \ No newline at end of file diff --git a/app/neato_auto_loader.php b/app/neato_auto_loader.php index 172047a..d5d87be 100644 --- a/app/neato_auto_loader.php +++ b/app/neato_auto_loader.php @@ -1,123 +1,163 @@ - + * @license https://mit-license.org/ MIT License + * @link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md + */ /** - * @author http://php-fig.org/ - * @site https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md + * Auto loader, uses namespace to guess where class file live. + * + * @category Util + * @package Neato + * @author http://php-fig.org/ + * @license https://mit-license.org/ MIT License + * @link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md */ -class Psr4AutoloaderClass { +class Neato_Auto_Loader +{ - /** - * An associative array where the key is a namespace prefix and the value - * is an array of base directories for classes in that namespace. - * - * @var array - */ - protected $prefixes = []; + /** + * An associative array where the key is a namespace prefix and the value + * is an array of base directories for classes in that namespace. + * + * @var array + */ + protected $prefixes = []; - /** - * Register loader with SPL autoloader stack. - * - * @return void - */ - public function register() { - spl_autoload_register(array($this, 'load_class')); - } + /** + * Register loader with SPL autoloader stack. + * + * @return void + */ + public function register() + { + spl_autoload_register(array($this, 'loadClass')); + } - public function is_loaded(string $prefix): bool { - $prefix = trim($prefix, '\\') . '\\'; - return (isset($this->prefixes[$prefix])) ? true : false; - } - - public function get_list(): array { - return $this->prefixes; - } + /** + * Is class loaded, yet? + * + * @param string $prefix holds global data of namespaces + * + * @return bool + */ + public function isLoaded(string $prefix): bool + { + $prefix = trim($prefix, '\\') . '\\'; + return (isset($this->prefixes[$prefix])) ? true : false; + } - /** - * Adds a base directory for a namespace prefix. - * - * @param string $prefix The namespace prefix. - * @param string $base_dir A base directory for class files in the - * namespace. - * @param bool $prepend If true, prepend the base directory to the stack - * instead of appending it; this causes it to be searched first rather - * than last. - * @return void - */ - public function add_namespace(string $prefix, string $base_dir, bool $prepend = false): void { - $prefix = trim($prefix, '\\') . '\\'; - $base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . '/'; - if (isset($this->prefixes[$prefix]) === false) { - $this->prefixes[$prefix] = array(); + /** + * Get List of loaded prefixes containing namespace/class. + * + * @return array + */ + public function getList(): array + { + return $this->prefixes; } - if ($prepend) { - array_unshift($this->prefixes[$prefix], $base_dir); - } else { - array_push($this->prefixes[$prefix], $base_dir); + + /** + * Adds a base directory for a namespace prefix. + * + * @param string $prefix The namespace prefix. + * @param string $base_dir A base directory for class files in the + * namespace. + * @param bool $prepend If true, prepend the base directory to the stack + * instead of appending it; this causes it to be + * searched first rather than last. + * + * @return void + */ + public function addNamespace(string $prefix, string $base_dir, bool $prepend = false): void + { + $prefix = trim($prefix, '\\') . '\\'; + $base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . '/'; + if (isset($this->prefixes[$prefix]) === false) { + $this->prefixes[$prefix] = array(); + } + if ($prepend) { + array_unshift($this->prefixes[$prefix], $base_dir); + } else { + array_push($this->prefixes[$prefix], $base_dir); + } } - } - /** - * Loads the class file for a given class name. - * - * @param string $class The fully-qualified class name. - * @return mixed The mapped file name on success, or boolean false on - * failure. - */ - public function load_class(string $class) { /** - * Semi-Fix for non-namespaced classes + * Loads the class file for a given class name. + * + * @param string $class The fully-qualified class name. + * + * @return mixed The mapped file name on success, or boolean false on + * failure. */ - if (! strrpos($class, '\\')) { - return ($this->load_mapped_file($class . '\\', $class)); - } - $prefix = $class; - while (false !== $pos = strrpos($prefix, '\\')) { - $prefix = substr($class, 0, $pos + 1); - $relative_class = substr($class, $pos + 1); - $mapped_file = $this->load_mapped_file($prefix, $relative_class); - if ($mapped_file) { - return $mapped_file; - } - $prefix = rtrim($prefix, '\\'); + public function loadClass(string $class) + { + /** + * Semi-Fix for non-namespaced classes + */ + if (! strrpos($class, '\\')) { + return ($this->loadMappedFile($class . '\\', $class)); + } + $prefix = $class; + while (false !== $pos = strrpos($prefix, '\\')) { + $prefix = substr($class, 0, $pos + 1); + $relative_class = substr($class, $pos + 1); + $mapped_file = $this->loadMappedFile($prefix, $relative_class); + if ($mapped_file) { + return $mapped_file; + } + $prefix = rtrim($prefix, '\\'); + } + return false; } - return false; - } - /** - * Load the mapped file for a namespace prefix and relative class. - * - * @param string $prefix The namespace prefix. - * @param string $relative_class The relative class name. - * @return mixed Boolean false if no mapped file can be loaded, or the - * name of the mapped file that was loaded. - */ - protected function load_mapped_file(string $prefix, string $relative_class) { - if (isset($this->prefixes[$prefix]) === false) { - return false; - } - foreach ($this->prefixes[$prefix] as $base_dir) { - $file = $base_dir - . str_replace('\\', '/', $relative_class) - . '.php'; - if ($this->require_file($file)) { - return $file; - } + /** + * Load the mapped file for a namespace prefix and relative class. + * + * @param string $prefix The namespace prefix. + * @param string $relative_class The relative class name. + * + * @return mixed Boolean false if no mapped file can be loaded, or the + * name of the mapped file that was loaded. + */ + protected function loadMappedFile(string $prefix, string $relative_class) + { + if (isset($this->prefixes[$prefix]) === false) { + return false; + } + foreach ($this->prefixes[$prefix] as $base_dir) { + $file = $base_dir + . str_replace('\\', '/', $relative_class) + . '.php'; + if ($this->requireFile($file)) { + return $file; + } + } + return false; } - return false; - } - /** - * If a file exists, require it from the file system. - * - * @param string $file The file to require. - * @return bool True if the file exists, false if not. - */ - protected function require_file(string $file): bool { - if (file_exists($file)) { - require $file; - return true; + /** + * If a file exists, require it from the file system. + * + * @param string $file The file to require. + * + * @return bool True if the file exists, false if not. + */ + protected function requireFile(string $file): bool + { + if (file_exists($file)) { + include $file; + return true; + } + return false; } - return false; - } } diff --git a/app/neato_colors.php b/app/neato_colors.php index bb171b9..1f56f15 100644 --- a/app/neato_colors.php +++ b/app/neato_colors.php @@ -1,75 +1,105 @@ + * @license https://mit-license.org/ MIT License + * @link https://git.mysnippetsofcode.com/tts/neatoDeploy + */ - $colored_string = ""; +/** + * Function getTermColors make ANSI color codes + * + * @param array|string $input text to display + * @param mixed $options colors to use + * + * @return string ANSI text + */ +function getTermColors(array|string $input, $options): string +{ - $styles = [ - 'normal' => '0', // reset - 'bold' => '1', - 'dim' => '2', - 'underlined' => '4', - 'blinking' => '5' - ]; + $colored_string = ""; - $fg_colors = [ - 'black' => '0;30', - 'dark_gray' => '1;30', - 'blue' => '0;34', - 'light_blue' => '1;34', - 'green' => '0;32', - 'light_green' => '1;32', - 'cyan' => '0;36', - 'light_cyan' => '1;36', - 'red' => '0;31', - 'light_red' => '1;31', - 'purple' => '0;35', - 'light_purple' => '1;35', - 'brown' => '0;33', - 'yellow' => '1;33', - 'light_gray' => '0;37', - 'white' => '1;37' - ]; + $styles = [ + 'normal' => '0', // reset + 'bold' => '1', + 'dim' => '2', + 'underlined' => '4', + 'blinking' => '5' + ]; - $bg_colors = [ - 'black' => '40', - 'red' => '41', - 'green' => '42', - 'yellow' => '43', - 'blue' => '44', - 'magenta' => '45', - 'cyan' => '46', - 'light_gray' => '47' - ]; + $fg_colors = [ + 'black' => '0;30', + 'dark_gray' => '1;30', + 'blue' => '0;34', + 'light_blue' => '1;34', + 'green' => '0;32', + 'light_green' => '1;32', + 'cyan' => '0;36', + 'light_cyan' => '1;36', + 'red' => '0;31', + 'light_red' => '1;31', + 'purple' => '0;35', + 'light_purple' => '1;35', + 'brown' => '0;33', + 'yellow' => '1;33', + 'light_gray' => '0;37', + 'white' => '1;37' + ]; - $style = (isset($options['style'])) ? strtolower($options['style']) : ''; - $color = (isset($options['color'])) ? strtolower($options['color']) : ''; - $fg_color = (isset($options['fg_color'])) ? strtolower($options['fg_color']) : $color; - $bg_color = (isset($options['bg_color'])) ? strtolower($options['bg_color']) : ''; - - if ($style !== '' && isset($styles[$style])) { - $colored_string .= "\033[" . $styles[$style] . "m"; - } - if ($fg_color !== '' && isset($fg_colors[$fg_color])) { - $colored_string .= "\033[" . $fg_colors[$fg_color] . "m"; - } - if ($bg_color !== '' && isset($bg_colors[$bg_color])) { - $colored_string .= "\033[" . $bg_colors[$bg_color] . "m"; - } + $bg_colors = [ + 'black' => '40', + 'red' => '41', + 'green' => '42', + 'yellow' => '43', + 'blue' => '44', + 'magenta' => '45', + 'cyan' => '46', + 'light_gray' => '47' + ]; + + $style = (isset($options['style'])) ? strtolower($options['style']) : ''; + $color = (isset($options['color'])) ? strtolower($options['color']) : ''; + $fg_color = (isset($options['fg_color'])) ? strtolower($options['fg_color']) : $color; + $bg_color = (isset($options['bg_color'])) ? strtolower($options['bg_color']) : ''; + + if ($style !== '' && isset($styles[$style])) { + $colored_string .= "\033[" . $styles[$style] . "m"; + } + if ($fg_color !== '' && isset($fg_colors[$fg_color])) { + $colored_string .= "\033[" . $fg_colors[$fg_color] . "m"; + } + if ($bg_color !== '' && isset($bg_colors[$bg_color])) { + $colored_string .= "\033[" . $bg_colors[$bg_color] . "m"; + } $str = ''; - if (is_array($input)) { - foreach ($input as $s) { - $str .= $s . PHP_EOL; - } - } else { - $str = $input; - } + if (is_array($input)) { + foreach ($input as $s) { + $str .= $s . PHP_EOL; + } + } else { + $str = $input; + } - $colored_string .= $str . "\033[0m"; - return $colored_string; + $colored_string .= $str . "\033[0m"; + return $colored_string; } -function ANSI($data, $a) { - getTermColors($data, $a); +/** + * Alias to getTermColors + * + * @param array|string $data text to display + * @param mixed $a options for colors + * + * @return string of ANSI + */ +function ANSI(array|string $data, $a): string +{ + return getTermColors($data, $a); } diff --git a/app/neato_common.php b/app/neato_common.php index 3e2b6b4..dca345a 100644 --- a/app/neato_common.php +++ b/app/neato_common.php @@ -13,12 +13,12 @@ require 'neato_enc.php'; configure::set('logger_time_zone', 'America/Detroit'); -registry::set('loader', new \Psr4AutoloaderClass); -registry::get('loader')->register(); -registry::get('loader')->add_namespace('utils', 'utils'); -registry::get('loader')->add_namespace('traits', 'traits'); -registry::get('loader')->add_namespace('package_managers', 'package_managers'); -registry::get('loader')->add_namespace('init_systems', 'init_systems'); +Neato_Registry::set('loader', new \Neato_Auto_Loader); +Neato_Registry::get('loader')->register(); +Neato_Registry::get('loader')->addNamespace('utils', 'utils'); +Neato_Registry::get('loader')->addNamespace('traits', 'traits'); +Neato_Registry::get('loader')->addNamespace('package_managers', 'package_managers'); +Neato_Registry::get('loader')->addNamespace('init_systems', 'init_systems'); function force_root(): void { if (posix_getuid() > 0) { @@ -66,45 +66,45 @@ function read_file($file) { function write_file($file, $data) { $exit_code = file_put_contents($file, $data); $real = ($exit_code === false) ? false : true; - check_for_error($real, "Unable to save to file: {$file}"); + checkForError($real, "Unable to save to file: {$file}"); return $real; } function append_to_file($file, $data) { $exit_code = file_put_contents($file, $data, FILE_APPEND | LOCK_EX); $real = ($exit_code === false) ? false : true; - check_for_error($real, "Unable to save to file: {$file}"); + checkForError($real, "Unable to save to file: {$file}"); return $real; } function rm($file) { $exit_code = unlink($file); - check_for_error($exit_code, "Unable to Delete file: {$file}"); + checkForError($exit_code, "Unable to Delete file: {$file}"); return $exit_code; } function mv($old, $new) { $exit_code = rename($old, $new); - check_for_error($exit_code, "Unable to Move file: {$old} to {$new}"); + checkForError($exit_code, "Unable to Move file: {$old} to {$new}"); return $exit_code; } function cp($source, $dest) { $exit_code = copy($source, $dest); - check_for_error($exit_code, "Unable to Copy file: {$source} to: {$dest}"); + checkForError($exit_code, "Unable to Copy file: {$source} to: {$dest}"); return $exit_code; } function ln($source, $new_link) { $exit_code = symlink($source, $new_link); - check_for_error($exit_code, "Unable to make Link for file: {$source} to: {$new_link}"); + checkForError($exit_code, "Unable to make Link for file: {$source} to: {$new_link}"); return $exit_code; } function make_dir($new_folder, $perms=0775) { if (!is_dir($new_folder)) { $exit_code = mkdir($new_folder, $perms, true); - check_for_error($exit_code, "Unable to mkdir: {$new_folder}"); + checkForError($exit_code, "Unable to mkdir: {$new_folder}"); return $exit_code; } else { return true; @@ -115,10 +115,10 @@ function chmod_file_or_dir($file, $kind) { if (!is_file($file) && !is_dir($file)) { $ret = false; } else { - $perms = get_perms($kind); + $perms = getPerms($kind); $ret = chmod($file, $perms); } - check_for_error($ret, "Unable to chmod: {$file}"); + checkForError($ret, "Unable to chmod: {$file}"); return $ret; } @@ -126,7 +126,7 @@ function change_owner($file, $uid, $gid) { $ret_owner = chown($file, $uid); $ret_group = chgrp($file, $gid); $exit_code = ($ret_owner && $ret_group) ? true : false; - check_for_error($exit_code, "Unable to chown on: {$file}"); + checkForError($exit_code, "Unable to chown on: {$file}"); return $exit_code; } diff --git a/app/neato_danger_checker.php b/app/neato_danger_checker.php index 95ada7c..cc980bf 100644 --- a/app/neato_danger_checker.php +++ b/app/neato_danger_checker.php @@ -194,13 +194,13 @@ function is_file_dangerious($file_name) : bool { $line = strtolower( $line ); // make sure it matches $line = str_replace( ' ', '', $line ); // remove white-spaces! foreach( $dangerious as $danger ) { - if ( is_string_found( $line, $danger . "(" ) ) { + if ( isStringFound( $line, $danger . "(" ) ) { echo PHP_EOL . "Warning: Found method: {$danger} in : " . $line . PHP_EOL; $found = true; } } foreach( $match_on as $whole_match ) { - if ( is_string_found($line, $whole_match) ) { + if ( isStringFound($line, $whole_match) ) { echo PHP_EOL . "Warning: Found method: {$whole_match} in : " . $line . PHP_EOL; $found = true; } diff --git a/app/neato_enc.php b/app/neato_enc.php index cb55898..6380808 100644 --- a/app/neato_enc.php +++ b/app/neato_enc.php @@ -66,7 +66,7 @@ class enc { if (!file_exists($file_name)) { $key = self::generate_key(); write_file($file_name, $key); - chmod_file_or_dir($file_name, get_perms("secret")); + chmod_file_or_dir($file_name, getPerms("secret")); change_owner($file_name, "root", "root"); } else { $key = read_file($file_name); diff --git a/app/neato_fns.php b/app/neato_fns.php index fa587de..b7d2568 100644 --- a/app/neato_fns.php +++ b/app/neato_fns.php @@ -1,8 +1,32 @@ + * @license https://mit-license.org/ MIT License + * @link https://git.mysnippetsofcode.com/tts/neatoDeploy + */ + +/** + * $cwd is deinfed in neato.php + * + * @phpstan-ignore-next-line Variable $cwd might not be defined + */ define('PROJECT_RUN_DIR', $cwd . '/run'); -function display($data) { +/** + * Function display MAY: echo to the screen, Syslog, and/or Loggger. + * + * @param array|string $data input to use for text + * + * @return bool may be false if no text was supplied. + */ +function display(array|string $data): bool +{ $str = ''; if (is_array($data)) { foreach ($data as $s) { @@ -26,12 +50,22 @@ function display($data) { if (configure::get('logfile')) { $config_file = (defined('CONFIG_FILE')) ? '_' . CONFIG_FILE : ''; - $logger = new logger('neatoInstaller' . $config_file); + $logger = new Logger('neatoInstaller' . $config_file); $logger->write($str); } + return true; } -function check_for_error($exit_code, $msg) { +/** + * Check for Error and display them. + * + * @param string|int|bool $exit_code int or boolean of success + * @param array|string $msg Error text to display if fails + * + * @return void + */ +function checkForError(string|int|bool $exit_code, array|string $msg): void +{ if ($exit_code === true) { return; } @@ -40,62 +74,86 @@ function check_for_error($exit_code, $msg) { } } -function get_perms($kind): int { +/** + * Take kind as input and figure out int Permissions. + * + * @param mixed $kind string|int Kind of permission for chmod + * + * @return int New file Permissions + */ +function getPerms($kind): int +{ if (is_numeric($kind) && (strlen($kind) == 3 || strlen($kind) == 4 )) { return intval($kind); } switch ($kind) { - case 'keydir': $perm = 0700; - break; - case 'dir': $perm = 0775; - break; - case 'web': - case 'normal': - $perm = 0664; - break; - case 'bin': $perm = 0755; - break; - case 'sbin': $perm = 0750; - break; - case 'writeonly': $perm = 0220; - break; - case 'readonly': $perm = 0444; - break; - case 'key': - case 'secret': $perm = 0600; - break; + case 'keydir': $perm = 0700; + break; + case 'dir': $perm = 0775; + break; + case 'web': + case 'normal': + $perm = 0664; + break; + case 'bin': $perm = 0755; + break; + case 'sbin': $perm = 0750; + break; + case 'writeonly': $perm = 0220; + break; + case 'readonly': $perm = 0444; + break; + case 'key': + case 'secret': $perm = 0600; + break; // config file - default: - $perm = 0644; + default: + $perm = 0644; } return $perm; } -function use_me($program) { +/** + * Use Me, Program to check if installed/Run + * + * @param string $program thing to install/Run + * + * @staticvar boolean $did_update Has it updated yet? + * + * @return mixed boolean or status int + */ +function useMe(string $program) +{ static $did_update = false; - $installed_a = do_command('is_installed', $program); + $installed_a = doCommand('is_installed', $program); $is_installed_b = $installed_a['installed']; if ($is_installed_b === false) { - if ($did_update === false) { - $did = do_command('update'); - if ($did !== 0) { - return false; + if ($did_update === false) { + $did = doCommand('update'); + if ($did !== 0) { + return false; + } + $did_update = true; } - $did_update = true; - } - return do_command('install', $program); + return doCommand('install', $program); } return true; } -function do_command() { +/** + * Gets argument list and passes it to either Utils or Neato + * + * @return mixed boolean or status int + */ +function doCommand() +{ $numargs = func_num_args(); if ($numargs == 0) { return false; } $arg_list = func_get_args(); - if (is_string_found($arg_list[0], "::")) { + if (isStringFound($arg_list[0], "::")) { $method = "\\utils\\" . array_shift($arg_list); } else { $method = "neato::" . array_shift($arg_list); @@ -117,50 +175,66 @@ function do_command() { } } -function file_loop($data) { +/** + * File Loop, Run File Utils + * + * @param array $data command and option + * + * @return boolean Success? + */ +function fileLoop(array $data) +{ $retval = true; foreach ($data as $command => $v) { switch (strtolower($command)) { - case 'sed': - $ret = sed_loop($v); - if ($ret === false) { - $retval = false; - } - break; - case 'cp': - case 'mv': - case 'ln': - case 'rm': - case 'make_dir': - case 'chmod_file_or_dir': - foreach ($v as $a => $b) { - $a = (isset($a) && !empty($a)) ? $a : false; - $b = (isset($b) && !empty($b)) ? $b : false; - if ($a !== false) { - if ($b !== false) { - $ret = $command($a, $b); - if ($ret === false) { - $retval = false; - } - } else { - $ret = $command($a); - if ($ret === false) { - $retval = false; - } + case 'sed': + $ret = sedLoop($v); + if ($ret === false) { + $retval = false; + } + break; + case 'cp': + case 'mv': + case 'ln': + case 'rm': + case 'make_dir': + case 'chmod_file_or_dir': + foreach ($v as $a => $b) { + $a = (isset($a) && !empty($a)) ? $a : false; + $b = (isset($b) && !empty($b)) ? $b : false; + if ($a !== false) { + if ($b !== false) { + $ret = $command($a, $b); + if ($ret === false) { + $retval = false; + } + } else { + $ret = $command($a); + if ($ret === false) { + $retval = false; } } } - break; + } + break; } } return $retval; } -function sed_loop($data) { +/** + * SED Loop, Text replacement tool + * + * @param array $data file and find/replace data + * + * @return boolean Success? + */ +function sedLoop(array $data) +{ $retval = true; foreach ($data as $file => $data) { foreach ($data as $find => $replace) { - $ret = do_command('sed::replace', $file, $find, $replace); + $ret = doCommand('sed::replace', $file, $find, $replace); if ($ret === false) { $retval = false; } @@ -169,11 +243,26 @@ function sed_loop($data) { return $retval; } -function stderr() { - return ' 2>&1'; // exec redirect std errors to output for use with display.... +/** + * Exec Redirect STD Errors to output for use with display... + * + * @return string + */ +function stdErr(): string +{ + return ' 2>&1'; } -function run_once($output = true, $halt = true) { +/** + * Force and script to only Run One time...! + * + * @param bool $output Display? Will it say Script was run once before... + * @param bool $halt Will exit(1) + * + * @return bool Success? + */ +function runOnce(bool $output = true, bool $halt = true): bool +{ if (!is_dir(PROJECT_RUN_DIR)) { mkdir(PROJECT_RUN_DIR, 0775); } @@ -198,17 +287,44 @@ function run_once($output = true, $halt = true) { } } -function safe_cmd_quotes($data) { +/** + * Make things safer to use for terminal with no Quotes. + * + * @param string $data shell program to run safer... + * + * @return string Safer Shell Arg without Quotes + */ +function safeCmdQuotes(string $data): string +{ $data = str_replace('"', "", $data); $data = str_replace("'", "", $data); return escapeshellcmd($data); } -function safe_cmd($input, $in = '') { +/** + * Let's help keep the console CLI safer. + * + * @param string $input main command to run + * @param string $in second command options + * + * @return string safer command + */ +function safeCmd(string $input, string $in = ''): string +{ return (!empty($in)) ? escapeshellcmd(escapeshellarg($input) . " " . escapeshellarg($in)) : escapeshellcmd(escapeshellarg($input)); } -function cgetopt($Options = []) { +/** + * This gets command line options for easy access to Arguments. + * + * @param array $Options User defined switches EX: -help + * + * @global array $argv CLI Arguments passed into this script + * + * @return array Options found typed into terminal + */ +function cGetOpt(array $Options = []): array +{ global $argv; $options = []; $currentOption = null; diff --git a/app/neato_init.php b/app/neato_init.php index 3d022b8..da1ebf1 100644 --- a/app/neato_init.php +++ b/app/neato_init.php @@ -1,6 +1,23 @@ + * @license https://mit-license.org/ MIT License + * @link https://git.mysnippetsofcode.com/tts/neatoDeploy + */ + +/** + * Checks to make sure php is in CLI AKA the Command Line + * + * @return bool true if in CLI + */ +function isCLI() +{ if (defined('STDIN')) { return true; } @@ -19,18 +36,30 @@ function is_cli() { return false; } -if (is_cli() === false) { +if (isCLI() === false) { echo('Unable to Start'); exit(1); } -function OS_details() { +/** + * Grabs the Kernel and System Architecture using PHP uname. + * + * @return array about version of Kernal and CPU Type. + */ +function OS_details(): array +{ $kernel_version = php_uname('r'); $system_architecture = php_uname('m'); return ['kernel'=>$kernel_version, 'architecture'=>$system_architecture]; } -function get_Windows_version() { +/** + * Grabs OS version and build. + * + * @return array Windows version and build number. + */ +function getWindowsVersion(): array +{ $os_info = php_uname(); $pattern = '/Windows\sNT\s(\d+\.\d+).*build\s(\d+)/'; preg_match($pattern, $os_info, $matches); @@ -45,7 +74,15 @@ function get_Windows_version() { } } -function get_based_on_distribution($distributionName) { +/** + * Fetch base OS name + * + * @param string $distributionName OS name + * + * @return string what is it based off of...Debian as an example + */ +function getBasedOnDistribution(string $distributionName): string +{ $distributions = [ 'ubuntu' => 'debian', 'debian' => 'unknown', @@ -74,13 +111,19 @@ function get_based_on_distribution($distributionName) { } } -function get_Linux_version() { +/** + * Grabs a bunch of OS details like codename, name, etc... + * + * @return null|array Linux OS details + */ +function getLinuxVersion(): ?array +{ $os_info = php_uname(); $pattern = '/^Linux (.+?)(?:\s+|\()([\d.]+)(?:\).*)?$/'; if (preg_match($pattern, $os_info, $matches)) { $distribution = $matches[1]; $version = $matches[2]; - return ['name'=>$distribution,'version_codename'=>null,'version_id'=>$version, 'id_like'=>get_based_on_distribution($distribution),'id'=>strtolower($distribution),'linux'=>true]; + return ['name'=>$distribution,'version_codename'=>null,'version_id'=>$version, 'id_like'=>getBasedOnDistribution($distribution),'id'=>strtolower($distribution),'linux'=>true]; } if (function_exists("exec")) { $codename = "unknown"; @@ -98,22 +141,28 @@ function get_Linux_version() { exec('lsb_release -si', $output, $return_code); if ($return_code === 0 && !empty($output)) { $distribution = trim($output[0]); - return ['name'=>$distribution, 'version_codename'=>$codename, 'version_id'=>$version, 'id_like'=>get_based_on_distribution($distribution),'id'=> strtolower($distribution),'linux'=>true]; + return ['name'=>$distribution, 'version_codename'=>$codename, 'version_id'=>$version, 'id_like'=>getBasedOnDistribution($distribution),'id'=> strtolower($distribution),'linux'=>true]; } } return null; } -function get_OS_information() { +/** + * Grab as much OS details and return as an array. + * + * @return null|array OS Details + */ +function getOSInformation(): ?array +{ if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - $windows_version = get_Windows_version(); + $windows_version = getWindowsVersion(); $build = $windows_version['build'] ?? false; $version = $windows_version['version'] ?? false; return ['name' => 'Windows', 'version_codename'=>$build, 'version_id'=>$version, 'id_like'=>"win"+$version,'id' => $build,'linux'=>false]; } if (function_exists("shell_exec") === false|| is_readable("/etc/os-release") === false) { - return get_Linux_version(); + return getLinuxVersion(); } $os = shell_exec('cat /etc/os-release'); @@ -123,32 +172,63 @@ function get_OS_information() { $list_val = preg_match_all('/=.*/', $os, $match_list_val); $list_val = $match_list_val[0]; - array_walk($list_ids, function(&$v, $k) { - $v = strtolower(str_replace('=', '', $v)); - }); + array_walk( + $list_ids, function (&$v, $k) { + $v = strtolower(str_replace('=', '', $v)); + } + ); - array_walk($list_val, function(&$v, $k) { - $v = preg_replace('/=|"/', '', $v); - }); + array_walk( + $list_val, function (&$v, $k) { + $v = preg_replace('/=|"/', '', $v); + } + ); $a = array_combine($list_ids, $list_val); $a['linux'] = true; return $a; } -function is_string_found(string $data, string $find): bool { +/** + * Like str_contains. + * + * @param string $data what to look at + * @param string $find Search for this + * + * @return bool was the string found + */ +function isStringFound(string $data, string $find): bool +{ return (stripos($data, $find) !== false); } -function get_left(string $str, int $length): string { +/** + * Get left most part of a string... + * + * @param string $str input + * @param int $length How much to get + * + * @return string data from the left most to X length. + */ +function getLeft(string $str, int $length): string +{ return substr($str, 0, $length); } -function get_right(string $str, int $length): string { +/** + * Get right most part of a string... + * + * @param string $str input + * @param int $length How much to get + * + * @return string data from the left most to X length. + */ +function getRight(string $str, int $length): string +{ return substr($str, -$length); } -$os = get_OS_information(); +$os = getOSInformation(); $details = OS_details(); $os['kernel'] = $details['kernel'] ?? false; $os['architecture'] = $details['architecture'] ?? false; diff --git a/app/neato_logger.php b/app/neato_logger.php index f7a2839..814a934 100644 --- a/app/neato_logger.php +++ b/app/neato_logger.php @@ -1,111 +1,152 @@ + * @license https://mit-license.org/ MIT License + * @link https://git.mysnippetsofcode.com/tts/neatoDeploy + */ + +/** + * $cwd is defined in neato.php + * + * @phpstan-ignore-next-line Variable $cwd might not be defined + */ define('PROJECT_LOGS_DIR', $cwd. '/log'); -class logger { +/** + * Logs display data + + * @param mixed $input text to display + * @param mixed $options colors to use + * + * @category Util + * @package Neato + * @author Robert S. + * @license https://mit-license.org/ MIT License + * @link https://git.mysnippetsofcode.com/tts/neatoDeploy + * + * @return string ANSI text + */ - private $handle; +class Logger +{ + + private $_handle; - /** - * Get Filename for writing to Log file - * @param string $filename for log - * @param int $max_count of lines before file wipe, to keep small logs. - */ - public function __construct(string $filename = 'neato_Installer', int $max_count = 1000) { - if (strpos($filename, "..") !== false) { - $this->handle = false; // Too dangerious, so return false - } else { - $filename = str_replace("php", "", $filename); - if (! is_dir(PROJECT_LOGS_DIR)){ - //Directory does not exist, so lets create it. - mkdir(PROJECT_LOGS_DIR, 0775); - } + /** + * Get Filename for writing to Log file + * + * @param string $filename for log + * @param int $max_count of lines before file wipe, to keep small logs. + */ + public function __construct(string $filename = 'neato_Installer', int $max_count = 1000) + { + if (strpos($filename, "..") !== false) { + $this->_handle = false; // Too dangerious, so return false + } else { + $filename = str_replace("php", "", $filename); + if (! is_dir(PROJECT_LOGS_DIR)) { + //Directory does not exist, so lets create it. + mkdir(PROJECT_LOGS_DIR, 0775); + } - $filename = preg_replace("|[^A-Za-z0-9_]|", "", $filename); - $filename = escapeshellcmd($filename); - $file = PROJECT_LOGS_DIR . '/' . $filename . ".log.txt"; + $filename = preg_replace("|[^A-Za-z0-9_]|", "", $filename); + $filename = escapeshellcmd($filename); + $file = PROJECT_LOGS_DIR . '/' . $filename . ".log.txt"; - if ($max_count > 1) { - if ($this->get_lines($file) > $max_count) { - unlink($file); - } - } + if ($max_count > 1) { + if ($this->getLines($file) > $max_count) { + unlink($file); + } + } - $success = touch($file); - if ($success === false) { - $this->handle = false; - throw new \Exception('Unable to touch file:' . $file); - } - chmod($file, 0660); - if (! is_writable($file)) { - $this->handle = false; - throw new \Exception('Unable to write to file:' . $file); - } - $this->handle = fopen($file, 'a'); + $success = touch($file); + if ($success === false) { + $this->_handle = false; + throw new \Exception('Unable to touch file:' . $file); + } + chmod($file, 0660); + if (! is_writable($file)) { + $this->_handle = false; + throw new \Exception('Unable to write to file:' . $file); + } + $this->_handle = fopen($file, 'a'); + } } - } - /** - * Count number of lines in Log File - * @param string $file - * @return int line count - */ - public function get_lines(string $file): int { - // No such file, so return zero for length. - if (! file_exists($file)) { - return 0; - } + /** + * Count number of lines in Log File + * + * @param string $file filename to check how big it is + * + * @return int line count + */ + public function getLines(string $file): int + { + // No such file, so return zero for length. + if (! file_exists($file)) { + return 0; + } - $f = fopen($file, 'rb'); - $lines = 0; + $f = fopen($file, 'rb'); + $lines = 0; - if ($f === false || !is_resource($f)) { - return 0; - } + if ($f === false || !is_resource($f)) { + return 0; + } - while (!feof($f)) { - $line = fread($f, 8192); - if ($line === false) { - return 0; - } - $lines += substr_count($line, "\n"); - } + while (!feof($f)) { + $line = fread($f, 8192); + if ($line === false) { + return 0; + } + $lines += substr_count($line, "\n"); + } - fclose($f); + fclose($f); - return $lines; - } - - /** - * Write to Log File - * @param string $message to save - * @return bool able to write to log file - */ - public function write(string $message): bool { - if ( $this->handle === false || ! is_resource($this->handle) ) { - return false; + return $lines; } - $tz = configure::get('logger_time_zone'); - if ($tz !== false && !empty($tz)) { - $tz_obj = new \DateTimeZone($tz); - $dt = new \DateTime(); - $dt->setTimezone($tz_obj); - $now = $dt->format('g:i A \o\n l jS F Y'); - } else { - $dt = new \DateTime(); - $now = $dt->format('g:i A \o\n l jS F Y'); + + /** + * Write to Log File + * + * @param string $message to save + * + * @return bool able to write to log file + */ + public function write(string $message): bool + { + if ($this->_handle === false || ! is_resource($this->_handle) ) { + return false; + } + $tz = configure::get('logger_time_zone'); + if ($tz !== false && !empty($tz)) { + $tz_obj = new \DateTimeZone($tz); + $dt = new \DateTime(); + $dt->setTimezone($tz_obj); + $now = $dt->format('g:i A \o\n l jS F Y'); + } else { + $dt = new \DateTime(); + $now = $dt->format('g:i A \o\n l jS F Y'); + } + fwrite($this->_handle, $now . ' - ' . print_r($message, true) . "\n"); + return true; } - fwrite($this->handle, $now . ' - ' . print_r($message, true) . "\n"); - return true; - } - /** - * Close Log File Handle - */ - public function __destruct() { - if ($this->handle !== false && is_resource($this->handle)) { - fclose($this->handle); + /** + * Close Log File Handle + */ + public function __destruct() + { + if ($this->_handle !== false && is_resource($this->_handle)) { + fclose($this->_handle); + } } - } } // end of Logger diff --git a/app/neato_registry.php b/app/neato_registry.php index 3d1c08a..83322d2 100644 --- a/app/neato_registry.php +++ b/app/neato_registry.php @@ -1,69 +1,178 @@ + * @license https://mit-license.org/ MIT License + * @link https://git.mysnippetsofcode.com/tts/neatoDeploy + */ -final class registry { - private static $registry = []; - protected function __construct() { } +/** + * Class Registry to hold di + * + * @category Util + * @package Neato + * @author Robert S. + * @license https://mit-license.org/ MIT License + * @link https://git.mysnippetsofcode.com/tts/neatoDeploy + */ +final class Neato_Registry +{ + private static $_registry = []; + + /** + * Protected constructor to stop instances from being created. + */ + protected function __construct() + { + } - public static function get(string $name, $key = false) { - if (isset(self::$registry[strtolower($name)])) { - $a = self::$registry[strtolower($name)]; - if ($key === false) { - return $a; - } - if (isset($a[$key])) { - return $a[$key]; - } + /** + * Retrieves data from the registry. + * + * @param string $name item label to fetch + * @param string|false $key is like a subkey for another item + * + * @return mixed + */ + public static function get(string $name, string|false $key = false) + { + if (isset(self::$_registry[strtolower($name)])) { + $a = self::$_registry[strtolower($name)]; + if ($key === false) { + return $a; + } + if (isset($a[$key])) { + return $a[$key]; + } + } + return null; } - return null; - } - public static function set(string $name, $value): bool { - if (array_key_exists(strtolower($name), self::$registry)) { - return false; + /** + * Assigns data into the registry to be used anywhere in the app. + * + * @param string $name label for item to set into registry. + * @param mixed $value data to put into registry. + * + * @return bool + */ + public static function set(string $name, mixed $value): bool + { + if (array_key_exists(strtolower($name), self::$_registry)) { + return false; + } + self::$_registry[strtolower($name)] = $value; + return true; } - self::$registry[strtolower($name)] = $value; - return true; - } } -final class di { - protected $services = []; - - public function register(string $service_name, callable $callable): void { - $this->services[$service_name] = $callable; - } - // Note args may be an object or an array maybe more...! - public function get_service(string $service_name, $args = []) { - if (!array_key_exists($service_name, $this->services)) { - throw new \Exception("The Service: {$service_name} does not exists."); +/** + * Class Di dependency injection. + * + * @category Util + * @package Neato + * @author Robert S. + * @license https://mit-license.org/ MIT License + * @link https://git.mysnippetsofcode.com/tts/neatoDeploy + */ + +final class Di +{ + /** + * Holds protected services in an array. + * + * @var array $services holds everything for di + */ + protected array $services = []; + /** + * Set's registry up for useage. + * + * @param string $service_name label for callable code + * @param callable $callable method to use + * + * @return void + */ + public function register(string $service_name, callable $callable): void + { + $this->services[$service_name] = $callable; + } + + /** + * Get service data + * Note args may be an object or an array maybe more...! + * + * @param string $service_name label for service + * @param mixed $args the parameters to use + * + * @return mixed code injected for later use. + * @throws \Exception + */ + public function getService(string $service_name, $args = []) + { + if (!array_key_exists($service_name, $this->services)) { + throw new \Exception("The Service: {$service_name} does not exists."); + } + return $this->services[$service_name]($args); } - return $this->services[$service_name]($args); - } - public function __set(string $service_name, callable $callable): void { - $this->register($service_name, $callable); - } - - public function __get(string $service_name) { - return $this->get_service($service_name); - } + /** + * Majic setter, service to be registered. + * + * @param string $service_name label for service + * @param callable $callable code injected for later use + * + * @return void + */ + public function __set(string $service_name, callable $callable): void + { + $this->register($service_name, $callable); + } - public function list_services_as_array(): array { - return array_keys($this->services); - } + /** + * Magic getter method same as get service. + * + * @param string $service_name label for service + * + * @return mixed code injected for later use. + */ + public function __get(string $service_name) + { + return $this->getService($service_name); + } + + /** + * Lists all services as an array. + * + * @return array of services that can be used + */ + public function listServicesAsArray(): array + { + return array_keys($this->services); + } - public function list_services_as_string(): string { - return implode(',', array_keys($this->services)); - } + /** + * Lists all services as a string. + * + * @return string of services + */ + public function listServicesAsString(): string + { + return implode(',', array_keys($this->services)); + } } // Initialize our Dependency Injector -registry::set('di', new di()); +Neato_Registry::set('di', new Di()); // Setup php for working with Unicode data, if possible if (extension_loaded('mbstring')) { - mb_internal_encoding('UTF-8'); - mb_http_output('UTF-8'); - mb_language('uni'); - setlocale(LC_ALL, "en_US.UTF-8"); + mb_internal_encoding('UTF-8'); + mb_http_output('UTF-8'); + mb_language('uni'); + setlocale(LC_ALL, "en_US.UTF-8"); } \ No newline at end of file diff --git a/app/package_managers/apk.php b/app/package_managers/apk.php index 8e79b8b..00567c7 100644 --- a/app/package_managers/apk.php +++ b/app/package_managers/apk.php @@ -5,47 +5,47 @@ namespace package_managers; class apk { public static function is_installed($prog) { - exec(\neato::get_user_bin . 'apk -e info ' . safe_cmd($prog), $out, $exit_code); + exec(\neato::get_user_bin . 'apk -e info ' . safeCmd($prog), $out, $exit_code); return ($exit_code == 0) ? ['installed' => true, 'version' => $out] : ['installed' => false]; } public static function upgrade($prog) { - exec(\neato::get_user_bin . 'apk upgrade -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apk upgrade -y ' . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to upgrade: {$prog}"); + checkForError($exit_code, "Unable to upgrade: {$prog}"); return $exit_code; } public static function install($prog) { - exec(\neato::get_user_bin . 'apk add -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apk add -y ' . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to install: {$prog}"); + checkForError($exit_code, "Unable to install: {$prog}"); return $exit_code; } public static function uninstall($prog) { - exec(\neato::get_user_bin . 'apk del -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apk del -y ' . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to uninstall: {$prog}"); + checkForError($exit_code, "Unable to uninstall: {$prog}"); return $exit_code; } public static function add_repo($repo) { exec("echo \"$repo\" >> /etc/apk/repositories"); - exec(\neato::get_user_bin . 'apk update' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apk update' . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to add new repo: {$repo}"); + checkForError($exit_code, "Unable to add new repo: {$repo}"); return $exit_code; } public static function update() { - exec(\neato::get_user_bin . 'apk update -y ' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apk update -y ' . stdErr(), $output, $exit_code); display($output); return $exit_code; } public static function full_update() { - exec(\neato::get_user_bin . 'apk update -y && ' . \neato::get_user_bin . 'apk upgrade -y' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apk update -y && ' . \neato::get_user_bin . 'apk upgrade -y' . stdErr(), $output, $exit_code); display($output); return $exit_code; } diff --git a/app/package_managers/apt.php b/app/package_managers/apt.php index af807ed..93186f9 100644 --- a/app/package_managers/apt.php +++ b/app/package_managers/apt.php @@ -5,66 +5,66 @@ namespace package_managers; class apt { public static function is_installed(string $prog) { - exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); - exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); + exec(\neato::get_user_bin . 'dpkg -s ' . safeCmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); + exec(\neato::get_user_bin . 'dpkg -s ' . safeCmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); $version = str_replace('Version: ', '', $output[0]); return ($exit_code == 0) ? ['installed' => true, 'version' => $version] : ['installed' => false]; } public static function upgrade(string $prog, bool $auto=true) { $assume = ($auto) ? "-y " : ""; - exec(\neato::get_user_bin . 'apt upgrade ' . $assume . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apt upgrade ' . $assume . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to upgrade: {$prog}"); + checkForError($exit_code, "Unable to upgrade: {$prog}"); return $exit_code; } public static function install(string $prog, bool $auto=true) { $assume = ($auto) ? "-y " : ""; - exec(\neato::get_user_bin . 'apt install ' . $assume . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apt install ' . $assume . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to install: {$prog}"); + checkForError($exit_code, "Unable to install: {$prog}"); return $exit_code; } public static function purge(string $prog, bool $auto=true) { $assume = ($auto) ? "-y " : ""; - exec(\neato::get_user_bin . 'apt --purge remove ' . $assume . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apt --purge remove ' . $assume . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to uninstall: {$prog}"); + checkForError($exit_code, "Unable to uninstall: {$prog}"); return $exit_code; } public static function uninstall(string $prog, bool $auto=true) { $assume = ($auto) ? "-y " : ""; - exec(\neato::get_user_bin . 'apt remove -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apt remove -y ' . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to uninstall: {$prog}"); + checkForError($exit_code, "Unable to uninstall: {$prog}"); return $exit_code; } public static function add_repo(string $repo) { - exec(\neato::get_user_bin . 'add-apt-repository -y -u ' . safe_cmd_quotes($repo) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'add-apt-repository -y -u ' . safeCmdQuotes($repo) . stdErr(), $output, $exit_code); display($output); // -u = DO UPDATE once done... - check_for_error($exit_code, "Unable to uninstall: {$repo}"); + checkForError($exit_code, "Unable to uninstall: {$repo}"); return $exit_code; } public static function update() { - exec(\neato::get_user_bin . 'apt update -y ' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apt update -y ' . stdErr(), $output, $exit_code); display($output); return $exit_code; } public static function full_update() { - exec(\neato::get_user_bin . 'apt update -y && '. \neato::get_user_bin . 'apt-get upgrade -y && ' . \neato::get_user_bin . 'apt autoremove -y && ' . \neato::get_user_bin . 'apt autoclean -y' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apt update -y && '. \neato::get_user_bin . 'apt-get upgrade -y && ' . \neato::get_user_bin . 'apt autoremove -y && ' . \neato::get_user_bin . 'apt autoclean -y' . stdErr(), $output, $exit_code); display($output); return $exit_code; } // Have a Backup!! public static function full_system_upgrade() { - exec(\neato::get_user_bin . 'apt update -y && '. \neato::get_user_bin . 'apt upgrade -y '. \neato::get_user_bin . 'apt full-upgrade -y && ' . \neato::get_user_bin . 'apt autoremove -y && ' . \neato::get_user_bin . 'apt autoclean -y' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apt update -y && '. \neato::get_user_bin . 'apt upgrade -y '. \neato::get_user_bin . 'apt full-upgrade -y && ' . \neato::get_user_bin . 'apt autoremove -y && ' . \neato::get_user_bin . 'apt autoclean -y' . stdErr(), $output, $exit_code); display($output); return $exit_code; } diff --git a/app/package_managers/apt_get.php b/app/package_managers/apt_get.php index 5b6c365..82422b7 100644 --- a/app/package_managers/apt_get.php +++ b/app/package_managers/apt_get.php @@ -5,65 +5,65 @@ namespace package_managers; class apt_get { public static function is_installed(string $prog) { - exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); - exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); + exec(\neato::get_user_bin . 'dpkg -s ' . safeCmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); + exec(\neato::get_user_bin . 'dpkg -s ' . safeCmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); $version = str_replace('Version: ', '', $output[0]); return ($exit_code == 0) ? ['installed' => true, 'version' => $version] : ['installed' => false]; } public static function upgrade(string $prog) { - exec(\neato::get_user_bin . 'apt-get upgrade -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apt-get upgrade -y ' . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to upgrade: {$prog}"); + checkForError($exit_code, "Unable to upgrade: {$prog}"); return $exit_code; } public static function install(string $prog, bool $auto=true) { $assume = ($auto) ? "-y " : ""; - exec(\neato::get_user_bin . 'apt-get install ' . $assume . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apt-get install ' . $assume . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to install: {$prog}"); + checkForError($exit_code, "Unable to install: {$prog}"); return $exit_code; } public static function purge(string $prog, bool $auto=true) { $assume = ($auto) ? "-y " : ""; - exec(\neato::get_user_bin . 'apt-get --purge remove ' . $assume . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apt-get --purge remove ' . $assume . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to uninstall: {$prog}"); + checkForError($exit_code, "Unable to uninstall: {$prog}"); return $exit_code; } public static function uninstall(string $prog, bool $auto=true) { $assume = ($auto) ? "-y " : ""; - exec(\neato::get_user_bin . 'apt-get remove ' . $assume . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apt-get remove ' . $assume . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to uninstall: {$prog}"); + checkForError($exit_code, "Unable to uninstall: {$prog}"); return $exit_code; } public static function add_repo(string $repo) { - exec(\neato::get_user_bin . 'add-apt-repository -y -u ' . safe_cmd_quotes($repo) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'add-apt-repository -y -u ' . safeCmdQuotes($repo) . stdErr(), $output, $exit_code); display($output); // -u = DO UPDATE once done... - check_for_error($exit_code, "Unable to uninstall: {$repo}"); + checkForError($exit_code, "Unable to uninstall: {$repo}"); return $exit_code; } public static function update() { - exec(\neato::get_user_bin . 'apt-get update -y ' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apt-get update -y ' . stdErr(), $output, $exit_code); display($output); return $exit_code; } public static function full_update() { - exec(\neato::get_user_bin . 'apt-get update -y && '. \neato::get_user_bin . 'apt-get upgrade -y && ' . \neato::get_user_bin . 'apt-get autoremove -y && ' . \neato::get_user_bin . 'apt-get autoclean -y' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apt-get update -y && '. \neato::get_user_bin . 'apt-get upgrade -y && ' . \neato::get_user_bin . 'apt-get autoremove -y && ' . \neato::get_user_bin . 'apt-get autoclean -y' . stdErr(), $output, $exit_code); display($output); return $exit_code; } // Have a Backup!! public static function full_system_upgrade() { - exec(\neato::get_user_bin . 'apt-get update -y && '. \neato::get_user_bin . 'apt-get upgrade -y '. \neato::get_user_bin . 'apt-get dist-upgrade -y && && ' . \neato::get_user_bin . 'apt-get autoremove -y && ' . \neato::get_user_bin . 'apt-get autoclean -y' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apt-get update -y && '. \neato::get_user_bin . 'apt-get upgrade -y '. \neato::get_user_bin . 'apt-get dist-upgrade -y && && ' . \neato::get_user_bin . 'apt-get autoremove -y && ' . \neato::get_user_bin . 'apt-get autoclean -y' . stdErr(), $output, $exit_code); display($output); return $exit_code; } diff --git a/app/package_managers/dnf.php b/app/package_managers/dnf.php index cc34c50..f525317 100644 --- a/app/package_managers/dnf.php +++ b/app/package_managers/dnf.php @@ -5,30 +5,30 @@ namespace package_managers; class dnf { public static function is_installed(string $prog) { - exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); - exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); + exec(\neato::get_user_bin . 'dpkg -s ' . safeCmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); + exec(\neato::get_user_bin . 'dpkg -s ' . safeCmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); $version = str_replace('Version: ', '', $output[0]); return ($exit_code == 0) ? ['installed' => true, 'version' => $version] : ['installed' => false]; } public static function upgrade($prog) { - exec(\neato::get_user_bin . 'dnf upgrade -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'dnf upgrade -y ' . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to upgrade: {$prog}"); + checkForError($exit_code, "Unable to upgrade: {$prog}"); return $exit_code; } public static function install($prog) { - exec(\neato::get_user_bin . 'dnf add -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'dnf add -y ' . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to install: {$prog}"); + checkForError($exit_code, "Unable to install: {$prog}"); return $exit_code; } public static function uninstall($prog) { - exec(\neato::get_user_bin . 'dnf del -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'dnf del -y ' . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to uninstall: {$prog}"); + checkForError($exit_code, "Unable to uninstall: {$prog}"); return $exit_code; } @@ -36,20 +36,20 @@ class dnf { * @todo figure out this method */ public static function add_repo($repo) { - exec(\neato::get_user_bin . 'dnf update' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'dnf update' . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to add new repo: {$repo}"); + checkForError($exit_code, "Unable to add new repo: {$repo}"); return $exit_code; } public static function update() { - exec(\neato::get_user_bin . 'dnf update -y ' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'dnf update -y ' . stdErr(), $output, $exit_code); display($output); return $exit_code; } public static function full_update() { - exec(\neato::get_user_bin . 'dnf update -y && ' . \neato::get_user_bin . 'apk upgrade -y' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'dnf update -y && ' . \neato::get_user_bin . 'apk upgrade -y' . stdErr(), $output, $exit_code); display($output); return $exit_code; } diff --git a/app/package_managers/flatpak.php b/app/package_managers/flatpak.php index 854e723..ce3edf2 100644 --- a/app/package_managers/flatpak.php +++ b/app/package_managers/flatpak.php @@ -5,8 +5,8 @@ namespace package_managers; class flatpak { public static function is_installed(string $prog) { - exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); - exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); + exec(\neato::get_user_bin . 'dpkg -s ' . safeCmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); + exec(\neato::get_user_bin . 'dpkg -s ' . safeCmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); $version = str_replace('Version: ', '', $output[0]); return ($exit_code == 0) ? ['installed' => true, 'version' => $version] : ['installed' => false]; } @@ -16,9 +16,9 @@ class flatpak { } public static function install(string $prog) { - exec(\neato::get_user_bin . 'flatpak install -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'flatpak install -y ' . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to install: {$prog}"); + checkForError($exit_code, "Unable to install: {$prog}"); return $exit_code; } @@ -27,9 +27,9 @@ class flatpak { } public static function uninstall(string $prog) { - exec(\neato::get_user_bin . 'flatpak uninstall -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'flatpak uninstall -y ' . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to uninstall: {$prog}"); + checkForError($exit_code, "Unable to uninstall: {$prog}"); return $exit_code; } @@ -37,13 +37,13 @@ class flatpak { * @todo fix me */ public static function add_repo(string $name, string $url) { - exec(\neato::get_user_bin . 'flatpak remote-add --if-not-exists ' . safe_cmd($name, $url) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'flatpak remote-add --if-not-exists ' . safeCmd($name, $url) . stdErr(), $output, $exit_code); display($output); return $exit_code; } public static function update() { - exec(\neato::get_user_bin . 'flatpak update' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'flatpak update' . stdErr(), $output, $exit_code); display($output); return $exit_code; } @@ -58,7 +58,7 @@ class flatpak { } public static function list() { - exec(\neato::get_user_bin . 'flatpak list' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'flatpak list' . stdErr(), $output, $exit_code); display($output); return $exit_code; } diff --git a/app/package_managers/nala.php b/app/package_managers/nala.php index 425c9e6..a30712b 100644 --- a/app/package_managers/nala.php +++ b/app/package_managers/nala.php @@ -5,8 +5,8 @@ namespace package_managers; class nala { public static function is_installed(string $prog) { - exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); - exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); + exec(\neato::get_user_bin . 'dpkg -s ' . safeCmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); + exec(\neato::get_user_bin . 'dpkg -s ' . safeCmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); $get_version = $output[0] ?? false; if ($get_version === false) { return ['installed' => false]; @@ -16,33 +16,33 @@ class nala { } public static function upgrade(string $prog) { - exec(\neato::get_user_bin . 'nala upgrade ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'nala upgrade ' . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to upgrade: {$prog}"); + checkForError($exit_code, "Unable to upgrade: {$prog}"); return $exit_code; } public static function install(string $prog, bool $auto=true) { $assume = ($auto) ? "--assume-yes " : ""; - exec(\neato::get_user_bin . 'nala install ' . $assume . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'nala install ' . $assume . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to install: {$prog}"); + checkForError($exit_code, "Unable to install: {$prog}"); return $exit_code; } public static function purge(string $prog, bool $auto=true) { $assume = ($auto) ? "--assume-yes " : ""; - exec(\neato::get_user_bin . 'nala purge ' . $assume . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'nala purge ' . $assume . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to uninstall: {$prog}"); + checkForError($exit_code, "Unable to uninstall: {$prog}"); return $exit_code; } public static function uninstall(string $prog, bool $auto=true) { $assume = ($auto) ? "--assume-yes " : ""; - exec(\neato::get_user_bin . 'nala remove ' . $assume . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'nala remove ' . $assume . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to uninstall: {$prog}"); + checkForError($exit_code, "Unable to uninstall: {$prog}"); return $exit_code; } @@ -54,13 +54,13 @@ class nala { } public static function update() { - exec(\neato::get_user_bin . 'nala update' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'nala update' . stdErr(), $output, $exit_code); display($output); return $exit_code; } public static function full_update() { - exec(\neato::get_user_bin . 'nala update && ' . \neato::get_user_bin . 'nala autoremove && ' . \neato::get_user_bin . 'nala clean' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'nala update && ' . \neato::get_user_bin . 'nala autoremove && ' . \neato::get_user_bin . 'nala clean' . stdErr(), $output, $exit_code); display($output); return $exit_code; } @@ -70,7 +70,7 @@ class nala { } public static function list() { - exec(\neato::get_user_bin . 'nala list --upgradeable' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'nala list --upgradeable' . stdErr(), $output, $exit_code); display($output); return $exit_code; } @@ -79,7 +79,7 @@ class nala { * shows only the packages installed on the system. */ public static function installed() { - exec(\neato::get_user_bin . 'nala list --installed' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'nala list --installed' . stdErr(), $output, $exit_code); display($output); return $exit_code; } @@ -88,7 +88,7 @@ class nala { * View the list of mirrors by using the fetch command. */ public static function fetch() { - exec(\neato::get_user_bin . 'nala fetch' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'nala fetch' . stdErr(), $output, $exit_code); display($output); return $exit_code; } @@ -97,7 +97,7 @@ class nala { * Delete the local cache files with the clean command. */ public static function clean() { - exec(\neato::get_user_bin . 'nala clean' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'nala clean' . stdErr(), $output, $exit_code); display($output); return $exit_code; } diff --git a/app/package_managers/pacman.php b/app/package_managers/pacman.php index 4f43f48..aab4203 100644 --- a/app/package_managers/pacman.php +++ b/app/package_managers/pacman.php @@ -5,30 +5,30 @@ namespace package_managers; class pacman { public static function is_installed(string $prog) { - exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); - exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); + exec(\neato::get_user_bin . 'dpkg -s ' . safeCmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); + exec(\neato::get_user_bin . 'dpkg -s ' . safeCmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); $version = str_replace('Version: ', '', $output[0]); return ($exit_code == 0) ? ['installed' => true, 'version' => $version] : ['installed' => false]; } public static function upgrade($prog) { - exec(\neato::get_user_bin . 'pacman upgrade -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'pacman upgrade -y ' . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to upgrade: {$prog}"); + checkForError($exit_code, "Unable to upgrade: {$prog}"); return $exit_code; } public static function install($prog) { - exec(\neato::get_user_bin . 'pacman -S ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'pacman -S ' . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to install: {$prog}"); + checkForError($exit_code, "Unable to install: {$prog}"); return $exit_code; } public static function uninstall($prog) { - exec(\neato::get_user_bin . 'pacman del -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'pacman del -y ' . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to uninstall: {$prog}"); + checkForError($exit_code, "Unable to uninstall: {$prog}"); return $exit_code; } @@ -36,20 +36,20 @@ class pacman { * @todo figure out this method */ public static function add_repo($repo) { - exec(\neato::get_user_bin . 'pacman update' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'pacman update' . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to add new repo: {$repo}"); + checkForError($exit_code, "Unable to add new repo: {$repo}"); return $exit_code; } public static function update() { - exec(\neato::get_user_bin . 'pacman update -y ' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'pacman update -y ' . stdErr(), $output, $exit_code); display($output); return $exit_code; } public static function full_update() { - exec(\neato::get_user_bin . 'pacman update -y && ' . \neato::get_user_bin . 'apk upgrade -y' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'pacman update -y && ' . \neato::get_user_bin . 'apk upgrade -y' . stdErr(), $output, $exit_code); display($output); return $exit_code; } diff --git a/app/package_managers/snap.php b/app/package_managers/snap.php index 3042860..76d53fa 100644 --- a/app/package_managers/snap.php +++ b/app/package_managers/snap.php @@ -5,8 +5,8 @@ namespace package_managers; class snap { public static function is_installed(string $prog) { - exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); - exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); + exec(\neato::get_user_bin . 'dpkg -s ' . safeCmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); + exec(\neato::get_user_bin . 'dpkg -s ' . safeCmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); $version = str_replace('Version: ', '', $output[0]); return ($exit_code == 0) ? ['installed' => true, 'version' => $version] : ['installed' => false]; } @@ -16,9 +16,9 @@ class snap { } public static function install(string $prog) { - exec(\neato::get_user_bin . 'snap install -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'snap install -y ' . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to install: {$prog}"); + checkForError($exit_code, "Unable to install: {$prog}"); return $exit_code; } @@ -27,9 +27,9 @@ class snap { } public static function uninstall(string $prog) { - exec(\neato::get_user_bin . 'snap remove -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'snap remove -y ' . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to uninstall: {$prog}"); + checkForError($exit_code, "Unable to uninstall: {$prog}"); return $exit_code; } @@ -41,7 +41,7 @@ class snap { } public static function update() { - exec(\neato::get_user_bin . 'snap refresh' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'snap refresh' . stdErr(), $output, $exit_code); display($output); return $exit_code; } @@ -56,7 +56,7 @@ class snap { } public static function list() { - exec(\neato::get_user_bin . 'snap list --upgradeable' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'snap list --upgradeable' . stdErr(), $output, $exit_code); display($output); return $exit_code; } @@ -65,7 +65,7 @@ class snap { * shows only the packages installed on the system. */ public static function installed() { - exec(\neato::get_user_bin . 'snap --installed' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'snap --installed' . stdErr(), $output, $exit_code); display($output); return $exit_code; } @@ -74,7 +74,7 @@ class snap { * View the list of mirrors by using the fetch command. */ public static function info() { - exec(\neato::get_user_bin . 'snap info --verbose' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'snap info --verbose' . stdErr(), $output, $exit_code); display($output); return $exit_code; } @@ -83,7 +83,7 @@ class snap { * Revert a Snap package to a previous version: */ public static function revert() { - exec(\neato::get_user_bin . 'snap revert' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'snap revert' . stdErr(), $output, $exit_code); display($output); return $exit_code; } diff --git a/app/package_managers/yum.php b/app/package_managers/yum.php index bd17e93..a7a4525 100644 --- a/app/package_managers/yum.php +++ b/app/package_managers/yum.php @@ -5,30 +5,30 @@ namespace package_managers; class yum { public static function is_installed(string $prog) { - exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); - exec(\neato::get_user_bin . 'dpkg -s ' . safe_cmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); + exec(\neato::get_user_bin . 'dpkg -s ' . safeCmd($prog) . ' | ' . \neato::get_bin . 'grep "install ok installed"', $out, $exit_code); + exec(\neato::get_user_bin . 'dpkg -s ' . safeCmd($prog) . ' | ' . \neato::get_bin . 'grep ^Version', $output, $code); $version = str_replace('Version: ', '', $output[0]); return ($exit_code == 0) ? ['installed' => true, 'version' => $version] : ['installed' => false]; } public static function upgrade($prog) { - exec(\neato::get_user_bin . 'yum upgrade -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'yum upgrade -y ' . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to upgrade: {$prog}"); + checkForError($exit_code, "Unable to upgrade: {$prog}"); return $exit_code; } public static function install($prog) { - exec(\neato::get_user_bin . 'yum add -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'yum add -y ' . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to install: {$prog}"); + checkForError($exit_code, "Unable to install: {$prog}"); return $exit_code; } public static function uninstall($prog) { - exec(\neato::get_user_bin . 'yum del -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'yum del -y ' . safeCmdQuotes($prog) . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to uninstall: {$prog}"); + checkForError($exit_code, "Unable to uninstall: {$prog}"); return $exit_code; } @@ -36,20 +36,20 @@ class yum { * @todo figure out this method */ public static function add_repo($repo) { - exec(\neato::get_user_bin . 'yum update' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'yum update' . stdErr(), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to add new repo: {$repo}"); + checkForError($exit_code, "Unable to add new repo: {$repo}"); return $exit_code; } public static function update() { - exec(\neato::get_user_bin . 'yum update -y ' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'yum update -y ' . stdErr(), $output, $exit_code); display($output); return $exit_code; } public static function full_update() { - exec(\neato::get_user_bin . 'yum update -y && ' . \neato::get_user_bin . 'apk upgrade -y' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'yum update -y && ' . \neato::get_user_bin . 'apk upgrade -y' . stdErr(), $output, $exit_code); display($output); return $exit_code; } diff --git a/app/traits/linux_core.php b/app/traits/linux_core.php index 375df21..2800480 100644 --- a/app/traits/linux_core.php +++ b/app/traits/linux_core.php @@ -8,8 +8,8 @@ trait linux_core { if (! file_exists($file)) { return true; } - exec(self::get_user_bin . 'chmod -s ' . safe_cmd($file), $output, $exit_code); - check_for_error($exit_code, "Unable to remove sticky bit with chmod: {$file}"); + exec(self::get_user_bin . 'chmod -s ' . safeCmd($file), $output, $exit_code); + checkForError($exit_code, "Unable to remove sticky bit with chmod: {$file}"); return $exit_code; } @@ -17,10 +17,10 @@ trait linux_core { if (!is_dir($dir)) { $exit_code = false; } else { - $perm = get_perms($kind); - exec(self::get_user_bin . 'find ' . safe_cmd($dir) . ' -type d -exec ' . self::get_bin . 'chmod ' . $perm . ' {} \;', $output, $exit_code); + $perm = getPerms($kind); + exec(self::get_user_bin . 'find ' . safeCmd($dir) . ' -type d -exec ' . self::get_bin . 'chmod ' . $perm . ' {} \;', $output, $exit_code); } - check_for_error($exit_code, "Unable to chmod folders in: {$dir}"); + checkForError($exit_code, "Unable to chmod folders in: {$dir}"); return $exit_code; } @@ -28,10 +28,10 @@ trait linux_core { if (!is_dir($dir)) { $exit_code = false; } else { - $perm = get_perms($kind); - exec(self::get_user_bin . 'find ' . safe_cmd($dir) . ' -type f -exec ' . self::get_bin . 'chmod ' . $perm . ' {} \;', $output, $exit_code); + $perm = getPerms($kind); + exec(self::get_user_bin . 'find ' . safeCmd($dir) . ' -type f -exec ' . self::get_bin . 'chmod ' . $perm . ' {} \;', $output, $exit_code); } - check_for_error($exit_code, "Unable to chmod files in: {$dir}"); + checkForError($exit_code, "Unable to chmod files in: {$dir}"); return $exit_code; } @@ -39,9 +39,9 @@ trait linux_core { if (!is_file($file)) { $exit_code = false; } else { - exec(self::get_user_bin . 'chattr +i ' . safe_cmd($file), $output, $exit_code); + exec(self::get_user_bin . 'chattr +i ' . safeCmd($file), $output, $exit_code); } - check_for_error($exit_code, "Unable to write protect: {$file}"); + checkForError($exit_code, "Unable to write protect: {$file}"); return $exit_code; } @@ -49,44 +49,44 @@ trait linux_core { if (!is_file($file)) { $exit_code = false; } else { - exec(self::get_user_bin . 'chattr -i ' . safe_cmd($file), $output, $exit_code); + exec(self::get_user_bin . 'chattr -i ' . safeCmd($file), $output, $exit_code); } - check_for_error($exit_code, "Unable to un-write protect: {$file}"); + checkForError($exit_code, "Unable to un-write protect: {$file}"); return $exit_code; } public static function groupadd(string $groupname, int $gid = 0) { $group_id = ($gid > 0) ? "-g {$gid} " : ""; - exec(self::get_super_user_bin . 'groupadd '. $group_id . safe_cmd($groupname), $output, $exit_code); + exec(self::get_super_user_bin . 'groupadd '. $group_id . safeCmd($groupname), $output, $exit_code); if ($exit_code === 0) { display(getTermColors("Added new group named: $groupname", ['color'=>'green'])); } - check_for_error($exit_code, "Unable to add new group: {$groupname}"); + checkForError($exit_code, "Unable to add new group: {$groupname}"); return $exit_code; } public static function userdel(string $username) { - exec(self::get_super_user_bin . 'userdel ' . safe_cmd($username), $output, $exit_code); + exec(self::get_super_user_bin . 'userdel ' . safeCmd($username), $output, $exit_code); if ($exit_code === 0) { display(getTermColors("Deleted user account named: $username", ['color'=>'green'])); } - check_for_error($exit_code, "Unable to delete user: {$username}"); + checkForError($exit_code, "Unable to delete user: {$username}"); return $exit_code; } public static function useradd(string $username, int $uid = 0, string $shell="/bin/bash", string $comment = "", string $groups="", string $homedir="") { $user_id = ($uid > 0) ? "-u {$uid} " : ""; - $dir = (empty($homedir)) ? " -m " : " -d " . safe_cmd($homedir); - exec(self::get_super_user_bin . 'useradd '. $user_id . '-s '. safe_cmd($shell) . $dir . ' -c '. safe_cmd($comment) .'-G'. safe_cmd($groups) . ' ' . safe_cmd($username), $output, $exit_code); + $dir = (empty($homedir)) ? " -m " : " -d " . safeCmd($homedir); + exec(self::get_super_user_bin . 'useradd '. $user_id . '-s '. safeCmd($shell) . $dir . ' -c '. safeCmd($comment) .'-G'. safeCmd($groups) . ' ' . safeCmd($username), $output, $exit_code); if ($exit_code === 0) { display(getTermColors("Added new user account named: $username", ['color'=>'green'])); } - check_for_error($exit_code, "Unable to add new user: {$username}"); + checkForError($exit_code, "Unable to add new user: {$username}"); return $exit_code; } public static function lock_status(string $username) { - exec(self::get_user_bin . 'passwd -S ' . safe_cmd($username) . " | awk '{print $2}'", $output, $exit_code); + exec(self::get_user_bin . 'passwd -S ' . safeCmd($username) . " | awk '{print $2}'", $output, $exit_code); $sw = $output[0] ?? ""; switch ($sw) { case "P": echo "Account is not locked"; break; @@ -94,34 +94,34 @@ trait linux_core { case "L": echo "Account is Locked"; break; default: echo "Account does not exist?!"; break; } - check_for_error($exit_code, "Unable to view account: {$username}"); + checkForError($exit_code, "Unable to view account: {$username}"); return $exit_code; } public static function passwd(string $username) { - exec(self::get_user_bin . 'passwd ' . safe_cmd($username), $output, $exit_code); - check_for_error($exit_code, "Unable to set user password: {$username}"); + exec(self::get_user_bin . 'passwd ' . safeCmd($username), $output, $exit_code); + checkForError($exit_code, "Unable to set user password: {$username}"); return $exit_code; } // Details about age of passwords public static function chage(string $username) { - exec(self::get_user_bin . 'chage -l ' . safe_cmd($username), $output, $exit_code); - check_for_error($exit_code, "Unable to view user password changes: {$username}"); + exec(self::get_user_bin . 'chage -l ' . safeCmd($username), $output, $exit_code); + checkForError($exit_code, "Unable to view user password changes: {$username}"); return $exit_code; } // yyyy-mm-dd public static function lock(string $username, string $expires_on="") { - $exp = (! empty($expires_on)) ? "--expiredate ". safe_cmd($expires_on) . " " : ""; - exec(self::get_super_user_bin . 'usermod -L '. $exp . safe_cmd($username), $output, $exit_code); - check_for_error($exit_code, "Unable to Lock user account: {$username}"); + $exp = (! empty($expires_on)) ? "--expiredate ". safeCmd($expires_on) . " " : ""; + exec(self::get_super_user_bin . 'usermod -L '. $exp . safeCmd($username), $output, $exit_code); + checkForError($exit_code, "Unable to Lock user account: {$username}"); return $exit_code; } public static function unlock(string $username, string $expires_on="") { - $exp = (! empty($expires_on)) ? "--expiredate ". safe_cmd($expires_on) . " " : "--expiredate '' "; - exec(self::get_super_user_bin . 'usermod -U ' . $exp . safe_cmd($username), $output, $exit_code); - check_for_error($exit_code, "Unable to Unlock user account: {$username}"); + $exp = (! empty($expires_on)) ? "--expiredate ". safeCmd($expires_on) . " " : "--expiredate '' "; + exec(self::get_super_user_bin . 'usermod -U ' . $exp . safeCmd($username), $output, $exit_code); + checkForError($exit_code, "Unable to Unlock user account: {$username}"); return $exit_code; } diff --git a/app/utils/apache.php b/app/utils/apache.php index c5d358c..1b3f9a9 100644 --- a/app/utils/apache.php +++ b/app/utils/apache.php @@ -5,58 +5,58 @@ namespace utils; class apache { public static function enable_site($site) { - exec(\neato::get_super_user_bin . 'a2ensite ' . safe_cmd_quotes($site), $output, $exit_code); - check_for_error($exit_code, "Apache Unable to enable site: {$site}"); + exec(\neato::get_super_user_bin . 'a2ensite ' . safeCmdQuotes($site), $output, $exit_code); + checkForError($exit_code, "Apache Unable to enable site: {$site}"); return $exit_code; } public static function disable_site($site) { - exec(\neato::get_super_user_bin . 'a2dissite ' . safe_cmd_quotes($site), $output, $exit_code); - check_for_error($exit_code, "Apache Unable to disable site: {$site}"); + exec(\neato::get_super_user_bin . 'a2dissite ' . safeCmdQuotes($site), $output, $exit_code); + checkForError($exit_code, "Apache Unable to disable site: {$site}"); return $exit_code; } public static function enable_module($name) { - exec(\neato::get_super_user_bin . 'a2enmod ' . safe_cmd_quotes($name), $output, $exit_code); - check_for_error($exit_code, "Apache Unable to enable module: {$name}"); + exec(\neato::get_super_user_bin . 'a2enmod ' . safeCmdQuotes($name), $output, $exit_code); + checkForError($exit_code, "Apache Unable to enable module: {$name}"); return $exit_code; } public static function disable_module($name) { - exec(\neato::get_super_user_bin . 'a2dismod ' . safe_cmd_quotes($name), $output, $exit_code); - check_for_error($exit_code, "Apache Unable to disable site: {$name}"); + exec(\neato::get_super_user_bin . 'a2dismod ' . safeCmdQuotes($name), $output, $exit_code); + checkForError($exit_code, "Apache Unable to disable site: {$name}"); return $exit_code; } public static function enable_config($name) { - exec(\neato::get_super_user_bin . 'a2enconf ' . safe_cmd_quotes($name), $output, $exit_code); - check_for_error($exit_code, "Apache Unable to enable config: {$name}"); + exec(\neato::get_super_user_bin . 'a2enconf ' . safeCmdQuotes($name), $output, $exit_code); + checkForError($exit_code, "Apache Unable to enable config: {$name}"); return $exit_code; } public static function disable_config($name) { - exec(\neato::get_super_user_bin . 'a2disconf ' . safe_cmd_quotes($name), $output, $exit_code); - check_for_error($exit_code, "Apache Unable to disable config: {$name}"); + exec(\neato::get_super_user_bin . 'a2disconf ' . safeCmdQuotes($name), $output, $exit_code); + checkForError($exit_code, "Apache Unable to disable config: {$name}"); return $exit_code; } public static function query_site($name) { - exec(\neato::get_super_user_bin . 'a2query -s ' . safe_cmd_quotes($name), $output, $exit_code); + exec(\neato::get_super_user_bin . 'a2query -s ' . safeCmdQuotes($name), $output, $exit_code); return $exit_code; } public static function query_module($name) { - exec(\neato::get_super_user_bin . 'a2query -m ' . safe_cmd_quotes($name), $output, $exit_code); + exec(\neato::get_super_user_bin . 'a2query -m ' . safeCmdQuotes($name), $output, $exit_code); return $exit_code; } public static function query_config($name) { - exec(\neato::get_super_user_bin . 'a2query -c ' . safe_cmd_quotes($name), $output, $exit_code); + exec(\neato::get_super_user_bin . 'a2query -c ' . safeCmdQuotes($name), $output, $exit_code); return $exit_code; } public static function ht_password($file, $user, $password, $secure = '') { - $utils = use_me("apache2-utils"); + $utils = useMe("apache2-utils"); if ($utils === false) { display("Unable to install apache2-utils"); @@ -67,8 +67,8 @@ class apache { if ($secure == 'bcrypt' || $secure == 'high') { $options .= ' -B'; } - exec(\neato::get_user_bin . 'htpasswd -b ' . $options . ' ' . safe_cmd($file, $user) . ' ' . safe_cmd($password), $output, $exit_code); - check_for_error($exit_code, "Unable to add htpasswd in: {$file}"); + exec(\neato::get_user_bin . 'htpasswd -b ' . $options . ' ' . safeCmd($file, $user) . ' ' . safeCmd($password), $output, $exit_code); + checkForError($exit_code, "Unable to add htpasswd in: {$file}"); return $exit_code; } diff --git a/app/utils/curl.php b/app/utils/curl.php index 90ac92a..dad8309 100644 --- a/app/utils/curl.php +++ b/app/utils/curl.php @@ -5,12 +5,12 @@ namespace utils; class curl { public static function save($site, $file) { - if (! is_string_found($site, '://')) { + if (! isStringFound($site, '://')) { $site = 'https://' . $site; } - exec(\neato::get_user_bin . 'curl ' . safe_cmd($site) . ' -o ' . safe_cmd($file), $output, $exit_code); - check_for_error($exit_code, "Unable to curl download from: {$site}"); + exec(\neato::get_user_bin . 'curl ' . safeCmd($site) . ' -o ' . safeCmd($file), $output, $exit_code); + checkForError($exit_code, "Unable to curl download from: {$site}"); return $exit_code; } diff --git a/app/utils/keygen.php b/app/utils/keygen.php index 41cbfcf..8f42cb4 100644 --- a/app/utils/keygen.php +++ b/app/utils/keygen.php @@ -5,23 +5,24 @@ namespace utils; class keygen { public static function ed25519(string $file, string $pwd = "", string $comment = "") { - exec(\neato::get_user_bin . 'ssh-keygen -t ed25519 -f ' . safe_cmd($file) . ' -N \'' . safe_cmd($pwd) . '\' -C \'' . safe_cmd($comment) . '\'', $output, $exit_code); + exec(\neato::get_user_bin . 'ssh-keygen -t ed25519 -f ' . safeCmd($file) . ' -N \'' . safeCmd($pwd) . '\' -C \'' . safeCmd($comment) . '\'', $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to run ssh-keygen command: {$file}"); + checkForError($exit_code, "Unable to run ssh-keygen command: {$file}"); return $exit_code; } public static function rsa($file, int $size = 4096, string $pwd = "", string $comment = "") { - exec(\neato::get_user_bin . 'ssh-keygen -t rsa -b '. safe_cmd($size) .' -f ' . safe_cmd($file) . ' -N \'' . safe_cmd($pwd) . '\' -C \'' . safe_cmd($comment) . '\'', $output, $exit_code); + $s_size = ($size> 1023 && $size < 9600) ? (string) $size : "4096"; + exec(\neato::get_user_bin . 'ssh-keygen -t rsa -b '. safeCmd($s_size) .' -f ' . safeCmd($file) . ' -N \'' . safeCmd($pwd) . '\' -C \'' . safeCmd($comment) . '\'', $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to run ssh-keygen command: {$file}"); + checkForError($exit_code, "Unable to run ssh-keygen command: {$file}"); return $exit_code; } public static function sign(string $host_ca_file, string $file, string $hostname, string $type="-h", string $fqdn = "", string $validfor = "+52w") { - exec(\neato::get_user_bin . 'ssh-keygen -s '. safe_cmd($host_ca_file).' -I '. safe_cmd($hostname).' '. safe_cmd($type).' -n '. safe_cmd($fqdn).' -V '. safe_cmd($validfor).' '. safe_cmd($file), $output, $exit_code); + exec(\neato::get_user_bin . 'ssh-keygen -s '. safeCmd($host_ca_file).' -I '. safeCmd($hostname).' '. safeCmd($type).' -n '. safeCmd($fqdn).' -V '. safeCmd($validfor).' '. safeCmd($file), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to run ssh-keygen command: {$file}"); + checkForError($exit_code, "Unable to run ssh-keygen command: {$file}"); return $exit_code; } diff --git a/app/utils/mysql.php b/app/utils/mysql.php index 573afea..8cad5e6 100644 --- a/app/utils/mysql.php +++ b/app/utils/mysql.php @@ -6,33 +6,33 @@ class mysql { public static function exec($db, $password, $sql, $user = "root") { $dsn = "-D {$db} -u {$user} -p{$password}"; - exec(\neato::get_user_bin . 'mysql '. safe_cmd_quotes($dsn) . ' -e ' . safe_cmd($sql), $output, $exit_code); + exec(\neato::get_user_bin . 'mysql '. safeCmdQuotes($dsn) . ' -e ' . safeCmd($sql), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to run MySQL command: {$sql}"); + checkForError($exit_code, "Unable to run MySQL command: {$sql}"); return $exit_code; } public static function import($db, $password, $file, $user = "root") { $dsn = "-D {$db} -u {$user} -p{$password}"; - exec(\neato::get_user_bin . 'mysql '. safe_cmd_quotes($dsn) . ' <' . safe_cmd($file), $output, $exit_code); + exec(\neato::get_user_bin . 'mysql '. safeCmdQuotes($dsn) . ' <' . safeCmd($file), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to Import MySQL file: {$file}"); + checkForError($exit_code, "Unable to Import MySQL file: {$file}"); return $exit_code; } public static function backup($db, $password, $file, $user = "root") { $what = ($db == 'all') ? '-A' : "-B {$db}"; $dsn = "{$what} -u {$user} -p{$password}"; - exec(\neato::get_user_bin . 'mysqldump '. safe_cmd_quotes($dsn) . ' | gzip > $(date +\%Y_\%m_\%d-\%T)'. safe_cmd($file) . '.sql.gz', $output, $exit_code); + exec(\neato::get_user_bin . 'mysqldump '. safeCmdQuotes($dsn) . ' | gzip > $(date +\%Y_\%m_\%d-\%T)'. safeCmd($file) . '.sql.gz', $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to Export MySQL file: {$file}"); + checkForError($exit_code, "Unable to Export MySQL file: {$file}"); return $exit_code; } public static function gunzip($file) { - exec(\neato::get_bin . 'gunzip ' . safe_cmd($file) . '.sql.gz', $output, $exit_code); + exec(\neato::get_bin . 'gunzip ' . safeCmd($file) . '.sql.gz', $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to unzip MySQL file: {$file}"); + checkForError($exit_code, "Unable to unzip MySQL file: {$file}"); return $exit_code; } diff --git a/app/utils/npm.php b/app/utils/npm.php index b4d46ce..495a31a 100644 --- a/app/utils/npm.php +++ b/app/utils/npm.php @@ -5,31 +5,31 @@ namespace utils; class npm { public static function install($program) { - exec(\neato::get_user_local_bin . 'npm install -g ' . safe_cmd($program), $output, $exit_code); + exec(\neato::get_user_local_bin . 'npm install -g ' . safeCmd($program), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to run npm install command: {$program}"); + checkForError($exit_code, "Unable to run npm install command: {$program}"); return $exit_code; } public static function uninstall($program) { - exec(\neato::get_user_local_bin . 'npm uninstall ' . safe_cmd($program), $output, $exit_code); + exec(\neato::get_user_local_bin . 'npm uninstall ' . safeCmd($program), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to run npm uninstall command: {$program}"); + checkForError($exit_code, "Unable to run npm uninstall command: {$program}"); return $exit_code; } public static function is_package_installed_globally($program, $display = false) { - exec(\neato::get_user_local_bin . 'npm list -g ' . safe_cmd($program), $output, $exit_code); + exec(\neato::get_user_local_bin . 'npm list -g ' . safeCmd($program), $output, $exit_code); if ($display === true) { - check_for_error($exit_code, "npm package not installed: {$program}"); + checkForError($exit_code, "npm package not installed: {$program}"); } return $exit_code; } public static function update($program) { - exec(\neato::get_user_local_bin . 'npm update -g ' . safe_cmd($program), $output, $exit_code); + exec(\neato::get_user_local_bin . 'npm update -g ' . safeCmd($program), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to run npm update command: {$program}"); + checkForError($exit_code, "Unable to run npm update command: {$program}"); return $exit_code; } diff --git a/app/utils/php.php b/app/utils/php.php index 86973c9..fd938bb 100644 --- a/app/utils/php.php +++ b/app/utils/php.php @@ -5,7 +5,7 @@ namespace utils; class php { private static function r_sapi($ver) { - if (is_string_found($ver, "-s ") && is_string_found($ver, "-v ")) { + if (isStringFound($ver, "-s ") && isStringFound($ver, "-v ")) { return $ver; } return match($ver) { @@ -18,14 +18,14 @@ class php { } public static function enable_module($name, $ver = false) { - exec(\neato::get_super_user_bin . 'phpenmod ' . self::r_sapi($ver) . safe_cmd_quotes($name), $output, $exit_code); - check_for_error($exit_code, "PHP Unable to enable module: {$name}"); + exec(\neato::get_super_user_bin . 'phpenmod ' . self::r_sapi($ver) . safeCmdQuotes($name), $output, $exit_code); + checkForError($exit_code, "PHP Unable to enable module: {$name}"); return $exit_code; } public static function disable_module($name, $ver = false) { - exec(\neato::get_super_user_bin . 'phpdismod ' . self::r_sapi($ver) . safe_cmd_quotes($name), $output, $exit_code); - check_for_error($exit_code, "PHP Unable to disable module: {$name}"); + exec(\neato::get_super_user_bin . 'phpdismod ' . self::r_sapi($ver) . safeCmdQuotes($name), $output, $exit_code); + checkForError($exit_code, "PHP Unable to disable module: {$name}"); return $exit_code; } @@ -45,9 +45,9 @@ class php { } $ver = "-v {$version} "; $module_name = "-m {$name}"; - exec(\neato::get_super_user_bin . 'phpquery ' . $ver . $api . safe_cmd_quotes($module_name), $output, $exit_code); + exec(\neato::get_super_user_bin . 'phpquery ' . $ver . $api . safeCmdQuotes($module_name), $output, $exit_code); if ($display === true) { - check_for_error($exit_code, "PHP module not enabled: {$name}"); + checkForError($exit_code, "PHP module not enabled: {$name}"); } return $exit_code; } diff --git a/app/utils/php_composer.php b/app/utils/php_composer.php index fd6b8b1..d2b1ce1 100644 --- a/app/utils/php_composer.php +++ b/app/utils/php_composer.php @@ -7,68 +7,68 @@ class php_composer { const composer_exe = "/usr/local/bin/composer"; public static function audit($dir) { - exec(self::composer_exe . " -d " . safe_cmd($dir) . " audit", $output, $exit_code); - check_for_error($exit_code, "PHP Composer audit error"); + exec(self::composer_exe . " -d " . safeCmd($dir) . " audit", $output, $exit_code); + checkForError($exit_code, "PHP Composer audit error"); return $exit_code; } public static function init($dir) { - exec(self::composer_exe . " -d " . safe_cmd($dir) . " init", $output, $exit_code); - check_for_error($exit_code, "PHP Composer init error"); + exec(self::composer_exe . " -d " . safeCmd($dir) . " init", $output, $exit_code); + checkForError($exit_code, "PHP Composer init error"); return $exit_code; } public static function install($dir) { - exec(self::composer_exe . " -d " . safe_cmd($dir) . " install", $output, $exit_code); - check_for_error($exit_code, "PHP Composer install error"); + exec(self::composer_exe . " -d " . safeCmd($dir) . " install", $output, $exit_code); + checkForError($exit_code, "PHP Composer install error"); return $exit_code; } public static function update($dir) { - exec(self::composer_exe . " -d " . safe_cmd($dir) . " update", $output, $exit_code); - check_for_error($exit_code, "PHP Composer update error"); + exec(self::composer_exe . " -d " . safeCmd($dir) . " update", $output, $exit_code); + checkForError($exit_code, "PHP Composer update error"); return $exit_code; } public static function require($dir, $vendor) { - exec(self::composer_exe . " -d " . safe_cmd($dir) . " require " . safe_cmd($vendor), $output, $exit_code); - check_for_error($exit_code, "PHP Composer require error"); + exec(self::composer_exe . " -d " . safeCmd($dir) . " require " . safeCmd($vendor), $output, $exit_code); + checkForError($exit_code, "PHP Composer require error"); return $exit_code; } public static function require_dev($dir, $vendor) { - exec(self::composer_exe . " -d " . safe_cmd($dir) . " require --dev " . safe_cmd($vendor), $output, $exit_code); - check_for_error($exit_code, "PHP Composer require error"); + exec(self::composer_exe . " -d " . safeCmd($dir) . " require --dev " . safeCmd($vendor), $output, $exit_code); + checkForError($exit_code, "PHP Composer require error"); return $exit_code; } public static function remove($dir, $vendor) { - exec(self::composer_exe . " -d " . safe_cmd($dir) . " remove " . safe_cmd($vendor), $output, $exit_code); - check_for_error($exit_code, "PHP Composer remove error"); + exec(self::composer_exe . " -d " . safeCmd($dir) . " remove " . safeCmd($vendor), $output, $exit_code); + checkForError($exit_code, "PHP Composer remove error"); return $exit_code; } public static function reinstall($dir, $vendor) { - exec(self::composer_exe . " -d " . safe_cmd($dir) . " reinstall " . safe_cmd($vendor), $output, $exit_code); - check_for_error($exit_code, "PHP Composer remove error"); + exec(self::composer_exe . " -d " . safeCmd($dir) . " reinstall " . safeCmd($vendor), $output, $exit_code); + checkForError($exit_code, "PHP Composer remove error"); return $exit_code; } public static function outdated($dir) { - exec(self::composer_exe . " -d " . safe_cmd($dir) . " outdated", $output, $exit_code); - check_for_error($exit_code, "PHP Composer self_update error"); + exec(self::composer_exe . " -d " . safeCmd($dir) . " outdated", $output, $exit_code); + checkForError($exit_code, "PHP Composer self_update error"); return $exit_code; } public static function validate($dir) { - exec(self::composer_exe . " -d " . safe_cmd($dir) . " validate", $output, $exit_code); - check_for_error($exit_code, "PHP Composer remove error"); + exec(self::composer_exe . " -d " . safeCmd($dir) . " validate", $output, $exit_code); + checkForError($exit_code, "PHP Composer remove error"); return $exit_code; } public static function self_update() { exec(self::composer_exe . " self-update", $output, $exit_code); - check_for_error($exit_code, "PHP Composer self_update error"); + checkForError($exit_code, "PHP Composer self_update error"); return $exit_code; } diff --git a/app/utils/sed.php b/app/utils/sed.php index 0992164..481943d 100644 --- a/app/utils/sed.php +++ b/app/utils/sed.php @@ -9,16 +9,16 @@ class sed { return false; } $find = str_replace('"', "'", $find); - $two = get_left($find, 2); - if ($two == '-$' || is_string_found($find, '=')) { - $find = get_right($find, strlen($find) - 2); + $two = getLeft($find, 2); + if ($two == '-$' || isStringFound($find, '=')) { + $find = getRight($find, strlen($find) - 2); $ds = ''; } else { $ds = '$'; } $replace = str_replace('"', "'", $replace); - exec(\neato::get_bin . 'sed -i "s@' . $ds . $find . '@' . $replace . '@g" ' . safe_cmd($file), $output, $exit_code); - check_for_error($exit_code, "sed: {$file} Unable to find/replace: {$find}"); + exec(\neato::get_bin . 'sed -i "s@' . $ds . $find . '@' . $replace . '@g" ' . safeCmd($file), $output, $exit_code); + checkForError($exit_code, "sed: {$file} Unable to find/replace: {$find}"); return $exit_code; } diff --git a/app/utils/ufw.php b/app/utils/ufw.php index 102eecb..57c553e 100644 --- a/app/utils/ufw.php +++ b/app/utils/ufw.php @@ -13,8 +13,8 @@ class ufw { default: return false; } - exec(\neato::get_super_user_bin . 'ufw ' . safe_cmd($action, $port), $output, $exit_code); - check_for_error($exit_code, "UFW Unable to {$action} for port: {$port}"); + exec(\neato::get_super_user_bin . 'ufw ' . safeCmd($action, $port), $output, $exit_code); + checkForError($exit_code, "UFW Unable to {$action} for port: {$port}"); return $exit_code; } diff --git a/app/utils/wget.php b/app/utils/wget.php index 190b43d..03bd9e5 100644 --- a/app/utils/wget.php +++ b/app/utils/wget.php @@ -5,9 +5,9 @@ namespace utils; class wget { public static function download($file, $site) { - exec(\neato::get_user_bin . 'wget -O ' . safe_cmd($file) . ' ' . safe_cmd($site), $output, $exit_code); + exec(\neato::get_user_bin . 'wget -O ' . safeCmd($file) . ' ' . safeCmd($site), $output, $exit_code); display($output); - check_for_error($exit_code, "Unable to run wget command: {$site}"); + checkForError($exit_code, "Unable to run wget command: {$site}"); return $exit_code; } diff --git a/deploy_files/deploy_example.php b/deploy_files/deploy_example.php index 2f0a758..817f2e0 100644 --- a/deploy_files/deploy_example.php +++ b/deploy_files/deploy_example.php @@ -34,9 +34,9 @@ $data = read_file($file); // Reads contents of a file //file_loop(Configure::get('preinstall')); -//do_command('apache::ht_password', 'my.htpasswd', 'johnny', $root_password); +//doCommand('apache::ht_password', 'my.htpasswd', 'johnny', $root_password); -$ret = do_command('is_installed', 'sed'); +$ret = doCommand('is_installed', 'sed'); if ($ret['installed'] === true) { if (version_compare($ret['version'], '4.2.1', '>=')) { echo 'sed - Already up to date'; diff --git a/deploy_files/deploy_mysql_ex1.php b/deploy_files/deploy_mysql_ex1.php index 172c5ba..8886a5e 100644 --- a/deploy_files/deploy_mysql_ex1.php +++ b/deploy_files/deploy_mysql_ex1.php @@ -14,9 +14,9 @@ configure::set('pre_actions', [ force_root(); -//do_command('service', 'mysql', 'stop'); +//doCommand('service', 'mysql', 'stop'); -file_loop(configure::get('pre_actions')); +fileLoop(configure::get('pre_actions')); $my_key = enc::make_key_file("/etc/neato_secrets/mysql_key"); @@ -35,8 +35,8 @@ if (!file_exists($cwd . "/my_vaults/mysql_secrets")) { //$o = Enc::decode_file($cwd . "/my_vaults/my_secrets", $my_key); //echo $o->root; -//do_command('service', 'mysql', 'start'); -$ret = do_command('service', 'mysql', 'status'); +//doCommand('service', 'mysql', 'start'); +$ret = doCommand('service', 'mysql', 'status'); if ($ret === 0) { echo "Status Running ;-)"; } else { diff --git a/deploy_files/deploy_mysql_ex2.php b/deploy_files/deploy_mysql_ex2.php index 0086316..ef7c5b8 100644 --- a/deploy_files/deploy_mysql_ex2.php +++ b/deploy_files/deploy_mysql_ex2.php @@ -3,7 +3,7 @@ configure::set('display', true); // Show Output configure::set('logfile', true); // Save to log folder configure::set('syslog', false); -//do_command('service', 'mysql', 'stop'); +//doCommand('service', 'mysql', 'stop'); force_root(); @@ -13,4 +13,4 @@ $my_key = read_file("/etc/neato_secrets/mysql_key"); $o = enc::decode_file($cwd . "/my_vaults/mysql_secrets", $my_key); echo $o->root; -//do_command('service', 'mysql', 'start'); +//doCommand('service', 'mysql', 'start'); diff --git a/deploy_files/deploy_podman.php b/deploy_files/deploy_podman.php index a7ffc12..3900180 100644 --- a/deploy_files/deploy_podman.php +++ b/deploy_files/deploy_podman.php @@ -11,14 +11,14 @@ configure::set('pre_actions', [ force_root(); -file_loop(configure::get('pre_actions')); +fileLoop(configure::get('pre_actions')); -$is_podman_installed = do_command('is_installed', "podman"); +$is_podman_installed = doCommand('is_installed', "podman"); if ($is_podman_installed['installed'] === false) { - do_command('install', "software-properties-common"); + doCommand('install', "software-properties-common"); //do_command("add_repo", "ppa:projectatomic/ppa"); - do_command('update'); - do_command('install', "podman"); + doCommand('update'); + doCommand('install', "podman"); } $policy = ' diff --git a/deploy_files/deploy_security_audit.php b/deploy_files/deploy_security_audit.php index 3faa96c..9fa135f 100644 --- a/deploy_files/deploy_security_audit.php +++ b/deploy_files/deploy_security_audit.php @@ -3,7 +3,7 @@ configure::set('display', true); configure::set('logfile', true); -$options = cgetopt(["updates"]); +$options = cGetOpt(["updates"]); $updates = $options['updates'] ?? "no"; configure::set('remove_users', [ @@ -16,18 +16,18 @@ force_root(); display(getTermColors("Deleteing unused user accounts", ['color'=>'blue'])); $remove_users = configure::get('remove_users'); foreach($remove_users as $del_user) { - do_command('userdel', $del_user); + doCommand('userdel', $del_user); } display(getTermColors("Removing old un-needed programs", ['color'=>'blue'])); -do_command('purge', "xinetd nis yp-tools tftpd atftpd tftpd-hpa telnetd rsh-server rsh-redone-server"); +doCommand('purge', "xinetd nis yp-tools tftpd atftpd tftpd-hpa telnetd rsh-server rsh-redone-server"); if ($updates === "yes") { display("Full updates and unattended-upgrades"); - do_command('full_update'); - do_command('install', "unattended-upgrades"); - do_command('systemctl', "unattended-upgrades", "start"); - do_command('systemctl', "unattended-upgrades", "enable"); + doCommand('full_update'); + doCommand('install', "unattended-upgrades"); + doCommand('systemctl', "unattended-upgrades", "start"); + doCommand('systemctl', "unattended-upgrades", "enable"); } display(getTermColors("List services", ['color'=>'blue'])); diff --git a/deploy_files/deploy_sshd.php b/deploy_files/deploy_sshd.php index e6542a3..9b8a1c3 100644 --- a/deploy_files/deploy_sshd.php +++ b/deploy_files/deploy_sshd.php @@ -1,6 +1,6 @@ getValue(); // any, IPv4, or IPv6 force_root(); -run_once(); +runOnce(); if ($rekey == "yes") { if (file_exists("/etc/ssh/ssh_host_rsa_key")) { @@ -45,8 +45,8 @@ if ($rekey == "yes") { cp("/etc/ssh/ssh_host_ed25519_key", "/etc/ssh/ssh_host_ed25519_key_backup"); rm("/etc/ssh/ssh_host_ed25519_key"); } - do_command('keygen::rsa', "/etc/ssh/ssh_host_rsa_key"); - do_command('keygen::ed25519', "/etc/ssh/ssh_host_ed25519_key"); + doCommand('keygen::rsa', "/etc/ssh/ssh_host_rsa_key"); + doCommand('keygen::ed25519', "/etc/ssh/ssh_host_ed25519_key"); } $sshd = "Protocol 2 diff --git a/deploy_files/deploy_test1.php b/deploy_files/deploy_test1.php index e9c2067..e001028 100644 --- a/deploy_files/deploy_test1.php +++ b/deploy_files/deploy_test1.php @@ -5,21 +5,21 @@ configure::set('syslog', false); force_root(); -do_command('apache::ht_password', '.htpasswd', 'johnny', 'shhhh'); +doCommand('apache::ht_password', '.htpasswd', 'johnny', 'shhhh'); -$status = do_command('php::query_module', 'gd', '8.2', 'apache2'); +$status = doCommand('php::query_module', 'gd', '8.2', 'apache2'); echo ($status == 0) ? 'PHP found module gd' : 'gd not found as module for PHP'; echo ".\r\n"; -$n = do_command('npm::is_package_installed_globally', 'gulp-cli'); +$n = doCommand('npm::is_package_installed_globally', 'gulp-cli'); echo ($n == 0) ? 'Found npm package Gulp-cli' : 'npm package gulp-cli not found'; echo ".\r\n"; -print_r(do_command('ufw::status')); +print_r(doCommand('ufw::status')); -$ok = use_me('wget'); +$ok = useMe('wget'); if ($ok !== false) { //do_command('wget::download', 'test.html', 'http://127.0.0.1/index.php'); } diff --git a/make-installer.sh b/make-installer.sh index c228dfb..dff3a9d 100755 --- a/make-installer.sh +++ b/make-installer.sh @@ -2,7 +2,7 @@ if [ "$EUID" -ne 0 ]; then /usr/bin/echo "Please run as root!" - exit + exit 1 fi pushd build || exit 2