How to apply manual changes from config files

Started by aney1, January 03, 2025, 02:49:38 PM

Previous topic - Next topic
Hi,

I would like to write a script that adds peers to the wireguard config.
When a peer is added via the webui this file is populated: /usr/local/etc/wireguard/wg0.conf.
So I added a peer there, but not matter what I do, the peer is never shown in the webgui and gets removed after a reboot.

Do I have to add it via /conf/config.xml or is there a way to apply from wg0.conf?

This is what I tried:
- created a peer from the gui to get a config that should definitely work.
- copied it from the config file; deleted it again from the gui; added it back to the config file
- configctl wireguard configure /usr/local/etc/wireguard/wg0.conf
- /usr/local/sbin/configctl wireguard restart
- /usr/local/sbin/configctl webgui restart

configctl wireguard showconf does show a new peer after that, but not the webgui, and after a reboot the config is overwritten again.

You can't undermine OPNsense like that, as you've discovered - the UI manages config.xml (which is not meant to be meddled with really), and other configs are generated from that. You can't (AFAIK anyway) backfeed it in the other direction.

If you want to automate things, look at the API. I haven't used it myself (yet), but it looks like WG is covered...

https://docs.opnsense.org/development/api.html
https://docs.opnsense.org/development/api/plugins/wireguard.html

Ok, I'll check how to do it via the API.

Thanks for the reply.