--- lib/PXElator/httpd.pm 2009/08/11 15:13:19 199 +++ lib/PXElator/httpd.pm 2009/08/30 15:54:30 379 @@ -19,11 +19,31 @@ use IO::Socket::INET; use Regexp::Common qw/net/; -sub menu {qq{ +our $title; +sub html_start { +qq{ + + +$title + + +}} + +sub html_end { +qq{ + + +}} + +sub menu { +qq{
home server +brctl +ip +nmap client
@@ -49,7 +69,14 @@ use kvm; use browser; use network; +use ip; +use wireshark; +use syslogd; +use nmap; +use ping; +use wol; +use CouchDB; sub static { my ($client,$path) = @_; @@ -61,7 +88,6 @@ if ( my $pid = fork ) { # parent close($client); - print "http static child $pid\n"; $static_pids->{$pid} = $path; return 1; } @@ -81,7 +107,7 @@ my $buff; my $pos = 0; - warn "static $path $type $size block: $block\n"; + CouchDB::audit( 'static', { pid => $$, path => $path, type => $type, size => $size, block => $block, peerhost => $client->peerhost }); progress_bar::start; @@ -96,13 +122,11 @@ print STDERR "\n"; - warn "exit static child"; - exit(0); } sub ok { - qq|HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n| . menu() + qq|HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n| . html_start() . menu() } sub redirect { @@ -116,20 +140,22 @@ server->refresh; - warn "get_request $path ", $param ? dump( $param ) : '', "\n"; + CouchDB::audit( 'request', { path => $path, param => $param, peerhost => $client->peerhost } ); + + $title = $path; if ( my $found = static( $client,$path ) ) { warn "static $found" if $debug; } elsif ( $path eq '/' ) { - my @rows = ( - 'debug', qq|$debug|, - ); + my @rows; my $debug_proc = ''; +warn "XXX pids = ", dump( $daemons::pids ); + foreach my $name ( sort keys %$daemons::pids ) { - my $pid = $daemons::pids->{$name} || next; + my $pid = $daemons::pids->{$name}; # || next; my $html; @@ -138,7 +164,7 @@ if ( -e $proc ) { $html .= qq|$pid|; if ( $debug ) { - $html .= qq| ?|; + $html .= qq| ?| if $name->can('start'); $debug_proc .= qq|$proc
|
@@ -147,17 +173,27 @@
 						;
 				}
 
-				if ( $name->can('start_fork') ) {
-					$html .= qq| $_| foreach $name->start_fork;
+				if ( $name->can('fork_if_active') ) {
+					$html .= qq| $_| foreach $name->fork_if_active;
 				}
 
 				if ( $name->can('actions') ) {
-					$html .= qq| $_| foreach $name->actions;
+					$html .= qq| $_| foreach $name->actions;
 				}
 			} else {
-				$html .= qq|restart $pid exited|;
+				if ( $pid =~ m{^\d+$} ) {
+					$html .= qq|$pid exited |
+				} else {
+					$html .= qq|$pid |;
+				}
+				$html .= qq|restart| if $pid || $name->can('start');
+				if ( $name->can('fork_actions') ) {
+					$html .= qq| $_| foreach $name->fork_actions;
+				}
 			}
 
+			die "no html generated" unless $html;
+
 			push @rows, ( $name => $html );
 		}
 
@@ -185,82 +221,159 @@
 
 	} elsif ( $path =~ m{^/server} ) {
 		print $client ok
-			, html::table( 2, map { ( $_, html::tt eval '$server::'.$_ ) } ( 'ip', 'netmask', 'ip_from', 'ip_to', 'domain_name', 'base_dir', 'conf' ) )
+			, html::table( 2,
+				'debug' => qq|$debug|,
+				 map {
+					( $_, html::tt eval '$server::'.$_ )
+				 } ( 'ip', 'netmask', 'ip_from', 'ip_to', 'domain_name', 'base_dir', 'conf' )
+			)
 			;
 	} elsif ( $path =~ m!^/client(?:/$RE{net}{IPv4}{-keep})?! ) {
-		my $ip = $1 || $client->peerhost;
-		if ( $ip ne $server::ip ) {
-			my $hostname = client::conf( $ip, 'hostname' => $param->{hostname} );
+		my $ip = $1;
+		$title = $ip;
 
-			my @table = (
-				'ip' => qq|