How to enable firewall rule by name using UCI

I have the following firewall rule:

firewall.@rule[13]=rule
firewall.@rule[13].name='Parental filter'
firewall.@rule[13].src='lan'
firewall.@rule[13].src_mac='C8:85:50:2B:EE:6C' '7C:61:66:A0:A9:F1'
firewall.@rule[13].dest='wan'
firewall.@rule[13].target='REJECT'
firewall.@rule[13].enabled='0'

Is there a way to toggle it from enabled=0 to enabled=1 using it's name (Parental Filter) instead of the @rule number?

No, but you can retrieve the rule number using its name and then use it to activate the rule.

rulenum=$(uci show firewall | grep 'Parental filter' | sed 's/.*\@//;s/\.name.*//'); uci set firewall.@"$rulenum".enabled="1"
4 Likes

Sweet, that works like a charm. Using the iOS shortcut for SSH scripts, I can enable and disable the parental filter as needed.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.