From cb9f9299d77deb3ba33ee8d8ff031e2dc15b7f58 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 7 Dec 2023 14:41:47 -0500 Subject: [PATCH] npm --- app/neato_common.php | 4 ++-- app/neato_fns.php | 4 ++-- app/utils/npm.php | 8 ++++---- config_files/deploy_mysql_ex1.php | 14 ++++++++------ config_files/deploy_mysql_ex2.php | 14 ++++++++++++++ config_files/deploy_test1.php | 12 ++++++++---- 6 files changed, 38 insertions(+), 18 deletions(-) create mode 100644 config_files/deploy_mysql_ex2.php diff --git a/app/neato_common.php b/app/neato_common.php index b1c7b2d..94d45b1 100644 --- a/app/neato_common.php +++ b/app/neato_common.php @@ -91,9 +91,9 @@ function ln($source, $new_link) { return $exit_code; } -function make_dir($new_folder) { +function make_dir($new_folder, $perms=0775) { if (!is_dir($new_folder)) { - $exit_code = mkdir($new_folder, 0775, true); + $exit_code = mkdir($new_folder, $perms, true); check_for_error($exit_code, "Unable to mkdir: {$new_folder}"); return $exit_code; } else { diff --git a/app/neato_fns.php b/app/neato_fns.php index 6fcdf83..2c05719 100644 --- a/app/neato_fns.php +++ b/app/neato_fns.php @@ -48,9 +48,9 @@ function get_perms($kind): int { // return $kind; // } switch ($kind) { - case 'keydir': $perm = 700; + case 'keydir': $perm = 0700; break; - case 'dir': $perm = 775; + case 'dir': $perm = 0775; break; case 'web': case 'normal': diff --git a/app/utils/npm.php b/app/utils/npm.php index 34d8fc1..b4d46ce 100644 --- a/app/utils/npm.php +++ b/app/utils/npm.php @@ -5,21 +5,21 @@ namespace utils; class npm { public static function install($program) { - exec(\neato::get_user_bin . 'npm install -g ' . safe_cmd($program), $output, $exit_code); + exec(\neato::get_user_local_bin . 'npm install -g ' . safe_cmd($program), $output, $exit_code); display($output); check_for_error($exit_code, "Unable to run npm install command: {$program}"); return $exit_code; } public static function uninstall($program) { - exec(\neato::get_user_bin . 'npm uninstall ' . safe_cmd($program), $output, $exit_code); + exec(\neato::get_user_local_bin . 'npm uninstall ' . safe_cmd($program), $output, $exit_code); display($output); check_for_error($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_bin . 'npm list -g ' . safe_cmd($program), $output, $exit_code); + exec(\neato::get_user_local_bin . 'npm list -g ' . safe_cmd($program), $output, $exit_code); if ($display === true) { check_for_error($exit_code, "npm package not installed: {$program}"); } @@ -27,7 +27,7 @@ class npm { } public static function update($program) { - exec(\neato::get_user_bin . 'npm update -g ' . safe_cmd($program), $output, $exit_code); + exec(\neato::get_user_local_bin . 'npm update -g ' . safe_cmd($program), $output, $exit_code); display($output); check_for_error($exit_code, "Unable to run npm update command: {$program}"); return $exit_code; diff --git a/config_files/deploy_mysql_ex1.php b/config_files/deploy_mysql_ex1.php index f0df7f7..7d49d46 100644 --- a/config_files/deploy_mysql_ex1.php +++ b/config_files/deploy_mysql_ex1.php @@ -4,12 +4,10 @@ Configure::set('logfile', true); // Save to log folder Configure::set('syslog', false); Configure::set('passwords', ['length' => rand(16, 26)]); -$root_password = make_password(Configure::get('passwords', 'length')); - Configure::set('pre_actions', [ 'make_dir' => [$cwd . '/my_vaults'=>'', '/etc/neato_secrets'=>''], 'chmod_file_or_dir' => - [ $cwd . '/my_vaults' => 'secret', '/etc/neato_secrets' => 'secret' ], + [ $cwd . '/my_vaults' => 'keydir', '/etc/neato_secrets' => 'keydir' ], ]); //do_command('service', 'mysql', 'stop'); @@ -20,9 +18,13 @@ file_loop(Configure::get('pre_actions')); $my_key = Enc::make_key_file("/etc/neato_secrets/mysql_data"); -$obj = new stdClass(); -$obj->root = $root_password; -Enc::encode_file($cwd . "/my_vaults/my_secrets", $obj, $my_key); +if (!file_exists($cwd . "/my_vaults/my_secrets")) { + $root_password = make_password(Configure::get('passwords', 'length')); + $obj = new stdClass(); + $obj->root = $root_password; + Enc::encode_file($cwd . "/my_vaults/my_secrets", $obj, $my_key); +} + //$my_key = read_file("/etc/neato_secrets/mysql_data"); //$o = Enc::decode_file($cwd . "/my_vaults/my_secrets", $my_key); diff --git a/config_files/deploy_mysql_ex2.php b/config_files/deploy_mysql_ex2.php new file mode 100644 index 0000000..0ccea03 --- /dev/null +++ b/config_files/deploy_mysql_ex2.php @@ -0,0 +1,14 @@ +root; + +//do_command('service', 'mysql', 'start'); diff --git a/config_files/deploy_test1.php b/config_files/deploy_test1.php index 3d5d911..10b70f6 100644 --- a/config_files/deploy_test1.php +++ b/config_files/deploy_test1.php @@ -5,15 +5,19 @@ Configure::set('syslog', false); //do_command('apache::ht_password', 'my.htpasswd', 'johnny', 'shhhh'); -$status = do_command('php::query_module', 'gd', '8.0', 'apache2'); +$status = do_command('php::query_module', 'gd', '8.2', 'apache2'); echo ($status == 0) ? 'PHP found module gd' : 'gd not found as module for PHP'; -//$n = do_command('npm::is_package_installed_globally', 'gulp-cli'); -//echo ($n == 0) ? 'Found npm package Gulp-cli' : 'npm package gulp-cli not found'; +echo ".\r\n"; + +$n = do_command('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')); $ok = use_me('wget'); if ($ok !== false) { - do_command('wget::download', 'test.html', 'http://127.0.0.1/index.php'); + //do_command('wget::download', 'test.html', 'http://127.0.0.1/index.php'); }