What's new

URL addresses management

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Blackstar

Occasional Visitor
Hello everyone, I need advice on automating URL address management in the Firewall's URL Filter settings. I'm tired of manually logging in, finding the Firewall tab, and adding or removing URL addresses via the router's GUI every day. I have an ASUS router RT-AX86U flashed with Merlin v386.5 and SSH access. My son is addicted to playing on roblox.com and watching youtube.com. I want to limit access to these sites on weekdays, starting at 9 pm, and block them after midnight, while keeping other URLs that existed in the list permanently blocked in the URL Filter. Any guidance would be appreciated.
 
I don't think the URL Filter is the right tool for that job. Maybe have a look at Parental Controls - Time Scheduling, although that blocks all internet access. Otherwise Parental Controls - Web & Apps Filters might work for you.
 
I don't think the URL Filter is the right tool for that job. Maybe have a look at Parental Controls - Time Scheduling, although that blocks all internet access. Otherwise Parental Controls - Web & Apps Filters might work for you.
I've dabbled with that Parental Controls settings. It is too broad just to block a few websites that ended up blocking other unnecessary sites so I abandoned it.
 
As an alternative to manually changing the URL filter in the GUI, if you only wanted to switch between two predefined configurations; you could save the relevant nvram variable for each configuration and then use a custom script to schedule switching between those at predefined times. A very clunky approach, and it would mean that you can't easily change it through the GUI, but it could work.
 
As an alternative to manually changing the URL filter in the GUI, if you only wanted to switch between two predefined configurations; you could save the relevant nvram variable for each configuration and then use a custom script to schedule switching between those at predefined times. A very clunky approach, and it would mean that you can't easily change it through the GUI, but it could work.
I would like to try it. I will need a guidance on this whole process...as I have never done any scripts or custom scripts nor where to begin making one.
 
If you could provide screenshots of the two URL Filter configurations you want (A vs. B) we can start there.
 
Before and After.

1709410872952.png

1709410931236.png
 
Can you clarify the schedule. You want to allow access to YouTube and Roblox only between 9pm and midnight, Monday to Friday. What about weekends?

You do realise that will block access for everybody on your network, not just your son?
 
Can you clarify the schedule. You want to allow access to YouTube and Roblox only between 9pm and midnight, Monday to Friday. What about weekends?

You do realise that will block access for everybody on your network, not just your son?
That is correct. Schedule is to allow on weekdays at 9pm to midnight. None on weekends.
 
Hello everyone, I need advice on automating URL address management in the Firewall's URL Filter settings. I'm tired of manually logging in, finding the Firewall tab, and adding or removing URL addresses via the router's GUI every day. I have an ASUS router RT-AX86U flashed with Merlin v386.5 and SSH access. My son is addicted to playing on roblox.com and watching youtube.com. I want to limit access to these sites on weekdays, starting at 9 pm, and block them after midnight, while keeping other URLs that existed in the list permanently blocked in the URL Filter. Any guidance would be appreciated.
What do you mean by limiting at 9pm but blocking at midnight?
 
That is correct. Schedule is to allow on weekdays at 9pm to midnight. None on weekends.
As a father of 5, if you have a problem with your son naturally obeying your requests, then you shouldn't be allowing him to stay up until midnight. He should be going to bed at 9:00. If I had the same problem it sounds like you have, the entire internet would be blocked starting at a 9:00 bedtime.
 
@Blackstar OK I've got two scripts for you. As your filter lists are quite small there's no need to create some complicated all-singing-all-dancing script.

You'll need to SSH into the router and create the scripts using an editor like nano. I don't know what your skill level is or what PC operating system you're using.

So SSH into the router, change to the /jffs/scripts directory and create the first file called url_filter.sh.
Code:
cd /jffs/scripts
nano url_filter.sh
The contents of this file should be exactly as follows:
Code:
#!/bin/sh

