$tpl_list = ''; if ($total_rows) { 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!'); } }
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($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 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 send_screen_cmd($srvid, $cmd) { if (empty($srvid)) { return 'Error: Restart class: No server ID given!'; } elseif (empty($cmd)) { return 'Error: Restart class: No command given!'; } if (preg_match('/\\./', $cmd)) { return 'Invalid command.'; } elseif (preg_match('/[;&/|]+/', $cmd)) { return 'Invalid command.'; } $cmd = escapeshellarg($cmd); $srv_info = $this->getinfo($srvid); $srv_username = $srv_info[0]['username']; $srv_ip = $srv_info[0]['ip']; $srv_port = $srv_info[0]['port']; $srv_working_dir = $srv_info[0]['working_dir']; if ($srv_working_dir) { $srv_working_dir = ' -w ' . $srv_working_dir; } $srv_netid = $srv_info[0]['netid']; $srv_parentid = $srv_info[0]['parentid']; require 'network.php'; $Network = new Network(); $net_info = $Network->netinfo($srv_netid); $ssh_cmd = "ServerSendCMD -u {$srv_username} -i {$srv_ip} -p {$srv_port} {$srv_working_dir} -c {$cmd}"; // Return server log return $Network->runcmd($srv_netid, $net_info, $ssh_cmd, true, $srvid); }
} ######################################################################## // Admins if (isset($_SESSION['gpx_admin'])) { if (GPXDEBUG) { echo "Saving description: {$url_descr}, for ID: {$url_id}<br>"; } @mysql_query("UPDATE servers SET \r\n netid = '{$url_netid}',userid = '{$url_userid}',port = '{$url_port}',maxplayers = '{$url_maxpl}',\r\n last_updated = NOW(),startup = '{$url_startup}',working_dir = '{$url_working_dir}',pid_file = '{$url_pid_file}',\r\n description = '{$url_descr}',update_cmd = '{$url_updatecmd}',simplecmd = '{$url_cmd}',hostname = '{$url_hostn}',\r\n map = '{$url_map}',rcon = '{$url_rcon}',sv_password = '******' \r\n WHERE id = '{$url_id}'") or die('Failed to update admin server settings: ' . mysql_error()); } else { @mysql_query("UPDATE servers SET \r\n last_updated = NOW(),description = '{$url_descr}',hostname = '{$url_hostn}',\r\n map = '{$url_map}',rcon = '{$url_rcon}',sv_password = '******' \r\n WHERE id = '{$url_id}' AND userid = '{$gpx_userid}'") or die('Failed to update client server settings!'); } ######################################################################## // Get net info require DOCROOT . '/includes/classes/network.php'; $Network = new Network(); $net_info = $Network->netinfo($url_netid); // Update server config $cfg_upd = $Servers->configupdate($url_id, $srvinfo, $net_info); if ($cfg_upd != 'success') { die('Failed to update config: ' . $cfg_upd); } ######################################################################## // Output echo 'success'; } elseif ($url_do == 'startup_save') { $sort_order = $GPXIN['sort_list']; $startup_type = $GPXIN['start_type']; // Get server info $srvinfo = $Servers->getinfo($url_id); // If simple, update and exit if (isset($_SESSION['gpx_admin'])) {