19 |
use IO::Socket::INET; |
use IO::Socket::INET; |
20 |
use Module::Refresh; |
use Module::Refresh; |
21 |
|
|
22 |
our $pids = { httpd => $$ }; |
our $pids; |
23 |
|
$pids = { httpd => $$ } unless defined $pids; # keep pids on refresh |
24 |
|
|
25 |
sub DESTROY { |
sub DESTROY { |
26 |
warn "pids ",dump( $pids ); |
warn "pids ",dump( $pids ); |
37 |
our $url = "http://$server::ip:$port"; |
our $url = "http://$server::ip:$port"; |
38 |
|
|
39 |
use html; |
use html; |
40 |
|
our $static_pids; |
41 |
|
|
42 |
sub static { |
sub static { |
43 |
my ($client,$path) = @_; |
my ($client,$path) = @_; |
46 |
|
|
47 |
return if ! -f $full; |
return if ! -f $full; |
48 |
|
|
49 |
|
if ( my $pid = fork ) { |
50 |
|
# parent |
51 |
|
close($client); |
52 |
|
print "http static child $pid\n"; |
53 |
|
$static_pids->{$pid} = $path; |
54 |
|
return 1; |
55 |
|
} |
56 |
|
|
57 |
my $type = 'application/octet-stream'; |
my $type = 'application/octet-stream'; |
58 |
$type = 'text/html' if $path =~ m{\.htm}; |
$type = 'text/html' if $path =~ m{\.htm}; |
59 |
$type = 'application/javascript' if $path =~ m{\.js}; |
$type = 'application/javascript' if $path =~ m{\.js}; |
80 |
|
|
81 |
print "$path $pos == $size OK\n"; |
print "$path $pos == $size OK\n"; |
82 |
|
|
83 |
return $path; |
exit; |
84 |
} |
} |
85 |
|
|
86 |
use boolean; |
use boolean; |
142 |
|
|
143 |
'debug', qq|<a href=/our/debug/| . boolean::toggle($debug) . qq|>$debug</a>|, |
'debug', qq|<a href=/our/debug/| . boolean::toggle($debug) . qq|>$debug</a>|, |
144 |
); |
); |
145 |
foreach my $name ( %$pids ) { |
|
146 |
|
warn 'pids: ', dump( $pids ); |
147 |
|
foreach my $name ( keys %$pids ) { |
148 |
my $pid = $pids->{$name} || next; |
my $pid = $pids->{$name} || next; |
149 |
my $proc = "/proc/$pid/status"; |
my $proc = "/proc/$pid/status"; |
150 |
|
|
156 |
push @rows, ( $name => $html ); |
push @rows, ( $name => $html ); |
157 |
} |
} |
158 |
|
|
159 |
|
warn 'static_pids: ', dump( $static_pids ); |
160 |
|
foreach my $pid ( keys %$static_pids ) { |
161 |
|
my $path = $static_pids->{$pid}; |
162 |
|
if ( -d "/proc/$pid" ) { |
163 |
|
push @rows, ( $path => qq|<a href=/kill/static/$pid>$pid</a>| ); |
164 |
|
} else { |
165 |
|
push @rows, ( $path => "$pid competed" ); |
166 |
|
} |
167 |
|
} |
168 |
|
|
169 |
print $client $ok, html::table( 2, @rows ); |
print $client $ok, html::table( 2, @rows ); |
170 |
|
|
171 |
} elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) { |
} elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) { |
175 |
server::debug( $debug ) if $1 eq 'debug'; |
server::debug( $debug ) if $1 eq 'debug'; |
176 |
} elsif ( $path =~ m{^/(screen|kvm)} ) { |
} elsif ( $path =~ m{^/(screen|kvm)} ) { |
177 |
print $client $redirect, start_stop($1); |
print $client $redirect, start_stop($1); |
178 |
|
} elsif ( $path =~ m{^/kill/static/(\d+)} ) { |
179 |
|
print $client $redirect; |
180 |
|
kill 9, $1 && warn "killed $1"; |
181 |
} elsif ( $path eq '/exit' ) { |
} elsif ( $path eq '/exit' ) { |
182 |
# DESTROY; |
# DESTROY; |
183 |
exit 0; |
exit 0; |