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 |
|
|
77 |
<a target=server href=/brctl >brctl</a> |
<a target=server href=/brctl >brctl</a> |
78 |
<a target=server href=/ip >ip</a> |
<a target=server href=/ip >ip</a> |
79 |
| |
| |
80 |
<a target=store href=$store_url >store</a> |
<a target=store href=$store_url >MongoDB</a> |
81 |
<a target=store href=/store/query >query</a> |
<a target=store href=/store/latest >latest</a> |
82 |
| |
| |
83 |
<a target=client href=/nmap >nmap</a> |
<a target=client href=/nmap >nmap</a> |
84 |
<a target=client href=/client >client</a> |
<a target=client href=/client >client</a> |
270 |
| |
| |
271 |
; |
; |
272 |
|
|
273 |
} elsif ( $path =~ m{^/store/query} ) { |
} elsif ( $path =~ m{^/store/latest} ) { |
274 |
print $client ok |
print $client ok |
275 |
, qq| |
, qq| |
276 |
<style type=text/css> |
<style type=text/css> |
293 |
my ( $s1,$s2 ) = ( ' class=z', '' ); |
my ( $s1,$s2 ) = ( ' class=z', '' ); |
294 |
my @cols; |
my @cols; |
295 |
|
|
296 |
store::query( sub { |
my $from_t = $param->{from_t}; |
297 |
|
|
298 |
|
my $q; |
299 |
|
$q->{'package.time'} = { '$lt' => $from_t * 1 } if $from_t; |
300 |
|
# $q->{'package.name'} = { '$ne' => 'syslogd' }; |
301 |
|
$q->{'package.name'} = { '$ne' => 'dhcpd' }; |
302 |
|
# $q->{'package.name'} = { '$ne' => [ 'dhcpd', 'dnsd' ] }; |
303 |
|
$q->{'tag'} = { '$ne' => 'CRON' }; |
304 |
|
store::query( $q, sub { |
305 |
my $o = shift; |
my $o = shift; |
306 |
my $p = delete( $o->{package} ); |
my $p = delete( $o->{package} ); |
307 |
delete( $o->{_id} ); |
delete( $o->{_id} ); |
308 |
|
|
309 |
if ( ! @cols ) { |
if ( ! @cols ) { |
310 |
@cols = keys %$p; |
#@cols = keys %$p; |
311 |
|
@cols = qw( time name ); |
312 |
print $client qq|<tr><th>| |
print $client qq|<tr><th>| |
313 |
, join(qq|</th><th>|, @cols) |
, join(qq|</th><th>|, @cols) |
314 |
, qq|</th><th></th></tr>| |
, qq|</th><th></th></tr>| |
316 |
} |
} |
317 |
|
|
318 |
# XXX sigh, dump dies if we don't do this |
# XXX sigh, dump dies if we don't do this |
319 |
delete $o->{$_} foreach ( grep { ! defined $o->{$_} } keys %$o ); |
# delete $o->{$_} foreach ( grep { ! defined $o->{$_} } keys %$o ); |
320 |
|
|
321 |
print $client qq|<tr$s1><td>| |
print $client qq|<tr$s1>| |
322 |
, join(qq|</td><td>|, map { $p->{$_} } @cols ) |
, strftime( qq|<td title="%Y-%m-%d">%H:%M:%S</td>|, localtime($p->{time}) ) |
323 |
, qq|</td><td><pre>| |
, map { qq|<td>$_<td>| } ( $p->{name} , html::pre_dump($o) ) |
324 |
, dump( $o ) |
, qq|</tr>\n| |
|
, qq|</pre></td></tr>\n| |
|
325 |
; |
; |
326 |
( $s1, $s2 ) = ( $s2, $s1 ); |
( $s1, $s2 ) = ( $s2, $s1 ); |
327 |
|
$from_t = $p->{time}; |
328 |
}); |
}); |
329 |
print $client qq|</table>|; |
print $client qq|</table>|, |
330 |
|
qq|<a href="/store/latest?from_t=$from_t">more</a>| |
331 |
|
; |
332 |
|
|
333 |
} elsif ( $path =~ m!^/client(?:/$RE{net}{IPv4}{-keep})?! ) { |
} elsif ( $path =~ m!^/client(?:/$RE{net}{IPv4}{-keep})?! ) { |
334 |
my $ip = $1; |
my $ip = $1; |
424 |
my $mac = delete $conf->{mac} || ''; |
my $mac = delete $conf->{mac} || ''; |
425 |
my $dev = $arp->{$mac}; |
my $dev = $arp->{$mac}; |
426 |
|
|
427 |
next unless $dev || $param->{all}; |
my $in_dhcp_range = ip::in_dhcp_range($ip); |
428 |
|
|
429 |
|
next unless $dev || $param->{all} || $in_dhcp_range; |
430 |
|
|
431 |
my $style |
my $style |
432 |
= 'style="color:' |
= 'style="color:' |
436 |
|
|
437 |
$style ||= ''; |
$style ||= ''; |
438 |
my $ip_text = qq|<tt>$ip</tt>|; |
my $ip_text = qq|<tt>$ip</tt>|; |
439 |
$ip_text = qq|<tt><b>$ip</b></tt>| if ip::in_dhcp_range($ip); |
$ip_text = qq|<tt><b>$ip</b></tt>| if $in_dhcp_range; |
440 |
|
|
441 |
$dev = qq|<tt>$dev</tt>| if $dev; |
$dev = qq|<tt>$dev</tt>| if $dev; |
442 |
|
|