ipfire 2 dnsmasq script to generate wildcard subdomains for dhcp-leases

raw

etc-dnsmasq.conf

1
2
conf-dir=/etc/dnsmasq.d/
 
raw

usr-local-bin-dnsmasq-dhcp-wildcards.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/sh
tld=.example
 
mode=$1
ip=$2
name=$3$tld
 
filename="/etc/dnsmasq.d/wildcard-dhcp-$ip.conf"
echo $@ >> /tmp/log
if [ "$mode" == add ]; then
    echo "address=/.$name/$ip" > "$filename"
    /etc/init.d/dnsmasq restart &
elif [ "$mode" == del ]; then
    rm "$filename"
    /etc/init.d/dnsmasq restart &
fi
 
raw

var-ipfire-dhcp-dhcpd.conf.local

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
on commit {
        set noname = concat("dhcp-", binary-to-ascii(10, 8, "-", leased-address));
        set ClientIP = binary-to-ascii(10, 8, ".", leased-address);
        set ClientMac = binary-to-ascii(16, 8, ":", substring(hardware, 1, 6));
        set ClientName = pick-first-value(option host-name, host-decl-name, config-option host-name, noname);
        # log(concat("Commit: IP: ", ClientIP, " Mac: ", ClientMac, " Name: ", ClientName));
        execute("/usr/local/bin/dnsmasq-dhcp-wildcards", "add", ClientIP, ClientName, ClientMac);
}
on release {
        set ClientIP = binary-to-ascii(10, 8, ".", leased-address);
        set ClientMac = binary-to-ascii(16, 8, ":", substring(hardware, 1, 6));
        # log(concat("Release: IP: ", ClientIP, " Mac: ", ClientMac));
        # cannot get a ClientName here, for some reason that always fails
        execute("/usr/local/bin/dnsmasq-dhcp-wildcards", "del", ClientIP, "", ClientMac);
}
on expiry {
        set ClientIP = binary-to-ascii(10, 8, ".", leased-address);
        # cannot get a ClientMac here, apparently this only works when actually receiving a packet
        # log(concat("Expired: IP: ", ClientIP));
        # cannot get a ClientName here, for some reason that always fails
        execute("/usr/local/bin/dnsmasq-dhcp-wildcards", "del", ClientIP, "", "0");
}
 
Christian Weiske Christian Weiske
owner

History