--- lib/PXElator/httpd.pm 2009/09/10 13:08:36 419 +++ lib/PXElator/httpd.pm 2010/01/23 18:31:14 482 @@ -36,20 +36,6 @@ }} -sub menu { -qq{ -
-home -server -brctl -ip -nmap -client -couchdb -
- -}} - our $port = 7777; use server; @@ -77,7 +63,28 @@ use ping; use wol; -use CouchDB; +use store; + + +sub menu { + my $couch_url = $url; + $couch_url =~ s{:\d+.+}{:5984/_utils/}; +qq{ +
+home +| +server +brctl +ip +| +couchdb +| +nmap +client +
+ +}} + sub static { my ($client,$path) = @_; @@ -110,7 +117,7 @@ my $buff; my $pos = 0; - CouchDB::audit( 'static', { pid => $$, path => $path, type => $type, size => $size, block => $block, peerhost => $client->peerhost }); + store::audit( 'static', { pid => $$, path => $path, type => $type, size => $size, block => $block, peerhost => $client->peerhost }); progress_bar::start; @@ -143,7 +150,7 @@ server->refresh; - CouchDB::audit( 'request', { path => $path, param => $param, peerhost => $client->peerhost } ); + store::audit( 'request', { path => $path, param => $param, peerhost => $client->peerhost } ); $title = $path; @@ -238,7 +245,7 @@ , 'new_clients' => qq|| ); - foreach my $editable ( 'ip', 'netmask', 'ip_from', 'ip_to', 'domain' ) { + foreach my $editable ( 'ip', 'bcast', 'netmask', 'ip_from', 'ip_to', 'domain' ) { my $v = eval '$server::' . $editable; push @table, ( $editable, qq|| ); } @@ -331,6 +338,8 @@ } else { + print $client ok qq|

Clients on $server::ip

|; + my @ping; if ( my $host = $param->{ping_target} ) { @ping = ( $host ); @@ -341,33 +350,40 @@ my $ping = ping::fping( @ping ) if @ping; my $arp = client::arp_mac_dev; - print $client ok - , qq|

Clients on $server::ip

| - , 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|$ip|; - $ip_text = qq|$ip| if ip::in_dhcp_range($ip); - ( - qq|$ip_text| - , 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} || ''; + my $dev = $arp->{$mac}; + + next unless $dev || $param->{all}; + + my $style + = 'style="color:' + . ( $ping->{$ip} ? 'green' : 'red' ) + . '"' + if $ping; + + $style ||= ''; + my $ip_text = qq|$ip|; + $ip_text = qq|$ip| if ip::in_dhcp_range($ip); + + $dev = qq|$dev| if $dev; + + push @clients + , qq|$ip_text| + , format::mac( $mac => 'html' ) + , $dev + , delete $conf->{hostname} + , html::conf( $ip, $conf, 'inline' ) ; + } + + my $all = $param->{all} ? 0 : 1; + + print $client html::table( -5, 'ip', 'mac', qq|dev|, 'hostname', 'conf', @clients ); print $client qq|
@@ -480,7 +496,21 @@ my $client = $server->accept() || next; # ALARM trickle us my $request = <$client>; - warn "request $request\n" if $debug; + my $headers; + + while ( my $header = <$client> ) { + chomp $header; + last if $header =~ m{^\s*$}; + my ( $n, $v ) = split(/:\s*/, $header); + $headers->{ lc $n } = $v; + } + + if ( my $host = $headers->{host} ) { + $url = 'http://' . $host; + $url .= ":$port" unless $url =~ m{:\d+$}; + } + + warn "## $url ## $request", dump( $headers ) if $debug; if ($request =~ m{^GET (/.*) HTTP/1.[01]}) { my $path = $1;