/[pxelator]/lib/PXElator/tftpd.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/tftpd.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 68 by dpavlin, Thu Jul 30 22:43:48 2009 UTC revision 115 by dpavlin, Sun Aug 2 12:09:02 2009 UTC
# Line 5  use strict; Line 5  use strict;
5    
6  use Net::TFTPd 0.03 qw(%OPCODES);  use Net::TFTPd 0.03 qw(%OPCODES);
7  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
8    use Module::Refresh;
9    
10  use server;  use server;
11    
# Line 16  sub path { Line 17  sub path {
17          my $glob = shift;          my $glob = shift;
18          my $path = (glob("$dir/$glob"))[0];          my $path = (glob("$dir/$glob"))[0];
19          die "can't find anything for $dir/$glob" unless $path;          die "can't find anything for $dir/$glob" unless $path;
20  warn $path;          warn 'path ', $path if $debug;
21          $path =~ s{^$dir}{};          $path =~ s{^$dir}{};
22          return $path;          return $path;
23  }  }
24    
25    STDERR->autoflush(1);
26    use progress_bar;
27    
28  sub transfer_status {  sub transfer_status {
29          my $req = shift;          my $request = shift;
30          if( $req->{'_REQUEST_'}{'OPCODE'} eq $OPCODES{'RRQ'} ) {          my $r = $request->{'_REQUEST_'} || die "no _REQUEST_ in ",dump( $request );
31                  printf "RRQ %u\/%u\r", $req->{'_REQUEST_'}{'LASTACK'}, $req->{'_REQUEST_'}{'LASTBLK'};  
32          } elsif ( $req->{'_REQUEST_'}{'OPCODE'} eq $OPCODES{'WRQ'} ) {          if( $r->{'OPCODE'} eq $OPCODES{'RRQ'} ) {
33                    progress_bar::tick( $r->{FileName}, $r->{BlkSize} * $r->{LASTACK}, $r->{BlkSize} * $r->{LASTBLK} );
34            } elsif ( $r->{'OPCODE'} eq $OPCODES{'WRQ'} ) {
35                  die "WRQ disabled";                  die "WRQ disabled";
                 printf "WRQ: %u\/%u\n", $req->{'_REQUEST_'}{'LASTBLK'}, $req->{'_REQUEST_'}{'LASTACK'};  
36          } else {          } else {
37                  warn "IGNORED: ", dump( $req );                  warn "IGNORED: ", dump( $request );
38          }          }
39  }  }
40    
41  sub tftp_request {  sub tftp_request {
42          my $request = shift;          my $request = shift;
43    
44            warn 'request: ', dump( $request ) if $debug;
45    
46            config::for_ip();
47    
48          if ( $request->{RootDir} ne $dir ) {          if ( $request->{RootDir} ne $dir ) {
49                  $request->{RootDir} = $dir;                  $request->{RootDir} = $dir;
50                  warn "new root: $dir";                  warn "new root: $dir";
51          }          }
52    
53            my $file = $request->{'_REQUEST_'}{'FileName'};
54          # received request          # received request
55          printf "Received a %s for file '%s'\n", $OPCODES{$request->{'_REQUEST_'}{'OPCODE'}}, $request->{'_REQUEST_'}{'FileName'};          print $OPCODES{$request->{'_REQUEST_'}{'OPCODE'}}, " $file\n";
56    
57            progress_bar::start;
58    
59          # process the request          # process the request
60          if( $request->processRQ() ) {          if( $request->processRQ() ) {
61                  print "OK, transfer completed successfully\n";                  print "\nOK completed $file ", -s "$dir/$file", "\n";
62          } else {          } else {
63                  warn Net::TFTPd->error;                  print "ERROR ", Net::TFTPd->error, "\n";
64                  $request->processRQ();                  $request->processRQ();
65          }          }
66    
# Line 75  sub start { Line 87  sub start {
87    
88          warn 'listener: ',dump( $listener ) if $debug;          warn 'listener: ',dump( $listener ) if $debug;
89    
90            printf "TFTP listen %s:%d timeout: %d dir: $dir\n",
91                    $listener->{LocalAddr},
92                    $listener->{LocalPort},
93                    $listener->{Timeout};
94    
95          while(1) {          while(1) {
96            
97                  printf "TFTP listen %s:%d timeout: %d dir: $dir\n",                  Module::Refresh->refresh;
                         $listener->{LocalAddr},  
                         $listener->{LocalPort},  
                         $listener->{Timeout};  
98    
99                  # wait for any request (RRQ or WRQ)                  # wait for any request (RRQ or WRQ)
100                  if(my $request = $listener->waitRQ()) {                  if(my $request = $listener->waitRQ()) {

Legend:
Removed from v.68  
changed lines
  Added in v.115

  ViewVC Help
Powered by ViewVC 1.1.26