/[pxelator]/lib/PXElator/httpd.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/PXElator/httpd.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 488 by dpavlin, Sat Jan 23 21:00:01 2010 UTC revision 522 by dpavlin, Thu Aug 26 19:29:18 2010 UTC
# Line 18  use File::Slurp; Line 18  use File::Slurp;
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 YAML;  use POSIX qw(strftime);
22    
23  our $title;  our $title;
24    
# Line 77  qq{ Line 77  qq{
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>
# Line 270  warn "XXX pids = ", dump( $daemons::pids Line 270  warn "XXX pids = ", dump( $daemons::pids
270                          |                          |
271                          ;                          ;
272    
273          } elsif ( $path =~ m{^/store/query} ) {          } elsif ( $path =~ m{^/store/latest} ) {
274                  print $client ok                  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>|                          , qq|<table>|
292                  ;                  ;
293                  store::query( sub {                  my ( $s1,$s2 ) = ( ' class=z', '' );
294                    my @cols;
295    
296                    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 ) {
310                                    #@cols = keys %$p;
311                                    @cols = qw( time name );
312                                    print $client qq|<tr><th>|
313                                            , join(qq|</th><th>|, @cols)
314                                            , qq|</th><th></th></tr>|
315                                    ;
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><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>|
322                                    , strftime( qq|<td title="%Y-%m-%d">%H:%M:%S</td>|, localtime($p->{time}) )
323                                    , map { qq|<td>$_<td>| } ( $p->{name} , html::pre_dump($o) )
324                                    , qq|</tr>\n|
325                            ;
326                            ( $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;
# Line 380  warn "XXX pids = ", dump( $daemons::pids Line 424  warn "XXX pids = ", dump( $daemons::pids
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:'
# Line 390  warn "XXX pids = ", dump( $daemons::pids Line 436  warn "XXX pids = ", dump( $daemons::pids
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    

Legend:
Removed from v.488  
changed lines
  Added in v.522

  ViewVC Help
Powered by ViewVC 1.1.26