adsb-receiver/build/portal/html/admin/index.php

491 wiersze
30 KiB
PHP
Czysty Zwykły widok Historia

<?php
/////////////////////////////////////////////////////////////////////////////////////
// ADS-B RECEIVER PORTAL //
// =============================================================================== //
// Copyright and Licensing Information: //
// //
// The MIT License (MIT) //
// //
// Copyright (c) 2015-2016 Joseph A. Prochazka //
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy //
// of this software and associated documentation files (the "Software"), to deal //
// in the Software without restriction, including without limitation the rights //
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell //
// copies of the Software, and to permit persons to whom the Software is //
// furnished to do so, subject to the following conditions: //
// //
// The above copyright notice and this permission notice shall be included in all //
// copies or substantial portions of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE //
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, //
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //
// SOFTWARE. //
/////////////////////////////////////////////////////////////////////////////////////
session_start();
// Load the require PHP classes.
require_once($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR."classes".DIRECTORY_SEPARATOR."settings.class.php");
require_once($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR."classes".DIRECTORY_SEPARATOR."common.class.php");
require_once($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR."classes".DIRECTORY_SEPARATOR."account.class.php");
$settings = new settings();
$common = new common();
$account = new account();
// Check if the user is logged in.
if (!$account->isAuthenticated()) {
// The user is not logged in so forward them to the login page.
header ("Location: login.php");
}
// Set updated variable to FALSE.
$updated = FALSE;
if ($common->postBack()) {
// Flight notifications
$notificationArray = explode(',', $_POST['flightNotifications']);
if ($settings::db_driver == "xml") {
// XML
$notifications = simplexml_load_file($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR."data".DIRECTORY_SEPARATOR."flightNotifications.xml");
unset($notifications->flight);
foreach ($notificationArray as $notification) {
$newNotification = $notifications->addChild('flight', $notification);
$dom = dom_import_simplexml($notifications)->ownerDocument;
$dom->formatOutput = TRUE;
file_put_contents($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR."data".DIRECTORY_SEPARATOR."flightNotifications.xml", $dom->saveXML());
}
} else {
// PDO
$dbh = $common->pdoOpen();
$sql = "SELECT * FROM ".$settings::db_prefix."flightNotifications";
$sth = $dbh->prepare($sql);
$sth->execute();
$savedFlights = $sth->fetchAll();
$sth = NULL;
$dbh = NULL;
foreach ($savedFlights as $flight) {
// Remove flight if not in list.
if (!in_array($flight, $notificationArray)) {
$dbh = $common->pdoOpen();
$sql = "DELETE FROM ".$settings::db_prefix."flightNotifications WHERE flight = :flight";
$sth = $dbh->prepare($sql);
$sth->bindParam(':flight', $flight['flight'], PDO::PARAM_STR, 10);
$sth->execute();
$sth = NULL;
$dbh = NULL;
}
}
foreach ($notificationArray as $flight) {
// Add flight if not saved already.
if (!in_array($flight, $savedFlights)) {
$dbh = $common->pdoOpen();
$sql = "INSERT INTO ".$settings::db_prefix."flightNotifications (flight) VALUES (:flight)";
$sth = $dbh->prepare($sql);
$sth->bindParam(':flight', $flight, PDO::PARAM_STR, 10);
$sth->execute();
$sth = NULL;
$dbh = NULL;
}
}
}
// Set TRUE or FALSE for checkbox items.
$enableFlightNotifications = FALSE;
if (isset($_POST['enableFlightNotifications']) && $_POST['enableFlightNotifications'] == "TRUE")
$enableFlightNotifications = TRUE;
$enableFlights = FALSE;
if (isset($_POST['enableFlights']) && $_POST['enableFlights'] == "TRUE")
$enableFlights = TRUE;
$enableBlog = FALSE;
if (isset($_POST['enableBlog']) && $_POST['enableBlog'] == "TRUE")
$enableBlog = TRUE;
$enableInfo = FALSE;
if (isset($_POST['enableInfo']) && $_POST['enableInfo'] == "TRUE")
$enableInfo = TRUE;
$enableGraphs = FALSE;
if (isset($_POST['enableGraphs']) && $_POST['enableGraphs'] == "TRUE")
$enableGraphs = TRUE;
$enableDump1090 = FALSE;
if (isset($_POST['enableDump1090']) && $_POST['enableDump1090'] == "TRUE")
$enableDump1090 = TRUE;
$enableDump978 = FALSE;
if (isset($_POST['enableDump978']) && $_POST['enableDump978'] == "TRUE")
$enableDump978 = TRUE;
$enablePfclient = FALSE;
if (isset($_POST['enablePfclient']) && $_POST['enablePfclient'] == "TRUE")
$enablePfclient = TRUE;
$enableFlightAwareLink = FALSE;
if (isset($_POST['enableFlightAwareLink']) && $_POST['enableFlightAwareLink'] == "TRUE")
$enableFlightAwareLink = TRUE;
$enablePlaneFinderLink = FALSE;
if (isset($_POST['enablePlaneFinderLink']) && $_POST['enablePlaneFinderLink'] == "TRUE")
$enablePlaneFinderLink = TRUE;
$enableFlightRadar24Link = FALSE;
if (isset($_POST['enableFlightRadar24Link']) && $_POST['enableFlightRadar24Link'] == "TRUE")
$enableFlightRadar24Link = TRUE;
$enableAdsbExchangeLink = FALSE;
if (isset($_POST['enableAdsbExchangeLink']) && $_POST['enableAdsbExchangeLink'] == "TRUE")
$enableAdsbExchangeLink = TRUE;
// Update settings using those supplied by the form.
$common->updateSetting("siteName", $_POST['siteName']);
$common->updateSetting("template", $_POST['template']);
$common->updateSetting("defaultPage", $_POST['defaultPage']);
$common->updateSetting("dateFormat", $_POST['dateFormat']);
$common->updateSetting("enableFlightNotifications", $enableFlightNotifications);
$common->updateSetting("enableFlights", $enableBlog);
$common->updateSetting("enableBlog", $enableBlog);
$common->updateSetting("enableInfo", $enableInfo);
$common->updateSetting("enableGraphs", $enableGraphs);
$common->updateSetting("enableDump1090", $enableDump1090);
$common->updateSetting("enableDump978", $enableDump978);
$common->updateSetting("enablePfclient", $enablePfclient);
$common->updateSetting("enableFlightAwareLink", $enableFlightAwareLink);
$common->updateSetting("flightAwareLogin", $_POST['flightAwareLogin']);
$common->updateSetting("flightAwareSite", $_POST['flightAwareSite']);
$common->updateSetting("enablePlaneFinderLink", $enablePlaneFinderLink);
$common->updateSetting("planeFinderReceiver", $_POST['planeFinderReceiver']);
$common->updateSetting("enableFlightRadar24Link", $enableFlightRadar24Link);
$common->updateSetting("flightRadar24Id", $_POST['flightRadar24Id']);
$common->updateSetting("enableAdsbExchangeLink", $enableAdsbExchangeLink);
$common->updateSetting("measurementRange", $_POST['measurementRange']);
$common->updateSetting("measurementTemperature", $_POST['measurementTemperature']);
$common->updateSetting("measurementBandwidth", $_POST['measurementBandwidth']);
$common->updateSetting("networkInterface", $_POST['networkInterface']);
// Set updated to TRUE since settings were updated.
$updated = TRUE;
}
// Get all flights to be notified about from the flightNotifications.xml file.
$flightNotifications = NULL;
$savedFlights = array();
if ($settings::db_driver == "xml") {
// XML
$savedFlights = simplexml_load_file($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR."data".DIRECTORY_SEPARATOR."flightNotifications.xml");
foreach ($savedFlights as $savedFlight) {
$flightNotifications = ltrim($flightNotifications.",".$savedFlight, ',');
}
} else {
//PDO
$dbh = $common->pdoOpen();
$sql = "SELECT * FROM ".$settings::db_prefix."flightNotifications";
$sth = $dbh->prepare($sql);
$sth->execute();
$savedFlights = $sth->fetchAll();
$sth = NULL;
$dbh = NULL;
foreach ($savedFlights as $savedFlight) {
$flightNotifications = ltrim($flightNotifications.",".$savedFlight['flight'], ',');
}
}
$enableFlightNotifications = $common->getSetting("enableFlightNotifications");
// Get general settings from settings.xml.
$siteName = $common->getSetting("siteName");
$currentTemplate = $common->getSetting("template");
$defaultPage = $common->getSetting("defaultPage");
$dateFormat = $common->getSetting("dateFormat");
// Get navigation settings from settings.xml.
$enableFlights = $common->getSetting("enableFlights");
$enableBlog = $common->getSetting("enableBlog");
$enableInfo = $common->getSetting("enableInfo");
$enableGraphs = $common->getSetting("enableGraphs");
$enableDump1090 = $common->getSetting("enableDump1090");
$enableDump978 = $common->getSetting("enableDump978");
$enablePfclient = $common->getSetting("enablePfclient");
// Get aggregate site settings from settings.xml.
$enableFlightAwareLink = $common->getSetting("enableFlightAwareLink");
$flightAwareLogin = $common->getSetting("flightAwareLogin");
$flightAwareSite = $common->getSetting("flightAwareSite");
$enablePlaneFinderLink = $common->getSetting("enablePlaneFinderLink");
$planeFinderReceiver = $common->getSetting("planeFinderReceiver");
$enableFlightRadar24Link = $common->getSetting("enableFlightRadar24Link");
$flightRadar24Id = $common->getSetting("flightRadar24Id");
$enableAdsbExchangeLink = $common->getSetting("enableAdsbExchangeLink");
// Get units of measurement setting from settings.xml.
$measurementRange = $common->getSetting("measurementRange");
$measurementTemperature = $common->getSetting("measurementTemperature");
$measurementBandwidth = $common->getSetting("measurementBandwidth");
// Get the network interface from settings.xml.
$networkInterface = $common->getSetting("networkInterface");
// Create an array of all directories in the template folder.
$templates = array();
$path = "../templates/";
$directoryHandle = @opendir($path) or die('Unable to open directory "'.$path.'".');
while($templateDirectory = readdir($directoryHandle)) {
if (is_dir($path."/".$templateDirectory)) {
if ($templateDirectory != "." && $templateDirectory != "..") {
array_push($templates, $templateDirectory);
}
}
}
closedir($directoryHandle);
////////////////
// BEGIN HTML
require_once('includes/header.inc.php');
// Display the updated message if settings were updated.
if ($updated) {
?>
<div id="settings-saved" class="alert alert-success fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
Settings have been updated.
</div>
<?php
}
?>
<form method="post" action="index.php">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#general" aria-controls="general" role="tab" data-toggle="tab">General</a></li>
<li role="presentation"><a href="#notifications" aria-controls="notifications" role="tab" data-toggle="tab">Notifications</a></li>
<li role="presentation"><a href="#navigation" aria-controls="navigation" role="tab" data-toggle="tab">Navigation</a></li>
<li role="presentation"><a href="#measurments" aria-controls="measurments" role="tab" data-toggle="tab">Measurements</a></li>
<li role="presentation"><a href="#system" aria-controls="system" role="tab" data-toggle="tab">System</a></li>
</ul>
<div class="padding"></div>
<div class="tab-content">
<div role="tabpanel" class="tab-pane fade in active" id="general">
<div class="panel panel-default">
<div class="panel-heading">Site Layout</div>
<div class="panel-body">
<div class="form-group">
<label for="siteName">Site Name</label>
<input type="text" class="form-control" id="siteName" name="siteName" value="<?php echo $siteName; ?>">
</div>
<div class="form-group">
<label for="template">Template</label>
<select class="form-control" id="template" name="template">
<?php
foreach ($templates as $template) {
echo ' <option value="'.$template.'"'.($template == $currentTemplate ? ' selected' : '').'>'.$template.'</option>'."\n";
}
?>
</select>
</div>
<div class="form-group">
<label for="defaultPage">Default Page</label>
<select class="form-control" id="defaultPage" name="defaultPage">
<option value="blog.php"<?php ($defaultPage == "blog.php" ? print ' selected' : ''); ?>>Blog</option>
<option value="system.php"<?php ($defaultPage == "system.php" ? print ' selected' : ''); ?>>System Information</option>
<option value="graphs.php"<?php ($defaultPage == "graphs.php" ? print ' selected' : ''); ?>>Performance Graphs</option>
<option value="dump1090.php"<?php ($defaultPage == "dump1090.php" ? print ' selected' : ''); ?>>Live Dump1090 Map</option>
<option value="dump978.php"<?php ($defaultPage == "dump978.php" ? print ' selected' : ''); ?>>Live Dump978 Map</option>
</select>
</div>
<div class="form-group">
<label for="defaultPage">Date Format</label>
<div class="radio">
<label><input type="radio" name="dateFormatSlelection" value="F jS, Y"<?php ($dateFormat == "F jS, Y" ? print ' checked' : ''); ?>>October 16, 2015</label>
</div>
<div class="radio">
<label><input type="radio" name="dateFormatSlelection" value="Y-m-d"<?php ($dateFormat == "Y-m-d" ? print ' checked' : ''); ?>>2015-10-16</label>
</div>
<div class="radio">
<label><input type="radio" name="dateFormatSlelection" value="m/d/Y"<?php ($dateFormat == "m/d/Y" ? print ' checked' : ''); ?>>16/10/2015</label>
</div>
<div class="radio">
<label><input type="radio" name="dateFormatSlelection" value="d/m/Y"<?php ($dateFormat == "d/m/Y" ? print ' checked' : ''); ?>>10/16/2015</label>
</div>
<input type="text" class="form-control" id="dateFormat" name="dateFormat" value="<?php echo $dateFormat; ?>">
</div>
</div>
</div>
</div>
<div role="tabpanel" class="tab-pane fade" id="notifications">
<div class="panel panel-default">
<div class="panel-heading">Flight Notifications</div>
<div class="panel-body">
<div class="checkbox">
<label>
<input type="checkbox" name="enableFlightNotifications" value="TRUE"<?php ($enableFlightNotifications == 1 ? print ' checked' : ''); ?>> Enable flight notifications.
</label>
</div>
<div class="form-group">
<label for="siteName">Flight Notifications (coma delimited)</label>
<input type="text" class="form-control" id="flightNotifications" name="flightNotifications" value="<?php echo $flightNotifications; ?>">
</div>
</div>
</div>
</div>
<div role="tabpanel" class="tab-pane fade" id="navigation">
<div class="panel panel-default">
<div class="panel-heading">Enable/Disable Navigation Links</div>
<div class="panel-body">
<div class="checkbox">
<label>
<input type="checkbox" name="enableFlights" value="TRUE"<?php ($enableFlights ? print ' checked' : ''); ?><?php ($settings::db_driver == "xml" ? print ' disabled' : ''); ?>> Enable flights link.
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="enableBlog" value="TRUE"<?php ($enableBlog ? print ' checked' : ''); ?>> Enable blog link.
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="enableInfo" value="TRUE"<?php ($enableInfo ? print ' checked' : ''); ?>> Enable system information link.
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="enableGraphs" value="TRUE"<?php ($enableGraphs ? print ' checked' : ''); ?>> Enable performance graphs link.
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="enableDump1090" value="TRUE"<?php ($enableDump1090 ? print ' checked' : ''); ?>> Enable live dump1090 map link.
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="enableDump978" value="TRUE"<?php ($enableDump978 ? print ' checked' : ''); ?>> Enable live dump978 map link.
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="enablePfclient" value="TRUE"<?php ($enablePfclient ? print ' checked' : ''); ?>> Enable Planfinder ADS-B Client link.
</label>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">Aggregate Site Settings</div>
<div class="panel-body">
<div class="form-group">
<label for="flightAwareLogin">FlightAware Login</label>
<input type="text" class="form-control" id="flightAwareLogin" name="flightAwareLogin" value="<?php echo $flightAwareLogin; ?>">
<label for="flightAwareSite">FlightAware ADS-B Site</label>
<input type="text" class="form-control" id="flightAwareSite" name="flightAwareSite" value="<?php echo $flightAwareSite; ?>">
<div class="checkbox">
<label>
<input type="checkbox" name="enableFlightAwareLink" value="TRUE"<?php ($enableFlightAwareLink == 1 ? print ' checked' : ''); ?>> Enable FlightAware Statistics Link.
</label>
</div>
</div>
<hr />
<div class="form-group">
<label for="planeFinderReceiver">PlaneFinder Receiver Number</label>
<input type="text" class="form-control" id="planeFinderReceiver" name="planeFinderReceiver" value="<?php echo $planeFinderReceiver; ?>">
<div class="checkbox">
<label>
<input type="checkbox" name="enablePlaneFinderLink" value="TRUE"<?php ($enablePlaneFinderLink == 1 ? print ' checked' : ''); ?>> Enable PlaneFinder Statistics Link.
</label>
</div>
</div>
<hr />
<div class="form-group">
<label for="flightRadar24FeedStatsId">FlightRadar24 Feed Stats ID</label>
<input type="text" class="form-control" id="flightRadar24Id" name="flightRadar24Id" value="<?php echo $flightRadar24Id; ?>">
<div class="checkbox">
<label>
<input type="checkbox" name="enableFlightRadar24Link" value="TRUE"<?php ($enableFlightRadar24Link == 1 ? print ' checked' : ''); ?>> Enable FlightRadar24 Statistics Link.
</label>
</div>
</div>
<hr />
<div class="form-group">
<div class="checkbox">
<label>
<input type="checkbox" name="enableAdsbExchangeLink" value="TRUE"<?php ($enableAdsbExchangeLink == 1 ? print ' checked' : ''); ?>> Enable ADSB-Exchange Link.
</label>
</div>
</div>
</div>
</div>
</div>
<div role="tabpanel" class="tab-pane fade" id="measurments">
<div class="panel panel-default">
<div class="panel-heading">Unit of Measurement (Range)</div>
<div class="panel-body">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default<?php ($measurementRange == "imperialNautical" ? print ' active' : ''); ?>">
<input type="radio" name="measurementRange" id="imperialNautical" value="imperialNautical" autocomplete="off"<?php ($measurementRange == "imperialNautical" ? print ' checked' : ''); ?>> Imperial (Nautical Miles)
</label>
<label class="btn btn-default<?php ($measurementRange == "imperialStatute" ? print ' active' : ''); ?>">
<input type="radio" name="measurementRange" id="imperialStatute" value="imperialStatute" autocomplete="off"<?php ($measurementRange == "imperialStatute" ? print ' checked' : ''); ?>> Imperial (Statute Miles)
</label>
<label class="btn btn-default<?php ($measurementRange == "metric" ? print ' active' : ''); ?>">
<input type="radio" name="measurementRange" id="metric" value="metric" autocomplete="off"<?php ($measurementRange == "metric" ? print ' checked' : ''); ?>> Metric
</label>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">Unit of Measurement (Temperature)</div>
<div class="panel-body">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default<?php ($measurementTemperature == "imperial" ? print ' active' : ''); ?>">
<input type="radio" name="measurementTemperature" id="imperial" value="imperial" autocomplete="off"<?php ($measurementTemperature == "imperial" ? print ' checked' : ''); ?>> Imperial
</label>
<label class="btn btn-default<?php ($measurementTemperature == "metric" ? print ' active' : ''); ?>">
<input type="radio" name="measurementTemperature" id="metric" value="metric" autocomplete="off"<?php ($measurementTemperature == "metric" ? print ' checked' : ''); ?>> Metric
</label>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">Unit of Measurement (Bandwidth)</div>
<div class="panel-body">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default<?php ($measurementBandwidth == "kbps" ? print ' active' : ''); ?>">
<input type="radio" name="measurementBandwidth" id="imperial" value="kbps" autocomplete="off"<?php ($measurementBandwidth == "kbps" ? print ' checked' : ''); ?>> Kbps
</label>
<label class="btn btn-default<?php ($measurementBandwidth == "mbps" ? print ' active' : ''); ?>">
<input type="radio" name="measurementBandwidth" id="metric" value="mbps" autocomplete="off"<?php ($measurementBandwidth == "mbps" ? print ' checked' : ''); ?>> Mbps
</label>
</div>
</div>
</div>
</div>
<div role="tabpanel" class="tab-pane fade" id="system">
<div class="panel panel-default">
<div class="panel-heading">Network Interface</div>
<div class="panel-body">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default<?php ($networkInterface == "eth0" ? print ' active' : ''); ?>">
<input type="radio" name="networkInterface" id="imperial" value="eth0" autocomplete="off"<?php ($networkInterface == "eth0" ? print ' checked' : ''); ?>> eth0
</label>
<label class="btn btn-default<?php ($networkInterface == "wlan0" ? print ' active' : ''); ?>">
<input type="radio" name="networkInterface" id="metric" value="wlan0" autocomplete="off"<?php ($networkInterface == "wlan0" ? print ' checked' : ''); ?>> wlan0
</label>
</div>
</div>
</div>
</div>
</div>
<input type="submit" class="btn btn-default" value="Save Settings">
</form>
<?php
require_once('includes/footer.inc.php');
?>