/[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 207 by dpavlin, Wed Aug 12 22:56:45 2009 UTC revision 243 by dpavlin, Mon Aug 17 13:25:48 2009 UTC
# Line 24  sub menu {qq{ Line 24  sub menu {qq{
24  <div style="font-size: 80%; color: #888">  <div style="font-size: 80%; color: #888">
25  <a href=/>home</a>  <a href=/>home</a>
26  <a href=/server>server</a>  <a href=/server>server</a>
27    <a href=/brctl>brctl</a>
28    <a href=/ip>ip</a>
29  <a href=/client>client</a>  <a href=/client>client</a>
30  </div>  </div>
31    
# Line 49  use daemons; Line 51  use daemons;
51  use kvm;  use kvm;
52  use browser;  use browser;
53  use network;  use network;
54    use ip;
55    use wireshark;
56    use syslogd;
57    
58  use CouchDB;  use CouchDB;
59    
# Line 63  sub static { Line 68  sub static {
68                  # parent                  # parent
69                  close($client);                  close($client);
70                  $static_pids->{$pid} = $path;                  $static_pids->{$pid} = $path;
                 CouchDB::audit('static', 'parent', { pid => $pid, path => $path });  
71                  return 1;                  return 1;
72          }          }
73    
# Line 82  sub static { Line 86  sub static {
86          my $buff;          my $buff;
87          my $pos = 0;          my $pos = 0;
88    
89          CouchDB::audit( 'static', 'child', { pid => $$, path => $path, type => $type, size => $size, block => $block });          CouchDB::audit( 'static', { pid => $$, path => $path, type => $type, size => $size, block => $block, peerhost => $client->peerhost });
90    
91          progress_bar::start;          progress_bar::start;
92    
# Line 97  sub static { Line 101  sub static {
101    
102          print STDERR "\n";          print STDERR "\n";
103    
         CouchDB::audit( 'static', 'child', 'exit', { pid => $$ } );  
   
