begin making server page
This commit is contained in:
parent
687ae5c384
commit
876c6ad1d2
@ -15,7 +15,8 @@
|
||||
"bigpaulie/yii2-fancybox": "^1.0",
|
||||
"knplabs/github-api": "^1.4",
|
||||
"vlucas/phpdotenv": "^2.0",
|
||||
"kartik-v/yii2-detail-view": "^1.7"
|
||||
"kartik-v/yii2-detail-view": "^1.7",
|
||||
"geoip/geoip": "~1.15"
|
||||
},
|
||||
"require-dev": {
|
||||
"yiisoft/yii2-debug": "*",
|
||||
|
58
src/controllers/ServerController.php
Normal file
58
src/controllers/ServerController.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace app\controllers;
|
||||
|
||||
use DOMDocument;
|
||||
use Yii;
|
||||
use yii\web\Controller;
|
||||
|
||||
/**
|
||||
* Class PackageController
|
||||
* @package app\controllers
|
||||
*/
|
||||
class ServerController extends Controller
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
// get server results from servers.minetest.ru
|
||||
$dom = new DOMDocument();
|
||||
$dom->preserveWhiteSpace = false;
|
||||
$html = $dom->loadHTMLFile('http://servers.minetest.net/');
|
||||
$tables = $dom->getElementsByTagName('table');
|
||||
$rows = $tables->item(0)->getElementsByTagName('tr');
|
||||
$results = array();
|
||||
foreach ($rows as $row) {
|
||||
$cols = $row->getElementsByTagName('td');
|
||||
$result = array();
|
||||
foreach ($cols as $col) {
|
||||
$result[] = $col->nodeValue;
|
||||
}
|
||||
$results[] = $result;
|
||||
}
|
||||
|
||||
// extract the server info
|
||||
$gi = geoip_open("GeoLiteCity.dat", GEOIP_STANDARD);
|
||||
$servers = array();
|
||||
foreach ($results as $result) {
|
||||
if (!$result) continue;
|
||||
list($host, $port) = explode(':', $result[0]);
|
||||
$geoip = geoip_record_by_addr($gi, gethostbyname($host));
|
||||
if (!$geoip) continue;
|
||||
$servers[] = array(
|
||||
'name' => $result[3],
|
||||
'host' => $host,
|
||||
'port' => $port,
|
||||
'lat' => $geoip->latitude,
|
||||
'lon' => $geoip->longitude,
|
||||
'site' => $result[2],
|
||||
'uptime' => $result[6],
|
||||
);
|
||||
}
|
||||
|
||||
return $this->render('index');
|
||||
}
|
||||
|
||||
}
|
55
src/views/server/index.php
Normal file
55
src/views/server/index.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Brett
|
||||
* Date: 30/10/2015
|
||||
* Time: 7:31 PM
|
||||
*/
|
||||
|
||||
$this->title = 'Servers';
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
|
||||
<div id="map_canvas" style="width:100%; height:100%"></div>
|
||||
|
||||
<style type="text/css">
|
||||
html {
|
||||
height: 100%
|
||||
}
|
||||
|
||||
body {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0
|
||||
}
|
||||
|
||||
#map_canvas {
|
||||
height: 100%
|
||||
}
|
||||
</style>
|
||||
|
||||
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyA6aXUYnpxJTCdvHwVRK24Sc-fx28Z4gXc&sensor=false"></script>
|
||||
<script type="text/javascript">
|
||||
function initialize() {
|
||||
var myLatlng = new google.maps.LatLng(-25.363882, 131.044922);
|
||||
var mapOptions = {
|
||||
zoom: 3,
|
||||
center: myLatlng,
|
||||
mapTypeId: google.maps.MapTypeId.ROADMAP
|
||||
};
|
||||
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
|
||||
var infowindow = new google.maps.InfoWindow();
|
||||
<?php foreach ($servers as $k=>$server) { ?>
|
||||
var marker_<?php echo $k; ?> = new google.maps.Marker({
|
||||
position: new google.maps.LatLng(<?php echo $server['lat']; ?>, <?php echo $server['lon']; ?>),
|
||||
title: '<?php echo addslashes($server['name']); ?>',
|
||||
map: map
|
||||
});
|
||||
google.maps.event.addListener(marker_<?php echo $k; ?>, 'click', function () {
|
||||
infowindow.setContent('<strong><a href="<?php echo $server['site']; ?>"><?php echo addslashes($server['name']); ?></a></strong><br/><?php echo $server['host']; ?>:<?php echo $server['port']; ?><br/><br/>Uptime: <?php echo $server['uptime']; ?>');
|
||||
infowindow.open(map, marker_<?php echo $k; ?>);
|
||||
});
|
||||
<?php } ?>
|
||||
initialize();
|
||||
}
|
||||
</script>
|
Loading…
x
Reference in New Issue
Block a user