From f459ea845c6a1b192fa35efa44f3116aca921dd1 Mon Sep 17 00:00:00 2001 From: Matthew Nickson Date: Wed, 12 Oct 2022 17:32:05 +0100 Subject: [PATCH] Added #2182 Add support for custom radius ports (#2197) This commit adds support for the port to be specified when using the radius monitor type. A check has been implemented to ensure that a null value is not passed to the radius check function as could occur with monitors that were created before this change was introduced. The default port of 1812 is displayed when the user selects the radius monitor in much the same way as the DNS port is handled. The port was not included in the hostname in the form hostname:port in order to avoid issues with IPv6 addresses and monitors that had been created before this change was implemented. Signed-off-by: Matthew Nickson Signed-off-by: Matthew Nickson --- server/model/monitor.js | 14 +++++++++++++- server/util-server.js | 13 +++++++++++++ src/pages/EditMonitor.vue | 8 +++++--- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index ac892560..c0a3cce6 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -534,6 +534,17 @@ class Monitor extends BeanModel { bean.ping = dayjs().valueOf() - startTime; } else if (this.type === "radius") { let startTime = dayjs().valueOf(); + + // Handle monitors that were created before the + // update and as such don't have a value for + // this.port. + let port; + if (this.port == null) { + port = 1812; + } else { + port = this.port; + } + try { const resp = await radius( this.hostname, @@ -541,7 +552,8 @@ class Monitor extends BeanModel { this.radiusPassword, this.radiusCalledStationId, this.radiusCallingStationId, - this.radiusSecret + this.radiusSecret, + port ); if (resp.code) { bean.msg = resp.code; diff --git a/server/util-server.js b/server/util-server.js index cf303ba8..b975a43f 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -291,6 +291,17 @@ exports.postgresQuery = function (connectionString, query) { }); }; +/** + * Query radius server + * @param {string} hostname Hostname of radius server + * @param {string} username Username to use + * @param {string} password Password to use + * @param {string} calledStationId ID of called station + * @param {string} callingStationId ID of calling station + * @param {string} secret Secret to use + * @param {number} [port=1812] Port to contact radius server on + * @returns {Promise} + */ exports.radius = function ( hostname, username, @@ -298,9 +309,11 @@ exports.radius = function ( calledStationId, callingStationId, secret, + port = 1812, ) { const client = new radiusClient({ host: hostname, + hostPort: port, dictionaries: [ file ], }); diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 99cbeb95..6d1a7e51 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -97,8 +97,8 @@ - -
+ +
@@ -616,9 +616,11 @@ export default { } // Set default port for DNS if not already defined - if (! this.monitor.port || this.monitor.port === "53") { + if (! this.monitor.port || this.monitor.port === "53" || this.monitor.port === "1812") { if (this.monitor.type === "dns") { this.monitor.port = "53"; + } else if (this.monitor.type === "radius") { + this.monitor.port = "1812"; } else { this.monitor.port = undefined; }