1
0

stop_server.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2018 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. require_once('home_handling_functions.php');
  25. require_once("modules/config_games/server_config_parser.php");
  26. function exec_ogp_module() {
  27. global $view,$db;
  28. require_once('includes/lib_remote.php');
  29. $ip = $_REQUEST['ip'];
  30. $port = $_REQUEST['port'];
  31. $home_id = $_REQUEST['home_id'];
  32. $mod_id = $_REQUEST['mod_id'];
  33. $user_id = $_SESSION['user_id'];
  34. // Check ip/port inputs
  35. if(!is_numeric($port))
  36. return;
  37. if(!preg_match("/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/",$ip))
  38. return;
  39. $isAdmin = $db->isAdmin( $user_id );
  40. if($isAdmin)
  41. $home_info = $db->getGameHome($home_id);
  42. else
  43. $home_info = $db->getUserGameHome($user_id,$home_id);
  44. if ( $home_info === FALSE )
  45. {
  46. print_failure(get_lang('no_rights_to_stop_server'));
  47. return;
  48. }
  49. $home_id = $home_info['home_id'];
  50. $home_path = clean_path($home_info['home_path']."/");
  51. echo "<h2>".htmlentities($home_info['home_name'])."</h2>";
  52. $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_info['home_cfg_file']);
  53. if ( !$server_xml )
  54. {
  55. echo create_back_button("gamemanager","game_monitor");
  56. return;
  57. }
  58. $rserver = $db->getRemoteServerById($home_info['remote_server_id']);
  59. if ( empty($rserver) )
  60. {
  61. print_failure("Could not find the remote server with ID ".$home_info['remote_server_id'].".");
  62. }
  63. else
  64. {
  65. $remote = new OGPRemoteLibrary($rserver['agent_ip'],
  66. $rserver['agent_port'],
  67. $rserver['encryption_key'],
  68. $rserver['timeout']);
  69. if(isset($server_xml->control_protocol_type))$control_type = $server_xml->control_protocol_type; else $control_type = "";
  70. if ($server_xml->protocol == "gameq")
  71. {
  72. $query_port = get_query_port($server_xml, $port);
  73. }
  74. elseif ($server_xml->protocol == "lgsl")
  75. {
  76. require('protocol/lgsl/lgsl_protocol.php');
  77. $get_ports = lgsl_port_conversion((string)$server_xml->lgsl_query_name, $port, "", "");
  78. $query_port = $get_ports['1'];
  79. }
  80. elseif ($server_xml->protocol == "teamspeak3")
  81. {
  82. $query_port = "10011";
  83. }
  84. $remote_retval = $remote->remote_stop_server($home_id,
  85. $ip, $port, $server_xml->control_protocol,
  86. $home_info['control_password'],$control_type, $home_path);
  87. $db->logger(get_lang_f('server_stopped', $home_info['home_name'] ) . "($ip:$port)");
  88. $firewall_settings = $db->getFirewallSettings($home_info['remote_server_id']);
  89. if ( $remote_retval === 1 )
  90. {
  91. print_success(get_lang_f("server_stopped",htmlentities($home_info['home_name'])));
  92. if ($firewall_settings['status'] == "enable")
  93. {
  94. $ip_ports = $db->getHomeIpPorts($home_id);
  95. foreach ($ip_ports as $ip_port)
  96. {
  97. if ($server_xml->protocol == "gameq")
  98. {
  99. $query_port = get_query_port($server_xml, $ip_port['port']);
  100. }
  101. elseif ($server_xml->protocol == "lgsl")
  102. {
  103. require('protocol/lgsl/lgsl_protocol.php');
  104. $get_ports = lgsl_port_conversion((string)$server_xml->lgsl_query_name, $ip_port['port'], "", "");
  105. $query_port = $get_ports['1'];
  106. }
  107. elseif ($server_xml->protocol == "teamspeak3")
  108. {
  109. $query_port = "10011";
  110. }
  111. set_firewall($remote, $firewall_settings, 'deny', $ip_port['port'], $ip_port['ip']);
  112. if(isset($query_port) and $query_port != "" and $query_port != $ip_port['port'])
  113. set_firewall($remote, $firewall_settings, 'deny', $query_port, $ip_port['ip']);
  114. }
  115. }
  116. }
  117. elseif ( $remote_retval === 0 )
  118. {
  119. $remote_retval = $remote->remote_stop_server($home_info['home_id'],
  120. $ip, $port, $server_xml->control_protocol,"",$control_type,$home_path);
  121. if ($remote_retval === 1 )
  122. {
  123. print_success(get_lang_f("server_stopped",htmlentities($home_info['home_name'])));
  124. if ($firewall_settings['status'] == "enable")
  125. {
  126. $ip_ports = $db->getHomeIpPorts($home_id);
  127. foreach ($ip_ports as $ip_port)
  128. {
  129. if ($server_xml->protocol == "gameq")
  130. {
  131. $query_port = get_query_port($server_xml, $ip_port['port']);
  132. }
  133. elseif ($server_xml->protocol == "lgsl")
  134. {
  135. require('protocol/lgsl/lgsl_protocol.php');
  136. $get_ports = lgsl_port_conversion((string)$server_xml->lgsl_query_name, $ip_port['port'], "", "");
  137. $query_port = $get_ports['1'];
  138. }
  139. elseif ($server_xml->protocol == "teamspeak3")
  140. {
  141. $query_port = "10011";
  142. }
  143. $remote->sudo_exec(str_replace("%PORT%",$ip_port['port'],$firewall_settings['deny_port_command']));
  144. if(isset($query_port))
  145. {
  146. $remote->sudo_exec(str_replace("%PORT%",$query_port,$firewall_settings['deny_port_command']));
  147. }
  148. }
  149. }
  150. }
  151. }
  152. if ( $remote_retval === 0 )
  153. print_failure(get_lang("agent_offline"));
  154. elseif ( $remote_retval !== 1 )
  155. print_failure("Error occurred on the remote host.");
  156. }
  157. $view->refresh("?m=gamemanager&amp;p=game_monitor&amp;home_id-mod_id-ip-port=". $home_id . "-". $mod_id . "-" . $ip . "-" . $port,3);
  158. }
  159. ?>