/[smeserver]/rpms/e-smith-tinydns/sme9/e-smith-tinydns-2.4.0_add_hostname_following_dhcpdleases_hostname.patch
ViewVC logotype

Contents of /rpms/e-smith-tinydns/sme9/e-smith-tinydns-2.4.0_add_hostname_following_dhcpdleases_hostname.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download)
Mon Jan 12 20:59:17 2015 UTC (9 years, 5 months ago) by stephdl
Branch: MAIN
CVS Tags: e-smith-tinydns-2_4_0-5_el6_sme
Changes since 1.3: +4 -4 lines
* Fri Jan 9 2015 stephane de Labrusse <stephdl@de-labrusse.fr> 2.4.0-5.sme
- Changed the name of /tmp/dhcpd.leases to /tmp/tmpdhcpd.leases [SME: 2388]

1 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 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 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 @@ -0,0 +1 @@
33 +enabled
34 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 @@ -0,0 +1 @@
38 +service
39 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 +{
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 + use File::Copy;
53 + copy('/var/lib/dhcpd/dhcpd.leases', '/tmp/tmpdhcpd.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 + # now we parse the leases
87 + $return = leaseparse('/tmp/tmpdhcpd.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 + # when the dhcp lease is over $name is empty .. we want only non empty one
97 + if ( $name ne "" ) {
98 + # 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 + system ("rm -f /tmp/tmpdhcpd.leases") ==0
117 + or die ("Error dhcp-dns Service : Can't rm the /tmp/tmpdhcpd.leases");
118 +}
119 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 +#!/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 +my $update_freq = 30;
132 +
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 + 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 +
154 + }
155 +
156 + # wait till next check time
157 + sleep $update_freq;
158 +
159 +} # end main
160 +###########################################################################
161 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 @@ -0,0 +1,4 @@
165 +#!/bin/sh
166 +
167 +exec 2>&1
168 +exec /usr/bin/perl dhcp-dns

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed