Fix localhost check, cleanup front end and favicon

This commit is contained in:
30hours 2024-02-18 12:26:17 +00:00
parent 2475b40502
commit 9ccdd745dc
19 changed files with 49 additions and 26 deletions

View file

@ -63,10 +63,11 @@
</div> </div>
</div> </div>
</body> </body>
<script src="../js/common.js"></script>
<script> <script>
window.onload = function() { window.onload = function() {
var host = window.location.hostname; var host = window.location.hostname;
var isLocalHost = (host === "localhost" || host === "127.0.0.1" || host === "192.168.0.112"); var isLocalHost = is_localhost(host);
var anchors = document.getElementsByTagName("a"); var anchors = document.getElementsByTagName("a");
if (isLocalHost) { if (isLocalHost) {
for (var i = 0; i < anchors.length; i++) { for (var i = 0; i < anchors.length; i++) {

View file

@ -25,5 +25,6 @@
xVariable = "delay"; xVariable = "delay";
yVariable = "doppler"; yVariable = "doppler";
</script> </script>
<script src="../../../js/common.js"></script>
<script src="../../../js/plot_detection.js"></script> <script src="../../../js/plot_detection.js"></script>
</html> </html>

View file

@ -25,5 +25,6 @@
xVariable = "timestamp"; xVariable = "timestamp";
yVariable = "delay"; yVariable = "delay";
</script> </script>
<script src="../../../js/common.js"></script>
<script src="../../../js/plot_detection.js"></script> <script src="../../../js/plot_detection.js"></script>
</html> </html>

View file

@ -25,5 +25,6 @@
xVariable = "timestamp"; xVariable = "timestamp";
yVariable = "doppler"; yVariable = "doppler";
</script> </script>
<script src="../../../js/common.js"></script>
<script src="../../../js/plot_detection.js"></script> <script src="../../../js/plot_detection.js"></script>
</html> </html>

View file

@ -22,5 +22,6 @@
<script> <script>
var urlMap = '/api/map'; var urlMap = '/api/map';
</script> </script>
<script src="../../js/common.js"></script>
<script src="../../js/plot_map.js"></script> <script src="../../js/plot_map.js"></script>
</html> </html>

View file

@ -22,5 +22,6 @@
<script> <script>
var urlMap = '/stash/map'; var urlMap = '/stash/map';
</script> </script>
<script src="../../js/common.js"></script>
<script src="../../js/plot_map.js"></script> <script src="../../js/plot_map.js"></script>
</html> </html>

View file

@ -21,6 +21,7 @@
</body> </body>
<script> <script>
</script> </script>
<script src="../../js/common.js"></script>
<script src="../../js/plot_spectrum.js"></script> <script src="../../js/plot_spectrum.js"></script>
</html> </html>

View file

@ -23,5 +23,6 @@
xTitle = "Timestamp"; xTitle = "Timestamp";
yTitle = "Time (ms)"; yTitle = "Time (ms)";
</script> </script>
<script src="../../js/common.js"></script>
<script src="../../js/plot_timing.js"></script> <script src="../../js/plot_timing.js"></script>
</html> </html>

1
html/favicon.ico Symbolic link
View file

@ -0,0 +1 @@
./favicon/favicon-32x32.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 975 B

View file

@ -4,6 +4,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>blah2</title> <title>blah2</title>
<link rel="icon" type="image/x-icon" href="/favicon/favicon-16x16.png" sizes="16x16">
<link rel="icon" type="image/x-icon" href="/favicon/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/x-icon" href="/favicon/favicon-128x128.png" sizes="128x128">
<link rel="icon" type="image/x-icon" href="/favicon/favicon-196x196.png" sizes="196x196">
<!-- load lib js --> <!-- load lib js -->
<script src="./lib/bootstrap-5.2.3.min.js"></script> <script src="./lib/bootstrap-5.2.3.min.js"></script>
<script src="./lib/plotly-2.20.0.min.js"></script> <script src="./lib/plotly-2.20.0.min.js"></script>
@ -41,6 +45,7 @@
<script> <script>
var urlMap = '/api/map'; var urlMap = '/api/map';
</script> </script>
<script src="js/common.js"></script>
<script src="js/plot_map.js"></script> <script src="js/plot_map.js"></script>
<script src="control.js"></script> <script src="control.js"></script>
</html> </html>

18
html/js/common.js Normal file
View file

@ -0,0 +1,18 @@
function is_localhost(ip) {
if (ip === 'localhost') {
return true;
}
const localRanges = ['127.0.0.1', '192.168.0.0/16', '10.0.0.0/8', '172.16.0.0/12'];
const ipToInt = ip => ip.split('.').reduce((acc, octet) => (acc << 8) + +octet, 0) >>> 0;
return localRanges.some(range => {
const [rangeStart, rangeSize = 32] = range.split('/');
const start = ipToInt(rangeStart);
const end = (start | (1 << (32 - +rangeSize))) >>> 0;
return ipToInt(ip) >= start && ipToInt(ip) <= end;
});
}

View file

@ -1,7 +1,7 @@
var timestamp = -1; var timestamp;
var nRows = 3; var nRows = 3;
var host = window.location.hostname; var host = window.location.hostname;
var isLocalHost = (host === "localhost" || host === "127.0.0.1" || host === "192.168.0.112"); var isLocalHost = is_localhost(host);
var range_x = []; var range_x = [];
var range_y = []; var range_y = [];
@ -18,8 +18,6 @@ if (isLocalHost) {
} else { } else {
urlDetection = '//' + host + '/stash/detection'; urlDetection = '//' + host + '/stash/detection';
} }
urlTimestamp = urlTimestamp + '?timestamp=' + Date.now();
urlDetection = urlDetection + '?timestamp=' + Date.now();
// setup plotly // setup plotly
var layout = { var layout = {

View file

@ -1,7 +1,7 @@
var timestamp = -1; var timestamp = -1;
var nRows = 3; var nRows = 3;
var host = window.location.hostname; var host = window.location.hostname;
var isLocalHost = (host === "localhost" || host === "127.0.0.1" || host === "192.168.0.112"); var isLocalHost = is_localhost(host);
var range_x = []; var range_x = [];
var range_y = []; var range_y = [];
@ -36,20 +36,17 @@ if (isLocalHost) {
} else { } else {
urlConfig = '//' + host + '/api/config'; urlConfig = '//' + host + '/api/config';
} }
urlTimestamp = urlTimestamp + '?timestamp=' + Date.now();
urlDetection = urlDetection + '?timestamp=' + Date.now();
urlMap = urlMap + '?timestamp=' + Date.now();
// get truth flag // get truth flag
var isTruth = false; var isTruth = false;
var configData = $.getJSON(urlConfig, function () { }) $.getJSON(urlConfig, function () { })
.done(function (data_config) { .done(function (data_config) {
if (data_config.truth.adsb.enabled === true) { if (data_config.truth.adsb.enabled === true) {
isTruth = true; isTruth = true;
var adsbLinkData = $.getJSON(urlAdsbLink, function () { }) $.getJSON(urlAdsbLink, function () { })
.done(function (data) { .done(function (data) {
urlAdsb = data.url; urlAdsb = data.url;
if (window.location.protocol === 'https:') { if (!is_localhost(new URL(urlAdsb).hostname)) {
urlAdsb = urlAdsb.replace(/^http:/, 'https:'); urlAdsb = urlAdsb.replace(/^http:/, 'https:');
} }
}) })
@ -120,21 +117,21 @@ Plotly.newPlot('data', data, layout, config);
var intervalId = window.setInterval(function () { var intervalId = window.setInterval(function () {
// check if timestamp is updated // check if timestamp is updated
var timestampData = $.get(urlTimestamp, function () { }) $.get(urlTimestamp, function () { })
.done(function (data) { .done(function (data) {
if (timestamp != data) { if (timestamp != data) {
timestamp = data; timestamp = data;
// get detection data (no detection lag) // get detection data (no detection lag)
var detectionData = $.getJSON(urlDetection, function () { }) $.getJSON(urlDetection, function () { })
.done(function (data_detection) { .done(function (data_detection) {
detection = data_detection; detection = data_detection;
}); });
// get ADS-B data if enabled in config // get ADS-B data if enabled in config
if (isTruth) { if (isTruth) {
var adsbData = $.getJSON(urlAdsb, function () { }) $.getJSON(urlAdsb, function () { })
.done(function (data_adsb) { .done(function (data_adsb) {
adsb['delay'] = []; adsb['delay'] = [];
adsb['doppler'] = []; adsb['doppler'] = [];
@ -150,7 +147,7 @@ var intervalId = window.setInterval(function () {
} }
// get new map data // get new map data
var apiData = $.getJSON(urlMap, function () { }) $.getJSON(urlMap, function () { })
.done(function (data) { .done(function (data) {
// case draw new plot // case draw new plot

View file

@ -1,7 +1,7 @@
var timestamp = -1; var timestamp = -1;
var nRows = 3; var nRows = 3;
var host = window.location.hostname; var host = window.location.hostname;
var isLocalHost = (host === "localhost" || host === "127.0.0.1" || host === "192.168.0.112"); var isLocalHost = is_localhost(host);
var range_x = []; var range_x = [];
var range_y = []; var range_y = [];
@ -18,8 +18,6 @@ if (isLocalHost) {
} else { } else {
urlMap = '//' + host + '/stash/iqdata'; urlMap = '//' + host + '/stash/iqdata';
} }
urlTimestamp = urlTimestamp + '?timestamp=' + Date.now();
urlMap = urlMap + '?timestamp=' + Date.now();
// setup plotly // setup plotly
var layout = { var layout = {
@ -82,14 +80,14 @@ Plotly.newPlot('data', data, layout, config);
var intervalId = window.setInterval(function () { var intervalId = window.setInterval(function () {
// check if timestamp is updated // check if timestamp is updated
var timestampData = $.get(urlTimestamp, function () { }) $.get(urlTimestamp, function () { })
.done(function (data) { .done(function (data) {
if (timestamp != data) { if (timestamp != data) {
timestamp = data; timestamp = data;
// get new map data // get new map data
var apiData = $.getJSON(urlMap, function () { }) $.getJSON(urlMap, function () { })
.done(function (data) { .done(function (data) {
// case draw new plot // case draw new plot

View file

@ -1,7 +1,7 @@
var timestamp = -1; var timestamp = -1;
var nRows = 3; var nRows = 3;
var host = window.location.hostname; var host = window.location.hostname;
var isLocalHost = (host === "localhost" || host === "127.0.0.1" || host === "192.168.0.112"); var isLocalHost = is_localhost(host);
// setup API // setup API
var urlTimestamp; var urlTimestamp;
@ -16,8 +16,6 @@ if (isLocalHost) {
} else { } else {
urlTiming = '//' + host + '/stash/timing'; urlTiming = '//' + host + '/stash/timing';
} }
urlTimestamp = urlTimestamp + '?timestamp=' + Date.now();
urlTiming = urlTiming + '?timestamp=' + Date.now();
// setup plotly // setup plotly
var layout = { var layout = {
@ -89,14 +87,14 @@ Plotly.newPlot('data', data, layout, config);
var intervalId = window.setInterval(function () { var intervalId = window.setInterval(function () {
// check if timestamp is updated // check if timestamp is updated
var timestampData = $.get(urlTimestamp, function () { }) $.get(urlTimestamp, function () { })
.done(function (data) { .done(function (data) {
if (timestamp != data) { if (timestamp != data) {
timestamp = data; timestamp = data;
// get new data // get new data
var apiData = $.getJSON(urlTiming, function () { }) $.getJSON(urlTiming, function () { })
.done(function (data) { .done(function (data) {
// case draw new plot // case draw new plot