From 876c6ad1d2b165199ea03cb09ff77e199230ba35 Mon Sep 17 00:00:00 2001 From: cornernote Date: Mon, 31 Oct 2016 10:17:06 +1030 Subject: [PATCH] begin making server page --- composer.json | 3 +- src/controllers/ServerController.php | 58 ++++++++++++++++++++++++++++ src/views/server/index.php | 55 ++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 src/controllers/ServerController.php create mode 100644 src/views/server/index.php diff --git a/composer.json b/composer.json index 6875b88..42659ad 100644 --- a/composer.json +++ b/composer.json @@ -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": "*", diff --git a/src/controllers/ServerController.php b/src/controllers/ServerController.php new file mode 100644 index 0000000..458a725 --- /dev/null +++ b/src/controllers/ServerController.php @@ -0,0 +1,58 @@ +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'); + } + +} diff --git a/src/views/server/index.php b/src/views/server/index.php new file mode 100644 index 0000000..9f8a12b --- /dev/null +++ b/src/views/server/index.php @@ -0,0 +1,55 @@ +title = 'Servers'; +$this->params['breadcrumbs'][] = $this->title; +?> + +
+ + + + + \ No newline at end of file