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 |
|
|
56 |
sub static { |
sub static { |
57 |
my ($client,$path) = @_; |
my ($client,$path) = @_; |
106 |
use boolean; |
use boolean; |
107 |
|
|
108 |
use kvm; |
use kvm; |
109 |
|
use qemu; $pids->{qemu} = 'stopped'; |
110 |
|
|
111 |
$SIG{CHLD} = 'IGNORE'; |
$SIG{CHLD} = 'IGNORE'; |
112 |
|
|
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 { |
217 |
} |
} |
218 |
|
|
219 |
print $client $ok |
print $client $ok |
|
, menu() |
|
220 |
, html::table( 2, @rows ) |
, html::table( 2, @rows ) |
221 |
, $below_table |
, $below_table |
222 |
, html::tabs( log::mac_changes ) |
, html::tabs( log::mac_changes ) |
225 |
|
|
226 |
} elsif ( $path =~ m{^/server} ) { |
} elsif ( $path =~ m{^/server} ) { |
227 |
print $client $ok |
print $client $ok |
|
, menu() |
|
228 |
, 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' ) ) |
229 |
; |
; |
230 |
} elsif ( $path =~ m{^/client} ) { |
} elsif ( $path =~ m!^/client(?:/$RE{net}{IPv4}{-keep})?! ) { |
231 |
my $ip = $client->peerhost; |
my $ip = $1 || $client->peerhost; |
232 |
my $hostname = server::shared( "hostname/$ip", $param->{hostname} ); |
if ( $ip ne $server::ip ) { |
233 |
my $deploy = server::shared( "deploy/$ip", $param->{deploy} ); |
my $hostname = client::conf( $ip, 'hostname' => $param->{hostname} ); |
234 |
print $client $ok |
my $deploy = client::conf( $ip, 'deploy' => $param->{deploy} ); |
235 |
, menu() |
print $client $ok |
236 |
, qq|<form method=get>| |
, qq|<form method=get>| |
237 |
, html::table( 2, |
, html::table( 2, |
238 |
'ip' => $ip, |
'ip' => $ip, |
239 |
'hostname' => qq|<input type=text name=hostname value=$hostname>|, |
'mac' => client::mac( $ip ), |
240 |
'deploy' => html::select( 'deploy', $deploy, config::available ), |
'hostname' => qq|<input type=text name=hostname value=$hostname>|, |
241 |
) |
'deploy' => html::select( 'deploy', $deploy, config::available ), |
242 |
, qq|<input type=submit value=change></form><pre>| |
) |
243 |
, config::for_ip( $ip ) |
, qq|<input type=submit value=change></form>| |
244 |
, qq|</pre>| |
, qq|<h2>PXElinux $deploy</h2><pre>| |
245 |
; |
, config::for_ip( $ip ) |
246 |
|
, qq|</pre>| |
247 |
|
; |
248 |
|
} else { |
249 |
|
print $client $ok |
250 |
|
, qq|<h2>Clients on $server::ip</h2>| |
251 |
|
, qq|<ul>| |
252 |
|
, join("\n", |
253 |
|
map { |
254 |
|
my $ip = $_; |
255 |
|
$ip =~ s{^.+/ip/}{}; |
256 |
|
qq|<li><a href=/client/$ip>$ip</a> |, client::mac($ip), qq|</li>|; |
257 |
|
} |
258 |
|
glob("$server::conf/ip/*") |
259 |
|
) |
260 |
|
, qq|</ul>| |
261 |
|
; |
262 |
|
} |
263 |
} elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) { |
} elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) { |
264 |
eval 'our $' . $1 . ' = ' . $2; |
eval 'our $' . $1 . ' = ' . $2; |
265 |
warn $@ if $@; |
warn $@ if $@; |
273 |
} elsif ( $path =~ m{^/kill/static/(\d+)} ) { |
} elsif ( $path =~ m{^/kill/static/(\d+)} ) { |
274 |
print $client $redirect; |
print $client $redirect; |
275 |
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/ |
|
|
|
|
|
}; |
|
276 |
} else { |
} else { |
277 |
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>"; |
278 |
warn "404 $path"; |
warn "404 $path"; |