· 9 years ago · Oct 02, 2016, 01:24 PM
1<?php
2/*
3 *
4 * OGP - Open Game Panel
5 * Copyright (C) Copyright (C) 2008 - 2014 The OGP Development Team
6 *
7 * http://www.opengamepanel.org/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 *
23 */
24// Report all PHP errors
25error_reporting(E_ALL);
26// Path definitions
27define("INCLUDES", "includes/");
28define("MODULES", "modules/");
29define("CONFIG_FILE",INCLUDES."config.inc.php");
30require_once(INCLUDES."functions.php");
31require_once(INCLUDES."helpers.php");
32require_once(INCLUDES."html_functions.php");
33require_once CONFIG_FILE;
34// Connect to the database server and select database.
35$db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
36$settings = $db->getSettings();
37function error($message){
38 echo json_encode(array('error' => array('message' => $message)));
39 exit();
40}
41function result($result){
42 echo json_encode(array('result' => $result));
43 exit();
44}
45if(isset($_POST['adminlogin']) and isset($_POST['adminpassword']))
46{
47 $adminInfo = $db->getUser($_POST['adminlogin']);
48 // If result matched $myusername and $mypassword, table row must be 1 row
49 if(isset($adminInfo['users_passwd']) and md5($_POST['adminpassword']) == $adminInfo['users_passwd'] and $adminInfo['users_role'] == 'admin')
50 {
51 $whmcs = $db->query('SELECT * FROM `OGP_DB_PREFIXwhmcs`');
52 if(!$whmcs)
53 {
54 $db->query("CREATE TABLE IF NOT EXISTS `OGP_DB_PREFIXwhmcs` (
55 `serviceid` int(11) NOT NULL,
56 `home_id` int(11) NOT NULL,
57 `user_id` int(11) NOT NULL,
58 `ip_id` int(11) NOT NULL,
59 `port` int(11) NOT NULL,
60 `main` tinyint(1) NULL,
61 UNIQUE KEY serviceid (`serviceid`)
62 ) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
63 }
64 if(isset($_POST['is_ts3']))
65 {
66 list($home_cfg_id, $mod_cfg_id) = explode("-", $_POST['home_cfg_id-mod_cfg_id']);
67 $game_cfg = $db->getGameCfg($home_cfg_id);
68 if(!$game_cfg)
69 {
70 error("The given IDs don't match any game.");
71 }
72 else
73 {
74 require(MODULES."config_games/server_config_parser.php");
75 $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$game_cfg['home_cfg_file']);
76 if($server_xml->protocol == "teamspeak3")
77 {
78 $remote_server_id = trim($_POST['rserver_id']);
79 $query = "SELECT home_id FROM `OGP_DB_PREFIXserver_homes` WHERE `home_cfg_id`=$home_cfg_id AND `remote_server_id`=$remote_server_id;";
80 $ts3_game_homes = $db->resultQuery($query);
81 if(!$ts3_game_homes)
82 error("There is no TS3 server installed at given remote server #ID.");
83 else
84 result($ts3_game_homes[0]['home_id']);
85 }
86 else
87 error("Not a TeamSpeak3 home_cfg_id.");
88 }
89 }
90 elseif(isset($_POST['get_main_serviceid']))
91 {
92 $userInfo = $db->getUserByEmail($_POST['user_email']);
93 if(is_array($userInfo))
94 {
95 $whmcs_service = $db->resultQuery("SELECT serviceid FROM `OGP_DB_PREFIXwhmcs` WHERE `main` = 1 AND `user_id`=$userInfo[user_id]");
96 $serviceid = $whmcs_service[0]['serviceid'];
97 if(is_numeric($serviceid))
98 {
99 result($serviceid);
100 }
101 else
102 error("There is no service assigned to this user yet.");
103 }
104 else
105 error("Can't find user with given email address (".$_POST['user_email'].").");
106 }
107 if(isset($_POST['get_user_serviceids']))
108 {
109 $userInfo = $db->getUserByEmail($_POST['user_email']);
110 if(is_array($userInfo))
111 {
112 $serviceids = $db->resultQuery("SELECT serviceid FROM `OGP_DB_PREFIXwhmcs` WHERE `user_id`=$userInfo[user_id]");
113 if(!$serviceids)
114 error("There is no services assigned to this user yet.");
115 else
116 result($serviceids);
117 }
118 else
119 error("Can't find user with given email address ($_POST[user_email]).");
120 }
121 elseif(isset($_POST['createaccount']))
122 {
123 $whmcs_service = $db->resultQuery("SELECT home_id FROM `OGP_DB_PREFIXwhmcs` WHERE `serviceid`=$_POST[serviceid]");
124 if(!$whmcs_service)
125 {
126 $userInfo = $db->getUserByEmail($_POST['user_email']);
127 $main = 'NULL';
128 if(!$userInfo)
129 {
130 $db->addUser($_POST['ulogin'],$_POST['upassword'],"user",$_POST['user_email']);
131 $userInfo = $db->getUserByEmail($_POST['user_email']);
132 $main = 1;
133 }
134 $user_id = $userInfo['user_id'];
135 list($home_cfg_id, $mod_cfg_id) = explode("-", $_POST['home_cfg_id-mod_cfg_id']);
136 if($_POST['debaranding'] == "1" or $_POST['debaranding'] == "")
137 $hostname = $_POST['server_name'];
138 else
139 $hostname = $settings['panel_name']." | ".$_POST['server_name'];
140
141 if(isset($_POST['ts3_home_id']))
142 {
143 $ts3_home_info = $db->getGameHome($_POST['ts3_home_id']);
144 $addresses = $db->getHomeIpPorts($_POST['ts3_home_id']);
145 require_once("protocol/TeamSpeak3/TeamSpeak3.php");
146 $cfg["user"] = "serveradmin";
147 $cfg["pass"] = $ts3_home_info['control_password'];
148 $cfg["query"] = "10011";
149 if ( $ts3_home_info['use_nat'] == 1 )
150 $cfg["host"] = $ts3_home_info['agent_ip'];
151 else
152 $cfg["host"] = $addresses[0]['ip'];
153 try
154 {
155 $ts3_ServerInstance = TeamSpeak3::factory("serverquery://".$cfg["user"].":".
156 $cfg["pass"]."@".
157 $cfg["host"].":".
158 $cfg["query"]."/");
159 }
160 catch(Exception $e)
161 {
162 error("Error ".$e->getCode().": ".$e->getMessage());
163 }
164 $ip_id = $addresses[0]['ip_id'];
165 $port = $db->getNextAvailablePort($ip_id,$home_cfg_id);
166 $db->addGameIpPort($_POST['ts3_home_id'],$ip_id,$port);
167 if (isset($ts3_home_info['ufw_status']) and $ts3_home_info['ufw_status'] == "enable")
168 {
169 include(INCLUDES.'lib_remote.php');
170 $remote = new OGPRemoteLibrary($ts3_home_info['agent_ip'], $ts3_home_info['agent_port'], $ts3_home_info['encryption_key'], $ts3_home_info['timeout']);
171 $remote->sudo_exec("ufw allow ".$port);
172 }
173 /* create server using given props */
174 try
175 {
176 $new_sid = $ts3_ServerInstance->serverCreate(array("virtualserver_name" => "$hostname", "virtualserver_maxclients" => $_POST['maxplayers'], "virtualserver_port" => $port));
177 }
178 catch(Exception $e)
179 {
180 $db->delGameIpPort($ts3_home_info['home_id'],$ip_id,$port);
181 if (isset($ts3_home_info['ufw_status']) and $ts3_home_info['ufw_status'] == "enable")
182 {
183 $remote->sudo_exec("ufw deny ".$port);
184 }
185 error("Error ".$e->getCode().": ".$e->getMessage());
186 }
187 $db->query("INSERT INTO OGP_DB_PREFIXts3_homes (`rserver_id`, `ip`, `pwd`, `vserver_id`, `user_id`) VALUES ('".$ts3_home_info['remote_server_id']."', '".
188 $addresses[0]['ip']."', '".
189 $cfg["pass"]."', '".
190 $new_sid['sid']."', '".
191 $user_id."');");
192 $home_id = (0 - $new_sid['sid']);
193 $ip_id = $_POST['ts3_home_id'];
194 }
195 else
196 {
197 $rserver = $db->getRemoteServer($_POST['rserver_id']);
198 $game_path = "/home/".$rserver['ogp_user']."/OGP_User_Files/whmcs/";
199 $home_id = $db->addGameHome($_POST['rserver_id'], $user_id, $home_cfg_id, $game_path, $hostname, $_POST['server_rcon'], $_POST['ftp_passwd']);
200 if($_POST['force_ip'] != "")
201 $ip_id = $db->getIpIdByIp($_POST['force_ip']);
202 else
203 {
204 $remote_server_ips = $db->getRemoteServerIPs($_POST['rserver_id']);
205 $ip_id = $remote_server_ips['0']['ip_id'];
206 }
207 $port = $db->getNextAvailablePort($ip_id,$home_cfg_id);
208 $db->addGameIpPort($home_id, $ip_id, $port);
209 $mod_id = $db->addModToGameHome($home_id, $mod_cfg_id);
210 $db->updateGameModParams($_POST['maxplayers'], "", "NA", "0", $home_id, $mod_cfg_id);
211 $db->assignHomeTo("user", $user_id, $home_id, $_POST['access_rights']);
212 $home_info = $db->getGameHome($home_id);
213 include(INCLUDES.'lib_remote.php');
214 $remote = new OGPRemoteLibrary($home_info['agent_ip'], $home_info['agent_port'], $home_info['encryption_key'], $home_info['timeout']);
215 if(preg_match("/t/", $_POST['access_rights']))
216 {
217 $remote->ftp_mgr("useradd", $home_id, $home_info['ftp_password'], $home_info['home_path']);
218 $db->changeFtpStatus('enabled', $home_id);
219 }
220 // Getting pre and post commands
221 $precmd = $home_info['mods'][$mod_id]['precmd'] == "" ? $home_info['mods'][$mod_id]['def_precmd'] : $home_info['mods'][$mod_id]['precmd'];
222 $postcmd = $home_info['mods'][$mod_id]['postcmd'] == "" ? $home_info['mods'][$mod_id]['def_postcmd'] : $home_info['mods'][$mod_id]['postcmd'];
223 // Starting Game server installation
224 if($_POST['installation'] == "steam")
225 {
226 require(MODULES."config_games/server_config_parser.php");
227 $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_info['home_cfg_file']);
228 if($server_xml->installer == "steamcmd")
229 {
230 $exec_folder_path = clean_path($home_info['home_path'] . "/" . $server_xml->exe_location);
231 $exec_path = clean_path($exec_folder_path . "/" . $server_xml->server_exec_name);
232 $mod_xml = xml_get_mod($server_xml, $home_info['mods'][$mod_id]['mod_key']);
233 $installer_name = $mod_xml->installer_name;
234 $modkey = $home_info['mods'][$mod_id]['mod_key'];
235 // Some games like L4D2 require anonymous login
236 if($mod_xml->installer_login){
237 $login = $mod_xml->installer_login;
238 $pass = '';
239 }else{
240 $login = $settings['steam_user'];
241 $pass = $settings['steam_pass'];
242 }
243 $modname = ( $installer_name == '90' and !preg_match("/(cstrike|valve)/", $modkey) ) ? $modkey : '';
244 $betaname = isset($mod_xml->betaname) ? $mod_xml->betaname : '';
245 $betapwd = isset($mod_xml->betapwd) ? $mod_xml->betapwd : '';
246 if(preg_match("/win(32|64)/", $server_xml->game_key))
247 $os = "windows";
248 elseif(preg_match("/linux/", $server_xml->game_key))
249 $os = "linux";
250 $remote->steam_cmd($home_id,$home_info['home_path'],$installer_name,$modname,
251 $betaname,$betapwd,$login,$pass,$settings['steam_guard'],
252 $exec_folder_path,$exec_path,$precmd,$postcmd,$os);
253 }
254 else
255 error('This game is not supported by Steam installation.');
256 }
257 elseif($_POST['installation'] == "rsync")
258 {
259 require(MODULES."config_games/server_config_parser.php");
260 $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_info['home_cfg_file']);
261 if(isset($server_xml->lgsl_query_name))
262 {
263 $rs_name = $server_xml->lgsl_query_name;
264 if($rs_name == "quake3")
265 {
266 if($server_xml->game_name == "Quake 3")
267 $rs_name = "q3";
268 }
269 }
270 elseif(isset($server_xml->gameq_query_name))
271 {
272 $rs_name = $server_xml->gameq_query_name;
273 if($rs_name == "minecraft")
274 {
275 if($server_xml->game_name == "Minecraft Tekkit")
276 $rs_name = "tekkit";
277 elseif($server_xml->game_name == "Minecraft Bukkit")
278 $rs_name = "bukkit";
279 }
280 }
281 elseif(isset($server_xml->protocol))
282 $rs_name = $server_xml->protocol;
283 else
284 $rs_name = $server_xml->mods->mod['key'];
285 $sync_list = @file(MODULES."gamemanager/rsync.list", FILE_IGNORE_NEW_LINES);
286 if ( in_array($rs_name, $sync_list) )
287 {
288 $exec_folder_path = clean_path($home_info['home_path'] . "/" . $server_xml->exe_location);
289 $exec_path = clean_path($exec_folder_path . "/" . $server_xml->server_exec_name);
290 $url = "rsync.opengamepanel.org";
291 if(preg_match("/win(32|64)/", $server_xml->game_key))
292 $os = "windows";
293 elseif(preg_match("/linux/", $server_xml->game_key))
294 $os = "linux";
295 $full_url = "$url/ogp_game_installer/$rs_name/$os/";
296 $remote->start_rsync_install($home_id,$home_info['home_path'],"$full_url",$exec_folder_path,$exec_path,$precmd,$postcmd);
297 }
298 else
299 error('This game is not supported by rsync installation.');
300 }
301 elseif($_POST['installation'] == "manual")
302 {
303 if($_POST['url'] != "")
304 {
305 $filename = basename($_POST['url']);
306 $remote->start_file_download($_POST['url'],$home_info['home_path'],$filename,"uncompress");
307 }
308 else
309 error('The URL for manual installation is empty.');
310 }
311 elseif($_POST['installation'] == "master")
312 {
313 require(MODULES."config_games/server_config_parser.php");
314 $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_info['home_cfg_file']);
315 $ms_home_id = $db->getMasterServer( $_POST['rserver_id'], $home_cfg_id );
316 if(is_numeric($ms_home_id))
317 {
318 $exec_folder_path = clean_path($home_info['home_path'] . "/" . $server_xml->exe_location );
319 $exec_path = clean_path($exec_folder_path . "/" . $server_xml->server_exec_name );
320 $ms_info = $db->getGameHome($ms_home_id);
321 $remote->masterServerUpdate($home_id,$home_info['home_path'],$ms_home_id,$ms_info['home_path'],$exec_folder_path,$exec_path,$precmd,$postcmd);
322 }
323 else
324 error('There is no master server assigned for this game.');
325 }
326 }
327 $db->query("INSERT INTO `OGP_DB_PREFIXwhmcs` (serviceid, home_id, user_id, ip_id, port, main) VALUES($_POST[serviceid], $home_id, $user_id, $ip_id, $port, $main);");
328 result(true);
329 }
330 else
331 error('Service already created.');
332 }
333 elseif(isset($_POST['terminateaccount']))
334 {
335 $whmcs_service = $db->resultQuery("SELECT * FROM `OGP_DB_PREFIXwhmcs` WHERE `serviceid`=$_POST[serviceid]");
336 if(is_array($whmcs_service['0']))
337 {
338 $user_id = $whmcs_service['0']['user_id'];
339 $home_id = $whmcs_service['0']['home_id'];
340 if($home_id < 0)
341 {
342 $sid = $home_id * ( -1 );
343 $ts3_home_id = $whmcs_service['0']['ip_id'];
344 $ts3 = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXts3_homes WHERE `vserver_id`=$sid AND `user_id`=$user_id;");
345 if(!$ts3)
346 {
347 $db->query("DELETE FROM OGP_DB_PREFIXts3_homes WHERE vserver_id=$sid");
348 $db->query("DELETE FROM `OGP_DB_PREFIXwhmcs` WHERE `serviceid`=$_POST[serviceid]");
349 error("TS3 Virtual server with id $sid is not assigned to user id $user_id.");
350 }
351 else
352 {
353 $ts3_info = $ts3[0];
354 $port = $whmcs_service['0']['port'];
355 $ip_id = $db->getIpIdByIp($ts3_info['ip']);
356 $DelVirtual = $db->delGameIpPort($ts3_home_id, $ip_id, $port);
357 if ($DelVirtual)
358 {
359 $ts3_home_info = $db->getGameHome($ts3_home_id);
360 require_once("protocol/TeamSpeak3/TeamSpeak3.php");
361 $cfg["user"] = "serveradmin";
362 $cfg["pass"] = $ts3_home_info['control_password'];
363 $cfg["query"] = "10011";
364 if ( $ts3_home_info['use_nat'] == 1 )
365 $cfg["host"] = $ts3_home_info['agent_ip'];
366 else
367 $cfg["host"] = $ts3_info['ip'];
368 try
369 {
370 $ts3_ServerInstance = TeamSpeak3::factory("serverquery://".$cfg["user"].":".
371 $cfg["pass"]."@".
372 $cfg["host"].":".
373 $cfg["query"]."/");
374 }
375 catch(Exception $e)
376 {
377 error("Error ".$e->getCode().": ".$e->getMessage());
378 }
379
380 $ts3_ServerInstance->serverStop($sid);
381 $ts3_ServerInstance->serverDelete($sid);
382 $db->query("DELETE FROM OGP_DB_PREFIXts3_homes WHERE vserver_id=$sid");
383 $db->query("DELETE FROM `OGP_DB_PREFIXwhmcs` WHERE `serviceid`=$_POST[serviceid]");
384 result(true);
385 }
386 else
387 error("The address of such TS3 virtual server does not exist.");
388 }
389 }
390 else
391 {
392 $home_info = $db->getGameHomeWithoutMods($home_id);
393 if(!$home_info)
394 {
395 $db->query("DELETE FROM `OGP_DB_PREFIXwhmcs` WHERE `serviceid`=$_POST[serviceid]");
396 error("The server for this service has been removed manually, so the service has been removed too.");
397 }
398 else
399 {
400 $server_info = $db->getRemoteServerById($home_info['remote_server_id']);
401 include(INCLUDES.'lib_remote.php');
402 $remote = new OGPRemoteLibrary($server_info['agent_ip'], $server_info['agent_port'], $server_info['encryption_key'], $server_info['timeout']);
403 if($db->IsFtpEnabled($home_id))
404 {
405 $login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
406 $remote->ftp_mgr("userdel", $login);
407 $db->changeFtpStatus('disabled',$home_id);
408 }
409 $user_homes = $db->getHomesFor("user_and_group",$user_id);
410 include(MODULES."config_games/server_config_parser.php");
411 $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_info['home_cfg_file']);
412 if(isset($server_xml->control_protocol_type))$control_type = $server_xml->control_protocol_type; else $control_type = "";
413 $ip_id = $whmcs_service['0']['ip_id'];
414 $port = $whmcs_service['0']['port'];
415 $ip = $db->getIpById($ip_id);
416 $remote->remote_stop_server($home_id,$ip,$port,$server_xml->control_protocol,$home_info['control_password'],$control_type,$home_info['home_path']);
417 $db->unassignHomeFrom("user", $user_id, $home_id);
418 $db->deleteGameHome($home_id);
419 $remote->remove_home($home_info['home_path']);
420 $db->query("DELETE FROM `OGP_DB_PREFIXwhmcs` WHERE `serviceid`=$_POST[serviceid]");
421 $user_services = $db->resultQuery("SELECT * FROM `OGP_DB_PREFIXwhmcs` WHERE `user_id`=$user_id");
422 if(!$user_services)
423 $db->delUser($user_id);
424 else
425 {
426 $main_serviceid = false;
427 foreach($user_services as $user_service)
428 {
429 if($user_service['main'] == 1)
430 $serviceid_main = true;
431 }
432 if(!$main_serviceid)
433 $db->query("UPDATE `OGP_DB_PREFIXwhmcs` SET `main`=1 WHERE `serviceid`=".$user_services[0]['serviceid']);
434 }
435 result(true);
436 }
437 }
438 }
439 else
440 error("Service id $_POST[serviceid] does not exists in OGP database.");
441 }
442 elseif(isset($_POST['suspendaccount']))
443 {
444 $whmcs_service = $db->resultQuery("SELECT * FROM `OGP_DB_PREFIXwhmcs` WHERE `serviceid`=$_POST[serviceid]");
445 if(is_array($whmcs_service['0']))
446 {
447 $user_id = $whmcs_service['0']['user_id'];
448 $home_id = $whmcs_service['0']['home_id'];
449 if($home_id < 0)
450 {
451 $sid = $home_id * ( -1 );
452 $ts3_home_id = $whmcs_service['0']['ip_id'];
453 $ts3 = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXts3_homes WHERE `vserver_id`=$sid AND `user_id`=$user_id;");
454 if(!$ts3)
455 error("TS3 Virtual server with id $sid is not assigned to user id $user_id.");
456 else
457 {
458 $ts3_info = $ts3[0];
459 $port = $whmcs_service['0']['port'];
460 $ip_id = $db->getIpIdByIp($ts3_info['ip']);
461 $ts3_home_info = $db->getGameHome($ts3_home_id);
462 require_once("protocol/TeamSpeak3/TeamSpeak3.php");
463 $cfg["user"] = "serveradmin";
464 $cfg["pass"] = $ts3_home_info['control_password'];
465 $cfg["query"] = "10011";
466 if ( $ts3_home_info['use_nat'] == 1 )
467 $cfg["host"] = $ts3_home_info['agent_ip'];
468 else
469 $cfg["host"] = $ts3_info['ip'];
470 try
471 {
472 $ts3_ServerInstance = TeamSpeak3::factory("serverquery://".$cfg["user"].":".
473 $cfg["pass"]."@".
474 $cfg["host"].":".
475 $cfg["query"]."/");
476 }
477 catch(Exception $e)
478 {
479 error("Error ".$e->getCode().": ".$e->getMessage());
480 }
481
482 $ts3_ServerInstance->serverStop($sid);
483 $db->query("DELETE FROM OGP_DB_PREFIXts3_homes WHERE vserver_id=$sid");
484 result(true);
485 }
486 }
487 else
488 {
489 $home_info = $db->getGameHomeWithoutMods($home_id);
490 if(!$home_info)
491 {
492 $db->query("DELETE FROM `OGP_DB_PREFIXwhmcs` WHERE `serviceid`=$_POST[serviceid]");
493 error("The server for this service has been removed manually, so the service has been removed too.");
494 }
495 else
496 {
497 $server_info = $db->getRemoteServerById($home_info['remote_server_id']);
498 include(INCLUDES.'lib_remote.php');
499 $remote = new OGPRemoteLibrary($server_info['agent_ip'], $server_info['agent_port'], $server_info['encryption_key'], $server_info['timeout']);
500 include(MODULES."config_games/server_config_parser.php");
501 $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_info['home_cfg_file']);
502 if(isset($server_xml->control_protocol_type))$control_type = $server_xml->control_protocol_type; else $control_type = "";
503 $ip_id = $whmcs_service['0']['ip_id'];
504 $port = $whmcs_service['0']['port'];
505 $ip = $db->getIpById($ip_id);
506 $remote->remote_stop_server($home_id,$ip,$port,$server_xml->control_protocol,$home_info['control_password'],$control_type,$home_info['home_path']);
507 $db->unassignHomeFrom("user", $user_id, $home_id);
508 if($db->IsFtpEnabled($home_id))
509 {
510 $login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
511 $remote->ftp_mgr("userdel", $login);
512 $db->changeFtpStatus('disabled',$home_id);
513 }
514 result(true);
515 }
516 }
517 }
518 else
519 error("Service id $_POST[serviceid] does not exists in OGP database.");
520 }
521 elseif(isset($_POST['unsuspendaccount']))
522 {
523 $whmcs_service = $db->resultQuery("SELECT * FROM `OGP_DB_PREFIXwhmcs` WHERE `serviceid`=$_POST[serviceid]");
524 if(is_array($whmcs_service['0']))
525 {
526 $user_id = $whmcs_service['0']['user_id'];
527 $home_id = $whmcs_service['0']['home_id'];
528 if($home_id < 0)
529 {
530 $sid = $home_id * ( -1 );
531 $ts3_home_id = $whmcs_service['0']['ip_id'];
532 $port = $whmcs_service['0']['port'];
533 $ts3_home_info = $db->getGameHome($ts3_home_id);
534 $addresses = $db->getHomeIpPorts($ts3_home_id);
535 require_once("protocol/TeamSpeak3/TeamSpeak3.php");
536 $cfg["user"] = "serveradmin";
537 $cfg["pass"] = $ts3_home_info['control_password'];
538 $cfg["query"] = "10011";
539 if ( $ts3_home_info['use_nat'] == 1 )
540 $cfg["host"] = $ts3_home_info['agent_ip'];
541 else
542 $cfg["host"] = $addresses[0]['ip'];
543 try
544 {
545 $ts3_ServerInstance = TeamSpeak3::factory("serverquery://".$cfg["user"].":".
546 $cfg["pass"]."@".
547 $cfg["host"].":".
548 $cfg["query"]."/");
549 }
550 catch(Exception $e)
551 {
552 error("Error ".$e->getCode().": ".$e->getMessage());
553 }
554 $ts3_ServerInstance->serverStart($sid);
555 $db->query("INSERT INTO OGP_DB_PREFIXts3_homes (`rserver_id`, `ip`, `pwd`, `vserver_id`, `user_id`) VALUES ('".$ts3_home_info['remote_server_id']."', '".
556 $addresses[0]['ip']."', '".
557 $cfg["pass"]."', '".
558 $sid."', '".
559 $user_id."');");
560 result(true);
561 }
562 else
563 {
564 $home_info = $db->getGameHomeWithoutMods($home_id);
565 if(!$home_info)
566 {
567 $db->query("DELETE FROM `OGP_DB_PREFIXwhmcs` WHERE `serviceid`=$_POST[serviceid]");
568 error("The server for this service has been removed manually, so the service has been removed too.");
569 }
570 else
571 {
572 $db->assignHomeTo("user", $user_id, $home_id, $_POST['access_rights']);
573 if(preg_match("/t/", $_POST['access_rights']))
574 {
575 include(INCLUDES.'lib_remote.php');
576 $remote = new OGPRemoteLibrary($home_info['agent_ip'],$home_info['agent_port'],$home_info['encryption_key'], $home_info['timeout']);
577 $login = isset($home_info['ftp_login']) ? $home_info['ftp_login'] : $home_id;
578 $remote->ftp_mgr("useradd", $login, $home_info['ftp_password'], $home_info['home_path']);
579 $db->changeFtpStatus('enabled',$home_id);
580 }
581 result(true);
582 }
583 }
584 }
585 else
586 error("Service id $_POST[serviceid] does not exists in OGP database.");
587 }
588 elseif(isset($_POST['changepassword']))
589 {
590 $userInfo = $db->getUserByEmail($_POST['user_email']);
591 if(!$userInfo)
592 {
593 error("Email $_POST[user_email] does not belong to any user of the panel.");
594 }
595 else
596 {
597 $user_id = $userInfo['user_id'];
598 $db_password = md5($_POST['upassword']);
599 $changepass = $db->updateUsersPassword($user_id,$db_password);
600 result(true);
601 }
602 }
603 }
604}
605else
606{
607 $game_cfgs = $db->getGameCfgs();
608 echo "<table style='border:1px solid black;'>";
609 echo "<tr style='border:1px solid black;' ><td style='border:1px solid black;' >Game Name</td><td style='border:1px solid black;' >Mod Name</td><td style='border:1px solid black;' >Home Cfg ID-Mod Cfg ID</td></tr>";
610 foreach($game_cfgs as $cfg)
611 {
612 $home_cfg_id = $cfg['home_cfg_id'];
613 $game_name = $cfg['game_name'];
614 if(preg_match("/linux/", $cfg['game_key'])) $os = " (Linux)"; elseif(preg_match("/win/", $cfg['game_key'])) $os = " (Windows)";
615 if(preg_match("/64/", $cfg['game_key'])) $arch = " (64bit)"; else $arch = " (32bit)";
616 {
617 $cfgs_mods = $db->getCfgMods($home_cfg_id);
618 foreach($cfgs_mods as $mod)
619 {
620 echo "<tr style='border:1px solid black;'><td style='border:1px solid black;'>".$game_name.$os.$arch."</td><td style='border:1px solid black;' >".$mod['mod_name']."</td><td style='border:1px solid black;' ><center>".$mod['home_cfg_id']."-".$mod['mod_cfg_id']."</center></td></tr>";
621 }
622 }
623 }
624 echo "</table>";
625}
626?>