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

Diff 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 | View Patch Patch

Revision 1.1 by stephdl, Sun May 18 15:10:52 2014 UTC Revision 1.8 by stephdl, Wed Jan 28 23:41:54 2015 UTC
# Line 1  Line 1 
1  diff -Nur e-smith-tinydns-2.4.0.old/createlinks e-smith-tinydns-2.4.0/createlinks  diff -Nur e-smith-tinydns-2.4.0.old2388/createlinks e-smith-tinydns-2.4.0.bz2388/createlinks
2  --- e-smith-tinydns-2.4.0.old/createlinks       2014-05-18 01:58:17.822368168 +0200  --- e-smith-tinydns-2.4.0.old2388/createlinks   2015-01-27 19:31:32.953849658 +0100
3  +++ e-smith-tinydns-2.4.0/createlinks   2014-05-18 02:04:52.426622645 +0200  +++ e-smith-tinydns-2.4.0.bz2388/createlinks    2015-01-27 20:23:29.080882560 +0100
4  @@ -26,3 +26,27 @@  @@ -26,3 +26,19 @@
5   service_link_enhanced("tinydns", "K65", "6");   service_link_enhanced("tinydns", "K65", "6");
6   service_link_enhanced("tinydns", "K65", "0");   service_link_enhanced("tinydns", "K65", "0");
7   service_link_enhanced("tinydns", "K65", "1");   service_link_enhanced("tinydns", "K65", "1");
# Line 10  diff -Nur e-smith-tinydns-2.4.0.old/crea Line 10  diff -Nur e-smith-tinydns-2.4.0.old/crea
10  +    for  my $event (qw( dhcp-dns ))  +    for  my $event (qw( dhcp-dns ))
11  +        {  +        {
12  +        # services to launch on event  +        # services to launch on event
13  +        safe_symlink("restart", "root/etc/e-smith/events/$event/services2adjust/dnscache");  +        safe_symlink("sigusr1", "root/etc/e-smith/events/$event/services2adjust/dnscache");
14  +        safe_symlink("sigusr1", "root/etc/e-smith/events/$event/services2adjust/tinydns");  +        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);  
15  +        }  +        }
16  +  +
17  +#creation of dhcp-dns service  +#creation of dhcp-dns service
# Line 29  diff -Nur e-smith-tinydns-2.4.0.old/crea Line 21  diff -Nur e-smith-tinydns-2.4.0.old/crea
21  +    service_link_enhanced("dhcp-dns", "K65", "0");  +    service_link_enhanced("dhcp-dns", "K65", "0");
22  +    service_link_enhanced("dhcp-dns", "K65", "1");  +    service_link_enhanced("dhcp-dns", "K65", "1");
23  +    safe_symlink("/var/service/dhcp-dns/", "root/service/dhcp-dns");  +    safe_symlink("/var/service/dhcp-dns/", "root/service/dhcp-dns");
24  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  diff -Nur e-smith-tinydns-2.4.0.old2388/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
25  --- 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.old2388/root/etc/e-smith/db/configuration/defaults/dhcp-dns/status    1970-01-01 01:00:00.000000000 +0100
26  +++ e-smith-tinydns-2.4.0/root/etc/e-smith/db/configuration/defaults/dhcp-dns/status    2014-05-18 02:05:57.345788401 +0200  +++ e-smith-tinydns-2.4.0.bz2388/root/etc/e-smith/db/configuration/defaults/dhcp-dns/status     2015-01-27 20:30:30.481143377 +0100
27  @@ -0,0 +1 @@  @@ -0,0 +1 @@
28  +enabled  +disabled
29  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  diff -Nur e-smith-tinydns-2.4.0.old2388/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
30  --- 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.old2388/root/etc/e-smith/db/configuration/defaults/dhcp-dns/type      1970-01-01 01:00:00.000000000 +0100
31  +++ e-smith-tinydns-2.4.0/root/etc/e-smith/db/configuration/defaults/dhcp-dns/type      2014-05-18 02:05:57.304783191 +0200  +++ e-smith-tinydns-2.4.0.bz2388/root/etc/e-smith/db/configuration/defaults/dhcp-dns/type       2015-01-27 20:23:29.075882144 +0100
32  @@ -0,0 +1 @@  @@ -0,0 +1 @@
33  +service  +service
34  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  diff -Nur e-smith-tinydns-2.4.0.old2388/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
35  --- 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.old2388/root/etc/e-smith/templates/var/service/tinydns/root/data/65dhcpARecords       1970-01-01 01:00:00.000000000 +0100
36  +++ e-smith-tinydns-2.4.0/root/etc/e-smith/events/actions/dnscache-change       2014-05-18 02:05:58.604948433 +0200  +++ e-smith-tinydns-2.4.0.bz2388/root/etc/e-smith/templates/var/service/tinydns/root/data/65dhcpARecords        2015-01-29 00:35:54.988996507 +0100
37  @@ -0,0 +1,3 @@  @@ -0,0 +1,136 @@
 +#!/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-05-18 02:06:05.227790167 +0200  
 @@ -0,0 +1,48 @@  
