* @license https://mit-license.org/ MIT License * @link https://git.mysnippetsofcode.com/tts/neatoDeploy */ set_time_limit(0); require 'neato_registry.php'; require 'neato_auto_loader.php'; require 'neato_init.php'; include 'neato_colors.php'; require 'neato_configure.php'; require 'neato_logger.php'; require 'neato_fns.php'; require 'neato_enc.php'; Configure::set('logger_time_zone', 'America/Detroit'); 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) { echo 'Please run as root' . PHP_EOL; exit(1); } } function force_normal(): void { if (posix_getuid() === 0) { echo 'Please run as a normal user' . PHP_EOL; exit(1); } } function shasum($file) { if(file_exists($file)) { $hash = hash_file('sha256', $file, false); if($hash === false) { return false; } return (string) $hash; } return false; } function xor_encrypt($text, $key) { $result = ''; $textLength = strlen($text); $keyLength = strlen($key); for ($i = 0; $i < $textLength; $i++) { $result .= $text[$i] ^ $key[$i % $keyLength]; } return $result; } function read_file($file) { $ret = file_get_contents($file); if ($ret === false) { display("Unable to read from file: {$file}"); } return $ret; } function write_file($file, $data) { $exit_code = file_put_contents($file, $data); $real = ($exit_code === false) ? false : true; 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; checkForError($real, "Unable to save to file: {$file}"); return $real; } function rm($file) { $exit_code = unlink($file); checkForError($exit_code, "Unable to Delete file: {$file}"); return $exit_code; } function mv($old, $new) { $exit_code = rename($old, $new); checkForError($exit_code, "Unable to Move file: {$old} to {$new}"); return $exit_code; } function cp($source, $dest) { $exit_code = copy($source, $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); 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); checkForError($exit_code, "Unable to mkdir: {$new_folder}"); return $exit_code; } else { return true; } } function chmod_file_or_dir($file, $kind) { if (!is_file($file) && !is_dir($file)) { $ret = false; } else { $perms = getPerms($kind); $ret = chmod($file, $perms); } checkForError($ret, "Unable to chmod: {$file}"); return $ret; } function change_owner($file, $uid, $gid) { $ret_owner = chown($file, $uid); $ret_group = chgrp($file, $gid); $exit_code = ($ret_owner && $ret_group) ? true : false; checkForError($exit_code, "Unable to chown on: {$file}"); return $exit_code; } function recursive_change_owner($mypath, $uid, $gid) { $d = opendir($mypath); while (($file = readdir($d)) !== false) { if ($file != "." && $file != "..") { $typepath = $mypath . "/" . $file; if (filetype($typepath) == 'dir') { recursive_change_owner($typepath, $uid, $gid); } chown($typepath, $uid); chgrp($typepath, $gid); } } } function make_password($length = 12) { $conso = array("b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "v", "w", "x", "y", "z"); $vocal = array("a", "e", "i", "o", "u"); $special = array("!", "@", "#", "%", "&", "*", "."); $password = ""; $did_special_chr = false; $did_number = false; srand((int) microtime() * 1000000); if (rand(0, 100) > 50) { $password .= $special[rand(0, 6)]; $did_special_chr = true; $length--; } while ($length > 0) { if ($length >= 1) { $password .= $conso[rand(0, 19)]; $length--; } if ($length >= 1) { $v = $vocal[rand(0, 4)]; $vp = ($v == 'o') ? $v : strtoupper($v); // A,E,I,o,U $password .= $vp; if ($v == 'o') { // Make Extra, letter upper since, o is lower.... $password .= strtoupper($conso[rand(0, 19)]); $length --; } $length --; } if ($length >= 1) { if ($did_special_chr === false || ( $did_number === true && (rand(0, 100) > 50) )) { $password .= $special[rand(0, 6)]; $did_special_chr = true; } else { $password .= rand(0, 9); $did_number = true; } $length--; } } return $password; }