rulelistA="<1>ALL>peacocktv.com<1>ALL>twitch.tv<1>ALL>myflixerz.to<1>ALL>tiktok.com<1>ALL>itunes.apple.com<1>ALL>spotify.com"
rulelistB="<1>ALL>peacocktv.com<1>ALL>twitch.tv<1>ALL>myflixerz.to<1>ALL>tiktok.com<1>ALL>itunes.apple.com<1>ALL>spotify.com<1>ALL>youtube.com<1>ALL>roblox.com"

case "$1" in
    A)
        nvram set url_rulelist="$rulelistA" ;;
    B)
        nvram set url_rulelist="$rulelistB" ;;
esac

nvram commit
service restart_firewall

Save this file and then create another file (again using nano) called services-start. This file should look like this:
Code:
#!/bin/sh

cru a FilterA "00 21 * * 1-5 /jffs/scripts/url_filter.sh A"
cru a FilterB "00 00 * * 2-6 /jffs/scripts/url_filter.sh B"

# allow time for ntp to sync then set initial filter rules
sleep 60
hour="$(date +'%H')"
day="$(date +'%w')"

if [ $hour -ge 21 ] && [ $day -ge 1 ] && [ $day -le 5 ] ; then
    /jffs/scripts/url_filter.sh A
else
    /jffs/scripts/url_filter.sh B
fi

After saving that file you need to make them both executable with this command:
Code:
chmod 755 url_filter.sh
chmod 755 services-start

Now log into the router's web interface and enable JFFS custom scripts in Administration - System. Reboot the router to activate the scheduling for the script.

*** As I said previously this is a very clunky approach because everything is hard-coded in the scripts. If you need something more versatile then there's probably a better solution.
 
Last edited:
Thank you very much. I will plug those scripts in and give it a test run. I am running on Windows 10 and using Putty for SSH. I am fine with clunky approach as long as it can do some automation and do some actual URL addresses management without any of my daily manual editing the URL list...this is just what I need.
 
@Blackstar

Please see the updated services-start script in post #13. I got the logic the opposite way around. My brain had trouble with "allowing access using a deny list". :oops:
 
Good catch @ColinTaylor. Supposedly, in the future, if I want to loosen the weekend restrictions to align with the Monday to Friday schedule (from 9 pm to midnight), what would the services-start file look like for this situation?
 
Wouldn't adguard be better for this purpose?

In adguard under Filters -> blocked services, you can block services and add a schedule at the bottom of that page.
 
Last edited:
Good catch @ColinTaylor. Supposedly, in the future, if I want to loosen the weekend restrictions to align with the Monday to Friday schedule (from 9 pm to midnight), what would the services-start file look like for this situation?
You would need to replace the day range in each of the cru commands with * (meaning all days) like this:
Code:
cru a FilterA "00 21 * * * /jffs/scripts/url_filter.sh A"
cru a FilterB "00 00 * * * /jffs/scripts/url_filter.sh B"
and also remove the test for the day in the if statement as follows:
Code:
if [ $hour -ge 21 ] ; then
 
Thanks again.

So, I had the time to try out the scripts today (it's currently 9:35 am here). I loosened the restrictions in your Sunday & Saturday code for a test run. I changed it to 10 am for FilterA and adjusted the test for the day condition to 10. After saving the changes, I rebooted the router. However, I noticed in the URL Filter tab GUI that it removed youtube.com and roblox.com—both URLs were already in the list prior to rebooting. The script shouldn't have kicked in to remove those two URLs as 10 am has not arrived yet. Any ideas on what could have caused that?
1709487198226.png
1709487235574.png

The end of rulelistA and rulelistB strings are intact but not shown in Putty's onscreen.
 
Ah, yes. I think you've found a design bug. :oops:

The services-start runs early in the boot process before the router's clock has been set correctly. So when it runs it thinks the time is ~06:05 GMT adjusted for your timezone.

Try running the script manually and see it it updates the rules correctly. Also, check the crontab:
Code:
/jffs/scripts/services-start
cru l
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top