our ($SH,$windoof,$sigpipe,$useragent);
our ($FEXSERVER);
-our $version = 20150615;
+our $version = 20160328;
# server defaults
my $server = 'fex.rus.uni-stuttgart.de';
-P use proxy server:port
examples: $0 1000
EOD
-
+
if ($Config{osname} =~ /^mswin/i) {
$windoof = $Config{osname};
$useragent = sprintf("fbm-$version (%s %s)",
exit;
}
-if ($opt_P) {
+if ($opt_P) {
if ($opt_P =~ /^[\w.-]+:\d+/) {
$proxy = $opt_P;
} else {
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";
}
} 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);
@r = ();
serverconnect($server,$port);
-
+
$boundary = randstring(48);
$P{command} = 'CHECKRECIPIENT';
-
+
# HTTP POST variables
@pv = qw'from to id command';
foreach my $v (@pv) {
push @hb,$P{$v};
}
}
-
+
# at last, the file
push @hb,"--$boundary";
push @hb,"Content-Disposition: form-data; name=\"FILE\"; filename=\"$filename\"";
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;
}
last if $bt >= $mb*M;
}
-
+
autoflush $SH 1;
print {$SH} "\r\n--$boundary--\r\n";
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;
}
my ($server,$port) = @_;
my $connect = "CONNECT $server:$port HTTP/1.1";
local $_;
-
+
if ($proxy) {
tcpconnect(split(':',$proxy));
if ($port == 443) {
# 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 $@;
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) {
return 0;
}
}
-
+
return 1;
}
local $_;
serverconnect($server,$port);
-
+
sendheader(
"GET $proxy_prefix$fop HTTP/1.1",
"User-Agent: $useragent",
sub sendheader {
my @head = @_;
my $head;
-
+
foreach $head (@head) {
print "--> $head\n" if $opt_v;
print {$SH} $head,"\r\n";