Convert PFsense DHCP static addresses via regex

Started by franciz, March 20, 2023, 05:03:43 PM

Previous topic - Next topic
1) Save PFsense config file
2) Go to https://regex101.com/
3) Select flavor "PCRE2" and function "List"
4) In "Test string" paste the contents of the backup file.
5) In "Regular Expression" paste the following:
<staticmap>\n\t+<mac>(.+)<\/mac>\n\t+(?:.*)\n\t+<ipaddr>(.+)<\/ipaddr>\n\t+<hostname>(.+)<\/hostname>\n\t+<descr><!\[CDATA\[(.+)\]\]><\/descr>
6) In "Function" paste the following:
\t\t\t<staticmap>\n\t\t\t\t<mac>$1</mac>\n\t\t\t\t<ipaddr>$2</ipaddr>\n\t\t\t\t<hostname>$3</hostname>\n\t\t\t\t<descr>$4</descr>\n\t\t\t</staticmap>\n
7) You will get the converted file below. You have to add the xml header and footer to this results:
<?xml version="1.0"?>
<opnsense>
<dhcpd>
    <lan>
********** The converted result*************
    </lan>
  </dhcpd>
</opnsense>


I hope this helps someone. I tried with uprt and got all the results mangled...

I'm currently trying OPNsense in a lab setting and considering making the change myself.  This will come in handy.  Thanks for posting!
Just a hobbyist trying to figure all this out.

I have just used your process and for me, it worked!  Thank you!