Multiple changes and documentation.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Baseline
|
||||
const product = 'NetRadius';
|
||||
const version = '0.2.0';
|
||||
const version = '0.4.0';
|
||||
|
||||
// Load dependencies
|
||||
const dgram = require ('dgram');
|
||||
@@ -13,44 +13,16 @@ const handlers = require ('./lib/handlers.js');
|
||||
|
||||
// Load configuration
|
||||
log.write (product + ' v' + version);
|
||||
config = {};
|
||||
try {
|
||||
config = JSON.parse (fs.readFileSync ('./config.json').toString ());
|
||||
}
|
||||
catch (error) {
|
||||
log.write ('Cannot open or read configuration file.');
|
||||
log.write ('Using defaults');
|
||||
config = {
|
||||
ports: {
|
||||
radius_authentication: 1812,
|
||||
radius_accounting: 1813,
|
||||
api: 8088
|
||||
},
|
||||
storage: "json:./data.json",
|
||||
client_secret: "password",
|
||||
default_vlan_enabled: false,
|
||||
mac_auth_only: false,
|
||||
session_duration: 60,
|
||||
time_rules_enabled: false
|
||||
}
|
||||
}
|
||||
if (process.env['SINATRA_PORT_RADIUS_AUTH']) config.ports.radius_authentication = process.env['SINATRA_PORT_RADIUS_AUTH'];
|
||||
if (process.env['SINATRA_PORT_RADIUS_ACCT']) config.ports.radius_accounting = process.env['SINATRA_PORT_RADIUS_ACCT'];
|
||||
if (process.env['SINATRA_PORT_API']) config.ports.api = process.env['SINATRA_PORT_API'];
|
||||
if (process.env['SINATRA_STORAGE']) config.storage = process.env['SINATRA_STORAGE'];
|
||||
if (process.env['SINATRA_DEFAULT_VLAN']) config.default_vlan_enabled = process.env['SINATRA_DEFAULT_VLAN'];
|
||||
if (process.env['SINATRA_DEFAULT_VLAN_ID']) config.default_vlan_id = process.env['SINATRA_DEFAULT_VLAN_ID'];
|
||||
if (process.env['SINATRA_CLIENT_SECRET']) config.client_secret = process.env['SINATRA_CLIENT_SECRET'];
|
||||
if (process.env['SINATRA_MAC_AUTH_ONLY']) config.mac_auth_only = process.env['SINATRA_MAC_AUTH_ONLY'];
|
||||
if (process.env['SINATRA_SESSION_DURATION']) config.session_duration = process.env['SINATRA_SESSION_DURATION'];
|
||||
if (process.env['SINATRA_TIME_RULES']) config.time_rules_enabled = process.env['SINATRA_TIME_RULES'];
|
||||
|
||||
// Set defaults
|
||||
if (!config.ports.radius_authentication) config.ports.radius_authentication = 1812;
|
||||
if (!config.ports.radius_accounting) config.ports.radius_accounting = 1813;
|
||||
if (!config.ports.api) config.ports.api = 8088;
|
||||
if (!config.session_duration) config.session_duration = 60;
|
||||
if (!config.time_rules_enabled) config.time_rules_enabled = false;
|
||||
config = { ports: {} };
|
||||
config.ports.radius_authentication = process.env['SINATRA_PORT_RADIUS_AUTH'] || 1812;
|
||||
config.ports.radius_accounting = process.env['SINATRA_PORT_RADIUS_ACCT'] || 1813;
|
||||
config.ports.api = process.env['SINATRA_PORT_API'] || 8088;
|
||||
config.storage = process.env['SINATRA_STORAGE'] || "json:./data.json";
|
||||
config.client_secret = process.env['SINATRA_CLIENT_SECRET'] || "password";
|
||||
config.default_vlan = process.env['SINATRA_DEFAULT_VLAN'] || false;
|
||||
config.mac_auth_only = process.env['SINATRA_MAC_AUTH_ONLY'] || false;
|
||||
config.session_duration = process.env['SINATRA_SESSION_DURATION'] || 60;
|
||||
config.time_rules = process.env['SINATRA_TIME_RULES'] || false;
|
||||
|
||||
// Display active configuration
|
||||
log.write ('Using configuration: ' + JSON.stringify (config));
|
||||
|
||||
@@ -41,7 +41,7 @@ const resolveRange = (str) => {
|
||||
module.exports = {
|
||||
checkAuth: (rules = []) => {
|
||||
var authorised = false;
|
||||
if (config.time_rules_enabled) {
|
||||
if (config.time_rules) {
|
||||
if (rules.length > 0) {
|
||||
var now = new Date ();
|
||||
var minuteOfDay = (now.getHours () * 60) + now.getMinutes (); // 0 - 1439
|
||||
|
||||
Reference in New Issue
Block a user