2009-12-29 12:54:46 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
Copyright 2009 Pieter Iserbyt
|
|
|
|
|
|
|
|
This file is part of Pamela.
|
|
|
|
|
|
|
|
Pamela is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Pamela is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Pamela. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
header("Content-type: application/javascript");
|
|
|
|
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
|
|
header("Cache-Control: no-cache");
|
|
|
|
header("Pragma: no-cache");
|
|
|
|
|
|
|
|
require_once("config.php");
|
|
|
|
require_once("lib/util.php");
|
2010-02-12 22:24:19 +00:00
|
|
|
require_once("lib/trans.php");
|
2009-12-29 12:54:46 +00:00
|
|
|
|
|
|
|
// [ "00:01:e8:04:99:be", "00:05:4e:40:1e:97", "00:0c:f1:16:10:ba", "00:0c:f1:1d:dc:70", "00:0e:35:96:c7:ff", "00:11:85:6a:1f:ec", ]
|
|
|
|
|
2010-02-12 22:24:19 +00:00
|
|
|
|
|
|
|
function translator($mac) {
|
|
|
|
global $mac_translation_table;
|
|
|
|
if (array_key_exists($mac, $mac_translation_table))
|
|
|
|
return $mac_translation_table[$mac];
|
|
|
|
return $mac;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-29 12:54:46 +00:00
|
|
|
class Macs {
|
|
|
|
|
|
|
|
private $macs;
|
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
$this->macs = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function readFile($filename) {
|
|
|
|
$mcs = file_get_contents($filename);
|
2009-12-29 21:53:31 +00:00
|
|
|
$this->macs = array_merge($this->macs, explode(',', $mcs));
|
2009-12-29 12:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function readFiles($directory) {
|
|
|
|
$macFiles = scandir($directory);
|
|
|
|
foreach ($macFiles as $macFile) {
|
2009-12-29 21:53:31 +00:00
|
|
|
if (preg_match("/.+\.macs$/", $macFile) != 1)
|
2009-12-29 12:54:46 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
$filename = "$directory/$macFile";
|
|
|
|
|
|
|
|
// data is too old, remove
|
|
|
|
if (filemtime($filename) + MACFILE_TTL < time()) {
|
|
|
|
unlink($filename);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->readFile($filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function cleanUp() {
|
|
|
|
$this->macs = array_unique($this->macs);
|
|
|
|
}
|
2010-02-12 22:24:19 +00:00
|
|
|
|
|
|
|
private function translate() {
|
|
|
|
$this->macs = array_map("translator", $this->macs);
|
|
|
|
}
|
2009-12-29 12:54:46 +00:00
|
|
|
|
|
|
|
private function createJson() {
|
2009-12-29 21:53:31 +00:00
|
|
|
if (count($this->macs) < 1) {
|
|
|
|
echo '[]';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-29 12:54:46 +00:00
|
|
|
echo '["';
|
|
|
|
echo implode('", "', $this->macs);
|
|
|
|
echo '"]';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function run() {
|
|
|
|
$this->readFiles(OUTPUT_SERVER_DIRECTORY);
|
|
|
|
$this->cleanUp();
|
2010-02-12 22:24:19 +00:00
|
|
|
$this->translate();
|
2009-12-29 12:54:46 +00:00
|
|
|
$this->createJson();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$macs = new Macs();
|
|
|
|
$macs->run();
|