--- lib/PXElator/httpd.pm 2009/08/04 17:16:11 140 +++ lib/PXElator/httpd.pm 2009/08/09 16:37:46 179 @@ -17,6 +17,17 @@ use File::Slurp; #use JSON; use IO::Socket::INET; +use Regexp::Common qw/net/; + +sub menu {qq{ + +
+home +server +client +
+ +}} our $pids; $pids = { httpd => $$ } unless defined $pids; # keep pids on refresh @@ -38,6 +49,10 @@ use html; our $static_pids; use progress_bar; +use config; +use client; +use log; +use x11; sub static { my ($client,$path) = @_; @@ -91,7 +106,6 @@ use boolean; -use screen; use kvm; $SIG{CHLD} = 'IGNORE'; @@ -119,10 +133,16 @@ # child my $invoke = 'start'; $invoke = $1 if $daemon =~ s{/(.+)}{}; - my $eval = $daemon . '::' . $invoke . '(' . ( @_ ? dump(@_) : '' ) . ')'; - warn "eval $eval"; - eval $eval; - warn "can't start $daemon: $@" if $@; + if ( $daemon =~ m{dhcpd|tftpd|dnsd} ) { + my $exec = "perl -I$server::base_dir/lib -I$server::base_dir/lib/PXElator -M$daemon -e ${daemon}::${invoke}"; + warn "exec $exec"; + x11::xterm( $daemon => $exec ); + } else { + my $eval = $daemon . '::' . $invoke . '(' . ( @_ ? dump(@_) : '' ) . ')'; + warn "eval $eval"; + eval $eval; + warn "can't start $daemon: $@" if $@; + } exit; } else { die "fork error $!"; @@ -130,7 +150,7 @@ } } -my $ok = qq|HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n|; +my $ok = qq|HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n| . menu(); my $redirect = qq|HTTP/1.1 302 Found\r\nContent-type: text/html\r\nLocation: $url\r\n\r\n|; sub get_request { @@ -144,14 +164,7 @@ warn "static $found" if $debug; } elsif ( $path eq '/' ) { - my $screen = $pids->{screen} ? qq|stop $pids->{screen}| : 'start'; - my $kvm = $pids->{kvm} ? qq|stop $pids->{kvm}| : - $pids->{screen} ? qq|start| : qq|start screen first|; - my @rows = ( - 'ip', html::tt( $server::ip ), - 'netmask', html::tt( $server::netmask ), - 'debug', qq|$debug|, ); @@ -161,11 +174,12 @@ foreach my $name ( sort keys %$pids ) { my $pid = $pids->{$name} || next; - my $html = qq|$pid|; + my $html; my $proc = "/proc/$pid/status"; if ( -e $proc ) { + $html .= qq|$pid|; if ( $debug ) { $html .= qq| ?|; @@ -183,6 +197,8 @@ if ( $name->can('actions') ) { $html .= qq| $_| foreach $name->actions; } + } else { + $html .= qq|restart $pid exited|; } push @rows, ( $name => $html ); @@ -210,12 +226,48 @@ , $debug_proc ; + } elsif ( $path =~ m{^/server} ) { + print $client $ok + , html::table( 2, map { ( $_, eval '$server::'.$_ ) } ( 'ip', 'netmask', 'ip_from', 'ip_to', 'domain_name', 'base_dir' ) ) + ; + } 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 $deploy = client::conf( $ip, 'deploy' => $param->{deploy} ); + print $client $ok + , qq|
| + , html::table( 2, + 'ip' => $ip, + 'mac' => client::mac( $ip ), + 'hostname' => qq||, + 'deploy' => html::select( 'deploy', $deploy, config::available ), + ) + , qq|
| + , qq|

PXElinux $deploy

|
+				, config::for_ip( $ip )
+				, qq|
| + ; + } else { + print $client $ok + , qq|

Clients on $server::ip

| + , html::table( -4, + 'ip', 'mac', 'hostname', 'deploy', + map { + my $ip = $_; + $ip =~ s{^.+/ip/}{}; + ( qq|$ip|, client::mac($ip), client::conf( $ip, 'hostname' ), client::conf( $ip, 'deploy' ) ); + } + glob("$server::conf/ip/*") + ) + ; + } } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) { eval 'our $' . $1 . ' = ' . $2; warn $@ if $@; print $client $redirect, qq|$1 = $2
Location: $url|; server::debug( $debug ) if $1 eq 'debug'; - } elsif ( $path =~ m{^/start_stop/((?:screen|kvm).*)} ) { # XXX we don't want to stop all classes + } elsif ( $path =~ m{^/start_stop/(\S+)} ) { print $client $redirect, start_stop($1); } elsif ( $path =~ m{^/action/([^/]+)/(.+)} ) { $1->$2(); @@ -223,17 +275,6 @@ } elsif ( $path =~ m{^/kill/static/(\d+)} ) { print $client $redirect; kill 1, $1 || kill 9, $2 && warn "killed $1"; - } elsif ( $path eq '/exit' ) { -# DESTROY; - exit 0; - } elsif ( $path =~ m{/boot} ) { - print $client qq{$ok -#!gpxe -imgfree -login -chain http://$server::ip:$httpd::port/ - - }; } else { print $client "HTTP/1.0 404 $path\r\nConnection: close\r\nContent-type: text/html\r\n\r\n404 $path"; warn "404 $path"; @@ -258,8 +299,10 @@ print "url $url\n"; start_stop 'browser', $url; - start_stop 'screen'; - start_stop 'kvm'; + start_stop 'dhcpd'; + start_stop 'tftpd'; + start_stop 'dnsd'; + start_stop 'kvm' unless $ENV{DEV}; # skip kvm statup when running on real device while (1) { my $client = $server->accept() || next; # ALARM trickle us @@ -283,13 +326,7 @@ warn "500 $request"; } - print $client qq{ -
- reload - index - exit -
- } if $client->connected; + print $client menu() if $client->connected; }