]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
dhcp.cgi: Call the unbound-dhcp-leases-client for all events
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 May 2024 15:07:05 +0000 (16:07 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 10 May 2024 15:07:05 +0000 (16:07 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
html/cgi-bin/dhcp.cgi

index be00f199a8b8215632307789d37e212b2dc2f6d8..83cd809656ad0076fd5d4646b8ce64d09aff3a55 100644 (file)
@@ -1374,6 +1374,49 @@ sub buildconf {
        }
     }
 
+       # Add event handlers
+       print FILE <<EOF;
+on commit {
+       set ClientAddress = concat(
+               "ADDRESS=",
+               binary-to-ascii(10, 8, ".", leased-address)
+       );
+       set ClientName = concat(
+               "NAME=",
+               pick-first-value(option host-name, config-option-host-name, client-name, "")
+       );
+
+       if (ClientName != "") {
+               execute("/usr/sbin/unbound-dhcp-leases-client", "commit", ClientAddress, ClientName);
+       }
+}
+
+on release {
+       set ClientAddress = concat(
+               "ADDRESS=",
+               binary-to-ascii(10, 8, ".", leased-address)
+       );
+       set ClientName = concat(
+               "NAME=",
+               pick-first-value(option host-name, config-option-host-name, client-name, "")
+       );
+
+       if (ClientName != "") {
+               execute("/usr/sbin/unbound-dhcp-leases-client", "release", ClientAddress, ClientName);
+       }
+}
+
+on expiry {
+       set ClientAddress = concat(
+               "ADDRESS=",
+               binary-to-ascii(10, 8, ".", leased-address)
+       );
+
+       execute("/usr/sbin/unbound-dhcp-leases-client", "expiry", ClientAddress);
+}
+
+EOF
+
     #write fixed leases if any. Does not handle duplicates to write them elsewhere than the global scope.
     my $key = 0;
     foreach my $line (@current2) {