upgrade webconverger 5.5 -> 6.2
[pxelator] / lib / PXElator / httpd.pm
index 5e38512..3218391 100644 (file)
@@ -18,6 +18,7 @@ use File::Slurp;
 #use JSON;
 use IO::Socket::INET;
 use Regexp::Common qw/net/;
+use POSIX qw(strftime);
 
 our $title;
 
@@ -76,8 +77,8 @@ qq{
 <a target=server href=/brctl >brctl</a>
 <a target=server href=/ip >ip</a>
 |
-<a target=store href=$store_url >store</a>
-<a target=store href=/store/query >query</a>
+<a target=store href=$store_url >MongoDB</a>
+<a target=store href=/store/latest >latest</a>
 |
 <a target=client href=/nmap >nmap</a>
 <a target=client href=/client >client</a>
@@ -269,7 +270,7 @@ warn "XXX pids = ", dump( $daemons::pids );
                        |
                        ;
 
-       } elsif ( $path =~ m{^/store/query} ) {
+       } elsif ( $path =~ m{^/store/latest} ) {
                print $client ok
                        , qq|
 <style type=text/css>
@@ -290,23 +291,44 @@ warn "XXX pids = ", dump( $daemons::pids );
                        , qq|<table>|
                ;
                my ( $s1,$s2 ) = ( ' class=z', '' );
-               store::query( sub {
+               my @cols;
+
+               my $from_t = $param->{from_t};
+
+               my $q;
+               $q->{'package.time'} = { '$lt' => $from_t * 1 } if $from_t;
+#              $q->{'package.name'} = { '$ne' => 'syslogd' };
+               $q->{'package.name'} = { '$ne' => 'dhcpd' };
+#              $q->{'package.name'} = { '$ne' => [ 'dhcpd', 'dnsd' ] };
+               $q->{'tag'} = { '$ne' => 'CRON' };
+               store::query( $q, sub {
                        my $o = shift;
                        my $p = delete( $o->{package} );
                        delete( $o->{_id} );
 
+                       if ( ! @cols ) {
+                               #@cols = keys %$p;
+                               @cols = qw( time name );
+                               print $client qq|<tr><th>|
+                                       , join(qq|</th><th>|, @cols)
+                                       , qq|</th><th></th></tr>|
+                               ;
+                       }
+
                        # XXX sigh, dump dies if we don't do this
-                       delete $o->{$_} foreach ( grep { ! defined $o->{$_} } keys %$o );
+#                      delete $o->{$_} foreach ( grep { ! defined $o->{$_} } keys %$o );
 
-                       print $client qq|<tr$s1><td>|
-                               , join(qq|</td><td>|, map { $p->{$_} } keys %$p )
-                               , qq|</td><td><pre>|
-                               , dump( $o )
-                               , qq|</pre></td></tr>\n|
+                       print $client qq|<tr$s1>|
+                               , strftime( qq|<td title="%Y-%m-%d">%H:%M:%S</td>|, localtime($p->{time}) )
+                               , map { qq|<td>$_<td>| } ( $p->{name} , html::pre_dump($o) )
+                               , qq|</tr>\n|
                        ;
                        ( $s1, $s2 ) = ( $s2, $s1 );
+                       $from_t = $p->{time};
                });
-               print $client qq|</table>|;
+               print $client qq|</table>|,
+                       qq|<a href="/store/latest?from_t=$from_t">more</a>|
+               ;
 
        } elsif ( $path =~ m!^/client(?:/$RE{net}{IPv4}{-keep})?! ) {
                my $ip = $1;
@@ -402,7 +424,9 @@ warn "XXX pids = ", dump( $daemons::pids );
                                my $mac = delete $conf->{mac} || '';
                                my $dev = $arp->{$mac};
 
-                               next unless $dev || $param->{all};
+                               my $in_dhcp_range = ip::in_dhcp_range($ip);
+
+                               next unless $dev || $param->{all} || $in_dhcp_range;
 
                                my $style
                                        = 'style="color:'
@@ -412,7 +436,7 @@ warn "XXX pids = ", dump( $daemons::pids );
 
                                $style ||= '';
                                my $ip_text = qq|<tt>$ip</tt>|;
-                               $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;
 
                                $dev = qq|<tt>$dev</tt>| if $dev;