/[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 65 by dpavlin, Thu Jul 30 17:07:48 2009 UTC revision 66 by dpavlin, Thu Jul 30 20:15:39 2009 UTC
# Line 19  use File::Slurp; Line 19  use File::Slurp;
19  use IO::Socket::INET;  use IO::Socket::INET;
20  use Module::Refresh;  use Module::Refresh;
21    
22    our $pids = { httpd => $$ };
23    
24    sub DESTROY {
25            warn "pids ",dump( $pids );
26            foreach ( values %$pids ) {
27                    warn "kill $_";
28                    kill 1,$_ || kill 9, $_;
29            }
30    }
31    
32  our $port = 7777;  our $port = 7777;
33  our $debug = 1;  our $debug = 0;
34    
35  use server;  use server;
36  our $url = "http://$server::ip:$port";  our $url = "http://$server::ip:$port";
# Line 69  use boolean; Line 79  use boolean;
79    
80  use screen;  use screen;
81  use kvm;  use kvm;
 our $pids;  
82    
83  $SIG{CHLD} = 'IGNORE';  $SIG{CHLD} = 'IGNORE';
84    
# Line 82  sub start_stop { Line 91  sub start_stop {
91          if ( $pid ) {          if ( $pid ) {
92                  warn "kill 9 $pid";                  warn "kill 9 $pid";
93                  kill 9, $pid;                  kill 9, $pid;
94                  delete $pids->{$daemon};                  $pids->{$daemon} = 'stopped';
95                  return qq|$daemon pid $pid stopped|;                  return qq|$daemon pid $pid stopped|;
96          } else {          } else {
97                  if ( $pid = fork ) {                  if ( $pid = fork ) {
# Line 92  sub start_stop { Line 101  sub start_stop {
101                          return qq|$daemon pid $pid started|;                          return qq|$daemon pid $pid started|;
102                  } elsif ( defined $pid ) {                  } elsif ( defined $pid ) {
103                          # child                          # child
104                          my $eval = $daemon . '::start';                          my $eval = $daemon . '::start(' . dump(@_) . ')';
105                          warn "eval $eval";                          warn "eval $eval";
106                          eval $eval;                          eval $eval;
107                          warn "can't start $daemon: $@" if $@;                          warn "can't start $daemon: $@" if $@;
# Line 116  sub get_request { Line 125  sub get_request {
125                  my $kvm    = $pids->{kvm}    ? qq|stop <tt>$pids->{kvm}</tt>|           :                  my $kvm    = $pids->{kvm}    ? qq|stop <tt>$pids->{kvm}</tt>|           :
126                                           $pids->{screen} ? qq|start|                                                    : qq|start screen first|;                                           $pids->{screen} ? qq|start|                                                    : qq|start screen first|;
127    
128                  print $client $ok,                  my @rows = (
                 html::table( 2,  
                         'pid',          html::tt( $$ ),  
129                          'ip',           html::tt( $server::ip ),                          'ip',           html::tt( $server::ip ),
130                          'netmask',      html::tt( $server::netmask ),                          'netmask',      html::tt( $server::netmask ),
131    
132                          'debug',        qq|<a href=/our/debug/| . boolean::toggle($debug) . qq|>$debug</a>|,                          'debug',        qq|<a href=/our/debug/| . boolean::toggle($debug) . qq|>$debug</a>|,
                         'screen',       qq|<a href=/screen>$screen</a>|,  
                         'kvm',          qq|<a href=/kvm>$kvm</a>|,  
133                  );                  );
134                    foreach my $name ( %$pids ) {
135                            my $pid = $pids->{$name} || next;
136    
137                            my $html = qq|<a href=/$name>$pid</a>|;
138                            $html   .= qq|<pre style="font-size: 10%">|
139                                            .  ( $debug ? read_file("/proc/$pid/status") : '' )
140                                            .  qq|</pre>| if $debug;
141    
142                            push @rows, ( $name => $html );
143                    }
144    
145                    print $client $ok, html::table( 2, @rows );
146    
147          } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {          } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {
148                  eval 'our $' . $1 . ' = ' . $2;                  eval 'our $' . $1 . ' = ' . $2;
# Line 132  sub get_request { Line 150  sub get_request {
150                  print $client qq|HTTP/1.1 302 Found\r\nLocation: $url\r\nContent-type: text/html\r\n\r\n<big>$1 = $2</big><br>Location: <a href="$url">$url</a>|;                  print $client qq|HTTP/1.1 302 Found\r\nLocation: $url\r\nContent-type: text/html\r\n\r\n<big>$1 = $2</big><br>Location: <a href="$url">$url</a>|;
151          } elsif ( $path =~ m{^/(screen|kvm)} ) {          } elsif ( $path =~ m{^/(screen|kvm)} ) {
152                  print $client $ok, start_stop($1);                  print $client $ok, start_stop($1);
153            } elsif ( $path eq '/exit' ) {
154    #               DESTROY;
155                    exit 0;
156          } elsif ( $path =~ m{/boot} ) {          } elsif ( $path =~ m{/boot} ) {
157                  print $client qq{$ok                  print $client qq{$ok
158  #!gpxe  #!gpxe
# Line 147  chain http://$server::ip:$httpd::port/ Line 168  chain http://$server::ip:$httpd::port/
168    
169  }  }
170    
171    use browser;
172    
173  sub start {  sub start {
174    
175          my $server = IO::Socket::INET->new(          my $server = IO::Socket::INET->new(
# Line 158  sub start { Line 181  sub start {
181    
182          print "url $url\n";          print "url $url\n";
183    
184          system "/mnt/llin/rest/cvs/uzbl/uzbl -u $url &";          start_stop 'browser', $url;
185            start_stop 'screen';
186            start_stop 'kvm';
187    
188          while (my $client = $server->accept()) {          while (my $client = $server->accept()) {
189                  $client->autoflush(1);                  $client->autoflush(1);
# Line 188  sub start { Line 213  sub start {
213                  print $client qq{                  print $client qq{
214                  <div style="font-size: 80%; color: #888">                  <div style="font-size: 80%; color: #888">
215                  <a href="">reload</a>                  <a href="">reload</a>
216                  <a href="/">index</a>                  <a href=/>index</a>
217                    <a href=/exit>exit</a>
218                  </div>                  </div>
219                  } if $client->connected;                  } if $client->connected;
220    

Legend:
Removed from v.65  
changed lines
  Added in v.66

  ViewVC Help
Powered by ViewVC 1.1.26