add radius check

This commit is contained in:
Sascha Kruse
2022-05-12 11:48:38 +02:00
parent 8077744c60
commit 398ecb7666
8 changed files with 127 additions and 4 deletions

View File

@@ -10,6 +10,12 @@ const chardet = require("chardet");
const mqtt = require("mqtt");
const chroma = require("chroma-js");
const { badgeConstants } = require("./config");
const radiusClient = require("node-radius-client");
const {
dictionaries: {
rfc2865: { file, attributes },
},
} = require("node-radius-utils");
// From ping-lite
exports.WIN = /^win/.test(process.platform);
@@ -203,6 +209,30 @@ exports.dnsResolve = function (hostname, resolverServer, rrtype) {
});
};
exports.radius = function (
hostname,
username,
password,
calledStationId,
callingStationId,
secret,
) {
const client = new radiusClient({
host: hostname,
dictionaries: [ file ],
});
return client.accessRequest({
secret: secret,
attributes: [
[ attributes.USER_NAME, username ],
[ attributes.USER_PASSWORD, password ],
[ attributes.CALLING_STATION_ID, callingStationId ],
[ attributes.CALLED_STATION_ID, calledStationId ],
],
});
};
/**
* Retrieve value of setting based on key
* @param {string} key Key of setting to retrieve