Merge pull request #56 from GameServerPanel/copilot/upgrade-php-8-safe-gamemanager-addonsmanager

This commit is contained in:
Frank Harris 2026-04-20 07:49:34 -05:00 committed by GitHub
commit c1d7c27b35
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 141 additions and 63 deletions

View file

@ -59,6 +59,9 @@ function exec_ogp_module() {
{
$home_info = $db->getUserGameHome($user_id,$home_id);
$groups = $db->getUsersGroups($_SESSION['user_id']);
if (!is_array($groups)) {
$groups = [];
}
$query_groups .= " AND (";
foreach($groups as $group)
$query_groups .= "group_id=".$group['group_id']." OR ";
@ -86,6 +89,9 @@ function exec_ogp_module() {
$addon_id = (int)$_REQUEST['addon_id'];
$addons_rows = $db->resultQuery("SELECT url, path, post_script FROM OGP_DB_PREFIXaddons WHERE addon_id=".$addon_id.$query_groups);
if (!is_array($addons_rows)) {
$addons_rows = [];
}
if (!$addons_rows) {
print_failure(get_lang('invalid_addon'));
@ -105,6 +111,9 @@ function exec_ogp_module() {
$check_passed = FALSE;
$address_at_post = $ip.":".$port;
$ip_ports = $db->getHomeIpPorts($home_info['home_id']);
if (!is_array($ip_ports)) {
$ip_ports = [];
}
foreach($ip_ports as $ip_port);
{
$address_owned = $ip_port['ip'].":".$ip_port['port'];
@ -234,7 +243,7 @@ function exec_ogp_module() {
elseif( $addon_type != "" )
{
if (!in_array($addon_type, $addon_types)) {
if (!(is_array($addon_types) && in_array($addon_type, $addon_types))) {
print_failure(get_lang('invalid_addon_type'));
$view->refresh('?m=addonsmanager&p=user_addons&home_id='. $home_id .'&mod_id='. $mod_id .'&ip='. $ip .'&port='.$port);
@ -261,6 +270,9 @@ function exec_ogp_module() {
<select name="addon_id">
<?php
$addons = $db->resultQuery("SELECT addon_id, name FROM OGP_DB_PREFIXaddons WHERE addon_type='".$addon_type."' AND home_cfg_id=" . $home_cfg_id . $query_groups . " ORDER BY name ASC");
if (!is_array($addons)) {
$addons = [];
}
foreach($addons as $addon)
{
?>
@ -290,4 +302,4 @@ function exec_ogp_module() {
<?php
}
}
?>
?>

View file

@ -73,6 +73,9 @@ function exec_ogp_module() {
if (isset($_POST['addon_id']) && (int)$_POST['addon_id'] > 0 && isset($_POST['edit']))
{
$addons_rows = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXaddons WHERE addon_id=".(int)$_POST['addon_id']);
if (!is_array($addons_rows)) {
$addons_rows = [];
}
$addon_info = $addons_rows[0];
$name = isset($addon_info['name']) ? $addon_info['name'] : "";
$url = isset($addon_info['url']) ? $addon_info['url'] : "";
@ -135,6 +138,9 @@ function exec_ogp_module() {
<select name='home_cfg_id'>
<?php
$game_cfgs = $db->getGameCfgs();
if (!is_array($game_cfgs)) {
$game_cfgs = [];
}
echo "<option style='background:black;color:white;' value=''>".get_lang('linux_games')."</option>\n";
foreach ( $game_cfgs as $row )
@ -186,6 +192,9 @@ function exec_ogp_module() {
<option value="0"><?php print_lang('all_groups'); ?></option>
<?php
$groups = $db->getGroupList();
if (!is_array($groups)) {
$groups = [];
}
foreach($groups as $group)
{
$selected = (isset($group_id) AND $group['group_id'] == $group_id) ? 'selected=selected' : '';
@ -315,7 +324,7 @@ function exec_ogp_module() {
}
$home_cfg_id = !empty($_GET['home_cfg_id']) && (int)$_GET['home_cfg_id'] > 0 ? (int)$_GET['home_cfg_id'] : 0;
$addon_type = !empty($_GET['addon_type']) && in_array($_GET['addon_type'], $addon_types) ? $_GET['addon_type'] : "";
$addon_type = !empty($_GET['addon_type']) && is_array($addon_types) && in_array($_GET['addon_type'], $addon_types) ? $_GET['addon_type'] : "";
$group_id = isset($_GET['group_id']) && is_numeric($_GET['group_id']) ? (int)$_GET['group_id'] : 0;
if ( isset($_GET['show']) )
@ -339,6 +348,9 @@ function exec_ogp_module() {
$group_id = $group_id == '0' ? $group_id." OR group_id IS NULL" : $group_id;
$result = $db->resultQuery("SELECT DISTINCT addon_id, name, game_name, url, path, group_id FROM OGP_DB_PREFIXaddons NATURAL JOIN OGP_DB_PREFIXconfig_homes WHERE group_id=".$group_id);
}
if (isset($result) && !is_array($result)) {
$result = [];
}
?>
<table class="center">
<?php
@ -346,7 +358,7 @@ function exec_ogp_module() {
foreach($groups as $group)
$group_names[$group['group_id']] = $group['group_name'];
if (isset($result) and $result > 0)
if (isset($result) and is_array($result) and (is_array($result) ? count($result) : 0) > 0)
{
foreach($result as $row)
{
@ -376,4 +388,4 @@ function exec_ogp_module() {
</table>
<?php
}
?>
?>

View file

@ -26,13 +26,16 @@ $query_groups = "";
if($_SESSION['users_role'] != "admin")
{
$groups = $db->getUsersGroups($_SESSION['user_id']);
if (!is_array($groups)) {
$groups = [];
}
$query_groups .= " AND (";
foreach($groups as $group)
$query_groups .= "group_id=".$group['group_id']." OR ";
$query_groups .= "group_id=0 OR group_id IS NULL)";
}
$addons = $db->resultQuery("SELECT addon_id FROM OGP_DB_PREFIXaddons WHERE home_cfg_id=".$server_home['home_cfg_id'].$query_groups);
$addons_qty = count($addons);
$addons_qty = is_array($addons) ? count($addons) : 0;
if($addons and $addons_qty >= 1){
$module_buttons = array(
"<a class='monitorbutton' href='?m=addonsmanager&amp;p=user_addons&amp;home_id=".
@ -45,4 +48,4 @@ if($addons and $addons_qty >= 1){
}
else
$module_buttons = array();
?>
?>

View file

@ -38,6 +38,9 @@ function exec_ogp_module() {
{
$home_info = $db->getUserGameHome($user_id,$home_id);
$groups = $db->getUsersGroups($_SESSION['user_id']);
if (!is_array($groups)) {
$groups = [];
}
$query_groups .= " AND (";
foreach($groups as $group)
$query_groups .= "group_id=".$group['group_id']." OR ";
@ -54,7 +57,7 @@ function exec_ogp_module() {
"NATURAL JOIN OGP_DB_PREFIXconfig_homes ".
"WHERE addon_type='plugin' ".
"AND home_cfg_id=".$home_cfg_id.$query_groups);
$plugins_qty = count($plugins);
$plugins_qty = is_array($plugins) ? count($plugins) : 0;
if($plugins and $plugins_qty >= 1)
echo "<a href='?m=addonsmanager&amp;p=addons&amp;home_id=".$home_id.
"&amp;mod_id=".$mod_id."&amp;addon_type=plugin&amp;ip=".$ip.
@ -65,7 +68,7 @@ function exec_ogp_module() {
"NATURAL JOIN OGP_DB_PREFIXconfig_homes ".
"WHERE addon_type='mappack' ".
"AND home_cfg_id=".$home_cfg_id.$query_groups);
$mappacks_qty = count($mappacks);
$mappacks_qty = is_array($mappacks) ? count($mappacks) : 0;
if($mappacks and $mappacks_qty >= 1){
echo "</td><td>";
echo "<a href='?m=addonsmanager&amp;p=addons&amp;home_id=".$home_id.
@ -77,7 +80,7 @@ function exec_ogp_module() {
"NATURAL JOIN OGP_DB_PREFIXconfig_homes ".
"WHERE addon_type='config' ".
"AND home_cfg_id=".$home_cfg_id.$query_groups);
$configs_qty = count($configs);
$configs_qty = is_array($configs) ? count($configs) : 0;
if($configs and $configs_qty >= 1){
echo "</td><td>";
echo "<a href='?m=addonsmanager&amp;p=addons&amp;home_id=".$home_id.

View file

@ -264,12 +264,15 @@ function exec_operation( $action, $home_id, $mod_id, $ip, $port, $override = fal
return FALSE;
else
{
$firewall_settings = $db->getFirewallSettings($home_info['remote_server_id']);
if ($firewall_settings['status'] == "enable")
{
$ip_ports = $db->getHomeIpPorts($home_info['home_id']);
foreach ($ip_ports as $ip_port)
$firewall_settings = $db->getFirewallSettings($home_info['remote_server_id']);
if ($firewall_settings['status'] == "enable")
{
$ip_ports = $db->getHomeIpPorts($home_info['home_id']);
if (!is_array($ip_ports)) {
$ip_ports = [];
}
foreach ($ip_ports as $ip_port)
{
if ($server_xml->protocol == "gameq")
{
$query_port = get_query_port($server_xml, $ip_port['port']);
@ -298,9 +301,11 @@ function exec_operation( $action, $home_id, $mod_id, $ip, $port, $override = fal
// Do text replacements in cfg file
if( $server_xml->replace_texts )
{
foreach($home_info['mods'][$mod_id] as $key => $value)
{
$home_info[$key] = $value;
if (is_array($home_info['mods'][$mod_id])) {
foreach($home_info['mods'][$mod_id] as $key => $value)
{
$home_info[$key] = $value;
}
}
$server_home = $home_info;
if( isset($server_xml->lgsl_query_name) )
@ -362,9 +367,11 @@ function exec_operation( $action, $home_id, $mod_id, $ip, $port, $override = fal
// Do text replacements in cfg file
if( $server_xml->replace_texts )
{
foreach($home_info['mods'][$mod_id] as $key => $value)
{
$home_info[$key] = $value;
if (is_array($home_info['mods'][$mod_id])) {
foreach($home_info['mods'][$mod_id] as $key => $value)
{
$home_info[$key] = $value;
}
}
$server_home = $home_info;
if( isset($server_xml->lgsl_query_name) )
@ -417,12 +424,15 @@ function exec_operation( $action, $home_id, $mod_id, $ip, $port, $override = fal
return FALSE;
else
{
$firewall_settings = $db->getFirewallSettings($home_info['remote_server_id']);
if ($firewall_settings['status'] == "enable")
{
$ip_ports = $db->getHomeIpPorts($home_info['home_id']);
foreach ($ip_ports as $ip_port)
$firewall_settings = $db->getFirewallSettings($home_info['remote_server_id']);
if ($firewall_settings['status'] == "enable")
{
$ip_ports = $db->getHomeIpPorts($home_info['home_id']);
if (!is_array($ip_ports)) {
$ip_ports = [];
}
foreach ($ip_ports as $ip_port)
{
if ($server_xml->protocol == "gameq")
{
$query_port = get_query_port($server_xml, $ip_port['port']);
@ -453,19 +463,27 @@ function get_monitor_buttons($server_home, $server_xml)
{
global $db;
$buttons = array();
foreach($db->getInstalledModules() as $installed_module)
$installed_modules = $db->getInstalledModules();
if (!is_array($installed_modules)) {
$installed_modules = [];
}
foreach($installed_modules as $installed_module)
{
$buttons_file = "modules/$installed_module[folder]/monitor_buttons.php";
if(file_exists($buttons_file))
{
require($buttons_file);
$buttons = array_merge($buttons, $module_buttons);
if (is_array($module_buttons)) {
$buttons = array_merge($buttons, $module_buttons);
}
unset($module_buttons);
}
}
$buttons_html = "";
foreach($buttons as $button)
if (is_array($buttons)) {
foreach($buttons as $button)
$buttons_html .= $button."\n";
}
return $buttons_html;
}
?>

View file

@ -87,7 +87,7 @@ if (preg_match("/u/",$server_home['access_rights']))
{
$sync_name = $server_xml->game_key;
$sync_list = @file("modules/gamemanager/rsync.list", FILE_IGNORE_NEW_LINES);
if ( in_array($sync_name, $sync_list) OR ($master_server_home_id != FALSE and $master_server_home_id != $server_home['home_id']) )
if ( (is_array($sync_list) && in_array($sync_name, $sync_list)) OR ($master_server_home_id != FALSE and $master_server_home_id != $server_home['home_id']) )
{
$module_buttons[] = "<a class='monitorbutton' href='?m=gamemanager&amp;p=rsync_install&amp;home_id=".$server_home['home_id']."&amp;mod_id=".$server_home['mod_id']."&amp;update=update'>
<img src='" . check_theme_image("images/rsync.png") . "' title='". rsync_install ."'>
@ -117,4 +117,3 @@ if($_SESSION['users_role'] == "admin")
}
}
?>

View file

@ -79,14 +79,16 @@ if(isset($_POST['command']) and !is_array($_POST['command']))
$_POST['command'] = array( '0' => stripcslashes($_POST['command']) );
elseif(isset($_POST['base64_command']))
{
foreach($_POST['base64_command'] as $key => $command)
{
$_POST['command'][$key] = isset($_POST['input']) ? str_replace("%input%", $_POST['input'], base64_decode($command)) : base64_decode($command);
if (is_array($_POST['base64_command'])) {
foreach($_POST['base64_command'] as $key => $command)
{
$_POST['command'][$key] = isset($_POST['input']) ? str_replace("%input%", $_POST['input'], base64_decode($command)) : base64_decode($command);
}
}
}
$presets = $db->getRconPresets($home_info['home_cfg_id'],$home_info['mods'][$mod_id]['mod_cfg_id']);
if($presets > 0)
if(is_array($presets) && (is_array($presets) ? count($presets) : 0) > 0)
{
echo '<form action="" method="post">'.
get_lang("rcon_presets") . ':
@ -124,16 +126,22 @@ if($presets > 0)
if(isset($_POST['remote_send_rcon_command']))
{
$response = "";
foreach($_POST['command'] as $command)
{
$ret = send_command($command, $remote, $server_xml, $home_info, $home_id, $ip, $port );
if(!$ret)
if (is_array($_POST['command'])) {
foreach($_POST['command'] as $command)
{
$response = FALSE;
break;
$ret = send_command($command, $remote, $server_xml, $home_info, $home_id, $ip, $port );
if(!$ret)
{
$response = FALSE;
break;
}
else
$response .= $ret;
}
else
$response .= $ret;
}
else
{
$response = FALSE;
}
if($response)
{

View file

@ -106,7 +106,7 @@ function exec_ogp_module() {
<br>
<?php
$presets = $db->getRconPresets($home_cfg_id,$mod_cfg_id);
if($presets > 0)
if(is_array($presets) && (is_array($presets) ? count($presets) : 0) > 0)
{
echo "<h2>".get_lang("edit_presets")."</h2>";

View file

@ -40,9 +40,11 @@ function exec_ogp_module() {
else
$home_info = $db->getUserGameHome($user_id,$home_id);
foreach($home_info['mods'][$mod_id] as $key => $value)
{
$home_info[$key] = $value;
if (is_array($home_info['mods'][$mod_id])) {
foreach($home_info['mods'][$mod_id] as $key => $value)
{
$home_info[$key] = $value;
}
}
require_once('includes/lib_remote.php');

View file

@ -27,6 +27,9 @@ function do_progress($kbytes,$rsyncPath)
$mbytes = round($kbytes / 1024, 2);
$sizes = file("modules/gamemanager/sizes.list", FILE_IGNORE_NEW_LINES)or print_failure("Can't open sizes.list");
if (!is_array($sizes)) {
$sizes = [];
}
# Adds a backslash on each slash so it can be used as patern at preg_match
$rsyncPath = addcslashes($rsyncPath,"/");
@ -365,7 +368,7 @@ function exec_ogp_module() {
}
}
$master_server_home_id = $db->getMasterServer( $home_info['remote_server_id'], $home_info['home_cfg_id'] );
if ( in_array($rs_gname, $sync_list) )
if ( is_array($sync_list) && in_array($rs_gname, $sync_list) )
{
echo "<form action='?m=gamemanager&amp;p=rsync_install' method='post'>
<table class='center'>
@ -412,4 +415,3 @@ function exec_ogp_module() {
}
}
?>

View file

@ -67,23 +67,28 @@ function renderParam($param, $last_param, $param_access_enabled, $home_id)
// Get homes
$homes = $db->getHomesFor($dbTypeHomesStr, $_SESSION['user_id']);
if (!is_array($homes)) {
$homes = [];
}
// Move current home_id home_path to the front of the array so that it is selected by default if no other option has been selected.
$homes = customShift($homes, "home_id", $home_id);
$inputElementString = "<select $idString name='params[" . $param['key'] . "{DEPENDS:$paramType}]'" . $disabledString . ">";
foreach($homes as $home){
if($home["home_path"][strlen($home["home_path"])-1] != "/"){
$home["home_path"] = $home["home_path"] . "/";
if (is_array($homes)) {
foreach($homes as $home){
if($home["home_path"][strlen($home["home_path"])-1] != "/"){
$home["home_path"] = $home["home_path"] . "/";
}
if(stripos($paramValue, $home["home_path"]) !== false){
$selectedString = "selected='selected'";
$selectedHome = $home["home_path"];
}else{
$selectedString = "";
}
$inputElementString .= '<option value="' . $home["home_path"] . '" ' . $selectedString . '>' . $home["home_path"] . '</option>';
}
if(stripos($paramValue, $home["home_path"]) !== false){
$selectedString = "selected='selected'";
$selectedHome = $home["home_path"];
}else{
$selectedString = "";
}
$inputElementString .= '<option value="' . $home["home_path"] . '" ' . $selectedString . '>' . $home["home_path"] . '</option>';
}
$inputElementString .="</select>";
if($paramType == "other_game_server_path_additional"){
@ -207,6 +212,12 @@ $home_info = $db->getGameHomeWithoutMods($home_id);
}
return;
}
if (!is_array($server_homes)) {
$server_homes = [];
}
if (!is_array($show_games_type)) {
$show_games_type = [];
}
?>
<form action="home.php" style="float:right;">
<b><?php print_lang('search'); ?>:</b>
@ -378,7 +389,7 @@ echo "<table id='servermonitor' class='tablesorter' data-sortlist='[[0,0],[3,1]]
$groupusers = $db->getGroupUsersByHomeId($server_home['home_id']);
$groupsus = "";
if($groupusers)
if(is_array($groupusers))
{
foreach($groupusers as $groupu)
{
@ -391,7 +402,7 @@ echo "<table id='servermonitor' class='tablesorter' data-sortlist='[[0,0],[3,1]]
$owners = $db->getUsersByHomeId($server_home['home_id']);
$other_owners = "";
if($owners)
if(is_array($owners))
{
foreach($owners as $owner)
{

View file

@ -71,6 +71,9 @@ function exec_ogp_module()
$home_id = $home_info['home_id'];
$ip_info = $db->getHomeIpPorts($home_id);
if (!is_array($ip_info)) {
$ip_info = [];
}
foreach ( $ip_info as $ip_ports_row )
@ -259,4 +262,3 @@ function exec_ogp_module()
return;
}
?>

View file

@ -110,6 +110,9 @@ function exec_ogp_module() {
if ($firewall_settings['status'] == "enable")
{
$ip_ports = $db->getHomeIpPorts($home_id);
if (!is_array($ip_ports)) {
$ip_ports = [];
}
foreach ($ip_ports as $ip_port)
{
if ($server_xml->protocol == "gameq")
@ -142,6 +145,9 @@ function exec_ogp_module() {
if ($firewall_settings['status'] == "enable")
{
$ip_ports = $db->getHomeIpPorts($home_id);
if (!is_array($ip_ports)) {
$ip_ports = [];
}
foreach ($ip_ports as $ip_port)
{
if ($server_xml->protocol == "gameq")