/[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 433 by dpavlin, Mon Sep 14 21:11:23 2009 UTC revision 488 by dpavlin, Sat Jan 23 21:00:01 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;
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 target=pids href=/ >home</a>  <a target=pids href=/ >home</a>
# 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=couch href=$couch_url >couchdb</a>  <a target=store href=$store_url >store</a>
81    <a target=store href=/store/query >query</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 117  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 145  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 241  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 264  warn "XXX pids = ", dump( $daemons::pids Line 270  warn "XXX pids = ", dump( $daemons::pids
270                          |                          |
271                          ;                          ;
272    
273            } elsif ( $path =~ m{^/store/query} ) {
274                    print $client ok
275                            , qq|<table>|
276                    ;
277                    store::query( sub {
278                            my $o = shift;
279                            my $p = delete( $o->{package} );
280                            delete( $o->{_id} );
281    
282                            # XXX sigh, dump dies if we don't do this
283                            delete $o->{$_} foreach ( grep { ! defined $o->{$_} } keys %$o );
284    
285                            print $client qq|<tr><td>|, join(qq|</td><td>|, map { $p->{$_} } keys %$p ), qq|</td><td><pre>|, dump( $o ), qq|</pre></td></tr>\n|;
286                    });
287                    print $client qq|</table>|;
288    
289          } elsif ( $path =~ m!^/client(?:/$RE{net}{IPv4}{-keep})?! ) {          } elsif ( $path =~ m!^/client(?:/$RE{net}{IPv4}{-keep})?! ) {
290                  my $ip = $1;                  my $ip = $1;
291                  $title = $ip if $ip;                  $title = $ip if $ip;
# Line 338  warn "XXX pids = ", dump( $daemons::pids Line 360  warn "XXX pids = ", dump( $daemons::pids
360    
361                  } else {                  } else {
362    
363                            print $client ok qq|<h2>Clients on $server::ip</h2>|;
364    
365                          my @ping;                          my @ping;
366                          if ( my $host = $param->{ping_target} ) {                          if ( my $host = $param->{ping_target} ) {
367                                  @ping = ( $host );                                  @ping = ( $host );
# Line 348  warn "XXX pids = ", dump( $daemons::pids Line 372  warn "XXX pids = ", dump( $daemons::pids
372                          my $ping = ping::fping( @ping ) if @ping;                          my $ping = ping::fping( @ping ) if @ping;
373                          my $arp = client::arp_mac_dev;                          my $arp = client::arp_mac_dev;
374    
375                          print $client ok                          my @clients;
376                                  , qq|<h2>Clients on $server::ip</h2>|  
377                                  , html::table( -5,                          foreach my $ip ( client::all_ips ) {
378                                          'ip', 'mac', 'dev', 'hostname', 'conf',                                  
379                                          map {                                  my $conf = client::all_conf( $ip );
380                                                  my $ip = $_;                                  my $mac = delete $conf->{mac} || '';
381                                                  my $conf = client::all_conf( $ip );                                  my $dev = $arp->{$mac};
382                                                  my $mac = delete $conf->{mac} || '';  
383                                                  my $style;                                  next unless $dev || $param->{all};
384                                                  $style  
385                                                          = 'style="color:'                                  my $style
386                                                          . ( $ping->{$ip} ? 'green' : 'red' )                                          = 'style="color:'
387                                                          . '"'                                          . ( $ping->{$ip} ? 'green' : 'red' )
388                                                          if $ping;                                          . '"'
389                                                  $style ||= '';                                          if $ping;
390                                                  my $ip_text = qq|<tt>$ip</tt>|;  
391                                                  $ip_text = qq|<tt><b>$ip</b></tt>| if ip::in_dhcp_range($ip);                                  $style ||= '';
392                                                  (                                  my $ip_text = qq|<tt>$ip</tt>|;
393                                                          qq|<a $style name=$ip target=client href=/client/$ip>$ip_text</a>|                                  $ip_text = qq|<tt><b>$ip</b></tt>| if ip::in_dhcp_range($ip);
394                                                          , format::mac( $mac => 'html' )  
395                                                          , $arp->{$mac}                                  $dev = qq|<tt>$dev</tt>| if $dev;
396                                                          , delete $conf->{hostname}  
397                                                          , html::conf( $ip, $conf, 'inline' )                                  push @clients
398                                                  )                                          , qq|<a $style name=$ip target=client href=/client/$ip>$ip_text</a>|
399                                          } client::all_ips                                          , format::mac( $mac => 'html' )
400                                  )                                          , $dev
401                                            , delete $conf->{hostname}
402                                            , html::conf( $ip, $conf, 'inline' )
403                                  ;                                  ;
404                            }
405    
406                            my $all = $param->{all} ? 0 : 1;
407    
408                            print $client html::table( -5, 'ip', 'mac', qq|<a href="?all=$all">dev</a>|, 'hostname', 'conf', @clients );
409                          print $client qq|                          print $client qq|
410                                  <form method=get>                                  <form method=get>
411                                  <input type=text   name=ping_target   size=15>                                  <input type=text   name=ping_target   size=15>

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

  ViewVC Help
Powered by ViewVC 1.1.26