/[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.5 by stephdl, Sat Jan 17 18:17:09 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-17 18:02:35.489764844 +0100  +++ e-smith-tinydns-2.4.0.bz2388/createlinks    2015-01-27 20:23:29.080882560 +0100
4  @@ -26,3 +26,19 @@  @@ -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");
# Line 21  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-16 20:02:12.050969025 +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-16 20:02:12.050969025 +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-17 19:02:21.779342484 +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,107 @@  @@ -0,0 +1,136 @@
38  +{  +{
39  +    use strict;  +    use strict;
40  +    use warnings;  +    use warnings;
41  +    use esmith::Logger;  +    use esmith::Logger;
42  +    use esmith::ConfigDB;  +    use esmith::ConfigDB;
43  +    # we need perl-Time-TAI64 for timestamp conversion  +    use esmith::HostsDB;
44  +    use Time::TAI64 qw /unixtai64/;  +    use Time::TAI64 qw /unixtai64/;
 +    # we need perl-Date-Manip to convert to a unix timestamp  
45  +    use Date::Manip qw /UnixDate/;  +    use Date::Manip qw /UnixDate/;
46  +    use File::Copy;  +    use File::Copy;
47  +  +
48  +    my $DB = esmith::ConfigDB->open_ro or die ("cannot open configuration database");  +    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  +    #we start a hash for name because we don't want several same names & ip  +    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 = ();  +    my %allocated_name = ();
56  +    my %allocated_ip_dhcplease = ();  +    my %allocated_ip_dhcplease = ();
57  +  +
58  +    # copy of dhcpd.leases file to /tmp because working directly on the original  +    #start a hash of all hosts in DB
59  +    # is not a good idea  +    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")  +    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");  +        or die ("Error dhcp-dns Service : Unable to copy the /var/lib/dhcpd/dhcpd.leases");
66  +  +
67  +   #we create a fonction because we want to write in log  +    #we want to write in log
68  +   sub log2messages  +    sub log2messages
69  +   {  +    {
70  +       my $message = shift;  +        my $message = shift;
71  +       tie *FH, 'esmith::Logger';  +        tie *FH, 'esmith::Logger';
72  +       print FH "$message";  +        print FH "$message";
73  +       close FH;  +        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  +   #Text::DHCPparse forked because it doesn't allow to retrieve the end of lease  +        while (<FILE>)
85  +   #Only the start is found by the leaseparse of DHCPparse.pm s/starts/ends  +        {
86  +   sub leaseparse {  +            next if /^#|^$/;
87  +   my $logfile = shift;  +            if (/^lease (\d+\.\d+\.\d+\.\d+)/)
88  +   my ( %list, $ip );  +            {
89  +   open FILE, $logfile or die;  +                $ip = $1;
90  +  +                $list{$ip} = sprintf("%-17s", $ip);
91  +   while (<FILE>) {  +            }
92  +      next if /^#|^$/;  +            /^\s*hardware ethernet (.*);/ && ($list{$ip} .= sprintf("%-19s", $1));
93  +      if (/^lease (\d+\.\d+\.\d+\.\d+)/) {  +            /^\s*ends \d (.*);/ && ($list{$ip} .= sprintf("%-21s", $1));
94  +         $ip = $1;  +            /^\s*(abandoned).*/ && ($list{$ip} .= sprintf("%-19s", $1));
95  +         $list{$ip} = sprintf("%-17s", $ip);  +            /^\s*client-hostname "(.*)";/ && ($list{$ip} .= sprintf("%-17s", $1));
96  +      }  +        }
 +      /^\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));  
 +   }  
97  +  +
98  +   close FILE;  +        close FILE;
99  +  +
100  +   # make all entries 74 characters long to format properly  +        # make all entries 74 characters long to format properly
101  +   foreach (keys %list) {  +        foreach (keys %list)
102  +      #$list{$_} = sprintf("%-74s", $list{$_}) if (length$list{$_} < 76);  +        {
103  +      $list{$_} = sprintf("%-74.74s", $list{$_});  +            $list{$_} = sprintf("%-74s", $list{$_}) if (length$list{$_} < 76);
104  +   }  +        }
105  +  +
106  +   return \%list;  +       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  +    my $return = leaseparse('/tmp/tmpdhcpd.leases');  +    my $return = leaseparse('/tmp/tmpdhcpd.leases');
139  +    my ($ip,$time,$mac,$name);  +    my ($ip,$time,$mac,$name);
140  +  +
141  +    # variable with local domain value (default is  mycompamy.local) and retrieve the server name  +    # retrieve the local domain name
142  +    my $localdomain = $DB->get_value('DomainName') or die ("Unable retrieve the DomainName property");  +    my $localdomain = $DB->get_value('DomainName') or die ("Unable retrieve the DomainName property");
 +    my $servername  = $DB->get_value('SystemName') or die ("Unable retrieve the SystemName 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  +        # when the dhcp lease is over $name is empty .. we want only non empty one  +        # we skip allocated ips & empty names
151  +        if ( $name ne "" )  +        unless ((exists $allocated_ip_dhcplease{$ip}) || ( $name eq "" ))
152  +        {  +        {
153  +            # we skip also ips & names already allocated  +            # Convert lease end time to the format expected as
154  +            unless (exists $allocated_ip_dhcplease{$ip} || exists $allocated_name{$name})  +            # see:  http://cr.yp.to/djbdns/tinydns-data.html
155  +            {  +            my $ts = UnixDate($time, "%s");
156  +                # Convert lease end time to the format expected as  +            my $endtai = unixtai64($ts);
157  +                # see:  http://cr.yp.to/djbdns/tinydns-data.html  +            $endtai =~ s/@//;
158  +                my $ts = UnixDate($time, "%s");  +
159  +                my $endtai = unixtai64($ts);  +            # Determine TTL
160  +                $endtai =~ s/@//;  +            my $ttl = '';
161  +  +            $ttl = 0 unless ($ts <= time);
 +                # Determine TTL  
 +                my $ttl = '';  
 +                $ttl = 0 unless ($ts <= time);  
 +                $OUT .= "=$name.$localdomain:$ip:$ttl:$endtai\n" unless ($name eq $servername);  
 +                log2messages("The hostname of this server ($servername) is used with different IP in /var/lib/dhcpd/dhcpd.leases")    
 +                    if ($name eq $servername);  
 +            }  
162  +  +
163  +            $allocated_ip_dhcplease{$ip} = 1;  +            # display if the hostname is valid
164  +            $allocated_name{$name} ++;  +            $OUT .= "=$name.$localdomain:$ip:$ttl:$endtai\n" if (namevalidator("$name") ne '1');
 +  
 +            log2messages("The hostname \"$name\" is duplicated with different IP in /var/lib/dhcpd/dhcpd.leases")    
 +                if ($allocated_name{$name} >1);  
165  +        }  +        }
166    +
167    +        $allocated_ip_dhcplease{$ip} = 1;
168    +        $allocated_name{$name} ++;
169  +    }  +    }
170  +    # remove the temp file  +    # remove the temp file
171  +    unlink "/tmp/tmpdhcpd.leases"  +    unlink "/tmp/tmpdhcpd.leases"
172  +      or log2messages("Error dhcp-dns Service : Unable to remove 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.old2388/root/var/service/dhcp-dns/dhcp-dns e-smith-tinydns-2.4.0.bz2388/root/var/service/dhcp-dns/dhcp-dns
175  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  --- 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    1970-01-01 01:00:00.000000000 +0100  +++ e-smith-tinydns-2.4.0.bz2388/root/var/service/dhcp-dns/dhcp-dns     2015-01-28 00:24:48.209462754 +0100
177  +++ e-smith-tinydns-2.4.0.bz2388/root/var/service/dhcp-dns/dhcp-dns     2015-01-17 18:06:32.318810671 +0100  @@ -0,0 +1,49 @@
 @@ -0,0 +1,45 @@  
178  +#!/usr/bin/perl  +#!/usr/bin/perl
179  +use strict;  +use strict;
180  +use warnings;  +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 158  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 create a function because we want to write in log  +#we want to write in log
195  +sub log2messages  +sub log2messages
196  +   {  +   {
197  +        my $message = shift;  +        my $message = shift;
# Line 169  diff -Nur e-smith-tinydns-2.4.0/root/var Line 202  diff -Nur e-smith-tinydns-2.4.0/root/var
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 191  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-16 20:02:12.055969339 +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