rcon.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <table>
  2. <tr>
  3. <td>
  4. <?php
  5. /*
  6. *
  7. * OGP - Open Game Panel
  8. * Copyright (C) 2008 - 2018 The OGP Development Team
  9. *
  10. * http://www.opengamepanel.org/
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version 2
  15. * of the License, or any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  25. *
  26. */
  27. function send_command($command, $remote, $server_xml, $home_info, $home_id, $ip, $port )
  28. {
  29. if( $server_xml->gameq_query_name and $server_xml->gameq_query_name == "minecraft" )
  30. {
  31. include_once("MinecraftRcon.class.php");
  32. $server_properties_file = clean_path($home_info['home_path']."/server.properties");
  33. $retval = $remote->remote_readfile($server_properties_file, $data);
  34. if($retval == 1 and strpos($data, 'rcon.port') !== FALSE)
  35. {
  36. $server_properties = parse_ini_string($data);
  37. $rcon_port = $server_properties['rcon.port'];
  38. }
  39. else
  40. {
  41. $rcon_port = $port+10;
  42. }
  43. $rcon = new MinecraftRcon;
  44. if( $rcon->Connect($ip, $rcon_port, $home_info['control_password']) )
  45. {
  46. $return = $rcon->Command($command);
  47. if($return)
  48. return $return;
  49. else
  50. return FALSE;
  51. $rcon->Disconnect();
  52. }
  53. else
  54. return get_lang("need_set_remote_pass") . " " . $home_info['home_name'] . " " . get_lang("before_sending_rcon_com");
  55. }
  56. elseif( $server_xml->lgsl_query_name and $server_xml->lgsl_query_name == "7dtd" )
  57. {
  58. $query_port = $port + 1;
  59. $return = $remote->exec('exec 3<>/dev/tcp/'.$ip.'/'. $query_port .' && echo -en "'.$command.'\\nexit\\n" >&3 && cat <&3');
  60. if(preg_match("/Connected with 7DTD server/",$return))
  61. return $return;
  62. else
  63. return FALSE;
  64. }
  65. else
  66. {
  67. $remote_retval = $remote->remote_send_rcon_command( $home_id, $ip, $port, $server_xml->control_protocol, $home_info['control_password'],$server_xml->control_protocol_type,$command,$return);
  68. if ( $remote_retval === 1 )
  69. return $return;
  70. elseif ( $remote_retval === -10 )
  71. return get_lang("need_set_remote_pass") . " " . $home_info['home_name'] . " " . get_lang("before_sending_rcon_com");
  72. else
  73. return FALSE;
  74. }
  75. }
  76. if(isset($_POST['command']) and !is_array($_POST['command']))
  77. $_POST['command'] = array( '0' => stripcslashes($_POST['command']) );
  78. elseif(isset($_POST['base64_command']))
  79. {
  80. foreach($_POST['base64_command'] as $key => $command)
  81. {
  82. $_POST['command'][$key] = isset($_POST['input']) ? str_replace("%input%", $_POST['input'], base64_decode($command)) : base64_decode($command);
  83. }
  84. }
  85. $presets = $db->getRconPresets($home_info['home_cfg_id'],$home_info['mods'][$mod_id]['mod_cfg_id']);
  86. if($presets > 0)
  87. {
  88. echo '<form action="" method="post">'.
  89. get_lang("rcon_presets") . ':
  90. <select onchange="this.form.submit()" name="command" >
  91. <option></option>\n';
  92. foreach ($presets as $preset)
  93. {
  94. echo '<option value="'.$preset['command'].'" >'.$preset['name'].'</option>\n';
  95. }
  96. echo '<input type="hidden" name="remote_send_rcon_command" value="">';
  97. echo '</form>';
  98. }
  99. ?>
  100. </td>
  101. </tr>
  102. </table>
  103. <table class="center" >
  104. <tr>
  105. <td>
  106. <?php echo get_lang("rcon_command_title"); ?></td>
  107. <td>
  108. <form method="post">
  109. <input class="rcon" type="text" name="command" size="200" style="width:98%;" value='<?php
  110. if( isset($_POST['command']) )
  111. echo htmlentities($_POST['command'][0]);
  112. ?>' />
  113. </td>
  114. <td>
  115. <input type="submit" name="remote_send_rcon_command" value="<?php print_lang('send_command'); ?>" />
  116. </form>
  117. </td>
  118. </tr>
  119. </table>
  120. <?php
  121. if(isset($_POST['remote_send_rcon_command']))
  122. {
  123. $response = "";
  124. foreach($_POST['command'] as $command)
  125. {
  126. $ret = send_command($command, $remote, $server_xml, $home_info, $home_id, $ip, $port );
  127. if(!$ret)
  128. {
  129. $response = FALSE;
  130. break;
  131. }
  132. else
  133. $response .= $ret;
  134. }
  135. if($response)
  136. {
  137. echo "<div class='bloc' ><h4>" . get_lang("rcon_command_title") . ": [" . htmlentities(implode(" | ", $_POST['command'])) . "] " .
  138. get_lang("has_sent_to") . " " . $home_info['home_name'] . "</h4><xmp style='overflow:auto;' >" .
  139. $response . "</xmp></div>";
  140. }
  141. }
  142. if($server_xml->list_players_command)
  143. {
  144. if(isset($_GET['view_player_commands']))
  145. {
  146. $response = send_command($server_xml->list_players_command, $remote, $server_xml, $home_info, $home_id, $ip, $port );
  147. if($response and $response != "")
  148. {
  149. preg_match_all($server_xml->player_info_regex, $response, $matches);
  150. if(!empty($matches[0]))
  151. {
  152. $data = array();
  153. $infos = array();
  154. $commands = array();
  155. foreach($server_xml->player_info->index as $index )
  156. {
  157. $i = 0;
  158. $key = (string)$index['key'];
  159. $name = (string)$index;
  160. $infos[] = $name;
  161. foreach($matches[$key] as $info)
  162. {
  163. $data[$i][$name] = $info;
  164. $i++;
  165. }
  166. }
  167. foreach($server_xml->player_commands->command as $command)
  168. {
  169. $name = (string)$command['key'];
  170. $commands[] = $name;
  171. $default = (string)$command->default ? (string)$command->default : "";
  172. $options = array();
  173. if($command->option)
  174. {
  175. foreach($command->option as $option)
  176. $options[(string)$option] = (string)$option['value'];
  177. }
  178. $actions = array();
  179. $replacements = array();
  180. foreach($command->string as $action)
  181. {
  182. preg_match_all("#%(\w*)%#", (string)$action, $replace);
  183. $replacements[] = $replace;
  184. $actions[] = (string)$action;
  185. }
  186. $replaced_actions = array();
  187. for($id = 0; $id < $i; $id++)
  188. {
  189. foreach($actions as $key => $action)
  190. {
  191. foreach($replacements[$key][1] as $index)
  192. {
  193. if(isset($data[$id][$index]) and $index != 'input')
  194. {
  195. $action = str_replace("%$index%", $data[$id][$index], $action);
  196. }
  197. }
  198. $replaced_actions[$key] = base64_encode($action);
  199. }
  200. $data[$id]['commands'][$name] = array('actions' => $replaced_actions,
  201. 'type' => (string)$command['type'],
  202. 'default' => $default,
  203. 'options' => $options);
  204. }
  205. unset($actions);
  206. }
  207. $headers = array_merge( $infos, $commands );
  208. $player_actions_table = "<table class='center'>\n<thead>\n<tr>";
  209. foreach($headers as $name)
  210. {
  211. $player_actions_table .= "<th>$name</th>";
  212. }
  213. $player_actions_table .= "</tr>\n</thead>\n<tbody>\n";
  214. foreach($data as $player)
  215. {
  216. $player_actions_table .= "<tr>\n";
  217. foreach($infos as $info)
  218. {
  219. $player_actions_table .= "<td>".htmlentities($player[$info])."</td>\n";
  220. }
  221. foreach($commands as $command)
  222. {
  223. $actions = $player['commands'][$command]['actions'];
  224. $type = $player['commands'][$command]['type'];
  225. $default = $player['commands'][$command]['default'];
  226. $options = $player['commands'][$command]['options'];
  227. /* echo "<xmp>";
  228. print_r($player['commands'][$command]['actions']);
  229. echo "</xmp><br>"; */
  230. $player_actions_table .= "<td>\n<form method='post'>\n";
  231. if($type == 'hidden')
  232. {
  233. foreach($actions as $key => $action)
  234. $player_actions_table .= "<input type='hidden' name='base64_command[$key]' value='$action'/>\n";
  235. }
  236. elseif($type == 'text')
  237. {
  238. foreach($actions as $key => $action)
  239. $player_actions_table .= "<input type='hidden' name='base64_command[$key]' value='$action'/>\n";
  240. $player_actions_table .= "<input type='text' name='input' value='$default'/>\n";
  241. }
  242. elseif($type == 'select')
  243. {
  244. foreach($actions as $key => $action)
  245. $player_actions_table .= "<input type='hidden' name='base64_command[$key]' value='$action'/>\n";
  246. $player_actions_table .= "<select name='input'>";
  247. foreach($options as $key => $value)
  248. {
  249. $player_actions_table .= "<option value='$value' >$key</option>";
  250. }
  251. $player_actions_table .= "<select name='input'>";
  252. }
  253. $player_actions_table .= "<input type='submit' name='remote_send_rcon_command' value='$command'/>\n".
  254. "</form>\n</td>\n";
  255. }
  256. $player_actions_table .= "</tr>\n";
  257. }
  258. $player_actions_table .= "</tbody>\n</table>\n";
  259. echo $player_actions_table;
  260. }
  261. else
  262. print_failure( get_lang("no_online_players") );
  263. }
  264. echo "<form method='GET' >".
  265. "<input type='hidden' name='m' value='gamemanager' />".
  266. "<input type='hidden' name='p' value='log' />".
  267. "<input type='hidden' name='home_id-mod_id-ip-port' value='" . $_GET['home_id-mod_id-ip-port'] . "' />";
  268. if(isset($_GET['setInterval']))
  269. echo "<input type='hidden' name='setInterval' value='" . $_GET['setInterval'] . "' />";
  270. if(isset($_GET['size']))
  271. echo "<input type='hidden' name='size' value='" . $_GET['size'] . "' />";
  272. echo "<input type='submit' name='hide_player_commands' value='" . get_lang("hide_player_commands") . "' />".
  273. "</form>";
  274. }
  275. else
  276. {
  277. echo "<form method='GET' >".
  278. "<input type='hidden' name='m' value='gamemanager' />".
  279. "<input type='hidden' name='p' value='log' />".
  280. "<input type='hidden' name='home_id-mod_id-ip-port' value='" . $_GET['home_id-mod_id-ip-port'] . "' />";
  281. if(isset($_GET['setInterval']))
  282. echo "<input type='hidden' name='setInterval' value='" . $_GET['setInterval'] . "' />";
  283. if(isset($_GET['size']))
  284. echo "<input type='hidden' name='size' value='" . $_GET['size'] . "' />";
  285. echo "<input type='submit' name='view_player_commands' value='" . get_lang("view_player_commands") . "' />".
  286. "</form>";
  287. }
  288. }
  289. ?>