2022-01-11 18:54:32 +00:00
|
|
|
<?php
|
2023-03-30 21:08:08 +00:00
|
|
|
|
2023-04-25 07:22:30 +00:00
|
|
|
$required_extentions = ['openssl', 'gd', 'mysql', 'PDO', 'mbstring', 'tokenizer', 'bcmath', 'xml', 'curl', 'zip', 'intl'];
|
2022-01-11 11:45:36 +00:00
|
|
|
|
2022-01-11 13:09:20 +00:00
|
|
|
$requirements = [
|
2023-01-11 15:44:44 +00:00
|
|
|
'minPhp' => '8.1',
|
2023-01-17 13:28:13 +00:00
|
|
|
'maxPhp' => '8.2', // This version is not supported
|
2023-01-05 17:01:42 +00:00
|
|
|
'mysql' => '5.7.22',
|
2022-01-11 13:09:20 +00:00
|
|
|
];
|
|
|
|
|
2023-04-25 07:22:30 +00:00
|
|
|
function checkPhpVersion()
|
2022-01-11 18:54:32 +00:00
|
|
|
{
|
|
|
|
global $requirements;
|
2023-01-11 15:44:44 +00:00
|
|
|
if (version_compare(phpversion(), $requirements['minPhp'], '>=') && version_compare(phpversion(), $requirements['maxPhp'], '<=')) {
|
2023-01-05 17:01:42 +00:00
|
|
|
return 'OK';
|
2022-01-11 18:54:32 +00:00
|
|
|
}
|
2023-01-05 17:01:42 +00:00
|
|
|
|
|
|
|
return 'not OK';
|
2022-01-11 11:45:36 +00:00
|
|
|
}
|
2023-04-25 07:22:30 +00:00
|
|
|
function checkWriteable()
|
2022-01-26 14:17:51 +00:00
|
|
|
{
|
2023-01-05 17:01:42 +00:00
|
|
|
return is_writable('../../.env');
|
2022-01-26 14:17:51 +00:00
|
|
|
}
|
2023-04-25 07:22:30 +00:00
|
|
|
function checkHTTPS()
|
2022-01-26 12:24:03 +00:00
|
|
|
{
|
2023-04-25 07:22:30 +00:00
|
|
|
return (! empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
|
|
|
|
|| $_SERVER['SERVER_PORT'] == 443;
|
2022-01-26 12:24:03 +00:00
|
|
|
}
|
|
|
|
|
2023-04-25 07:22:30 +00:00
|
|
|
function getMySQLVersion()
|
2022-01-11 18:54:32 +00:00
|
|
|
{
|
|
|
|
global $requirements;
|
2022-01-11 11:45:36 +00:00
|
|
|
|
2023-04-25 07:22:30 +00:00
|
|
|
$output = shell_exec('mysql -V');
|
2022-01-11 18:54:32 +00:00
|
|
|
preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version);
|
2022-01-11 11:45:36 +00:00
|
|
|
|
2023-01-05 17:01:42 +00:00
|
|
|
$versionoutput = $version[0] ?? '0';
|
2022-01-11 11:45:36 +00:00
|
|
|
|
2023-01-05 17:01:42 +00:00
|
|
|
return intval($versionoutput) > intval($requirements['mysql']) ? 'OK' : $versionoutput;
|
2022-01-11 13:09:20 +00:00
|
|
|
}
|
|
|
|
|
2023-04-25 07:22:30 +00:00
|
|
|
function getZipVersion()
|
2022-01-11 18:54:32 +00:00
|
|
|
{
|
2023-04-25 07:22:30 +00:00
|
|
|
$output = shell_exec('zip -v');
|
2022-01-11 18:54:32 +00:00
|
|
|
preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version);
|
2022-01-11 13:09:20 +00:00
|
|
|
|
2022-01-11 18:54:32 +00:00
|
|
|
$versionoutput = $version[0] ?? 0;
|
2022-01-11 13:09:20 +00:00
|
|
|
|
2023-01-05 17:01:42 +00:00
|
|
|
return $versionoutput != 0 ? 'OK' : 'not OK';
|
2022-01-11 13:09:20 +00:00
|
|
|
}
|
|
|
|
|
2023-04-25 07:22:30 +00:00
|
|
|
function getGitVersion()
|
2022-01-11 18:54:32 +00:00
|
|
|
{
|
2023-04-25 07:22:30 +00:00
|
|
|
$output = shell_exec('git --version');
|
2022-01-11 18:54:32 +00:00
|
|
|
preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version);
|
2022-01-11 13:09:20 +00:00
|
|
|
|
2022-01-11 18:54:32 +00:00
|
|
|
$versionoutput = $version[0] ?? 0;
|
2022-01-11 13:09:20 +00:00
|
|
|
|
2023-01-05 17:01:42 +00:00
|
|
|
return $versionoutput != 0 ? 'OK' : 'not OK';
|
2022-01-11 11:45:36 +00:00
|
|
|
}
|
|
|
|
|
2023-04-25 07:22:30 +00:00
|
|
|
function getTarVersion()
|
2022-01-11 18:54:32 +00:00
|
|
|
{
|
2023-04-25 07:22:30 +00:00
|
|
|
$output = shell_exec('tar --version');
|
2022-01-11 18:54:32 +00:00
|
|
|
preg_match('@[0-9]+\.[0-9]+@', $output, $version);
|
2022-01-11 13:09:20 +00:00
|
|
|
|
2022-01-11 18:54:32 +00:00
|
|
|
$versionoutput = $version[0] ?? 0;
|
2022-01-11 13:09:20 +00:00
|
|
|
|
2023-01-05 17:01:42 +00:00
|
|
|
return $versionoutput != 0 ? 'OK' : 'not OK';
|
2022-01-11 13:09:20 +00:00
|
|
|
}
|
2022-01-11 11:45:36 +00:00
|
|
|
|
2023-04-25 07:22:30 +00:00
|
|
|
function checkExtensions()
|
2022-01-11 18:54:32 +00:00
|
|
|
{
|
2023-04-25 07:22:30 +00:00
|
|
|
global $required_extentions;
|
2023-03-30 20:04:17 +00:00
|
|
|
|
2022-01-11 18:54:32 +00:00
|
|
|
$not_ok = [];
|
|
|
|
$extentions = get_loaded_extensions();
|
2022-01-11 11:45:36 +00:00
|
|
|
|
2023-04-25 07:22:30 +00:00
|
|
|
foreach ($required_extentions as $ext) {
|
|
|
|
if (! preg_grep('/^(?=.*'.$ext.').*$/', $extentions)) {
|
2022-01-11 18:54:32 +00:00
|
|
|
array_push($not_ok, $ext);
|
2023-01-05 17:01:42 +00:00
|
|
|
}
|
2022-01-11 18:54:32 +00:00
|
|
|
}
|
2023-01-05 17:01:42 +00:00
|
|
|
|
2022-01-11 18:54:32 +00:00
|
|
|
return $not_ok;
|
2022-01-11 11:45:36 +00:00
|
|
|
}
|
|
|
|
|
2023-04-25 07:22:30 +00:00
|
|
|
function setEnvironmentValue($envKey, $envValue)
|
2022-01-11 18:54:32 +00:00
|
|
|
{
|
2023-03-30 20:04:17 +00:00
|
|
|
$envFile = dirname(__FILE__, 3).'/.env';
|
|
|
|
$str = file_get_contents($envFile);
|
|
|
|
|
|
|
|
$str .= "\n"; // In case the searched variable is in the last line without \n
|
|
|
|
$keyPosition = strpos($str, "{$envKey}=");
|
|
|
|
$endOfLinePosition = strpos($str, PHP_EOL, $keyPosition);
|
|
|
|
$oldLine = substr($str, $keyPosition, $endOfLinePosition - $keyPosition);
|
|
|
|
$str = str_replace($oldLine, "{$envKey}={$envValue}", $str);
|
|
|
|
$str = substr($str, 0, -1);
|
|
|
|
|
|
|
|
$fp = fopen($envFile, 'w');
|
|
|
|
fwrite($fp, $str);
|
|
|
|
fclose($fp);
|
|
|
|
}
|
|
|
|
|
2023-04-25 07:22:30 +00:00
|
|
|
function getEnvironmentValue($envKey)
|
2023-03-29 22:30:19 +00:00
|
|
|
{
|
2023-04-25 07:22:30 +00:00
|
|
|
$envFile = dirname(__FILE__, 3).'/.env';
|
|
|
|
$str = file_get_contents($envFile);
|
2023-03-29 22:30:19 +00:00
|
|
|
|
2023-04-25 07:22:30 +00:00
|
|
|
$str .= "\n"; // In case the searched variable is in the last line without \n
|
|
|
|
$keyPosition = strpos($str, "{$envKey}=");
|
|
|
|
$endOfLinePosition = strpos($str, PHP_EOL, $keyPosition);
|
|
|
|
$oldLine = substr($str, $keyPosition, $endOfLinePosition - $keyPosition);
|
|
|
|
$value = substr($oldLine, strpos($oldLine, '=') + 1);
|
2022-01-20 08:26:46 +00:00
|
|
|
|
2023-04-25 07:22:30 +00:00
|
|
|
return $value;
|
2022-01-20 08:26:46 +00:00
|
|
|
}
|
|
|
|
|
2023-04-25 07:22:30 +00:00
|
|
|
function run_console($command)
|
2022-01-24 11:12:50 +00:00
|
|
|
{
|
|
|
|
$path = dirname(__FILE__, 3);
|
2023-04-25 07:22:30 +00:00
|
|
|
$cmd = "cd '$path' && bash -c 'exec -a ServerCPP $command' 2>&1";
|
2023-01-05 17:01:42 +00:00
|
|
|
|
2023-04-25 07:22:30 +00:00
|
|
|
return shell_exec($cmd);
|
2022-01-24 11:12:50 +00:00
|
|
|
}
|
2022-01-11 13:09:20 +00:00
|
|
|
|
2023-04-25 07:22:30 +00:00
|
|
|
function wh_log($log_msg)
|
2022-02-08 07:13:13 +00:00
|
|
|
{
|
2023-04-25 07:22:30 +00:00
|
|
|
$log_filename = 'logs';
|
|
|
|
if (! file_exists($log_filename)) {
|
|
|
|
// create directory/folder uploads.
|
|
|
|
mkdir($log_filename, 0777, true);
|
2022-02-08 07:13:13 +00:00
|
|
|
}
|
2023-04-25 07:22:30 +00:00
|
|
|
$log_file_data = $log_filename.'/installer.log';
|
|
|
|
// if you don't add `FILE_APPEND`, the file will be erased each time you add a log
|
|
|
|
file_put_contents($log_file_data, '['.date('h:i:s').'] '.$log_msg."\n", FILE_APPEND);
|
2022-02-08 07:13:13 +00:00
|
|
|
}
|
2022-06-07 15:30:38 +00:00
|
|
|
|
2023-04-25 07:22:30 +00:00
|
|
|
function generateRandomString($length = 8)
|
2023-01-05 17:01:42 +00:00
|
|
|
{
|
2022-06-07 15:30:38 +00:00
|
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
|
$charactersLength = strlen($characters);
|
|
|
|
$randomString = '';
|
|
|
|
for ($i = 0; $i < $length; $i++) {
|
|
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
|
|
}
|
2023-01-05 17:01:42 +00:00
|
|
|
|
2022-06-07 15:30:38 +00:00
|
|
|
return $randomString;
|
|
|
|
}
|