/[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.2 - (hide annotations) (download)
Tue Jun 17 23:11:11 2014 UTC (10 years ago) by stephdl
Branch: MAIN
Changes since 1.1: +13 -13 lines
* Tue Jun 18 2014 stephane de Labrusse <stephdl@de-labrusse.fr> 2.4.0-3.sme
- add new feature Parse dhcpd.leases and feed to tinydns
- e-smith-tinydns-2.4.0_add_hostname_following_dhcpdleases_hostname.patch
- 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 stephdl 1.2 --- e-smith-tinydns-2.4.0.old/createlinks 2014-06-17 23:46:27.046462016 +0200
3     +++ e-smith-tinydns-2.4.0/createlinks 2014-06-17 23:47:00.027649759 +0200
4 stephdl 1.1 @@ -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 stephdl 1.2 +++ e-smith-tinydns-2.4.0/root/etc/e-smith/db/configuration/defaults/dhcp-dns/status 2014-06-17 23:47:00.028649886 +0200
35 stephdl 1.1 @@ -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 stephdl 1.2 +++ e-smith-tinydns-2.4.0/root/etc/e-smith/db/configuration/defaults/dhcp-dns/type 2014-06-17 23:47:00.029650013 +0200
40 stephdl 1.1 @@ -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 stephdl 1.2 +++ e-smith-tinydns-2.4.0/root/etc/e-smith/events/actions/dnscache-change 2014-06-17 23:47:00.030650140 +0200
45 stephdl 1.1 @@ -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 stephdl 1.2 +++ 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
52 stephdl 1.1 @@ -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 stephdl 1.2 + use File::Copy;
66     + copy('/var/lib/dhcpd/dhcpd.leases', '/tmp/dhcpd.leases');
67     +
68 stephdl 1.1 + # now we parse the leases
69     + $return = leaseparse('/tmp/dhcpd.leases');
70     +
71     + # variable with local domain value (default is mycompamy.local)
72     + my $localdomain = get_local_domainname;
73     +
74     + $OUT .= "# A records for dhcp hosts in $localdomain\n";
75     +
76     + foreach (keys %$return) {
77     + ($ip, $time, $mac, $name) = unpack("A17 A21 A19 A30", $return->{$_});
78     +
79 stephdl 1.2 + # when the dhcp lease is over $name is empty .. we want only non empty one
80     + if ( $name ne "" ) {
81 stephdl 1.1 + # we skip also ips already allocated
82     + unless (exists $allocated_ips{$ip})
83     + {
84     + # Convert lease end time to the format expected as
85     + # see: http://cr.yp.to/djbdns/tinydns-data.html
86     + my $ts = UnixDate($time, "%s");
87     + my $endtai = unixtai64($ts);
88     + $endtai =~ s/@//;
89     +
90     + # Determine TTL
91     + my $ttl = '';
92     + $ttl = 0 unless ($ts <= time);
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 stephdl 1.2 +++ e-smith-tinydns-2.4.0/root/var/service/dhcp-dns/dhcp-dns 2014-06-17 23:47:00.031650267 +0200
104 stephdl 1.1 @@ -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 stephdl 1.2 +++ e-smith-tinydns-2.4.0/root/var/service/dhcp-dns/run 2014-06-17 23:47:00.032650394 +0200
141 stephdl 1.1 @@ -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