/[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.4 by stephdl, Mon Jan 12 20:59:17 2015 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/createlinks e-smith-tinydns-2.4.0.bz2388/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/createlinks   2006-03-14 23:01:42.000000000 +0100  --- e-smith-tinydns-2.4.0.old2388/createlinks   2015-01-27 19:31:32.953849658 +0100
3  +++ e-smith-tinydns-2.4.0.bz2388/createlinks    2015-01-09 22:18:42.489639249 +0100  +++ e-smith-tinydns-2.4.0.bz2388/createlinks    2015-01-27 20:23:29.080882560 +0100
4  @@ -26,3 +26,24 @@  @@ -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/createli Line 10  diff -Nur e-smith-tinydns-2.4.0/createli
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");  
 +          
 +        # Template to event  
 +        templates2events("/var/service/tinydns/root/data", $event);  
15  +        }  +        }
16  +  +
17  +#creation of dhcp-dns service  +#creation of dhcp-dns service
# Line 26  diff -Nur e-smith-tinydns-2.4.0/createli Line 21  diff -Nur e-smith-tinydns-2.4.0/createli
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/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  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/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.bz2388/root/etc/e-smith/db/configuration/defaults/dhcp-dns/status     2015-01-08 13:33:30.870973725 +0100  +++ 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/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  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/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.bz2388/root/etc/e-smith/db/configuration/defaults/dhcp-dns/type       2015-01-08 13:33:30.870973725 +0100  +++ 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/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  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/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.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.bz2388/root/etc/e-smith/templates/var/service/tinydns/root/data/65dhcpARecords        2015-01-09 22:09:02.149175482 +0100  +++ 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,76 @@  @@ -0,0 +1,136 @@
38  +{  +{
39  +    # we need perl-Date-Manip to convert to a unix timestamp  +    use strict;
40  +    use Date::Manip qw /UnixDate/;  +    use warnings;
41  +    +    use esmith::Logger;
42  +    # we need perl-Time-TAI64 for timestamp conversion  +    use esmith::ConfigDB;
43    +    use esmith::HostsDB;
44  +    use Time::TAI64 qw /unixtai64/;  +    use Time::TAI64 qw /unixtai64/;
45  +  +    use Date::Manip qw /UnixDate/;
 +    # copy of dhcpd.leases file to /tmp because working directly on the original  
 +    # is not a good idea  
46  +    use File::Copy;  +    use File::Copy;
 +    copy('/var/lib/dhcpd/dhcpd.leases', '/tmp/tmpdhcpd.leases')  
 +        or die ("Error dhcp-dns Service : Can't copy the /var/lib/dhcpd/dhcpd.leases");  
47  +  +
48  +   #Text::DHCPparse forked because it doesn't allow to retrieve the end of lease  +    my $DB = esmith::ConfigDB->open_ro or die ("Unable to open configuration database");
49  +   #Only the start is found by the leaseparse of DHCPparse.pm s/starts/ends  +    my $hosts = esmith::HostsDB->open_ro or die ("Unable to open Host database");
 +   sub leaseparse {  
 +   my $logfile = shift;  
 +   my ( %list, $ip );  
 +   open FILE, $logfile or die;  
 +  
 +   while (<FILE>) {  
 +      next if /^#|^$/;  
 +      if (/^lease (\d+\.\d+\.\d+\.\d+)/) {  
 +         $ip = $1;  
 +         $list{$ip} = sprintf("%-17s", $ip);  
 +      }  
 +      /^\s*hardware ethernet (.*);/ && ($list{$ip} .= sprintf("%-19s", $1));  
 +      /^\s*ends \d (.*);/ && ($list{$ip} .= sprintf("%-21s", $1));  
 +      /^\s*(abandoned).*/ && ($list{$ip} .= sprintf("%-19s", $1));  
 +      /^\s*client-hostname "(.*)";/ && ($list{$ip} .= sprintf("%-17s", $1));  
 +   }  
50  +  +
51  +   close FILE;  +    my $dhcpdns = $DB->get_prop('dhcp-dns','status') || 'disabled';
52    +    return '' if $dhcpdns ne 'enabled';
53  +  +
54  +   # make all entries 74 characters long to format properly  +    #we start a hash for name & ip
55  +   foreach (keys %list) {  +    my %allocated_name = ();
56  +      #$list{$_} = sprintf("%-74s", $list{$_}) if (length$list{$_} < 76);  +    my %allocated_ip_dhcplease = ();
57  +      $list{$_} = sprintf("%-74.74s", $list{$_});  +
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  +   return \%list;  +    #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  +  +
137  +    # now we parse the leases  +    # now we parse the leases
138  +    $return = leaseparse('/tmp/tmpdhcpd.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  +         # when the dhcp lease is over $name is empty .. we want only non empty one  +
150  +         if ( $name ne "" ) {  +        # we skip allocated ips & empty names
151  +            # we skip also ips already allocated  +        unless ((exists $allocated_ip_dhcplease{$ip}) || ( $name eq "" ))
152  +            unless (exists $allocated_ips{$ip})  +        {
153  +            {  +            # Convert lease end time to the format expected as
154  +                # Convert lease end time to the format expected as  +            # see:  http://cr.yp.to/djbdns/tinydns-data.html
155  +                # see:  http://cr.yp.to/djbdns/tinydns-data.html  +            my $ts = UnixDate($time, "%s");
156  +                my $ts = UnixDate($time, "%s");  +            my $endtai = unixtai64($ts);
157  +                my $endtai = unixtai64($ts);  +            $endtai =~ s/@//;
158  +                $endtai =~ s/@//;  +
159  +  +            # Determine TTL
160  +                # Determine TTL  +            my $ttl = '';
161  +                my $ttl = '';  +            $ttl = 0 unless ($ts <= time);
162  +                $ttl = 0 unless ($ts <= time);  +
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/tmpdhcpd.leases") ==0  +    unlink "/tmp/tmpdhcpd.leases"
172  +       or die ("Error dhcp-dns Service : Can't rm the /tmp/tmpdhcpd.leases");  +      or log2messages("Error dhcp-dns Service : Unable to remove the /tmp/tmpdhcpd.leases");
173  +}  +}
174  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  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/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.bz2388/root/var/service/dhcp-dns/dhcp-dns     2015-01-09 22:22:32.389241240 +0100  +++ 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,38 @@  @@ -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 130  diff -Nur e-smith-tinydns-2.4.0/root/var Line 191  diff -Nur e-smith-tinydns-2.4.0/root/var
191  +# seconds to wait  +# seconds to wait
192  +my $update_freq = 30;  +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 142  diff -Nur e-smith-tinydns-2.4.0/root/var Line 212  diff -Nur e-smith-tinydns-2.4.0/root/var
212  +  if ($stats[9] > $modtime) {  +  if ($stats[9] > $modtime) {
213  +    +  
214  +       $modtime = $stats[9];  +       $modtime = $stats[9];
 +        system ("expand-template /var/service/tinydns/root/data") ==0  
 +            or warn ("Error service dhcp-dns : can't do expand-template /var/service/tinydns/root/data");  
 +  
215  +        system ("/usr/bin/sv 1 /service/tinydns") ==0  +        system ("/usr/bin/sv 1 /service/tinydns") ==0
216  +            or warn ("Error service dhcp-dns : can't do sv 1 /service/tinydns");  +            or log2messages('Error service dhcp-dns : Unable to restart /service/tinydns');
217  +  +
218  +        system ("/usr/bin/sv 1 /service/dnscache") ==0  +        system ("/usr/bin/sv 1 /service/dnscache") ==0
219  +            or warn ("Error service dhcp-dns : can't do sv 1 /service/dnscache");  +            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 158  diff -Nur e-smith-tinydns-2.4.0/root/var Line 224  diff -Nur e-smith-tinydns-2.4.0/root/var
224  +  +
225  +} # end main  +} # end main
226  +###########################################################################  +###########################################################################
227  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  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/root/var/service/dhcp-dns/run 1970-01-01 01:00:00.000000000 +0100  --- e-smith-tinydns-2.4.0.old2388/root/var/service/dhcp-dns/run 1970-01-01 01:00:00.000000000 +0100
229  +++ e-smith-tinydns-2.4.0.bz2388/root/var/service/dhcp-dns/run  2015-01-08 13:33:30.871973834 +0100  +++ e-smith-tinydns-2.4.0.bz2388/root/var/service/dhcp-dns/run  2015-01-27 20:23:29.079882477 +0100
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