Community discussions

 
infused
Member
Member
Topic Author
Posts: 305
Joined: Fri Dec 28, 2012 2:33 pm

Example of enable/disable a rule based on time

Wed Oct 15, 2014 10:34 pm

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.
 
User avatar
skot
Long time Member
Long time Member
Posts: 586
Joined: Wed Nov 30, 2011 3:05 am

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

Wed Oct 15, 2014 11:07 pm

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
I don't need any karma... I have Ιησους Χριστος!
 
infused
Member
Member
Topic Author
Posts: 305
Joined: Fri Dec 28, 2012 2:33 pm

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

Thu Oct 16, 2014 1:00 am

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.
 
User avatar
skot
Long time Member
Long time Member
Posts: 586
Joined: Wed Nov 30, 2011 3:05 am

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

Thu Oct 16, 2014 2:36 am

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"]
}
I don't need any karma... I have Ιησους Χριστος!
 
makstex
newbie
Posts: 46
Joined: Fri Mar 27, 2009 6:31 am

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

Fri Nov 20, 2015 9:52 am

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?

Who is online

Users browsing this forum: No registered users and 4 guests