Finalizing Server webUI
Still needed: - Way to update clients' versions - Way to delete nodes - working dashboard - working search function
This commit is contained in:
@@ -98,4 +98,4 @@ log.DEBUG(`Starting HTTP Server`);
|
||||
runHTTPServer();
|
||||
|
||||
log.DEBUG("Checking in with the master server")
|
||||
checkIn();
|
||||
checkIn(true);
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"Westchester Cty. Simulcast":{"frequencies":[470575000,470375000,470525000,470575000,470550000],"mode":"p25","trunkFile":"trunk.tsv"},"coppies":{"frequencies":[154690000],"mode":"nbfm","trunkFile":"none"},"poopoo":{"frequencies":[479135500],"mode":"nbfm","trunkFile":"none"},"ppeeeeeeeeee":{"frequencies":[479135500,133990000,133000000,555999000],"mode":"p25","trunkFile":"none"}}
|
||||
{"Westchester Cty. Simulcast":{"frequencies":[470575000,470375000,470525000,470575000,470550000],"mode":"p25","trunkFile":"trunk.tsv"},"coppies":{"frequencies":[154690000],"mode":"nbfm","trunkFile":"none"},"asdadadadasd":{"frequencies":[123321000],"mode":"nbfm","trunkFile":"none"}}
|
||||
@@ -5,13 +5,14 @@ const log = new DebugBuilder("client", "clientController");
|
||||
require('dotenv').config();
|
||||
const modes = require("../config/modes");
|
||||
// Modules
|
||||
const { executeAsyncConsoleCommand, nodeObject, BufferToJson } = require("../utilities/utilities");
|
||||
const { executeAsyncConsoleCommand, BufferToJson } = require("../utilities/utilities");
|
||||
// Utilities
|
||||
const { updateId, updateConfig } = require("../utilities/updateConfig");
|
||||
const { getFullConfig } = require("../utilities/configHandler");
|
||||
const { updateId, updateConfig, updateClientConfig } = require("../utilities/updateConfig");
|
||||
const { updatePreset, addNewPreset, getPresets, removePreset } = require("../utilities/updatePresets");
|
||||
const { onHttpError, requestOptions, sendHttpRequest } = require("../utilities/httpRequests");
|
||||
|
||||
var runningClientConfig = new nodeObject({_id: process.env.CLIENT_ID, _ip: process.env.CLIENT_IP, _name: process.env.CLIENT_NAME, _port: process.env.CLIENT_PORT, _location: process.env.CLIENT_LOCATION, _nearbySystems: getPresets(), _online: process.env.CLIENT_ONLINE});
|
||||
var runningClientConfig = getFullConfig()
|
||||
|
||||
/**
|
||||
* Check the body for the required fields to update or add a preset
|
||||
@@ -97,12 +98,11 @@ exports.checkConfig = async function checkConfig() {
|
||||
* If the bot has a saved ID, check in with the server to get any updated information or just check back in
|
||||
* If the bot does not have a saved ID, it will attempt to request a new ID from the server
|
||||
*
|
||||
* @param {boolean} init If set to true, the client will update the server to it's config, instead of taking the server's config
|
||||
* @param {boolean} update If set to true, the client will update the server to it's config, instead of taking the server's config
|
||||
*/
|
||||
exports.checkIn = async (init = false) => {
|
||||
exports.checkIn = async (update = false) => {
|
||||
let reqOptions;
|
||||
await this.checkConfig();
|
||||
runningClientConfig.online = true;
|
||||
// Check if there is an ID found, if not add the node to the server. If there was an ID, check in with the server to make sure it has the correct information
|
||||
try {
|
||||
if (!runningClientConfig?.id || runningClientConfig.id == 0) {
|
||||
@@ -136,7 +136,7 @@ exports.checkIn = async (init = false) => {
|
||||
}
|
||||
else {
|
||||
// ID is in the config, checking in with the server
|
||||
if (init) reqOptions = new requestOptions(`/nodes/${runningClientConfig.id}`, "PUT");
|
||||
if (update) reqOptions = new requestOptions(`/nodes/${runningClientConfig.id}`, "PUT");
|
||||
else reqOptions = new requestOptions(`/nodes/nodeCheckIn/${runningClientConfig.id}`, "POST");
|
||||
sendHttpRequest(reqOptions, JSON.stringify(runningClientConfig), (responseObject) => {
|
||||
log.DEBUG("Check In Respose: ", responseObject);
|
||||
@@ -156,6 +156,8 @@ exports.checkIn = async (init = false) => {
|
||||
}
|
||||
if (responseObject.statusCode === 200) {
|
||||
// Server accepted the response but there were no keys to be updated
|
||||
const tempUpdatedConfig = updateClientConfig(responseObject.body);
|
||||
if (!tempUpdatedConfig.length > 0) return;
|
||||
}
|
||||
if (responseObject.statusCode >= 300) {
|
||||
// Server threw an error
|
||||
@@ -192,6 +194,7 @@ exports.updatePreset = async (req, res) => {
|
||||
checkBodyForPresetFields(req, res, () => {
|
||||
updatePreset(req.body.systemName, () => {
|
||||
runningClientConfig.nearbySystems = getPresets();
|
||||
this.checkIn(true);
|
||||
return res.sendStatus(200);
|
||||
}, {frequencies: req.body.frequencies, mode: req.body.mode, trunkFile: req.body.trunkFile});
|
||||
})
|
||||
@@ -204,6 +207,7 @@ exports.addNewPreset = async (req, res) => {
|
||||
checkBodyForPresetFields(req, res, () => {
|
||||
addNewPreset(req.body.systemName, req.body.frequencies, req.body.mode, () => {
|
||||
runningClientConfig.nearbySystems = getPresets();
|
||||
this.checkIn(true);
|
||||
return res.sendStatus(200);
|
||||
}, req.body.trunkFile);
|
||||
});
|
||||
@@ -217,6 +221,7 @@ exports.removePreset = async (req, res) => {
|
||||
if (!req.body.systemName) return res.status("500").json({"message": "You must specify a system name to delete, this must match exactly to how the system name is saved."})
|
||||
removePreset(req.body.systemName, () => {
|
||||
runningClientConfig.nearbySystems = getPresets();
|
||||
this.checkIn(true);
|
||||
return res.sendStatus(200);
|
||||
}, req.body.trunkFile);
|
||||
});
|
||||
|
||||
@@ -11,6 +11,11 @@ const { requestCheckIn, getPresets, updatePreset, addNewPreset, removePreset, up
|
||||
*/
|
||||
router.get('/requestCheckIn', requestCheckIn);
|
||||
|
||||
/** GET Object of all known presets
|
||||
* Query the client to get all the known presets
|
||||
*/
|
||||
router.put('/', );
|
||||
|
||||
/** GET Object of all known presets
|
||||
* Query the client to get all the known presets
|
||||
*/
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder.js");
|
||||
const log = new DebugBuilder("client", "configController");
|
||||
// Modules
|
||||
const { nodeObject } = require("./utilities.js");
|
||||
const { getPresets } = require("../utilities/updatePresets");
|
||||
const { readFileSync } = require('fs');
|
||||
const path = require("path");
|
||||
require('dotenv').config();
|
||||
@@ -33,4 +35,8 @@ function getDeviceName(){
|
||||
log.DEBUG("Device Name: ", DeviceName);
|
||||
return DeviceName;
|
||||
}
|
||||
exports.getDeviceName = getDeviceID;
|
||||
exports.getDeviceName = getDeviceID;
|
||||
|
||||
exports.getFullConfig = () => {
|
||||
return new nodeObject({_id: process.env.CLIENT_ID, _ip: process.env.CLIENT_IP, _name: process.env.CLIENT_NAME, _port: process.env.CLIENT_PORT, _location: process.env.CLIENT_LOCATION, _nearbySystems: getPresets()});
|
||||
}
|
||||
@@ -9,7 +9,7 @@ const { isJsonString } = require("./utilities.js");
|
||||
|
||||
exports.requestOptions = class requestOptions {
|
||||
constructor(path, method, hostname = undefined, headers = undefined, port = undefined) {
|
||||
if (method === "POST"){
|
||||
if (["POST", "PUT"].includes(method)){
|
||||
log.VERBOSE("Hostname Vars: ", hostname, process.env.SERVER_HOSTNAME, process.env.SERVER_IP);
|
||||
if (hostname) this.hostname = hostname;
|
||||
if (process.env.SERVER_HOSTNAME) this.hostname = process.env.SERVER_HOSTNAME;
|
||||
|
||||
@@ -3,6 +3,7 @@ const { DebugBuilder } = require("../utilities/debugBuilder.js");
|
||||
const log = new DebugBuilder("client", "updateConfig");
|
||||
// Modules
|
||||
const replace = require('replace-in-file');
|
||||
const { getFullConfig } = require("./configHandler.js");
|
||||
|
||||
class Options {
|
||||
constructor(key, updatedValue) {
|
||||
@@ -23,6 +24,56 @@ exports.updateId = (updatedId) => {
|
||||
this.updateConfig('CLIENT_ID', updatedId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to update any or all keys in the client config
|
||||
*
|
||||
* @param {*} configObject Object with what keys you wish to update (node object format, will be converted)
|
||||
* @returns
|
||||
*/
|
||||
exports.updateClientConfig = (configObject) => {
|
||||
const runningConfig = getFullConfig();
|
||||
var updatedKeys = []
|
||||
const configKeys = Object.keys(configObject);
|
||||
|
||||
if (configKeys.includes("id")) {
|
||||
if (runningConfig.id != configObject.id) {
|
||||
this.updateConfig('CLIENT_ID', configObject.id);
|
||||
updatedKeys.push({'CLIENT_ID': configObject.id});
|
||||
log.DEBUG("Updated ID to: ", configObject.id);
|
||||
}
|
||||
}
|
||||
if (configKeys.includes("name")) {
|
||||
if (runningConfig.name != configObject.name) {
|
||||
this.updateConfig('CLIENT_NAME', configObject.name);
|
||||
updatedKeys.push({'CLIENT_NAME': configObject.name});
|
||||
log.DEBUG("Updated name to: ", configObject.name);
|
||||
}
|
||||
}
|
||||
if (configKeys.includes("ip")) {
|
||||
if (runningConfig.ip != configObject.ip) {
|
||||
this.updateConfig('CLIENT_IP', configObject.ip);
|
||||
updatedKeys.push({'CLIENT_IP': configObject.ip});
|
||||
log.DEBUG("Updated ip to: ", configObject.ip);
|
||||
}
|
||||
}
|
||||
if (configKeys.includes("port")) {
|
||||
if (runningConfig.port != configObject.port) {
|
||||
this.updateConfig('CLIENT_PORT', configObject.port);
|
||||
updatedKeys.push({'CLIENT_PORT': configObject.port});
|
||||
log.DEBUG("Updated port to: ", configObject.port);
|
||||
}
|
||||
}
|
||||
if (configKeys.includes("location")) {
|
||||
if (runningConfig.location != configObject.location) {
|
||||
this.updateConfig('CLIENT_LOCATION', configObject.location);
|
||||
updatedKeys.push({'CLIENT_LOCATION': configObject.location});
|
||||
log.DEBUG("Updated location to: ", configObject.location);
|
||||
}
|
||||
}
|
||||
|
||||
return updatedKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} key The config file key to update with the value
|
||||
@@ -37,7 +88,6 @@ exports.updateConfig = function updateConfig(key, value) {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wrapper to write changes to the file
|
||||
* @param options An instance of the Objects class specified to the key being updated
|
||||
|
||||
@@ -25,17 +25,15 @@ exports.nodeObject = class nodeObject {
|
||||
* @param {*} param0._ip The IP that the master can contact the node at
|
||||
* @param {*} param0._port The port that the client is listening on
|
||||
* @param {*} param0._location The physical location of the node
|
||||
* @param {*} param0._online An integer representation of the online status of the bot, ie 0=off, 1=on
|
||||
* @param {*} param0._nearbySystems An object array of nearby systems
|
||||
*/
|
||||
constructor({ _id = null, _name = null, _ip = null, _port = null, _location = null, _nearbySystems = null, _online = null }) {
|
||||
constructor({ _id = null, _name = null, _ip = null, _port = null, _location = null, _nearbySystems = null }) {
|
||||
this.id = _id;
|
||||
this.name = _name;
|
||||
this.ip = _ip;
|
||||
this.port = _port;
|
||||
this.location = _location;
|
||||
this.nearbySystems = _nearbySystems;
|
||||
this.online = _online;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user