This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfexsend
executable file
·3854 lines (3395 loc) · 92.2 KB
/
fexsend
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl -w
# CLI client for the F*EX service (send, list, delete)
#
# see also: fexget
#
# Author: Ulli Horlacher <[email protected]>
#
# Perl Artistic Licence
use 5.006;
use strict qw'vars subs';
use Encode;
use Config;
use Socket;
use IO::Handle;
use IO::Socket::INET;
use Getopt::Std;
use File::Basename;
use Cwd qw'abs_path';
use Fcntl qw':flock :mode';
use Digest::MD5 qw'md5_hex'; # encrypted ID / SID
use Time::HiRes qw'time';
# use Smart::Comments;
use constant k => 2**10;
use constant M => 2**20;
eval 'use Net::INET6Glue::INET_is_INET6';
&update if "@ARGV" eq 'UPDATE';
$| = 1;
our ($SH,$fexhome,$idf,$tmpdir,$windoof,$macos,$useragent,$editor,$nomail);
our ($anonymous,$public);
our ($tpid,$frecipient);
our ($FEXID,$FEXXX,$HOME);
our (%alias);
our $chunksize = 0;
our $version = 20160328;
our $_0 = $0;
our $DEBUG = $ENV{DEBUG};
my %SSL = (SSL_version => 'TLSv1');
my $sigpipe;
if ($Config{osname} =~ /^mswin/i) {
# http://slu.livejournal.com/17395.html
$windoof = $Config{osname};
$HOME = $ENV{USERPROFILE};
$fexhome = $ENV{FEXHOME} || $HOME.'\fex';
$tmpdir = $ENV{FEXTMP} || $ENV{TEMP} || "$fexhome\\tmp";
$idf = "$fexhome\\id";
$editor = $ENV{EDITOR} || 'notepad.exe';
$useragent = sprintf("fexsend-$version (%s %s)",
$Config{osname},$Config{archname});
$SSL{SSL_verify_mode} = 0;
} elsif ($Config{osname} =~ /^darwin/i or $ENV{MACOS}) {
# http://stackoverflow.com/questions/989349/running-a-command-in-a-new-mac-os-x-terminal-window
$macos = $Config{osname};
$HOME = (getpwuid($<))[7]||$ENV{HOME};
$fexhome = $HOME.'/.fex';
$tmpdir = $ENV{FEXTMP} || $ENV{TMPDIR} || "$fexhome/tmp";
$tmpdir =~ s:/$::;
$idf = "$fexhome/id";
chmod 0600,$idf;
$editor = $ENV{EDITOR} || 'open -W -n -e';
$_ = `sw_vers -productVersion 2>/dev/null`||'';
chomp;
$useragent = "fexsend-$version (MacOS $_)";
} else {
$0 =~ s:.*/::;
$HOME = (getpwuid($<))[7]||$ENV{HOME};
$fexhome = $HOME.'/.fex';
$tmpdir = $ENV{FEXTMP} || "$fexhome/tmp";
$idf = "$fexhome/id";
chmod 0600,$idf;
$editor = $ENV{EDITOR} || 'vi';
$_ = `(lsb_release -d||uname -a)2>/dev/null`||'';
chomp;
s/^Description:\s+//;
$useragent = "fexsend-$version ($_)";
}
if (-f ($_ = '/etc/fex/config.pl')) {
eval { require } or warn $@;
}
my $from = '';
my $to = '';
my $id = '';
my $skey = '';
my $gkey = '';
my $atype = ''; # archive type
my $fexcgi; # F*EX CGI URL
my @files; # files to send
my %AB = (); # server based address book
my ($server,$port,$sid,$https);
my $proxy = '';
my $proxy_prefix = '';
my $features = '';
my $timeout = 30; # server timeout
my $fexlist = "$tmpdir/fexlist";
my ($usage,$hints);
my $xx = $0 =~ /\bxx$/;
if ($xx) {
$usage = "usage: send file(s): xx [:slot] file...\n".
" or: send STDIN: xx [:slot] -\n".
" or: send pipe: ... | xx [:slot] \n".
" or: get file(s) or STDIN: xx [:slot] \n".
" or: get file(s) no-questions: xx [:slot] --\n".
"examples: dmesg | xx\n".
" xx project\n".
" xx --\n".
" xx :conf /etc /boot\n";
} else {
$usage = <<EOD;
usage: $0 [options] file(s) [@] recipient(s)
or: $0 [special options]
or: $0 -l [recipient-regexp]
or: $0 -f \# recipient(s)
or: $0 -x \# [-C -k -D -K -S]
options: -v verbose mode
-d delete file on fex server
-c compress file with gzip
-g encrypt file with gpg
-m limit limit throughput (kB/s)
-i account use ID data [account] from ID file
-C comment add comment to notification e-mail
-k max keep file max days on fex server
-D delay auto-delete after download
-K no auto-delete after download
-M MIME-file (to be displayed in recipient\'s webbrowser)
-o overwrite mode, do not resume
-a archive put files in archive (.zip .7z .tar .tgz)
-s stream read data from pipe and upload it with stream name
special options: -I initialize ID file or show ID
-I account add alternate ID data (secondary logins) to ID file
-l list sent files numbers (# needed for -f -x -d -N)
-f \# forward already uploaded file to another recipient
-x \# use -C -k -D -K for already uploaded file
-d \# delete file on fex server
-N \# resend notification e-mail
-Q check quotas
-T up:down test internet speed with up and down MBs
-A edit server address book (aliases)
-S show server/user settings and auth-ID
-H show hints, examples and more options
-V show version and ask for upgrade
(# is a file number, see output from $0 -l)
examples: $0 visualization.mpg framstag\@rus.uni-stuttgart.de
$0 -a images.zip *.jpg webmaster\@flupp.org,metoo
lshw | $0 -s hardware.list admin\@flupp.org
EOD
# or: $0 -R FEX-URL e-mail
# -R FEX mail self-register your e-mail address at FEX server
$hints = <<EOD;
$0 hints and more options:
usage: $0 [options] file recipient(s)
Recipient can be a comma separated address list. Example:
$0 big.file framstag\@rus.uni-stuttgart.de,webmaster\@flupp.org
Recipient can be an alias from your server address book
(use "$0 -A" to edit it). Example:
$0 big.file framstag
Recipient can be a SKEY URL, which you have received from a regular F*EX user.
When using this URL you are a subuser of this full user and the file will be
sent to him. Example:
$0 big.file http://fex.rus.uni-stuttgart.de/fup?skey=4285f8cdd881626524fba686d5f0a83a
Recipient can be a GKEY URL, which you have received from a regular F*EX user.
Using this URL you are a member of his group and the file will be sent to all
members of this group. Example:
$0 big.file http://fex.rus.uni-stuttgart.de/fup?gkey=50d26547b1e8c1110beb8748fc1d9444
When you use "FEX-URL/anonymous" as recipient and your F*EX administrator has
allowed anonymous upload for your IP address then no auth-ID is needed.
"." as recipient means fex to yourself and show immediately the download URL
(no notification e-mail will be sent). Example:
$0 software.tar .
"//" as recipient means fex to yourself and create extra short download URL.
Example:
$0 software.tar //
If you want a Bcc of the notification e-mail then add '!bcc!' to the comment:
fexsend -C '!bcc! for me and you' ...
Additional special options:
-. sends a short instead of a detailed notification e-mail
-/ does not upload the file, but tells the server to link it
-= uses an alias name as file name
-# excludes files (# is list separator) from archive -a
-n sends no notification e-mail, but shows the download URL immediately
-q is quiet mode
-r ADDRESS sets e-mail Reply-To ADDRESS
-F activates female mode
-U show authorized URL
-+ is an undocumented feature - test it :-)
To manage your subuser and groups or forward or redirect files, use a
webbrowser with the URL from "$0 -U", e.g.: firefox \$($0 -U)
If you want to copy-forward an already uploaded file to another recipient,
then you first have to query the file number with:
$0 -l
and then copy-forward it with:
$0 -b # other\@address
Where # is the file number.
You can list an uploaded file in more detail with
$0 -l #
Where # is the file number.
If you want to modify the keep time, comment or auto-delete behaviour of an
already uploaded file then you first have to query the file number with:
$0 -l
and then for example set the keep time to 30 days with:
$0 -x # -k 30
Where # is the file number.
With option -a you can send several files or whole directories within a single
archive file. The archive types tar and tgz are build on-the-fly (streaming)
whereas archive types zip and 7z need a temporary archive file on local disk.
With option -s you can send any data coming from a pipe (STDIN) as a file
without wasting local disc space.
With option -X you can specify any URL parameter, e.g.:
fexsend -X autodelete=yes ...
fexsend -X 'autodelete=no&locale=german' ...
For HTTPS you can set the environment variables:
SSLVERIFY=1 # activate server identity verification
SSLVERSION=TLSv1 # this is the default
SSLCAPATH=/etc/ssl/certs # path to trusted (root) certificates
SSLCAFILE=/etc/ssl/cert.pem # file with trusted (root) certificates
SSLCIPHERLIST=HIGH:!3DES # see http://www.openssl.org/docs/apps/ciphers.html
Partner program xx is an internet clipboard. See: xx -h
Partner program fexget is for downloading. See: fexget -h
For temporary usage of a HTTP proxy use:
$0 -P your_proxy:port:chunksize_in_MB file recipient
Example:
$0 -P wwwproxy.uni-stuttgart.de.de:8080:1024 4GB.tar .
For temporary usage of an alternative F*EX server or user use:
FEXID="FEXSERVER USER AUTHID" $0 file recipient
Example:
FEXID="fex.flupp.org gaga\@flupp.org blubb" $0 big.file framstag\@rus.uni-stuttgart.de
You can define aliases (and optional fexsend options) in \$HOME/.fex/config.pl:
%alias = (
'alias1' => 'user1\@domain1.org',
'alias2' => 'user2\@domain2.org',
'both' => 'user1\@domain1.org,user2\@domain2.org',
'extra' => 'extra\@special.net:-i other -K -k 30',
);
fexsend also respects aliases in $HOME/.mutt/aliases
The alias priority is (descending):
\$HOME/.fex/config.pl
\$HOME/.mutt/aliases
fexserver address book
In \$HOME/.fex/config.pl you can also set the SSL* environment variables and the
\$opt_* variables, e.g.:
\$ENV{SSLVERSION} = 'TLSv1';
\${'opt_+'} = 1;
\$opt_m = 200;
EOD
}
my @rcamel = (
'[A
_ _ c*_)
/ \/ \//
*=( __ /
\\\\/\\\\/
',
"[A \\\\/\\\\/ \n",
"[A //\\\\//\\\\\n"
);
my @rrcamel = (
'[A
(_*p _ _
\\\\/ \/ \\
\ __ )=*
//\\\\//\\\\
',
"[A \\\\/\\\\/ \n",
"[A //\\\\//\\\\\n"
);
autoflush STDOUT;
autoflush STDERR;
if ($windoof and not @ARGV and not $ENV{PROMPT}) {
# restart with cmd.exe to have mouse cut+paste
exec qw'cmd /k',$0,'-W';
exit;
}
unless (-d $fexhome) {
mkdir $fexhome,0700 or die "$0: cannot create FEXHOME $fexhome - $!\n";
}
unless (-d $tmpdir) {
mkdir $tmpdir,0700 or die "$0: cannot create tmpdir $tmpdir - $!\n";
}
my @_ARGV = @ARGV; # save arguments
our ($opt_q,$opt_h,$opt_H,$opt_v,$opt_m,$opt_c,$opt_k,$opt_d,$opt_l,$opt_I,
$opt_K,$opt_D,$opt_u,$opt_f,$opt_a,$opt_C,$opt_R,$opt_M,$opt_L,$opt_Q,
$opt_A,$opt_i,$opt_z,$opt_Z,$opt_b,$opt_P,$opt_x,$opt_X,$opt_V,$opt_U,
$opt_s,$opt_o,$opt_g,$opt_F,$opt_n,$opt_r,$opt_S,$opt_N,$opt_T);
if ($xx) {
$opt_q = 1 if @ARGV and $ARGV[-1] eq '--' and pop @ARGV or not -t STDOUT;
$opt_h = $opt_v = $opt_m = $opt_I = 0;
$opt_X = '';
$_ = "$fexhome/config.pl"; require if -f;
getopts('hvIm:') or die $usage;
} else {
if ($macos and not @ARGV) {
&ask_file;
}
$opt_h = $opt_v = $opt_m = $opt_c = $opt_k = $opt_d = $opt_l = $opt_I = 0;
$opt_H = $opt_K = $opt_D = $opt_R = $opt_M = $opt_L = $opt_Q = $opt_A = 0;
$opt_x = $opt_o = $opt_g = $opt_V = $opt_U = $opt_F = $opt_n = $opt_q = 0;
$opt_S = $opt_N = 0;
${'opt_@'} = ${'opt_!'} = ${'opt_+'} = ${'opt_.'} = ${'opt_/'} = 0;
${'opt_='} = ${'opt_#'} = '';
$opt_u = $opt_f = $opt_a = $opt_C = $opt_i = $opt_b = $opt_P = $opt_X = '';
$opt_s = $opt_r = $opt_T = '';
$_ = "$fexhome/config.pl"; require if -f;
getopts('hHvcdognVDKlILUARWMFzZqQS@!+./r:m:k:u:f:a:s:C:i:b:P:x:X:N:T:=:#:')
or die $usage;
if ($opt_H) {
print $hints;
exit;
}
if ($opt_V) {
print "Version: $version\n";
unless (@ARGV) {
print "Upgrade fexsend? ";
$_ = <STDIN>||'';
if (/^y/i) {
my $new = `wget -nv -O- http://fex.belwue.de/download/fexsend`;
if ($new !~ /upgrade fexsend/) {
die "$0: bad update\n";
}
system qw'cp -aL',$_0,$_0.'_old';
exit $? if $?;
open $_0,'>',$_0 or die "$0: cannot write $_0. - $!\n";
print {$_0} $new;
close $_0;
exec $_0,qw'-V .';
}
}
exit if "@ARGV" eq '.';
}
if ($opt_K and $opt_D) {
die "$0: you cannot use both options -D and -K\n";
}
if ($opt_a and $opt_c) {
die "$0: you cannot use both options -a and -c\n";
}
if ($opt_a and $opt_s) {
die "$0: you cannot use both options -a and -s\n";
}
if ($opt_g and $opt_c) {
$opt_c = 0;
}
$opt_f ||= $opt_b;
if ($opt_f and $opt_f !~ /^\d+$/) {
die "$0: option -f needs a number, see $0 -l\n";
}
if ($opt_I and $opt_R) {
die "$0: you cannot use both options -I and -R\n";
}
# $opt_C is COMMENT command in F*EX protocol
$opt_C =
($opt_d) ? 'DELETE':
($opt_l or $opt_L) ? 'LIST':
($opt_Q) ? 'CHECKQUOTA':
($opt_S) ? 'LISTSETTINGS':
($opt_Z) ? 'RECEIVEDLOG':
($opt_z) ? 'SENDLOG':
(${'opt_!'}) ? 'FOPLOG':
$opt_C;
$opt_D =
($opt_D) ? 'DELAY':
($opt_K) ? 'NO':
$opt_D;
}
&get_ssl_env;
if ($opt_h) {
female_mode("show help?") if $opt_F;
print $usage;
exit;
}
if ($opt_R) {
®ister;
exit;
}
die $usage if $opt_m and $opt_m !~ /^\d+/;
if ($opt_P) {
if ($opt_P =~ /^([\w.-]+:\d+)(:(\d+))?/) {
$proxy = $1;
$chunksize = $3 || 0;
} else {
die "$0: proxy must be: SERVER:PORT\n";
}
}
if ($FEXID = $ENV{FEXID}) {
$FEXID = decode_b64($FEXID) if $FEXID !~ /\s/;
($fexcgi,$from,$id) = split(/\s+/,$FEXID);
} else {
if ($windoof and not -f $idf) { &init_id }
if (open $idf,$idf) {
&get_id($idf);
close $idf;
}
}
if ($xx) {
# convert old idxx file
if ($idf and open $idf,$idf.'xx') {
&get_id($idf);
close $idf;
if (open $idf,'>>',$idf) {
print {$idf} "\n[xx]\n",
"$fexcgi\n",
"$from\n",
"$id\n";
close $idf;
unlink $idf.'xx';
}
}
# special xx ID?
if ($FEXXX = $ENV{FEXXX}) {
$FEXXX = decode_b64($FEXXX) if $FEXXX !~ /\s/;
($fexcgi,$from,$id) = split(/\s+/,$FEXXX);
} elsif (open $idf,$idf) {
while (<$idf>) {
if (/^\[xx\]/) {
$proxy = $proxy_prefix = '';
&get_id($idf);
last;
}
}
close $idf;
}
} else {
# alternativ ID?
if ($opt_i) {
$proxy = $proxy_prefix = '';
open $idf,$idf or die "$0: cannot open $idf - $!\n";
while (<$idf>) {
if (/^\[$opt_i\]/) {
&get_id($idf);
last;
}
}
close $idf;
die "$0: no [$opt_i] in $idf\n" unless $_;
}
}
if ($opt_I) {
if ($xx) { &show_id }
else { &init_id }
exit;
}
if ($opt_T) {
my ($up,$down);
$usage = "usage: $0 -T MB_up[:MB_down] [fexserver]\n";
if ($opt_T =~ /^(\d+)$/) {
$up = $down = $1;
} elsif ($opt_T =~ /^(\d+):(\d+)$/) {
$up = $1;
$down = $2;
} else {
die $usage;
}
if (@ARGV) {
nettest($ARGV[0],$up,$down);
} elsif ($fexcgi) {
nettest($fexcgi,$up,$down);
} else {
nettest('fex.belwue.de',$up,$down);
}
exit;
}
if (@ARGV > 1 and $ARGV[-1] =~ /(^|\/)anonymous/) {
$fexcgi = $1 if $ARGV[-1] =~ s:(.+)/::;
die "usage: $0 [options] file FEXSERVER/anonymous\n" unless $fexcgi;
$anonymous = $from = 'anonymous';
$sid = $id = 'ANONYMOUS';
} elsif (@ARGV > 1 and $id eq 'PUBLIC') {
$public = $sid = $id;
} elsif (@ARGV > 1 and $ARGV[-1] =~ m{^(https?://[\w.-]+(:\d+)?/fup\?[sg]key=\w+)}) {
$fexcgi = $1;
$skey = $1 if $fexcgi =~ /skey=(\w+)/;
$gkey = $1 if $fexcgi =~ /gkey=(\w+)/;
} else {
$fexcgi = $opt_u if $opt_u;
if (not -e $idf and not ($fexcgi and $from and $id)) {
die "$0: no ID file $idf found, use \"fexsend -I\" to create it\n";
}
unless ($fexcgi) {
die "$0: no FEX URL found, use \"$0 -u URL\" or \"$0 -I\"\n";
}
unless ($from and $id) {
die "$0: no sender found, use \"$0 -f FROM:ID\" or \"$0 -I\"\n";
}
if ($fexcgi !~ /^http/) {
if ($fexcgi =~ /:443/) { $fexcgi = "https://$fexcgi" }
else { $fexcgi = "http://$fexcgi" }
}
}
$server = $fexcgi;
$port = 80;
$port = 443 if $server =~ s{https://}{};
$port = $1 if $server =~ s/:(\d+)//;
if ($port == 443) {
# $opt_s and die "$0: cannot use -s with https due to stunnel bug\n";
# $opt_g and die "$0: cannot use -g with https due to stunnel bug\n";
$https = $port;
}
$server =~ s{http://}{};
$server =~ s{/.*}{};
# $chunksize = 4*k unless $chunksize;
$chunksize *= M;
if ($proxy) {
if ($port == 80) { $proxy_prefix = "http://$server" }
elsif ($port != 443) { $proxy_prefix = "http://$server:$port" }
}
# xx: special file exchange between own accounts
if ($xx) {
my $transferfile = "$tmpdir/STDFEX";
# slot?
if ($0 eq 'xxx') {
$transferfile = "$tmpdir/xx:xxx";
} elsif (@ARGV and $ARGV[0] =~ /^:([\w.=+-]+)$/) {
$transferfile = "$tmpdir/xx:$1";
shift @ARGV;
}
open my $lock,'>>',$transferfile
or die "$0: cannot write $transferfile - $!\n";
flock($lock,LOCK_EX|LOCK_NB)
or die "$0: $transferfile is locked by another process\n";
truncate $transferfile,0;
if (not @ARGV and -t) {
&get_xx($transferfile);
} else {
&send_xx($transferfile);
}
exit;
}
# regular fexsend
&inquire if $windoof and not @ARGV and not
($opt_l or $opt_L or $opt_Q or $opt_A or $opt_U or $opt_I or
$opt_f or $opt_x or $opt_N);
if (${'opt_.'}) {
$opt_C = "!SHORTMAIL! $opt_C";
}
if ($opt_n or $opt_C =~ /NOMAIL|!#!/) {
$nomail = 'NOMAIL';
}
unless ($skey or $gkey or $anonymous) {
if (not $opt_q and (
$opt_f||$opt_x||$opt_Q||$opt_l||$opt_L||$opt_U||$opt_z||$opt_Z||$opt_A
||$opt_d||${'opt_!'}||${'opt_@'})
) { warn "Server/User: $fexcgi/$from\n" }
}
if ($opt_V and not @ARGV) { exit }
if ($opt_f) { &forward }
elsif ($opt_x) { &modify }
elsif ($opt_N) { &renotify }
elsif ($opt_Q) { &query_quotas }
elsif ($opt_S) { &query_settings }
elsif ($opt_l or $opt_L) { &list }
elsif ($opt_U) { &show_URL }
elsif ($opt_z or $opt_Z or ${'opt_!'}) { &get_log }
elsif ($opt_A) { edit_address_book($from) }
elsif (${'opt_@'}) { &show_address_book }
elsif ($opt_d and $anonymous) { &purge }
elsif ($opt_d and $ARGV[-1] =~ /^\d+$/) { &delete_file_number }
else { &send_fex }
exit;
# initialize ID file or show ID
sub init_id {
my $tag;
my $proxy = '';
if ($opt_I) {
$tag = shift @ARGV;
die $usage if @ARGV;
}
$fexcgi = $from = $id = '';
unless (-d $fexhome) {
mkdir $fexhome,0700 or die "$0: cannot create FEXHOME $fexhome - $!\n";
}
# show ID
if (not $tag and open $idf,$idf) {
if ($opt_i) {
while (<$idf>) {
last if /^\[$opt_i\]/;
}
}
$fexcgi = <$idf>;
$from = <$idf>;
$id = <$idf>;
close $idf;
if ($id) {
chomp($fexcgi,$from,$id);
$FEXID = encode_b64("$fexcgi $from $id");
if (-t STDIN) {
print "# hint: to edit the ID file $idf use \"$0 -I .\" #\n";
print "export FEXID=$FEXID\n";
print "history -d \$((HISTCMD-1));history -d \$((HISTCMD-1))\n";
} else {
print "FEXID=$FEXID\n";
}
exit;
} else {
die "$0: no ID data found\n";
}
}
if ($tag and $tag eq '.') { exec $ENV{EDITOR}||'vi',$idf }
if ($tag) { print "F*EX server URL for [$tag]: " }
else { print "F*EX server URL: " }
$fexcgi = <STDIN>;
$fexcgi =~ s/[\s\n]//g;
die "you MUST provide a FEX-URL!\n" unless $fexcgi;
if ($fexcgi =~ /\?/) {
$from = $1 if $fexcgi =~ /\bfrom=(.+?)(&|$)/i;
$id = $1 if $fexcgi =~ /\bid=(.+?)(&|$)/i;
# $skey = $1 if $fexcgi =~ /\bskey=(.+?)(&|$)/i;
# $gkey = $1 if $fexcgi =~ /\bgkey=(.+?)(&|$)/i;
die "$0: cannot use GKEY URL in ID file\n" if $fexcgi =~ /gkey=/i;
die "$0: cannot use SKEY URL in ID file\n" if $fexcgi =~ /skey=/i;
$fexcgi =~ s/\?.*//;
}
unless ($fexcgi =~ /^[_:=\w\-\.\/\@\%]+$/) {
die "\"$fexcgi\" is not a legal FEX-URL!\n";
}
$fexcgi =~ s:/fup/*$::;
print "proxy address (hostname:port or empty if none): ";
$proxy = <STDIN>;
$proxy =~ s/[\s\n]//g;
if ($proxy =~ /^[\w.-]+:\d+$/) {
$proxy = "!$proxy";
} elsif ($proxy =~ /\S/) {
die "wrong proxy address format\n";
} else {
$proxy = "";
}
if ($proxy) {
print "proxy POST limit in MB (use 2048 if unknown): ";
$_ = <STDIN>;
if (/(\d+)/) {
$proxy .= "[$1]";
}
}
if ($skey) {
$from = 'SUBUSER';
$id = $skey;
} elsif ($gkey) {
$from = 'GROUPMEMBER';
$id = $gkey;
} else {
unless ($from) {
print "Your e-mail address as registered at $fexcgi: ";
$from = <STDIN>;
$from =~ s/[\s\n]//g;
die "you MUST provide your e-mail address!\n" unless $from;
}
unless ($from =~ /^[_:=\w\-\.\/\@\%\+]+$/) {
die "\"$from\" is not a legal e-mail address!\n";
}
unless ($id) {
print "Your auth-ID for $from at $fexcgi: ";
$id = <STDIN>;
$id =~ s/[\s\n]//g;
die "you MUST provide your ID!\n" unless $id;
}
}
if (open $idf,'>>',$idf) {
print {$idf} "\n[$tag]\n" if $tag and -s $idf;
print {$idf} "$fexcgi$proxy\n",
"$from\n",
"$id\n";
close $idf;
print "data written to $idf\n";
} else {
die "$0: cannot write to $idf - $!\n";
}
}
sub show_id {
my ($fexcgi,$from,$id);
if (open $idf,$idf) {
$fexcgi = <$idf>;
# $fexcgi = <$idf> if $fexcgi =~ /^\[.+\]/;
$from = <$idf>;
$id = <$idf>;
while (<$idf>) {
if (/^\[xx\]/) {
$fexcgi = <$idf>;
$from = <$idf>;
$id = <$idf>;
}
}
close $idf;
die "$0: too few data in $idf" unless defined $id;
chomp($fexcgi);
chomp($from);
chomp($id);
$FEXXX = encode_b64("$fexcgi $from $id");
if (-t STDIN) {
print "export FEXXX=$FEXXX\n";
print "history -d \$((HISTCMD-1));history -d \$((HISTCMD-1))\n";
} else {
print "FEXXX=$FEXXX\n";
}
} else {
die "$0: cannot read $idf - $!\n";
}
}
sub register {
my $fs = shift @ARGV or die $usage;
my $mail = shift @ARGV or die $usage;
my $port;
my ($server,$user,$id);
die "$0: $idf does already exist\n" if -e $idf;
if ($fs =~ /^https/) {
die "$0: cannot handle https at this time\n";
}
$fs =~ s{^http://}{};
$fs =~ s{/.*}{};
if ($fs =~ s/:(\d+)//) { $port = $1 }
else { $port = 80 }
tcpconnect($fs,$port);
sendheader("$fs:$port","GET $proxy_prefix/fur?user=$mail&verify=no HTTP/1.1");
http_response();
# header
while (<$SH>) {
s/\r//;
printf "<-- $_"if $opt_v;
last if /^\s*$/;
}
while (<$SH>) {
s/\r//;
printf "<-- $_"if $opt_v;
if (m{http://(.*)/fup\?from=(.+)&ID=(.+)}) {
$server = $1;
$user = $2;
$id = $3;
if (open F,">$idf") {
print F "$server\n",
"$user\n",
"$id\n";
close F;
chmod 0600,$idf;
print "user data written to $idf\n";
print "you can now fex!\n";
exit;
} else {
die "$0: cannot write to $idf - $!\n";
}
}
}
die "$0: no account data received from F*EX server\n";
}
# menu for MacOS users
sub menu {
my $key;
my $new;
local $_;
system 'clear';
print "\n";
print "fexsend-$version\n";
for (;;) {
if (open $idf,$idf) {
$fexcgi = getline($idf) and
$from = getline($idf) and
$id = getline($idf);
close $idf;
last if $id;
}
&set_ID;
}
print "\n";
print "$from on $fexcgi\n";
print "\n";
for (;;) {
print "\n";
print "[s] send a file or directory\n";
print "[u] update fexsend\n";
print "[l] change login data (user, server, auth-ID)\n";
print "[h] help\n";
print "[q] quit\n";
print "\n";
print "your choice: ";
$key = ReadKey(0);
if ($key eq 'q') {
print "$key\n";
print "\n";
print "Type [Cmd]W to close this window.\n";
exit;
}
if ($key eq 'h') {
print "$key\n";
print
"\n".
"With fexsend you can send files of any size to any e-mail address.\n".
"\n".
"At the recipient or file prompt [RETURN] brings you to this option menu.\n".
"\n".
"To send more than one file:\n".
"When you enter * at the file prompt, you will be first asked for an archive name\n".
"and then you can drag+drop multiple files.\n".
"\n".
"Do not forget to terminate each input line with [RETURN].\n".
"\n".
"See http://fex.rus.uni-stuttgart.de/ for more information.\n";
next;
}
if ($key eq 'u') {
print "$key\n";
if ($0 =~ m:(^/client/|/sw/):) {
print "\n";
print "use swupdate to update fexsend!\n";
next;
}
$new = $0.'.new';
system "curl http://fex.belwue.de/download/fexsend>".quote($new);
chmod 0755,$new;
system qw'perl -c',$new;
if ($? == 0) {
rename $new,$0;
exec $0;
} else {
print "\n";
print "cannot install new fexsend\n";
}
next;
}
if ($key eq 'l') {
print "$key\n";
system 'clear';
&set_ID;
next;
}
if ($key eq 's' or $key eq "\n") {
print "s\n";
&ask_file;
next;
}
}
exit;
}
# for MacOS
sub ask_file {
my ($file,$comment,$recipient,$archive,$size,$cmd,$key);
my @files;
my $qfiles;
local $_;
system 'clear';
&set_ID unless -s $idf;
print "\n";
print "Enter [RETURN] after each input line.\n";
print "\n";
for (;;) {
print "Recipient(s): ";
$recipient = <STDIN>;
chomp $recipient;
$recipient =~ s/^\s+//;
$recipient =~ s/\s+$//;
$recipient =~ s/[\s;,]+/,/g;
&menu unless $recipient;
last if $recipient =~ /\w/ or $recipient eq '.';
}
for (;;) {
print "\n";
print "Drag a file into this window or hit [RETURN] ";
print $archive ? "to continue.\n" : "for menu options.\n";
print "File to send: ";
$file = <STDIN>||'';
chomp $file;
$file =~ s/^\s+//;
$file =~ s/ $// if $file !~ /\\ $/;
&menu unless $file or $archive;
if ($file eq '*') {
print "Archive name: ";
$archive = <STDIN>||'';
chomp $archive;
next unless $archive;
$archive =~ s/^\s+//g;
$archive =~ s/\s+$//g;
$archive =~ s/[^\w=.+-]/_/g;
next;
}
if ($file) {
unless (-e $file) {
$file =~ s/\\\\/\000/g;
$file =~ s/\\//g;
$file =~ s/\000/\\/g;