PHP Deployment Scripts
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.
 
 
neatoDeploy/app/neato_init.php

101 lines
2.7 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 get_Windows_version() {
$os_info = php_uname();
// Regular expression pattern to extract version and build number
$pattern = '/Windows\sNT\s(\d+\.\d+).*build\s(\d+)/';
// Perform the regular expression match
preg_match($pattern, $os_info, $matches);
// Check if the match was successful
if ($matches && count($matches) >= 3) {
// Extracted version and build number
$version = $matches[1];
$build_number = $matches[2];
// Return as an array
return ['version' => $version, 'build' => $build_number];
} else {
// Return an empty array or handle the case when information is not found
return [];
}
}
function get_OS_information() {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
// Get Windows version information
$windows_version = get_Windows_version();
$build = $windows_version['build'] ?? false;
$version = $windows_version['version'] ?? false;
return ['name' => 'Windows', 'id' => 'win', 'build'=>$build, 'version_id'=>$version, 'id_like'=>'Windows'];
}
if (false == function_exists("shell_exec") || false == is_readable("/etc/os-release")) {
return null;
}
$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);
});
return array_combine($list_ids, $list_val);
}
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();
$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;