commit 33899c38a4b3c17b4eedb6d2838944cb1fe8cf07 Author: Antonio de la Rosa Date: Thu Dec 11 21:37:45 2025 +0100 Added filers diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b23c332 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*~ +composer.lock +vendor/* +!vendor/phangoapp +settings/ diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..f1b63c6 --- /dev/null +++ b/composer.json @@ -0,0 +1,12 @@ + +{ + "repositories": [ + { + "type": "path", + "url": "./vendor/phangoapp/cuchuluphputils" + } + ], + "require": { + "phangoapp/cuchuluphputils": "dev-master" + } +} diff --git a/vendor/phangoapp/cuchuluphputils/composer.json b/vendor/phangoapp/cuchuluphputils/composer.json new file mode 100644 index 0000000..b767cc0 --- /dev/null +++ b/vendor/phangoapp/cuchuluphputils/composer.json @@ -0,0 +1,20 @@ +{ + "name": "phangoapp/cuchuluphputils", + "description": "A set of classes and methods for make shell operations in linux", + "require-dev": { + "phpunit/phpunit": "^12" + }, + "license": "GPL3", + "authors": [ + { + "name": "Antonio de la Rosa", + "email": "antonio.delarosa@cuchulu.com" + } + ], + "minimum-stability": "stable", + "autoload": { + "psr-4": { + "PhangoApp\\CuchuluPHPUtils\\": "src" + } + } +} diff --git a/vendor/phangoapp/cuchuluphputils/src/Linux.php b/vendor/phangoapp/cuchuluphputils/src/Linux.php new file mode 100644 index 0000000..d9c821b --- /dev/null +++ b/vendor/phangoapp/cuchuluphputils/src/Linux.php @@ -0,0 +1,327 @@ + array("pipe", "r"), // stdin + 1 => array("pipe", "w"), // stdout + 2 => array("pipe", "w") // stderr + ); + + $pipes=[]; + + $process=proc_open($final_command, $descriptorspec, $pipes); + + if(is_resource($process)) { + + while($s=fgets($pipes[1])) { + + echo $s; + + flush(); + } + + while($e=fgets($pipes[2])) { + + echo $e; + + flush(); + } + + } + + fclose($pipes[0]); + fclose($pipes[1]); + fclose($pipes[2]); + + $result=proc_close($process); + + if($result>0) { + + echo 'Error executing command '.$final_command."\n"; + + if($exit_if_error) { + + exit($result); + + } + else { + + return $result; + + } + + } + + + } + + static public function get_linux_distro() { + + $file_distro=__DIR__.'/../../../../settings/distro.php'; + + $dir_distro=__DIR__.'/../../../../settings/'; + + if(!is_file($file_distro)) { + + ob_start(); + + Linux::shell_command(['python3 -c "import distro;print(distro.id())"']); + + $distro=trim(ob_get_contents()); + + ob_end_clean(); + + $distro_data=" 0: + return Linux::shell_command(['sudo dnf install -y '.$package[$distro]]); + + } + else if($distro=='arch') { + + //sudo pacman -S --noconfirm + return Linux::shell_command(['sudo pacman -S --noconfirm '.$package[$distro]]); + + } + + } + + static public function patch_file($original_file, $patch_file) { + + $distro=Linux::get_linux_distro(); + + //if call("sudo patch {} < {}".format(original_file[linux_distro], patch_file[linux_distro]), shell=True) > 0: + + if(!isset($original_file[$distro])) { + + echo "Sorry, you don't have a patch for this distro\n\n"; + + exit(1); + + } + + Linux::shell_command(["sudo patch ${original_file[$distro]} < ${patch_file[$distro]}"]); + + } + + static public function systemd_service($action, $service) { + + $distro=Linux::get_linux_distro(); + + if(!isset($service[$distro])) { + + echo "Sorry, you don't have a service reload for this distro\n\n"; + + exit(1); + + } + + return Linux::shell_command(["sudo systemctl ${action} ".$service[$distro]]); + + } + + static public function exec($executable) { + + $distro=Linux::get_linux_distro(); + + if(!isset($executable[$distro])) { + + echo "Sorry, you don't have a exec for this distro\n\n"; + + exit(1); + + } + + return Linux::shell_command($executable[$distro]); + + } + + static public function sed($arr_sed) { + + $distro=Linux::get_linux_distro(); + + if(!isset($arr_sed[$distro])) { + + echo "Sorry, you don't have a sed str for this distro\n\n"; + + exit(1); + + } + + return Linux::shell_command(["sudo sed -i", "\"s/".$arr_sed[$distro][0]."/".$arr_sed[$distro][1]."/g\" ".$arr_sed[$distro][2]]); + + } + + + static public function json_log($message, $error=0, $status=0, $progress=0, $no_progress=0) { + + $log=["error" => $error, "status" => $status, "progress" => $progress, "no_progress" => $no_progress, "message" => $message]; + + echo json_encode($log)."\n"; + + } + + static public function check_domain_name($domain_name) { + + return preg_match("/^(a-z\d*)(\.(a-z\d*))*$/i", $domain_name); + + } + + /** + * Function used for generate a simple random password. Used RamdomLib from Ircmaxell + * + * @param string $length_pass A variable used for set the character's length the password. More length, password more secure + * + */ + + static public function generate_random_password($length_pass=32) + { + + $x=0; + $z=0; + + $abc=array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '*', '+', '!', '-', '_', '@', '#', '$'); + + $disorder_abc=[]; + + //Simple disorder using random_int + + while(count($abc)>0) { + + $c_abc=count($abc); + + $num_element_move=random_int(0, $c_abc-1); + + $disorder_abc[]=$abc[$num_element_move]; + + unset($abc[$num_element_move]); + + $abc=array_values($abc); + + } + + //Get randomly elements from the randomly generated array. + + $c=count($disorder_abc); + + $password_final=''; + + for($x=0;$x<$length_pass;$x++) { + + $num_element_pass=random_int(0, $c-1); + + $password_final.=$disorder_abc[$num_element_pass]; + + } + + //Add strange characters + + return $password_final; + + } + +} diff --git a/vendor/phangoapp/cuchuluphputils/tests/LinuxTest.php b/vendor/phangoapp/cuchuluphputils/tests/LinuxTest.php new file mode 100644 index 0000000..c386165 --- /dev/null +++ b/vendor/phangoapp/cuchuluphputils/tests/LinuxTest.php @@ -0,0 +1,21 @@ +assertEquals($distro, 'manjaro'); + + unlink('./settings/distro.php'); + + rmdir('./settings'); + + } + +}