Compare commits

..

10 Commits

4 changed files with 48 additions and 24 deletions

View File

@@ -1,2 +1,2 @@
NETBOX=192.168.1.56
NETBOX=192.168.1.100
TOKEN=fd92ccbd826a3ef585688bb9b56ace7da512e965

29
dhcpd.conf.head Executable file
View File

@@ -0,0 +1,29 @@
max-lease-time 600;
default-lease-time 600;
subnet 10.0.10.0 netmask 255.255.255.0 {
option routers 10.0.10.1;
option domain-name-servers 10.0.10.1;
range 10.0.10.2 10.0.10.254;
}
subnet 10.0.20.0 netmask 255.255.255.0 {
option routers 10.0.20.1;
option domain-name-servers 10.0.20.1;
option domain-name "home.paler.net";
range 10.0.20.100 10.0.20.200;
}
subnet 10.0.30.0 netmask 255.255.255.0 {
option routers 10.0.30.1;
option domain-name-servers 10.0.30.1;
range 10.0.30.100 10.0.30.200;
}
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option domain-name-servers 192.168.1.1;
option domain-name "home.paler.net";
range 192.168.1.100 192.168.1.200;
}

View File

@@ -3,34 +3,29 @@
. ./config.sh
do_curl() {
curl -s -k -H "Authorization: Token ${TOKEN}" -X GET $1
curl -s -k -H "Host: netbox.v.paler.net" -H "Authorization: Token ${TOKEN}" -X GET $1
}
cat<<EOF
# generated by $0 at $(date)
echo "# generated by $0 at $(date)"
echo
cat dhcpd.conf.head
option domain-name "home.paler.net";
max-lease-time 600;
default-lease-time 600;
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option domain-name-servers 192.168.1.1;
range 192.168.1.100 192.168.1.200;
EOF
do_curl "https://${NETBOX}/api/ipam/ip-addresses/" | \
jq -r '.results[] | .assigned_object.device.name + .assigned_object.virtual_machine.name + " " + (.address / "/")[0] + " " + .assigned_object.url' |
do_curl "https://${NETBOX}/api/ipam/ip-addresses/?limit=10000" | \
jq -r ".results[] | .assigned_object.device.name + .assigned_object.virtual_machine.name + \" \" + (.address / \"/\")[0] + \" \" + (.assigned_object.url | sub(\"netbox.v.paler.net\"; \"${NETBOX}\"))" |
while read name ip owner
do
mac=$(do_curl $owner | jq -r '.mac_address')
if [[ $name == comfoconnect ]] then
extra="max-lease-time 864000; default-lease-time 864000;"
else
extra=""
fi
cat<<EOF
host $name {
fixed-address ${ip};
hardware ethernet ${mac};
}
host $name {
fixed-address ${ip};
hardware ethernet ${mac};
${extra}
}
EOF
done
echo "}"

View File

@@ -4,6 +4,6 @@
RPZ_FILE=/var/unbound/db/local.rpz
curl -s -k -H "Authorization: Token ${TOKEN}" -X GET "https://${NETBOX}/api/ipam/ip-addresses/" | \
curl -s -k -H "Host: netbox.v.paler.net" -H "Authorization: Token ${TOKEN}" -X GET "https://${NETBOX}/api/ipam/ip-addresses/?limit=10000" | \
jq -r '.results[] | (.address / "/")[0] as $addr | (.assigned_object.device.name + .assigned_object.virtual_machine.name + ".home.paler.net") as $name | ($addr | split(".") | reverse | join(".") + ".in-addr.arpa") as $rev | $name + " A " + $addr, $rev + " PTR " + $name + "."' | \
tee ${RPZ_FILE}