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