EngineGP/system/library/cron/privileges.php
Sergei Solovev 276ec7f3eb Updating the server name reference in code
This change replaces the use of $_SERVER['SERVER_NAME'] with $_SERVER['HTTP_HOST'] throughout the codebase. The modification ensures consistency and compliance with best practices, since $_SERVER['HTTP_HOST'] is often used to extract the host header from an HTTP request. This update may improve compatibility and security, especially in scenarios where the Host header plays a key role in proper server configuration and routing. Please review and test the changes carefully to ensure smooth functionality in different environments.
2023-12-23 04:50:14 +03:00

97 lines
3.4 KiB
PHP
Raw Permalink Blame History

<?php
if (!DEFINED('EGP'))
exit(header('Refresh: 0; URL=http://' . $_SERVER['HTTP_HOST'] . '/404'));
class privileges extends cron
{
function __construct()
{
global $sql, $argv, $start_point;
$servers = $argv;
unset($servers[0], $servers[1], $servers[2]);
$game = $servers[3];
if (!array_key_exists($game, cron::$admins_file))
return NULL;
$sql->query('SELECT `address` FROM `units` WHERE `id`="' . $servers[4] . '" LIMIT 1');
if (!$sql->num())
return '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: UNIT#' . $servers[4] . ' <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.';
$unit = $sql->get();
unset($servers[3], $servers[4]);
foreach ($servers as $i => $id) {
$sql->query('SELECT `id` FROM `privileges_buy` WHERE `server`="' . $id . '" AND `status`="1" LIMIT 1');
if (!$sql->num())
unset($servers[$i]);
}
if (!count($servers))
return NULL;
$sql->query('SELECT `unit` FROM `servers` WHERE `id`="' . end($servers) . '" LIMIT 1');
$server = $sql->get();
$sql->query('SELECT `address`, `passwd` FROM `units` WHERE `id`="' . $server['unit'] . '" LIMIT 1');
$unit = $sql->get();
include(LIB . 'ssh.php');
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ssh <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (!$ssh->auth($unit['passwd'], $unit['address']))
return '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: UNIT#' . $server['unit'] . ' <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>.';
$time = $start_point - 172800;
foreach ($servers as $id) {
$sql->query('DELETE FROM `privileges_buy` WHERE `date`<"' . $time . '" AND status`="0" LIMIT 5');
$aMail = array();
$sql->query('SELECT `uid`, `tarif` FROM `servers` WHERE `id`="' . $id . '" LIMIT 1');
$server = $sql->get();
$sql->query('SELECT `install` FROM `tarifs` WHERE `id`="' . $server['tarif'] . '" LIMIT 1');
$tarif = $sql->get();
$file = $tarif['install'] . $server['uid'] . '/' . cron::$admins_file[$game];
$text = $ssh->get('cat ' . $file);
$privileges = $sql->query('SELECT `id`, `text`, `sql`, `mail` FROM `privileges_buy` WHERE `server`="' . $id . '" AND `status`="1" LIMIT 3');
while ($privilege = $sql->get($privileges)) {
$text .= base64_decode($privilege['text']) . PHP_EOL;
$sql->query(base64_decode($privilege['sql']));
$sql->query('DELETE FROM `privileges_buy` WHERE `id`="' . $privilege['id'] . '" LIMIT 1');
$aMail[] = $privilege['mail'];
}
$temp = sys::temp($text);
$ssh->setfile($temp, $file, 0644);
unlink($temp);
$cmd = $game == 'cs' ? 'amx_reloadadmins' : 'sm_reloadadmins';
$ssh->set('chown server' . $server['uid'] . ':servers ' . $file);
$ssh->set("sudo -u server" . $server['uid'] . " screen -p 0 -S s_" . $server['uid'] . " -X eval 'stuff \"" . $cmd . "\"\015'");
foreach ($aMail as $mail)
sys::mail('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', sys::text('mail', 'success_privilege'), $mail);
echo 'server#' . $id . ' (' . $game . ') -> add privileges ' . PHP_EOL;
}
return NULL;
}
}
?>