--- lib/PXElator/httpd.pm 2009/07/30 14:16:59 57 +++ lib/PXElator/httpd.pm 2009/07/30 17:07:48 65 @@ -23,30 +23,42 @@ our $debug = 1; use server; -our $url = "http://$server::ip:$port/"; +our $url = "http://$server::ip:$port"; use html; sub static { my ($client,$path) = @_; - $path = "tftp/$path"; + my $full = "$server::base_dir/tftp/$path"; - if ( ! -e $path || -d $path ) { - print $client "HTTP/1.0 404 $path not found\r\n"; - return; - } + return if ! -f $full; - my $type = 'text/plain'; + my $type = 'application/octet-stream'; $type = 'text/html' if $path =~ m{\.htm}; $type = 'application/javascript' if $path =~ m{\.js}; + $type = 'text/plain' if $path =~ m{\.txt}; + + my $size = -s $full || return; + + print $client "HTTP/1.0 200 OK\r\nContent-Type: $type\r\nContent-Length: $size\r\nConnection: close\r\n\r\n"; - print $client "HTTP/1.0 200 OK\r\nContent-Type: $type\r\nContent-Length: ", -s $path,"\r\n\r\n"; - open(my $html, $path); - while(<$html>) { - print $client $_; + open(my $fh, $full); + print "static $path $type $size\n"; + + my $block = 8192; + my $buff; + my $pos = 0; + + while( my $len = read $fh, $buff, $block ) { + print $client $buff; + $pos += $len; + printf "%s %d/%d %.2f%%\r", $path, $pos, $size, $pos * 100 / $size; } - close($html); + close($fh); + close($client); + + print "$path $pos == $size OK\n"; return $path; } @@ -106,10 +118,12 @@ print $client $ok, html::table( 2, - 'pid', $$, - 'debug', qq|$debug|, - 'screen', qq|$screen|, - 'kvm', qq|$kvm|, + 'pid', html::tt( $$ ), + 'ip', html::tt( $server::ip ), + 'netmask', html::tt( $server::netmask ), + 'debug', qq|$debug|, + 'screen', qq|$screen|, + 'kvm', qq|$kvm|, ); } elsif ( $path =~ m{^/our/(\w+)/(\S+)} ) {