diff --git a/index.js b/index.js index 6247510..df8e2d5 100644 --- a/index.js +++ b/index.js @@ -334,7 +334,7 @@ app.get('/getDevices', (req, res) => { */ wss.on('connection', (ws, request) => { - const clientIp = request.connection.remoteAddress; + const clientIp = request.headers['x-forwarded-for'] || request.connection.remoteAddress; currentUsers++; dataHandler.showOnlineUsers(currentUsers); @@ -409,4 +409,4 @@ httpServer.listen(serverConfig.webserver.webserverPort, serverConfig.webserver.w module.exports = { serverConfig -} \ No newline at end of file +} diff --git a/web/index.ejs b/web/index.ejs index 22230c4..49dcbed 100644 --- a/web/index.ejs +++ b/web/index.ejs @@ -11,7 +11,7 @@ - + @@ -230,11 +230,11 @@ <% if (isAdminAuthenticated) { %> -

You are logged in as an adminstrator. Setup | Logout

+

You are logged in as an adminstrator. Setup | Logout

<% } else if (isTuneAuthenticated) { %>

You are logged in and can control the receiver. Logout

<% } else { %> -
+ @@ -258,4 +258,4 @@ - \ No newline at end of file + diff --git a/web/js/main.js b/web/js/main.js index 7c64796..ab3c5ae 100644 --- a/web/js/main.js +++ b/web/js/main.js @@ -1,7 +1,6 @@ -var hostParts = window.location.host.split(':'); -var hostname = hostParts[0]; // Extract the hostname -var port = hostParts[1] || '8080'; // Extract the port or use a default (e.g., 8080) -var socketAddress = 'ws://' + hostname + ':' + port + '/text'; // Use 'wss' for secure WebSocket connections (recommended for external access) +var url = new URL('text', window.location.href); +url.protocol = url.protocol.replace('http', 'ws'); +var socketAddress = url.href; var socket = new WebSocket(socketAddress); var parsedData; var data = []; @@ -121,7 +120,7 @@ $(document).ready(function() { function getInitialSettings() { $.ajax({ - url: '/static_data', + url: './static_data', dataType: 'json', success: function(data) { // Use the received data (data.qthLatitude, data.qthLongitude) as needed @@ -521,4 +520,4 @@ function toggleButtonState(buttonId) { message += parsedData.eq ? "1" : "0"; message += parsedData.ims ? "1" : "0"; socket.send(message); -} \ No newline at end of file +} diff --git a/web/js/settings.js b/web/js/settings.js index 3a722d7..5c79858 100644 --- a/web/js/settings.js +++ b/web/js/settings.js @@ -54,7 +54,7 @@ // Perform an AJAX request to the /login endpoint $.ajax({ type: 'POST', - url: '/login', + url: './login', data: $(this).serialize(), success: function (data) { // Update the content on the page with the message from the response @@ -83,7 +83,7 @@ // Perform an AJAX request to the /logout endpoint $.ajax({ type: 'GET', // Assuming the logout is a GET request, adjust accordingly - url: '/logout', + url: './logout', success: function (data) { // Update the content on the page with the message from the response $('#login-message').text(data.message); @@ -113,4 +113,4 @@ $(':root').css('--color-main', themeColors[0]); $(':root').css('--color-main-bright', themeColors[1]); } - } \ No newline at end of file + } diff --git a/web/js/setup.js b/web/js/setup.js index 704ebf8..83a9651 100644 --- a/web/js/setup.js +++ b/web/js/setup.js @@ -2,10 +2,6 @@ var map; var pin; var tilesURL='https://tiles.stadiamaps.com/tiles/alidade_smooth_dark/{z}/{x}/{y}.png'; var mapAttrib='© OpenStreetMap, Tiles by Stadiamaps'; -var hostParts = window.location.host.split(':'); -var hostname = hostParts[0]; // Extract the hostname -var port = hostParts[1] || '80'; // Extract the port or use a default (e.g., 8080) -var serverAddress = 'http://' + hostname + ':' + port; // add map container @@ -36,7 +32,7 @@ $(document).ready(function() { // Perform an AJAX request to the /login endpoint $.ajax({ type: 'POST', - url: '/login', + url: './login', data: $(this).serialize(), success: function (data) { // Update the content on the page with the message from the response @@ -65,7 +61,7 @@ $(document).ready(function() { // Perform an AJAX request to the /logout endpoint $.ajax({ type: 'GET', // Assuming the logout is a GET request, adjust accordingly - url: '/logout', + url: './logout', success: function (data) { // Update the content on the page with the message from the response $('#login-message').text(data.message); @@ -108,7 +104,7 @@ function MapCreate() { function fetchData() { // Make a GET request to retrieve the data.json file - fetch(serverAddress + "/getData") + fetch("./getData") .then(response => { if (!response.ok) { throw new Error(`HTTP error! Status: ${response.status}`); @@ -231,7 +227,7 @@ function submitData() { } // Send data to the server using jQuery $.ajax({ - url: serverAddress + '/saveData', + url: './saveData', type: 'POST', contentType: 'application/json', data: JSON.stringify(data), @@ -242,4 +238,4 @@ function submitData() { console.error(error); } }); - } \ No newline at end of file + } diff --git a/web/js/webserver.js b/web/js/webserver.js index cf91a64..ae228c2 100644 --- a/web/js/webserver.js +++ b/web/js/webserver.js @@ -1,4 +1,4 @@ -$.getScript('/js/main.js'); -$.getScript('/js/dropdown.js'); -$.getScript('/js/modal.js'); -$.getScript('/js/settings.js'); \ No newline at end of file +$.getScript('./js/main.js'); +$.getScript('./js/dropdown.js'); +$.getScript('./js/modal.js'); +$.getScript('./js/settings.js'); diff --git a/web/setup.ejs b/web/setup.ejs index a3e7de4..2b4377e 100644 --- a/web/setup.ejs +++ b/web/setup.ejs @@ -150,7 +150,7 @@

Feel free to contact us on Discord for community support.

- + <% } else { %>

FM-DX WebServer

@@ -160,7 +160,7 @@

LOGIN

- + @@ -172,4 +172,4 @@ - \ No newline at end of file +