show just hosts in arp
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 5 Jan 2010 00:07:35 +0000 (00:07 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 5 Jan 2010 00:07:35 +0000 (00:07 +0000)
toggle to view all with click on dev column

lib/PXElator/httpd.pm

index a342e83..8cd7085 100644 (file)
@@ -338,6 +338,8 @@ warn "XXX pids = ", dump( $daemons::pids );
 
                } else {
 
+                       print $client ok qq|<h2>Clients on $server::ip</h2>|;
+
                        my @ping;
                        if ( my $host = $param->{ping_target} ) {
                                @ping = ( $host );
@@ -348,33 +350,37 @@ warn "XXX pids = ", dump( $daemons::pids );
                        my $ping = ping::fping( @ping ) if @ping;
                        my $arp = client::arp_mac_dev;
 
-                       print $client ok
-                               , qq|<h2>Clients on $server::ip</h2>|
-                               , html::table( -5,
-                                       'ip', 'mac', 'dev', 'hostname', 'conf',
-                                       map {
-                                               my $ip = $_;
-                                               my $conf = client::all_conf( $ip );
-                                               my $mac = delete $conf->{mac} || '';
-                                               my $style;
-                                               $style
-                                                       = 'style="color:'
-                                                       . ( $ping->{$ip} ? 'green' : 'red' )
-                                                       . '"'
-                                                       if $ping;
-                                               $style ||= '';
-                                               my $ip_text = qq|<tt>$ip</tt>|;
-                                               $ip_text = qq|<tt><b>$ip</b></tt>| if ip::in_dhcp_range($ip);
-                                               (
-                                                       qq|<a $style name=$ip target=client href=/client/$ip>$ip_text</a>|
-                                                       , format::mac( $mac => 'html' )
-                                                       , $arp->{$mac}
-                                                       , delete $conf->{hostname}
-                                                       , html::conf( $ip, $conf, 'inline' )
-                                               )
-                                       } client::all_ips
-                               )
+                       my @clients;
+
+                       foreach my $ip ( client::all_ips ) {
+                               
+                               my $conf = client::all_conf( $ip );
+                               my $mac = delete $conf->{mac} || '';
+
+                               next unless $arp->{$mac} || $param->{all};
+
+                               my $style
+                                       = 'style="color:'
+                                       . ( $ping->{$ip} ? 'green' : 'red' )
+                                       . '"'
+                                       if $ping;
+
+                               $style ||= '';
+                               my $ip_text = qq|<tt>$ip</tt>|;
+                               $ip_text = qq|<tt><b>$ip</b></tt>| if ip::in_dhcp_range($ip);
+
+                               push @clients
+                                       , qq|<a $style name=$ip target=client href=/client/$ip>$ip_text</a>|
+                                       , format::mac( $mac => 'html' )
+                                       , $arp->{$mac}
+                                       , delete $conf->{hostname}
+                                       , html::conf( $ip, $conf, 'inline' )
                                ;
+                       }
+
+                       my $all = $param->{all} ? 0 : 1;
+
+                       print $client html::table( -5, 'ip', 'mac', qq|<a href="?all=$all">dev</a>|, 'hostname', 'conf', @clients );
                        print $client qq|
                                <form method=get>
                                <input type=text   name=ping_target   size=15>