Time of day connection filter
This simple filter allows you to accept or reject connections based on the weekday and/or the time. This is mostly meant as a simple demonstration, though it might be useful to some people.
Parameter: Days
Optional. This is a text field that can contain a comma-separated list of weekdays that are acceptable, for instance:
monday, tuesday, thursday, friday
The names are case-insensitive. If this parameter is specified, then connections will be accepted only if the current time (on the Gallium Data server) shows that the current day is in the list.
Parameter: Hours
Optional. This is a text field that can specify hours or ranges of hours, for instance:
8, 10, 12-15, 18-23
Connections will be rejected if they do not fall on an hour specified by this parameter.
Parameter: Execute code
If this checkbox is selected, then in addition to its normal operation, this filter will also execute its JavaScript code. This allows you to take complete control and override the result in any way you see fit.
Context
If the JavaScript code is executed, it will have access to the following variables:
log: a Logger object
context: an object containing the following properties:
socket: a Java Socket object, which you can use to get the client's address
result: the current result as determined by the filter. This is a result object, it has two main properties: success (boolean) and errorMessage (string).
Code example
This is probably not very realistic, but it's simple:
// Simple demo: reject connections if the time is not right, or if we don't like the client address
log.info("Executing code for Business Hours Filter");
const now = new Date();
const minutes = now.getMinutes();
if (minutes > 5) {
context.result.success = false;
context.result.errorMessage = "Connections not allowed after 5 past the hour";
return;
}
let ip = context.socket.getRemoteSocketAddress().getAddress().getHostAddress();
// Keep in mind that this could be an IP4 or an IP6 address
if ( ! ip.startsWith("127.")) {
context.result.success = false;
context.result.errorMessage = "We don't like your IP address";
}