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

Annotation 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.1 - (hide annotations) (download)
Sun May 18 15:10:52 2014 UTC (10 years, 1 month ago) by stephdl
Branch: MAIN
CVS Tags: e-smith-tinydns-2_4_0-2_el6_sme
* Sun May 18 2014 stephane de Labrusse <stephdl@de-labrusse.fr> 2.4.0-2
- add new feature Parse dhcpd.leases and feed to tinydns
- made from the solution of Stefano Zamboni [SME:2388]
- Thanks also for all other implicated members in this bug report

1 stephdl 1.1 diff -Nur e-smith-tinydns-2.4.0.old/createlinks e-smith-tinydns-2.4.0/createlinks
2     --- e-smith-tinydns-2.4.0.old/createlinks 2014-05-18 01:58:17.822368168 +0200
3     +++ e-smith-tinydns-2.4.0/createlinks 2014-05-18 02:04:52.426622645 +0200
4     @@ -26,3 +26,27 @@
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     + # actions to perform
19     + safe_symlink("../actions/dnscache-change", "root/etc/e-smith/events/$event/S20dnscache-change");
20     +
21     + # Template to event
22     + templates2events("/var/service/tinydns/root/data", $event);
23     + }
24     +
25     +#creation of dhcp-dns service
26     + safe_symlink("daemontools", "root/etc/rc.d/init.d/dhcp-dns");
27     + service_link_enhanced("dhcp-dns", "S85", "7");
28     + service_link_enhanced("dhcp-dns", "K65", "6");
29     + service_link_enhanced("dhcp-dns", "K65", "0");
30     + service_link_enhanced("dhcp-dns", "K65", "1");
31     + safe_symlink("/var/service/dhcp-dns/", "root/service/dhcp-dns");
32     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
33     --- 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
34     +++ e-smith-tinydns-2.4.0/root/etc/e-smith/db/configuration/defaults/dhcp-dns/status 2014-05-18 02:05:57.345788401 +0200
35     @@ -0,0 +1 @@
36     +enabled
37     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
38     --- 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
39     +++ e-smith-tinydns-2.4.0/root/etc/e-smith/db/configuration/defaults/dhcp-dns/type 2014-05-18 02:05:57.304783191 +0200
40     @@ -0,0 +1 @@
41     +service
42     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
43     --- e-smith-tinydns-2.4.0.old/root/etc/e-smith/events/actions/dnscache-change 1970-01-01 01:00:00.000000000 +0100
44     +++ e-smith-tinydns-2.4.0/root/etc/e-smith/events/actions/dnscache-change 2014-05-18 02:05:58.604948433 +0200
45     @@ -0,0 +1,3 @@
46     +#!/bin/sh
47     +
48     +/usr/bin/sv 1 /service/tinydns
49     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
50     --- 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
51     +++ e-smith-tinydns-2.4.0/root/etc/e-smith/templates/var/service/tinydns/root/data/65dhcpARecords 2014-05-18 02:06:05.227790167 +0200
52     @@ -0,0 +1,48 @@
53     +{
54     + # we need perl-Text-DHCPparse rpm from Dag's repo
55     + use Text::DHCPparse;
56     +
57     + # we need perl-Date-Manip to convert to a unix timestamp
58     + use Date::Manip qw /UnixDate/;
59     +
60     + # we need perl-Time-TAI64 for timestamp conversion
61     + use Time::TAI64 qw /unixtai64/;
62     +
63     + # copy of dhcpd.leases file to /tmp because working directly on the original
64     + # is not a good idea
65     + system "cat /var/lib/dhcpd/dhcpd.leases > /tmp/dhcpd.leases";
66     +
67     + # now we parse the leases
68     + $return = leaseparse('/tmp/dhcpd.leases');
69     +
70     + # variable with local domain value (default is mycompamy.local)
71     + my $localdomain = get_local_domainname;
72     +
73     + $OUT .= "# A records for dhcp hosts in $localdomain\n";
74     +
75     + foreach (keys %$return) {
76     + ($ip, $time, $mac, $name) = unpack("A17 A21 A19 A30", $return->{$_});
77     +
78     + # sometimes $name is empty.. we want only non empty one
79     + if ( (defined $name) && (defined $ip)) {
80     + # we skip also ips already allocated
81     + unless (exists $allocated_ips{$ip})
82     + {
83     + # Convert lease end time to the format expected as
84     + # see: http://cr.yp.to/djbdns/tinydns-data.html
85     + my $ts = UnixDate($time, "%s");
86     + my $endtai = unixtai64($ts);
87     + $endtai =~ s/@//;
88     +
89     + # Determine TTL
90     + my $ttl = '';
91     + $ttl = 0 unless ($ts <= time);
92     +
93     + $OUT .= "=$name.$localdomain:$ip:$ttl:$endtai\n";
94     + }
95     + $allocated_ips{$ip} = 1;
96     + }
97     + }
98     + # remove the temp file
99     + system "rm -f /tmp/dhcpd.leases";
100     +}
101     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
102     --- e-smith-tinydns-2.4.0.old/root/var/service/dhcp-dns/dhcp-dns 1970-01-01 01:00:00.000000000 +0100
103     +++ e-smith-tinydns-2.4.0/root/var/service/dhcp-dns/dhcp-dns 2014-05-18 02:06:08.370189551 +0200
104     @@ -0,0 +1,33 @@
105     +#!/usr/bin/perl
106     +
107     +my $lease_file = "/var/lib/dhcpd/dhcpd.leases";
108     +
109     +# last modified time
110     +my $modtime = 0;
111     +
112     +# seconds to wait
113     +my $update_freq = 15;
114     +
115     +###########################################################################
116     +# Main Loop
117     +while (1) {
118     +
119     + # check the file's last updated time, if it's been changed, update
120     + # the DNS and save the modified time. This will ALWAYS run once - on
121     + # startup, since $modtime starts at zero.
122     +
123     + my @stats = stat ($lease_file);
124     + if ($stats[9] > $modtime) {
125     +
126     + $modtime = $stats[9];
127     +
128     + system ("/usr/bin/sv 1 /service/tinydns");
129     + }
130     +
131     + # wait till next check time
132     + sleep $update_freq;
133     +
134     +} # end main
135     +###########################################################################
136     +
137     +
138     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
139     --- e-smith-tinydns-2.4.0.old/root/var/service/dhcp-dns/run 1970-01-01 01:00:00.000000000 +0100
140     +++ e-smith-tinydns-2.4.0/root/var/service/dhcp-dns/run 2014-05-18 02:06:08.429197051 +0200
141     @@ -0,0 +1,4 @@
142     +#!/bin/sh
143     +
144     +exec 2>&1
145     +exec /usr/bin/perl dhcp-dns

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