38  +{  +{
39  +    # we need perl-Text-DHCPparse rpm from Dag's repo  +    use strict;
40  +    use Text::DHCPparse;  +    use warnings;
41  +  +    use esmith::Logger;
42  +    # we need perl-Date-Manip to convert to a unix timestamp  +    use esmith::ConfigDB;
43  +    use Date::Manip qw /UnixDate/;  +    use esmith::HostsDB;
 +    
 +    # we need perl-Time-TAI64 for timestamp conversion  
44  +    use Time::TAI64 qw /unixtai64/;  +    use Time::TAI64 qw /unixtai64/;
45    +    use Date::Manip qw /UnixDate/;
46    +    use File::Copy;
47    +
48    +    my $DB = esmith::ConfigDB->open_ro or die ("Unable to open configuration database");
49    +    my $hosts = esmith::HostsDB->open_ro or die ("Unable to open Host database");
50    +
51    +    my $dhcpdns = $DB->get_prop('dhcp-dns','status') || 'disabled';
52    +    return '' if $dhcpdns ne 'enabled';
53    +
54    +    #we start a hash for name & ip
55    +    my %allocated_name = ();
56    +    my %allocated_ip_dhcplease = ();
57    +
58    +    #start a hash of all hosts in DB
59    +    my @hosts = $hosts->keys;
60    +    my %hostsdb;
61    +    @hostsdb{@hosts} = ();
62    +
63    +    # copy dhcpd.leases to /tmp
64    +    copy("/var/lib/dhcpd/dhcpd.leases","/tmp/tmpdhcpd.leases")
65    +        or die ("Error dhcp-dns Service : Unable to copy the /var/lib/dhcpd/dhcpd.leases");
66    +
67    +    #we want to write in log
68    +    sub log2messages
69    +    {
70    +        my $message = shift;
71    +        tie *FH, 'esmith::Logger';
72    +        print FH "$message";
73    +        close FH;
74    +    }
75    +
76    +    #Text::DHCPparse forked because it doesn't allow to retrieve the end of lease
77    +    #Only the start is found by the leaseparse of DHCPparse.pm s/starts/ends
78    +    sub leaseparse
79    +    {
80    +        my $logfile = shift;
81    +        my ( %list, $ip );
82    +        open FILE, $logfile or die;
83    +
84    +        while (<FILE>)
85    +        {
86    +            next if /^#|^$/;
87    +            if (/^lease (\d+\.\d+\.\d+\.\d+)/)
88    +            {
89    +                $ip = $1;
90    +                $list{$ip} = sprintf("%-17s", $ip);
91    +            }
92    +            /^\s*hardware ethernet (.*);/ && ($list{$ip} .= sprintf("%-19s", $1));
93    +            /^\s*ends \d (.*);/ && ($list{$ip} .= sprintf("%-21s", $1));
94    +            /^\s*(abandoned).*/ && ($list{$ip} .= sprintf("%-19s", $1));
95    +            /^\s*client-hostname "(.*)";/ && ($list{$ip} .= sprintf("%-17s", $1));
96    +        }
97    +
98    +        close FILE;
99    +
100    +        # make all entries 74 characters long to format properly
101    +        foreach (keys %list)
102    +        {
103    +            $list{$_} = sprintf("%-74s", $list{$_}) if (length$list{$_} < 76);
104    +        }
105    +
106    +       return \%list;
107    +    }
108    +
109    +    #hostname validator routine
110    +    sub namevalidator
111    +    {
112    +        my $local_domain = $DB->get_value('DomainName') or die ("Unable retrieve the DomainName property");
113    +        my $server_name  = $DB->get_value('SystemName') or die ("Unable retrieve the SystemName property");
114    +        my  $validator = shift;
115    +
116    +        if ($validator eq $server_name) {
117    +        log2messages("The hostname of this server ($server_name) is already in use with a different IP address in /var/lib/dhcpd/dhcpd.leases");
118    +        return 1;
119    +        }
120    +        elsif ($validator !~ /^[a-zA-Z0-9][a-zA-Z0-9-]*$/) {
121    +        log2messages("The hostname of the dhcp client ($validator) contains illegal characters in /var/lib/dhcpd/dhcpd.leases");
122    +        return 1;
123    +        }
124    +        elsif  (exists $hostsdb{lc "$validator\.$local_domain"}) {
125    +        log2messages("The hostname of the dhcp client ($validator) is already used in the hosts database");
126    +        return 1;
127    +        }
128    +        elsif   (exists $allocated_name{$validator}) {
129    +        log2messages("The hostname ($validator)  has already been assigned an IP address in /var/lib/dhcpd/dhcpd.leases");
130    +        return 1;
131    +        }
132    +        else {
133    +        return 0;
134    +        }
135    +    }
136  +  +
 +    # copy of dhcpd.leases file to /tmp because working directly on the original  
 +    # is not a good idea  
 +    system "cat /var/lib/dhcpd/dhcpd.leases > /tmp/dhcpd.leases";  
 +        
137  +    # now we parse the leases  +    # now we parse the leases
138  +    $return = leaseparse('/tmp/dhcpd.leases');  +    my $return = leaseparse('/tmp/tmpdhcpd.leases');
139  +    +    my ($ip,$time,$mac,$name);
140  +    # variable with local domain value (default is  mycompamy.local)  +
141  +    my $localdomain = get_local_domainname;  +    # retrieve the local domain name
142    +    my $localdomain = $DB->get_value('DomainName') or die ("Unable retrieve the DomainName property");
143  +  +
144  +    $OUT .= "# A records for dhcp hosts in $localdomain\n";  +    $OUT .= "# A records for dhcp hosts in $localdomain\n";
145  +  +
146  +    foreach (keys %$return) {  +    foreach (keys %$return)
147    +    {
148  +        ($ip, $time, $mac, $name) = unpack("A17 A21 A19 A30", $return->{$_});  +        ($ip, $time, $mac, $name) = unpack("A17 A21 A19 A30", $return->{$_});
149  +  +
150  +        # sometimes $name is empty.. we want only non empty one  +        # we skip allocated ips & empty names
151  +        if ( (defined $name) && (defined $ip)) {  +        unless ((exists $allocated_ip_dhcplease{$ip}) || ( $name eq "" ))
152  +            # we skip also ips already allocated  +        {
153  +            unless (exists $allocated_ips{$ip})  +            # Convert lease end time to the format expected as
154  +            {  +            # see:  http://cr.yp.to/djbdns/tinydns-data.html
155  +                # Convert lease end time to the format expected as  +            my $ts = UnixDate($time, "%s");
156  +                # see:  http://cr.yp.to/djbdns/tinydns-data.html  +            my $endtai = unixtai64($ts);
157  +                my $ts = UnixDate($time, "%s");  +            $endtai =~ s/@//;
158  +                my $endtai = unixtai64($ts);  +
159  +                $endtai =~ s/@//;  +            # Determine TTL
160  +  +            my $ttl = '';
161  +                # Determine TTL  +            $ttl = 0 unless ($ts <= time);
 +                my $ttl = '';  
 +                $ttl = 0 unless ($ts <= time);  
162  +  +
163  +                $OUT .= "=$name.$localdomain:$ip:$ttl:$endtai\n";  +            # display if the hostname is valid
164  +            }  +            $OUT .= "=$name.$localdomain:$ip:$ttl:$endtai\n" if (namevalidator("$name") ne '1');
 +            $allocated_ips{$ip} = 1;  
165  +        }  +        }
166    +
167    +        $allocated_ip_dhcplease{$ip} = 1;
168    +        $allocated_name{$name} ++;
169  +    }  +    }
170  +    # remove the temp file  +    # remove the temp file
171  +    system "rm -f /tmp/dhcpd.leases";  +    unlink "/tmp/tmpdhcpd.leases"
172    +      or log2messages("Error dhcp-dns Service : Unable to remove the /tmp/tmpdhcpd.leases");
173  +}  +}
174  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  diff -Nur e-smith-tinydns-2.4.0.old2388/root/var/service/dhcp-dns/dhcp-dns e-smith-tinydns-2.4.0.bz2388/root/var/service/dhcp-dns/dhcp-dns
175  --- 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.old2388/root/var/service/dhcp-dns/dhcp-dns    1970-01-01 01:00:00.000000000 +0100
176  +++ e-smith-tinydns-2.4.0/root/var/service/dhcp-dns/dhcp-dns    2014-05-18 02:06:08.370189551 +0200  +++ e-smith-tinydns-2.4.0.bz2388/root/var/service/dhcp-dns/dhcp-dns     2015-01-28 00:24:48.209462754 +0100
177  @@ -0,0 +1,33 @@  @@ -0,0 +1,49 @@
178  +#!/usr/bin/perl  +#!/usr/bin/perl
179    +use strict;
180    +use warnings;
181    +use esmith::ConfigDB;
182    +
183    +my $DB = esmith::ConfigDB->open_ro or die ("Unable to open configuration database");
184    +my $dhcpdns = $DB->get_prop('dhcp-dns','status') || 'disabled';
185  +  +
186  +my $lease_file = "/var/lib/dhcpd/dhcpd.leases";  +my $lease_file = "/var/lib/dhcpd/dhcpd.leases";
187  +  +
# Line 110  diff -Nur e-smith-tinydns-2.4.0.old/root Line 189  diff -Nur e-smith-tinydns-2.4.0.old/root
189  +my $modtime = 0;  +my $modtime = 0;
190  +  +
191  +# seconds to wait  +# seconds to wait
192  +my $update_freq = 15;  +my $update_freq = 30;
193    +
194    +#we want to write in log
195    +sub log2messages
196    +   {
197    +        my $message = shift;
198    +        tie *FH, 'esmith::Logger';
199    +        print FH "$message";
200    +        close FH;
201    +   }
202  +  +
203  +###########################################################################  +###########################################################################
204  +# Main Loop  +# Main Loop
205  +while (1) {  +while ($dhcpdns eq 'enabled') {
206  +  +
207  +  # check the file's last updated time, if it's been changed, update  +  # check the file's last updated time, if it's been changed, update
208  +  # the DNS and save the modified time.  This will ALWAYS run once - on  +  # the DNS and save the modified time.  This will ALWAYS run once - on
# Line 124  diff -Nur e-smith-tinydns-2.4.0.old/root Line 212  diff -Nur e-smith-tinydns-2.4.0.old/root
212  +  if ($stats[9] > $modtime) {  +  if ($stats[9] > $modtime) {
213  +    +  
214  +       $modtime = $stats[9];  +       $modtime = $stats[9];
215    +        system ("/usr/bin/sv 1 /service/tinydns") ==0
216    +            or log2messages('Error service dhcp-dns : Unable to restart /service/tinydns');
217  +  +
218  +        system ("/usr/bin/sv 1 /service/tinydns");  +        system ("/usr/bin/sv 1 /service/dnscache") ==0
219    +            or log2messages('Error service dhcp-dns : Unable to do restart /service/dnscache');
220  +  }  +  }
221  +  +
222  +  # wait till next check time  +  # wait till next check time
# Line 133  diff -Nur e-smith-tinydns-2.4.0.old/root Line 224  diff -Nur e-smith-tinydns-2.4.0.old/root
224  +  +
225  +} # end main  +} # end main
226  +###########################################################################  +###########################################################################
227  +  diff -Nur e-smith-tinydns-2.4.0.old2388/root/var/service/dhcp-dns/run e-smith-tinydns-2.4.0.bz2388/root/var/service/dhcp-dns/run
228  +  --- e-smith-tinydns-2.4.0.old2388/root/var/service/dhcp-dns/run 1970-01-01 01:00:00.000000000 +0100
229  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.bz2388/root/var/service/dhcp-dns/run  2015-01-27 20:23:29.079882477 +0100
 --- 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-05-18 02:06:08.429197051 +0200  
230  @@ -0,0 +1,4 @@  @@ -0,0 +1,4 @@
231  +#!/bin/sh  +#!/bin/sh
232  +  +


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

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