view_server_log.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) Copyright (C) 2008 - 2013 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. {
  28. global $db;
  29. global $view;
  30. list($home_id, $mod_id, $ip, $port) = explode("-", $_GET['home_id-mod_id-ip-port']);
  31. $user_id = $_SESSION['user_id'];
  32. $isAdmin = $db->isAdmin( $user_id );
  33. if($isAdmin)
  34. $home_info = $db->getGameHome($home_id);
  35. else
  36. $home_info = $db->getUserGameHome($user_id,$home_id);
  37. $current_mod_info = $home_info['mods'][$mod_id];
  38. $home_cfg_id = $current_mod_info['home_cfg_id'];
  39. $mod_cfg_id = $current_mod_info['mod_cfg_id'];
  40. if($home_cfg_id === null && $mod_cfg_id === null){
  41. print_failure(get_lang('invalid_game_mod_id'));
  42. return;
  43. }
  44. if ( $home_info === FALSE )
  45. {
  46. print_failure( no_access_to_home );
  47. return;
  48. }
  49. $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$home_info['home_cfg_file']);
  50. if ( !$server_xml )
  51. {
  52. echo create_back_button( $_GET['m'], 'game_monitor&home_id-mod_id-ip-port='.$_GET['home_id-mod_id-ip-port'] );
  53. return;
  54. }
  55. require_once('includes/lib_remote.php');
  56. $remote = new OGPRemoteLibrary($home_info['agent_ip'],$home_info['agent_port'],$home_info['encryption_key'],$home_info['timeout']);
  57. $home_log = "";
  58. if( isset( $server_xml->console_log ) )
  59. {
  60. $log_retval = $remote->get_log(OGP_SCREEN_TYPE_HOME,
  61. $home_info['home_id'],
  62. clean_path($home_info['home_path']),
  63. $home_log, 100, (string) $server_xml->console_log);
  64. }
  65. else
  66. {
  67. $log_retval = $remote->get_log(OGP_SCREEN_TYPE_HOME,
  68. $home_info['home_id'],
  69. clean_path($home_info['home_path']."/".$server_xml->exe_location),
  70. $home_log);
  71. }
  72. if ($log_retval == 0)
  73. {
  74. print_failure( agent_offline );
  75. echo create_back_button( $_GET['m'], 'game_monitor&home_id-mod_id-ip-port='.$_GET['home_id-mod_id-ip-port'] );
  76. }
  77. elseif ($log_retval == 1 || $log_retval == 2)
  78. {
  79. // Using the refreshed class
  80. if( isset($_GET['refreshed']) )
  81. {
  82. echo "<pre class='log'>".htmlentities($home_log)."</pre>";
  83. }
  84. else
  85. {
  86. echo "<h2>".htmlentities($home_info['home_name'])."</h2>";
  87. if($log_retval == 1)
  88. {
  89. require_once("includes/refreshed.php");
  90. $control = '<form method="GET" >
  91. <input type="hidden" name="m" value="gamemanager" />
  92. <input type="hidden" name="p" value="log" />
  93. <input type="hidden" name="home_id-mod_id-ip-port" value="'.$_GET['home_id-mod_id-ip-port'].'" />';
  94. if(isset($_GET['setInterval']))
  95. $control .= "<input type='hidden' name='setInterval' value='" . $_GET['setInterval'] . "' />";
  96. if(isset($_GET['view_player_commands']))
  97. $control .= "<input type='hidden' name='view_player_commands' value='" . $_GET['view_player_commands'] . "' />";
  98. $control .= '<input type="submit" name="size" value="';
  99. if( isset( $_GET['size'] ) and $_GET['size'] == "+" )
  100. {
  101. $height = "100%";
  102. $control .= '-';
  103. }
  104. else
  105. {
  106. $height = "500px";
  107. $control .= '+';
  108. }
  109. $control .= '" /></form>';
  110. $intervals = array( "4s" => "4000",
  111. "8s" => "8000",
  112. "30s" => "30000",
  113. "2m" => "120000",
  114. "5m" => "300000" );
  115. $intSel = '<form action="" method="GET" >
  116. <input type="hidden" name="m" value="gamemanager" />
  117. <input type="hidden" name="p" value="log" />
  118. <input type="hidden" name="home_id-mod_id-ip-port" value="'.$_GET['home_id-mod_id-ip-port'].'" />';
  119. if(isset($_GET['size']))
  120. $intSel .= "<input type='hidden' name='size' value='" . $_GET['size'] . "' />";
  121. if(isset($_GET['view_player_commands']))
  122. $intSel .= "<input type='hidden' name='view_player_commands' value='" . $_GET['view_player_commands'] . "' />";
  123. $intSel .= refresh_interval . ':<select name="setInterval" onchange="this.form.submit();">';
  124. foreach ($intervals as $interval => $value )
  125. {
  126. $selected = "";
  127. if ( isset( $_GET['setInterval'] ) AND $_GET['setInterval'] == $value )
  128. $selected = 'selected="selected"';
  129. $intSel .= '<option value="'.$value.'" '.$selected.' >'.$interval.'</option>';
  130. }
  131. $intSel .= "</select></form>";
  132. $setInterval = isset($_GET['setInterval']) ? $_GET['setInterval'] : 4000;
  133. $refresh = new refreshed();
  134. $pos = $refresh->add("home.php?m=gamemanager&p=log&type=cleared&refreshed&home_id-mod_id-ip-port=". $_GET['home_id-mod_id-ip-port']);
  135. echo $refresh->getdiv($pos,"height:".$height.";overflow:auto;max-width:1600px;");
  136. ?><script type="text/javascript">$(document).ready(function(){ <?php echo $refresh->build("$setInterval"); ?>} ); </script><?php
  137. echo "<table class='center' ><tr><td>$intSel</td><td>$control</td></tr></table>";
  138. if( ($server_xml->control_protocol and preg_match("/^r?l?con2?$/", $server_xml->control_protocol)) OR
  139. ($server_xml->gameq_query_name and $server_xml->gameq_query_name == "minecraft") OR
  140. ($server_xml->lgsl_query_name and $server_xml->lgsl_query_name == "7dtd") )
  141. require('modules/gamemanager/rcon.php');
  142. }
  143. else
  144. {
  145. echo "<pre class='log'>" . htmlentities($home_log) . "</pre>";
  146. print_failure( server_not_running );
  147. }
  148. echo create_back_button( $_GET['m'], 'game_monitor&home_id-mod_id-ip-port='.$_GET['home_id-mod_id-ip-port'] );
  149. }
  150. }
  151. else
  152. {
  153. print_failure(get_lang_f('unable_to_get_log',$log_retval));
  154. echo create_back_button( $_GET['m'], 'game_monitor&home_id-mod_id-ip-port='.$_GET['home_id-mod_id-ip-port'] );
  155. }
  156. }
  157. ?>