OPNsense
  • Home
  • Help
  • Search
  • Login
  • Register

  • OPNsense Forum »
  • English Forums »
  • General Discussion (Moderator: fabian) »
  • [SOLVED] dhcp static mappings import using modified backup-file
« previous next »
  • Print
Pages: [1]

Author Topic: [SOLVED] dhcp static mappings import using modified backup-file  (Read 336 times)

migrator

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
[SOLVED] dhcp static mappings import using modified backup-file
« on: August 23, 2018, 09:34:58 am »
Hello,

i'm trying to import static DHCP entries into OPNsense since i have i.e. lots of printers in various subnets.
Since there seems to be no official way, nore did i found anything except for pfsense, itried to modify the related sections of a downloaded backup (.xml) and reimport that again.
I added entries  for <ipaddr>,  <mac>, <decr> and <hostname> in the xml-code, so it loooks identically to entries done by the GUI
Code: [Select]
  <dhcpd>
    <opt3>
      <enable>1</enable>
      <numberoptions/>
      <range>
        <from>192.168.110.50</from>
        <to>192.168.110.55</to>
      </range>
      <staticmap>
        <mac>00:25:90:cd:0d:98</mac>
        <ipaddr>192.168.110.100</ipaddr>
        <hostname>110-100</hostname>
        <descr>Backup</descr>
      </staticmap>
    </opt3>
    <opt7>
      <enable>1</enable>
      <numberoptions/>
      <range>
        <from>192.168.245.46</from>
        <to>192.168.245.56</to>
      </range>
      <staticmap>
        <mac>c8:5b:76:4f:ae:a0</mac>
        <ipaddr>192.168.245.34</ipaddr>
        <hostname>245-34</hostname>
        <descr> laptop 28.11.2016</descr>
        <mac>c8:5b:76:4f:a4:f3</mac>
        <ipaddr>192.168.245.35</ipaddr>
        <hostname>245-35</hostname>
        <descr> laptop 28.11.2016</descr>
        <mac>50:7B:9D:E4:7B:F0</mac>
        <ipaddr>192.168.245.36</ipaddr>
        <hostname>245-36</hostname>
        <descr> laptop 20.12.2016</descr>
      </staticmap>
    </opt7>
When importing the XML-file i receive the following error in one line for all the added entires (existing mappings, done via the GUI remain and stay the same):
Code: [Select]
Warning: htmlspecialchars() expects parameter 1 to be string, array given in /usr/local/www/services_dhcp.php on line 1121 / 1124 /1127  /1130.
Reviewing te code of services_dhcp.php doesn't help, i don't find an error on my site - did i miss anything here?
Is the back.xml-file secured via checksum or can't be modified at all?
Did anyone tried to import static DHCP mappings or has a better guess how to do this?

Thank you for reading and any ideas.
« Last Edit: August 28, 2018, 08:18:36 am by migrator »
Logged

migrator

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
Re: dhcp static mappings import using modified backup-file
« Reply #1 on: August 28, 2018, 08:18:16 am »
It works now. I missed the <staticmaps>-tags for each host :o
If anyone needs to read out host entries from an isc-dhcp-server, too, here is my script ...

Code: [Select]
#!/bin/bash

# read active ip-addr from isc-dhcp-server and write xml-structure for opnsense
# etries in dhcpd.conf looks like:
# host 110-100 { hardware ethernet 00:25:90:cd:0d:98; fixed-address 192.168.110.100; } # my comment

dhcpin=/etc/dhcp/dhcpd.conf
dhcpout=$(hostname)-dhcp-4-opnsense.xml

grep '^host' $dhcpin | while read line
do
echo "      <staticmap>" >> $dhcpout
mac=$(echo $line | cut -d '{' -f 2 | cut -d ' ' -f 4 | cut -d';' -f 1)
echo "        <mac>$mac</mac>" >> $dhcpout
ip=$(echo $line | cut -d ';' -f 2 | cut -d ' ' -f 3)
echo "        <ipaddr>$ip</ipaddr>" >> $dhcpout
hn=$(echo $line | cut -d ' ' -f 2)
echo "        <hostname>$hn</hostname>" >> $dhcpout
beschr=$(echo $line | cut -d '#' -f 2)
echo "        <descr>$beschr</descr>" >> $dhcpout
echo "      </staticmap>" >> $dhcpout
done

I copied the scripts output into the special sections of the OPNsense-backup-file an reimported that. To be sure about the needed structure it is useful to create some entries before. At least the script saved me  a lot of time ...

Cheers
« Last Edit: August 28, 2018, 08:37:37 am by migrator »
Logged

Snowmanut

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
    • View Profile
Re: [SOLVED] dhcp static mappings import using modified backup-file
« Reply #2 on: February 12, 2019, 12:39:57 am »
Trying to figure out how to use this to get my PFsense dhcp mappings into Opnsense. Newb to scripts of any sort. Tried in windows but doesn't like this. Any help for a newb on how to use this? I got my Pfsense dhcpd.conf file and tried running it a as scrip i windows but doesn't like grep.

Another way to import dhcp mappings as I have alot.
Logged

  • Print
Pages: [1]
« previous next »
  • OPNsense Forum »
  • English Forums »
  • General Discussion (Moderator: fabian) »
  • [SOLVED] dhcp static mappings import using modified backup-file
 

OPNsense is an OSS project © Deciso B.V. 2015 - 2019 All rights reserved
  • SMF 2.0.15 | SMF © 2017, Simple Machines
    Privacy Policy
    | XHTML | RSS | WAP2