/[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 431 by dpavlin, Mon Sep 14 13:44:42 2009 UTC revision 493 by dpavlin, Mon Jan 25 18:30:47 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 POSIX qw(strftime);
22    
23  our $title;  our $title;
24    
# Line 50  use client; Line 51  use client;
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;
# Line 63  use nmap; Line 63  use nmap;
63  use ping;  use ping;
64  use wol;  use wol;
65    
66  use CouchDB;  use store;
67    
68    
69  sub menu {  sub menu {
70          my $couch_url = $url;          my $store_url = $url;
71          $couch_url =~ s{:\d+.+}{:5984/_utils/};          $store_url =~ s{:\d+.+}{:28017};
72  qq{  qq{
73  <div style="font-size: 80%; color: #888">  <div style="font-size: 80%; color: #888">
74  <a href=/ target=/>home</a>  <a target=pids href=/ >home</a>
75  <a href=/server target=server>server</a>  |
76  <a href=/brctl target=brctl>brctl</a>  <a target=server href=/server >server</a>
77  <a href=/ip target=ip>ip</a>  <a target=server href=/brctl >brctl</a>
78  <a href=/nmap target=nmap>nmap</a>  <a target=server href=/ip >ip</a>
79  <a href=/client target=client>client</a>  |
80  <a href=$couch_url target=couchdb>couchdb</a>  <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>  </div>
86    
87  }}  }}
# Line 114  sub static { Line 118  sub static {
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    
# Line 142  sub redirect { Line 146  sub redirect {
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    
# Line 238  warn "XXX pids = ", dump( $daemons::pids Line 247  warn "XXX pids = ", dump( $daemons::pids
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    
# Line 261  warn "XXX pids = ", dump( $daemons::pids Line 270  warn "XXX pids = ", dump( $daemons::pids
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                    store::query( sub {
297                            my $o = shift;
298                            my $p = delete( $o->{package} );
299                            delete( $o->{_id} );
300    
301                            if ( ! @cols ) {
302                                    #@cols = keys %$p;
303                                    @cols = qw( time name );
304                                    print $client qq|<tr><th>|
305                                            , join(qq|</th><th>|, @cols)
306                                            , qq|</th><th></th></tr>|
307                                    ;
308                            }
309    
310                            # XXX sigh, dump dies if we don't do this
311    #                       delete $o->{$_} foreach ( grep { ! defined $o->{$_} } keys %$o );
312    
313                            print $client qq|<tr$s1>|
314                                    , strftime( qq|<td title="%Y-%m-%d">%H:%M:%S</td>|, localtime($p->{time}) )
315                                    , map { qq|<td>$_<td>| } ( $p->{name} , html::pre_dump($o) )
316                                    , qq|</tr>\n|
317                            ;
318                            ( $s1, $s2 ) = ( $s2, $s1 );
319                    });
320                    print $client qq|</table>|;
321    
322          } elsif ( $path =~ m!^/client(?:/$RE{net}{IPv4}{-keep})?! ) {          } elsif ( $path =~ m!^/client(?:/$RE{net}{IPv4}{-keep})?! ) {
323                  my $ip = $1;                  my $ip = $1;
324                  $title = $ip if $ip;                  $title = $ip if $ip;
# Line 335  warn "XXX pids = ", dump( $daemons::pids Line 393  warn "XXX pids = ", dump( $daemons::pids
393    
394                  } else {                  } else {
395    
396                            print $client ok qq|<h2>Clients on $server::ip</h2>|;
397    
398                          my @ping;                          my @ping;
399                          if ( my $host = $param->{ping_target} ) {                          if ( my $host = $param->{ping_target} ) {
400                                  @ping = ( $host );                                  @ping = ( $host );
# Line 345  warn "XXX pids = ", dump( $daemons::pids Line 405  warn "XXX pids = ", dump( $daemons::pids
405                          my $ping = ping::fping( @ping ) if @ping;                          my $ping = ping::fping( @ping ) if @ping;
406                          my $arp = client::arp_mac_dev;                          my $arp = client::arp_mac_dev;
407    
408                          print $client ok                          my @clients;
409                                  , qq|<h2>Clients on $server::ip</h2>|  
410                                  , html::table( -5,                          foreach my $ip ( client::all_ips ) {
411                                          'ip', 'mac', 'dev', 'hostname', 'conf',                                  
412                                          map {                                  my $conf = client::all_conf( $ip );
413                                                  my $ip = $_;                                  my $mac = delete $conf->{mac} || '';
414                                                  my $conf = client::all_conf( $ip );                                  my $dev = $arp->{$mac};
415                                                  my $mac = delete $conf->{mac} || '';  
416                                                  my $style;                                  next unless $dev || $param->{all};
417                                                  $style  
418                                                          = 'style="color:'                                  my $style
419                                                          . ( $ping->{$ip} ? 'green' : 'red' )                                          = 'style="color:'
420                                                          . '"'                                          . ( $ping->{$ip} ? 'green' : 'red' )
421                                                          if $ping;                                          . '"'
422                                                  $style ||= '';                                          if $ping;
423                                                  my $ip_text = qq|<tt>$ip</tt>|;  
424                                                  $ip_text = qq|<tt><b>$ip</b></tt>| if ip::in_dhcp_range($ip);                                  $style ||= '';
425                                                  (                                  my $ip_text = qq|<tt>$ip</tt>|;
426                                                          qq|<a $style name=$ip target=$ip href=/client/$ip>$ip_text</a>|                                  $ip_text = qq|<tt><b>$ip</b></tt>| if ip::in_dhcp_range($ip);
427                                                          , format::mac( $mac => 'html' )  
428                                                          , $arp->{$mac}                                  $dev = qq|<tt>$dev</tt>| if $dev;
429                                                          , delete $conf->{hostname}  
430                                                          , html::conf( $ip, $conf, 'inline' )                                  push @clients
431                                                  )                                          , qq|<a $style name=$ip target=client href=/client/$ip>$ip_text</a>|
432                                          } client::all_ips                                          , format::mac( $mac => 'html' )
433                                  )                                          , $dev
434                                            , delete $conf->{hostname}
435                                            , html::conf( $ip, $conf, 'inline' )
436                                  ;                                  ;
437                            }
438    
439                            my $all = $param->{all} ? 0 : 1;
440    
441                            print $client html::table( -5, 'ip', 'mac', qq|<a href="?all=$all">dev</a>|, 'hostname', 'conf', @clients );
442                          print $client qq|                          print $client qq|
443                                  <form method=get>                                  <form method=get>
444                                  <input type=text   name=ping_target   size=15>                                  <input type=text   name=ping_target   size=15>

Legend:
Removed from v.431  
changed lines
  Added in v.493

  ViewVC Help
Powered by ViewVC 1.1.26