Added time rule flags
This commit is contained in:
parent
8265e89d69
commit
a3e0cc381b
@ -30,7 +30,8 @@ catch (error) {
|
|||||||
client_secret: "password",
|
client_secret: "password",
|
||||||
default_vlan_enabled: false,
|
default_vlan_enabled: false,
|
||||||
mac_auth_only: false,
|
mac_auth_only: false,
|
||||||
session_duration: 60
|
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_AUTH']) config.ports.radius_authentication = process.env['SINATRA_PORT_RADIUS_AUTH'];
|
||||||
@ -42,12 +43,14 @@ if (process.env['SINATRA_DEFAULT_VLAN_ID']) config.default_vlan_id = process.env
|
|||||||
if (process.env['SINATRA_CLIENT_SECRET']) config.client_secret = process.env['SINATRA_CLIENT_SECRET'];
|
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_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_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
|
// Set defaults
|
||||||
if (!config.ports.radius_authentication) config.ports.radius_authentication = 1812;
|
if (!config.ports.radius_authentication) config.ports.radius_authentication = 1812;
|
||||||
if (!config.ports.radius_accounting) config.ports.radius_accounting = 1813;
|
if (!config.ports.radius_accounting) config.ports.radius_accounting = 1813;
|
||||||
if (!config.ports.api) config.ports.api = 8088;
|
if (!config.ports.api) config.ports.api = 8088;
|
||||||
if (!config.session_duration) config.session_duration = 1800;
|
if (!config.session_duration) config.session_duration = 60;
|
||||||
|
if (!config.time_rules_enabled) config.time_rules_enabled = false;
|
||||||
|
|
||||||
// Display active configuration
|
// Display active configuration
|
||||||
log.write ('Using configuration: ' + JSON.stringify (config));
|
log.write ('Using configuration: ' + JSON.stringify (config));
|
||||||
|
|||||||
@ -41,40 +41,45 @@ const resolveRange = (str) => {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
checkAuth: (rules = []) => {
|
checkAuth: (rules = []) => {
|
||||||
var authorised = false;
|
var authorised = false;
|
||||||
if (rules.length > 0) {
|
if (config.time_rules_enabled) {
|
||||||
var now = new Date ();
|
if (rules.length > 0) {
|
||||||
var minuteOfDay = (now.getHours () * 60) + now.getMinutes (); // 0 - 1439
|
var now = new Date ();
|
||||||
var day = now.getDay (); // 1 - 7
|
var minuteOfDay = (now.getHours () * 60) + now.getMinutes (); // 0 - 1439
|
||||||
var date = now.getDate (); // 1 - 31
|
var day = now.getDay (); // 1 - 7
|
||||||
var month = now.getMonth () + 1; // 1 - 12
|
var date = now.getDate (); // 1 - 31
|
||||||
var actions = [];
|
var month = now.getMonth () + 1; // 1 - 12
|
||||||
rules.forEach ((rule) => {
|
var actions = [];
|
||||||
var valid = false;
|
rules.forEach ((rule) => {
|
||||||
// Process rule
|
var valid = false;
|
||||||
var r = {
|
// Process rule
|
||||||
startMinute: parseInt (rule.startTime.split (":")[0] * 60) + parseInt (rule.startTime.split (":")[1]),
|
var r = {
|
||||||
endMinute: parseInt (rule.endTime.split (":")[0] * 60) + parseInt (rule.endTime.split (":")[1]),
|
startMinute: parseInt (rule.startTime.split (":")[0] * 60) + parseInt (rule.startTime.split (":")[1]),
|
||||||
days: resolveRange (rule.weekdays),
|
endMinute: parseInt (rule.endTime.split (":")[0] * 60) + parseInt (rule.endTime.split (":")[1]),
|
||||||
dates: resolveRange (rule.dates),
|
days: resolveRange (rule.weekdays),
|
||||||
months: resolveRange (rule.months)
|
dates: resolveRange (rule.dates),
|
||||||
|
months: resolveRange (rule.months)
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
minuteOfDay >= r.startMinute &&
|
||||||
|
minuteOfDay <= r.endMinute &&
|
||||||
|
r.days.indexOf (day) !== -1 &&
|
||||||
|
r.dates.indexOf (date) !== -1 &&
|
||||||
|
r.months.indexOf (month) !== -1
|
||||||
|
) {
|
||||||
|
actions.push (rule.action.toLowerCase ());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (actions.indexOf ("allow") !== -1) {
|
||||||
|
authorised = true;
|
||||||
}
|
}
|
||||||
if (
|
if (actions.indexOf ("deny") !== -1) {
|
||||||
minuteOfDay >= r.startMinute &&
|
authorised = false;
|
||||||
minuteOfDay <= r.endMinute &&
|
|
||||||
r.days.indexOf (day) !== -1 &&
|
|
||||||
r.dates.indexOf (date) !== -1 &&
|
|
||||||
r.months.indexOf (month) !== -1
|
|
||||||
) {
|
|
||||||
actions.push (rule.action.toLowerCase ());
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
if (actions.indexOf ("allow")) {
|
|
||||||
authorised = true;
|
|
||||||
}
|
|
||||||
if (actions.indexOf ("deny")) {
|
|
||||||
authorised = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
authorised = true;
|
||||||
|
}
|
||||||
return authorised;
|
return authorised;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user