view_server_log.php 6.0 KB

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