/[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 66 by dpavlin, Thu Jul 30 20:15:39 2009 UTC revision 67 by dpavlin, Thu Jul 30 21:31:30 2009 UTC
# Line 30  sub DESTROY { Line 30  sub DESTROY {
30  }  }
31    
32  our $port = 7777;  our $port = 7777;
 our $debug = 0;  
33    
34  use server;  use server;
35    our $debug = server::debug;
36  our $url = "http://$server::ip:$port";  our $url = "http://$server::ip:$port";
37    
38  use html;  use html;
# Line 73  sub static { Line 73  sub static {
73          return $path;          return $path;
74  }  }
75    
 my $ok = "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n";  
   
76  use boolean;  use boolean;
77    
78  use screen;  use screen;
# Line 86  sub start_stop { Line 84  sub start_stop {
84          my $daemon = shift;          my $daemon = shift;
85          my $pid = $pids->{$daemon};          my $pid = $pids->{$daemon};
86    
87          warn "start_stop $daemon pids: ",dump( $pids );          warn "start_stop $daemon $pid pids: ",dump( $pids );
88    
89          if ( $pid ) {          if ( $pid =~ m{^\d+$} ) {
90                  warn "kill 9 $pid";                  warn "kill 9 $pid";
91                  kill 9, $pid;                  kill 9, $pid;
92                  $pids->{$daemon} = 'stopped';                  $pids->{$daemon} = 'stopped';
# Line 101  sub start_stop { Line 99  sub start_stop {
99                          return qq|$daemon pid $pid started|;                          return qq|$daemon pid $pid started|;
100                  } elsif ( defined $pid ) {                  } elsif ( defined $pid ) {
101                          # child                          # child
102                          my $eval = $daemon . '::start(' . dump(@_) . ')';                          my $eval = $daemon . '::start(' . ( @_ ? dump(@_) : '' ) . ')';
103                          warn "eval $eval";                          warn "eval $eval";
104                          eval $eval;                          eval $eval;
105                          warn "can't start $daemon: $@" if $@;                          warn "can't start $daemon: $@" if $@;
# Line 112  sub start_stop { Line 110  sub start_stop {
110          }          }
111  }  }
112    
113    my $ok =       qq|HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n|;
114    my $redirect = qq|HTTP/1.1 302 Found\r\nContent-type: text/html\r\nLocation: $url\r\n\r\n|;
115    
116  sub get_request {  sub get_request {
117          my ( $client, $path, $param ) = @_;          my ( $client, $path, $param ) = @_;
118    
# Line 133  sub get_request { Line 134  sub get_request {
134                  );                  );
135                  foreach my $name ( %$pids ) {                  foreach my $name ( %$pids ) {
136                          my $pid = $pids->{$name} || next;                          my $pid = $pids->{$name} || next;
137                            my $proc = "/proc/$pid/status";
138    
139                          my $html = qq|<a href=/$name>$pid</a>|;                          my $html = qq|<a href=/$name>$pid</a>|;
140                          $html   .= qq|<pre style="font-size: 10%">|                          $html   .= qq|<pre style="font-size: 10%">|
141                                          .  ( $debug ? read_file("/proc/$pid/status") : '' )                                          .  ( $debug && -e $proc ? read_file($proc) : '' )
142                                          .  qq|</pre>| if $debug;                                          .  qq|</pre>| if $debug;
143    
144                          push @rows, ( $name => $html );                          push @rows, ( $name => $html );
# Line 147  sub get_request { Line 149  sub get_request {
149          } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {          } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {
150                  eval 'our $' . $1 . ' = ' . $2;                  eval 'our $' . $1 . ' = ' . $2;
151                  warn $@ if $@;                  warn $@ if $@;
152                  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 $redirect, qq|<big>$1 = $2</big><br>Location: <a href="$url">$url</a>|;
153                    server::debug( $debug ) if $1 eq 'debug';
154          } elsif ( $path =~ m{^/(screen|kvm)} ) {          } elsif ( $path =~ m{^/(screen|kvm)} ) {
155                  print $client $ok, start_stop($1);                  print $client $redirect, start_stop($1);
156          } elsif ( $path eq '/exit' ) {          } elsif ( $path eq '/exit' ) {
157  #               DESTROY;  #               DESTROY;
158                  exit 0;                  exit 0;

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

  ViewVC Help
Powered by ViewVC 1.1.26