/[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 45 by dpavlin, Wed Jul 29 22:04:58 2009 UTC revision 53 by dpavlin, Thu Jul 30 12:10:53 2009 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 Module::Refresh;  use Module::Refresh;
21    use Parallel::ForkManager;
22    
23  our $port = 7777;  our $port = 7777;
24  our $debug = 1;  our $debug = 1;
25    
26    my $pm = Parallel::ForkManager->new(10);
27    
28    our $screen_pid;
29    
30  use server;  use server;
31  our $url = "http://$server::ip:$port/";  our $url = "http://$server::ip:$port/";
32    
# Line 54  sub static { Line 59  sub static {
59  my $ok = "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n";  my $ok = "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n";
60    
61  use boolean;  use boolean;
62    use screen;
63    
64  sub get_request {  sub get_request {
65          my ( $client, $path, $param ) = @_;          my ( $client, $path, $param ) = @_;
66    
67          warn "get_request $client $path $param";          warn "get_request $client $path ",dump( $param );
68    
69          if ( my $found = static( $client,$path ) ) {          if ( my $found = static( $client,$path ) ) {
70                  warn "static $found" if $debug;                  warn "static $found" if $debug;
71          } elsif ( $path eq '/' ) {          } elsif ( $path eq '/' ) {
72    
73                    my $screen = $screen_pid ? qq|stop <tt>$screen_pid</tt>| : 'start';
74    
75                  print $client $ok,                  print $client $ok,
76                  html::table( 2,                  html::table( 2,
77                          'pid',   $$,                          'pid',   $$,
78                          'debug', qq|<a href=/our/debug/| . boolean::toggle($debug) . qq|>$debug</a>|,                          'debug', qq|<a href=/our/debug/| . boolean::toggle($debug) . qq|>$debug</a>|,
79                            'screen', qq|<a href=/screen>$screen</a>|,
80                  );                  );
81    
82          } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {          } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {
83                  eval 'our $' . $1 . ' = ' . $2;                  eval 'our $' . $1 . ' = ' . $2;
84                  warn $@ if $@;                  warn $@ if $@;
85                  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>|;
86            } elsif ( $path =~ m{^/screen} ) {
87    
88                    if ( $screen_pid ) {
89                            if ( ! kill $screen_pid ) {
90                                    warn "kill -9 $screen_pid";
91                                    if ( kill 9, $screen_pid ) {
92                                            print $client $ok, qq|screen pid $screen_pid stopped|;
93                                            $screen_pid = 0;
94                                    } else {
95                                            print $client $ok, qq|can't stop screen $screen_pid: $!|;
96                                    }
97                            }
98                    } else {
99                            if ( $screen_pid = $pm->start ) {
100                                    print $client $ok, qq|screen started pid $screen_pid|;
101                            } else {
102                                    screen::start;
103                                    $pm->finish;
104                            }
105                    }
106    
107          } elsif ( $path =~ m{/boot} ) {          } elsif ( $path =~ m{/boot} ) {
108                  print $client qq{$ok                  print $client qq{$ok
109  #!gpxe  #!gpxe
# Line 87  chain http://$server::ip:$httpd::port/ Line 118  chain http://$server::ip:$httpd::port/
118          }          }
119    
120  }  }
121    
122  sub start {  sub start {
123    
124          my $server = IO::Socket::INET->new(          my $server = IO::Socket::INET->new(

Legend:
Removed from v.45  
changed lines
  Added in v.53

  ViewVC Help
Powered by ViewVC 1.1.26