1
0

view_server_log.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. {
  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( get_lang("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( get_lang("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. // Force log file contents to be UTF-8 (fixes http://www.opengamepanel.org/forum/viewthread.php?thread_id=5379)
  80. if(hasValue($home_log)){
  81. $home_log = utf8_encode($home_log);
  82. }
  83. // Using the refreshed class
  84. if( isset($_GET['refreshed']) )
  85. {
  86. echo "<pre class='log'>".htmlentities($home_log)."</pre>";
  87. }
  88. else
  89. {
  90. echo "<h2>".htmlentities($home_info['home_name'])."</h2>";
  91. if($log_retval == 1)
  92. {
  93. require_once("includes/refreshed.php");
  94. $control = '<form method="GET" >
  95. <input type="hidden" name="m" value="gamemanager" />
  96. <input type="hidden" name="p" value="log" />
  97. <input type="hidden" name="home_id-mod_id-ip-port" value="'.$_GET['home_id-mod_id-ip-port'].'" />';
  98. if(isset($_GET['setInterval']))
  99. $control .= "<input type='hidden' name='setInterval' value='" . $_GET['setInterval'] . "' />";
  100. if(isset($_GET['view_player_commands']))
  101. $control .= "<input type='hidden' name='view_player_commands' value='" . $_GET['view_player_commands'] . "' />";
  102. $control .= '<input type="submit" name="size" value="';
  103. if( isset( $_GET['size'] ) and $_GET['size'] == "+" )
  104. {
  105. $height = "100%";
  106. $control .= '-';
  107. }
  108. else
  109. {
  110. $height = "500px";
  111. $control .= '+';
  112. }
  113. $control .= '" /></form>';
  114. $intervals = array( "4s" => "4000",
  115. "8s" => "8000",
  116. "30s" => "30000",
  117. "2m" => "120000",
  118. "5m" => "300000" );
  119. $intSel = '<form action="" method="GET" >
  120. <input type="hidden" name="m" value="gamemanager" />
  121. <input type="hidden" name="p" value="log" />
  122. <input type="hidden" name="home_id-mod_id-ip-port" value="'.$_GET['home_id-mod_id-ip-port'].'" />';
  123. if(isset($_GET['size']))
  124. $intSel .= "<input type='hidden' name='size' value='" . $_GET['size'] . "' />";
  125. if(isset($_GET['view_player_commands']))
  126. $intSel .= "<input type='hidden' name='view_player_commands' value='" . $_GET['view_player_commands'] . "' />";
  127. $intSel .= get_lang("refresh_interval") . ':<select name="setInterval" onchange="this.form.submit();">';
  128. foreach ($intervals as $interval => $value )
  129. {
  130. $selected = "";
  131. if ( isset( $_GET['setInterval'] ) AND $_GET['setInterval'] == $value )
  132. $selected = 'selected="selected"';
  133. $intSel .= '<option value="'.$value.'" '.$selected.' >'.$interval.'</option>';
  134. }
  135. $intSel .= "</select></form>";
  136. $setInterval = isset($_GET['setInterval']) ? $_GET['setInterval'] : 4000;
  137. $refresh = new refreshed();
  138. $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']);
  139. echo $refresh->getdiv($pos,"height:".$height.";overflow:auto;max-width:1600px;");
  140. ?><script type="text/javascript">$(document).ready(function(){ <?php echo $refresh->build("$setInterval"); ?>} ); </script><?php
  141. echo "<table class='center' ><tr><td>$intSel</td><td>$control</td></tr></table>";
  142. if( ($server_xml->control_protocol and preg_match("/^r?l?con2?$/", $server_xml->control_protocol)) OR
  143. ($server_xml->gameq_query_name and $server_xml->gameq_query_name == "minecraft") OR
  144. ($server_xml->lgsl_query_name and $server_xml->lgsl_query_name == "7dtd") )
  145. require('modules/gamemanager/rcon.php');
  146. }
  147. else
  148. {
  149. echo "<pre class='log'>" . htmlentities($home_log) . "</pre>";
  150. print_failure( get_lang("server_not_running") );
  151. }
  152. echo create_back_button( $_GET['m'], 'game_monitor&home_id-mod_id-ip-port='.$_GET['home_id-mod_id-ip-port'] );
  153. }
  154. }
  155. else
  156. {
  157. print_failure(get_lang_f('unable_to_get_log',$log_retval));
  158. echo create_back_button( $_GET['m'], 'game_monitor&home_id-mod_id-ip-port='.$_GET['home_id-mod_id-ip-port'] );
  159. }
  160. }
  161. ?>