/[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 128 by dpavlin, Mon Aug 3 19:59:08 2009 UTC revision 159 by dpavlin, Thu Aug 6 15:40:42 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    
21    sub menu {qq{
22    
23    <div style="font-size: 80%; color: #888">
24    <a href=/>home</a>
25    <a href=/server>server</a>
26    <a href=/client>client</a>
27    </div>
28    
29    }}
30    
31  our $pids;  our $pids;
32  $pids = { httpd => $$ } unless defined $pids; # keep pids on refresh  $pids = { httpd => $$ } unless defined $pids; # keep pids on refresh
33    
# Line 38  our $url = "http://$server::ip:$port"; Line 48  our $url = "http://$server::ip:$port";
48  use html;  use html;
49  our $static_pids;  our $static_pids;
50  use progress_bar;  use progress_bar;
51    use config;
52    use client;
53    use log;
54    
55  sub static {  sub static {
56          my ($client,$path) = @_;          my ($client,$path) = @_;
# Line 91  sub static { Line 104  sub static {
104    
105  use boolean;  use boolean;
106    
 use screen;  
107  use kvm;  use kvm;
108    
109  $SIG{CHLD} = 'IGNORE';  $SIG{CHLD} = 'IGNORE';
110    
111  sub start_stop {  sub start_stop {
112          my $daemon = shift;          my $daemon = shift;
113          my $pid = $pids->{$daemon};          my $pid = $pids->{$daemon} || 'not started';
114    
115          warn "start_stop $daemon $pid\n";          warn "start_stop $daemon $pid\n";
116    
# Line 119  sub start_stop { Line 131  sub start_stop {
131                          # child                          # child
132                          my $invoke = 'start';                          my $invoke = 'start';
133                          $invoke = $1 if $daemon =~ s{/(.+)}{};                          $invoke = $1 if $daemon =~ s{/(.+)}{};
134                          my $eval = $daemon . '::' . $invoke . '(' . ( @_ ? dump(@_) : '' ) . ')';                          if ( $daemon =~ m{dhcpd|tftpd|dnsd} ) {
135                          warn "eval $eval";                                  my $exec = "perl -I$server::base_dir/lib -I$server::base_dir/lib/PXElator -M$daemon -e ${daemon}::${invoke}";
136                          eval $eval;                                  warn "exec $exec";
137                          warn "can't start $daemon: $@" if $@;                                  exec "xterm -T $daemon -n $daemon -e $exec";
138                            } else {
139                                    my $eval = $daemon . '::' . $invoke . '(' . ( @_ ? dump(@_) : '' ) . ')';
140                                    warn "eval $eval";
141                                    eval $eval;
142                                    warn "can't start $daemon: $@" if $@;
143                            }
144                          exit;                          exit;
145                  } else {                  } else {
146                          die "fork error $!";                          die "fork error $!";
# Line 144  sub get_request { Line 162  sub get_request {
162                  warn "static $found" if $debug;                  warn "static $found" if $debug;
163          } elsif ( $path eq '/' ) {          } elsif ( $path eq '/' ) {
164    
                 my $screen = $pids->{screen} ? qq|stop <tt>$pids->{screen}</tt>|        : 'start';  
                 my $kvm    = $pids->{kvm}    ? qq|stop <tt>$pids->{kvm}</tt>|           :  
                                          $pids->{screen} ? qq|start|                                                    : qq|start screen first|;  
   
165                  my @rows = (                  my @rows = (
                         'ip',           html::tt( $server::ip ),  
                         'netmask',      html::tt( $server::netmask ),  
   
166                          'debug',        qq|<a href=/our/debug/| . boolean::toggle($debug) . qq|>$debug</a>|,                          'debug',        qq|<a href=/our/debug/| . boolean::toggle($debug) . qq|>$debug</a>|,
167                  );                  );
168    
# Line 204  sub get_request { Line 215  sub get_request {
215                  }                  }
216    
217                  print $client $ok                  print $client $ok
218                            , menu()
219                          , html::table( 2, @rows )                          , html::table( 2, @rows )
220                          , $below_table                          , $below_table
221                          , html::tabs( log::mac_changes )                          , html::tabs( log::mac_changes )
222                          , $debug_proc                          , $debug_proc
223                          ;                          ;
224    
225            } elsif ( $path =~ m{^/server} ) {
226                    print $client $ok
227                            , menu()
228                            , html::table( 2, map { ( $_, eval '$server::'.$_ ) } ( 'ip', 'netmask', 'ip_from', 'ip_to', 'domain_name', 'base_dir' ) )
229                            ;
230            } elsif ( $path =~ m{^/client} ) {
231                    my $ip = $client->peerhost;
232                    my $hostname = client::conf( $ip, 'hostname' => $param->{hostname} );
233                    my $deploy   = client::conf( $ip, 'deploy'   => $param->{deploy}   );
234                    print $client $ok
235                            , menu()
236                            , qq|<form method=get>|
237                            , html::table( 2,
238                                    'ip' => $ip,
239                                    'hostname' => qq|<input type=text name=hostname value=$hostname>|,
240                                    'deploy' => html::select( 'deploy', $deploy, config::available ),
241                            )
242                            , qq|<input type=submit value=change></form><pre>|
243                            , config::for_ip( $ip )
244                            , qq|</pre>|
245                            ;
246          } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {          } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {
247                  eval 'our $' . $1 . ' = ' . $2;                  eval 'our $' . $1 . ' = ' . $2;
248                  warn $@ if $@;                  warn $@ if $@;
249                  print $client $redirect, qq|<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>|;
250                  server::debug( $debug ) if $1 eq 'debug';                  server::debug( $debug ) if $1 eq 'debug';
251          } elsif ( $path =~ m{^/start_stop/((?:screen|kvm).*)} ) { # XXX we don't want to stop all classes          } elsif ( $path =~ m{^/start_stop/(\S+)} ) {
252                  print $client $redirect, start_stop($1);                  print $client $redirect, start_stop($1);
253          } elsif ( $path =~ m{^/action/([^/]+)/(.+)} ) {          } elsif ( $path =~ m{^/action/([^/]+)/(.+)} ) {
254                  $1->$2();                  $1->$2();
# Line 242  chain http://$server::ip:$httpd::port/ Line 275  chain http://$server::ip:$httpd::port/
275  }  }
276    
277  use browser;  use browser;
278    use network;
279    
280  sub start {  sub start {
281    
282            warn 'tap ', network::tap();
283    
284          my $server = IO::Socket::INET->new(          my $server = IO::Socket::INET->new(
285                          Proto     => 'tcp',                          Proto     => 'tcp',
286                          LocalPort => $httpd::port,                          LocalPort => $httpd::port,
# Line 255  sub start { Line 291  sub start {
291          print "url $url\n";          print "url $url\n";
292    
293          start_stop 'browser', $url;          start_stop 'browser', $url;
294          start_stop 'screen';          start_stop 'dhcpd';
295            start_stop 'tftpd';
296            start_stop 'dnsd';
297          start_stop 'kvm';          start_stop 'kvm';
298    
299          while (1) {          while (1) {
# Line 280  sub start { Line 318  sub start {
318                          warn "500 $request";                          warn "500 $request";
319                  }                  }
320    
321                  print $client qq{                  print $client menu() if $client->connected;
                 <div style="font-size: 80%; color: #888">  
                 <a href="">reload</a>  
                 <a href=/>index</a>  
                 <a href=/exit>exit</a>  
                 </div>  
                 } if $client->connected;  
322    
323          }          }
324    

Legend:
Removed from v.128  
changed lines
  Added in v.159

  ViewVC Help
Powered by ViewVC 1.1.26