--- lib/PXElator/httpd.pm 2009/08/05 13:25:55 149 +++ lib/PXElator/httpd.pm 2009/08/06 18:10:31 162 @@ -17,12 +17,14 @@ use File::Slurp; #use JSON; use IO::Socket::INET; +use Regexp::Common qw/net/; sub menu {qq{
home server +client
}} @@ -47,6 +49,9 @@ use html; our $static_pids; use progress_bar; +use config; +use client; +use log; sub static { my ($client,$path) = @_; @@ -100,7 +105,6 @@ use boolean; -use screen; use kvm; $SIG{CHLD} = 'IGNORE'; @@ -128,10 +132,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"; + exec "xterm -T $daemon -n $daemon -e $exec"; + } else { + my $eval = $daemon . '::' . $invoke . '(' . ( @_ ? dump(@_) : '' ) . ')'; + warn "eval $eval"; + eval $eval; + warn "can't start $daemon: $@" if $@; + } exit; } else { die "fork error $!"; @@ -139,7 +149,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 { @@ -153,10 +163,6 @@ 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 = ( 'debug', qq|$debug|, ); @@ -210,7 +216,6 @@ } print $client $ok - , menu() , html::table( 2, @rows ) , $below_table , html::tabs( log::mac_changes ) @@ -219,15 +224,46 @@ } 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(?:/$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, + '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

| + , qq|| + ; + } } 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(); @@ -235,17 +271,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"; @@ -270,7 +295,9 @@ print "url $url\n"; start_stop 'browser', $url; - start_stop 'screen'; + start_stop 'dhcpd'; + start_stop 'tftpd'; + start_stop 'dnsd'; start_stop 'kvm'; while (1) {