mirror of https://github.com/nostar/urfd.git
commit
ddc9ca62f6
@ -0,0 +1,6 @@
|
||||
RewriteEngine On
|
||||
RewriteBase /json/
|
||||
RewriteRule ^index\\.php$ - [L]
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule . /json/index.php [L]
|
||||
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/pgs/functions.php")) require_once($_SERVER['DOCUMENT_ROOT'] . "/pgs/functions.php");
|
||||
if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/pgs/config.inc.php")) require_once($_SERVER['DOCUMENT_ROOT'] . "/pgs/config.inc.php");
|
||||
|
||||
if (!class_exists('ParseXML')) require_once($_SERVER['DOCUMENT_ROOT'] . "/pgs/class.parsexml.php");
|
||||
if (!class_exists('Node')) require_once($_SERVER['DOCUMENT_ROOT'] . "/pgs/class.node.php");
|
||||
if (!class_exists('xReflector')) require_once($_SERVER['DOCUMENT_ROOT'] . "/pgs/class.reflector.php");
|
||||
if (!class_exists('Station')) require_once($_SERVER['DOCUMENT_ROOT'] . "/pgs/class.station.php");
|
||||
if (!class_exists('Peer')) require_once($_SERVER['DOCUMENT_ROOT'] . "/pgs/class.peer.php");
|
||||
|
||||
$Reflector = new xReflector();
|
||||
$Reflector->SetXMLFile($Service['XMLFile']);
|
||||
$Reflector->SetPIDFile($Service['PIDFile']);
|
||||
$Reflector->LoadXML();
|
||||
$Reflector->SetFlagFile($_SERVER['DOCUMENT_ROOT'] . "/pgs/country.csv");
|
||||
$Reflector->LoadFlags();
|
||||
|
||||
$Request = $_SERVER['REQUEST_URI'];
|
||||
$ViewDir = '/views/';
|
||||
|
||||
switch ($Request) {
|
||||
case '/json/links':
|
||||
require __DIR__ . $ViewDir . 'links.php';
|
||||
break;
|
||||
|
||||
case '/json/metadata':
|
||||
require __DIR__ . $ViewDir . 'metadata.php';
|
||||
break;
|
||||
|
||||
case '/json/modulesinuse':
|
||||
require __DIR__ . $ViewDir . 'modulesinuse.php';
|
||||
break;
|
||||
|
||||
case '/json/peers':
|
||||
require __DIR__ . $ViewDir . 'peers.php';
|
||||
break;
|
||||
|
||||
case '/json/reflector':
|
||||
require __DIR__ . $ViewDir . 'reflector.php';
|
||||
break;
|
||||
|
||||
case '/json/stations':
|
||||
require __DIR__ . $ViewDir . 'stations.php';
|
||||
break;
|
||||
|
||||
case '/json/status':
|
||||
require __DIR__ . $ViewDir . 'status.php';
|
||||
break;
|
||||
|
||||
default:
|
||||
header('Content-Type: text/plain');
|
||||
http_response_code(404);
|
||||
echo('404 page not found');
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*** Add links to payload ***/
|
||||
for ($i=0;$i<$Reflector->NodeCount();$i++) {
|
||||
|
||||
// craft payload array
|
||||
$payload[$i] = array(
|
||||
'callsign' => $Reflector->Nodes[$i]->GetCallSign() . ' ' . $Reflector->Nodes[$i]->GetSuffix(),
|
||||
'ip' => $Reflector->Nodes[$i]->GetIP(),
|
||||
'linkedmodule' => $Reflector->Nodes[$i]->GetLinkedModule(),
|
||||
'protocol' => $Reflector->Nodes[$i]->GetProtocol(),
|
||||
'connecttime' => gmdate('Y-m-d\TH:i:sp', $Reflector->Nodes[$i]->GetConnectTime()),
|
||||
'lastheardtime' => gmdate('Y-m-d\TH:i:sp', $Reflector->Nodes[$i]->GetLastHeardTime())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// json encode payload array
|
||||
$records = json_encode($payload);
|
||||
|
||||
echo $records;
|
||||
|
||||
?>
|
||||
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
$Url = @parse_url($CallingHome['MyDashBoardURL']);
|
||||
$Net4 = @dns_get_record($Url['host'], DNS_A);
|
||||
$Net6 = @dns_get_record($Url['host'], DNS_AAAA);
|
||||
|
||||
/*** add metadata to payload ***/
|
||||
$payload = array(
|
||||
'dashboard_version' => $PageOptions['DashboardVersion'],
|
||||
'ipV4' => @$Net4[0]['ip'],
|
||||
'ipV6' => @$Net6[0]['ipv6'],
|
||||
'reflector_callsign' => str_replace("XLX", "URF", $Reflector->GetReflectorName()),
|
||||
'reflector_version' => $Reflector->GetVersion(),
|
||||
'sysop_email' => $PageOptions['ContactEmail']
|
||||
);
|
||||
|
||||
|
||||
// json encode payload array
|
||||
$records = json_encode($payload);
|
||||
|
||||
echo $records;
|
||||
|
||||
?>
|
||||
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
$Modules = $Reflector->GetModules();
|
||||
sort($Modules, SORT_STRING);
|
||||
|
||||
|
||||
/*** Add modules to payload ***/
|
||||
for ($i=0;$i<count($Modules);$i++) {
|
||||
|
||||
$payload[$i] = array(
|
||||
'name' => $Modules[$i]
|
||||
);
|
||||
|
||||
$Users = $Reflector->GetNodesInModulesByID($Modules[$i]);
|
||||
|
||||
for ($j=0;$j<count($Users);$j++) {
|
||||
|
||||
$payload[$i]['callsigns'][$j] = $Reflector->GetCallsignAndSuffixByID($Users[$j]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// json encode payload array
|
||||
$records = json_encode($payload);
|
||||
|
||||
echo $records;
|
||||
|
||||
?>
|
||||
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/*** Add links to payload ***/
|
||||
for ($i=0;$i<$Reflector->PeerCount();$i++) {
|
||||
|
||||
$payload[$i] = array(
|
||||
'callsign' => $Reflector->Peers[$i]->GetCallSign(),
|
||||
'ip' => $Reflector->Peers[$i]->GetIP(),
|
||||
'linkedmodule' => $Reflector->Peers[$i]->GetLinkedModule(),
|
||||
'connecttime' => gmdate('Y-m-d\TH:i:sp', $Reflector->Peers[$i]->GetConnectTime()),
|
||||
'lastheardtime' => gmdate('Y-m-d\TH:i:sp', $Reflector->Peers[$i]->GetLastHeardTime())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// json encode payload array
|
||||
$records = json_encode($payload);
|
||||
|
||||
echo $records;
|
||||
|
||||
?>
|
||||
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
$Status = (file_exists($Service['PIDFile'])) ? 'up' : 'down';
|
||||
|
||||
$payload = array(
|
||||
'lastupdatechecktime' => date('Y-m-d\TH:i:sp', time()),
|
||||
'status' => $Status,
|
||||
'uptime' => $Reflector->GetServiceUptime()
|
||||
);
|
||||
|
||||
|
||||
/*** add data to payload ***/
|
||||
$payload['data'] = array(
|
||||
'filetime' => date('Y-m-d\TH:i:sp', filemtime($Service['XMLFile'])),
|
||||
'callsign' => str_replace("XLX", "URF", $Reflector->GetReflectorName()),
|
||||
'version' => $Reflector->GetVersion()
|
||||
);
|
||||
|
||||
|
||||
/*** Add peers to payload ***/
|
||||
for ($i=0;$i<$Reflector->PeerCount();$i++) {
|
||||
|
||||
$payload['data']['peers'][] = array(
|
||||
'callsign' => $Reflector->Peers[$i]->GetCallSign(),
|
||||
'ip' => $Reflector->Peers[$i]->GetIP(),
|
||||
'linkedmodule' => $Reflector->Peers[$i]->GetLinkedModule(),
|
||||
'connecttime' => date('Y-m-d\TH:i:sp', $Reflector->Peers[$i]->GetConnectTime()),
|
||||
'lastheardtime' => date('Y-m-d\TH:i:sp', $Reflector->Peers[$i]->GetLastHeardTime())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*** Add nodes to payload ***/
|
||||
for ($i=0;$i<$Reflector->NodeCount();$i++) {
|
||||
|
||||
// craft payload array
|
||||
$payload['data']['nodes'][] = array(
|
||||
'callsign' => $Reflector->Nodes[$i]->GetCallSign() . ' ' . $Reflector->Nodes[$i]->GetSuffix(),
|
||||
'ip' => $Reflector->Nodes[$i]->GetIP(),
|
||||
'linkedmodule' => $Reflector->Nodes[$i]->GetLinkedModule(),
|
||||
'protocol' => $Reflector->Nodes[$i]->GetProtocol(),
|
||||
'connecttime' => gmdate('Y-m-d\TH:i:sp', $Reflector->Nodes[$i]->GetConnectTime()),
|
||||
'lastheardtime' => gmdate('Y-m-d\TH:i:sp', $Reflector->Nodes[$i]->GetLastHeardTime())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*** Add stations to payload ***/
|
||||
for ($i=0;$i<$Reflector->StationCount();$i++) {
|
||||
|
||||
// craft payload array
|
||||
$payload['data']['stations'][] = array(
|
||||
'callsign' => $Reflector->Stations[$i]->GetCallSign(),
|
||||
'vianode' => $Reflector->Stations[$i]->GetVia(),
|
||||
'onmodule' => $Reflector->Stations[$i]->GetModule(),
|
||||
'viapeer' => $Reflector->Stations[$i]->GetPeer(),
|
||||
'lastheardtime' => gmdate('Y-m-d\TH:i:sp', $Reflector->Stations[$i]->GetLastHeardTime())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// json encode payload array
|
||||
$records = json_encode($payload);
|
||||
|
||||
echo $records;
|
||||
|
||||
?>
|
||||
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/*** Add stations to payload ***/
|
||||
for ($i=0;$i<$Reflector->StationCount();$i++) {
|
||||
|
||||
$tmp = preg_split('/\s+/', $Reflector->Stations[$i]->GetCallSign(), -1, PREG_SPLIT_NO_EMPTY);
|
||||
$Callsign = $tmp[0];
|
||||
|
||||
$tmp = preg_split('/\s+/', $Reflector->Stations[$i]->GetVia(), -1, PREG_SPLIT_NO_EMPTY);
|
||||
$CallsignSuffix = $tmp[1];
|
||||
|
||||
// craft payload array
|
||||
$payload['stations'][$i] = array(
|
||||
'callsign' => $Callsign,
|
||||
'callsignsuffix' => $CallsignSuffix,
|
||||
'vianode' => $Reflector->Stations[$i]->GetVia(),
|
||||
'onmodule' => $Reflector->Stations[$i]->GetModule(),
|
||||
'lastheard' => gmdate('Y-m-d\TH:i:sp', $Reflector->Stations[$i]->GetLastHeardTime())
|
||||
);
|
||||
|
||||
list ($CountryCode, $Country) = $Reflector->GetFlag($Reflector->Stations[$i]->GetCallSign());
|
||||
|
||||
$payload['stations'][$i]['country'] = array (
|
||||
'country' => $Country,
|
||||
'countrycode' => $CountryCode
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// json encode payload array
|
||||
$records = json_encode($payload);
|
||||
|
||||
echo $records;
|
||||
|
||||
?>
|
||||
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
$ReflectorStatus = (file_exists($Service['PIDFile'])) ? 'up' : 'down';
|
||||
|
||||
$payload = array(
|
||||
'lastupdate' => gmdate('U', time()),
|
||||
'lasturfdupdate' => gmdate('U', filemtime($Service['XMLFile'])),
|
||||
'reflectorstatus' => $ReflectorStatus,
|
||||
'reflectoruptimeseconds' => $Reflector->GetServiceUptime()
|
||||
);
|
||||
|
||||
|
||||
// json encode payload array
|
||||
$records = json_encode($payload);
|
||||
|
||||
echo $records;
|
||||
|
||||
?>
|
||||
Loading…
Reference in new issue