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.
159 lines
5.0 KiB
159 lines
5.0 KiB
<?php
|
|
|
|
function is_cli() {
|
|
if (defined('STDIN')) {
|
|
return true;
|
|
}
|
|
if (php_sapi_name() === 'cli') {
|
|
return true;
|
|
}
|
|
if (array_key_exists('SHELL', $_ENV)) {
|
|
return true;
|
|
}
|
|
if (empty($_SERVER['REMOTE_ADDR']) and ! isset($_SERVER['HTTP_USER_AGENT']) and count($_SERVER['argv']) > 0) {
|
|
return true;
|
|
}
|
|
if (!array_key_exists('REQUEST_METHOD', $_SERVER)) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
if (is_cli() === false) {
|
|
echo('Unable to Start');
|
|
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() {
|
|
$os_info = php_uname();
|
|
$pattern = '/Windows\sNT\s(\d+\.\d+).*build\s(\d+)/';
|
|
preg_match($pattern, $os_info, $matches);
|
|
if ($matches && count($matches) >= 3) {
|
|
$version = $matches[1];
|
|
$build_number = $matches[2];
|
|
return ['version' => $version, 'build' => $build_number];
|
|
} else {
|
|
$windows_info = explode(" ", $os_info);
|
|
$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() {
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
|
$windows_version = get_Windows_version();
|
|
$build = $windows_version['build'] ?? false;
|
|
$version = $windows_version['version'] ?? 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) {
|
|
return get_Linux_version();
|
|
}
|
|
|
|
$os = shell_exec('cat /etc/os-release');
|
|
$list_ids = preg_match_all('/.*=/', $os, $match_list_ids);
|
|
$list_ids = $match_list_ids[0];
|
|
|
|
$list_val = preg_match_all('/=.*/', $os, $match_list_val);
|
|
$list_val = $match_list_val[0];
|
|
|
|
array_walk($list_ids, function(&$v, $k) {
|
|
$v = strtolower(str_replace('=', '', $v));
|
|
});
|
|
|
|
array_walk($list_val, function(&$v, $k) {
|
|
$v = preg_replace('/=|"/', '', $v);
|
|
});
|
|
|
|
$a = array_combine($list_ids, $list_val);
|
|
$a['linux'] = true;
|
|
return $a;
|
|
}
|
|
|
|
function is_string_found(string $data, string $find): bool {
|
|
return (stripos($data, $find) !== false);
|
|
}
|
|
|
|
function get_left(string $str, int $length): string {
|
|
return substr($str, 0, $length);
|
|
}
|
|
|
|
function get_right(string $str, int $length): string {
|
|
return substr($str, -$length);
|
|
}
|
|
|
|
$os = get_OS_information();
|
|
$details = OS_details();
|
|
$os['kernel'] = $details['kernel'] ?? 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;
|