3 # client for anonymous FEX or SEX
5 # Author: Ulli Horlacher <framstag@rus.uni-stuttgart.de>
7 # Perl Artistic Licence
13 $u = $ENV{AFEX} || $fexserver || &guessserver;
14 $u = "http://$u" if $u !~ /^http/;
16 if (@ARGV and $ARGV[0] eq '-h' or not @ARGV and -t STDIN) { &usage }
18 $opt_v = (@ARGV and $ARGV[0] eq '-v') ? shift @ARGV : '';
22 if (-t STDIN and @ARGV and "@ARGV" =~ /^(\d+)( -)?$/) {
25 vexec("sexget $opt_v $a $id | tar xvf -");
27 vexec(ws("sexget $opt_v $a $id"));
30 if (@ARGV and $ARGV[0] =~ /^\d+$/) {
33 $id = sprintf("%06d",rand(1000000));
35 print "# commands for SEX recipient:\n";
37 print "wget -qO- $u/sex?anonymous=$id | tar xvf -\n";
39 print "# streaming files and waiting for SEX recipient:\n";
40 vexec("tar cvf - @ARGV | sexsend -q $opt_v $a $id");
42 print "wget -qO- $u/sex?anonymous=$id\n";
44 vexec(ws("sexsend -q $opt_v $a $id"));
52 if ("@ARGV" =~ /^-(\d+)$/) {
54 $cmd = "wget -qO/dev/null $u/fop/anonymous/anonymous/afex_$n.tar?DELETE";
62 if (-t STDIN and "@ARGV" =~ /^(\d+)( -)?$/) {
65 $u .= "/fop/anonymous/anonymous/afex_$id.tar";
67 vexec("fexget $opt_v -s- $u | tar xvf -");
69 $aft = "/tmp/afex_$id.tar";
70 $cmd = "fexget $opt_v -s- $u >$aft";
72 if (`file $aft` =~ /tar archive/) {
73 print "Files in archive:\n";
74 $cmd = "tar tvf $aft";
76 print "extract these files (Y/n)? ";
77 if ((<STDIN>||'y') =~ /^[Yy\n]/) {
78 $cmd = "tar xvf $aft";
82 print "keeping $aft\n";
85 open $aft,$aft or die "$0: cannot open $aft = $!\n";
87 print while read($aft,$_,65536);
95 if (@ARGV and $ARGV[0] =~ /^\d+$/) {
98 $id = sprintf("%06d",rand(1000000));
100 $aft = "afex_$id.tar";
101 my $durl ="$u/fop/anonymous/anonymous/$aft??ID=ANONYMOUS";
102 if (`wget -S --spider $durl 2>&1` =~ /X-Location:/) {
103 die "$0: afex $id already exists - choose another ID\n";
105 @fexsend = ws("fexsend $opt_v -o -K -k 1");
107 vsystem(@fexsend,'-a',$aft,@ARGV,"$u/anonymous");
109 } elsif (not -t STDIN) {
111 open $aft,'>',$aft or die "$0: cannot write $aft - $!\n";
112 print {$aft} $_ while read(STDIN,$_,65536);
114 $s = vsystem(@fexsend,$aft,"$u/anonymous");
118 die "say captain, say WHOT?!";
120 print "For download use:\n";
121 print "$u//$aft\n" if -t STDIN;
131 my $rc = '/etc/resolv.conf';
134 open $rc,$rc or die "$0: cannot open $rc - $!\n";
136 if (/^\s*domain\s+([\w.-]+)/) {
137 $fexserver = "http://fex.$1";
140 if (/^\s*search\s+([\w.-]+)/) {
141 $fexserver = "http://fex.$1";
154 warn "@_\n" if $opt_v;
159 warn "@_\n" if $opt_v;
165 print "file input usage: $0 [ID] files...\n";
166 print "file output usage: $0 ID [-]\n";
167 print "pipe input usage: ... | $0 [ID]\n";
168 print "pipe output usage: $0 ID | ...\n";
169 print "delete usage: $0 -ID\n";
173 print "file input usage: $0 [ID] files...\n";
174 print "file output usage: $0 ID -\n";
175 print "pipe input usage: ... | $0 [ID]\n";
176 print "pipe output usage: $0 ID | ...\n";
179 die "program name must be a afex or asex, not $0\n";