You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
193 lines
5.3 KiB
193 lines
5.3 KiB
<?php
|
|
|
|
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');
|
|
|
|
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');
|
|
|
|
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;
|
|
check_for_error($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}");
|
|
return $real;
|
|
}
|
|
|
|
function rm($file) {
|
|
$exit_code = unlink($file);
|
|
check_for_error($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}");
|
|
return $exit_code;
|
|
}
|
|
|
|
function cp($source, $dest) {
|
|
$exit_code = copy($source, $dest);
|
|
check_for_error($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}");
|
|
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}");
|
|
return $exit_code;
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
function chmod_file_or_dir($file, $kind) {
|
|
if (!is_file($file) && !is_dir($file)) {
|
|
$ret = false;
|
|
} else {
|
|
$perms = get_perms($kind);
|
|
$ret = chmod($file, $perms);
|
|
}
|
|
check_for_error($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;
|
|
check_for_error($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((double) 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;
|
|
}
|
|
|