From 56b100171c41f400eca1014a012022baedf82492 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 14 Dec 2023 17:31:55 -0500 Subject: [PATCH] old stuff --- app/OS/neato_Alpine.php | 10 ++----- app/OS/neato_Linux_Generic.php | 7 ++--- app/OS/neato_Ubuntu.php | 7 ++--- app/neato_logger.php | 2 +- app/package_managers/apt.php | 15 ++++++---- app/package_managers/apt_get.php | 15 ++++++---- app/package_managers/nala.php | 30 +++++++++++-------- app/traits/packages.php | 8 +++--- app/utils/apache.php | 7 +++++ app/utils/php.php | 19 +++++-------- app/utils/php_composer.php | 49 ++++++++++++++++++++++---------- config_files/deploy_test1.php | 4 +-- 12 files changed, 99 insertions(+), 74 deletions(-) diff --git a/app/OS/neato_Alpine.php b/app/OS/neato_Alpine.php index 78a647b..a023fb8 100644 --- a/app/OS/neato_Alpine.php +++ b/app/OS/neato_Alpine.php @@ -14,12 +14,6 @@ final class neato { const get_super_user_bin = '/usr/sbin/'; const get_user_local_bin = '/usr/local/bin/'; - protected function __construct() { - - } - - - -} + protected function __construct() { } -// end of neato installer commands +} \ No newline at end of file diff --git a/app/OS/neato_Linux_Generic.php b/app/OS/neato_Linux_Generic.php index b32bfb1..a19bdcf 100644 --- a/app/OS/neato_Linux_Generic.php +++ b/app/OS/neato_Linux_Generic.php @@ -8,13 +8,12 @@ final class neato { const get_opt = '/opt/'; const get_etc = '/etc/'; - const get_bin = '/bin/'; + const get_bin = '/bin/'; + const get_super_bin = '/sbin/'; const get_user_bin = '/usr/bin/'; const get_super_user_bin = '/usr/sbin/'; const get_user_local_bin = '/usr/local/bin/'; protected function __construct() { } -} - -// end of neato installer commands +} \ No newline at end of file diff --git a/app/OS/neato_Ubuntu.php b/app/OS/neato_Ubuntu.php index e0f02f0..037c2b4 100644 --- a/app/OS/neato_Ubuntu.php +++ b/app/OS/neato_Ubuntu.php @@ -8,13 +8,12 @@ final class neato { const get_opt = '/opt/'; const get_etc = '/etc/'; - const get_bin = '/bin/'; + const get_bin = '/bin/'; + const get_super_bin = '/sbin/'; const get_user_bin = '/usr/bin/'; const get_super_user_bin = '/usr/sbin/'; const get_user_local_bin = '/usr/local/bin/'; protected function __construct() { } -} - -// end of neato installer commands +} \ No newline at end of file diff --git a/app/neato_logger.php b/app/neato_logger.php index 218e6a7..14f3d23 100644 --- a/app/neato_logger.php +++ b/app/neato_logger.php @@ -15,7 +15,7 @@ class logger { 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); diff --git a/app/package_managers/apt.php b/app/package_managers/apt.php index 0e90ce3..b014744 100644 --- a/app/package_managers/apt.php +++ b/app/package_managers/apt.php @@ -12,27 +12,30 @@ class apt { } public static function upgrade(string $prog) { - exec(\neato::get_user_bin . 'apt upgrade -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'apt upgrade ' . $assume . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); display($output); check_for_error($exit_code, "Unable to upgrade: {$prog}"); return $exit_code; } - public static function install(string $prog) { - exec(\neato::get_user_bin . 'apt install -y ' . safe_cmd_quotes($prog) . stderr(), $output, $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); display($output); check_for_error($exit_code, "Unable to install: {$prog}"); return $exit_code; } - public static function purge(string $prog) { - exec(\neato::get_user_bin . 'apt --purge remove -y ' . safe_cmd_quotes($prog) . stderr(), $output, $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); display($output); check_for_error($exit_code, "Unable to uninstall: {$prog}"); return $exit_code; } - public static function uninstall(string $prog) { + 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); display($output); check_for_error($exit_code, "Unable to uninstall: {$prog}"); diff --git a/app/package_managers/apt_get.php b/app/package_managers/apt_get.php index 217354b..5b6c365 100644 --- a/app/package_managers/apt_get.php +++ b/app/package_managers/apt_get.php @@ -18,22 +18,25 @@ class apt_get { return $exit_code; } - public static function install(string $prog) { - exec(\neato::get_user_bin . 'apt-get install -y ' . safe_cmd_quotes($prog) . stderr(), $output, $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); display($output); check_for_error($exit_code, "Unable to install: {$prog}"); return $exit_code; } - public static function purge(string $prog) { - exec(\neato::get_user_bin . 'apt-get --purge remove -y ' . safe_cmd_quotes($prog) . stderr(), $output, $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); display($output); check_for_error($exit_code, "Unable to uninstall: {$prog}"); return $exit_code; } - public static function uninstall(string $prog) { - exec(\neato::get_user_bin . 'apt-get remove -y ' . safe_cmd_quotes($prog) . stderr(), $output, $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); display($output); check_for_error($exit_code, "Unable to uninstall: {$prog}"); return $exit_code; diff --git a/app/package_managers/nala.php b/app/package_managers/nala.php index 4e0f39a..425c9e6 100644 --- a/app/package_managers/nala.php +++ b/app/package_managers/nala.php @@ -7,33 +7,40 @@ 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); - $version = str_replace('Version: ', '', $output[0]); + $get_version = $output[0] ?? false; + if ($get_version === false) { + return ['installed' => false]; + } + $version = str_replace('Version: ', '', $get_version); return ($exit_code == 0) ? ['installed' => true, 'version' => $version] : ['installed' => false]; } public static function upgrade(string $prog) { - exec(\neato::get_user_bin . 'nala upgrade -y ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'nala upgrade ' . safe_cmd_quotes($prog) . stderr(), $output, $exit_code); display($output); check_for_error($exit_code, "Unable to upgrade: {$prog}"); return $exit_code; } - public static function install(string $prog) { - exec(\neato::get_user_bin . 'nala install -y ' . safe_cmd_quotes($prog) . stderr(), $output, $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); display($output); check_for_error($exit_code, "Unable to install: {$prog}"); return $exit_code; } - public static function purge(string $prog) { - exec(\neato::get_user_bin . 'nala purge -y ' . safe_cmd_quotes($prog) . stderr(), $output, $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); display($output); check_for_error($exit_code, "Unable to uninstall: {$prog}"); return $exit_code; } - public static function uninstall(string $prog) { - exec(\neato::get_user_bin . 'nala remove -y ' . safe_cmd_quotes($prog) . stderr(), $output, $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); display($output); check_for_error($exit_code, "Unable to uninstall: {$prog}"); return $exit_code; @@ -47,18 +54,17 @@ class nala { } public static function update() { - exec(\neato::get_user_bin . 'nala update -y ' . 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 -y && ' . \neato::get_user_bin . 'nala autoremove -y && ' . \neato::get_user_bin . 'nala clean -y' . 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; } - // Have a Backup!! public static function full_system_upgrade() { return false; } @@ -91,7 +97,7 @@ class nala { * Delete the local cache files with the clean command. */ public static function clean() { - exec(\neato::get_user_bin . 'nala fetch' . stderr(), $output, $exit_code); + exec(\neato::get_user_bin . 'nala clean' . stderr(), $output, $exit_code); display($output); return $exit_code; } diff --git a/app/traits/packages.php b/app/traits/packages.php index 50ed3ce..e655608 100644 --- a/app/traits/packages.php +++ b/app/traits/packages.php @@ -122,7 +122,7 @@ trait packages { return false; } $namespaced = "\\package_managers\\{$pkg}::add_repo"; - return $namespaced($prog); + return $namespaced($repo); } @@ -132,7 +132,7 @@ trait packages { return false; } $namespaced = "\\package_managers\\{$pkg}::update"; - return $namespaced($prog); + return $namespaced(); } @@ -142,7 +142,7 @@ trait packages { return false; } $namespaced = "\\package_managers\\{$pkg}::full_update"; - return $namespaced($prog); + return $namespaced(); } // Have a Backup!! @@ -152,7 +152,7 @@ trait packages { return false; } $namespaced = "\\package_managers\\{$pkg}::full_system_upgrade"; - return $namespaced($prog); + return $namespaced(); } diff --git a/app/utils/apache.php b/app/utils/apache.php index b1ebfa7..c5d358c 100644 --- a/app/utils/apache.php +++ b/app/utils/apache.php @@ -56,6 +56,13 @@ class apache { } public static function ht_password($file, $user, $password, $secure = '') { + $utils = use_me("apache2-utils"); + + if ($utils === false) { + display("Unable to install apache2-utils"); + return false; + } + $options = (!file_exists($file)) ? '-c' : ''; if ($secure == 'bcrypt' || $secure == 'high') { $options .= ' -B'; diff --git a/app/utils/php.php b/app/utils/php.php index 20f2e19..381d9d3 100644 --- a/app/utils/php.php +++ b/app/utils/php.php @@ -8,18 +8,13 @@ class php { if (is_string_found($ver, "-s ") && is_string_found($ver, "-v ")) { return $ver; } - switch ($ver) { - case "cli": - return "-s cli "; - case "fpm": - return "-s fpm "; - case "apache2": - return "-s apache2 "; - case false: - return ""; - default: - return "-v " . $ver . " "; - } + return match($ver) { + "cli"=>"-s cli ", + "fpm"=>"-s fpm ", + "apache2"=>"-s apache2 ", + false=>"", + default=>"-v " . $ver . " ", + }; } public static function enable_module($name, $ver = false) { diff --git a/app/utils/php_composer.php b/app/utils/php_composer.php index d6aeff4..b9e8ff6 100644 --- a/app/utils/php_composer.php +++ b/app/utils/php_composer.php @@ -5,45 +5,64 @@ namespace utils; 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"); + return $exit_code; + } public static function init($dir) { - chdir($dir); - exec(self::composer_exe . " init", $output, $exit_code); + exec(self::composer_exe . " -d " . safe_cmd($dir) . " init", $output, $exit_code); check_for_error($exit_code, "PHP Composer init error"); return $exit_code; } public static function install($dir) { - chdir($dir); - exec(self::composer_exe . " install", $output, $exit_code); - check_for_error($exit_code, "PHP Composer init error"); + exec(self::composer_exe . " -d " . safe_cmd($dir) . " install", $output, $exit_code); + check_for_error($exit_code, "PHP Composer install error"); return $exit_code; } public static function update($dir) { - chdir($dir); - exec(self::composer_exe . " update", $output, $exit_code); - check_for_error($exit_code, "PHP Composer init error"); + exec(self::composer_exe . " -d " . safe_cmd($dir) . " update", $output, $exit_code); + check_for_error($exit_code, "PHP Composer update error"); return $exit_code; } public static function require($dir, $vendor) { - chdir($dir); - exec(self::composer_exe . " require " . safe_cmd($vendor), $output, $exit_code); - check_for_error($exit_code, "PHP Composer init error"); + exec(self::composer_exe . " -d " . safe_cmd($dir) . " require " . safe_cmd($vendor), $output, $exit_code); + check_for_error($exit_code, "PHP Composer require error"); return $exit_code; } public static function remove($dir, $vendor) { - chdir($dir); - exec(self::composer_exe . " remove " . safe_cmd($vendor), $output, $exit_code); - check_for_error($exit_code, "PHP Composer init error"); + exec(self::composer_exe . " -d " . safe_cmd($dir) . " remove " . safe_cmd($vendor), $output, $exit_code); + check_for_error($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"); + 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"); + 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"); + return $exit_code; + } + public static function self_update() { exec(self::composer_exe . " self-update", $output, $exit_code); - check_for_error($exit_code, "PHP Composer init error"); + check_for_error($exit_code, "PHP Composer self_update error"); return $exit_code; } diff --git a/config_files/deploy_test1.php b/config_files/deploy_test1.php index baab6ed..e9c2067 100644 --- a/config_files/deploy_test1.php +++ b/config_files/deploy_test1.php @@ -3,10 +3,10 @@ configure::set('display', true); // Show Output configure::set('logfile', false); // Save to log folder configure::set('syslog', false); -//do_command('apache::ht_password', 'my.htpasswd', 'johnny', 'shhhh'); - force_root(); +do_command('apache::ht_password', '.htpasswd', 'johnny', 'shhhh'); + $status = do_command('php::query_module', 'gd', '8.2', 'apache2'); echo ($status == 0) ? 'PHP found module gd' : 'gd not found as module for PHP';