--- lib/PXElator/httpd.pm 2009/08/09 22:05:09 188 +++ lib/PXElator/httpd.pm 2009/08/15 22:38:02 224 @@ -24,6 +24,7 @@
home server +ip client
@@ -49,7 +50,9 @@ use kvm; use browser; use network; +use ip; +use CouchDB; sub static { my ($client,$path) = @_; @@ -61,7 +64,6 @@ if ( my $pid = fork ) { # parent close($client); - print "http static child $pid\n"; $static_pids->{$pid} = $path; return 1; } @@ -81,7 +83,7 @@ my $buff; my $pos = 0; - warn "static $path $type $size block: $block\n"; + CouchDB::audit( 'static', { pid => $$, path => $path, type => $type, size => $size, block => $block, peerhost => $client->peerhost }); progress_bar::start; @@ -96,20 +98,25 @@ print STDERR "\n"; - warn "exit static child"; - exit(0); } -my $ok = qq|HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n| . menu(); -my $redirect = qq|HTTP/1.1 302 Found\r\nContent-type: text/html\r\nLocation: $url\r\n\r\n|; +sub ok { + qq|HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n| . menu() +} + +sub redirect { + my $to = shift; + $to ||= $url; + qq|HTTP/1.1 302 Found\r\nContent-type: text/html\r\nLocation: $to\r\n\r\n| +} sub get_request { my ( $client, $path, $param ) = @_; server->refresh; - warn "get_request $path ", $param ? dump( $param ) : '', "\n"; + CouchDB::audit( 'request', { path => $path, param => $param, peerhost => $client->peerhost } ); if ( my $found = static( $client,$path ) ) { warn "static $found" if $debug; @@ -169,7 +176,7 @@ } } - print $client $ok + print $client ok , html::table( 2, @rows ) , $below_table , html::tabs( log::mac_changes ) @@ -177,31 +184,37 @@ ; } elsif ( $path =~ m{^/server} ) { - print $client $ok + print $client ok , html::table( 2, map { ( $_, html::tt eval '$server::'.$_ ) } ( 'ip', 'netmask', 'ip_from', 'ip_to', 'domain_name', 'base_dir', 'conf' ) ) ; } elsif ( $path =~ m!^/client(?:/$RE{net}{IPv4}{-keep})?! ) { my $ip = $1 || $client->peerhost; + + if ( my $new_ip = $param->{change_ip} ) { + client::change_ip( $ip, $new_ip ); + $ip = $new_ip; + } + if ( $ip ne $server::ip ) { my $hostname = client::conf( $ip, 'hostname' => $param->{hostname} ); my @table = ( - 'ip' => $ip, - 'hostname' => qq||, + 'ip' => qq|