--- lib/PXElator/httpd.pm 2009/08/01 00:44:52 107 +++ lib/PXElator/httpd.pm 2009/08/05 23:22:17 153 @@ -17,7 +17,16 @@ use File::Slurp; #use JSON; use IO::Socket::INET; -use Module::Refresh; + +sub menu {qq{ + +
+home +server +client +
+ +}} our $pids; $pids = { httpd => $$ } unless defined $pids; # keep pids on refresh @@ -38,8 +47,8 @@ use html; our $static_pids; - -use Time::HiRes qw/time/; +use progress_bar; +use config; sub static { my ($client,$path) = @_; @@ -71,26 +80,15 @@ my $buff; my $pos = 0; - STDERR->autoflush(1); warn "static $path $type $size block: $block\n"; - my $start_t = time(); - my $last_t = $start_t; + progress_bar::start; while( my $len = read $fh, $buff, $block ) { print $client $buff; $client->flush; $pos += $len; - my $t = time(); - next unless $t - $last_t > 0.75; - $last_t = $t; - my $speed = ( $pos ) / ( $t - $start_t ); - printf STDERR "%s %d/%d %.2f%% %.2f K/s ETA %.1fs \r" - , $path, $pos - , $size, $pos * 100 / $size - , $speed / 1024 - , ( $size - $pos ) / $speed - ; + progress_bar::tick( $path, $pos, $size ); } close($fh); close($client); @@ -111,7 +109,7 @@ sub start_stop { my $daemon = shift; - my $pid = $pids->{$daemon}; + my $pid = $pids->{$daemon} || 'not started'; warn "start_stop $daemon $pid\n"; @@ -149,6 +147,8 @@ sub get_request { my ( $client, $path, $param ) = @_; + server->refresh; + warn "get_request $path ", $param ? dump( $param ) : '', "\n"; if ( my $found = static( $client,$path ) ) { @@ -160,9 +160,6 @@ $pids->{screen} ? qq|start| : qq|start screen first|; my @rows = ( - 'ip', html::tt( $server::ip ), - 'netmask', html::tt( $server::netmask ), - 'debug', qq|$debug|, ); @@ -215,12 +212,34 @@ } print $client $ok + , menu() , html::table( 2, @rows ) , $below_table , html::tabs( log::mac_changes ) , $debug_proc ; + } elsif ( $path =~ m{^/server} ) { + print $client $ok + , menu() + , html::table( 2, map { ( $_, eval '$server::'.$_ ) } ( 'ip', 'netmask', 'ip_from', 'ip_to', 'domain_name', 'base_dir' ) ) + ; + } elsif ( $path =~ m{^/client} ) { + my $ip = $client->peerhost; + my $hostname = server::shared( "hostname/$ip", $param->{hostname} ); + my $deploy = server::shared( "deploy/$ip", $param->{deploy} ); + print $client $ok + , menu() + , qq|
| + , html::table( 2, + 'ip' => $ip, + 'hostname' => qq||, + 'deploy' => html::select( 'deploy', $deploy, config::available ), + ) + , qq|
|
+			, config::for_ip( $ip )
+			, qq|
| + ; } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) { eval 'our $' . $1 . ' = ' . $2; warn $@ if $@; @@ -253,9 +272,12 @@ } use browser; +use network; sub start { + warn 'tap ', network::tap(); + my $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $httpd::port, @@ -269,14 +291,12 @@ start_stop 'screen'; start_stop 'kvm'; - while (my $client = $server->accept()) { - $client->autoflush(1); + while (1) { + my $client = $server->accept() || next; # ALARM trickle us my $request = <$client>; warn "request $request\n" if $debug; - Module::Refresh->refresh; - if ($request =~ m{^GET (/.*) HTTP/1.[01]}) { my $path = $1; my $param; @@ -293,13 +313,7 @@ warn "500 $request"; } - print $client qq{ -
- reload - index - exit -
- } if $client->connected; + print $client menu() if $client->connected; }