Following the documentation here:
https://docs.opnsense.org/development/api/plugins/firewall.html
via the api I can retrieve the enabled status of a firewall rule, and I can toggle it from enabled to disabled (or the other way), and I can apply the change.
However, I would rather simply either a) enable it, or in other cases b) disabled it, without needing to first retrieve the current status. Afterwards I can apply the change.
The documentation above, does reference a setRule feature of the API, but I can't find it otherwise documented, and the parms for it don't seem to include an way to indicate if the rule should be enabled or disabled.
Is there a way to enable or disable a rule with a direct api post (i.e. not toggle it, rather just either enable or disable it directly)?
toggleRule has a second argument, which defaults to "null", but you can also use "true" or "false" to set it to the respective state directlyl.
Cheers,
Franco
Thank you Franco, that is great news.
I had actually tried a combination of things before posting this but nothing seemed to work.
I am using an encoded url for the post, and while
https://n.n.n.n/api/firewall/filter/toggleRule/uuid
works great,
I couldn't get any of the following to work:
https://n.n.n.n/api/firewall/filter/toggleRule/uuid,enabled="true"
https://n.n.n.n/api/firewall/filter/toggleRule/uuid,enabled="True"
https://n.n.n.n/api/firewall/filter/toggleRule/uuid,enabled=true
https://n.n.n.n/api/firewall/filter/toggleRule/uuid,$enabled="true"
https://n.n.n.n/api/firewall/filter/toggleRule/uuid,$enabled=true
https://n.n.n.n/api/firewall/filter/toggleRule/uuid,"True"
https://n.n.n.n/api/firewall/filter/toggleRule/uuid,"true"
https://n.n.n.n/api/firewall/filter/toggleRule/uuid,true
https://n.n.n.n/api/firewall/filter/toggleRule/uuid,enabled=1
https://n.n.n.n/api/firewall/filter/toggleRule/uuid,1
Could you please let me know what is the required syntax looks like?
Thanks,
Rob
try
https://n.n.n.n/api/firewall/filter/toggleRule/uuid/1
Perfect.
Thank you very much for your help!
Does /false or /true not work? Maybe it's casting to string. In JSON body it's probably type-safe.
Cheers,
Franco
@franco
QuoteDoes /false or /true not work?
not for me ({"result":"failed","changed":false})
toggleBase() expects string "1" and "0" only. and i dont see any casting in body parsing?
I really thought its by design
It's a design choice it seems in the URL parsing, but it's not perfect ;)
Cheers,
Franco