Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - migrator

#1
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 ...

#!/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
#2
Es funktioniert nun. ich hatte die <staticmaps>-Tags für jeden Host über sehen  :o
Falls jemand auch mittles Skript statische Hosts aus einem isc-dhcp-server auslesen möchte, hier mein Skript dazu ...


#!/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


Den ausgegeben Code habe ich dann in die Backupdatei von OPNsense an den entsprechenden Stellen reinkopiert - es hilft ein paar Einträge von Hand anzulegen um das Muster zu versehen. danach habe ich das Backup wieder importiert und mir eine Menge Klickerei gespart.

Cheers
#3
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

  <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):

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.
#4
Hallo,

ich versuche statische DHCPv4-Einträge zu importieren.
Leider scheint es keine offizielle Lösung zu geben, deswegen habe ich versucht die XML-Datei aus dem Backup um die entsprechenden Einträge zu erweitern und das Backup dann wieder einzulesen.
Ich lese die Einträge für <ipaddr>,  <mac>, <decr> und <hostname> per Script aus einem isc-dhcp-server aus und erzeuge damit den xml-code, den ich dann in die entsprechende Section der Backup-Datei hineinkopiere.
Wenn ich über die OPNsense-Gui Einträge  unter DHCP Static Mappings anlege, sehen diese im Backup identisch und i.A. folgendermaßen aus ...

  <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>

Nach Einlesen des Backup bleiben von Hand eingegebene Einträge bestehen, für die modifizierten hingegen wird eine Zeile angezeigt mit jeweils einer Meldung pro Spalte:

Warning: htmlspecialchars() expects parameter 1 to be string, array given in /usr/local/www/services_dhcp.php on line 1121 / 1124 /1127  /1130.

Den entsprechenden Abschnitt habe ich mir angesehen, sehe aber keine Lösung, übersehe ich etwas?
Ist das Backup evtl. geschützt (bspw. über eine Checksum) und nicht modifizierbar?
Hat jemand schon mal etwas ähnliches probiert oder kennt eine andere Lösung für den DHCP-Import?

Danke fürs lesen und noch mehr für Hilfe