From patchwork Wed Oct 21 11:48:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo-Andres Hofmann X-Patchwork-Id: 3592 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4CGS020pJjz3wgF for ; Wed, 21 Oct 2020 10:48:34 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4CGS00539YzJj; Wed, 21 Oct 2020 10:48:32 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4CGS003D1Tz2xyS; Wed, 21 Oct 2020 10:48:32 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4CGRzz00V9z2xbW for ; Wed, 21 Oct 2020 10:48:30 +0000 (UTC) Received: from mirfac.uberspace.de (mirfac.uberspace.de [185.26.156.40]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPS id 4CGRzy0lp7zJj for ; Wed, 21 Oct 2020 10:48:30 +0000 (UTC) Received: (qmail 23749 invoked from network); 21 Oct 2020 10:48:29 -0000 Received: from localhost (HELO suhail.uberspace.de) (127.0.0.1) by mirfac.uberspace.de with SMTP; 21 Oct 2020 10:48:29 -0000 Received: (qmail 22150 invoked from network); 21 Oct 2020 10:48:28 -0000 Received: from localhost (HELO Leo-Laptop.local) (127.0.0.1) by suhail.uberspace.de with SMTP; 21 Oct 2020 10:48:28 -0000 Date: Wen, 21 Oct 2020 12:48:30 +0100 From: Leo-Andres Hofmann To: development@lists.ipfire.org Subject: [PATCH 1/2] Improve indentation and HTML output of PrintActualLeases & leasesort Message-ID: <7eb80482-9fa4-4c80-a042-f55d25cf869c@Leo-Laptop.local> X-Mailer: TortoiseGit MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1603277310; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jNEcChmpREbDbkg9M2Qly3zF3WDcXRLYNj7I7sCrFpM=; b=Rz5FuEZSn/S8PlmS7mO4xcY2nqCMCzhKHGCE1tj3nbwPsMwKwD6c2SB7dqiG+GeevT9ZrU ga337t0duRPDt0dtxekurccjN8ibEEv0BN8MaDBfqjp6/dhfhwwT5T/w+awQf8Srs7/FAd QWEzcWkzL84KpjCgCyVKOdkfwD4QGFFrhOWNwV87w+DdIYkAubhnHjSqwcubQnCoghfCrj G+DM+I6ZDsqibmSxXGf+IW5/MlGzpgxXqMgn7dro59Y3TqmD+NB4IbxDsCoyNYcJ8W+guo m/4QAXKl8Pi4Hv9rVzgq79XovhEPeu5gl8mX+QGYhGw+dFWfIadfZQGtFmjhAw== ARC-Seal: i=1; s=202003rsa; d=lists.ipfire.org; t=1603277310; a=rsa-sha256; cv=none; b=ZMBeAIut4+pcjvCkHA1bvZFQrpv9kTt0Auq4t+QRP3JOFLeNl0effD8e2uNsRNJI+X7Zmw D9ym+pjFOmVhfzDBaAjmRl/24vkWfqdLBtEIfN46QCL4GxGkEkEVNtO7fr1mmaBKzAK9eK +hpHH6r5NdVS/4Hpgx3yOyTtioWeoe480BFpsk1IRyyJlcldJBUwJyi0SNgt1TafUh21Sj 3ObSuqkBtFO8xxwo54fC9315Juw/0Rq0DBNFMKAg4qm1OEBKuKrt4FkPQkSeqfVmU3yz72 BvPKY5YQBuRvIpNW1lzd9RwvNrIRcDN0As6gbz9Liy+w9MCs4MX2ZJtmvP/SiQ== ARC-Authentication-Results: i=1; mail01.ipfire.org; dkim=none; spf=softfail (mail01.ipfire.org: 185.26.156.40 is neither permitted nor denied by domain of hofmann@leo-andres.de) smtp.mailfrom=hofmann@leo-andres.de X-Rspamd-Queue-Id: 4CGRzy0lp7zJj X-Spamd-Result: default: False [-0.60 / 11.00]; ARC_NA(0.00)[]; XM_UA_NO_VERSION(0.01)[]; FROM_HAS_DN(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; ARC_SIGNED(0.00)[lists.ipfire.org:s=202003rsa:i=1]; R_SPF_SOFTFAIL(0.00)[~all]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_THREE(0.00)[3]; DMARC_NA(0.00)[leo-andres.de]; IP_REPUTATION_HAM(-0.01)[asn: 205766(0.00), country: DE(-0.00), ip: 185.26.156.40(0.00)]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:205766, ipnet:185.26.156.0/24, country:DE]; RCVD_TLS_LAST(0.00)[]; BAYES_HAM(-3.00)[99.99%] Authentication-Results: mail01.ipfire.org; dkim=none; dmarc=none; spf=softfail (mail01.ipfire.org: 185.26.156.40 is neither permitted nor denied by domain of hofmann@leo-andres.de) smtp.mailfrom=hofmann@leo-andres.de X-Rspamd-Server: mail01.haj.ipfire.org X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Signed-off-by: Leo-Andres Hofmann --- config/cfgroot/header.pl | 159 +++++++++++++++++++-------------------- 1 file changed, 79 insertions(+), 80 deletions(-) diff --git a/config/cfgroot/header.pl b/config/cfgroot/header.pl index 1046f5992..6322cfebe 100644 --- a/config/cfgroot/header.pl +++ b/config/cfgroot/header.pl @@ -403,66 +403,65 @@ 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; + $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); + } - 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); + $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 = ""; foreach my $key (sort leasesort keys %entries) { - print "
\n"; - my $hostname = &cleanhtml($entries{$key}->{HOSTNAME},"y"); + print "\n"; + my $hostname = &cleanhtml($entries{$key}->{HOSTNAME},"y"); - if ($id % 2) { - print ""; - $col="bgcolor='$table1colour'"; - } - else { - print ""; - $col="bgcolor='$table2colour'"; - } + if ($id % 2) { + print ""; + $col="bgcolor='$table1colour'"; + } else { + print ""; + $col="bgcolor='$table2colour'"; + } - print <$entries{$key}->{IPADDR} $entries{$key}->{ETHER}  $hostname @@ -470,20 +469,20 @@ END 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); + ($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 <{ENDTIME} < time() ){ + print "$enddate"; + } else { + print "$enddate"; + } + print < END ; - $id++; + $id++; } print ""; @@ -493,34 +492,34 @@ END # This sub is used during display of actives leases sub leasesort { - if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1) - { - $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3); - if ($qs eq 'IPADDR') { - @a = split(/\./,$entries{$a}->{$qs}); - @b = split(/\./,$entries{$b}->{$qs}); - ($b[0]<=>$a[0]) || - ($b[1]<=>$a[1]) || - ($b[2]<=>$a[2]) || - ($b[3]<=>$a[3]); - }else { - $entries{$b}->{$qs} cmp $entries{$a}->{$qs}; - } - } - else #not reverse - { - $qs=$dhcpsettings{'SORT_LEASELIST'}; - if ($qs eq 'IPADDR') { - @a = split(/\./,$entries{$a}->{$qs}); - @b = split(/\./,$entries{$b}->{$qs}); - ($a[0]<=>$b[0]) || - ($a[1]<=>$b[1]) || - ($a[2]<=>$b[2]) || - ($a[3]<=>$b[3]); - }else { - $entries{$a}->{$qs} cmp $entries{$b}->{$qs}; + if (rindex ($dhcpsettings{'SORT_LEASELIST'},'Rev') != -1) + { + $qs=substr ($dhcpsettings{'SORT_LEASELIST'},0,length($dhcpsettings{'SORT_LEASELIST'})-3); + if ($qs eq 'IPADDR') { + @a = split(/\./,$entries{$a}->{$qs}); + @b = split(/\./,$entries{$b}->{$qs}); + ($b[0]<=>$a[0]) || + ($b[1]<=>$a[1]) || + ($b[2]<=>$a[2]) || + ($b[3]<=>$a[3]); + } else { + $entries{$b}->{$qs} cmp $entries{$a}->{$qs}; + } + } + else #not reverse + { + $qs=$dhcpsettings{'SORT_LEASELIST'}; + if ($qs eq 'IPADDR') { + @a = split(/\./,$entries{$a}->{$qs}); + @b = split(/\./,$entries{$b}->{$qs}); + ($a[0]<=>$b[0]) || + ($a[1]<=>$b[1]) || + ($a[2]<=>$b[2]) || + ($a[3]<=>$b[3]); + } else { + $entries{$a}->{$qs} cmp $entries{$b}->{$qs}; + } } - } } sub colorize { From patchwork Wed Oct 21 11:48:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo-Andres Hofmann X-Patchwork-Id: 3593 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4CGS032tdRz3wgF for ; Wed, 21 Oct 2020 10:48:35 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4CGS024v6Vz18G; Wed, 21 Oct 2020 10:48:34 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4CGS024Gn2z2xxj; Wed, 21 Oct 2020 10:48:34 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4CGS0131VPz2xbW for ; Wed, 21 Oct 2020 10:48:33 +0000 (UTC) Received: from mirfac.uberspace.de (mirfac.uberspace.de [185.26.156.40]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPS id 4CGS011pB4z11D for ; Wed, 21 Oct 2020 10:48:33 +0000 (UTC) Received: (qmail 23768 invoked from network); 21 Oct 2020 10:48:33 -0000 Received: from localhost (HELO suhail.uberspace.de) (127.0.0.1) by mirfac.uberspace.de with SMTP; 21 Oct 2020 10:48:33 -0000 Received: (qmail 22622 invoked from network); 21 Oct 2020 10:48:30 -0000 Received: from localhost (HELO Leo-Laptop.local) (127.0.0.1) by suhail.uberspace.de with SMTP; 21 Oct 2020 10:48:30 -0000 Date: Wen, 21 Oct 2020 12:48:33 +0100 From: Leo-Andres Hofmann To: development@lists.ipfire.org Subject: [PATCH 2/2] 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. Message-ID: <2d983761-437b-4b08-9638-06f57f560fb5@Leo-Laptop.local> X-Mailer: TortoiseGit MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1603277313; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=g+Vcsu9GCrVKO9MH5TbgW7H702WUTVI1DdAdP3eYElg=; b=llCnxRb7VGE1Y1abDX+/8A5NCFwo4+dlgXYpDQByf82rEbZxPkabtT2OnXEO6QeDOeBr1S 16iUOWtV342Jryf8WXVePDDjQU9jw5WnrNzjrx52k3CfNGznllDLwKmdgnHfjOHpuwMcdV DudWhzSKjKJ8ymqadk5j8HdwBCH0PvdBQNjFcsQu378t/62/YFMhouxiKf9UJkOTWjS6ii R7MlVPDd4fbU+EeSycOAffkdP0VvP96eubPO5yTKjmfYuCR3eYuCK3eedQ85F5+cDmw2A8 Vl6W+L6HGvPt8Vv2wTIF/nc3YBTNw6D/7Ol/X9N+zvkHRwMGgi6G7gfdwRYc4Q== ARC-Seal: i=1; s=202003rsa; d=lists.ipfire.org; t=1603277313; a=rsa-sha256; cv=none; b=ClB+yB5wGOouQ+ddhWCX4NnKdtixMuQNuem0qeBkhlRpJh7A8kJgqJTEMv9oL+gwPrybWg gOl3rlh29NM3ixZJ3ipA4B8iiyNOBTveOqxmiOKSB19AiMAz7lcP1r9N0NDBPGEfqQtODe oWSlVQYAZY7inHqhczx33MmomNgZ4uD08aeecN6fqKWTDsEAIdA9eBvR4ENn5Lg3pfiro5 C9wnA5cBlYltsLpMTwy+dudGKO7kf+IIYedwcaMceDzxABGRNWl2FM0DEZ9lfY10SxJihN 3Z9527GwTtK3J1T5atfHxfXIp5HrKzuZZ2n9FLkjCJ5j43hLW2c/X0acFg/XsA== ARC-Authentication-Results: i=1; mail01.ipfire.org; dkim=none; spf=softfail (mail01.ipfire.org: 185.26.156.40 is neither permitted nor denied by domain of hofmann@leo-andres.de) smtp.mailfrom=hofmann@leo-andres.de X-Rspamd-Queue-Id: 4CGS011pB4z11D X-Spamd-Result: default: False [-0.60 / 11.00]; ARC_NA(0.00)[]; XM_UA_NO_VERSION(0.01)[]; FROM_HAS_DN(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; ARC_SIGNED(0.00)[lists.ipfire.org:s=202003rsa:i=1]; R_SPF_SOFTFAIL(0.00)[~all:c]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_THREE(0.00)[3]; DMARC_NA(0.00)[leo-andres.de]; IP_REPUTATION_HAM(-0.01)[asn: 205766(0.00), country: DE(-0.00), ip: 185.26.156.40(0.00)]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:205766, ipnet:185.26.156.0/24, country:DE]; RCVD_TLS_LAST(0.00)[]; BAYES_HAM(-3.00)[99.99%] Authentication-Results: mail01.ipfire.org; dkim=none; dmarc=none; spf=softfail (mail01.ipfire.org: 185.26.156.40 is neither permitted nor denied by domain of hofmann@leo-andres.de) smtp.mailfrom=hofmann@leo-andres.de X-Rspamd-Server: mail01.haj.ipfire.org X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Signed-off-by: Leo-Andres Hofmann --- 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 6322cfebe..e2e6fd689 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}; } }