From c27b8825beeed2f45b5c6caa507363982675bd10 Mon Sep 17 00:00:00 2001 From: Leo-Andres Hofmann Date: Wed, 21 Oct 2020 12:48:33 +0100 Subject: [PATCH] Improve DHCP dynamic leases list usability. Active and expired leases are now grouped and the list is divided by a horizontal line. Sorting and creating static leases remains unchanged. Signed-off-by: Leo-Andres Hofmann Signed-off-by: Michael Tremer --- config/cfgroot/header.pl | 66 +++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/config/cfgroot/header.pl b/config/cfgroot/header.pl index 6322cfebef..e2e6fd6892 100644 --- a/config/cfgroot/header.pl +++ b/config/cfgroot/header.pl @@ -418,6 +418,8 @@ END $ip = $temp[1]; #All field are not necessarily read. Clear everything $endtime = 0; + $endtime_print = ""; + $expired = 0; $ether = ""; $hostname = ""; } @@ -425,6 +427,9 @@ END 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/) { @@ -434,12 +439,11 @@ END if ($line =~ /^\s*client-hostname/) { $hostname = "$temp[1] $temp[2] $temp[3]"; - $hostname =~ s/;//g; - $hostname =~ s/\"//g; + $hostname =~ s/\"|[;\s]+?$//g; # remove quotes, trim semicolon and white space } if ($line eq "}") { - @record = ('IPADDR',$ip,'ENDTIME',$endtime,'ETHER',$ether,'HOSTNAME',$hostname); + @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 @@ -449,37 +453,53 @@ END my $id = 0; my $col = ""; + my $divider_printed = 0; foreach my $key (sort leasesort keys %entries) { - print "
\n"; my $hostname = &cleanhtml($entries{$key}->{HOSTNAME},"y"); - + my $hostname_print = $hostname; + if($hostname_print eq "") { #print blank space if no hostname is found + $hostname_print = "   "; + } + + # separate active and expired leases with a horizontal line + if(($entries{$key}->{expired}) && ($divider_printed == 0)) { + $divider_printed = 1; + if ($id % 2) { + print "
\n"; + } else { + print "
\n"; + } + $id++; + } + + print "\n"; if ($id % 2) { - print ""; $col="bgcolor='$table1colour'"; } else { - print ""; $col="bgcolor='$table2colour'"; } - - print <{expired}) { + print <$entries{$key}->{IPADDR} +$entries{$key}->{ETHER} +$hostname_print +$entries{$key}->{endtime_print} +END +; + } else { + print <$entries{$key}->{IPADDR} $entries{$key}->{ETHER} - $hostname - +$hostname_print +$entries{$key}->{endtime_print} END ; - - ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime ($entries{$key}->{ENDTIME}); - $enddate = sprintf ("%02d/%02d/%d %02d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec); - - if ($entries{$key}->{ENDTIME} < time() ){ - print "$enddate"; - } else { - print "$enddate"; } + print < - + + END ; $id++; @@ -498,11 +518,13 @@ sub leasesort { if ($qs eq 'IPADDR') { @a = split(/\./,$entries{$a}->{$qs}); @b = split(/\./,$entries{$b}->{$qs}); + $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} || # always sort by expiration first ($b[0]<=>$a[0]) || ($b[1]<=>$a[1]) || ($b[2]<=>$a[2]) || ($b[3]<=>$a[3]); } else { + $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} || $entries{$b}->{$qs} cmp $entries{$a}->{$qs}; } } @@ -512,11 +534,13 @@ sub leasesort { if ($qs eq 'IPADDR') { @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[3]<=>$b[3]); } else { + $entries{$a}->{'expired'} <=> $entries{$b}->{'expired'} || $entries{$a}->{$qs} cmp $entries{$b}->{$qs}; } } -- 2.39.2