From e29e3a3f04c768d71c7bdafc0bc1361a15374b71 Mon Sep 17 00:00:00 2001 From: NoobishSVK Date: Sun, 15 Sep 2024 14:47:32 +0200 Subject: [PATCH] bugfixes, UI improvements, logging improvements --- package.json | 2 +- server/endpoints.js | 25 +++++++++++++++++++-- web/css/breadcrumbs.css | 5 +++++ web/css/dropdown.css | 1 + web/css/helpers.css | 4 ++++ web/index.ejs | 6 ++--- web/js/confighandler.js | 4 ++-- web/js/init.js | 4 ++-- web/js/main.js | 50 ++++++++++++++++++++++++++++------------- web/js/settings.js | 21 ++++++++++++++++- web/setup.ejs | 47 ++++++++++++++++++++------------------ 11 files changed, 120 insertions(+), 49 deletions(-) diff --git a/package.json b/package.json index 1669514..e84400e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fm-dx-webserver", - "version": "1.3.0", + "version": "1.3.0.1", "description": "FM DX Webserver", "main": "index.js", "scripts": { diff --git a/server/endpoints.js b/server/endpoints.js index c8a30da..ab81677 100644 --- a/server/endpoints.js +++ b/server/endpoints.js @@ -270,6 +270,19 @@ router.get('/ping', (req, res) => { res.send('pong'); }); +const logHistory = {}; + +// Function to check if the ID has been logged within the last 60 minutes +function canLog(id) { + const now = Date.now(); + const sixtyMinutes = 60 * 60 * 1000; // 60 minutes in milliseconds + if (logHistory[id] && (now - logHistory[id]) < sixtyMinutes) { + return false; // Deny logging if less than 60 minutes have passed + } + logHistory[id] = now; // Update with the current timestamp + return true; +} + router.get('/log_fmlist', (req, res) => { if(dataHandler.dataToSend.txInfo.tx.length === 0) { res.status(500).send('No suitable transmitter to log.'); @@ -278,8 +291,18 @@ router.get('/log_fmlist', (req, res) => { if(serverConfig.extras?.fmlist_integration == false) { res.status(500).send('FMLIST Integration is not enabled on this server.'); + return; } + const clientIp = req.headers['x-forwarded-for'] || req.connection.remoteAddress; + const txId = dataHandler.dataToSend.txInfo.id; // Extract the ID + + // Check if the ID can be logged (i.e., not logged within the last 60 minutes) + if (!canLog(txId)) { + res.status(429).send(`ID ${txId} was already logged recently. Please wait before logging again.`); + return; + } + const postData = JSON.stringify({ station: { freq: dataHandler.dataToSend.freq, @@ -336,6 +359,4 @@ router.get('/log_fmlist', (req, res) => { request.end(); }); - - module.exports = router; diff --git a/web/css/breadcrumbs.css b/web/css/breadcrumbs.css index d16da01..2cc5ba6 100644 --- a/web/css/breadcrumbs.css +++ b/web/css/breadcrumbs.css @@ -305,6 +305,11 @@ pre { top: 10px; } +.flex-container.contains-dropdown { + z-index: 999; + position: relative; +} + @media (max-width: 768px) { canvas, #flags-container { display: none; diff --git a/web/css/dropdown.css b/web/css/dropdown.css index d6e133c..b527652 100644 --- a/web/css/dropdown.css +++ b/web/css/dropdown.css @@ -95,6 +95,7 @@ display:block; transform: translateY(0); position:absolute; + z-index: 1000; } .dropdown.opened::before { transform: rotate(-225deg); diff --git a/web/css/helpers.css b/web/css/helpers.css index c408a3e..ce84def 100644 --- a/web/css/helpers.css +++ b/web/css/helpers.css @@ -71,6 +71,10 @@ margin-left: 20px; } +.m-right-10 { + margin-right: 10px; +} + .m-right-20 { margin-right: 20px; } diff --git a/web/index.ejs b/web/index.ejs index f808779..c5eff3a 100644 --- a/web/index.ejs +++ b/web/index.ejs @@ -232,7 +232,7 @@ <% } %> <% if (fmlist_integration == true) { %> <% } %> @@ -356,11 +356,11 @@
- +
- +
diff --git a/web/js/confighandler.js b/web/js/confighandler.js index 1e46725..481cf4e 100644 --- a/web/js/confighandler.js +++ b/web/js/confighandler.js @@ -315,8 +315,8 @@ function submitData() { } } - $("#fmlist-integration").prop("checked", data.extras ? data.extras?.fmlist_integration : "true"); - $('#fmlist-omid').val(data.extras?.fmlist_omid); + $("#fmlist-integration").prop("checked", data.extras ? data.extras?.fmlistIntegration : "true"); + $('#fmlist-omid').val(data.extras?.fmlistOmid); }) .catch(error => { console.error('Error fetching data:', error.message); diff --git a/web/js/init.js b/web/js/init.js index d73378c..1ca3395 100644 --- a/web/js/init.js +++ b/web/js/init.js @@ -1,9 +1,9 @@ -var currentDate = new Date('Sep 15, 2024 00:00:00'); +var currentDate = new Date('Sep 15, 2024 15:00:00'); var day = currentDate.getDate(); var month = currentDate.getMonth() + 1; // Months are zero-indexed, so add 1 var year = currentDate.getFullYear(); var formattedDate = day + '/' + month + '/' + year; -var currentVersion = 'v1.3.0 [' + formattedDate + ']'; +var currentVersion = 'v1.3.0.1 [' + formattedDate + ']'; getInitialSettings(); removeUrlParameters(); // Call this function to remove URL parameters diff --git a/web/js/main.js b/web/js/main.js index 30b1c6e..bcae21e 100644 --- a/web/js/main.js +++ b/web/js/main.js @@ -181,6 +181,38 @@ $(document).ready(function () { textInput.focus(); }); initTooltips(); + + //FMLIST logging + $('#log-fmlist').on('click', function() { + console.log('asdfdasf'); + $.ajax({ + url: './log_fmlist', + method: 'GET', + success: function(response) { + // Show a success toast with the response message + sendToast('success', 'Log successful', response, false, true); + }, + error: function(xhr) { + let errorMessage; + + // Handle different error status codes with custom messages + switch (xhr.status) { + case 429: + errorMessage = xhr.responseText; + break; + case 500: + errorMessage = 'Server error: ' + xhr.responseText || 'Internal Server Error'; + break; + default: + errorMessage = xhr.statusText || 'An error occurred'; + } + + // Show an error toast with the specific error message + sendToast('error', 'Log failed', errorMessage, false, true); + } + }); + }); + }); function getServerTime() { @@ -834,7 +866,7 @@ const updateDataElements = throttle(function(parsedData) { } if(parsedData.txInfo.tx.length > 1 && parsedData.txInfo.dist > 150 && parsedData.txInfo.dist < 4000) { - $('#log-fmlist').attr('disabled', 'false').removeClass('btn-disabled cursor-disabled'); + $('#log-fmlist').removeAttr('disabled').removeClass('btn-disabled cursor-disabled'); } else { $('#log-fmlist').attr('disabled', 'true').addClass('btn-disabled cursor-disabled'); } @@ -1016,18 +1048,4 @@ function fillPresets() { tuneTo(Number(presetText)); }); } -} - -//FMLIST logging -$('#log-fmlist').on('click', function() { - $.ajax({ - url: './log_fmlist', - method: 'GET', - success: function(response) { - sendToast('success', 'Log successful', response, false, true); - }, - error: function(xhr) { - sendToast('error', 'Log failed', xhr.statusText, false, true); - } - }); -}); +} \ No newline at end of file diff --git a/web/js/settings.js b/web/js/settings.js index df997f6..882c2ee 100644 --- a/web/js/settings.js +++ b/web/js/settings.js @@ -155,6 +155,13 @@ $(document).ready(() => { $('.version-string').text(currentVersion); setBg(); + + updateIconState(); + + // Update icons when the checkbox state changes + $('input[type="checkbox"]').change(function() { + updateIconState(); + }); }); function getQueryParameter(name) { @@ -162,6 +169,17 @@ function getQueryParameter(name) { return urlParams.get(name); } +function updateIconState() { + $('input[type="checkbox"]').each(function() { + var icon = $(this).siblings('label').find('i'); + if ($(this).is(':checked')) { + icon.removeClass('fa-toggle-off').addClass('fa-toggle-on'); + } else { + icon.removeClass('fa-toggle-on').addClass('fa-toggle-off'); + } + }); +} + function setTheme(themeName) { const themeColors = themes[themeName]; if (themeColors) { @@ -191,4 +209,5 @@ function setBg() { } else { $('body').css('background', 'var(--color-main)'); } -} \ No newline at end of file +} + diff --git a/web/setup.ejs b/web/setup.ejs index 3ada2a1..fad5ac0 100644 --- a/web/setup.ejs +++ b/web/setup.ejs @@ -118,11 +118,11 @@
- +
- +

@@ -156,7 +156,7 @@

Audio settings

-
+

Device

@@ -220,7 +220,7 @@

Miscellaneous

- +
@@ -228,7 +228,7 @@

Webserver settings

-
+

Connection

Leave the IP at 0.0.0.0 unless you explicitly know you have to change it.
Don't enter your public IP here.

@@ -249,9 +249,9 @@
-

Themes

-
- +

Themes

+
+

Antennas

+
+ +
- +

@@ -282,7 +285,7 @@
-
+

@@ -300,7 +303,7 @@
-
+

@@ -315,14 +318,14 @@
-
+

Tuning options

If you want to limit which frequencies the users can tune to,
you can set the lower and upper limit here.
Enter frequencies in MHz.

- +

@@ -363,14 +366,14 @@

You can switch between American (RBDS) / Global (RDS) mode here.

- +

Chat options

- +
@@ -411,11 +414,11 @@

Tuner settings

-
+

Device type

- + @@ -544,7 +547,7 @@

- +

@@ -586,7 +589,7 @@ Your server also needs to have a valid UUID, which is obtained by registering on maps in the Identification & Map tab.

- +

You can also fill in your OMID from FMLIST.org, if you want the logs to be saved to your account.