Home
Help
Search
Login
Register
OPNsense Forum
»
Archive
»
23.7 Legacy Series
»
API Firewall set to enabled or disabled
« previous
next »
Print
Pages: [
1
]
Author
Topic: API Firewall set to enabled or disabled (Read 1770 times)
RobLatour
Full Member
Posts: 132
Karma: 7
API Firewall set to enabled or disabled
«
on:
September 11, 2023, 05:03:09 pm »
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)?
Logged
franco
Administrator
Hero Member
Posts: 17661
Karma: 1611
Re: API Firewall set to enabled or disabled
«
Reply #1 on:
September 12, 2023, 07:28:01 am »
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
Logged
RobLatour
Full Member
Posts: 132
Karma: 7
Re: API Firewall set to enabled or disabled
«
Reply #2 on:
September 12, 2023, 03:14:43 pm »
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
«
Last Edit: September 12, 2023, 04:54:25 pm by RobLatour
»
Logged
Fright
Hero Member
Posts: 1777
Karma: 164
Re: API Firewall set to enabled or disabled
«
Reply #3 on:
September 12, 2023, 05:35:14 pm »
try
https://n.n.n.n/api/firewall/filter/toggleRule/uuid/1
Logged
RobLatour
Full Member
Posts: 132
Karma: 7
Re: API Firewall set to enabled or disabled
«
Reply #4 on:
September 12, 2023, 05:56:11 pm »
Perfect.
Thank you very much for your help!
Logged
franco
Administrator
Hero Member
Posts: 17661
Karma: 1611
Re: API Firewall set to enabled or disabled
«
Reply #5 on:
September 12, 2023, 09:08:22 pm »
Does /false or /true not work? Maybe it's casting to string. In JSON body it's probably type-safe.
Cheers,
Franco
Logged
Fright
Hero Member
Posts: 1777
Karma: 164
Re: API Firewall set to enabled or disabled
«
Reply #6 on:
September 12, 2023, 10:42:58 pm »
@franco
Quote
Does /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
Logged
franco
Administrator
Hero Member
Posts: 17661
Karma: 1611
Re: API Firewall set to enabled or disabled
«
Reply #7 on:
September 13, 2023, 11:06:40 am »
It's a design choice it seems in the URL parsing, but it's not perfect
Cheers,
Franco
Logged
Print
Pages: [
1
]
« previous
next »
OPNsense Forum
»
Archive
»
23.7 Legacy Series
»
API Firewall set to enabled or disabled