-
-
Save Samuell1/23b4fd527f46cdca1e63 to your computer and use it in GitHub Desktop.
Revisions
-
dkesberg revised this gist
Dec 15, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ <?php /** * @author Daniel Kesberg <kesberg@gmail.com> * @copyright (c) 2013, Daniel Kesberg */ -
dkesberg revised this gist
Dec 15, 2013 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,15 +29,16 @@ // only keep lines with client info $logClients = array_filter($logLines, function($line) { return preg_match('/^Info:.*Client/', $line); }); // extract clients $clients = array(); foreach ($logClients as $line) { if (preg_match('/.*?\\\'(.*)\\\'.*?\(.*?\)(.*)/i', $line, $matches) == 1) { if (strlen($matches[1])) { $clientName = htmlentities(trim($matches[1])); $clients[$clientName] = trim($matches[2]); } } } -
dkesberg revised this gist
Dec 13, 2013 . 1 changed file with 32 additions and 32 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ 'server' => array( 'hostname' => '127.0.0.1', 'port' => 21025 ), 'paths' => array( 'log' => '/home/starbound-server/Steam/SteamApps/common/Starbound/linux64/starbound_server.log' ) @@ -29,22 +29,22 @@ // only keep lines with client info $logClients = array_filter($logLines, function($line) { return preg_match('/^Info:.*<User/', $line); }); // extract clients $clients = array(); foreach ($logClients as $line) { if (preg_match('/<User: ([0-9a-zA-Z-\s]*)>\s+([a-z].*)/i', $line, $matches) == 1) { if (strlen($matches[1])) { $clients[$matches[1]] = trim($matches[2]); } } } // only keep "connected" status $clients = array_filter($clients, function($status) { return trim($status) == 'connected'; }); // sort @@ -105,22 +105,22 @@ <tr> <th>Status</th> <td class="server-status"> <span class="label label-<?php echo ($serverIsRunning == 1) ? 'success' : 'danger' ; ?>"> <?php echo ($serverIsRunning == 1) ? 'Online' : 'Offline' ; ?> </span> </td> </tr> <tr> <th>Version</th> <td><?php echo $logVersion; ?></td> </tr> <tr> <th>IP</th> <td><?php echo $_SERVER['SERVER_ADDR']; ?></td> </tr> <tr> <th>Players Online</th> <td><?php echo count($clients); ?></td> </tr> </tbody> </table> @@ -133,23 +133,23 @@ <div class="panel panel-default"> <div class="panel-heading"><span class="glyphicon glyphicon-user"></span> Players</div> <div class="panel-body"> <?php if (count($clients)): ?> <table class="table table-condensed table-bordered"> <thead> <tr> <th>Playername</th> </tr> </thead> <tbody> <?php foreach ($clients as $client => $status): ?> <tr> <td> <?php echo $client; ?> </td> </tr> <?php endforeach; ?> </tbody> </table> <?php else: ?> No active players <?php endif; ?> @@ -160,7 +160,7 @@ <div class="row"> <div class="col-md-12"> <span class="label label-default"> Parse time: <?php echo microtime() - $parseTimeStart; ?> seconds. </span> </div> </div> -
dkesberg revised this gist
Dec 12, 2013 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -47,6 +47,9 @@ return trim($status) == 'connected'; }); // sort ksort($clients); // get server version $logVersion = array_filter($logLines, function($line) { return preg_match('/^Info: Server version/', $line); -
dkesberg revised this gist
Dec 12, 2013 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,14 +37,14 @@ foreach ($logClients as $line) { if (preg_match('/<User: ([0-9a-zA-Z-\s]*)>\s+([a-z].*)/i', $line, $matches) == 1) { if (strlen($matches[1])) { $clients[$matches[1]] = trim($matches[2]); } } } // only keep "connected" status $clients = array_filter($clients, function($status) { return trim($status) == 'connected'; }); // get server version @@ -110,6 +110,10 @@ <tr> <th>Version</th> <td><?= $logVersion; ?></td> </tr> <tr> <th>IP</th> <td><?= $_SERVER['SERVER_ADDR']; ?></td> </tr> <tr> <th>Players Online</th> -
dkesberg revised this gist
Dec 12, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ */ error_reporting(E_ALL); ini_set('display_errors', false); $parseTimeStart = microtime(); -
dkesberg renamed this gist
Dec 12, 2013 . 1 changed file with 7 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,8 @@ * @copyright (c) 2013, Daniel Kesberg */ error_reporting(E_ALL); ini_set('display_errors', true); $parseTimeStart = microtime(); @@ -34,13 +35,11 @@ // extract clients $clients = array(); foreach ($logClients as $line) { if (preg_match('/<User: ([0-9a-zA-Z-\s]*)>\s+([a-z].*)/i', $line, $matches) == 1) { if (strlen($matches[1])) { $clients[$matches[1]] = $matches[2]; } } } // only keep "connected" status -
dkesberg revised this gist
Dec 12, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ * @copyright (c) 2013, Daniel Kesberg */ ini_set('display_errors', false); $parseTimeStart = microtime(); @@ -103,7 +103,7 @@ <tr> <th>Status</th> <td class="server-status"> <span class="label label-<?= ($serverIsRunning == 1) ? 'success' : 'danger' ; ?>"> <?= ($serverIsRunning == 1) ? 'Online' : 'Offline' ; ?> </span> </td> -
dkesberg revised this gist
Dec 12, 2013 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,8 +4,7 @@ * @copyright (c) 2013, Daniel Kesberg */ error_reporting(0); $parseTimeStart = microtime(); -
dkesberg revised this gist
Dec 12, 2013 . 1 changed file with 11 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,9 @@ * @copyright (c) 2013, Daniel Kesberg */ error_reporting(E_ALL); ini_set('display_errors', true); $parseTimeStart = microtime(); // load config @@ -76,6 +79,9 @@ body { padding-top: 70px; } table > tbody > tr > td.server-status { vertical-align: middle; } </style> </head> <body> @@ -97,7 +103,11 @@ <tbody> <tr> <th>Status</th> <td class="server-status"> <span class="label label-<?= ($serverIsRunning == 1) ? 'success' : 'error' ; ?>"> <?= ($serverIsRunning == 1) ? 'Online' : 'Offline' ; ?> </span> </td> </tr> <tr> <th>Version</th> -
dkesberg revised this gist
Dec 12, 2013 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,8 +7,7 @@ $parseTimeStart = microtime(); // load config // Set paths.log to the full path of the log file $config = array( 'server' => array( 'hostname' => '127.0.0.1', -
dkesberg revised this gist
Dec 12, 2013 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,11 @@ // $config = require_once __DIR__ . '/../app/config/app.php'; // Set this to the full path of the log file $config = array( 'server' => array( 'hostname' => '127.0.0.1', 'port' => 21025 ), 'paths' => array( 'log' => '/home/starbound-server/Steam/SteamApps/common/Starbound/linux64/starbound_server.log' ) ); @@ -55,7 +59,7 @@ // server is running ? // edit: removed shell cmd, stole fsockopen from https://gist.github.com/lagonnebula/7928214 ;) $fp = fsockopen($config['server']['hostname'], $config['server']['port'], $errno, $errstr, 30); if ($fp){ $serverIsRunning = 1; fclose($fp); -
dkesberg revised this gist
Dec 12, 2013 . 1 changed file with 8 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -54,16 +54,14 @@ $logVersion = $tmp[1]; // server is running ? // edit: removed shell cmd, stole fsockopen from https://gist.github.com/lagonnebula/7928214 ;) $fp = fsockopen('127.0.0.1', 21025, $errno, $errstr, 30); if ($fp){ $serverIsRunning = 1; fclose($fp); } else { $serverIsRunning = 0; } // output ?> -
dkesberg revised this gist
Dec 12, 2013 . 1 changed file with 73 additions and 26 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,21 +15,20 @@ ) ); // read logfile $log = file_get_contents($config['paths']['log']); // split into lines $logLines = explode("\n", $log); // only keep lines with client info $logClients = array_filter($logLines, function($line) { return preg_match('/^Info:.*<User/', $line); }); // extract clients $clients = array(); foreach ($logClients as $line) { $tmp = explode('<User: ', $line); $tmp = str_replace('>','', $tmp[1]); $tmp = explode(' ', $tmp); @@ -44,16 +43,37 @@ return $status == 'connected'; }); // get server version $logVersion = array_filter($logLines, function($line) { return preg_match('/^Info: Server version/', $line); }); // only look at the last line $logVersion = end($logVersion); $tmp = explode("'", $logVersion); $logVersion = $tmp[1]; // server is running ? // this is just a quick and dirty way // you dont actually want to exec shell commands in php // and if your server is in safe_mode (which it should be) it might not even be possible to run this // the better way would be to set up a cron job with: // netstat -at | grep :21025 | grep LISTEN | wc -l > path/to/log/directory/server_status.log // and then have the php script read the log file // $serverIsRunning = intval(trim(file_get_contents('path/to/log/directory/server_status.log'))); $cmdRunning = 'netstat -at | grep :21025 | grep LISTEN | wc -l'; exec($cmdRunning, $serverIsRunning); $serverIsRunning = intval($serverIsRunning[0]); // output ?> <html> <head> <title>Starbound Server Info</title> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"> <style type="text/css"> body { padding-top: 70px; } </style> </head> @@ -69,31 +89,58 @@ <div class="container"> <div class="row"> <div class="col-md-12"> <div class="panel panel-default"> <div class="panel-heading"><span class="glyphicon glyphicon-globe"></span> Server</div> <div class="panel-body"> <table class="table table-condensed table-bordered"> <tbody> <tr> <th>Status</th> <td><?= ($serverIsRunning == 1) ? 'Online' : 'Offline' ; ?></td> </tr> <tr> <th>Version</th> <td><?= $logVersion; ?></td> </tr> <tr> <th>Players Online</th> <td><?= count($clients); ?></td> </tr> </tbody> </table> </div> </div> </div> </div> <div class="row"> <div class="col-md-12"> <div class="panel panel-default"> <div class="panel-heading"><span class="glyphicon glyphicon-user"></span> Players</div> <div class="panel-body"> <?php if (count($clients)): ?> <table class="table table-condensed table-bordered"> <thead> <tr> <th>Playername</th> </tr> </thead> <tbody> <?php foreach ($clients as $client => $status): ?> <tr> <td> <?= $client; ?> </td> </tr> <?php endforeach; ?> </tbody> </table> <?php else: ?> No active players <?php endif; ?> </div> </div> </div> </div> <div class="row"> <div class="col-md-12"> <span class="label label-default"> -
dkesberg created this gist
Dec 12, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,106 @@ <?php /** * @author Daniel Kesberg <[email protected]> * @copyright (c) 2013, Daniel Kesberg */ $parseTimeStart = microtime(); // load config // $config = require_once __DIR__ . '/../app/config/app.php'; // Set this to the full path of the log file $config = array( 'paths' => array( 'log' => '/home/starbound-server/Steam/SteamApps/common/Starbound/linux64/starbound_server.log' ) ); $clients = array(); // read logfile $log = file_get_contents($config['paths']['log']); // split into lines $log = explode("\n", $log); // only keep lines with client info $log = array_filter($log, function($line) { return preg_match('/^Info:.*<User/', $line); }); // extract clients foreach ($log as $line) { $tmp = explode('<User: ', $line); $tmp = str_replace('>','', $tmp[1]); $tmp = explode(' ', $tmp); if (count($tmp) == 2) { $clients[$tmp[0]] = $tmp[1]; } } // only keep "connected" status $clients = array_filter($clients, function($status) { return $status == 'connected'; }); // output // var_dump($clients); ?> <html> <head> <title>Starbound Server Info</title> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"> <style type="text/css"> body { padding-top: 50px; } </style> </head> <body> <div class="navbar navbar-inverse navbar-fixed-top" role="navigation"> <div class="container"> <div class="navbar-header"> <a class="navbar-brand" href="#">Starbound Server Info</a> </div> </div> </div> <div class="container"> <div class="row"> <div class="col-md-12"> <h3>Active Players: <?= count($clients); ?></h3> </div> </div> <?php if (count($clients)): ?> <div class="row"> <div class="col-md-12"> <table class="table table-striped table-bordered"> <thead> <tr> <th>Playername</th> </tr> </thead> <tbody> <?php foreach ($clients as $client => $status): ?> <tr> <td> <?= $client; ?> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> <?php endif; ?> <div class="row"> <div class="col-md-12"> <span class="label label-default"> Parse time: <?= microtime() - $parseTimeStart; ?> seconds. </span> </div> </div> </div> </body> </html>