|
|
|
@ -16,7 +16,7 @@ set_time_limit(0); |
|
|
|
require 'neato_registry.php'; |
|
|
|
require 'neato_registry.php'; |
|
|
|
require 'neato_auto_loader.php'; |
|
|
|
require 'neato_auto_loader.php'; |
|
|
|
require 'neato_init.php'; |
|
|
|
require 'neato_init.php'; |
|
|
|
include 'neato_colors.php'; |
|
|
|
require 'neato_colors.php'; |
|
|
|
require 'neato_configure.php'; |
|
|
|
require 'neato_configure.php'; |
|
|
|
require 'neato_logger.php'; |
|
|
|
require 'neato_logger.php'; |
|
|
|
require 'neato_fns.php'; |
|
|
|
require 'neato_fns.php'; |
|
|
|
@ -31,24 +31,44 @@ Neato_Registry::get('loader')->addNamespace('traits', 'traits'); |
|
|
|
Neato_Registry::get('loader')->addNamespace('package_managers', 'package_managers'); |
|
|
|
Neato_Registry::get('loader')->addNamespace('package_managers', 'package_managers'); |
|
|
|
Neato_Registry::get('loader')->addNamespace('init_systems', 'init_systems'); |
|
|
|
Neato_Registry::get('loader')->addNamespace('init_systems', 'init_systems'); |
|
|
|
|
|
|
|
|
|
|
|
function force_root(): void { |
|
|
|
/** |
|
|
|
|
|
|
|
* Force script to require being root to run |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return void not ah |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function forceRoot(): void |
|
|
|
|
|
|
|
{ |
|
|
|
if (posix_getuid() > 0) { |
|
|
|
if (posix_getuid() > 0) { |
|
|
|
echo 'Please run as root' . PHP_EOL; |
|
|
|
echo 'Please run as root' . PHP_EOL; |
|
|
|
exit(1); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function force_normal(): void { |
|
|
|
/** |
|
|
|
|
|
|
|
* Force script to require being a Regular user to run |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return void not ah |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function forceNormal(): void |
|
|
|
|
|
|
|
{ |
|
|
|
if (posix_getuid() === 0) { |
|
|
|
if (posix_getuid() === 0) { |
|
|
|
echo 'Please run as a normal user' . PHP_EOL; |
|
|
|
echo 'Please run as a normal user' . PHP_EOL; |
|
|
|
exit(1); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function shasum($file) { |
|
|
|
/** |
|
|
|
if(file_exists($file)) { |
|
|
|
* SHA Sum on a file. Make a hash on file. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param string $file filename to give a SHA256 hash on. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return string|false Hash Value of File |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function shaSum(string $file): string|false |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (file_exists($file)) { |
|
|
|
$hash = hash_file('sha256', $file, false); |
|
|
|
$hash = hash_file('sha256', $file, false); |
|
|
|
if($hash === false) { |
|
|
|
if ($hash === false) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
return (string) $hash; |
|
|
|
return (string) $hash; |
|
|
|
@ -56,7 +76,16 @@ function shasum($file) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function xor_encrypt($text, $key) { |
|
|
|
/** |
|
|
|
|
|
|
|
* XOR Encrypt/Decrypt, weak encoding... |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param string $text Message |
|
|
|
|
|
|
|
* @param string $key Password |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return string Results |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function xorEncrypt(string $text, string $key): string |
|
|
|
|
|
|
|
{ |
|
|
|
$result = ''; |
|
|
|
$result = ''; |
|
|
|
$textLength = strlen($text); |
|
|
|
$textLength = strlen($text); |
|
|
|
$keyLength = strlen($key); |
|
|
|
$keyLength = strlen($key); |
|
|
|
@ -66,7 +95,15 @@ function xor_encrypt($text, $key) { |
|
|
|
return $result; |
|
|
|
return $result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function read_file($file) { |
|
|
|
/** |
|
|
|
|
|
|
|
* Get the contents of a file. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param string $file file to open and read... |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return string|false Contents of the file are returned |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function readMyFile(string $file): string|false |
|
|
|
|
|
|
|
{ |
|
|
|
$ret = file_get_contents($file); |
|
|
|
$ret = file_get_contents($file); |
|
|
|
if ($ret === false) { |
|
|
|
if ($ret === false) { |
|
|
|
display("Unable to read from file: {$file}"); |
|
|
|
display("Unable to read from file: {$file}"); |
|
|
|
@ -74,45 +111,107 @@ function read_file($file) { |
|
|
|
return $ret; |
|
|
|
return $ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function write_file($file, $data) { |
|
|
|
/** |
|
|
|
|
|
|
|
* Write text to a new file. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param string $file Filename to save to |
|
|
|
|
|
|
|
* @param string $data What to put in the file. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return bool Success? |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function writeFile(string $file, string $data): bool |
|
|
|
|
|
|
|
{ |
|
|
|
$exit_code = file_put_contents($file, $data); |
|
|
|
$exit_code = file_put_contents($file, $data); |
|
|
|
$real = ($exit_code === false) ? false : true; |
|
|
|
$real = ($exit_code === false) ? false : true; |
|
|
|
checkForError($real, "Unable to save to file: {$file}"); |
|
|
|
checkForError($real, "Unable to save to file: {$file}"); |
|
|
|
return $real; |
|
|
|
return $real; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function append_to_file($file, $data) { |
|
|
|
/** |
|
|
|
|
|
|
|
* Append text to a existing file. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param string $file Filename to save to |
|
|
|
|
|
|
|
* @param string $data What to add to the file. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return bool Success? |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function appendToFile(string $file, string $data): bool |
|
|
|
|
|
|
|
{ |
|
|
|
$exit_code = file_put_contents($file, $data, FILE_APPEND | LOCK_EX); |
|
|
|
$exit_code = file_put_contents($file, $data, FILE_APPEND | LOCK_EX); |
|
|
|
$real = ($exit_code === false) ? false : true; |
|
|
|
$real = ($exit_code === false) ? false : true; |
|
|
|
checkForError($real, "Unable to save to file: {$file}"); |
|
|
|
checkForError($real, "Unable to save to file: {$file}"); |
|
|
|
return $real; |
|
|
|
return $real; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function rm($file) { |
|
|
|
/** |
|
|
|
|
|
|
|
* Remove/Delete file |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param string $file Filename to erase |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return bool Success? |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function rm(string $file): bool |
|
|
|
|
|
|
|
{ |
|
|
|
$exit_code = unlink($file); |
|
|
|
$exit_code = unlink($file); |
|
|
|
checkForError($exit_code, "Unable to Delete file: {$file}"); |
|
|
|
checkForError($exit_code, "Unable to Delete file: {$file}"); |
|
|
|
return $exit_code; |
|
|
|
return $exit_code; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function mv($old, $new) { |
|
|
|
/** |
|
|
|
|
|
|
|
* Renames a file or directory. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param string $old Existing file |
|
|
|
|
|
|
|
* @param string $new Rename it to this new filename |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return bool Success? |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function mv(string $old, string $new): bool |
|
|
|
|
|
|
|
{ |
|
|
|
$exit_code = rename($old, $new); |
|
|
|
$exit_code = rename($old, $new); |
|
|
|
checkForError($exit_code, "Unable to Move file: {$old} to {$new}"); |
|
|
|
checkForError($exit_code, "Unable to Move file: {$old} to {$new}"); |
|
|
|
return $exit_code; |
|
|
|
return $exit_code; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function cp($source, $dest) { |
|
|
|
/** |
|
|
|
|
|
|
|
* Copies a file |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param string $source Existing file |
|
|
|
|
|
|
|
* @param string $dest To make cloned file |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return bool Success? |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function cp(string $source, string $dest): bool |
|
|
|
|
|
|
|
{ |
|
|
|
$exit_code = copy($source, $dest); |
|
|
|
$exit_code = copy($source, $dest); |
|
|
|
checkForError($exit_code, "Unable to Copy file: {$source} to: {$dest}"); |
|
|
|
checkForError($exit_code, "Unable to Copy file: {$source} to: {$dest}"); |
|
|
|
return $exit_code; |
|
|
|
return $exit_code; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function ln($source, $new_link) { |
|
|
|
/** |
|
|
|
|
|
|
|
* Make a symbolic-Link |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param string $source Existing file |
|
|
|
|
|
|
|
* @param string $new_link Create new linked file |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return bool Success? |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function ln(string $source, string $new_link): bool |
|
|
|
|
|
|
|
{ |
|
|
|
$exit_code = symlink($source, $new_link); |
|
|
|
$exit_code = symlink($source, $new_link); |
|
|
|
checkForError($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; |
|
|
|
return $exit_code; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function make_dir($new_folder, $perms=0775) { |
|
|
|
/** |
|
|
|
|
|
|
|
* Make a new Directory |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param string $new_folder Create the new folder here |
|
|
|
|
|
|
|
* @param int $perms Set permissions |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return bool Success? |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function makeDir(string $new_folder, int $perms=0775): bool |
|
|
|
|
|
|
|
{ |
|
|
|
if (!is_dir($new_folder)) { |
|
|
|
if (!is_dir($new_folder)) { |
|
|
|
$exit_code = mkdir($new_folder, $perms, true); |
|
|
|
$exit_code = mkdir($new_folder, $perms, true); |
|
|
|
checkForError($exit_code, "Unable to mkdir: {$new_folder}"); |
|
|
|
checkForError($exit_code, "Unable to mkdir: {$new_folder}"); |
|
|
|
@ -122,7 +221,16 @@ function make_dir($new_folder, $perms=0775) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function chmod_file_or_dir($file, $kind) { |
|
|
|
/** |
|
|
|
|
|
|
|
* Chmod Change Permissions on File or Directory. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param string $file filename to change permissions on |
|
|
|
|
|
|
|
* @param string|int $kind Set new permissions |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return bool Success? |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function chmodFileOrDir(string $file, string|int $kind): bool |
|
|
|
|
|
|
|
{ |
|
|
|
if (!is_file($file) && !is_dir($file)) { |
|
|
|
if (!is_file($file) && !is_dir($file)) { |
|
|
|
$ret = false; |
|
|
|
$ret = false; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
@ -133,7 +241,17 @@ function chmod_file_or_dir($file, $kind) { |
|
|
|
return $ret; |
|
|
|
return $ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function change_owner($file, $uid, $gid) { |
|
|
|
/** |
|
|
|
|
|
|
|
* Change User-ownership and Group-ownership of a file |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param string $file Filename to change |
|
|
|
|
|
|
|
* @param string|int $uid New User ID |
|
|
|
|
|
|
|
* @param string|int $gid New Group ID |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return bool Success? |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function changeOwner(string $file, string|int $uid, string|int $gid): bool |
|
|
|
|
|
|
|
{ |
|
|
|
$ret_owner = chown($file, $uid); |
|
|
|
$ret_owner = chown($file, $uid); |
|
|
|
$ret_group = chgrp($file, $gid); |
|
|
|
$ret_group = chgrp($file, $gid); |
|
|
|
$exit_code = ($ret_owner && $ret_group) ? true : false; |
|
|
|
$exit_code = ($ret_owner && $ret_group) ? true : false; |
|
|
|
@ -141,13 +259,23 @@ function change_owner($file, $uid, $gid) { |
|
|
|
return $exit_code; |
|
|
|
return $exit_code; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function recursive_change_owner($mypath, $uid, $gid) { |
|
|
|
/** |
|
|
|
|
|
|
|
* Recursive change ownership on files |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param string $mypath Directory path |
|
|
|
|
|
|
|
* @param string|int $uid New User ID |
|
|
|
|
|
|
|
* @param string|int $gid New Group ID |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return void IDK |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function recursiveChangeOwner(string $mypath, string|int $uid, string|int $gid): void |
|
|
|
|
|
|
|
{ |
|
|
|
$d = opendir($mypath); |
|
|
|
$d = opendir($mypath); |
|
|
|
while (($file = readdir($d)) !== false) { |
|
|
|
while (($file = readdir($d)) !== false) { |
|
|
|
if ($file != "." && $file != "..") { |
|
|
|
if ($file != "." && $file != "..") { |
|
|
|
$typepath = $mypath . "/" . $file; |
|
|
|
$typepath = $mypath . "/" . $file; |
|
|
|
if (filetype($typepath) == 'dir') { |
|
|
|
if (filetype($typepath) == 'dir') { |
|
|
|
recursive_change_owner($typepath, $uid, $gid); |
|
|
|
recursiveChangeOwner($typepath, $uid, $gid); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
chown($typepath, $uid); |
|
|
|
chown($typepath, $uid); |
|
|
|
@ -156,7 +284,15 @@ function recursive_change_owner($mypath, $uid, $gid) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function make_password($length = 12) { |
|
|
|
/** |
|
|
|
|
|
|
|
* Make a random Password |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param int $length Give max length |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return string New Password Assigned |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function makePassword(int $length = 12): string |
|
|
|
|
|
|
|
{ |
|
|
|
$conso = array("b", "c", "d", "f", "g", "h", "j", "k", "l", |
|
|
|
$conso = array("b", "c", "d", "f", "g", "h", "j", "k", "l", |
|
|
|
"m", "n", "p", "r", "s", "t", "v", "w", "x", "y", "z"); |
|
|
|
"m", "n", "p", "r", "s", "t", "v", "w", "x", "y", "z"); |
|
|
|
$vocal = array("a", "e", "i", "o", "u"); |
|
|
|
$vocal = array("a", "e", "i", "o", "u"); |
|
|
|
@ -174,10 +310,9 @@ function make_password($length = 12) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
while ($length > 0) { |
|
|
|
while ($length > 0) { |
|
|
|
if ($length >= 1) { |
|
|
|
$password .= $conso[rand(0, 19)]; |
|
|
|
$password .= $conso[rand(0, 19)]; |
|
|
|
$length--; |
|
|
|
$length--; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if ($length >= 1) { |
|
|
|
if ($length >= 1) { |
|
|
|
$v = $vocal[rand(0, 4)]; |
|
|
|
$v = $vocal[rand(0, 4)]; |
|
|
|
$vp = ($v == 'o') ? $v : strtoupper($v); // A,E,I,o,U |
|
|
|
$vp = ($v == 'o') ? $v : strtoupper($v); // A,E,I,o,U |
|
|
|
|