--- lib/PXElator/httpd.pm 2009/08/10 16:36:16 193
+++ lib/PXElator/httpd.pm 2009/08/13 13:06:18 216
@@ -50,6 +50,7 @@
use browser;
use network;
+use CouchDB;
sub static {
my ($client,$path) = @_;
@@ -61,7 +62,6 @@
if ( my $pid = fork ) {
# parent
close($client);
- print "http static child $pid\n";
$static_pids->{$pid} = $path;
return 1;
}
@@ -81,7 +81,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 +96,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 +174,7 @@
}
}
- print $client $ok
+ print $client ok
, html::table( 2, @rows )
, $below_table
, html::tabs( log::mac_changes )
@@ -177,31 +182,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|old: $ip|,
+ 'hostname' => qq||,
);
my $deploy;
- if ( my $mac = client::mac( $ip ) ) {
+ if ( my $mac = client::mac_from_ip( $ip ) ) {
$deploy = client::conf( $ip, 'deploy' => $param->{deploy} );
push @table, (
- 'mac' => $mac,
+ 'mac' => format::mac( $mac => 'html' ),
'deploy' => html::select( 'deploy', $deploy, config::available )
);
$deploy = qq|PXElinux
| . html::pre( config::for_ip( $ip ) );
}
- print $client $ok
+ print $client ok
, qq||
@@ -225,20 +236,21 @@
warn "# arp ",dump( $arp );
- print $client $ok
+ print $client ok
, qq|Clients on $server::ip
|
, html::table( -5,
'ip', 'hostname', 'mac', 'deploy', 'arp',
map {
my $ip = $_;
$ip =~ s{^.+/ip/}{};
- my $arp = $arp->{ client::mac $ip, 'clean' };
+ my $mac = client::mac_from_ip $ip;
+ my $arp = $arp->{ $mac };
$arp = $arp ? $arp->[1] : '';
$arp =~ s{$ip}{};
(
qq|$ip|
, client::conf( $ip, 'hostname' )
- , client::mac( $ip )
+ , format::mac( $mac => 'html' )
, html::tt( client::conf( $ip, 'deploy' ) )
, $arp
);
@@ -249,7 +261,7 @@
, html::table( -3, 'mac', 'dev', 'ip',
map {
my $c = $arp->{$_};
- ( html::tt( $_ ), $c->[1], $c->[0] )
+ ( format::mac( $_ => 'html' ), $c->[1], $c->[0] )
} sort keys %$arp
)
;
@@ -257,15 +269,15 @@
} elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {
eval 'our $' . $1 . ' = ' . $2;
warn $@ if $@;
- print $client $redirect, qq|$1 = $2
Location: $url|;
+ print $client redirect($url), qq|$1 = $2
Location: $url|;
server::debug( $debug ) if $1 eq 'debug';
} elsif ( $path =~ m{^/start_stop/(\S+)} ) {
- print $client $redirect, daemons::start_stop($1);
+ print $client redirect, daemons::start_stop($1);
} elsif ( $path =~ m{^/action/([^/]+)/(.+)} ) {
$1->$2();
- print $client $redirect;
+ print $client redirect;
} elsif ( $path =~ m{^/kill/static/(\d+)} ) {
- print $client $redirect;
+ print $client redirect;
kill 1, $1 || kill 9, $2 && warn "killed $1";
} else {
print $client "HTTP/1.0 404 $path\r\nConnection: close\r\nContent-type: text/html\r\n\r\n404 $path";