rcon.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <table>
  2. <tr>
  3. <td>
  4. <?php
  5. /*
  6. *
  7. * OGP - Open Game Panel
  8. * Copyright (C) Copyright (C) 2008 - 2013 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. $rcon_port = $port+10;
  33. $rcon = new MinecraftRcon;
  34. if( $rcon->Connect($ip, $rcon_port, $home_info['control_password']) )
  35. {
  36. $return = $rcon->Command($command);
  37. if($return)
  38. return $return;
  39. else
  40. return FALSE;
  41. $rcon->Disconnect();
  42. }
  43. else
  44. return need_set_remote_pass . " " . $home_info['home_name'] . " " . before_sending_rcon_com;
  45. }
  46. elseif( $server_xml->lgsl_query_name and $server_xml->lgsl_query_name == "7dtd" )
  47. {
  48. $query_port = $port + 1;
  49. $return = $remote->exec('exec 3<>/dev/tcp/'.$ip.'/'. $query_port .' && echo -en "'.$command.'\\nexit\\n" >&3 && cat <&3');
  50. if(preg_match("/Connected with 7DTD server/",$return))
  51. return $return;
  52. else
  53. return FALSE;
  54. }
  55. else
  56. {
  57. $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);
  58. if ( $remote_retval === 1 )
  59. return $return;
  60. elseif ( $remote_retval === -10 )
  61. return need_set_remote_pass . " " . $home_info['home_name'] . " " . before_sending_rcon_com;
  62. else
  63. return FALSE;
  64. }
  65. }
  66. if(isset($_POST['command']) and !is_array($_POST['command']))
  67. $_POST['command'] = array( '0' => stripcslashes($_POST['command']) );
  68. elseif(isset($_POST['base64_command']))
  69. {
  70. foreach($_POST['base64_command'] as $key => $command)
  71. {
  72. $_POST['command'][$key] = isset($_POST['input']) ? str_replace("%input%", $_POST['input'], base64_decode($command)) : base64_decode($command);
  73. }
  74. }
  75. $presets = $db->getRconPresets($home_info['home_cfg_id'],$home_info['mods'][$mod_id]['mod_cfg_id']);
  76. if($presets > 0)
  77. {
  78. echo '<form action="" method="post">'.
  79. rcon_presets . ':
  80. <select onchange="this.form.submit()" name="command" >
  81. <option></option>\n';
  82. foreach ($presets as $preset)
  83. {
  84. echo '<option value="'.$preset['command'].'" >'.$preset['name'].'</option>\n';
  85. }
  86. echo '<input type="hidden" name="remote_send_rcon_command" value="">';
  87. echo '</form>';
  88. }
  89. ?>
  90. </td>
  91. </tr>
  92. </table>
  93. <table class="center" >
  94. <tr>
  95. <td>
  96. <?php echo rcon_command_title; ?></td>
  97. <td>
  98. <form method="post">
  99. <input class="rcon" type="text" name="command" size="200" style="width:98%;" value='<?php
  100. if( isset($_POST['command']) )
  101. echo htmlentities($_POST['command'][0]);
  102. ?>' />
  103. </td>
  104. <td>
  105. <input type="submit" name="remote_send_rcon_command" value="<?php print_lang('send_command'); ?>" />
  106. </form>
  107. </td>
  108. </tr>
  109. </table>
  110. <?php
  111. if(isset($_POST['remote_send_rcon_command']))
  112. {
  113. $response = "";
  114. foreach($_POST['command'] as $command)
  115. {
  116. $ret = send_command($command, $remote, $server_xml, $home_info, $home_id, $ip, $port );
  117. if(!$ret)
  118. {
  119. $response = FALSE;
  120. break;
  121. }
  122. else
  123. $response .= $ret;
  124. }
  125. if($response)
  126. {
  127. echo "<div class='bloc' ><h4>" . rcon_command_title . ": [" . htmlentities(implode(" | ", $_POST['command'])) . "] " .
  128. has_sent_to . " " . $home_info['home_name'] . "</h4><xmp style='overflow:auto;' >" .
  129. $response . "</xmp></div>";
  130. }
  131. }
  132. if($server_xml->list_players_command)
  133. {
  134. if(isset($_GET['view_player_commands']))
  135. {
  136. $response = send_command($server_xml->list_players_command, $remote, $server_xml, $home_info, $home_id, $ip, $port );
  137. if($response and $response != "")
  138. {
  139. preg_match_all($server_xml->player_info_regex, $response, $matches);
  140. if(!empty($matches[0]))
  141. {
  142. $data = array();
  143. $infos = array();
  144. $commands = array();
  145. foreach($server_xml->player_info->index as $index )
  146. {
  147. $i = 0;
  148. $key = (string)$index['key'];
  149. $name = (string)$index;
  150. $infos[] = $name;
  151. foreach($matches[$key] as $info)
  152. {
  153. $data[$i][$name] = $info;
  154. $i++;
  155. }
  156. }
  157. foreach($server_xml->player_commands->command as $command)
  158. {
  159. $name = (string)$command['key'];
  160. $commands[] = $name;
  161. $default = (string)$command->default ? (string)$command->default : "";
  162. $options = array();
  163. if($command->option)
  164. {
  165. foreach($command->option as $option)
  166. $options[(string)$option] = (string)$option['value'];
  167. }
  168. $actions = array();
  169. $replacements = array();
  170. foreach($command->string as $action)
  171. {
  172. preg_match_all("#%(\w*)%#", (string)$action, $replace);
  173. $replacements[] = $replace;
  174. $actions[] = (string)$action;
  175. }
  176. $replaced_actions = array();
  177. for($id = 0; $id < $i; $id++)
  178. {
  179. foreach($actions as $key => $action)
  180. {
  181. foreach($replacements[$key][1] as $index)
  182. {
  183. if(isset($data[$id][$index]) and $index != 'input')
  184. {
  185. $action = str_replace("%$index%", $data[$id][$index], $action);
  186. }
  187. }
  188. $replaced_actions[$key] = base64_encode($action);
  189. }
  190. $data[$id]['commands'][$name] = array('actions' => $replaced_actions,
  191. 'type' => (string)$command['type'],
  192. 'default' => $default,
  193. 'options' => $options);
  194. }
  195. unset($actions);
  196. }
  197. $headers = array_merge( $infos, $commands );
  198. $player_actions_table = "<table class='center'>\n<thead>\n<tr>";
  199. foreach($headers as $name)
  200. {
  201. $player_actions_table .= "<th>$name</th>";
  202. }
  203. $player_actions_table .= "</tr>\n</thead>\n<tbody>\n";
  204. foreach($data as $player)
  205. {
  206. $player_actions_table .= "<tr>\n";
  207. foreach($infos as $info)
  208. {
  209. $player_actions_table .= "<td>".htmlentities($player[$info])."</td>\n";
  210. }
  211. foreach($commands as $command)
  212. {
  213. $actions = $player['commands'][$command]['actions'];
  214. $type = $player['commands'][$command]['type'];
  215. $default = $player['commands'][$command]['default'];
  216. $options = $player['commands'][$command]['options'];
  217. /* echo "<xmp>";
  218. print_r($player['commands'][$command]['actions']);
  219. echo "</xmp><br>"; */
  220. $player_actions_table .= "<td>\n<form method='post'>\n";
  221. if($type == 'hidden')
  222. {
  223. foreach($actions as $key => $action)
  224. $player_actions_table .= "<input type='hidden' name='base64_command[$key]' value='$action'/>\n";
  225. }
  226. elseif($type == 'text')
  227. {
  228. foreach($actions as $key => $action)
  229. $player_actions_table .= "<input type='hidden' name='base64_command[$key]' value='$action'/>\n";
  230. $player_actions_table .= "<input type='text' name='input' value='$default'/>\n";
  231. }
  232. elseif($type == 'select')
  233. {
  234. foreach($actions as $key => $action)
  235. $player_actions_table .= "<input type='hidden' name='base64_command[$key]' value='$action'/>\n";
  236. $player_actions_table .= "<select name='input'>";
  237. foreach($options as $key => $value)
  238. {
  239. $player_actions_table .= "<option value='$value' >$key</option>";
  240. }
  241. $player_actions_table .= "<select name='input'>";
  242. }
  243. $player_actions_table .= "<input type='submit' name='remote_send_rcon_command' value='$command'/>\n".
  244. "</form>\n</td>\n";
  245. }
  246. $player_actions_table .= "</tr>\n";
  247. }
  248. $player_actions_table .= "</tbody>\n</table>\n";
  249. echo $player_actions_table;
  250. }
  251. else
  252. print_failure( no_online_players );
  253. }
  254. echo "<form method='GET' >".
  255. "<input type='hidden' name='m' value='gamemanager' />".
  256. "<input type='hidden' name='p' value='log' />".
  257. "<input type='hidden' name='home_id-mod_id-ip-port' value='" . $_GET['home_id-mod_id-ip-port'] . "' />";
  258. if(isset($_GET['setInterval']))
  259. echo "<input type='hidden' name='setInterval' value='" . $_GET['setInterval'] . "' />";
  260. if(isset($_GET['size']))
  261. echo "<input type='hidden' name='size' value='" . $_GET['size'] . "' />";
  262. echo "<input type='submit' name='hide_player_commands' value='" . hide_player_commands . "' />".
  263. "</form>";
  264. }
  265. else
  266. {
  267. echo "<form method='GET' >".
  268. "<input type='hidden' name='m' value='gamemanager' />".
  269. "<input type='hidden' name='p' value='log' />".
  270. "<input type='hidden' name='home_id-mod_id-ip-port' value='" . $_GET['home_id-mod_id-ip-port'] . "' />";
  271. if(isset($_GET['setInterval']))
  272. echo "<input type='hidden' name='setInterval' value='" . $_GET['setInterval'] . "' />";
  273. if(isset($_GET['size']))
  274. echo "<input type='hidden' name='size' value='" . $_GET['size'] . "' />";
  275. echo "<input type='submit' name='view_player_commands' value='" . view_player_commands . "' />".
  276. "</form>";
  277. }
  278. }
  279. ?>