Script Request: WPS button temp toggle blocked service

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Author Message
fmto
DD-WRT Novice


Joined: 30 Dec 2023
Posts: 2

PostPosted: Sat Dec 30, 2023 14:54    Post subject: Script Request: WPS button temp toggle blocked service Reply with quote
Hello. I'm running an old WRT54G router as a client. It's running firmware v24-sp2 (10/10/09 micro).

I am looking to set this thing up with a script where upon pressing the SES/WPS button it blocks traffic on a specific port for 10 seconds and then enables it again.

I defined a custom service under Access Restrictions -- WAN Accesss -- Blocked Services. If possible, I'd like the script to toggle that blocked service on for 10 seconds then disable it once done upon button press. Or if there's a simpler way please let me know.

I am new to scripting on this so any help would be greatly appeciated as I have had no luck searching, other than to find a script that blinks the led 10 times found here: https://wiki.dd-wrt.com/wiki/index.php/SES_Button

Thanks in advance for any help.
Sponsor
mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1858
Location: Hung Hom, Hong Kong

PostPosted: Sun Dec 31, 2023 10:53    Post subject: Reply with quote
A simple method to debug your script is to use the command logger:
Code:
#!/bin/sh
#
# This is a script to be executed by SES/WPS button ($$ is process ID)
# You can save it as testing123.sh, and have it hooked to the SES/WPS button.
#
logger -s -t testing123 "[$$]Entering SES/WPS script"
sleep 10
logger -s -t testing123 "[$$]Exiting SES/WPS script"

You can then read the system log and find messages created above:
Code:
grep testing123 /var/log/messages

_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
fmto
DD-WRT Novice


Joined: 30 Dec 2023
Posts: 2

PostPosted: Mon Jan 01, 2024 10:23    Post subject: Reply with quote
After much struggle with trying to write something using iptables I abandoned that and found the following links and was able to get something together that works. Here's the script I came up with with references to topics that helped:

Code:


#Firmware: DD-WRT v24-sp2 (10/10/09) micro
#https://wiki.dd-wrt.com/wiki/index.php/Access_Restrictions
#https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=486225
#https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=307182

mkdir /tmp/etc/config
echo '#!/bin/sh
/usr/sbin/nvram set filter_rule1="\$STAT:0\$NAME:ruleName\$DENY:0\$\$" && /sbin/stopservice firewall && /sbin/startservice firewall
sleep 10000
/usr/sbin/nvram set filter_rule1="\$STAT:1\$NAME:ruleName\$DENY:0\$\$" && /sbin/stopservice firewall && /sbin/startservice firewall
sleep 1000
' > /tmp/etc/config/buttonScriptName.sesbutton
chmod +x /tmp/etc/config/buttonScriptName.sesbutton



Works as expected for me. After setting up the access restriction rule, saving this script in "startup" under Administration -- Commands, and pressing the SES/WPS button enables the access restriction rule (in this case, rule number 1 with the rule name "ruleName") for 10 seconds and then disables it again.
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum