--- lib/PXElator/httpd.pm 2009/08/28 22:29:08 330
+++ lib/PXElator/httpd.pm 2009/08/29 16:51:07 346
@@ -56,6 +56,8 @@
use wireshark;
use syslogd;
use nmap;
+use ping;
+use wol;
use CouchDB;
@@ -224,35 +226,44 @@
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;
}
}
if ( $ip && $ip ne $server::ip ) {
- my $hostname = client::conf( $ip, 'hostname' => $param->{hostname} );
+ my @editable = ( qw/hostname deploy homepage/ );
+
+ client::conf( $ip, $_ => $param->{$_} ) foreach @editable;
+
+ my $conf = client::all_conf( $ip );
+ my $deploy = delete $conf->{deploy};
+
+ my $nmap = qq|nmap|;
my @table = (
'ip' => qq|old: $ip|,
- 'hostname' => qq||,
+ 'mac' => format::mac( delete $conf->{mac}, 'html' ),
+ 'hostname' => qq||,
+ 'ping' => ping::host($ip) ? qq|up $nmap| : qq|down wol $nmap|,
+ 'deploy' => html::select( 'deploy', $deploy, config::available ),
+ html::conf( $ip, $conf, 'edit', @editable )
);
- my $deploy;
+warn "XX conf ",dump( $conf );
- if ( my $mac = client::mac_from_ip( $ip ) ) {
- $deploy = client::conf( $ip, 'deploy' => $param->{deploy} );
- push @table, (
- 'mac' => format::mac( $mac => 'html' ),
- 'deploy' => html::select( 'deploy', $deploy, config::available )
- );
- if ( my $pxelinux = config::for_ip( $ip ) ) {
- $deploy = qq|PXElinux
| . html::pre( $pxelinux );
+ my $config = '';
+
+ if ( $deploy ) {
+ if ( $config = config::for_ip( $ip ) ) {
+ $config = qq|config
| . html::pre( $config );
}
}
@@ -263,7 +274,7 @@
|
- , $deploy
+ , $config
;
if ( my $amt = client::conf( $ip, 'amt' ) ) {
@@ -272,16 +283,20 @@
} 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|Clients on $server::ip
|
- , html::table( -6,
- 'ip', 'mac', 'dev', 'hostname', 'deploy', 'conf',
+ , html::table( -5,
+ 'ip', 'mac', 'dev', 'hostname', 'conf',
map {
my $ip = $_;
my $conf = client::all_conf( $ip );
@@ -292,27 +307,35 @@
. ( $ping->{$ip} ? 'green' : 'red' )
. '"'
if $ping;
+ $style ||= '';
(
qq|$ip|
, format::mac( $mac => 'html' )
, $arp->{$mac}
, delete $conf->{hostname}
- , delete $conf->{deploy}
- , ( %$conf ? html::pre_dump( $conf ) : qq|nmap| )
- );
- } @ips
+ , html::conf( $ip, $conf, 'inline' )
+ )
+ } client::all_ips
)
;
print $client qq|
|;
}
} elsif ( $path =~ m{^/brctl} ) {
- print $client ok
- ,html::pre( `brctl show` )
- ;
+ print $client ok, html::table( -4,
+ map {
+ my @c = split(/\t+/,$_,4);
+ if ( $#c == 1 ) {
+ ( '', '', '', $c[1] )
+ } else {
+ @c
+ }
+ } split(/\n/, `brctl show`)
+ );
} elsif ( $path =~ m{^/ip/?(\w+)?} ) {
print $client ok
, join("\n", map { qq|$_| } ( qw/link addr route neigh ntable tunnel maddr mroute xfrm/ ))
@@ -330,6 +353,8 @@
|;
}
+ } elsif ( $path =~ m{^/wol/(\S+)} ) {
+ print $client redirect( "$url/client/$1" ), wol::power_on($1);
} elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {
eval 'our $' . $1 . ' = ' . $2;
warn $@ if $@;