18 |
#use JSON; |
#use JSON; |
19 |
use IO::Socket::INET; |
use IO::Socket::INET; |
20 |
use Regexp::Common qw/net/; |
use Regexp::Common qw/net/; |
21 |
|
use POSIX qw(strftime); |
22 |
|
|
23 |
our $title; |
our $title; |
24 |
|
|
37 |
</html> |
</html> |
38 |
}} |
}} |
39 |
|
|
|
sub menu { |
|
|
qq{ |
|
|
<div style="font-size: 80%; color: #888"> |
|
|
<a href=/ target=/>home</a> |
|
|
<a href=/server target=server>server</a> |
|
|
<a href=/brctl target=brctl>brctl</a> |
|
|
<a href=/ip target=ip>ip</a> |
|
|
<a href=/nmap target=nmap>nmap</a> |
|
|
<a href=/client target=client>client</a> |
|
|
<a href=http://$server::ip:5984/_utils/ target=couchdb>couchdb</a> |
|
|
</div> |
|
|
|
|
|
}} |
|
|
|
|
40 |
our $port = 7777; |
our $port = 7777; |
41 |
|
|
42 |
use server; |
use server; |
51 |
use log; |
use log; |
52 |
use x11; |
use x11; |
53 |
use amt; |
use amt; |
|
use boolean; |
|
54 |
use daemons; |
use daemons; |
55 |
|
|
56 |
use kvm; |
use kvm; |
63 |
use ping; |
use ping; |
64 |
use wol; |
use wol; |
65 |
|
|
66 |
use CouchDB; |
use store; |
67 |
|
|
68 |
|
|
69 |
|
sub menu { |
70 |
|
my $store_url = $url; |
71 |
|
$store_url =~ s{:\d+.+}{:28017}; |
72 |
|
qq{ |
73 |
|
<div style="font-size: 80%; color: #888"> |
74 |
|
<a target=pids href=/ >home</a> |
75 |
|
| |
76 |
|
<a target=server href=/server >server</a> |
77 |
|
<a target=server href=/brctl >brctl</a> |
78 |
|
<a target=server href=/ip >ip</a> |
79 |
|
| |
80 |
|
<a target=store href=$store_url >MongoDB</a> |
81 |
|
<a target=store href=/store/latest >latest</a> |
82 |
|
| |
83 |
|
<a target=client href=/nmap >nmap</a> |
84 |
|
<a target=client href=/client >client</a> |
85 |
|
</div> |
86 |
|
|
87 |
|
}} |
88 |
|
|
89 |
|
|
90 |
sub static { |
sub static { |
91 |
my ($client,$path) = @_; |
my ($client,$path) = @_; |
118 |
my $buff; |
my $buff; |
119 |
my $pos = 0; |
my $pos = 0; |
120 |
|
|
121 |
CouchDB::audit( 'static', { pid => $$, path => $path, type => $type, size => $size, block => $block, peerhost => $client->peerhost }); |
store::audit( 'static', { pid => $$, path => $path, type => $type, size => $size, block => $block, peerhost => $client->peerhost }); |
122 |
|
|
123 |
progress_bar::start; |
progress_bar::start; |
124 |
|
|
146 |
qq|HTTP/1.1 302 Found\r\nContent-type: text/html\r\nLocation: $to\r\n\r\n| |
qq|HTTP/1.1 302 Found\r\nContent-type: text/html\r\nLocation: $to\r\n\r\n| |
147 |
} |
} |
148 |
|
|
149 |
|
sub toggle { |
150 |
|
my $v = shift; |
151 |
|
return $v ? 0 : 1; |
152 |
|
} |
153 |
|
|
154 |
sub get_request { |
sub get_request { |
155 |
my ( $client, $path, $param ) = @_; |
my ( $client, $path, $param ) = @_; |
156 |
|
|
157 |
server->refresh; |
server->refresh; |
158 |
|
|
159 |
CouchDB::audit( 'request', { path => $path, param => $param, peerhost => $client->peerhost } ); |
store::audit( 'request', { path => $path, param => $param, peerhost => $client->peerhost } ); |
160 |
|
|
161 |
$title = $path; |
$title = $path; |
162 |
|
|
247 |
eval '$server::' . $name . '= $param->{$name}'; |
eval '$server::' . $name . '= $param->{$name}'; |
248 |
} |
} |
249 |
my @table = ( |
my @table = ( |
250 |
'debug' => qq|<a href=/our/debug/| . boolean::toggle($debug) . qq|>$debug</a>|, |
'debug' => qq|<a href=/our/debug/| . toggle($debug) . qq|>$debug</a>|, |
251 |
, 'new_clients' => qq|<input type=text name=new_clients size=3 value="$server::new_clients">| |
, 'new_clients' => qq|<input type=text name=new_clients size=3 value="$server::new_clients">| |
252 |
); |
); |
253 |
|
|
270 |
| |
| |
271 |
; |
; |
272 |
|
|
273 |
|
} elsif ( $path =~ m{^/store/latest} ) { |
274 |
|
print $client ok |
275 |
|
, qq| |
276 |
|
<style type=text/css> |
277 |
|
.z { |
278 |
|
background: #eee; |
279 |
|
} |
280 |
|
td > pre { |
281 |
|
margin: 0; |
282 |
|
max-height: 3em; |
283 |
|
overflow: hidden; |
284 |
|
} |
285 |
|
td:hover > pre { |
286 |
|
max-height: 100%; |
287 |
|
overflow: show; |
288 |
|
} |
289 |
|
</style> |
290 |
|
| |
291 |
|
, qq|<table>| |
292 |
|
; |
293 |
|
my ( $s1,$s2 ) = ( ' class=z', '' ); |
294 |
|
my @cols; |
295 |
|
|
296 |
|
my $from_t = $param->{from_t}; |
297 |
|
|
298 |
|
store::query( $from_t, sub { |
299 |
|
my $o = shift; |
300 |
|
my $p = delete( $o->{package} ); |
301 |
|
delete( $o->{_id} ); |
302 |
|
|
303 |
|
if ( ! @cols ) { |
304 |
|
#@cols = keys %$p; |
305 |
|
@cols = qw( time name ); |
306 |
|
print $client qq|<tr><th>| |
307 |
|
, join(qq|</th><th>|, @cols) |
308 |
|
, qq|</th><th></th></tr>| |
309 |
|
; |
310 |
|
} |
311 |
|
|
312 |
|
# XXX sigh, dump dies if we don't do this |
313 |
|
# delete $o->{$_} foreach ( grep { ! defined $o->{$_} } keys %$o ); |
314 |
|
|
315 |
|
print $client qq|<tr$s1>| |
316 |
|
, strftime( qq|<td title="%Y-%m-%d">%H:%M:%S</td>|, localtime($p->{time}) ) |
317 |
|
, map { qq|<td>$_<td>| } ( $p->{name} , html::pre_dump($o) ) |
318 |
|
, qq|</tr>\n| |
319 |
|
; |
320 |
|
( $s1, $s2 ) = ( $s2, $s1 ); |
321 |
|
$from_t = $p->{time}; |
322 |
|
}); |
323 |
|
print $client qq|</table>|, |
324 |
|
qq|<a href="/store/latest?from_t=$from_t">more</a>| |
325 |
|
; |
326 |
|
|
327 |
} elsif ( $path =~ m!^/client(?:/$RE{net}{IPv4}{-keep})?! ) { |
} elsif ( $path =~ m!^/client(?:/$RE{net}{IPv4}{-keep})?! ) { |
328 |
my $ip = $1; |
my $ip = $1; |
329 |
$title = $ip if $ip; |
$title = $ip if $ip; |
398 |
|
|
399 |
} else { |
} else { |
400 |
|
|
401 |
|
print $client ok qq|<h2>Clients on $server::ip</h2>|; |
402 |
|
|
403 |
my @ping; |
my @ping; |
404 |
if ( my $host = $param->{ping_target} ) { |
if ( my $host = $param->{ping_target} ) { |
405 |
@ping = ( $host ); |
@ping = ( $host ); |
410 |
my $ping = ping::fping( @ping ) if @ping; |
my $ping = ping::fping( @ping ) if @ping; |
411 |
my $arp = client::arp_mac_dev; |
my $arp = client::arp_mac_dev; |
412 |
|
|
413 |
print $client ok |
my @clients; |
414 |
, qq|<h2>Clients on $server::ip</h2>| |
|
415 |
, html::table( -5, |
foreach my $ip ( client::all_ips ) { |
416 |
'ip', 'mac', 'dev', 'hostname', 'conf', |
|
417 |
map { |
my $conf = client::all_conf( $ip ); |
418 |
my $ip = $_; |
my $mac = delete $conf->{mac} || ''; |
419 |
my $conf = client::all_conf( $ip ); |
my $dev = $arp->{$mac}; |
420 |
my $mac = delete $conf->{mac} || ''; |
|
421 |
my $style; |
my $in_dhcp_range = ip::in_dhcp_range($ip); |
422 |
$style |
|
423 |
= 'style="color:' |
next unless $dev || $param->{all} || $in_dhcp_range; |
424 |
. ( $ping->{$ip} ? 'green' : 'red' ) |
|
425 |
. '"' |
my $style |
426 |
if $ping; |
= 'style="color:' |
427 |
$style ||= ''; |
. ( $ping->{$ip} ? 'green' : 'red' ) |
428 |
my $ip_text = qq|<tt>$ip</tt>|; |
. '"' |
429 |
$ip_text = qq|<tt><b>$ip</b></tt>| if ip::in_dhcp_range($ip); |
if $ping; |
430 |
( |
|
431 |
qq|<a $style name=$ip target=$ip href=/client/$ip>$ip_text</a>| |
$style ||= ''; |
432 |
, format::mac( $mac => 'html' ) |
my $ip_text = qq|<tt>$ip</tt>|; |
433 |
, $arp->{$mac} |
$ip_text = qq|<tt><b>$ip</b></tt>| if $in_dhcp_range; |
434 |
, delete $conf->{hostname} |
|
435 |
, html::conf( $ip, $conf, 'inline' ) |
$dev = qq|<tt>$dev</tt>| if $dev; |
436 |
) |
|
437 |
} client::all_ips |
push @clients |
438 |
) |
, qq|<a $style name=$ip target=client href=/client/$ip>$ip_text</a>| |
439 |
|
, format::mac( $mac => 'html' ) |
440 |
|
, $dev |
441 |
|
, delete $conf->{hostname} |
442 |
|
, html::conf( $ip, $conf, 'inline' ) |
443 |
; |
; |
444 |
|
} |
445 |
|
|
446 |
|
my $all = $param->{all} ? 0 : 1; |
447 |
|
|
448 |
|
print $client html::table( -5, 'ip', 'mac', qq|<a href="?all=$all">dev</a>|, 'hostname', 'conf', @clients ); |
449 |
print $client qq| |
print $client qq| |
450 |
<form method=get> |
<form method=get> |
451 |
<input type=text name=ping_target size=15> |
<input type=text name=ping_target size=15> |