Page 1 of 1

Example of enable/disable a rule based on time

Posted: Wed Oct 15, 2014 10:34 pm
by infused
Hi Guys.

Could someone give me an idea on where to start with a shell of a script?

I need one that disables a rule at 10:30am, enables it again 11am, disables again at 12:30pm, enables again and 1pm

never done a script and kind of been forced in to this. I've done a lot of coding/powershell, so lay it on me.

Re: Example of enable/disable a rule based on time

Posted: Wed Oct 15, 2014 11:07 pm
by skot
You could use a script... or an easier way would be to use 2 duplicate firewall rules that are only activated during the said times. Something like this:

ros code

/ip firewall filter
add action=accept chain=forward time=11h-12h30m,sun,mon,tue,wed,thu,fri,sat
add action=accept chain=forward time=13h-22h30m,sun,mon,tue,wed,thu,fri,sa

Re: Example of enable/disable a rule based on time

Posted: Thu Oct 16, 2014 1:00 am
by infused
I would, but you actually need 3...

then if I want to block youtube, it becomes 6...

Script seems better to go to future proof it.

Re: Example of enable/disable a rule based on time

Posted: Thu Oct 16, 2014 2:36 am
by skot
You could create a schedule that runs a script like this every 30 minutes. It checks the time and enables / disables the firewall rule with comment "My Comment" if the times match.

ros code

:local time [:pick [/system clock get time] 0 5]

:if ($time = "10:30") do={
  /ip firewall filter disable [find comment="My Comment"]
}
:if ($time = "11:00") do={
  /ip firewall filter enable [find comment="My Comment"]
}
:if ($time = "12:30") do={
  /ip firewall filter disable [find comment="My Comment"]
}
:if ($time = "13:00") do={
  /ip firewall filter enable [find comment="My Comment"]
}

Re: Example of enable/disable a rule based on time

Posted: Fri Nov 20, 2015 9:52 am
by makstex
Please tell me how to make one with the rule to work 23:00:00 - 7:00:00?
Or always have to make 2 rules, one with the 23:00:00 - 23:59:59, and the second with 00:00:00 - 7:00:00?