cleanup client detection (again), added ping to single host
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 28 Aug 2009 23:30:38 +0000 (23:30 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 28 Aug 2009 23:30:38 +0000 (23:30 +0000)
lib/PXElator/httpd.pm
lib/PXElator/ping.pm

index f679f02..17e7a7e 100644 (file)
@@ -224,13 +224,14 @@ warn "XXX pids = ", dump( $daemons::pids );
                if ( ! $ip ) {
                        my $peer_ip = $client->peerhost;
 
-                       my $netmask = ip::to_int $server::netmask;
-                       my $network = ip::to_int $server::ip & $netmask;
-                       my ( $from, $to ) = ( $network | $server::ip_from, $network | $server::ip_to );
-                       my $ip_int  = ip::to_int $peer_ip;
+                       my $netmask  = ip::to_int $server::netmask;
+                       my $network  = ip::to_int($server::ip) & $netmask;
+                       my $from_int = $network | $server::ip_from;
+                       my $to_int   = $network | $server::ip_to;
+                       my $ip_int   = ip::to_int $peer_ip;
 
                        # show edit for clients in our dhcp range
-                       if ( $ip_int >= ( $network | $server::ip_from ) && $ip_int <= ( $network | $server::ip_to ) ) {
+                       if ( $ip_int >= $from_int && $ip_int <= $to_int ) {
                                $ip = $peer_ip;
                        }
                }
@@ -272,11 +273,15 @@ warn "XXX pids = ", dump( $daemons::pids );
 
                } else {
 
-                       my $arp = client::arp_mac_dev;
-                       my @ips = client::all_ips;
+                       my @ping;
+                       if ( my $host = $param->{ping_target} ) {
+                               @ping = ( $host );
+                       } elsif ( $param->{ping} ) {
+                               @ping = client::all_ips;
+                       }
 
-                       my $ping;
-                       $ping = ping::fping( @ips ) if $param->{ping};
+                       my $ping = ping::fping( @ping ) if @ping;
+                       my $arp = client::arp_mac_dev;
 
                        print $client ok
                                , qq|<h2>Clients on $server::ip</h2>|
@@ -292,6 +297,7 @@ warn "XXX pids = ", dump( $daemons::pids );
                                                        . ( $ping->{$ip} ? 'green' : 'red' )
                                                        . '"'
                                                        if $ping;
+                                               $style ||= '';
                                                (
                                                        qq|<a $style name=$ip href=/client/$ip>$ip</a>|
                                                        , format::mac( $mac => 'html' )
@@ -300,11 +306,12 @@ warn "XXX pids = ", dump( $daemons::pids );
                                                        , delete $conf->{deploy}
                                                        , ( %$conf ? html::pre_dump( $conf ) : qq|<a href=/nmap?scan=$ip>nmap</a>| )
                                                );
-                                       } @ips
+                                       } client::all_ips
                                )
                                ;
                        print $client qq|
                                <form method=get>
+                               <input type=text   name=ping_target   size=15>
                                <input type=submit name=ping value=ping>
                                </form>
                        |;
index 261decd..801809e 100644 (file)
@@ -36,7 +36,7 @@ sub fping {
                client::conf( $ip => 'hostname', default => $host ) if $host ne $ip;
        }
 
-       warn dump($status);
+       warn "# fping ",dump($status);
 
        return $status;