while ($row_unf = mysql_fetch_array($result_unf)) { $this_tpl = $row_unf['id']; $this_netid = $row_unf['netid']; $cur_status = $row_unf['status']; // Set orig id first run if ($cntr == 1) { $orig_netid = $this_netid; } // New net server or last in output; SSH into previous and run all tpl ids if ($orig_netid != $this_netid && $cntr >= 1) { // SSH into previous net server $tpl_list = substr($tpl_list, 0, -1); // Lose last comma $net_arr = $Network->netinfo($orig_netid); $net_cmd = "CheckTemplates -i \"{$tpl_list}\""; $cmd_out = $Network->runcmd($orig_netid, $net_arr, $net_cmd, true); // Decode JSON response $out_arr = json_decode($cmd_out, true); foreach ($out_arr as $this_tplid => $this_status) { if ($this_status != 'running' && $this_status != 'complete') { continue; } // Skip if bad syntax // Only if newer if ($cur_status != $this_status) { $updated = true; @mysql_query("UPDATE templates SET status = '{$this_status}' WHERE id = '{$this_tplid}'") or die('Failed to update template check!'); } } // Save new netid and tplid for later $orig_netid = $this_netid;
public function create_newdir($srvid, $dir_name) { if (empty($dir_name)) { return 'No directory name given!'; } // Get network ID $result_nid = @mysql_query("SELECT netid FROM servers WHERE id = '{$srvid}'"); $row_nid = mysql_fetch_row($result_nid); $this_netid = $row_nid[0]; if (empty($this_netid)) { return 'Failed to get network ID!'; } require DOCROOT . '/includes/classes/network.php'; $Network = new Network(); $netinfo = $Network->netinfo($this_netid); // Get real server info require DOCROOT . '/includes/classes/servers.php'; $Servers = new Servers(); $srvinfo = $Servers->getinfo($srvid); $net_game_ip = $netinfo['game_ip']; $net_local = $netinfo['is_local']; $net_gameuser = $srvinfo[0]['username']; $net_game_port = $srvinfo[0]['port']; // Add full path to dir if (isset($_SESSION['curdir'])) { $dir_name = $_SESSION['curdir'] . '/' . $dir_name; } // Get userdir if ($net_local) { $localdir = DOCROOT . '/_SERVERS/'; $game_dir = $localdir . '/accounts/' . $net_gameuser . '/' . $net_game_ip . '.' . $net_game_port . '/' . $dir_name; // Check existing if (file_exists($game_dir)) { die('Sorry, that directory already exists!'); } // Create directory if (!mkdir($game_dir)) { return 'Failed to create the directory (' . $game_dir . ')!'; } else { return 'success'; } } else { // Save File $run_cmd = "CreateDirectory -u {$net_gameuser} -i {$net_game_ip} -p {$net_game_port} -d \"{$dir_name}\""; // Run the command, return output return $Network->runcmd($this_netid, $netinfo, $run_cmd, true, $srvid); } }
public function delete($userid) { if (empty($userid)) { return 'No User ID given!'; } // Check if user even exists $result_uex = @mysql_query("SELECT username FROM users WHERE id = '{$userid}' LIMIT 1"); $row_uex = mysql_fetch_row($result_uex); $uex_username = $row_uex[0]; if (empty($uex_username)) { return 'That user account no longer exists!'; } // Not if they have servers $result_net = @mysql_query("SELECT netid FROM servers WHERE userid = '{$userid}' ORDER BY id DESC LIMIT 1"); $row_net = mysql_fetch_row($result_net); $latest_netid = $row_net[0]; if ($latest_netid) { return 'This user has server(s) on their account! Move the server(s) to another user or delete them and try again.'; } // Admins only if (isset($_SESSION['gpx_admin'])) { @mysql_query("UPDATE users SET deleted = '1' WHERE id = '{$userid}'") or die('Failed to delete the user'); } else { return 'You are not authorized to do this!'; } ############################################# // Delete SSO account $result_net = @mysql_query("SELECT id FROM network WHERE parentid = '0' AND is_local = '0' ORDER BY ip ASC"); require DOCROOT . '/includes/classes/network.php'; $Network = new Network(); while ($row_net = mysql_fetch_array($result_net)) { $netid = $row_net['id']; $net_arr = $Network->netinfo($netid); // Setup delete command $net_cmd = "DeleteUser -u '{$uex_username}'"; $delete_result = $Network->runcmd($netid, $net_arr, $net_cmd, true); // Account didn't exist...don't warn if ($delete_result == 'That user does not exist, exiting.') { return 'success'; } elseif ($delete_result != 'success') { return 'Failed to delete user on network server ' . $netid . ': ' . $delete_result; } } ############################################# return 'success'; }
public function delete($tplid) { if (empty($tplid)) { return 'Delete: No template ID provided!'; } // Get netid $result_nid = @mysql_query("SELECT netid FROM templates WHERE id = '{$tplid}' LIMIT 1"); $row_nid = mysql_fetch_row($result_nid); $netid = $row_nid[0]; // Delete from DB @mysql_query("DELETE FROM templates WHERE id = '{$tplid}'") or die('Failed to delete the template row!'); // Run network deletion require DOCROOT . '/includes/classes/network.php'; $Network = new Network(); $net_arr = $Network->netinfo($netid); $net_cmd = 'DeleteTemplate -i ' . $tplid; // Run command $cmd_out = $Network->runcmd($netid, $net_arr, $net_cmd, true); return $cmd_out; }
public function configupdate($srvid, $srv_info, $net_info) { if (empty($srvid)) { return 'No server ID given'; } elseif (empty($srv_info)) { return 'No server info array given'; } elseif (empty($_SESSION['gamesrv_root'])) { return 'No gameserver session found'; } elseif (empty($net_info)) { return 'No server network info array given'; } $config_file = $srv_info[0]['config_file']; // Save server config file with current server settings first if (!empty($config_file)) { // Some settings $orig_userid = $srv_info[0]['userid']; $orig_netid = $srv_info[0]['netid']; $orig_port = $srv_info[0]['port']; $orig_username = $srv_info[0]['username']; $orig_ip = $srv_info[0]['ip']; $orig_port = $srv_info[0]['port']; $orig_maxpl = $srv_info[0]['maxplayers']; $orig_map = $srv_info[0]['map']; $orig_hostname = $srv_info[0]['hostname']; $orig_rcon = $srv_info[0]['rcon']; $orig_sv_pass = $srv_info[0]['sv_password']; $orig_intname = $srv_info[0]['intname']; // Server values $config_sepa = $srv_info[0]['cfg_separator']; $cfg_ip = $srv_info[0]['cfg_ip']; $cfg_port = $srv_info[0]['cfg_port']; $cfg_map = $srv_info[0]['cfg_map']; $cfg_maxpl = $srv_info[0]['cfg_maxplayers']; $cfg_hostn = $srv_info[0]['cfg_hostname']; $cfg_rcon = $srv_info[0]['cfg_rcon']; $cfg_passw = $srv_info[0]['cfg_password']; $net_local = $net_info['is_local']; // Clients dont access port/maxplayers, so replace with current known ones if (!isset($_SESSION['gpx_admin'])) { $url_port = $orig_port; $url_maxpl = $orig_maxpl; } // Local Server if ($net_local) { $cfg_file = DOCROOT . '/_SERVERS/' . $_SESSION['gamesrv_root'] . '/' . stripslashes($config_file); if (GPXDEBUG) { echo 'DEBUG: Opening config file for reading: ' . $cfg_file . '<br>'; } $fh = fopen($cfg_file, 'r'); $file_lines = fread($fh, 4096); fclose($fh); if (GPXDEBUG) { echo 'DEBUG: Config lines: ' . $file_lines . '<br>'; } // Lose excess newlines $file_lines = preg_replace("/\n+/", "\n", $file_lines); $arr_lines = explode("\n", $file_lines); $new_file = ''; foreach ($arr_lines as $file_lines) { // XML Configs (such as Multi-Theft Auto/MTA). Set "Config Separator" to "X" (caps matters) in default games to make it work with XML. if ($config_sepa == 'X') { if (!empty($cfg_ip)) { $file_lines = preg_replace("/<{$cfg_ip}>.*/", "<{$cfg_ip}>{$orig_ip}</{$cfg_ip}>", $file_lines); } if (!empty($cfg_port)) { $file_lines = preg_replace("/<{$cfg_port}>.*/", "<{$cfg_port}>{$orig_port}</{$cfg_port}>", $file_lines); } if (!empty($cfg_map)) { $file_lines = preg_replace("/<{$cfg_map}>.*/", "<{$cfg_map}>{$orig_map}</{$cfg_map}>", $file_lines); } if (!empty($cfg_maxpl)) { $file_lines = preg_replace("/<{$cfg_maxpl}>.*/", "<{$cfg_maxpl}>{$orig_maxpl}</{$cfg_maxpl}>", $file_lines); } if (!empty($cfg_hostn)) { $file_lines = preg_replace("/<{$cfg_hostn}>.*/", "<{$cfg_hostn}>{$orig_hostname}</{$cfg_hostn}>", $file_lines); } if (!empty($cfg_rcon)) { $file_lines = preg_replace("/<{$cfg_rcon}>.*/", "<{$cfg_rcon}>{$orig_rcon}</{$cfg_rcon}>", $file_lines); } if (!empty($cfg_passw)) { $file_lines = preg_replace("/<{$cfg_passw}>.*/", "<{$cfg_passw}>{$orig_sv_pass}</{$cfg_passw}>", $file_lines); } } else { // Setup all changes if (!empty($cfg_ip)) { $file_lines = preg_replace("/^{$cfg_ip}.*/", $cfg_ip . $config_sepa . $orig_ip, $file_lines); } if (!empty($cfg_port)) { $file_lines = preg_replace("/^{$cfg_port}.*/", $cfg_port . $config_sepa . $orig_port, $file_lines); } if (!empty($cfg_map)) { $file_lines = preg_replace("/^{$cfg_map}.*/", $cfg_map . $config_sepa . $orig_map, $file_lines); } if (!empty($cfg_maxpl)) { $file_lines = preg_replace("/^{$cfg_maxpl}.*/", $cfg_maxpl . $config_sepa . $orig_maxpl, $file_lines); } if (!empty($cfg_hostn)) { $file_lines = preg_replace("/^{$cfg_hostn}.*/", $cfg_hostn . $config_sepa . $orig_hostname, $file_lines); } if (!empty($cfg_rcon)) { $file_lines = preg_replace("/^{$cfg_rcon}.*/", $cfg_rcon . $config_sepa . $orig_rcon, $file_lines); } if (!empty($cfg_passw)) { $file_lines = preg_replace("/^{$cfg_passw}.*/", $cfg_passw . $config_sepa . $orig_sv_pass, $file_lines); } // Minecraft - force query to true if ($orig_intname == 'mcraft') { $file_lines = preg_replace("/^enable\\-query.*/", 'enable-query=true', $file_lines); } } // Finish with newline $new_file .= $file_lines . "\n"; } // Write changes to file $fh = fopen($cfg_file, 'w') or die('Failed to open local config (' . $cfg_file . ') for writing.'); fwrite($fh, $new_file); fclose($fh); } else { // Double-escape some stuff $orig_hostname = addslashes(stripslashes($orig_hostname)); // Add exhaustive list of config options to this script (no, the option letters dont make sense, they are random because there are so many) $ssh_cmd = "ConfigUpdate -x \"{$orig_port}\" -u \"{$orig_username}\" -i \"{$orig_ip}\" -p \"{$orig_port}\" -c \"{$config_file}\" -s \"{$config_sepa}\" "; $ssh_cmd .= "-d \"{$cfg_ip}\" -e \"{$cfg_port}\" -f \"{$cfg_map}\" -g \"{$cfg_maxpl}\" -h \"{$cfg_rcon}\" -j \"{$cfg_hostn}\" -r \"{$cfg_passw}\" "; $ssh_cmd .= "-k \"{$orig_ip}\" -m \"{$orig_map}\" -n \"{$orig_maxpl}\" -O \"{$orig_rcon}\" -q \"{$orig_hostname}\" -t \"{$orig_sv_pass}\""; require_once DOCROOT . '/includes/classes/network.php'; $Network = new Network(); $result_update = $Network->runcmd($orig_netid, $net_info, $ssh_cmd, true, $srvid); if ($result_update != 'success') { return $result_update; } else { return true; } } } return 'success'; }