Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use configd.py or the backend registry/database to add elements using a python script and without writing xml #8072

Open
ji-podhead opened this issue Nov 19, 2024 · 1 comment
Labels
support Community support

Comments

@ji-podhead
Copy link

ji-podhead commented Nov 19, 2024

Hi,
so i wanted to recreate the module prototypes using python classes and the provided models in /src/opnsense/mvc/app/models/OPNsense/. so i wrote myself a parser that creates classes from the prototypes.
But then i notices that elements dont get placed in the same field in /conf/config.xml
For example i cant add Firewall lan rules like i add snat rules, but the prototypes are both in the same xml file.
Then i thought: ok never mind, i just can search the parent element, but this wont work either cause the structure of the containers also differs.

Example Filter.xml

this is the model file

<model>
    <mount>//OPNsense/Firewall/Filter</mount>
    <version>1.0.4</version>
    <migration_prefix>MFP</migration_prefix>
    <description>OPNsense firewall filter rules</description>
    <items>
        <rules>
            <rule type=".\FilterRuleField">
 ...
  • theres rules, snatrules and a bunch of others
  • in the config.xml the filter rules are defined as this:
  <filter>
   <rule>
     <type>pass</type>
     <ipprotocol>inet</ipprotocol>
     ...

but snatrules are under:

 <OPNsense>
    <Firewall>
      <Filter version="1.0.4">
        <rules />
        <snatrules /> 

in the config.xml i can only apply snat rules via OPNsense.Firewall.Filter and rules only under filter.rules.
Is there any other way i can find all the attributes for the wrapper-classes i want to create, other than scanning the php-files, or adding every module-elemt at least a single time via the web gui?


I am not really sure i f i should use the php scripts rather than the daemon or something else.
I just dont know if configd is having a in memory representation of the config.xml.

so it wouldbe cool if i could add the objects directly to the registry, rather than dumping xmls. for example like this:

daemon= configd_daemoin
config=daemon.get_config()
config["Fiter"].append(New Filter_Rule())
daemon.apply(config)
daemon.verify()
daemon.save()
@ji-podhead ji-podhead added the support Community support label Nov 19, 2024
@ji-podhead ji-podhead changed the title How to use configd.py or the backend registry/database to add elements using a python script How to use configd.py or the backend registry/database to add elements using a python script and without writing xml Nov 19, 2024
@fichtner
Copy link
Member

Mhh, I don't think we should support writing confg.xml directly from configd -- it has read access for templating, but the rest is better done via PHP as it always has been.

Cheers,
Franco

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Community support
Development

No branches or pull requests

2 participants