30 |
} |
} |
31 |
|
|
32 |
our $port = 7777; |
our $port = 7777; |
|
our $debug = 0; |
|
33 |
|
|
34 |
use server; |
use server; |
35 |
|
our $debug = server::debug; |
36 |
our $url = "http://$server::ip:$port"; |
our $url = "http://$server::ip:$port"; |
37 |
|
|
38 |
use html; |
use html; |
73 |
return $path; |
return $path; |
74 |
} |
} |
75 |
|
|
|
my $ok = "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n"; |
|
|
|
|
76 |
use boolean; |
use boolean; |
77 |
|
|
78 |
use screen; |
use screen; |
84 |
my $daemon = shift; |
my $daemon = shift; |
85 |
my $pid = $pids->{$daemon}; |
my $pid = $pids->{$daemon}; |
86 |
|
|
87 |
warn "start_stop $daemon pids: ",dump( $pids ); |
warn "start_stop $daemon $pid pids: ",dump( $pids ); |
88 |
|
|
89 |
if ( $pid ) { |
if ( $pid =~ m{^\d+$} ) { |
90 |
warn "kill 9 $pid"; |
warn "kill 9 $pid"; |
91 |
kill 9, $pid; |
kill 9, $pid; |
92 |
$pids->{$daemon} = 'stopped'; |
$pids->{$daemon} = 'stopped'; |
99 |
return qq|$daemon pid $pid started|; |
return qq|$daemon pid $pid started|; |
100 |
} elsif ( defined $pid ) { |
} elsif ( defined $pid ) { |
101 |
# child |
# child |
102 |
my $eval = $daemon . '::start(' . dump(@_) . ')'; |
my $eval = $daemon . '::start(' . ( @_ ? dump(@_) : '' ) . ')'; |
103 |
warn "eval $eval"; |
warn "eval $eval"; |
104 |
eval $eval; |
eval $eval; |
105 |
warn "can't start $daemon: $@" if $@; |
warn "can't start $daemon: $@" if $@; |
110 |
} |
} |
111 |
} |
} |
112 |
|
|
113 |
|
my $ok = qq|HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n|; |
114 |
|
my $redirect = qq|HTTP/1.1 302 Found\r\nContent-type: text/html\r\nLocation: $url\r\n\r\n|; |
115 |
|
|
116 |
sub get_request { |
sub get_request { |
117 |
my ( $client, $path, $param ) = @_; |
my ( $client, $path, $param ) = @_; |
118 |
|
|
134 |
); |
); |
135 |
foreach my $name ( %$pids ) { |
foreach my $name ( %$pids ) { |
136 |
my $pid = $pids->{$name} || next; |
my $pid = $pids->{$name} || next; |
137 |
|
my $proc = "/proc/$pid/status"; |
138 |
|
|
139 |
my $html = qq|<a href=/$name>$pid</a>|; |
my $html = qq|<a href=/$name>$pid</a>|; |
140 |
$html .= qq|<pre style="font-size: 10%">| |
$html .= qq|<pre style="font-size: 10%">| |
141 |
. ( $debug ? read_file("/proc/$pid/status") : '' ) |
. ( $debug && -e $proc ? read_file($proc) : '' ) |
142 |
. qq|</pre>| if $debug; |
. qq|</pre>| if $debug; |
143 |
|
|
144 |
push @rows, ( $name => $html ); |
push @rows, ( $name => $html ); |
149 |
} elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) { |
} elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) { |
150 |
eval 'our $' . $1 . ' = ' . $2; |
eval 'our $' . $1 . ' = ' . $2; |
151 |
warn $@ if $@; |
warn $@ if $@; |
152 |
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>|; |
153 |
|
server::debug( $debug ) if $1 eq 'debug'; |
154 |
} elsif ( $path =~ m{^/(screen|kvm)} ) { |
} elsif ( $path =~ m{^/(screen|kvm)} ) { |
155 |
print $client $ok, start_stop($1); |
print $client $redirect, start_stop($1); |
156 |
} elsif ( $path eq '/exit' ) { |
} elsif ( $path eq '/exit' ) { |
157 |
# DESTROY; |
# DESTROY; |
158 |
exit 0; |
exit 0; |