Forum Discussion

bsm1970's avatar
bsm1970
Icon for Nimbostratus rankNimbostratus
Sep 09, 2019
Solved

Restrict access to virtual server during specified time

I'm wondering if there is a way in the F5 to restrict access to a virtual server during certain hours. For instance, if I wanted to only allow access during work hours (say, from 7am to 6pm on weekd...
  • Stanislas_Piro2's avatar
    Sep 10, 2019

    try this:

    when RULE_INIT {
        array set static::timerange {
            Sunday {"07:00" "18:00"}
            Monday {"07:00" "18:00"}
            Tuesday {"07:00" "18:00"}
            Wednesday {"07:00" "18:00"}
            Thursday {"07:00" "18:00"}
            Friday {}
            Saturday {}
        }
    }
     
    when HTTP_REQUEST {
        set now [clock seconds]
        set current_day [clock format $now -format {%A}]
        set start [lindex $static::timerange($current_day) 0]
        set end [lindex $static::timerange($current_day) 1]
        if {($start ne "") && ($end ne "") && ($now >= [clock scan $start]) && ($now < [clock scan $end])} {
            set denied 0
        } else {set denied 1}
        unset start end
     
        if { $denied } {
            HTTP::respond 200 content "<html><head><title>Not Authorised! Contact Administrator</title></head><body>Not Authorised! Contact Administrator...</body></html>"
        } else {pool POOL_443}
        unset denied
    }