104          exit(0);          exit(0);
105  }  }
106    
# Line 117  sub get_request { Line 119  sub get_request {
119    
120          server->refresh;          server->refresh;
121    
122          CouchDB::audit( 'request', { path => $path, param => $param } );          CouchDB::audit( 'request', { path => $path, param => $param, peerhost => $client->peerhost } );
123    
124          if ( my $found = static( $client,$path ) ) {          if ( my $found = static( $client,$path ) ) {
125                  warn "static $found" if $debug;                  warn "static $found" if $debug;
# Line 129  sub get_request { Line 131  sub get_request {
131    
132                  my $debug_proc = '';                  my $debug_proc = '';
133    
134    warn "XXX pids = ", dump( $daemons::pids );
135    
136                  foreach my $name ( sort keys %$daemons::pids ) {                  foreach my $name ( sort keys %$daemons::pids ) {
137                          my $pid = $daemons::pids->{$name} || next;                          my $pid = $daemons::pids->{$name}; # || next;
138    
139                          my $html;                          my $html;
140    
# Line 139  sub get_request { Line 143  sub get_request {
143                          if ( -e $proc ) {                          if ( -e $proc ) {
144                                  $html .= qq|<a href=/start_stop/$name>$pid</a>|;                                  $html .= qq|<a href=/start_stop/$name>$pid</a>|;
145                                  if ( $debug ) {                                  if ( $debug ) {
146                                          $html .= qq| <a name=$pid href=#proc-$pid>?</a>|;                                          $html .= qq| <a name=$pid href=#proc-$pid>?</a>| if $name->can('start');
147    
148                                          $debug_proc                                          $debug_proc
149                                                  .= qq|<a name=proc-$pid href=#$pid>$proc</a><pre style="font-size: 10%">|                                                  .= qq|<a name=proc-$pid href=#$pid>$proc</a><pre style="font-size: 10%">|
# Line 148  sub get_request { Line 152  sub get_request {
152                                                  ;                                                  ;
153                                  }                                  }
154    
155                                  if ( $name->can('start_fork') ) {                                  if ( $name->can('fork_if_active') ) {
156                                          $html .= qq| <a href=/start_stop/kvm/$_>$_</a>| foreach $name->start_fork;                                          $html .= qq| <a href=/start_stop/$name/$_>$_</a>| foreach $name->fork_if_active;
157                                  }                                  }
158    
159                                  if ( $name->can('actions') ) {                                  if ( $name->can('actions') ) {
160                                          $html .= qq| <a href=/action/kvm/$_>$_</a>| foreach $name->actions;                                          $html .= qq| <a href=/action/$name/$_>$_</a>| foreach $name->actions;
161                                  }                                  }
162                          } else {                          } else {
163                                  $html .= qq|<a href=/start_stop/$name>restart</a> $pid exited|;                                  if ( $pid =~ m{^\d+$} ) {
164                                            $html .= qq|$pid exited |
165                                    } else {
166                                            $html .= qq|$pid |;
167                                    }
168                                    $html .= qq|<a href=/start_stop/$name>restart</a>| if $pid || $name->can('start');
169                                    if ( $name->can('fork_actions') ) {
170                                            $html .= qq| <a href=/start_stop/$name/$_>$_</a>| foreach $name->fork_actions;
171                                    }
172                          }                          }
173    
174                            die "no html generated" unless $html;
175    
176                          push @rows, ( $name => $html );                          push @rows, ( $name => $html );
177                  }                  }
178    
# Line 206  sub get_request { Line 220  sub get_request {
220    
221                          my $deploy;                          my $deploy;
222    
223                          if ( my $mac = client::mac( $ip ) ) {                          if ( my $mac = client::mac_from_ip( $ip ) ) {
224                                  $deploy = client::conf( $ip, 'deploy' => $param->{deploy} );                                  $deploy = client::conf( $ip, 'deploy' => $param->{deploy} );
225                                  push @table, (                                  push @table, (
226                                          'mac' => $mac,                                          'mac' => format::mac( $mac => 'html' ),
227                                          'deploy' => html::select( 'deploy', $deploy, config::available )                                          'deploy' => html::select( 'deploy', $deploy, config::available )
228                                  );                                  );
229                                  $deploy = qq|<h2>PXElinux</h2>| . html::pre( config::for_ip( $ip ) );                                  $deploy = qq|<h2>PXElinux</h2>| . html::pre( config::for_ip( $ip ) );
# Line 246  sub get_request { Line 260  sub get_request {
260                                          map {                                          map {
261                                                  my $ip = $_;                                                  my $ip = $_;
262                                                  $ip =~ s{^.+/ip/}{};                                                  $ip =~ s{^.+/ip/}{};
263                                                  my $arp = $arp->{ client::mac $ip, 'clean' };                                                  my $mac = client::mac_from_ip $ip;
264                                                    my $arp = $arp->{ $mac };
265                                                  $arp = $arp ? $arp->[1] : '';                                                  $arp = $arp ? $arp->[1] : '';
266                                                  $arp =~ s{$ip}{};                                                  $arp =~ s{$ip}{};
267                                                  (                                                  (
268                                                          qq|<a href=/client/$ip>$ip</a>|                                                          qq|<a href=/client/$ip>$ip</a>|
269                                                          , client::conf( $ip, 'hostname' )                                                          , client::conf( $ip, 'hostname' )
270                                                          , client::mac( $ip )                                                          , format::mac( $mac => 'html' )
271                                                          , html::tt( client::conf( $ip, 'deploy' ) )                                                          , html::tt( client::conf( $ip, 'deploy' ) )
272                                                          , $arp                                                          , $arp
273                                                  );                                                  );
# Line 263  sub get_request { Line 278  sub get_request {
278                                  , html::table( -3, 'mac', 'dev', 'ip',                                  , html::table( -3, 'mac', 'dev', 'ip',
279                                          map {                                          map {
280                                                  my $c = $arp->{$_};                                                  my $c = $arp->{$_};
281                                                  ( html::tt( $_ ), $c->[1], $c->[0] )                                                  ( format::mac( $_ => 'html' ), $c->[1], $c->[0] )
282                                          } sort keys %$arp                                          } sort keys %$arp
283                                  )                                  )
284                                  ;                                  ;
285                  }                  }
286            } elsif ( $path =~ m{^/brctl} ) {
287                    print $client ok
288                            ,html::pre( `brctl show` )
289                            ;
290            } elsif ( $path =~ m{^/ip/?(\w+)?} ) {
291                    print $client ok
292                            , join("\n", map { qq|<a href=/ip/$_>$_</a>| } ( qw/link addr route neigh ntable tunnel maddr mroute xfrm/ ))
293                            , ip::html( $1 )
294                            ;
295          } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {          } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {
296                  eval 'our $' . $1 . ' = ' . $2;                  eval 'our $' . $1 . ' = ' . $2;
297                  warn $@ if $@;                  warn $@ if $@;
# Line 290  sub get_request { Line 314  sub get_request {
314    
315  sub start {  sub start {
316    
317          warn 'tap ', network::tap();          warn 'network ', network::setup();
318    
319          daemons::start_stop 'browser', $url;          daemons::start_stop 'browser', $url;
320          daemons::start_stop $_ foreach ( qw/dhcpd tftpd dnsd/ );          daemons::start_stop $_ foreach ( qw/dhcpd tftpd dnsd syslogd/ );
321          daemons::start_stop 'kvm' unless $ENV{DEV}; # skip kvm statup when running on real device          daemons::start_stop 'kvm' unless $ENV{DEV}; # skip kvm statup when running on real device
322    
323          my $server = IO::Socket::INET->new(          my $server = IO::Socket::INET->new(

Legend:
Removed from v.207  
changed lines
  Added in v.243

  ViewVC Help
Powered by ViewVC 1.1.26