Advertisement
Guest User

page

a guest
Dec 19th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.93 KB | None | 0 0
  1. <?php
  2. /**
  3. * @author Daniel Kesberg <kesberg@ebene3.com>
  4. * @copyright (c) 2013, Daniel Kesberg
  5. */
  6.  
  7. error_reporting(E_ALL);
  8. ini_set('display_errors', false);
  9.  
  10. $parseTimeStart = microtime();
  11.  
  12. // load config
  13. // Set paths.log to the full path of the log file
  14. $config = array(
  15. 'server' => array(
  16. 'hostname' => '127.0.0.1',
  17. 'port' => 21025
  18. ),
  19. 'paths' => array(
  20. 'log' => 'd:/games/Steam/steamApps/common/Starbound/starbound_server.log',
  21. 'config' => 'd:/games/Steam/steamApps/common/Starbound/starbound.config'
  22. )
  23. );
  24.  
  25. // read logfile
  26. $log = file_get_contents($config['paths']['log']);
  27.  
  28. // read configfile
  29. $conf = file_get_contents($config['paths']['config']);
  30.  
  31. // split into lines
  32. $logLines = explode("\n", $log);
  33. $confLines = explode("\n", $conf);
  34.  
  35. // get server version
  36. $confMax = array_filter($confLines, function($line) {
  37. return preg_match('/maxPlayers/', $line);
  38. });
  39.  
  40. // only look at the last line
  41. $confMax = end($confMax);
  42. $tmp = explode(': ', $confMax);
  43. $tmp2 = str_replace(',',' ',$tmp);
  44. $confMax = $tmp2[1];
  45.  
  46. // only keep lines with client info
  47. $logClients = array_filter($logLines, function($line) {
  48. return preg_match('/^Info:.*Client/', $line);
  49. });
  50.  
  51. // '/!Info\:\s*<([^>]{2,})>\s?(.*)!i/'
  52. // only keep lines with client info
  53. $chats = array_filter($logLines, function($line) {
  54. return preg_match('/^Info\:\s\s/', $line);
  55. });
  56.  
  57. // extract clients
  58. $clients = array();
  59. foreach ($logClients as $line) {
  60. if (preg_match('/.*?\\\'(.*)\\\'.*?\(.*?\)(.*)/is', $line, $matches) == 1) {
  61. if (strlen($matches[1])) {
  62. $clients[$matches[1]] = trim($matches[2]);
  63. }
  64. }
  65. }
  66.  
  67. // only keep "connected" status
  68. $clients = array_filter($clients, function($status) {
  69. return trim($status) == 'connected';
  70. });
  71.  
  72. // sort
  73. ksort($clients);
  74.  
  75.  
  76. // get server version
  77. $logVersion = array_filter($logLines, function($line) {
  78. return preg_match('/^Info: Server version/', $line);
  79. });
  80.  
  81. // only look at the last line
  82. $logVersion = end($logVersion);
  83. $tmp = explode("'", $logVersion);
  84. $logVersion = $tmp[1];
  85.  
  86. // server is running ?
  87. // edit: removed shell cmd, stole fsockopen from https://gist.github.com/lagonnebula/7928214 ;)
  88. $fp = fsockopen($config['server']['hostname'], $config['server']['port'], $errno, $errstr, 30);
  89. if ($fp){
  90. $serverIsRunning = 1;
  91. fclose($fp);
  92. } else {
  93. $serverIsRunning = 0;
  94. }
  95.  
  96. // output
  97. ?>
  98. <?php
  99. function removePrefix(array $input) {
  100.  
  101. $return = array();
  102. foreach ($input as $key => $value) {
  103. if (strpos($key, 'Info' ) === 0)
  104. $key = substr($key, 4);
  105.  
  106. if (is_array($value))
  107. $value = removePrefix($value);
  108.  
  109. $return[$key] = $value;
  110. }
  111. return $return;
  112. }
  113.  
  114. $chats = removePrefix($chats);
  115. ?>
  116.  
  117. <html>
  118. <head>
  119. <title>Starbound Server Info</title>
  120. <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
  121. <style type="text/css">
  122. body {
  123. padding-top: 70px;
  124. }
  125. table > tbody > tr > td.server-status {
  126. vertical-align: middle;
  127. }
  128. </style>
  129. <script>
  130. window.onload=function() {
  131. var elem = document.getElementById('users');
  132. var elem = document.getElementById('chat');
  133. elem.scrollTop = elem.scrollHeight;
  134. };
  135. </script>
  136. <META HTTP-EQUIV=Refresh CONTENT="30">
  137. </head>
  138. <body>
  139. <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
  140. <div class="container">
  141. <div class="navbar-header">
  142. <a class="navbar-brand" href="#">Starbound Server Info</a>
  143. </div>
  144. </div>
  145. </div>
  146.  
  147. <div class="container">
  148. <div class="row">
  149. <div class="col-md-12">
  150. <div class="panel panel-default">
  151. <div class="panel-heading"><span class="glyphicon glyphicon-globe"></span> Server</div>
  152. <div class="panel-body">
  153. <table class="table table-condensed table-bordered">
  154. <tbody>
  155. <tr>
  156. <th>Status</th>
  157. <td class="server-status">
  158. <span class="label label-<?php echo ($serverIsRunning == 1) ? 'success' : 'danger' ; ?>">
  159. <?php echo ($serverIsRunning == 1) ? 'Online' : 'Offline' ;?>
  160. <?php if($serverIsRunning == 0) { ?>
  161. <script>
  162. // alert('hello');
  163. // or
  164. //window.open("http://colony-nyan.com/warn.html","alert","width=320,height=50");
  165. // or any type of script you want to run
  166.  
  167. </script>
  168. <?php } ?>
  169. </span>
  170. </td>
  171. </tr>
  172. <tr>
  173. <th>Version</th>
  174. <td><?php echo $logVersion; ?></td>
  175. </tr>
  176. <tr>
  177. <th>IP</th>
  178. <td><?php echo 'www.colony-nyan.com'; ?></td>
  179. </tr>
  180. <tr>
  181. <th>Players Online</th>
  182. <td><?php echo count($clients),'/',$confMax; ?></td>
  183. </tr>
  184. </tbody>
  185. </table>
  186. </div>
  187. </div>
  188. </div>
  189. </div>
  190. <div class="row">
  191. <div class="col-md-12">
  192. <div class="panel panel-default" style="float:left;width:300;">
  193. <div class="panel-heading"><span class="glyphicon glyphicon-user"></span> Players</div>
  194. <div class="panel-body" style="height:400px;overflow:auto;overflow-y:scroll;" id="users">
  195. <?php if (count($clients)): ?>
  196. <table class="table table-condensed table-bordered">
  197. <thead>
  198. </thead>
  199. <tbody>
  200. <?php foreach ($clients as $client => $status): ?>
  201. <tr>
  202. <td>
  203. <?php echo htmlspecialchars($client); ?>
  204. </td>
  205. </tr>
  206. <?php endforeach; ?>
  207. </tbody>
  208. </table>
  209. <?php else: ?>
  210. No active players
  211. <?php endif; ?>
  212. </div>
  213. </div>
  214. <div class="panel panel-default">
  215. <div class="panel-heading">&nbsp&nbsp&nbsp<span class="glyphicon glyphicon-user"></span> Chat</div>
  216. <div class="panel-body" style="height:400px;overflow:auto;overflow-y:scroll;" id="chat">
  217. <?php if (count($chats)): ?>
  218. <table class="table table-condensed table-bordered">
  219. <thead>
  220. </thead>
  221. <tbody>
  222. <?php foreach ($chats as $Convo): ?>
  223. <tr>
  224. <td>
  225. <?php echo htmlspecialchars($Convo); ?>
  226. </td>
  227. </tr>
  228. <?php endforeach; ?>
  229. </tbody>
  230. </table>
  231. <?php else: ?>
  232. No active chats
  233. <?php endif; ?>
  234. </div>
  235. </div>
  236. </div>
  237. </div>
  238.  
  239. <div class="row">
  240. <div class="col-md-12">
  241. <span class="label label-default">
  242. Parse time: <?php echo microtime() - $parseTimeStart; ?> seconds.
  243. </span>
  244. </div>
  245. </div>
  246.  
  247. </div>
  248. </body>
  249. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement