Ported (go/gin) json api from gomrefdash (https://github.com/kc1awv/gomrefdash) to (php/apache) urfd dashboard. This provides consistency between mrefd and urfd reflector dashboards and is intended to accelerate integration with dvref.com for an official URFD reflector registry.

Updated dashboard version to 2.5.0 to help reflector admins determine compatibility with eventual dvref.com integration (>= 2.5.0).

It has been extensively tested and is currently running on https://urf847.kk7mnz.com/json/reflector

dvref.com integration has been tested at https://dvref.com/mrefd/m17-847
This commit is contained in:
mfiscus committed 2023-11-26 13:50:16 -07:00
1 parent 6aa57a784d
commit 72a0a337f6
10 files changed
+293 -1

No files matched your search

+6
View File
@@ -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]
+63
View File
@@ -0,0 +1,63 @@
<?php
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
date_default_timezone_set("UTC");
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');
}
?>
+24
View File
@@ -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' => date('Y-m-d\TH:i:sp', $Reflector->Nodes[$i]->GetConnectTime()),
'lastheardtime' => date('Y-m-d\TH:i:sp', $Reflector->Nodes[$i]->GetLastHeardTime())
);
}
// json encode payload array
$records = json_encode($payload);
echo $records;
?>
+23
View File
@@ -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;
?>
+30
View File
@@ -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;
?>
+22
View File
@@ -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' => date('Y-m-d\TH:i:sp', $Reflector->Peers[$i]->GetConnectTime()),
'lastheardtime' => date('Y-m-d\TH:i:sp', $Reflector->Peers[$i]->GetLastHeardTime())
);
}
// json encode payload array
$records = json_encode($payload);
echo $records;
?>
+70
View File
@@ -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' => date('Y-m-d\TH:i:sp', $Reflector->Nodes[$i]->GetConnectTime()),
'lastheardtime' => date('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' => date('Y-m-d\TH:i:sp', $Reflector->Stations[$i]->GetLastHeardTime())
);
}
// json encode payload array
$records = json_encode($payload);
echo $records;
?>
+36
View File
@@ -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' => date('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;
?>
+18
View File
@@ -0,0 +1,18 @@
<?php
$ReflectorStatus = (file_exists($Service['PIDFile'])) ? 'up' : 'down';
$payload = array(
'lastupdate' => date('U', time()),
'lasturfdupdate' => date('U', filemtime($Service['XMLFile'])),
'reflectorstatus' => $ReflectorStatus,
'reflectoruptimeseconds' => $Reflector->GetServiceUptime()
);
// json encode payload array
$records = json_encode($payload);
echo $records;
?>
+1 -1
View File
@@ -16,7 +16,7 @@ $PageOptions = array();
$PageOptions['ContactEmail'] = 'your_email'; // Support E-Mail address
$PageOptions['DashboardVersion'] = '2.4.1'; // Dashboard Version
$PageOptions['DashboardVersion'] = '2.5.0'; // Dashboard Version
$PageOptions['PageRefreshActive'] = true; // Activate automatic refresh
$PageOptions['PageRefreshDelay'] = '10000'; // Page refresh time in miliseconds