24 |
<div style="font-size: 80%; color: #888"> |
<div style="font-size: 80%; color: #888"> |
25 |
<a href=/>home</a> |
<a href=/>home</a> |
26 |
<a href=/server>server</a> |
<a href=/server>server</a> |
27 |
|
<a href=/ip>ip</a> |
28 |
<a href=/client>client</a> |
<a href=/client>client</a> |
29 |
</div> |
</div> |
30 |
|
|
50 |
use kvm; |
use kvm; |
51 |
use browser; |
use browser; |
52 |
use network; |
use network; |
53 |
|
use ip; |
54 |
|
|
55 |
|
use CouchDB; |
56 |
|
|
57 |
sub static { |
sub static { |
58 |
my ($client,$path) = @_; |
my ($client,$path) = @_; |
64 |
if ( my $pid = fork ) { |
if ( my $pid = fork ) { |
65 |
# parent |
# parent |
66 |
close($client); |
close($client); |
|
print "http static child $pid\n"; |
|
67 |
$static_pids->{$pid} = $path; |
$static_pids->{$pid} = $path; |
68 |
return 1; |
return 1; |
69 |
} |
} |
83 |
my $buff; |
my $buff; |
84 |
my $pos = 0; |
my $pos = 0; |
85 |
|
|
86 |
warn "static $path $type $size block: $block\n"; |
CouchDB::audit( 'static', { pid => $$, path => $path, type => $type, size => $size, block => $block, peerhost => $client->peerhost }); |
87 |
|
|
88 |
progress_bar::start; |
progress_bar::start; |
89 |
|
|
98 |
|
|
99 |
print STDERR "\n"; |
print STDERR "\n"; |
100 |
|
|
|
warn "exit static child"; |
|
|
|
|
101 |
exit(0); |
exit(0); |
102 |
} |
} |
103 |
|
|
116 |
|
|
117 |
server->refresh; |
server->refresh; |
118 |
|
|
119 |
warn "get_request $path ", $param ? dump( $param ) : '', "\n"; |
CouchDB::audit( 'request', { path => $path, param => $param, peerhost => $client->peerhost } ); |
120 |
|
|
121 |
if ( my $found = static( $client,$path ) ) { |
if ( my $found = static( $client,$path ) ) { |
122 |
warn "static $found" if $debug; |
warn "static $found" if $debug; |
189 |
; |
; |
190 |
} elsif ( $path =~ m!^/client(?:/$RE{net}{IPv4}{-keep})?! ) { |
} elsif ( $path =~ m!^/client(?:/$RE{net}{IPv4}{-keep})?! ) { |
191 |
my $ip = $1 || $client->peerhost; |
my $ip = $1 || $client->peerhost; |
192 |
|
|
193 |
|
if ( my $new_ip = $param->{change_ip} ) { |
194 |
|
client::change_ip( $ip, $new_ip ); |
195 |
|
$ip = $new_ip; |
196 |
|
} |
197 |
|
|
198 |
if ( $ip ne $server::ip ) { |
if ( $ip ne $server::ip ) { |
199 |
my $hostname = client::conf( $ip, 'hostname' => $param->{hostname} ); |
my $hostname = client::conf( $ip, 'hostname' => $param->{hostname} ); |
200 |
|
|
205 |
|
|
206 |
my $deploy; |
my $deploy; |
207 |
|
|
208 |
if ( my $mac = client::mac( $ip ) ) { |
if ( my $mac = client::mac_from_ip( $ip ) ) { |
209 |
$deploy = client::conf( $ip, 'deploy' => $param->{deploy} ); |
$deploy = client::conf( $ip, 'deploy' => $param->{deploy} ); |
210 |
push @table, ( |
push @table, ( |
211 |
'mac' => $mac, |
'mac' => format::mac( $mac => 'html' ), |
212 |
'deploy' => html::select( 'deploy', $deploy, config::available ) |
'deploy' => html::select( 'deploy', $deploy, config::available ) |
213 |
); |
); |
214 |
$deploy = qq|<h2>PXElinux</h2>| . html::pre( config::for_ip( $ip ) ); |
$deploy = qq|<h2>PXElinux</h2>| . html::pre( config::for_ip( $ip ) ); |
245 |
map { |
map { |
246 |
my $ip = $_; |
my $ip = $_; |
247 |
$ip =~ s{^.+/ip/}{}; |
$ip =~ s{^.+/ip/}{}; |
248 |
my $arp = $arp->{ client::mac $ip, 'clean' }; |
my $mac = client::mac_from_ip $ip; |
249 |
|
my $arp = $arp->{ $mac }; |
250 |
$arp = $arp ? $arp->[1] : ''; |
$arp = $arp ? $arp->[1] : ''; |
251 |
$arp =~ s{$ip}{}; |
$arp =~ s{$ip}{}; |
252 |
( |
( |
253 |
qq|<a href=/client/$ip>$ip</a>| |
qq|<a href=/client/$ip>$ip</a>| |
254 |
, client::conf( $ip, 'hostname' ) |
, client::conf( $ip, 'hostname' ) |
255 |
, client::mac( $ip ) |
, format::mac( $mac => 'html' ) |
256 |
, html::tt( client::conf( $ip, 'deploy' ) ) |
, html::tt( client::conf( $ip, 'deploy' ) ) |
257 |
, $arp |
, $arp |
258 |
); |
); |
263 |
, html::table( -3, 'mac', 'dev', 'ip', |
, html::table( -3, 'mac', 'dev', 'ip', |
264 |
map { |
map { |
265 |
my $c = $arp->{$_}; |
my $c = $arp->{$_}; |
266 |
( html::tt( $_ ), $c->[1], $c->[0] ) |
( format::mac( $_ => 'html' ), $c->[1], $c->[0] ) |
267 |
} sort keys %$arp |
} sort keys %$arp |
268 |
) |
) |
269 |
; |
; |
270 |
} |
} |
271 |
|
} elsif ( $path =~ m{^/ip/?(\w+)?} ) { |
272 |
|
print $client ok |
273 |
|
, join("\n", map { qq|<a href=/ip/$_>$_</a>| } ( qw/link addr route neigh ntable tunnel maddr mroute xfrm/ )) |
274 |
|
, ip::html( $1 ) |
275 |
|
; |
276 |
} elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) { |
} elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) { |
277 |
eval 'our $' . $1 . ' = ' . $2; |
eval 'our $' . $1 . ' = ' . $2; |
278 |
warn $@ if $@; |
warn $@ if $@; |