Merge pull request #6 from M17-Project/cleanup

Code Cleanup - v1.2.0
pull/7/head
Steve Miller 2020-10-27 17:36:14 -04:00 committed by GitHub
commit e7f71b8952
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 163 deletions

View File

@ -1,3 +1,7 @@
v1.2.0
* Code cleanup - remove unneeded parts
* Rename "Repeaters" as "Links"
v1.1.1
* Add in time elapsed for Last Heard - thanks N7TAE

View File

@ -2,6 +2,10 @@
This is the dashboard as seen on [M17-M17 Reflector](https://ref.m17.link) to be used with mrefd.
### Version 1.2.0 - code cleanup
Possible breaking change, a rename of "Repeaters" to "Links" requires use of a new copy of the configuration file to be used. Backup your old config.inc.php and follow the setup process below to update to the new configuration.
### Clone dashboard to /var/www
```bash

View File

@ -292,25 +292,6 @@ class xReflector {
return $out;
}
public function GetModuleOfNode($Node) {
die("FUNCTION DEPRECATED...");
$Node = trim(str_replace(" ", "-", $Node));
$Node = trim(str_replace(" ", "-", $Node));
$Node = trim(str_replace(" ", "-", $Node));
$found = false;
$i = 0;
$Module = "";
while (!$found && $i<$this->NodeCount()) {
if (strpos($Node, $this->Nodes[$i]->GetFullCallsign()) !== false) {
$Module = $this->Nodes[$i]->GetLinkedModule();
$found = true;
}
$i++;
}
return $Module;
}
public function GetCallSignsInModules($Module) {
$out = array();
for ($i=0;$i<$this->NodeCount();$i++) {
@ -331,39 +312,6 @@ class xReflector {
return $out;
}
public function SetCallingHome($CallingHomeVariables, $Hash) {
if (!isset($CallingHomeVariables['Active'])) { $CallingHomeVariables['Active'] = false; }
if (!isset($CallingHomeVariables['MyDashBoardURL'])) { $CallingHomeVariables['MyDashBoardURL'] = ''; }
if (!isset($CallingHomeVariables['ServerURL'])) { $CallingHomeVariables['ServerURL'] = ''; }
if (!isset($CallingHomeVariables['Country'])) { $CallingHomeVariables['Country'] = ''; }
if (!isset($CallingHomeVariables['Comment'])) { $CallingHomeVariables['Comment'] = ''; }
if (!isset($CallingHomeVariables['OverrideIPAddress'])) { $CallingHomeVariables['OverrideIPAddress'] = false; }
if (!isset($CallingHomeVariables['InterlinkFile'])) { $CallingHomeVariables['InterlinkFile'] = ''; }
if (!file_exists($CallingHomeVariables['InterlinkFile'])) {
$this->Interlinkfile = '';
$this->Transferinterlink = false;
}
else {
$this->Transferinterlink = true;
$this->Interlinkfile = $CallingHomeVariables['InterlinkFile'];
}
$this->CallingHomeActive = ($CallingHomeVariables['Active'] === true);
$this->CallingHomeHash = $Hash;
$this->CallingHomeDashboardURL = $CallingHomeVariables['MyDashBoardURL'];
$this->CallingHomeServerURL = $CallingHomeVariables['ServerURL'];
$this->CallingHomeCountry = $CallingHomeVariables['Country'];
$this->CallingHomeComment = $CallingHomeVariables['Comment'];
$this->CallingHomeOverrideIP = $CallingHomeVariables['OverrideIPAddress'];
}
public function PushCallingHome() {
$CallingHome = @fopen($this->CallingHomeServerURL."?ReflectorName=".$this->ReflectorName."&ReflectorUptime=".$this->ServiceUptime."&ReflectorHash=".$this->CallingHomeHash."&DashboardURL=".$this->CallingHomeDashboardURL."&Country=".urlencode($this->CallingHomeCountry)."&Comment=".urlencode($this->CallingHomeComment)."&OverrideIP=".$this->CallingHomeOverrideIP, "r");
}
public function ReadInterlinkFile() {
if (file_exists($this->Interlinkfile) && (is_readable($this->Interlinkfile))) {
$this->Interlinks = array();
@ -418,18 +366,6 @@ class xReflector {
</reflector>';
}
public function CallHome() {
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<query>CallingHome</query>'.$this->ReflectorXML.$this->InterlinkXML;
$p = @stream_context_create(array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query(array('xml' => $xml)) )));
$result = @file_get_contents($this->CallingHomeServerURL, false, $p);
if ($result === false) {
die("CONNECTION FAILED!");
}
}
public function InterlinkCount() {
return count($this->Interlinks);
}

View File

@ -27,10 +27,10 @@ $PageOptions['PageRefreshActive'] = true;
$PageOptions['PageRefreshDelay'] = '10000'; // Page refresh time in miliseconds
$PageOptions['RepeatersPage'] = array();
$PageOptions['RepeatersPage']['LimitTo'] = 99; // Number of Repeaters to show
$PageOptions['RepeatersPage']['IPModus'] = 'ShowLast2ByteOfIP'; // See possible options above
$PageOptions['RepeatersPage']['MasqueradeCharacter'] = '*'; // Character used for masquerade
$PageOptions['LinksPage'] = array();
$PageOptions['LinksPage']['LimitTo'] = 99; // Number of Links to show
$PageOptions['LinksPage']['IPModus'] = 'ShowLast2ByteOfIP'; // See possible options above
$PageOptions['LinksPage']['MasqueradeCharacter'] = '*'; // Character used for masquerade
$PageOptions['PeerPage'] = array();
@ -49,7 +49,7 @@ $PageOptions['ModuleNames']['D'] = '';
$PageOptions['MetaDescription'] = 'MREFD is an M17 Reflector System for Ham Radio Operators.'; // Meta Tag Values, useful for Search Engines
$PageOptions['MetaKeywords'] = 'Ham Radio, M17, XReflector, '; // Meta Tag Values, useful for Search Engines
$PageOptions['MetaAuthor'] = 'N7TAE, KC1AWV'; // Meta Tag Values, useful for Search Engines
$PageOptions['MetaAuthor'] = 'KC1AWV'; // Meta Tag Values, useful for Search Engines
$PageOptions['MetaRevisit'] = 'After 30 Days'; // Meta Tag Values, useful for Search Engines
$PageOptions['MetaRobots'] = 'index,follow'; // Meta Tag Values, useful for Search Engines
@ -58,18 +58,6 @@ $PageOptions['UserPage']['ShowFilter'] = true;
$Service['PIDFile'] = '/var/run/mrefd.pid';
$Service['XMLFile'] = '/var/log/mrefd.xml';
/* Do we really want to keep this? Let's disable it for now.
$CallingHome['Active'] = false; // xlx phone home, true or false
$CallingHome['MyDashBoardURL'] = 'http://your_dashboard'; // dashboard url
$CallingHome['ServerURL'] = 'http://xlxapi.rlx.lu/api.php'; // database server, do not change !!!!
$CallingHome['PushDelay'] = 600; // push delay in seconds
$CallingHome['Country'] = "your_country"; // Country
$CallingHome['Comment'] = "your_comment"; // Comment. Max 100 character
$CallingHome['HashFile'] = "/tmp/callinghome.php"; // Make sure the apache user has read and write permissions in this folder.
$CallingHome['OverrideIPAddress'] = ""; // Insert your IP address here. Leave blank for autodetection. No need to enter a fake address.
$CallingHome['InterlinkFile'] = "/usr/local/etc/mrefd.linklist"; // Path to interlink file
*/
/*
include an extra config file for people who dont like to mess with shipped config.inc.php
this makes updating dashboard from git a little bit easier

View File

@ -3,13 +3,13 @@
<th>#</th>
<th>Flag</th>
<th>DV Station</th>
<th>Band</th>
<th>Via</th>
<th>Last Heard</th>
<th>Linked for</th>
<th>Protocol</th>
<th>Module</th><?php
if ($PageOptions['RepeatersPage']['IPModus'] != 'HideIP') {
if ($PageOptions['LinksPage']['IPModus'] != 'HideIP') {
echo '
<th>IP</th>';
}
@ -29,11 +29,9 @@ for ($i=0;$i<$Reflector->NodeCount();$i++) {
echo '<a href="#" class="tip"><img src="./images/flags/'.$Flag.'.svg" class="table-flag" alt="'.$Name.'"><span>'.$Name.'</span></a>';
}
echo '</td>
<td><a href="http://www.aprs.fi/'.$Reflector->Nodes[$i]->GetCallSign();
if ($Reflector->Nodes[$i]->GetSuffix() != "") echo '-'.$Reflector->Nodes[$i]->GetSuffix();
echo '" class="pl" target="_blank">'.$Reflector->Nodes[$i]->GetCallSign();
<td>'.$Reflector->Nodes[$i]->GetCallSign();
if ($Reflector->Nodes[$i]->GetSuffix() != "") { echo '-'.$Reflector->Nodes[$i]->GetSuffix(); }
echo '</a></td>
echo '</td>
<td>';
if ($Reflector->Nodes[$i]->GetPrefix() == 'M17') {
switch ($Reflector->Nodes[$i]->GetPrefix()) {
@ -45,7 +43,7 @@ for ($i=0;$i<$Reflector->NodeCount();$i++) {
case 'A' : echo '23cm'; break;
case 'B' : echo '70cm'; break;
case 'C' : echo '2m'; break;
case 'D' : echo 'Dongle'; break;
case 'D' : echo 'DV Client'; break;
case 'G' : echo 'Internet-Gateway'; break;
default : echo '';
}
@ -55,12 +53,12 @@ for ($i=0;$i<$Reflector->NodeCount();$i++) {
<td>'.FormatSeconds(time()-$Reflector->Nodes[$i]->GetConnectTime()).' s</td>
<td>'.$Reflector->Nodes[$i]->GetProtocol().'</td>
<td>'.$Reflector->Nodes[$i]->GetLinkedModule().'</td>';
if ($PageOptions['RepeatersPage']['IPModus'] != 'HideIP') {
if ($PageOptions['LinksPage']['IPModus'] != 'HideIP') {
echo '<td>';
$Bytes = explode(".", $Reflector->Nodes[$i]->GetIP());
$MC = $PageOptions['RepeatersPage']['MasqueradeCharacter'];
$MC = $PageOptions['LinksPage']['MasqueradeCharacter'];
if ($Bytes !== false && count($Bytes) == 4) {
switch ($PageOptions['RepeatersPage']['IPModus']) {
switch ($PageOptions['LinksPage']['IPModus']) {
case 'ShowLast1ByteOfIP':
echo $MC.'.'.$MC.'.'.$MC.'.'.$Bytes[3];
break;
@ -87,7 +85,7 @@ for ($i=0;$i<$Reflector->NodeCount();$i++) {
echo '</td>';
}
echo '</tr>';
if ($i == $PageOptions['RepeatersPage']['LimitTo']) { $i = $Reflector->NodeCount()+1; }
if ($i == $PageOptions['LinksPage']['LimitTo']) { $i = $Reflector->NodeCount()+1; }
}
?>

View File

@ -85,7 +85,6 @@ if (isset($_GET['do'])) {
<th>Flag</th>
<th>Callsign</th>
<th>Suffix</th>
<th>DPRS</th>
<th>Via / Peer</th>
<th>Last heard</th>
<th><img src="./images/ear.png" alt="Listening on" /></th>
@ -148,13 +147,12 @@ if (isset($_GET['do'])) {
echo '</td>
<td class="align-middle"><a href="https://www.qrz.com/db/' . $Reflector->Stations[$i]->GetCallsignOnly() . '" class="pl" target="_blank">' . $Reflector->Stations[$i]->GetCallsignOnly() . '</a></td>
<td class="align-middle">' . $Reflector->Stations[$i]->GetSuffix() . '</td>
<td class="align-middle"><a href="http://www.aprs.fi/' . $Reflector->Stations[$i]->GetCallsignOnly() . '" class="pl" target="_blank"><img src="./images/sat.png" alt=""></a></td>
<td class="align-middle">' . $Reflector->Stations[$i]->GetVia();
if ($Reflector->Stations[$i]->GetPeer() != $Reflector->GetReflectorName()) {
echo ' / ' . $Reflector->Stations[$i]->GetPeer();
}
echo '</td>
<td>' . @date("d.m.Y H:i", $Reflector->Stations[$i]->GetLastHeardTime()) . '<br />(about ' . elapsedTime($Reflector->Stations[$i]->GetLastHeardTime()) . ' ago.)</td>
<td>' . @date("d.m.Y H:i", $Reflector->Stations[$i]->GetLastHeardTime()) . '<br />' . elapsedTime($Reflector->Stations[$i]->GetLastHeardTime()) . ' ago</td>
<td class="align-middle">' . $Reflector->Stations[$i]->GetModule() . '</td>
</tr>';
}
@ -168,7 +166,6 @@ if (isset($_GET['do'])) {
<div class="col-md-3">
<?php echo '<a href="' . $PageOptions['Homepage'] . '"><img class="mx-auto d-none d-md-block" src="./images/' . $PageOptions['Logo'] . '" width="50%"></a>'; ?>
<!-- <a href="https://m17project.org"><img class="mx-auto d-none d-md-block" src="./images/m17_logo.svg" width="50%"></a> -->
<table class="table table-sm table-striped table-hover">
<?php
$Modules = $Reflector->GetModules();
@ -196,7 +193,7 @@ if (isset($_GET['do'])) {
$Displayname = $Reflector->GetCallsignAndSuffixByID($Users[$j]);
echo '
<tr>
<td><a href="http://www.aprs.fi/'.$Displayname.'" class="pl" target="_blank">'.$Displayname.'</a> </td>
<td>'.$Displayname.'</td>
</tr>';
$UserCheckedArray[] = $Users[$j];
}

View File

@ -1,13 +1,11 @@
<?php
/*
* This dashboard is being developed by the DVBrazil Team as a courtesy to
* the XLX Multiprotocol Gateway Reflector Server project.
* The dashboard is based of the Bootstrap dashboard template.
* This dashboard is developed by KC1AWV for the mrefd M17
* reflector system. It is derived from the XLX dashboard
* originally developed by the DVBrazil team.
*
* This code is further edited by KC1AWV for the M17 Reflector M17-M17
*
* version 1.1.0 - Bootstrap 4.5
* version 1.1.2
*/
if (file_exists("./include/functions.php")) {
@ -18,7 +16,7 @@ if (file_exists("./include/functions.php")) {
if (file_exists("./include/config.inc.php")) {
require_once("./include/config.inc.php");
} else {
die("config.inc.php does not exist.");
die("config.inc.php does not exist. Be sure to copy /include/config.inc.php.dist to /include/config.inc.php and edit the file accordingly.");
}
if (!class_exists('ParseXML')) require_once("./include/class.parsexml.php");
@ -35,48 +33,8 @@ $Reflector->SetXMLFile($Service['XMLFile']);
$Reflector->LoadXML();
if ($CallingHome['Active']) {
$CallHomeNow = false;
if (!file_exists($CallingHome['HashFile'])) {
$Hash = CreateCode(16);
$LastSync = 0;
$Ressource = @fopen($CallingHome['HashFile'], "w");
if ($Ressource) {
@fwrite($Ressource, "<?php\n");
@fwrite($Ressource, "\n" . '$LastSync = 0;');
@fwrite($Ressource, "\n" . '$Hash = "' . $Hash . '";');
@fwrite($Ressource, "\n\n" . '?>');
@fclose($Ressource);
@exec("chmod 777 " . $CallingHome['HashFile']);
$CallHomeNow = true;
}
} else {
include($CallingHome['HashFile']);
if ($LastSync < (time() - $CallingHome['PushDelay'])) {
$Ressource = @fopen($CallingHome['HashFile'], "w");
if ($Ressource) {
@fwrite($Ressource, "<?php\n");
@fwrite($Ressource, "\n" . '$LastSync = ' . time() . ';');
@fwrite($Ressource, "\n" . '$Hash = "' . $Hash . '";');
@fwrite($Ressource, "\n\n" . '?>');
@fclose($Ressource);
}
$CallHomeNow = true;
}
}
if ($CallHomeNow || isset($_GET['callhome'])) {
$Reflector->SetCallingHome($CallingHome, $Hash);
$Reflector->ReadInterlinkFile();
$Reflector->PrepareInterlinkXML();
$Reflector->PrepareReflectorXML();
$Reflector->CallHome();
}
} else {
$Hash = "";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
@ -150,9 +108,9 @@ if ($CallingHome['Active']) {
<div id="navbarCollapse" class="collapse navbar-collapse">
<ul class="navbar-nav mr-auto">
<li<?php echo (($_GET['show'] == "users") || ($_GET['show'] == "")) ? ' class="nav-item active"' : ''; ?>><a class="nav-link" href="./index.php">Last Heard</a></li>
<li<?php echo ($_GET['show'] == "repeaters") ? ' class="nav-item active"' : ''; ?>><a class="nav-link" href="./index.php?show=repeaters">Links (<?php echo $Reflector->NodeCount(); ?>)</a></li>
<li<?php echo ($_GET['show'] == "links") ? ' class="nav-item active"' : ''; ?>><a class="nav-link" href="./index.php?show=links">Links (<?php echo $Reflector->NodeCount(); ?>)</a></li>
</ul>
<span class="navbar-text px-2">mrefd v<?php echo $Reflector->GetVersion(); ?> - Dashboard v1.1.1 <?php echo $PageOptions['LocalModification']; ?></span>
<span class="navbar-text px-2">mrefd v<?php echo $Reflector->GetVersion(); ?> - Dashboard v1.2.0 <?php echo $PageOptions['LocalModification']; ?></span>
<span class="navbar-text px-2">Service uptime: <?php echo FormatSeconds($Reflector->GetServiceUptime()); ?></span>
</div>
</nav>
@ -160,22 +118,12 @@ if ($CallingHome['Active']) {
<div class="container-fluid">
<div class="row">
<?php
/* Do we really want to keep calling home?
if ($CallingHome['Active']) {
if (!is_readable($CallingHome['HashFile']) && (!is_writeable($CallingHome['HashFile']))) {
echo '
<div class="error">
your private hash in ' . $CallingHome['HashFile'] . ' could not be created, please check your config file and the permissions for the defined folder.
</div>';
}
}
*/
switch ($_GET['show']) {
case 'users' :
require_once("./include/users.php");
break;
case 'repeaters' :
require_once("./include/repeaters.php");
case 'links' :
require_once("./include/links.php");
break;
default :
require_once("./include/users.php");
@ -198,12 +146,9 @@ if ($CallingHome['Active']) {
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous"></script>
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> -->
<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="js/bootstrap.bundle.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug
<script src="js/ie10-viewport-bug-workaround.js"></script>
-->
</body>
</html>