Restricting Access Based on the Time of Day

This example only allows access to a particular service during designated office hours (between 9am and 6pm, Monday to Friday). It discards all connections that occur outside these times.

$dayofweek = sys.time.weekDay();

$hourofday = sys.time.hour();

 

# $dayofweek: Sunday is 1, Saturday is 7

# $hourofday: office hours are between 9am and 5:59pm

if( $dayofweek == 1 ||

$dayofweek == 7 ||

$hourofday < 9 ||

$hourofday >= 18 ) {

log.warn( "Warning: access out of hours!" );

connection.discard();

}

In practice, it may be more appropriate to direct restricted traffic to a separate error pool of servers rather than just dropping the connection without warning. The servers in the error pool can be configured to return an appropriate error message before closing the connection. The procedure for doing this depends on the protocol being balanced.