X-Git-Url: https://git.treefish.org/fex.git/blobdiff_plain/97b87610331f53e756d032ad21db786037f921a1..20160328:/bin/fbm diff --git a/bin/fbm b/bin/fbm index d285a1e..1d9c10d 100755 --- a/bin/fbm +++ b/bin/fbm @@ -20,7 +20,7 @@ use constant M => 2**20; our ($SH,$windoof,$sigpipe,$useragent); our ($FEXSERVER); -our $version = 20150729; +our $version = 20160328; # server defaults my $server = 'fex.rus.uni-stuttgart.de'; @@ -46,7 +46,7 @@ options: -n do not store on server -P use proxy server:port examples: $0 1000 EOD - + if ($Config{osname} =~ /^mswin/i) { $windoof = $Config{osname}; $useragent = sprintf("fbm-$version (%s %s)", @@ -78,7 +78,7 @@ if ($opt_h) { exit; } -if ($opt_P) { +if ($opt_P) { if ($opt_P =~ /^[\w.-]+:\d+/) { $proxy = $opt_P; } else { @@ -111,9 +111,9 @@ print "Testing $server:\n"; id => $id, comment => $opt_n ? 'NOSTORE' : 'NOMAIL', keep => 1, - autodelete => 'YES', + autodelete => 'YES', ); - + if (not @r or not grep /\w/,@r) { die "$0: no response from server\n"; } @@ -130,12 +130,12 @@ if (($r) = grep /^Location: http/,@r) { } else { download("/ddd/$mb"); } - + exit; sub formdatapost { - my %P = @_; + my %P = @_; my ($boundary,$filename,$filesize,$length); my (@hh,@hb,@r,@pv); my ($t,$bt,$t0,$t1,$t2,$tt); @@ -148,10 +148,10 @@ sub formdatapost { @r = (); serverconnect($server,$port); - + $boundary = randstring(48); $P{command} = 'CHECKRECIPIENT'; - + # HTTP POST variables @pv = qw'from to id command'; foreach my $v (@pv) { @@ -213,7 +213,7 @@ sub formdatapost { push @hb,$P{$v}; } } - + # at last, the file push @hb,"--$boundary"; push @hb,"Content-Disposition: form-data; name=\"FILE\"; filename=\"$filename\""; @@ -242,12 +242,12 @@ sub formdatapost { pop @hb; pop @hb; nvtsend(@hh,@hb) or die "$0: server has closed the connection\n"; - + $t0 = $t2 = int(time); $t1 = 0; - + autoflush $SH 0; - + for (;;) { print {$SH} $buf or die "$0: server has closed the connection\n"; $b += $bs; @@ -275,7 +275,7 @@ sub formdatapost { } last if $bt >= $mb*M; } - + autoflush $SH 1; print {$SH} "\r\n--$boundary--\r\n"; @@ -285,14 +285,14 @@ sub formdatapost { last if @r and $r[0] =~ / 204 / and /^$/ or /<\/html>/i; push @r,$_; } - + $tt = (time-$t0)||1; printf STDERR "upload: %d MB in %d s, %d kB/s \n", int($bt/M),$tt,int($bt/k/$tt); - + close $SH; undef $SH; - + return @r; } @@ -312,7 +312,7 @@ sub serverconnect { my ($server,$port) = @_; my $connect = "CONNECT $server:$port HTTP/1.1"; local $_; - + if ($proxy) { tcpconnect(split(':',$proxy)); if ($port == 443) { @@ -337,12 +337,12 @@ sub serverconnect { # set up tcp/ip connection sub tcpconnect { my ($server,$port) = @_; - + if ($SH) { close $SH; undef $SH; } - + if ($port == 443) { eval "use IO::Socket::SSL"; die "$0: cannot load IO::Socket::SSL\n" if $@; @@ -358,25 +358,25 @@ sub tcpconnect { Proto => 'tcp', ); } - + if ($SH) { autoflush $SH 1; } else { die "$0: cannot connect $server:$port - $@\n"; } - + print "TCPCONNECT to $server:$port\n" if $opt_v; } sub nvtsend { local $SIG{PIPE} = sub { $sigpipe = "@_" }; - + $sigpipe = ''; - + die "$0: internal error: no active network handle\n" unless $SH; die "$0: remote host has closed the link\n" unless $SH->connected; - + foreach my $line (@_) { print {$SH} $line,"\r\n"; if ($sigpipe) { @@ -384,7 +384,7 @@ sub nvtsend { return 0; } } - + return 1; } @@ -403,7 +403,7 @@ sub download { local $_; serverconnect($server,$port); - + sendheader( "GET $proxy_prefix$fop HTTP/1.1", "User-Agent: $useragent", @@ -459,7 +459,7 @@ sub download { sub sendheader { my @head = @_; my $head; - + foreach $head (@head) { print "--> $head\n" if $opt_v; print {$SH} $head,"\r\n";