17 |
use File::Slurp; |
use File::Slurp; |
18 |
#use JSON; |
#use JSON; |
19 |
use IO::Socket::INET; |
use IO::Socket::INET; |
20 |
|
use Regexp::Common qw/net/; |
21 |
|
|
22 |
sub menu {qq{ |
sub menu {qq{ |
23 |
|
|
50 |
our $static_pids; |
our $static_pids; |
51 |
use progress_bar; |
use progress_bar; |
52 |
use config; |
use config; |
53 |
|
use client; |
54 |
|
use log; |
55 |
|
use x11; |
56 |
|
|
57 |
sub static { |
sub static { |
58 |
my ($client,$path) = @_; |
my ($client,$path) = @_; |
136 |
if ( $daemon =~ m{dhcpd|tftpd|dnsd} ) { |
if ( $daemon =~ m{dhcpd|tftpd|dnsd} ) { |
137 |
my $exec = "perl -I$server::base_dir/lib -I$server::base_dir/lib/PXElator -M$daemon -e ${daemon}::${invoke}"; |
my $exec = "perl -I$server::base_dir/lib -I$server::base_dir/lib/PXElator -M$daemon -e ${daemon}::${invoke}"; |
138 |
warn "exec $exec"; |
warn "exec $exec"; |
139 |
exec "xterm -T $daemon -n $daemon -e $exec"; |
x11::xterm( $daemon => $exec ); |
140 |
} else { |
} else { |
141 |
my $eval = $daemon . '::' . $invoke . '(' . ( @_ ? dump(@_) : '' ) . ')'; |
my $eval = $daemon . '::' . $invoke . '(' . ( @_ ? dump(@_) : '' ) . ')'; |
142 |
warn "eval $eval"; |
warn "eval $eval"; |
150 |
} |
} |
151 |
} |
} |
152 |
|
|
153 |
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(); |
154 |
my $redirect = qq|HTTP/1.1 302 Found\r\nContent-type: text/html\r\nLocation: $url\r\n\r\n|; |
my $redirect = qq|HTTP/1.1 302 Found\r\nContent-type: text/html\r\nLocation: $url\r\n\r\n|; |
155 |
|
|
156 |
sub get_request { |
sub get_request { |
174 |
foreach my $name ( sort keys %$pids ) { |
foreach my $name ( sort keys %$pids ) { |
175 |
my $pid = $pids->{$name} || next; |
my $pid = $pids->{$name} || next; |
176 |
|
|
177 |
my $html = qq|<a href=/start_stop/$name>$pid</a>|; |
my $html; |
178 |
|
|
179 |
my $proc = "/proc/$pid/status"; |
my $proc = "/proc/$pid/status"; |
180 |
|
|
181 |
if ( -e $proc ) { |
if ( -e $proc ) { |
182 |
|
$html .= qq|<a href=/start_stop/$name>$pid</a>|; |
183 |
if ( $debug ) { |
if ( $debug ) { |
184 |
$html .= qq| <a name=$pid href=#proc-$pid>?</a>|; |
$html .= qq| <a name=$pid href=#proc-$pid>?</a>|; |
185 |
|
|
197 |
if ( $name->can('actions') ) { |
if ( $name->can('actions') ) { |
198 |
$html .= qq| <a href=/action/kvm/$_>$_</a>| foreach $name->actions; |
$html .= qq| <a href=/action/kvm/$_>$_</a>| foreach $name->actions; |
199 |
} |
} |
200 |
|
} else { |
201 |
|
$html .= qq|<a href=/start_stop/$name>restart</a> $pid exited|; |
202 |
} |
} |
203 |
|
|
204 |
push @rows, ( $name => $html ); |
push @rows, ( $name => $html ); |
220 |
} |
} |
221 |
|
|
222 |
print $client $ok |
print $client $ok |
|
, menu() |
|
223 |
, html::table( 2, @rows ) |
, html::table( 2, @rows ) |
224 |
, $below_table |
, $below_table |
225 |
, html::tabs( log::mac_changes ) |
, html::tabs( log::mac_changes ) |
228 |
|
|
229 |
} elsif ( $path =~ m{^/server} ) { |
} elsif ( $path =~ m{^/server} ) { |
230 |
print $client $ok |
print $client $ok |
|
, menu() |
|
231 |
, html::table( 2, map { ( $_, eval '$server::'.$_ ) } ( 'ip', 'netmask', 'ip_from', 'ip_to', 'domain_name', 'base_dir' ) ) |
, html::table( 2, map { ( $_, eval '$server::'.$_ ) } ( 'ip', 'netmask', 'ip_from', 'ip_to', 'domain_name', 'base_dir' ) ) |
232 |
; |
; |
233 |
} elsif ( $path =~ m{^/client} ) { |
} elsif ( $path =~ m!^/client(?:/$RE{net}{IPv4}{-keep})?! ) { |
234 |
my $ip = $client->peerhost; |
my $ip = $1 || $client->peerhost; |
235 |
my $hostname = server::shared( "hostname/$ip", $param->{hostname} ); |
if ( $ip ne $server::ip ) { |
236 |
my $deploy = server::shared( "deploy/$ip", $param->{deploy} ); |
my $hostname = client::conf( $ip, 'hostname' => $param->{hostname} ); |
237 |
print $client $ok |
my $deploy = client::conf( $ip, 'deploy' => $param->{deploy} ); |
238 |
, menu() |
print $client $ok |
239 |
, qq|<form method=get>| |
, qq|<form method=get>| |
240 |
, html::table( 2, |
, html::table( 2, |
241 |
'ip' => $ip, |
'ip' => $ip, |
242 |
'hostname' => qq|<input type=text name=hostname value=$hostname>|, |
'mac' => client::mac( $ip ), |
243 |
'deploy' => html::select( 'deploy', $deploy, config::available ), |
'hostname' => qq|<input type=text name=hostname value=$hostname>|, |
244 |
) |
'deploy' => html::select( 'deploy', $deploy, config::available ), |
245 |
, qq|<input type=submit value=change></form><pre>| |
) |
246 |
, config::for_ip( $ip ) |
, qq|<input type=submit value=change></form>| |
247 |
, qq|</pre>| |
, qq|<h2>PXElinux $deploy</h2><pre>| |
248 |
; |
, config::for_ip( $ip ) |
249 |
|
, qq|</pre>| |
250 |
|
; |
251 |
|
} else { |
252 |
|
print $client $ok |
253 |
|
, qq|<h2>Clients on $server::ip</h2>| |
254 |
|
, html::table( -4, |
255 |
|
'ip', 'mac', 'hostname', 'deploy', |
256 |
|
map { |
257 |
|
my $ip = $_; |
258 |
|
$ip =~ s{^.+/ip/}{}; |
259 |
|
( qq|<a href=/client/$ip>$ip</a>|, client::mac($ip), client::conf( $ip, 'hostname' ), client::conf( $ip, 'deploy' ) ); |
260 |
|
} |
261 |
|
glob("$server::conf/ip/*") |
262 |
|
) |
263 |
|
; |
264 |
|
} |
265 |
} elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) { |
} elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) { |
266 |
eval 'our $' . $1 . ' = ' . $2; |
eval 'our $' . $1 . ' = ' . $2; |
267 |
warn $@ if $@; |
warn $@ if $@; |
275 |
} elsif ( $path =~ m{^/kill/static/(\d+)} ) { |
} elsif ( $path =~ m{^/kill/static/(\d+)} ) { |
276 |
print $client $redirect; |
print $client $redirect; |
277 |
kill 1, $1 || kill 9, $2 && warn "killed $1"; |
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/ |
|
|
|
|
|
}; |
|
278 |
} else { |
} else { |
279 |
print $client "HTTP/1.0 404 $path\r\nConnection: close\r\nContent-type: text/html\r\n\r\n<big>404 $path</big>"; |
print $client "HTTP/1.0 404 $path\r\nConnection: close\r\nContent-type: text/html\r\n\r\n<big>404 $path</big>"; |
280 |
warn "404 $path"; |
warn "404 $path"; |
302 |
start_stop 'dhcpd'; |
start_stop 'dhcpd'; |
303 |
start_stop 'tftpd'; |
start_stop 'tftpd'; |
304 |
start_stop 'dnsd'; |
start_stop 'dnsd'; |
305 |
start_stop 'kvm'; |
start_stop 'kvm' unless $ENV{DEV}; # skip kvm statup when running on real device |
306 |
|
|
307 |
while (1) { |
while (1) { |
308 |
my $client = $server->accept() || next; # ALARM trickle us |
my $client = $server->accept() || next; # ALARM trickle us |