diff -Nur e-smith-tinydns-2.4.0.old/createlinks e-smith-tinydns-2.4.0/createlinks --- e-smith-tinydns-2.4.0.old/createlinks 2014-06-17 23:46:27.046462016 +0200 +++ e-smith-tinydns-2.4.0/createlinks 2014-06-17 23:47:00.027649759 +0200 @@ -26,3 +26,27 @@ service_link_enhanced("tinydns", "K65", "6"); service_link_enhanced("tinydns", "K65", "0"); service_link_enhanced("tinydns", "K65", "1"); + +#link to services2adjust and templates2expand for dhcp-dns event + for my $event (qw( dhcp-dns )) + { + # services to launch on event + safe_symlink("restart", "root/etc/e-smith/events/$event/services2adjust/dnscache"); + safe_symlink("sigusr1", "root/etc/e-smith/events/$event/services2adjust/tinydns"); + safe_symlink("restart", "root/etc/e-smith/events/$event/services2adjust/dhcpd"); + safe_symlink("restart", "root/etc/e-smith/events/$event/services2adjust/dhcp-dns"); + + # actions to perform + safe_symlink("../actions/dnscache-change", "root/etc/e-smith/events/$event/S20dnscache-change"); + + # Template to event + templates2events("/var/service/tinydns/root/data", $event); + } + +#creation of dhcp-dns service + safe_symlink("daemontools", "root/etc/rc.d/init.d/dhcp-dns"); + service_link_enhanced("dhcp-dns", "S85", "7"); + service_link_enhanced("dhcp-dns", "K65", "6"); + service_link_enhanced("dhcp-dns", "K65", "0"); + service_link_enhanced("dhcp-dns", "K65", "1"); + safe_symlink("/var/service/dhcp-dns/", "root/service/dhcp-dns"); diff -Nur e-smith-tinydns-2.4.0.old/root/etc/e-smith/db/configuration/defaults/dhcp-dns/status e-smith-tinydns-2.4.0/root/etc/e-smith/db/configuration/defaults/dhcp-dns/status --- e-smith-tinydns-2.4.0.old/root/etc/e-smith/db/configuration/defaults/dhcp-dns/status 1970-01-01 01:00:00.000000000 +0100 +++ e-smith-tinydns-2.4.0/root/etc/e-smith/db/configuration/defaults/dhcp-dns/status 2014-06-17 23:47:00.028649886 +0200 @@ -0,0 +1 @@ +enabled diff -Nur e-smith-tinydns-2.4.0.old/root/etc/e-smith/db/configuration/defaults/dhcp-dns/type e-smith-tinydns-2.4.0/root/etc/e-smith/db/configuration/defaults/dhcp-dns/type --- e-smith-tinydns-2.4.0.old/root/etc/e-smith/db/configuration/defaults/dhcp-dns/type 1970-01-01 01:00:00.000000000 +0100 +++ e-smith-tinydns-2.4.0/root/etc/e-smith/db/configuration/defaults/dhcp-dns/type 2014-06-17 23:47:00.029650013 +0200 @@ -0,0 +1 @@ +service diff -Nur e-smith-tinydns-2.4.0.old/root/etc/e-smith/events/actions/dnscache-change e-smith-tinydns-2.4.0/root/etc/e-smith/events/actions/dnscache-change --- e-smith-tinydns-2.4.0.old/root/etc/e-smith/events/actions/dnscache-change 1970-01-01 01:00:00.000000000 +0100 +++ e-smith-tinydns-2.4.0/root/etc/e-smith/events/actions/dnscache-change 2014-06-17 23:47:00.030650140 +0200 @@ -0,0 +1,3 @@ +#!/bin/sh + +/usr/bin/sv 1 /service/tinydns diff -Nur e-smith-tinydns-2.4.0.old/root/etc/e-smith/templates/var/service/tinydns/root/data/65dhcpARecords e-smith-tinydns-2.4.0/root/etc/e-smith/templates/var/service/tinydns/root/data/65dhcpARecords --- e-smith-tinydns-2.4.0.old/root/etc/e-smith/templates/var/service/tinydns/root/data/65dhcpARecords 1970-01-01 01:00:00.000000000 +0100 +++ e-smith-tinydns-2.4.0/root/etc/e-smith/templates/var/service/tinydns/root/data/65dhcpARecords 2014-06-17 23:52:49.434051111 +0200 @@ -0,0 +1,48 @@ +{ + # we need perl-Text-DHCPparse rpm from Dag's repo + use Text::DHCPparse; + + # we need perl-Date-Manip to convert to a unix timestamp + use Date::Manip qw /UnixDate/; + + # we need perl-Time-TAI64 for timestamp conversion + use Time::TAI64 qw /unixtai64/; + + # copy of dhcpd.leases file to /tmp because working directly on the original + # is not a good idea + use File::Copy; + copy('/var/lib/dhcpd/dhcpd.leases', '/tmp/dhcpd.leases'); + + # now we parse the leases + $return = leaseparse('/tmp/dhcpd.leases'); + + # variable with local domain value (default is mycompamy.local) + my $localdomain = get_local_domainname; + + $OUT .= "# A records for dhcp hosts in $localdomain\n"; + + foreach (keys %$return) { + ($ip, $time, $mac, $name) = unpack("A17 A21 A19 A30", $return->{$_}); + + # when the dhcp lease is over $name is empty .. we want only non empty one + if ( $name ne "" ) { + # we skip also ips already allocated + unless (exists $allocated_ips{$ip}) + { + # Convert lease end time to the format expected as + # see: http://cr.yp.to/djbdns/tinydns-data.html + my $ts = UnixDate($time, "%s"); + my $endtai = unixtai64($ts); + $endtai =~ s/@//; + + # Determine TTL + my $ttl = ''; + $ttl = 0 unless ($ts <= time); + $OUT .= "=$name.$localdomain:$ip:$ttl:$endtai\n"; + } + $allocated_ips{$ip} = 1; + } + } + # remove the temp file + system "rm -f /tmp/dhcpd.leases"; +} diff -Nur e-smith-tinydns-2.4.0.old/root/var/service/dhcp-dns/dhcp-dns e-smith-tinydns-2.4.0/root/var/service/dhcp-dns/dhcp-dns --- e-smith-tinydns-2.4.0.old/root/var/service/dhcp-dns/dhcp-dns 1970-01-01 01:00:00.000000000 +0100 +++ e-smith-tinydns-2.4.0/root/var/service/dhcp-dns/dhcp-dns 2014-06-17 23:47:00.031650267 +0200 @@ -0,0 +1,33 @@ +#!/usr/bin/perl + +my $lease_file = "/var/lib/dhcpd/dhcpd.leases"; + +# last modified time +my $modtime = 0; + +# seconds to wait +my $update_freq = 15; + +########################################################################### +# Main Loop +while (1) { + + # check the file's last updated time, if it's been changed, update + # the DNS and save the modified time. This will ALWAYS run once - on + # startup, since $modtime starts at zero. + + my @stats = stat ($lease_file); + if ($stats[9] > $modtime) { + + $modtime = $stats[9]; + + system ("/usr/bin/sv 1 /service/tinydns"); + } + + # wait till next check time + sleep $update_freq; + +} # end main +########################################################################### + + diff -Nur e-smith-tinydns-2.4.0.old/root/var/service/dhcp-dns/run e-smith-tinydns-2.4.0/root/var/service/dhcp-dns/run --- e-smith-tinydns-2.4.0.old/root/var/service/dhcp-dns/run 1970-01-01 01:00:00.000000000 +0100 +++ e-smith-tinydns-2.4.0/root/var/service/dhcp-dns/run 2014-06-17 23:47:00.032650394 +0200 @@ -0,0 +1,4 @@ +#!/bin/sh + +exec 2>&1 +exec /usr/bin/perl dhcp-dns