|
|
|
@ -4,23 +4,18 @@ function is_cli() { |
|
|
|
if (defined('STDIN')) { |
|
|
|
if (defined('STDIN')) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (php_sapi_name() === 'cli') { |
|
|
|
if (php_sapi_name() === 'cli') { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (array_key_exists('SHELL', $_ENV)) { |
|
|
|
if (array_key_exists('SHELL', $_ENV)) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (empty($_SERVER['REMOTE_ADDR']) and ! isset($_SERVER['HTTP_USER_AGENT']) and count($_SERVER['argv']) > 0) { |
|
|
|
if (empty($_SERVER['REMOTE_ADDR']) and ! isset($_SERVER['HTTP_USER_AGENT']) and count($_SERVER['argv']) > 0) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!array_key_exists('REQUEST_METHOD', $_SERVER)) { |
|
|
|
if (!array_key_exists('REQUEST_METHOD', $_SERVER)) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -29,40 +24,96 @@ if (is_cli() === false) { |
|
|
|
exit(1); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function OS_details() { |
|
|
|
|
|
|
|
$kernel_version = php_uname('r'); |
|
|
|
|
|
|
|
$system_architecture = php_uname('m'); |
|
|
|
|
|
|
|
return ['kernel'=>$kernel_version, 'architecture'=>$system_architecture]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function get_Windows_version() { |
|
|
|
function get_Windows_version() { |
|
|
|
$os_info = php_uname(); |
|
|
|
$os_info = php_uname(); |
|
|
|
|
|
|
|
|
|
|
|
// Regular expression pattern to extract version and build number |
|
|
|
|
|
|
|
$pattern = '/Windows\sNT\s(\d+\.\d+).*build\s(\d+)/'; |
|
|
|
$pattern = '/Windows\sNT\s(\d+\.\d+).*build\s(\d+)/'; |
|
|
|
|
|
|
|
|
|
|
|
// Perform the regular expression match |
|
|
|
|
|
|
|
preg_match($pattern, $os_info, $matches); |
|
|
|
preg_match($pattern, $os_info, $matches); |
|
|
|
|
|
|
|
|
|
|
|
// Check if the match was successful |
|
|
|
|
|
|
|
if ($matches && count($matches) >= 3) { |
|
|
|
if ($matches && count($matches) >= 3) { |
|
|
|
// Extracted version and build number |
|
|
|
|
|
|
|
$version = $matches[1]; |
|
|
|
$version = $matches[1]; |
|
|
|
$build_number = $matches[2]; |
|
|
|
$build_number = $matches[2]; |
|
|
|
|
|
|
|
|
|
|
|
// Return as an array |
|
|
|
|
|
|
|
return ['version' => $version, 'build' => $build_number]; |
|
|
|
return ['version' => $version, 'build' => $build_number]; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Return an empty array or handle the case when information is not found |
|
|
|
$windows_info = explode(" ", $os_info); |
|
|
|
return []; |
|
|
|
$windows_version = end($windows_info); |
|
|
|
|
|
|
|
return ['version' => $windows_version, 'build' => 'unknown']; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function get_based_on_distribution($distributionName) { |
|
|
|
|
|
|
|
$distributions = [ |
|
|
|
|
|
|
|
'ubuntu' => 'debian', |
|
|
|
|
|
|
|
'debian' => 'unknown', |
|
|
|
|
|
|
|
'fedora' => 'red hat', |
|
|
|
|
|
|
|
'centos' => 'red hat', |
|
|
|
|
|
|
|
'arch' => 'unknown', |
|
|
|
|
|
|
|
'opensuse' => 'suse', |
|
|
|
|
|
|
|
'gentoo' => 'unknown', |
|
|
|
|
|
|
|
'slackware' => 'unknown', |
|
|
|
|
|
|
|
'mageia' => 'mandriva', |
|
|
|
|
|
|
|
'manjaro' => 'arch', |
|
|
|
|
|
|
|
'alpine' => 'unknown', |
|
|
|
|
|
|
|
'mint' => 'ubuntu', |
|
|
|
|
|
|
|
'elementary' => 'ubuntu', |
|
|
|
|
|
|
|
'kali' => 'debian', |
|
|
|
|
|
|
|
'red hat enterprise linux' => 'red hat', |
|
|
|
|
|
|
|
'oracle linux' => 'red hat', |
|
|
|
|
|
|
|
'scientific linux' => 'red hat', |
|
|
|
|
|
|
|
'clear linux' => 'unknown', |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$distributionName = strtolower($distributionName); |
|
|
|
|
|
|
|
if (isset($distributions[$distributionName])) { |
|
|
|
|
|
|
|
return $distributions[$distributionName]; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return 'unknown'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function get_Linux_version() { |
|
|
|
|
|
|
|
$os_info = php_uname(); |
|
|
|
|
|
|
|
$pattern = '/^Linux (.+?)(?:\s+|\()([\d.]+)(?:\).*)?$/'; |
|
|
|
|
|
|
|
if (preg_match($pattern, $os_info, $matches)) { |
|
|
|
|
|
|
|
$distribution = $matches[1]; |
|
|
|
|
|
|
|
$version = $matches[2]; |
|
|
|
|
|
|
|
return ['name'=>$distribution,'version_codename'=>null,'version_id'=>$version, 'id_like'=>get_based_on_distribution($distribution),'id'=>strtolower($distribution),'linux'=>true]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (function_exists("exec")) { |
|
|
|
|
|
|
|
$codename = "unknown"; |
|
|
|
|
|
|
|
exec('lsb_release -sc', $output, $returnCode); |
|
|
|
|
|
|
|
if ($returnCode === 0 && !empty($output)) { |
|
|
|
|
|
|
|
$codename = trim($output[0]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
unset($output); |
|
|
|
|
|
|
|
$version = "unknown"; |
|
|
|
|
|
|
|
exec('lsb_release -rs', $output, $returnCode); |
|
|
|
|
|
|
|
if ($returnCode === 0 && !empty($output)) { |
|
|
|
|
|
|
|
$version = trim($output[0]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
unset($output); |
|
|
|
|
|
|
|
exec('lsb_release -si', $output, $return_code); |
|
|
|
|
|
|
|
if ($return_code === 0 && !empty($output)) { |
|
|
|
|
|
|
|
$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 null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function get_OS_information() { |
|
|
|
function get_OS_information() { |
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
|
|
|
// Get Windows version information |
|
|
|
|
|
|
|
$windows_version = get_Windows_version(); |
|
|
|
$windows_version = get_Windows_version(); |
|
|
|
$build = $windows_version['build'] ?? false; |
|
|
|
$build = $windows_version['build'] ?? false; |
|
|
|
$version = $windows_version['version'] ?? false; |
|
|
|
$version = $windows_version['version'] ?? false; |
|
|
|
return ['name' => 'Windows', 'id' => 'win', 'build'=>$build, 'version_id'=>$version, 'id_like'=>'Windows']; |
|
|
|
return ['name' => 'Windows', 'version_codename'=>$build, 'version_id'=>$version, 'id_like'=>"win"+$version,'id' => $build,'linux'=>false]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (false == function_exists("shell_exec") || false == is_readable("/etc/os-release")) { |
|
|
|
if (function_exists("shell_exec") === false|| is_readable("/etc/os-release") === false) { |
|
|
|
return null; |
|
|
|
return get_Linux_version(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$os = shell_exec('cat /etc/os-release'); |
|
|
|
$os = shell_exec('cat /etc/os-release'); |
|
|
|
@ -80,7 +131,9 @@ function get_OS_information() { |
|
|
|
$v = preg_replace('/=|"/', '', $v); |
|
|
|
$v = preg_replace('/=|"/', '', $v); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return array_combine($list_ids, $list_val); |
|
|
|
$a = array_combine($list_ids, $list_val); |
|
|
|
|
|
|
|
$a['linux'] = true; |
|
|
|
|
|
|
|
return $a; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function is_string_found(string $data, string $find): bool { |
|
|
|
function is_string_found(string $data, string $find): bool { |
|
|
|
@ -96,6 +149,11 @@ function get_right(string $str, int $length): string { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$os = get_OS_information(); |
|
|
|
$os = get_OS_information(); |
|
|
|
$osVer = (isset($os['version_id'])) ? $os['version_id'] : false; |
|
|
|
$details = OS_details(); |
|
|
|
$codeName = (isset($os['version_codename'])) ? $os['version_codename'] : false; |
|
|
|
$os['kernel'] = $details['kernel'] ?? false; |
|
|
|
$os_like = (isset($os['id_like'])) ? $os['id_like'] : false; |
|
|
|
$os['architecture'] = $details['architecture'] ?? false; |
|
|
|
|
|
|
|
$osVer = $os['version_id'] ?? false; |
|
|
|
|
|
|
|
$codeName = $os['version_codename'] ?? false; |
|
|
|
|
|
|
|
$os_like = $os['id_like'] ?? false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//var_dump($os); exit; |