diff --git a/config/cfgroot/header.pl b/config/cfgroot/header.pl
index 1046f5992..b5d153a55 100644
--- a/config/cfgroot/header.pl
+++ b/config/cfgroot/header.pl
@@ -403,88 +403,110 @@ sub PrintActualLeases
$tr{'mac address'} |
$tr{'hostname'} |
$tr{'lease expires'} (local time d/m/y) |
-Add to fix leases |
+Add to fix leases |
END
;
open(LEASES,"/var/state/dhcp/dhcpd.leases") or die "Can't open dhcpd.leases";
- while ($line = ) {
- next if( $line =~ /^\s*#/ );
- chomp($line);
- @temp = split (' ', $line);
-
- if ($line =~ /^\s*lease/) {
- $ip = $temp[1];
- #All field are not necessarily read. Clear everything
- $endtime = 0;
- $ether = "";
- $hostname = "";
- }
+ while (my $line = ) {
+ next if( $line =~ /^\s*#/ );
+ chomp($line);
+ @temp = split (' ', $line);
+
+ if ($line =~ /^\s*lease/) {
+ $ip = $temp[1];
+ #All field are not necessarily read. Clear everything
+ $endtime = 0;
+ $endtime_print = "";
+ $expired = 0;
+ $ether = "";
+ $hostname = "";
+ }
- if ($line =~ /^\s*ends/) {
- $line =~ /(\d+)\/(\d+)\/(\d+) (\d+):(\d+):(\d+)/;
- $endtime = timegm($6, $5, $4, $3, $2 - 1, $1 - 1900);
- }
+ if ($line =~ /^\s*ends/) {
+ $line =~ /(\d+)\/(\d+)\/(\d+) (\d+):(\d+):(\d+)/;
+ $endtime = timegm($6, $5, $4, $3, $2 - 1, $1 - 1900);
+ ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime($endtime);
+ $endtime_print = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);
+ $expired = $endtime < time();
+ }
- if ($line =~ /^\s*hardware ethernet/) {
- $ether = $temp[2];
- $ether =~ s/;//g;
- }
+ if ($line =~ /^\s*hardware ethernet/) {
+ $ether = $temp[2];
+ $ether =~ s/;//g;
+ }
- if ($line =~ /^\s*client-hostname/) {
- $hostname = "$temp[1] $temp[2] $temp[3]";
- $hostname =~ s/;//g;
- $hostname =~ s/\"//g;
- }
+ if ($line =~ /^\s*client-hostname/) {
+ $hostname = "$temp[1] $temp[2] $temp[3]";
+ $hostname =~ s/;//g;
+ $hostname =~ s/\"//g;
+ }
- if ($line eq "}") {
- @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname);
- $record = {}; # create a reference to empty hash
- %{$record} = @record; # populate that hash with @record
- $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
- }
+ if ($line eq "}") {
+ @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname,'endtime_print',$endtime_print,'expired',$expired);
+ $record = {}; # create a reference to empty hash
+ %{$record} = @record; # populate that hash with @record
+ $entries{$record->{'IPADDR'}} = $record; # add this to a hash of hashes
+ }
}
close(LEASES);
my $id = 0;
- my $col="";
+ my $col = "";
+ my $separator_printed = 0;
foreach my $key (sort leasesort keys %entries) {
- print "
END
-;
- $id++;
- }
+;
+ $id++;
+ }
print "";
&closebox();
@@ -499,11 +521,14 @@ sub leasesort {
if ($qs eq 'IPADDR') {
@a = split(/\./,$entries{$a}->{$qs});
@b = split(/\./,$entries{$b}->{$qs});
+ $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} ||
($b[0]<=>$a[0]) ||
($b[1]<=>$a[1]) ||
($b[2]<=>$a[2]) ||
($b[3]<=>$a[3]);
- }else {
+ ;
+ } else {
+ $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} ||
$entries{$b}->{$qs} cmp $entries{$a}->{$qs};
}
}
@@ -511,15 +536,17 @@ sub leasesort {
{
$qs=$dhcpsettings{'SORT_LEASELIST'};
if ($qs eq 'IPADDR') {
- @a = split(/\./,$entries{$a}->{$qs});
+ @a = split(/\./,$entries{$a}->{$qs});
@b = split(/\./,$entries{$b}->{$qs});
+ $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} ||
($a[0]<=>$b[0]) ||
- ($a[1]<=>$b[1]) ||
- ($a[2]<=>$b[2]) ||
+ ($a[1]<=>$b[1]) ||
+ ($a[2]<=>$b[2]) ||
($a[3]<=>$b[3]);
- }else {
+ } else {
+ $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} ||
$entries{$a}->{$qs} cmp $entries{$b}->{$qs};
- }
+ }
}
}