You've already forked fm-dx-webserver
mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-02-26 22:13:53 +01:00
auth & console bugfixes
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
./example.js
|
/example.js
|
||||||
./userconfig.json
|
/userconfig.json
|
||||||
|
/userconfig_backup.js
|
||||||
29
console.js
29
console.js
@@ -1,17 +1,22 @@
|
|||||||
const { verboseMode } = require('./userconfig');
|
const { verboseMode } = require('./userconfig');
|
||||||
|
|
||||||
const MESSAGE_PREFIX = {
|
const getCurrentTime = () => {
|
||||||
INFO: "\x1b[32m[INFO]\x1b[0m",
|
const currentTime = new Date();
|
||||||
DEBUG: "\x1b[36m[DEBUG]\x1b[0m",
|
const hours = currentTime.getHours().toString().padStart(2, '0');
|
||||||
};
|
const minutes = currentTime.getMinutes().toString().padStart(2, '0');
|
||||||
|
return `\x1b[90m[${hours}:${minutes}]\x1b[0m`;
|
||||||
const logInfo = (...messages) => console.log(MESSAGE_PREFIX.INFO, ...messages);
|
|
||||||
const logDebug = (...messages) => {
|
|
||||||
if (verboseMode) {
|
|
||||||
console.log(MESSAGE_PREFIX.DEBUG, ...messages);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const MESSAGE_PREFIX = {
|
||||||
|
DEBUG: "\x1b[36m[DEBUG]\x1b[0m",
|
||||||
|
INFO: "\x1b[32m[INFO]\x1b[0m",
|
||||||
|
WARN: "\x1b[33m[WARN]\x1b[0m",
|
||||||
|
};
|
||||||
|
|
||||||
|
const logDebug = (...messages) => verboseMode ? console.log(getCurrentTime(), MESSAGE_PREFIX.DEBUG, ...messages) : '';
|
||||||
|
const logInfo = (...messages) => console.log(getCurrentTime(), MESSAGE_PREFIX.INFO, ...messages);
|
||||||
|
const logWarn = (...messages) => console.log(getCurrentTime(), MESSAGE_PREFIX.WARN, ...messages);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
logInfo, logDebug
|
logInfo, logDebug, logWarn
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -197,6 +197,7 @@ var dataToSend = {
|
|||||||
country_iso: 'UN',
|
country_iso: 'UN',
|
||||||
users: '',
|
users: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
var legacyRdsPiBuffer = null;
|
var legacyRdsPiBuffer = null;
|
||||||
const initialData = { ...dataToSend };
|
const initialData = { ...dataToSend };
|
||||||
const resetToDefault = dataToSend => Object.assign(dataToSend, initialData);
|
const resetToDefault = dataToSend => Object.assign(dataToSend, initialData);
|
||||||
@@ -297,5 +298,5 @@ function showOnlineUsers(currentUsers) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
handleData, showOnlineUsers
|
handleData, showOnlineUsers, dataToSend
|
||||||
};
|
};
|
||||||
|
|||||||
66
index.js
66
index.js
@@ -61,32 +61,60 @@ function authenticateWithXdrd(client, salt, password) {
|
|||||||
|
|
||||||
// WebSocket client connection
|
// WebSocket client connection
|
||||||
client.connect(xdrdServerPort, xdrdServerHost, () => {
|
client.connect(xdrdServerPort, xdrdServerHost, () => {
|
||||||
consoleCmd.logInfo('Connected to xdrd successfully.');
|
consoleCmd.logInfo('Connection to xdrd established successfully.');
|
||||||
|
|
||||||
client.once('data', (data) => {
|
const authFlags = {
|
||||||
|
authMsg: false,
|
||||||
|
firstClient: false,
|
||||||
|
receivedPassword: false
|
||||||
|
};
|
||||||
|
|
||||||
|
const authDataHandler = (data) => {
|
||||||
const receivedData = data.toString();
|
const receivedData = data.toString();
|
||||||
const lines = receivedData.split('\n');
|
const lines = receivedData.split('\n');
|
||||||
|
|
||||||
// Salt reading, so we can authenticate
|
for (const line of lines) {
|
||||||
if (lines.length > 0 && !receivedPassword) {
|
|
||||||
receivedSalt = lines[0].trim();
|
if (!authFlags.receivedPassword) {
|
||||||
authenticateWithXdrd(client, receivedSalt, xdrdPassword);
|
authFlags.receivedSalt = line.trim();
|
||||||
receivedPassword = true;
|
authenticateWithXdrd(client, authFlags.receivedSalt, xdrdPassword);
|
||||||
|
authFlags.receivedPassword = true;
|
||||||
|
} else {
|
||||||
|
if (line.startsWith('a')) {
|
||||||
|
authFlags.authMsg = true;
|
||||||
|
consoleCmd.logWarn('Authentication with xdrd failed. Is your password set correctly?');
|
||||||
|
} else if (line.startsWith('o1')) {
|
||||||
|
authFlags.firstClient = true;
|
||||||
|
} else if (line.startsWith('T') && line.length <= 7) {
|
||||||
|
const freq = line.slice(1) / 1000;
|
||||||
|
dataHandler.dataToSend.freq = freq.toFixed(3);
|
||||||
|
} else if (line.startsWith('OK')) {
|
||||||
|
authFlags.authMsg = true;
|
||||||
|
consoleCmd.logInfo('Authentication with xdrd successful.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (authFlags.authMsg && authFlags.firstClient) {
|
||||||
|
client.write('T87500\n');
|
||||||
|
client.off('data', authDataHandler);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
client.on('data', (data) => {
|
||||||
|
const receivedData = data.toString();
|
||||||
|
|
||||||
|
wss.clients.forEach((client) => {
|
||||||
|
if (client.readyState === WebSocket.OPEN) {
|
||||||
|
dataHandler.handleData(client, receivedData);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
client.on('data', authDataHandler);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('data', (data) => {
|
|
||||||
const receivedData = data.toString();
|
|
||||||
|
|
||||||
wss.clients.forEach((client) => {
|
|
||||||
if (client.readyState === WebSocket.OPEN) {
|
|
||||||
dataHandler.handleData(client, receivedData);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
client.on('close', () => {
|
client.on('close', () => {
|
||||||
console.log('Disconnected from xdrd');
|
console.log('Disconnected from xdrd');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const webServerHost = '0.0.0.0'; // IP of the web server
|
|||||||
const webServerPort = 8080; // web server port
|
const webServerPort = 8080; // web server port
|
||||||
const webServerName = "Noobish's Server" // web server name (will be displayed in title, bookmarks...)
|
const webServerName = "Noobish's Server" // web server name (will be displayed in title, bookmarks...)
|
||||||
|
|
||||||
const xdrdServerHost = '192.168.1.15'; // xdrd server IP (if it's running on the same machine, use 127.0.0.1)
|
const xdrdServerHost = '127.0.0.1'; // xdrd server IP (if it's running on the same machine, use 127.0.0.1)
|
||||||
const xdrdServerPort = 7373; // xdrd server port
|
const xdrdServerPort = 7373; // xdrd server port
|
||||||
const xdrdPassword = 'password'; // xdrd password (optional)
|
const xdrdPassword = 'password'; // xdrd password (optional)
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ $(document).ready(function() {
|
|||||||
canvas.width = canvas.parentElement.clientWidth;
|
canvas.width = canvas.parentElement.clientWidth;
|
||||||
|
|
||||||
var data = [];
|
var data = [];
|
||||||
var maxDataPoints = 250;
|
var maxDataPoints = 300;
|
||||||
var pointWidth = (canvas.width - 80) / maxDataPoints;
|
var pointWidth = (canvas.width - 80) / maxDataPoints;
|
||||||
|
|
||||||
var europe_programmes = [
|
var europe_programmes = [
|
||||||
@@ -52,15 +52,15 @@ $(document).ready(function() {
|
|||||||
function updateCanvas() {
|
function updateCanvas() {
|
||||||
const color2 = getComputedStyle(document.documentElement).getPropertyValue('--color-2').trim();
|
const color2 = getComputedStyle(document.documentElement).getPropertyValue('--color-2').trim();
|
||||||
const color4 = getComputedStyle(document.documentElement).getPropertyValue('--color-4').trim();
|
const color4 = getComputedStyle(document.documentElement).getPropertyValue('--color-4').trim();
|
||||||
|
|
||||||
while (data.length >= maxDataPoints) {
|
while (data.length >= maxDataPoints) {
|
||||||
data.shift();
|
data.shift();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modify the WebSocket onmessage callback
|
// Modify the WebSocket onmessage callback
|
||||||
socket.onmessage = (event) => {
|
socket.onmessage = (event) => {
|
||||||
const parsedData = JSON.parse(event.data);
|
const parsedData = JSON.parse(event.data);
|
||||||
|
|
||||||
updatePanels(parsedData);
|
updatePanels(parsedData);
|
||||||
// Push the new signal data to the array
|
// Push the new signal data to the array
|
||||||
data.push(parsedData.signal);
|
data.push(parsedData.signal);
|
||||||
@@ -69,69 +69,71 @@ $(document).ready(function() {
|
|||||||
zoomMinValue = actualLowestValue - ((actualHighestValue - actualLowestValue) / 2);
|
zoomMinValue = actualLowestValue - ((actualHighestValue - actualLowestValue) / 2);
|
||||||
zoomMaxValue = actualHighestValue + ((actualHighestValue - actualLowestValue) / 2);
|
zoomMaxValue = actualHighestValue + ((actualHighestValue - actualLowestValue) / 2);
|
||||||
zoomAvgValue = (zoomMaxValue - zoomMinValue) / 2 + zoomMinValue;
|
zoomAvgValue = (zoomMaxValue - zoomMinValue) / 2 + zoomMinValue;
|
||||||
|
|
||||||
// Clear the canvas
|
// Clear the canvas
|
||||||
context.clearRect(0, 0, canvas.width, canvas.height);
|
context.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
// Draw the signal graph with zoom
|
// Draw the signal graph with zoom
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
context.moveTo(50, canvas.height - (data[0] - zoomMinValue) * (canvas.height / (zoomMaxValue - zoomMinValue)));
|
|
||||||
|
|
||||||
for (let i = 1; i < data.length; i++) {
|
// Start drawing from the rightmost point
|
||||||
const x = i * pointWidth;
|
const startingIndex = Math.max(0, data.length - maxDataPoints);
|
||||||
|
context.moveTo(canvas.width - 40 - (data.length - startingIndex) * pointWidth, canvas.height - (data[startingIndex] - zoomMinValue) * (canvas.height / (zoomMaxValue - zoomMinValue)));
|
||||||
|
|
||||||
|
for (let i = startingIndex + 1; i < data.length; i++) {
|
||||||
|
const x = canvas.width - (data.length - i) * pointWidth - 40;
|
||||||
const y = canvas.height - (data[i] - zoomMinValue) * (canvas.height / (zoomMaxValue - zoomMinValue));
|
const y = canvas.height - (data[i] - zoomMinValue) * (canvas.height / (zoomMaxValue - zoomMinValue));
|
||||||
context.lineTo(x + 40, y);
|
context.lineTo(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
context.strokeStyle = color4;
|
context.strokeStyle = color4;
|
||||||
context.lineWidth = 1;
|
context.lineWidth = 1;
|
||||||
context.stroke();
|
context.stroke();
|
||||||
|
|
||||||
// Draw horizontal lines for lowest, highest, and average values
|
// Draw horizontal lines for lowest, highest, and average values
|
||||||
context.strokeStyle = color2; // Set line color
|
context.strokeStyle = color2; // Set line color
|
||||||
context.lineWidth = 1;
|
context.lineWidth = 1;
|
||||||
|
|
||||||
// Draw the lowest value line
|
// Draw the lowest value line
|
||||||
const lowestY = canvas.height - (zoomMinValue - zoomMinValue) * (canvas.height / (zoomMaxValue - zoomMinValue));
|
const lowestY = canvas.height - (zoomMinValue - zoomMinValue) * (canvas.height / (zoomMaxValue - zoomMinValue));
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
context.moveTo(40, lowestY - 18);
|
context.moveTo(40, lowestY - 18);
|
||||||
context.lineTo(canvas.width - 40, lowestY - 18);
|
context.lineTo(canvas.width - 40, lowestY - 18);
|
||||||
context.stroke();
|
context.stroke();
|
||||||
|
|
||||||
// Draw the highest value line
|
// Draw the highest value line
|
||||||
const highestY = canvas.height - (zoomMaxValue - zoomMinValue) * (canvas.height / (zoomMaxValue - zoomMinValue));
|
const highestY = canvas.height - (zoomMaxValue - zoomMinValue) * (canvas.height / (zoomMaxValue - zoomMinValue));
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
context.moveTo(40, highestY + 10);
|
context.moveTo(40, highestY + 10);
|
||||||
context.lineTo(canvas.width - 40, highestY + 10);
|
context.lineTo(canvas.width - 40, highestY + 10);
|
||||||
context.stroke();
|
context.stroke();
|
||||||
|
|
||||||
const avgY = canvas.height / 2;
|
const avgY = canvas.height / 2;
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
context.moveTo(40, avgY - 7);
|
context.moveTo(40, avgY - 7);
|
||||||
context.lineTo(canvas.width - 40, avgY - 7);
|
context.lineTo(canvas.width - 40, avgY - 7);
|
||||||
context.stroke();
|
context.stroke();
|
||||||
|
|
||||||
// Label the lines with their values
|
// Label the lines with their values
|
||||||
context.fillStyle = color4;
|
context.fillStyle = color4;
|
||||||
context.font = '12px Titillium Web';
|
context.font = '12px Titillium Web';
|
||||||
|
|
||||||
const offset = signalToggle.prop('checked') ? 11.75 : 0;
|
const offset = signalToggle.prop('checked') ? 11.75 : 0;
|
||||||
context.textAlign = 'right';
|
context.textAlign = 'right';
|
||||||
context.fillText(`${(zoomMinValue - offset).toFixed(1)}`, 35, lowestY - 14);
|
context.fillText(`${(zoomMinValue - offset).toFixed(1)}`, 35, lowestY - 14);
|
||||||
context.fillText(`${(zoomMaxValue - offset).toFixed(1)}`, 35, highestY + 14);
|
context.fillText(`${(zoomMaxValue - offset).toFixed(1)}`, 35, highestY + 14);
|
||||||
context.fillText(`${(zoomAvgValue - offset).toFixed(1)}`, 35, avgY - 3);
|
context.fillText(`${(zoomAvgValue - offset).toFixed(1)}`, 35, avgY - 3);
|
||||||
|
|
||||||
context.textAlign = 'left';
|
context.textAlign = 'left';
|
||||||
context.fillText(`${(zoomMinValue - offset).toFixed(1)}`, canvas.width - 35, lowestY - 14);
|
context.fillText(`${(zoomMinValue - offset).toFixed(1)}`, canvas.width - 35, lowestY - 14);
|
||||||
context.fillText(`${(zoomMaxValue - offset).toFixed(1)}`, canvas.width - 35, highestY + 14);
|
context.fillText(`${(zoomMaxValue - offset).toFixed(1)}`, canvas.width - 35, highestY + 14);
|
||||||
context.fillText(`${(zoomAvgValue - offset).toFixed(1)}`, canvas.width - 35, avgY - 3);
|
context.fillText(`${(zoomAvgValue - offset).toFixed(1)}`, canvas.width - 35, avgY - 3);
|
||||||
|
|
||||||
// Update the data container with the latest data
|
// Update the data container with the latest data
|
||||||
dataContainer.html(event.data + '<br>');
|
dataContainer.html(event.data + '<br>');
|
||||||
};
|
};
|
||||||
requestAnimationFrame(updateCanvas);
|
requestAnimationFrame(updateCanvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function compareNumbers(a, b) {
|
function compareNumbers(a, b) {
|
||||||
|
|||||||
Reference in New Issue
Block a user