/[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 407 by dpavlin, Wed Sep 9 09:41:03 2009 UTC revision 482 by dpavlin, Sat Jan 23 18:31:14 2010 UTC
# Line 36  qq{ Line 36  qq{
36  </html>  </html>
37  }}  }}
38    
 sub menu {  
 qq{  
 <div style="font-size: 80%; color: #888">  
 <a href=/>home</a>  
 <a href=/server>server</a>  
 <a href=/brctl>brctl</a>  
 <a href=/ip>ip</a>  
 <a href=/nmap>nmap</a>  
 <a href=/client>client</a>  
 </div>  
   
 }}  
   
39  our $port = 7777;  our $port = 7777;
40    
41  use server;  use server;
# Line 76  use nmap; Line 63  use nmap;
63  use ping;  use ping;
64  use wol;  use wol;
65    
66  use CouchDB;  use store;
67    
68    
69    sub menu {
70            my $couch_url = $url;
71            $couch_url =~ s{:\d+.+}{:5984/_utils/};
72    qq{
73    <div style="font-size: 80%; color: #888">
74    <a target=pids href=/ >home</a>
75    |
76    <a target=server href=/server >server</a>
77    <a target=server href=/brctl >brctl</a>
78    <a target=server href=/ip >ip</a>
79    |
80    <a target=couch href=$couch_url >couchdb</a>
81    |
82    <a target=client href=/nmap >nmap</a>
83    <a target=client href=/client >client</a>
84    </div>
85    
86    }}
87    
88    
89  sub static {  sub static {
90          my ($client,$path) = @_;          my ($client,$path) = @_;
# Line 109  sub static { Line 117  sub static {
117          my $buff;          my $buff;
118          my $pos = 0;          my $pos = 0;
119    
120          CouchDB::audit( 'static', { pid => $$, path => $path, type => $type, size => $size, block => $block, peerhost => $client->peerhost });          store::audit( 'static', { pid => $$, path => $path, type => $type, size => $size, block => $block, peerhost => $client->peerhost });
121    
122          progress_bar::start;          progress_bar::start;
123    
# Line 142  sub get_request { Line 150  sub get_request {
150    
151          server->refresh;          server->refresh;
152    
153          CouchDB::audit( 'request', { path => $path, param => $param, peerhost => $client->peerhost } );          store::audit( 'request', { path => $path, param => $param, peerhost => $client->peerhost } );
154    
155          $title = $path;          $title = $path;
156    
# Line 237  warn "XXX pids = ", dump( $daemons::pids Line 245  warn "XXX pids = ", dump( $daemons::pids
245                          , 'new_clients' => qq|<input type=text name=new_clients size=3 value="$server::new_clients">|                          , 'new_clients' => qq|<input type=text name=new_clients size=3 value="$server::new_clients">|
246                  );                  );
247    
248                  foreach my $editable ( 'ip', 'netmask', 'ip_from', 'ip_to', 'domain' ) {                  foreach my $editable ( 'ip', 'bcast', 'netmask', 'ip_from', 'ip_to', 'domain' ) {
249                          my $v = eval '$server::' . $editable;                          my $v = eval '$server::' . $editable;
250                          push @table, ( $editable, qq|<input type=text name=$editable value="$v">| );                          push @table, ( $editable, qq|<input type=text name=$editable value="$v">| );
251                  }                  }
# Line 258  warn "XXX pids = ", dump( $daemons::pids Line 266  warn "XXX pids = ", dump( $daemons::pids
266    
267          } elsif ( $path =~ m!^/client(?:/$RE{net}{IPv4}{-keep})?! ) {          } elsif ( $path =~ m!^/client(?:/$RE{net}{IPv4}{-keep})?! ) {
268                  my $ip = $1;                  my $ip = $1;
269                  $title = $ip;                  $title = $ip if $ip;
270    
271                  if ( $param->{action} eq 'remove' ) {                  if ( $param->{action} eq 'remove' ) {
272                          client::remove( $param->{change_ip} );                          client::remove( $param->{change_ip} );
# Line 330  warn "XXX pids = ", dump( $daemons::pids Line 338  warn "XXX pids = ", dump( $daemons::pids
338    
339                  } else {                  } else {
340    
341                            print $client ok qq|<h2>Clients on $server::ip</h2>|;
342    
343                          my @ping;                          my @ping;
344                          if ( my $host = $param->{ping_target} ) {                          if ( my $host = $param->{ping_target} ) {
345                                  @ping = ( $host );                                  @ping = ( $host );
# Line 340  warn "XXX pids = ", dump( $daemons::pids Line 350  warn "XXX pids = ", dump( $daemons::pids
350                          my $ping = ping::fping( @ping ) if @ping;                          my $ping = ping::fping( @ping ) if @ping;
351                          my $arp = client::arp_mac_dev;                          my $arp = client::arp_mac_dev;
352    
353                          print $client ok                          my @clients;
354                                  , qq|<h2>Clients on $server::ip</h2>|  
355                                  , html::table( -5,                          foreach my $ip ( client::all_ips ) {
356                                          'ip', 'mac', 'dev', 'hostname', 'conf',                                  
357                                          map {                                  my $conf = client::all_conf( $ip );
358                                                  my $ip = $_;                                  my $mac = delete $conf->{mac} || '';
359                                                  my $conf = client::all_conf( $ip );                                  my $dev = $arp->{$mac};
360                                                  my $mac = delete $conf->{mac} || '';  
361                                                  my $style;                                  next unless $dev || $param->{all};
362                                                  $style  
363                                                          = 'style="color:'                                  my $style
364                                                          . ( $ping->{$ip} ? 'green' : 'red' )                                          = 'style="color:'
365                                                          . '"'                                          . ( $ping->{$ip} ? 'green' : 'red' )
366                                                          if $ping;                                          . '"'
367                                                  $style ||= '';                                          if $ping;
368                                                  (  
369                                                          qq|<a $style name=$ip target=$ip href=/client/$ip>$ip</a>|                                  $style ||= '';
370                                                          , format::mac( $mac => 'html' )                                  my $ip_text = qq|<tt>$ip</tt>|;
371                                                          , $arp->{$mac}                                  $ip_text = qq|<tt><b>$ip</b></tt>| if ip::in_dhcp_range($ip);
372                                                          , delete $conf->{hostname}  
373                                                          , html::conf( $ip, $conf, 'inline' )                                  $dev = qq|<tt>$dev</tt>| if $dev;
374                                                  )  
375                                          } client::all_ips                                  push @clients
376                                  )                                          , qq|<a $style name=$ip target=client href=/client/$ip>$ip_text</a>|
377                                            , format::mac( $mac => 'html' )
378                                            , $dev
379                                            , delete $conf->{hostname}
380                                            , html::conf( $ip, $conf, 'inline' )
381                                  ;                                  ;
382                            }
383    
384                            my $all = $param->{all} ? 0 : 1;
385    
386                            print $client html::table( -5, 'ip', 'mac', qq|<a href="?all=$all">dev</a>|, 'hostname', 'conf', @clients );
387                          print $client qq|                          print $client qq|
388                                  <form method=get>                                  <form method=get>
389                                  <input type=text   name=ping_target   size=15>                                  <input type=text   name=ping_target   size=15>
# Line 462  sub start { Line 481  sub start {
481    
482          my $server = IO::Socket::INET->new(          my $server = IO::Socket::INET->new(
483                          Proto     => 'tcp',                          Proto     => 'tcp',
484                          LocalAddr => $server::ip,  #                       LocalAddr => $server::ip,
485                          LocalPort => $httpd::port,                          LocalPort => $httpd::port,
486                          Listen    => SOMAXCONN,                          Listen    => SOMAXCONN,
487                          Reuse     => 1                          Reuse     => 1
# Line 477  sub start { Line 496  sub start {
496                  my $client = $server->accept() || next; # ALARM trickle us                  my $client = $server->accept() || next; # ALARM trickle us
497                  my $request = <$client>;                  my $request = <$client>;
498    
499                  warn "request $request\n" if $debug;                  my $headers;
500    
501                    while ( my $header = <$client> ) {
502                            chomp $header;
503                            last if $header =~ m{^\s*$};
504                            my ( $n, $v ) = split(/:\s*/, $header);
505                            $headers->{ lc $n } = $v;
506                    }
507    
508                    if ( my $host = $headers->{host} ) {
509                            $url = 'http://' . $host;
510                            $url .= ":$port" unless $url =~ m{:\d+$};
511                    }
512    
513                    warn "## $url ## $request", dump( $headers ) if $debug;
514    
515                  if ($request =~ m{^GET (/.*) HTTP/1.[01]}) {                  if ($request =~ m{^GET (/.*) HTTP/1.[01]}) {
516                          my $path = $1;                          my $path = $1;

Legend:
Removed from v.407  
changed lines
  Added in v.482

  ViewVC Help
Powered by ViewVC 1.1.26