|
|
|
@ -1,6 +1,23 @@ |
|
|
|
<?php |
|
|
|
<?php |
|
|
|
|
|
|
|
/** |
|
|
|
function is_cli() { |
|
|
|
* Gets important OS data for the rest of the system. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* PHP version 8.3 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @category Util |
|
|
|
|
|
|
|
* @package Neato |
|
|
|
|
|
|
|
* @author Robert S. <tips@technowizardbob.com> |
|
|
|
|
|
|
|
* @license https://mit-license.org/ MIT License |
|
|
|
|
|
|
|
* @link https://git.mysnippetsofcode.com/tts/neatoDeploy |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Checks to make sure php is in CLI AKA the Command Line |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return bool true if in CLI |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function isCLI() |
|
|
|
|
|
|
|
{ |
|
|
|
if (defined('STDIN')) { |
|
|
|
if (defined('STDIN')) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -19,18 +36,30 @@ function is_cli() { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (is_cli() === false) { |
|
|
|
if (isCLI() === false) { |
|
|
|
echo('Unable to Start'); |
|
|
|
echo('Unable to Start'); |
|
|
|
exit(1); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function OS_details() { |
|
|
|
/** |
|
|
|
|
|
|
|
* Grabs the Kernel and System Architecture using PHP uname. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return array about version of Kernal and CPU Type. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function OS_details(): array |
|
|
|
|
|
|
|
{ |
|
|
|
$kernel_version = php_uname('r'); |
|
|
|
$kernel_version = php_uname('r'); |
|
|
|
$system_architecture = php_uname('m'); |
|
|
|
$system_architecture = php_uname('m'); |
|
|
|
return ['kernel'=>$kernel_version, 'architecture'=>$system_architecture]; |
|
|
|
return ['kernel'=>$kernel_version, 'architecture'=>$system_architecture]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function get_Windows_version() { |
|
|
|
/** |
|
|
|
|
|
|
|
* Grabs OS version and build. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return array Windows version and build number. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function getWindowsVersion(): array |
|
|
|
|
|
|
|
{ |
|
|
|
$os_info = php_uname(); |
|
|
|
$os_info = php_uname(); |
|
|
|
$pattern = '/Windows\sNT\s(\d+\.\d+).*build\s(\d+)/'; |
|
|
|
$pattern = '/Windows\sNT\s(\d+\.\d+).*build\s(\d+)/'; |
|
|
|
preg_match($pattern, $os_info, $matches); |
|
|
|
preg_match($pattern, $os_info, $matches); |
|
|
|
@ -45,7 +74,15 @@ function get_Windows_version() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function get_based_on_distribution($distributionName) { |
|
|
|
/** |
|
|
|
|
|
|
|
* Fetch base OS name |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param string $distributionName OS name |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return string what is it based off of...Debian as an example |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function getBasedOnDistribution(string $distributionName): string |
|
|
|
|
|
|
|
{ |
|
|
|
$distributions = [ |
|
|
|
$distributions = [ |
|
|
|
'ubuntu' => 'debian', |
|
|
|
'ubuntu' => 'debian', |
|
|
|
'debian' => 'unknown', |
|
|
|
'debian' => 'unknown', |
|
|
|
@ -74,13 +111,19 @@ function get_based_on_distribution($distributionName) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function get_Linux_version() { |
|
|
|
/** |
|
|
|
|
|
|
|
* Grabs a bunch of OS details like codename, name, etc... |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return null|array Linux OS details |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function getLinuxVersion(): ?array |
|
|
|
|
|
|
|
{ |
|
|
|
$os_info = php_uname(); |
|
|
|
$os_info = php_uname(); |
|
|
|
$pattern = '/^Linux (.+?)(?:\s+|\()([\d.]+)(?:\).*)?$/'; |
|
|
|
$pattern = '/^Linux (.+?)(?:\s+|\()([\d.]+)(?:\).*)?$/'; |
|
|
|
if (preg_match($pattern, $os_info, $matches)) { |
|
|
|
if (preg_match($pattern, $os_info, $matches)) { |
|
|
|
$distribution = $matches[1]; |
|
|
|
$distribution = $matches[1]; |
|
|
|
$version = $matches[2]; |
|
|
|
$version = $matches[2]; |
|
|
|
return ['name'=>$distribution,'version_codename'=>null,'version_id'=>$version, 'id_like'=>get_based_on_distribution($distribution),'id'=>strtolower($distribution),'linux'=>true]; |
|
|
|
return ['name'=>$distribution,'version_codename'=>null,'version_id'=>$version, 'id_like'=>getBasedOnDistribution($distribution),'id'=>strtolower($distribution),'linux'=>true]; |
|
|
|
} |
|
|
|
} |
|
|
|
if (function_exists("exec")) { |
|
|
|
if (function_exists("exec")) { |
|
|
|
$codename = "unknown"; |
|
|
|
$codename = "unknown"; |
|
|
|
@ -98,22 +141,28 @@ function get_Linux_version() { |
|
|
|
exec('lsb_release -si', $output, $return_code); |
|
|
|
exec('lsb_release -si', $output, $return_code); |
|
|
|
if ($return_code === 0 && !empty($output)) { |
|
|
|
if ($return_code === 0 && !empty($output)) { |
|
|
|
$distribution = trim($output[0]); |
|
|
|
$distribution = trim($output[0]); |
|
|
|
return ['name'=>$distribution, 'version_codename'=>$codename, 'version_id'=>$version, 'id_like'=>get_based_on_distribution($distribution),'id'=> strtolower($distribution),'linux'=>true]; |
|
|
|
return ['name'=>$distribution, 'version_codename'=>$codename, 'version_id'=>$version, 'id_like'=>getBasedOnDistribution($distribution),'id'=> strtolower($distribution),'linux'=>true]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function get_OS_information() { |
|
|
|
/** |
|
|
|
|
|
|
|
* Grab as much OS details and return as an array. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return null|array OS Details |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function getOSInformation(): ?array |
|
|
|
|
|
|
|
{ |
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
|
|
|
$windows_version = get_Windows_version(); |
|
|
|
$windows_version = getWindowsVersion(); |
|
|
|
$build = $windows_version['build'] ?? false; |
|
|
|
$build = $windows_version['build'] ?? false; |
|
|
|
$version = $windows_version['version'] ?? false; |
|
|
|
$version = $windows_version['version'] ?? false; |
|
|
|
return ['name' => 'Windows', 'version_codename'=>$build, 'version_id'=>$version, 'id_like'=>"win"+$version,'id' => $build,'linux'=>false]; |
|
|
|
return ['name' => 'Windows', 'version_codename'=>$build, 'version_id'=>$version, 'id_like'=>"win"+$version,'id' => $build,'linux'=>false]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (function_exists("shell_exec") === false|| is_readable("/etc/os-release") === false) { |
|
|
|
if (function_exists("shell_exec") === false|| is_readable("/etc/os-release") === false) { |
|
|
|
return get_Linux_version(); |
|
|
|
return getLinuxVersion(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$os = shell_exec('cat /etc/os-release'); |
|
|
|
$os = shell_exec('cat /etc/os-release'); |
|
|
|
@ -123,32 +172,63 @@ function get_OS_information() { |
|
|
|
$list_val = preg_match_all('/=.*/', $os, $match_list_val); |
|
|
|
$list_val = preg_match_all('/=.*/', $os, $match_list_val); |
|
|
|
$list_val = $match_list_val[0]; |
|
|
|
$list_val = $match_list_val[0]; |
|
|
|
|
|
|
|
|
|
|
|
array_walk($list_ids, function(&$v, $k) { |
|
|
|
array_walk( |
|
|
|
|
|
|
|
$list_ids, function (&$v, $k) { |
|
|
|
$v = strtolower(str_replace('=', '', $v)); |
|
|
|
$v = strtolower(str_replace('=', '', $v)); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
array_walk($list_val, function(&$v, $k) { |
|
|
|
array_walk( |
|
|
|
|
|
|
|
$list_val, function (&$v, $k) { |
|
|
|
$v = preg_replace('/=|"/', '', $v); |
|
|
|
$v = preg_replace('/=|"/', '', $v); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$a = array_combine($list_ids, $list_val); |
|
|
|
$a = array_combine($list_ids, $list_val); |
|
|
|
$a['linux'] = true; |
|
|
|
$a['linux'] = true; |
|
|
|
return $a; |
|
|
|
return $a; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function is_string_found(string $data, string $find): bool { |
|
|
|
/** |
|
|
|
|
|
|
|
* Like str_contains. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param string $data what to look at |
|
|
|
|
|
|
|
* @param string $find Search for this |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return bool was the string found |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function isStringFound(string $data, string $find): bool |
|
|
|
|
|
|
|
{ |
|
|
|
return (stripos($data, $find) !== false); |
|
|
|
return (stripos($data, $find) !== false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function get_left(string $str, int $length): string { |
|
|
|
/** |
|
|
|
|
|
|
|
* Get left most part of a string... |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param string $str input |
|
|
|
|
|
|
|
* @param int $length How much to get |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return string data from the left most to X length. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function getLeft(string $str, int $length): string |
|
|
|
|
|
|
|
{ |
|
|
|
return substr($str, 0, $length); |
|
|
|
return substr($str, 0, $length); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function get_right(string $str, int $length): string { |
|
|
|
/** |
|
|
|
|
|
|
|
* Get right most part of a string... |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param string $str input |
|
|
|
|
|
|
|
* @param int $length How much to get |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return string data from the left most to X length. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function getRight(string $str, int $length): string |
|
|
|
|
|
|
|
{ |
|
|
|
return substr($str, -$length); |
|
|
|
return substr($str, -$length); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$os = get_OS_information(); |
|
|
|
$os = getOSInformation(); |
|
|
|
$details = OS_details(); |
|
|
|
$details = OS_details(); |
|
|
|
$os['kernel'] = $details['kernel'] ?? false; |
|
|
|
$os['kernel'] = $details['kernel'] ?? false; |
|
|
|
$os['architecture'] = $details['architecture'] ?? false; |
|
|
|
$os['architecture'] = $details['architecture'] ?? false; |
|
|
|
|