use Net::DHCP::Constants 0.67;
use server;
+my $debug = server::debug;
use pxe;
-my $debug = 1;
-
if ( ! $server::ip ) {
my $server_ip = `/sbin/ifconfig`;
$server_ip =~ s/^.+?addr:([\d\.]+).*$/$1/gs;
my $dhcp = Net::DHCP::Packet->new($buf);
$dhcp->comment( $transaction++ );
- warn "recv: ", $dhcp->toString;
+ warn "recv: ", $dhcp->toString if $debug;
my $mac = substr($dhcp->chaddr(),0,$dhcp->hlen()*2);
my $ip = client_ip($mac);
warn ">> $mac == $ip server: $server::ip", $pxe::file ? " pxe file: $pxe::file\n" : "\n";
$packet = new Net::DHCP::Packet( %$packet );
- warn "## ",$packet->toString(),"\n" if $debug;
+ warn "send ",$packet->toString() if $debug;
my $reply = IO::Socket::INET->new(
LocalAddr => $server::ip,
}
our $port = 7777;
-our $debug = 0;
use server;
+our $debug = server::debug;
our $url = "http://$server::ip:$port";
use html;
return $path;
}
-my $ok = "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n";
-
use boolean;
use screen;
my $daemon = shift;
my $pid = $pids->{$daemon};
- warn "start_stop $daemon pids: ",dump( $pids );
+ warn "start_stop $daemon $pid pids: ",dump( $pids );
- if ( $pid ) {
+ if ( $pid =~ m{^\d+$} ) {
warn "kill 9 $pid";
kill 9, $pid;
$pids->{$daemon} = 'stopped';
return qq|$daemon pid $pid started|;
} elsif ( defined $pid ) {
# child
- my $eval = $daemon . '::start(' . dump(@_) . ')';
+ my $eval = $daemon . '::start(' . ( @_ ? dump(@_) : '' ) . ')';
warn "eval $eval";
eval $eval;
warn "can't start $daemon: $@" if $@;
}
}
+my $ok = qq|HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n|;
+my $redirect = qq|HTTP/1.1 302 Found\r\nContent-type: text/html\r\nLocation: $url\r\n\r\n|;
+
sub get_request {
my ( $client, $path, $param ) = @_;
);
foreach my $name ( %$pids ) {
my $pid = $pids->{$name} || next;
+ my $proc = "/proc/$pid/status";
my $html = qq|<a href=/$name>$pid</a>|;
$html .= qq|<pre style="font-size: 10%">|
- . ( $debug ? read_file("/proc/$pid/status") : '' )
+ . ( $debug && -e $proc ? read_file($proc) : '' )
. qq|</pre>| if $debug;
push @rows, ( $name => $html );
} elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {
eval 'our $' . $1 . ' = ' . $2;
warn $@ if $@;
- print $client qq|HTTP/1.1 302 Found\r\nLocation: $url\r\nContent-type: text/html\r\n\r\n<big>$1 = $2</big><br>Location: <a href="$url">$url</a>|;
+ print $client $redirect, qq|<big>$1 = $2</big><br>Location: <a href="$url">$url</a>|;
+ server::debug( $debug ) if $1 eq 'debug';
} elsif ( $path =~ m{^/(screen|kvm)} ) {
- print $client $ok, start_stop($1);
+ print $client $redirect, start_stop($1);
} elsif ( $path eq '/exit' ) {
# DESTROY;
exit 0;