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.
74 lines
1.8 KiB
74 lines
1.8 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 getOSInformation() {
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
|
return ['name' => 'Windows'];
|
|
}
|
|
|
|
if (false == function_exists("shell_exec") || false == is_readable("/etc/os-release")) {
|
|
return null;
|
|
}
|
|
|
|
$os = shell_exec('cat /etc/os-release');
|
|
$listIds = preg_match_all('/.*=/', $os, $matchListIds);
|
|
$listIds = $matchListIds[0];
|
|
|
|
$listVal = preg_match_all('/=.*/', $os, $matchListVal);
|
|
$listVal = $matchListVal[0];
|
|
|
|
array_walk($listIds, function(&$v, $k) {
|
|
$v = strtolower(str_replace('=', '', $v));
|
|
});
|
|
|
|
array_walk($listVal, function(&$v, $k) {
|
|
$v = preg_replace('/=|"/', '', $v);
|
|
});
|
|
|
|
return array_combine($listIds, $listVal);
|
|
}
|
|
|
|
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 = getOSInformation();
|
|
$osVer = (isset($os['version_id'])) ? $os['version_id'] : false;
|
|
$codeName = (isset($os['version_codename'])) ? $os['version_codename'] : false;
|
|
$os_like = (isset($os['id_like'])) ? $os['id_like'] : false;
|
|
|