1 |
stephdl |
1.3 |
diff -Nur e-smith-tinydns-2.4.0/createlinks e-smith-tinydns-2.4.0.bz2388/createlinks |
2 |
|
|
--- e-smith-tinydns-2.4.0/createlinks 2006-03-14 23:01:42.000000000 +0100 |
3 |
|
|
+++ e-smith-tinydns-2.4.0.bz2388/createlinks 2015-01-09 22:18:42.489639249 +0100 |
4 |
|
|
@@ -26,3 +26,24 @@ |
5 |
stephdl |
1.1 |
service_link_enhanced("tinydns", "K65", "6"); |
6 |
|
|
service_link_enhanced("tinydns", "K65", "0"); |
7 |
|
|
service_link_enhanced("tinydns", "K65", "1"); |
8 |
|
|
+ |
9 |
|
|
+#link to services2adjust and templates2expand for dhcp-dns event |
10 |
|
|
+ for my $event (qw( dhcp-dns )) |
11 |
|
|
+ { |
12 |
|
|
+ # services to launch on event |
13 |
|
|
+ safe_symlink("restart", "root/etc/e-smith/events/$event/services2adjust/dnscache"); |
14 |
|
|
+ safe_symlink("sigusr1", "root/etc/e-smith/events/$event/services2adjust/tinydns"); |
15 |
|
|
+ safe_symlink("restart", "root/etc/e-smith/events/$event/services2adjust/dhcpd"); |
16 |
|
|
+ safe_symlink("restart", "root/etc/e-smith/events/$event/services2adjust/dhcp-dns"); |
17 |
|
|
+ |
18 |
|
|
+ # Template to event |
19 |
|
|
+ templates2events("/var/service/tinydns/root/data", $event); |
20 |
|
|
+ } |
21 |
|
|
+ |
22 |
|
|
+#creation of dhcp-dns service |
23 |
|
|
+ safe_symlink("daemontools", "root/etc/rc.d/init.d/dhcp-dns"); |
24 |
|
|
+ service_link_enhanced("dhcp-dns", "S85", "7"); |
25 |
|
|
+ service_link_enhanced("dhcp-dns", "K65", "6"); |
26 |
|
|
+ service_link_enhanced("dhcp-dns", "K65", "0"); |
27 |
|
|
+ service_link_enhanced("dhcp-dns", "K65", "1"); |
28 |
|
|
+ safe_symlink("/var/service/dhcp-dns/", "root/service/dhcp-dns"); |
29 |
stephdl |
1.3 |
diff -Nur e-smith-tinydns-2.4.0/root/etc/e-smith/db/configuration/defaults/dhcp-dns/status e-smith-tinydns-2.4.0.bz2388/root/etc/e-smith/db/configuration/defaults/dhcp-dns/status |
30 |
|
|
--- e-smith-tinydns-2.4.0/root/etc/e-smith/db/configuration/defaults/dhcp-dns/status 1970-01-01 01:00:00.000000000 +0100 |
31 |
|
|
+++ e-smith-tinydns-2.4.0.bz2388/root/etc/e-smith/db/configuration/defaults/dhcp-dns/status 2015-01-08 13:33:30.870973725 +0100 |
32 |
stephdl |
1.1 |
@@ -0,0 +1 @@ |
33 |
|
|
+enabled |
34 |
stephdl |
1.3 |
diff -Nur e-smith-tinydns-2.4.0/root/etc/e-smith/db/configuration/defaults/dhcp-dns/type e-smith-tinydns-2.4.0.bz2388/root/etc/e-smith/db/configuration/defaults/dhcp-dns/type |
35 |
|
|
--- e-smith-tinydns-2.4.0/root/etc/e-smith/db/configuration/defaults/dhcp-dns/type 1970-01-01 01:00:00.000000000 +0100 |
36 |
|
|
+++ e-smith-tinydns-2.4.0.bz2388/root/etc/e-smith/db/configuration/defaults/dhcp-dns/type 2015-01-08 13:33:30.870973725 +0100 |
37 |
stephdl |
1.1 |
@@ -0,0 +1 @@ |
38 |
|
|
+service |
39 |
stephdl |
1.3 |
diff -Nur e-smith-tinydns-2.4.0/root/etc/e-smith/templates/var/service/tinydns/root/data/65dhcpARecords e-smith-tinydns-2.4.0.bz2388/root/etc/e-smith/templates/var/service/tinydns/root/data/65dhcpARecords |
40 |
|
|
--- e-smith-tinydns-2.4.0/root/etc/e-smith/templates/var/service/tinydns/root/data/65dhcpARecords 1970-01-01 01:00:00.000000000 +0100 |
41 |
|
|
+++ e-smith-tinydns-2.4.0.bz2388/root/etc/e-smith/templates/var/service/tinydns/root/data/65dhcpARecords 2015-01-09 22:09:02.149175482 +0100 |
42 |
|
|
@@ -0,0 +1,76 @@ |
43 |
stephdl |
1.1 |
+{ |
44 |
|
|
+ # we need perl-Date-Manip to convert to a unix timestamp |
45 |
|
|
+ use Date::Manip qw /UnixDate/; |
46 |
|
|
+ |
47 |
|
|
+ # we need perl-Time-TAI64 for timestamp conversion |
48 |
|
|
+ use Time::TAI64 qw /unixtai64/; |
49 |
|
|
+ |
50 |
|
|
+ # copy of dhcpd.leases file to /tmp because working directly on the original |
51 |
|
|
+ # is not a good idea |
52 |
stephdl |
1.2 |
+ use File::Copy; |
53 |
stephdl |
1.3 |
+ copy('/var/lib/dhcpd/dhcpd.leases', '/tmp/dhcpd.leases') |
54 |
|
|
+ or die ("Error dhcp-dns Service : Can't copy the /var/lib/dhcpd/dhcpd.leases"); |
55 |
|
|
+ |
56 |
|
|
+ #Text::DHCPparse forked because it doesn't allow to retrieve the end of lease |
57 |
|
|
+ #Only the start is found by the leaseparse of DHCPparse.pm s/starts/ends |
58 |
|
|
+ sub leaseparse { |
59 |
|
|
+ my $logfile = shift; |
60 |
|
|
+ my ( %list, $ip ); |
61 |
|
|
+ open FILE, $logfile or die; |
62 |
|
|
+ |
63 |
|
|
+ while (<FILE>) { |
64 |
|
|
+ next if /^#|^$/; |
65 |
|
|
+ if (/^lease (\d+\.\d+\.\d+\.\d+)/) { |
66 |
|
|
+ $ip = $1; |
67 |
|
|
+ $list{$ip} = sprintf("%-17s", $ip); |
68 |
|
|
+ } |
69 |
|
|
+ /^\s*hardware ethernet (.*);/ && ($list{$ip} .= sprintf("%-19s", $1)); |
70 |
|
|
+ /^\s*ends \d (.*);/ && ($list{$ip} .= sprintf("%-21s", $1)); |
71 |
|
|
+ /^\s*(abandoned).*/ && ($list{$ip} .= sprintf("%-19s", $1)); |
72 |
|
|
+ /^\s*client-hostname "(.*)";/ && ($list{$ip} .= sprintf("%-17s", $1)); |
73 |
|
|
+ } |
74 |
|
|
+ |
75 |
|
|
+ close FILE; |
76 |
|
|
+ |
77 |
|
|
+ # make all entries 74 characters long to format properly |
78 |
|
|
+ foreach (keys %list) { |
79 |
|
|
+ #$list{$_} = sprintf("%-74s", $list{$_}) if (length$list{$_} < 76); |
80 |
|
|
+ $list{$_} = sprintf("%-74.74s", $list{$_}); |
81 |
|
|
+ } |
82 |
|
|
+ |
83 |
|
|
+ return \%list; |
84 |
|
|
+} |
85 |
|
|
+ |
86 |
stephdl |
1.1 |
+ # now we parse the leases |
87 |
|
|
+ $return = leaseparse('/tmp/dhcpd.leases'); |
88 |
|
|
+ |
89 |
|
|
+ # variable with local domain value (default is mycompamy.local) |
90 |
|
|
+ my $localdomain = get_local_domainname; |
91 |
|
|
+ |
92 |
|
|
+ $OUT .= "# A records for dhcp hosts in $localdomain\n"; |
93 |
|
|
+ |
94 |
|
|
+ foreach (keys %$return) { |
95 |
|
|
+ ($ip, $time, $mac, $name) = unpack("A17 A21 A19 A30", $return->{$_}); |
96 |
stephdl |
1.3 |
+ # when the dhcp lease is over $name is empty .. we want only non empty one |
97 |
stephdl |
1.2 |
+ if ( $name ne "" ) { |
98 |
stephdl |
1.1 |
+ # we skip also ips already allocated |
99 |
|
|
+ unless (exists $allocated_ips{$ip}) |
100 |
|
|
+ { |
101 |
|
|
+ # Convert lease end time to the format expected as |
102 |
|
|
+ # see: http://cr.yp.to/djbdns/tinydns-data.html |
103 |
|
|
+ my $ts = UnixDate($time, "%s"); |
104 |
|
|
+ my $endtai = unixtai64($ts); |
105 |
|
|
+ $endtai =~ s/@//; |
106 |
|
|
+ |
107 |
|
|
+ # Determine TTL |
108 |
|
|
+ my $ttl = ''; |
109 |
|
|
+ $ttl = 0 unless ($ts <= time); |
110 |
|
|
+ $OUT .= "=$name.$localdomain:$ip:$ttl:$endtai\n"; |
111 |
|
|
+ } |
112 |
|
|
+ $allocated_ips{$ip} = 1; |
113 |
|
|
+ } |
114 |
|
|
+ } |
115 |
|
|
+ # remove the temp file |
116 |
stephdl |
1.3 |
+ system ("rm -f /tmp/dhcpd.leases") ==0 |
117 |
|
|
+ or die ("Error dhcp-dns Service : Can't rm the /tmp/dhcpd.leases"); |
118 |
stephdl |
1.1 |
+} |
119 |
stephdl |
1.3 |
diff -Nur e-smith-tinydns-2.4.0/root/var/service/dhcp-dns/dhcp-dns e-smith-tinydns-2.4.0.bz2388/root/var/service/dhcp-dns/dhcp-dns |
120 |
|
|
--- e-smith-tinydns-2.4.0/root/var/service/dhcp-dns/dhcp-dns 1970-01-01 01:00:00.000000000 +0100 |
121 |
|
|
+++ e-smith-tinydns-2.4.0.bz2388/root/var/service/dhcp-dns/dhcp-dns 2015-01-09 22:22:32.389241240 +0100 |
122 |
|
|
@@ -0,0 +1,38 @@ |
123 |
stephdl |
1.1 |
+#!/usr/bin/perl |
124 |
|
|
+ |
125 |
|
|
+my $lease_file = "/var/lib/dhcpd/dhcpd.leases"; |
126 |
|
|
+ |
127 |
|
|
+# last modified time |
128 |
|
|
+my $modtime = 0; |
129 |
|
|
+ |
130 |
|
|
+# seconds to wait |
131 |
stephdl |
1.3 |
+my $update_freq = 30; |
132 |
stephdl |
1.1 |
+ |
133 |
|
|
+########################################################################### |
134 |
|
|
+# Main Loop |
135 |
|
|
+while (1) { |
136 |
|
|
+ |
137 |
|
|
+ # check the file's last updated time, if it's been changed, update |
138 |
|
|
+ # the DNS and save the modified time. This will ALWAYS run once - on |
139 |
|
|
+ # startup, since $modtime starts at zero. |
140 |
|
|
+ |
141 |
|
|
+ my @stats = stat ($lease_file); |
142 |
|
|
+ if ($stats[9] > $modtime) { |
143 |
|
|
+ |
144 |
|
|
+ $modtime = $stats[9]; |
145 |
stephdl |
1.3 |
+ system ("expand-template /var/service/tinydns/root/data") ==0 |
146 |
|
|
+ or warn ("Error service dhcp-dns : can't do expand-template /var/service/tinydns/root/data"); |
147 |
|
|
+ |
148 |
|
|
+ system ("/usr/bin/sv 1 /service/tinydns") ==0 |
149 |
|
|
+ or warn ("Error service dhcp-dns : can't do sv 1 /service/tinydns"); |
150 |
|
|
+ |
151 |
|
|
+ system ("/usr/bin/sv 1 /service/dnscache") ==0 |
152 |
|
|
+ or warn ("Error service dhcp-dns : can't do sv 1 /service/dnscache"); |
153 |
stephdl |
1.1 |
+ |
154 |
|
|
+ } |
155 |
|
|
+ |
156 |
|
|
+ # wait till next check time |
157 |
|
|
+ sleep $update_freq; |
158 |
|
|
+ |
159 |
|
|
+} # end main |
160 |
|
|
+########################################################################### |
161 |
stephdl |
1.3 |
diff -Nur e-smith-tinydns-2.4.0/root/var/service/dhcp-dns/run e-smith-tinydns-2.4.0.bz2388/root/var/service/dhcp-dns/run |
162 |
|
|
--- e-smith-tinydns-2.4.0/root/var/service/dhcp-dns/run 1970-01-01 01:00:00.000000000 +0100 |
163 |
|
|
+++ e-smith-tinydns-2.4.0.bz2388/root/var/service/dhcp-dns/run 2015-01-08 13:33:30.871973834 +0100 |
164 |
stephdl |
1.1 |
@@ -0,0 +1,4 @@ |
165 |
|
|
+#!/bin/sh |
166 |
|
|
+ |
167 |
|
|
+exec 2>&1 |
168 |
|
|
+exec /usr/bin/perl dhcp-dns |