Hi. I want to run an script each time an Apply is triggered from Luci. Where should I put my script?
singular or global?
@anon50098793 Thanks, sorry I don't understand very well what you're referring with singular or global. I already have the script, and I run it manually from SSH after I click on "Save & Apply" on Luci. What I want is to automate that run, so I don't need to login to SSH and manually run the script, but simply to run it automatically on each Apply.
changing luci is probably not the best way unless there is further interaction with the browser / page / page-s...
if you instantiate a service... with procd config.trigger's for all config's... you'll get luci+cmdline+manual edits...
Seems too complicated for my humble knowledge... I'll try to change my approach, and will do it with a cron job that detects changes in uci each minute.
What script?
The script i quite simple: It checks if all DHCP static hosts have a tag applied, and if not, it's applied, and dnsmasq is reloaded:
#!/bin/ash
i=1
check=1
change=0
while [ $check -eq 1 ]
do
if [ $(uci get dhcp.@host[$i]) ]; then
if [ $(uci get dhcp.@host[$i].tag) ]; then
if [ $(uci get dhcp.@host[$i].tag) != 'unrestricted' ]; then
uci set dhcp.@host[$i].tag='unrestricted'
change=1
fi
else
uci set dhcp.@host[$i].tag='unrestricted'
change=1
fi
i=$(expr $i + 1)
else
check=0
fi
done
if [ $change -eq 1 ]; then
uci commit dhcp
/etc/init.d/dnsmasq reload
fi
Options:
- Include your script in the dnsmasq init/reload.
- Specify the default tag value.
The latter is preferable.
Oh, I didn't know about these scripts. Is this reload function also invoked when an Apply is triggered from Luci?