--- lib/PXElator/httpd.pm 2009/08/09 22:05:09 188
+++ lib/PXElator/httpd.pm 2009/08/12 23:59:01 208
@@ -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,17 +182,23 @@
;
} 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;
@@ -201,7 +212,7 @@
$deploy = qq|PXElinux
| . html::pre( config::for_ip( $ip ) );
}
- print $client $ok
+ print $client ok
, qq||
@@ -212,31 +223,60 @@
print $client qq|AMT
|, amt::info( $amt );
}
} else {
- print $client $ok
+
+ my $arp = {
+ map {
+ my @c = split(/\s+/,$_);
+ if ( $#c == 5 ) {
+ ( uc $c[3] => [ $c[0] , $c[5] ] )
+ } else {
+ }
+ } read_file('/proc/net/arp')
+ };
+
+ warn "# arp ",dump( $arp );
+
+ print $client ok
, qq|Clients on $server::ip
|
- , html::table( -4,
- 'ip', 'mac', 'hostname', 'deploy',
+ , html::table( -5,
+ 'ip', 'hostname', 'mac', 'deploy', 'arp',
map {
my $ip = $_;
$ip =~ s{^.+/ip/}{};
- ( qq|$ip|, client::mac($ip), client::conf( $ip, 'hostname' ), html::tt client::conf( $ip, 'deploy' ) );
+ my $arp = $arp->{ client::mac $ip, 'clean' };
+ $arp = $arp ? $arp->[1] : '';
+ $arp =~ s{$ip}{};
+ (
+ qq|$ip|
+ , client::conf( $ip, 'hostname' )
+ , client::mac( $ip )
+ , html::tt( client::conf( $ip, 'deploy' ) )
+ , $arp
+ );
}
glob("$server::conf/ip/*")
)
+ , qq|ARP
|
+ , html::table( -3, 'mac', 'dev', 'ip',
+ map {
+ my $c = $arp->{$_};
+ ( html::tt( $_ ), $c->[1], $c->[0] )
+ } sort keys %$arp
+ )
;
}
} 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";
@@ -249,6 +289,10 @@
warn 'tap ', network::tap();
+ daemons::start_stop 'browser', $url;
+ daemons::start_stop $_ foreach ( qw/dhcpd tftpd dnsd/ );
+ daemons::start_stop 'kvm' unless $ENV{DEV}; # skip kvm statup when running on real device
+
my $server = IO::Socket::INET->new(
Proto => 'tcp',
LocalAddr => $server::ip,
@@ -259,10 +303,6 @@
print "url $url\n";
- daemons::start_stop 'browser', $url;
- daemons::start_stop $_ foreach ( qw/dhcpd tftpd dnsd/ );
- daemons::start_stop 'kvm' unless $ENV{DEV}; # skip kvm statup when running on real device
-
while (1) {
my $client = $server->accept() || next; # ALARM trickle us
my $request = <$client>;