OPNsense Forum

English Forums => General Discussion => Topic started by: adminexploit on July 22, 2025, 06:55:39 PM

Title: adding rules by API: V 25.1.12- rule invisible on GUI
Post by: adminexploit on July 22, 2025, 06:55:39 PM
Hi:
I'm fighting for hours to add a firewall rule on, lets say, openvpn interface.

def add_firewall_rules(cn):
    payload = {
          "rule":{
              "interface": "openvpn",
              "type": "pass",
              "direction": "in",
  "quick": "1",
              "ipprotocol": "inet",
              "protocol": "TCP/UDP",
              "source": {
                  "address": cn + "_net"
                },
              "enabled": "1",
              "destination": {
                  "address": cn + "_openvpn_host",
                  "port": cn + '_port',
                },

             "description": cn + 'fw1'
               }
            }
result=add_firewall_rules(cn)
    print(result)

this's a very basic example. The API gives me an valid answers such like:

'result': 'saved', 'uuid': 'f2d28fb8-84a8-4f9c-a049-6f0ee2755e9c'}that's fine. But, the added rule is not visible on GUI interface. I'm looking for it for hours but it's invisible.
I'm able to find it on confi.xml file but on another paragraph.

for example:
here's visible firewall rule on conf.xml:
under:  opensense->flter->

But the mine are under:  opensense -> OPNsense -> Firewall -> <Filter version="1.0.4"> -> rules

So... humm.... I tried to get my rule with;

https://mystrangeopnsense.doctor.strange.somewhere/api/firewall/filter/get_rule/f2d28fb8-84a8-4f9c-a049-6f0ee2755e9c
and I get it.
So my question is: why is it invisible on GUI ??
Title: Re: adding rules by API: V 25.1.12- rule invisible on GUI
Post by: Monviech (Cedrik) on July 22, 2025, 07:08:32 PM
Did you look at Firewall - Automation - Filter and select the OpenVPN Group?
Title: Re: adding rules by API: V 25.1.12- rule invisible on GUI
Post by: adminexploit on July 22, 2025, 11:27:20 PM
Quote from: Monviech (Cedrik) on July 22, 2025, 07:08:32 PMDid you look at Firewall - Automation - Filter and select the OpenVPN Group?
Yes but I didn't see there are different groups. and yes, all my customs rules are here.
great thanks for your helps. But how automation rules interact with openvpn under "rules" group ?? are they parsed before ?
Title: Re: adding rules by API: V 25.1.12- rule invisible on GUI
Post by: Monviech (Cedrik) on July 23, 2025, 06:17:31 AM
https://docs.opnsense.org/manual/firewall_automation.html#processing-order
Title: Re: adding rules by API: V 25.1.12- rule invisible on GUI
Post by: adminexploit on July 23, 2025, 12:21:02 PM
Quote from: Monviech (Cedrik) on July 23, 2025, 06:17:31 AMhttps://docs.opnsense.org/manual/firewall_automation.html#processing-order
again, thx a lot for your helps for saving my time. this topic is SOVLED