5 # Author: Ulli Horlacher <framstag@rus.uni-stuttgart.de>
8 # Sebastian Zaiser <szcode@arcor.de> (upload status)
11 BEGIN { ($ENV{PERLINIT}||'') =~ /(.+)/s and eval $1 }
15 use Fcntl qw':flock :seek :mode';
17 use Digest::MD5 qw'md5_hex';
21 (our $FEXLIB) = $ENV{FEXLIB} =~ /(.+)/;
27 our $error = 'F*EX upload ERROR';
28 our $head = "$ENV{SERVER_NAME} F*EX upload";
29 our $autodelete = 'YES';
33 our (@locales,@throttle,$bcc,$keep_max,$nomail,$nostore,$overwrite);
34 our (@local_domains,@local_rdomains,@local_hosts,@local_rhosts,);
35 our (@registration_hosts,@demo,@file_link_dirs);
39 our ($spooldir,$durl,$tmpdir,@logdir,$logdir,$docdir,$hostname,$admin,$fra);
40 our ($keep_default,$recipient_quota,$sender_quota,$fex_yourself);
41 our ($sendmail,$mdomain,$fop_auth,$mail_auth,$faillog,$amdl);
42 our ($dkeydir,$ukeydir,$akeydir,$skeydir,$gkeydir,$xkeydir);
44 our $RB; # read POST bytes (total)
50 our $seek = 0; # already sent bytes (from previous upload)
51 our $filesize = 0; # total file size
52 our $fpsize = 0; # file part size (MIME-part)
56 my $rid = ''; # real ID
57 my @header; # HTTP entity header
60 my $muser; # main user fur sub or group user
62 # load common code, local config: $FEXLIB/fex.ph
63 require "$FEXLIB/fex.pp";
65 # load fup local config
66 our ($info_1,$info_2,$info_login);
68 $locale = $ENV{LOCALE} || 'english';
70 "/var/lib/fex/locale/$locale/lib/fup.pl",
79 &check_camel unless $sid;
81 chdir $spooldir or http_die("$spooldir - $!\n");
85 my $http_client = $ENV{HTTP_USER_AGENT} || '';
86 my $cl = $ENV{X_CONTENT_LENGTH} || $ENV{CONTENT_LENGTH} || 0;
88 $fra .= '/'.$ENV{HTTP_X_FORWARDED_FOR} if $ENV{HTTP_X_FORWARDED_FOR};
90 $from = $to = $id = $file = $fkey = $comment = $command = $bwlimit = '';
91 $filename = $okey = $addto = $replyto = $submit = '';
94 $locale = untaint($ENV{LOCALE}||'');
96 my $ra = $ENV{REMOTE_ADDR}||0;
97 if (@upload_hosts and not ipin($ra,@upload_hosts)) {
99 "Uploads from your host ($ra) are not allowed.",
100 "Contact $ENV{SERVER_ADMIN} for details."
106 &parse_request; # showstatus will not come back!
110 foreach $to (@to) { $to{$to} = 1 }
111 push @to,$addto unless $to{$addto};
112 if ($submit and @to == 1) { $addto = '' }
117 if ($from eq $to and $fex_yourself =~ /^no|0$/i) {
118 http_die("fexing to yourself is not allowed");
121 $uid = randstring(8) unless $uid; # upload ID
123 # user requests for forgotten ID
124 $id_forgotten = $id if $id =~ /^"?\?"?$/;
125 if ($from and $id_forgotten and $mail_authid and not ($fop_auth or $nomail)) {
126 &check_status($from);
131 # public recipients? (needs no auth-ID for sender)
132 if ($to and $id and $id eq 'PUBLIC' and @public_recipients) {
135 http_die("missing sender e-mail address");
137 # must use $param{FROM} for checking because $from is expanded with $mdomain
138 unless (checkaddress(despace($param{FROM}))) {
139 http_die("<code>$param{FROM}</code> is not a valid e-mail address");
141 foreach my $to (@to) {
142 unless (grep /^\Q$to\E$/i,@public_recipients) {
143 http_die("<code>$to</code> is not a valid recipient");
146 $restricted = $public = $rid = $id;
149 # anonymous upload from enabled IP?
150 if ($from =~ /^anonymous@/ and
151 @anonymous_upload and ipin($ra,@anonymous_upload)) {
152 $id = $rid = $anonymous = 'anonymous';
153 if ($to =~ /^anonymous/) {
155 $autodelete{$to} = $autodelete = $specific{'autodelete'}||'NO';
157 $nomail = $anonymous;
160 $comment = 'NOMAIL' if $nomail and not $comment;
164 $to = "@to" or http_die("no recipient specified");
165 $from = readlink "$to/\@OKEY/$okey"
166 or http_die("no upload key \"<code>$okey</code>\" - ".
167 "request another one from <code>$to</code>");
168 $from = untaint($from);
171 &check_status($from) if $from;
173 # look for regular sender ID
174 if ($id and $from and not ($public or $anonymous or $okey)) {
175 if (open $from,'<',"$from/\@") {
176 # chomp($rid = <$from> || '');
177 $rid = getline($from);
179 $rid = sidhash($rid,$id);
180 # set time mark for successfull access
182 my $time = untaint(time);
183 utime $time,$time,$from;
187 # if recipient (to) is specified, we have to look for subusers later, too
189 fuplog("ERROR: $spooldir/$from/\@ $error");
190 debuglog("cannot open $spooldir/$from/\@ : $error");
191 faillog("user $from, id $id");
192 http_die("wrong user or auth-ID");
198 if ($from and $id and not ($gkey or $skey or $public or $okey)) {
199 if ($rid and $rid eq $id) {
200 # set akey link for HTTP sessions
201 # (need original id for consistant non-moving akey)
202 if (-d $akeydir and open $idf,'<',"$from/@" and my $id = getline($idf)) {
203 # akey for webbrowser or fexsend special
204 if (not $sid or ($from eq $to and ($comment eq '*')) or $command) {
205 $akey = untaint(md5_hex("$from:$id"));
206 mksymlink("$akeydir/$akey","../$from");
209 $captive = -e "$from/\@CAPTIVE";
211 fuplog("ERROR: wrong auth-ID for $from");
212 debuglog("id sent by user $from=$id, real id=$rid");
213 faillog("user $from, id $id");
214 http_die("Wrong user or auth-ID");
218 # optional $auth_hook() in fup.pl
219 if ($auth_hook and ($akey or $skey or $gkey) and $from and -d $from) {
223 # forward a copy of a file to another recipient
224 if ($akey and $dkey and $command eq 'FORWARD') {
225 my $file = untaint(readlink "$dkeydir/$dkey"||'');
226 http_die("unknown dkey <code>$dkey></code>") unless $file;
232 # modify file parameter
233 if ($akey and $dkey and $command eq 'MODIFY') {
234 my $file = untaint(readlink "$dkeydir/$dkey"||'');
235 http_die("unknown dkey <code>$dkey</code>") unless $file;
241 # copy file from incoming to outgoing spool
242 if ($akey and $dkey and $command eq 'COPY') {
243 unless ($file = readlink "$dkeydir/$dkey") {
244 http_die("No such file with DKEY=$dkey");
246 if ($file =~ m:../(.+)/(.+)/(.+):) {
247 ($to,$from,$file) = ($1,$2,$3);
249 http_die("Bad DKEY $dkey -> $file");
251 unless (-f "$to/$from/$file/data") {
252 http_die("File not found");
254 if (-e "$to/$to/$file/data") {
255 http_die("File $file already exists in your outgoing spool")
256 if (readlink("$to/$to/$file/id")||$to) ne
257 (readlink("$to/$from/$file/id")||$from);
259 mkdirp("$to/$to/$file");
260 link "$to/$from/$file/data","$to/$to/$file/data"
261 or http_die("cannot link to $to/$to/$file/data - $!\n");
262 copy("$to/$from/$file/filename","$to/$to/$file/filename");
263 copy("$to/$from/$file/id","$to/$to/$file/id");
264 open $file,'>',"$to/$to/$file/notify";
266 open $file,'>',"$to/$to/$file/download";
267 print {$file} "$to\n";
269 $dkey = randstring(8);
270 unlink "$to/$to/$file/dkey","$to/$to/$file/keep","$dkeydir/$dkey";
271 symlink "../$to/$to/$file","$dkeydir/$dkey";
272 symlink $dkey,"$to/$to/$file/dkey";
275 "HTTP/1.1 302 Found",
276 "Location: $ENV{PROTO}://$ENV{HTTP_HOST}/rup?akey=$akey&oto=$to&file=$file",
283 # delete file without download
284 if ($akey and $dkey and $command eq 'DELETE') {
285 $del = untaint(readlink "$dkeydir/$dkey"||'');
286 http_die("unknown dkey <code>$dkey</code>") unless $del;
288 $filename = filename($del);
289 if (unlink("$del/data") or unlink("$del/upload")) {
290 if (open F,'>',"$del/error") {
291 printf F "%s has been deleted by %s at %s\n",
292 $filename,$ENV{REMOTE_ADDR},isodate(time);
295 # http_header('200 OK');
296 # print html_header($head);
297 # print "<h3>$filename deleted</h3>\n";
299 "HTTP/1.1 302 Found",
300 "Location: $ENV{PROTO}://$ENV{HTTP_HOST}/fup?akey=$akey&command=LISTRECEIVED",
307 http_header('404 Not Found');
308 print html_header($head);
309 print "<h3>$filename not deleted ($s)</h3>\n";
310 print "<a href=\"/fup?akey=$akey&command=LISTRECEIVED\">continue</a>\n" if $akey;
311 print "</body></html>\n";
317 if (($from and $id and $rid eq $id or $gkey or $skey) and $command) {
319 if ($command eq 'CHECKQUOTA') {
320 http_die("illegal command \"$command\"") if $public or $anonymous;
321 nvt_print('HTTP/1.1 204 OK');
322 # nvt_print("X-SID: $ENV{SID}") if $ENV{SID};
323 ($quota,$du) = check_sender_quota($muser||$from);
324 nvt_print("X-Sender-Quota: $quota $du") if $quota;
325 ($quota,$du) = check_recipient_quota($muser||$from);
326 nvt_print("X-Recipient-Quota: $quota $du") if $quota;
331 if ($command eq 'LISTSETTINGS') {
332 http_die("illegal command \"$command\"") if $public or $anonymous;
333 nvt_print('HTTP/1.1 204 OK');
334 # nvt_print("X-SID: $ENV{SID}") if $ENV{SID};
335 ($quota,$du) = check_sender_quota($muser||$from);
336 nvt_print("X-Sender-Quota: $quota $du") if $quota;
337 ($quota,$du) = check_recipient_quota($muser||$from);
338 nvt_print("X-Recipient-Quota: $quota $du") if $quota;
339 $autodelete = lc(readlink "$from/\@AUTODELETE" || $autodelete);
340 nvt_print("X-Autodelete: $autodelete");
341 $keep = readlink "$from/\@KEEP" || $keep;
342 nvt_print("X-Default-Keep: $keep");
343 $locale = readlink "$from/\@LOCALE" || $default_locale || 'english';
344 nvt_print("X-Default-Locale: $locale");
345 $mime = -e "$from/\@MIME" ? 'yes' : 'no';
346 nvt_print("X-MIME: $mime");
351 if ($command eq 'RENOTIFY') {
352 http_die("illegal command \"$command\"") if $public or $anonymous;
355 # resend notification e-mail
356 $file = readlink("$dkeydir/$dkey")
357 or html_error($error,"illegal DKEY $dkey");
359 $file = untaint($file);
360 unlink "$file/download"; # re-allow download from any ip address
361 notify_locale($dkey,'new');
368 http_header('200 OK');
370 print html_header($head);
372 print "<h3>Files from $from, ",
373 "click on the file name to resend a notification e-mail:</h3>\n",
375 foreach $file (glob "*/$from/*") {
376 next if $file =~ m:/STDFEX$:;
377 next if $file =~ m:(.+?)/: and -l $1;
378 $size = -s "$file/data";
380 $size = int($size/$MB+0.5);
381 $filename = $comment = '';
384 if ($dkey = readlink "$file/dkey") {
387 print "\nto $to :\n";
389 if (open $file,'<',"$file/filename") {
393 if ($filename and length $filename) {
394 $filename = html_quote($filename);
398 if (open $file,'<',"$file/comment") {
399 $comment = untaint(html_quote(getline($file)));
402 my $rkeep = untaint(readlink "$file/keep"||$keep_default)
403 - int((time-mtime("$file/filename"))/$DS);
404 if ($comment =~ /NOMAIL/ or
405 (readlink "$to/\@NOTIFICATION"||'') =~ /^no/i) {
406 printf "%8s MB (%2s d) %s/%s/%s\n",
411 urlencode(basename($file));
413 printf "%8s MB (%2s d) <a href=\"%s\">%s</a>%s %s\n",
416 untaint("/fup?akey=$akey&dkey=$dkey&command=RENOTIFY"),
418 $comment ? qq' "$comment"' : '',
420 " → notification e-mail has been resent" :
427 '<p><a href="/foc?akey=$akey">back to F*EX operation control</a>'
433 if ($command =~ /^LIST(RECEIVED)?$/) {
434 http_die("illegal command \"$command\"") if $public or $anonymous;
436 if ($to and $param{'TO'} eq '*') {
437 http_header('200 OK');
438 print html_header($head);
439 # "(Format: [size] [rest keep time] [filename] [comment])<p>\n",
440 print "<h3>Files from $from:</h3>\n",
442 foreach $file (glob "*/$from/*") {
443 next if $file =~ m:/STDFEX$:;
444 next if $file =~ m:(.+?)/: and -l $1;
445 $size = -s "$file/data";
447 $size = int($size/$MB+0.5);
448 $filename = $comment = '';
451 if ($dkey = readlink "$file/dkey") {
452 # die $file if -s "$file/data" and $file =~ /^$from/;
455 print "\nto $to :\n";
457 if (open $file,'<',"$file/filename") {
461 if ($filename and length $filename) {
462 $filename = html_quote($filename);
466 if (open $file,'<',"$file/comment") {
467 $comment = untaint(html_quote(getline($file)));
470 my $rkeep = untaint(readlink "$file/keep"||$keep_default)
471 - int((time-mtime("$file/filename"))/$DS);
472 printf "%8s MB (%2s d) %s <a href=\"%s\">%s</a>%s\n",
475 stat("$file/download")?'+':'-',
476 untaint("/fup?akey=$akey&dkey=$dkey&command=FORWARD"),
478 $comment?qq( "$comment"):'';
483 '<p><a href="javascript:history.back()">back to F*EX operation control</a>'
487 # list received files
490 http_header('200 OK');
491 print html_header($head);
492 # "(Format: [size] [rest keep time] [URL] [comment])<p>\n",
493 print "<h3>Files for $to (*):</h3>\n",
495 foreach $from (glob "$to/*") {
496 next if $from =~ /[A-Z]/;
499 foreach $file (glob "$to/$from/*") {
500 next if $file =~ /\/STDFEX$/;
501 $filename = $comment = '';
502 $size = -s "$file/data";
504 $size = int($size/$MB+0.5);
505 if ($dkey = readlink "$file/dkey") {
506 print "\nfrom $from :\n" unless $url;
508 $url = "$durl/$dkey/$1";
509 unless (-l "$dkeydir/$dkey") {
510 symlink untaint("../$file"),untaint("$dkeydir/$dkey");
512 if (open $file,'<',"$file/filename") {
516 if ($filename and length $filename) {
517 $filename = html_quote($filename);
521 if (open $file,'<',"$file/comment") {
522 $comment = untaint(html_quote(getline($file)));
523 $comment = ' "'.$comment.'"';
526 my $rkeep = untaint(readlink "$file/keep"||$keep_default)
527 - int((time-mtime("$file/filename"))/$DS);
528 printf "[<a href=\"/fup?akey=%s&dkey=%s&command=DELETE\">delete</a>] ",
530 printf "[<a href=\"/fup?akey=%s&dkey=%s&command=COPY\">forward</a>] ",
532 printf "%8s MB (%2s d) <a href=\"%s\">%s</a>%s\n",
533 $size,$rkeep,$url,$filename,$comment;
539 '(*) Files for other e-mail addresses you own will not be listed here!<p>'
540 '<a href="/foc?akey=$akey">back to F*EX operation control</a>'
547 if ($command eq 'LISTSENT') {
548 http_die("illegal command \"$command\"") if $public or $anonymous;
550 http_header('200 OK');
551 print html_header($head);
552 print "<h2>Download URLs of files you have sent\n";
553 foreach $to (glob "*/$from") {
554 if (@files = glob "$to/*/data") {
556 print "<h3>to <code>$to</code> :</h3>\n";
558 foreach $file (@files) {
560 next if $file =~ /\/STDFEX$/;
561 $dkey = readlink "$file/dkey" or next;
563 print "$ENV{PROTO}://$ENV{HTTP_HOST}/fop/$dkey/$file\n";
570 '<p><a href="javascript:history.back()">back to F*EX operation control</a>'
576 if ($command eq 'FOPLOG') {
577 http_die("illegal command \"$command\"") if $public or $anonymous;
578 if (open my $log,"$logdir/fop.log") {
579 http_header('200 OK');
581 next if /\/STDFEX\s/;
582 if (s:^([^/]+)/$from/:$1 :) {
583 if (s:(\d+)/(\d+)$:$1: and $1 and $1 == $2) {
593 if ($command eq 'RECEIVEDLOG') {
594 http_die("illegal command \"$command\"") if $public or $anonymous;
595 if (open my $log,"$logdir/fup.log") {
596 http_header('200 OK');
598 next if /\sSTDFEX\s/;
611 if ($command eq 'SENDLOG') {
612 http_die("illegal command \"$command\"") if $public or $anonymous;
613 if (open my $log,"$logdir/fup.log") {
614 http_header('200 OK');
616 next if /\sSTDFEX\s/;
617 if (/(\S+\@\S+)/ and $1 eq $from) {
626 if (@to and $command eq 'CHECKRECIPIENT') {
627 http_die("illegal command \"$command\"") if $public or $anonymous;
629 nvt_print('HTTP/1.1 204 OK');
630 nvt_print("X-SID: $sid") if $sid;
631 foreach my $to (@group?@group:@to) {
632 # my $options = sprintf "(autodelete=%s,keep=%s,locale=%s)",
633 # readlink "$to/\@LOCALE"||$locale||$locale{$to}||$default_locale;
634 my $options = sprintf "(autodelete=%s,keep=%s,locale=%s,notification=%s)",
635 $autodelete{$to}||$autodelete,
636 $keep{$to}||$keep_default,
637 readlink("$to/\@LOCALE")||$default_locale,
638 readlink("$to/\@NOTIFICATION")||'full';
639 nvt_print("X-Recipient: $to $options");
642 # control back to fexsrv for further HTTP handling
646 if ($file and @to and $command eq 'DELETE') {
647 http_die("illegal command \"$command\"") if $public or $anonymous;
648 foreach (@group?@group:@to) {
650 $to =~ s/:\w+=.*//; # remove options from address
651 $del = "$to/$from/$fkey";
652 # swap to and from for special senders, see fup storage swap!
653 $del = "$from/$to/$fkey" if $from =~ /^(fexmail|anonymous)/;
656 if ($del =~ /\/\./) {
657 http_die("illegal parameter <code>$del</code>");
659 $del = untaint($del);
661 if (unlink("$del/data") or unlink("$del/upload")) {
662 if (open F,'>',"$del/error") {
663 print F "$file has been deleted by $from\n";
666 http_header('200 OK',"X-File: $del");
667 print html_header($head);
668 print "<h3>$file deleted</h3>\n";
670 http_header("404 Not Found");
671 print html_header($head);
672 print "<h3>$file not deleted</h3>\n";
675 printf "<a href=\"/fup?akey=%s&to=%s&command=LISTRECEIVED\">continue</a>\n",
678 print "</body></html>\n";
686 if ($from and $id and $rid eq $id and open my $ipr,"$from/\@UPLOAD_HOSTS") {
691 push @hosts,$_ if /\w/;
694 unless (@hosts and ipin($ra,@hosts)) {
695 http_die("<code>$from</code> is not allowed to upload from IP $ra");
700 if ($from and $id and $rid eq $id and @to and not $flink and not $seek) {
704 ($quota,$du) = check_sender_quota($muser||$from);
705 if ($quota and $du+$cl/$MB > $quota) {
706 http_die("you are overquota");
709 # check recipient quota
710 foreach my $to (@to) {
711 ($quota,$du) = check_recipient_quota($to);
712 if ($quota and $du+$cl/$MB > $quota) {
713 http_die("$to cannot receive files: is overquota");
719 # check recipients restriction
720 if ($id and $id eq $rid and $from and @to and not $public) {
724 # on secure mode "fop authorization" also check if recipient(s) exists
726 if (not $addto and $fop_auth and $id and $id eq $rid and $from and @to) {
727 my ($to_reg,$idf,$subuser);
728 foreach my $to (my @loop = @to) {
729 $to =~ s/:\w+=.*//; # remove options from address
732 if (open $idf,'<',"$to/@") {
733 $to_reg = getline($idf);
737 elsif (open $idf,'<',"$from/\@SUBUSER") {
742 ($subuser) = split ':';
743 if ($subuser eq $to or $subuser eq '*@*'
744 or $subuser =~ /^\*\@(.+)/ and $to =~ /\@\Q$1\E$/i
745 or $subuser =~ /(.+)\@\*$/ and $to =~ /^\Q$1\E\@/i) {
753 http_die("recipient <code>$to</code> is not a registered F*EX full or sub user");
760 if ($to =~ /^@(.+)/) {
762 http_die("server runs in NOMAIL mode - groups ($to) are not allowed");
764 my $gf = "$from/\@GROUP/$1";
765 if (open $gf,'<',$gf) {
768 push @group,$1 if /(.+@.+):/;
777 "HTTP/1.1 302 Found",
778 "Location: $ENV{PROTO}://$ENV{HTTP_HOST}/$redirect?akey=$akey",
785 if ($from and $id and $id eq $rid and $faillog) {
789 # display HTML form and request user data
792 if ($test) { $cgi = $test }
793 else { $cgi = $ENV{SCRIPT_NAME} }
796 # delete old cookies on logout referer
798 if ($logout and my $cookie = $ENV{HTTP_COOKIE}) {
799 while ($cookie =~ s/(\w+key)=\w+//) {
800 push @cookies,"Set-Cookie: $1=x; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";
804 if (($akey or $skey or $gkey) and $from and -d $from) {
805 # save default locale for this user
806 if (not $locale and ($ENV{HTTP_COOKIE}||'') =~ /\blocale=(\w+)/) {
809 mksymlink("$from/\@LOCALE",$locale) if $locale;
812 http_header('200 OK',@cookies);
813 # print html_header($head,'<img src="/fex_small.gif">');
814 print html_header($head);
816 if ($http_client =~ /(Konqueror|w3m)/) {
820 '<h3>Your client seems to be "$1" which is incompatible with F*EX and will probably not work!</h3>'
821 'We recommend firefox.'
827 # default "fex yourself" setting?
828 if ($from and $id and $id eq $rid and not $addto
829 and not ($gkey or $skey or $okey or $public or $anonymous)
830 and (not @to or "@to" eq $from)
831 and -f "$from/\@FEXYOURSELF")
834 $nomail = 'fexyourself';
837 # ask for recipient address(es)
838 elsif ($from and $id and $id eq $rid and ($addto or not $submit or not @to)
839 and not ($gkey or $skey or $okey or $public or $anonymous))
841 present_locales('/fup');
843 @ab = ("<option></option>");
845 # select menu from server address book
846 if (open my $AB,'<',"$from/\@ADDRESS_BOOK") {
849 if (/(\S+)[=\s]+(\S+@[\w.-]+\S*)/) {
852 push @ab,"<option>$_</option>";
860 foreach (glob "$from/\@GROUP/*") {
863 push @ab,"<option>\@$_</option>" unless /~$/;
869 my $ab64 = b64("from=$from&id=$id");
870 # '<form class="uploadform" name="upload"'
872 '<form name="upload"'
875 ' accept-charset="UTF-8"'
876 ' enctype="multipart/form-data">'
877 ' <input type="hidden" name="from" value="$from">'
878 ' <input type="hidden" name="id" value="$id">'
879 ' <table border="1">'
880 ' <tr><td>sender: <td><a href="/foc">$from</a></tr>'
881 ' <tr title="e-mail address or alias"><td>recipient(s):'
882 ' <td><input type="text" name="to" size="96" value="$to"><br>'
886 ' or select from your address book:'
887 ' <select name="addto" size="1">@ab</select>'
889 ' <input type="submit" name="addsubmit" value="add to recipients list">'
897 my $rr = "$from/\@ALLOWED_RECIPIENTS";
898 if (-s $rr and open $rr,'<',$rr) {
900 'You are a restricted user and may only fex to these recipients:<p>'
908 if (/^\@LOCAL_RDOMAINS/) {
909 foreach my $rd (@local_rdomains) {
912 } elsif (/^\@LOCAL_USERS/) {
913 foreach (glob "*/@") {
924 print qq' <input type="submit" name="submit" value="check recipient(s) and continue">';
925 if ($fex_yourself =~ /^yes|1/i) {
926 print qq' or <input type="submit" name="fexyourself" value="fex yourself">'
928 print "\n</form>\n<p>\n";
929 if ($akey and -f "$from/\@" and not $captive ) {
931 '<a href="/foc?akey=$akey">user config & operation control</a>'
935 if ($from eq $admin ) {
938 '<a href="/fac">server config & admin control</a>'
942 if (0 and -f "$docdir/FIX.jar") {
944 if ($public) { print "<a href=\"/fix?from=$from&id=$public&to=$to\">" }
945 elsif ($skey) { print "<a href=\"/fix?skey=$skey&to=$to\">" }
946 elsif ($gkey) { print "<a href=\"/fix?gkey=$gkey&to=$to\">" }
947 else { print "<a href=\"/fix?akey=$akey\">" }
948 print "Alternate Java client</a> (for files > 2 GB or sending of more than one file)\n";
951 if (-x "$FEXHOME/cgi-bin/login") {
952 print $info_login||$info_1;
957 'Warning: the recipient must not be a mailing list,'
958 'because after download the file will be no more available!'
960 'Contact <a href="mailto:$ENV{SERVER_ADMIN}">fexmaster</a> if you want to fex to a mailing list,'
961 'he can allow multiple downloads for specific addresses.'
963 'Use a <a href="/tools.html">F*EX client</a> if you want to send more than one file or resume an interrupted upload.'
971 if ($from and ($id or $okey)) {
972 $to = $group if $group;
973 present_locales($ENV{REQUEST_URI}) if $skey or $gkey or $okey;
974 # " '$ENV{PROTO}://$ENV{HTTP_HOST}/$cgi?showstatus=$uid',"
976 '<script type="text/javascript">'
977 ' function showstatus() {'
978 ' var file = document.forms["upload"].elements["file"].value;'
979 ' if (file == "") return false;'
981 " '/$cgi?showstatus=$uid',"
983 " 'width=700,height=500'"
988 ' function checkupload() {'
989 ' var file = document.forms["upload"].elements["file"].value;'
990 ' if (file == "") { alert("No file selected"); }'
993 ' function reportsize() {'
994 ' var form = document.forms["upload"];'
995 ' var filesize = form.file.files[0].size;'
996 ' // alert(filesize + " bytes");'
997 ' form.elements["filesize"].value = filesize;'
998 ' filesize = filesize.toString();'
999 ' filesize = filesize.replace(/(\\d)(?=(\\d\\d\\d)+(?!\\d))/g,"\$1,");'
1000 ' document.getElementById("filesize").innerHTML = filesize + " bytes";'
1005 '<form name="upload"'
1008 ' accept-charset="UTF-8"'
1009 ' enctype="multipart/form-data"'
1010 ' onsubmit="return showstatus();">'
1011 ' <input type="hidden" name="uid" value="$uid">'
1012 ' <input type="hidden" name="from" value="$from">'
1013 ' <input type="hidden" name="filesize" value="">'
1017 my $toh = join('<br>',@to);
1019 ' <input type="hidden" name="id" value="$public">'
1020 ' <input type="hidden" name="to" value="$to">'
1021 ' <table border="1">'
1022 ' <tr><td>sender: <td><code>$from</code></tr>'
1023 ' <tr><td>recipient:<td><code>$toh</code></tr>'
1027 ' <input type="hidden" name="okey" value="$okey">'
1028 ' <input type="hidden" name="to" value="$to">'
1029 ' <table border="1">'
1030 ' <tr><td>sender: <td>$from</tr>'
1031 ' <tr><td>recipient:<td>$to</tr>'
1035 ' <input type="hidden" name="skey" value="$skey">'
1036 ' <table border="1">'
1037 ' <tr><td>sender: <td>$from</tr>'
1038 ' <tr><td>recipient:<td>$to</tr>'
1043 ' <input type="hidden" name="gkey" value="$gkey">'
1046 my $toh = "group $group:<ul>";
1047 my $toc = join(',',@group);
1048 foreach my $gm (@group) { $toh .= "<li>$gm" }
1051 ' <input type="hidden" name="id" value="$id">'
1052 ' <table border="1">'
1053 ' <tr><td>sender:<td>$from</tr>'
1054 ' <tr><td>recipient(s):'
1055 ' <td><input type="hidden" name="to" value="$toc">$toh</tr>'
1058 my $toc = join(',',@to);
1059 my $toh = join('<br>',@to);
1061 ' <input type="hidden" name="akey" value="$akey">'
1062 ' <table border="1">'
1063 ' <tr><td>sender:<td><a href="/foc">$from</a></tr>'
1067 ' <tr><td>recipient:'
1068 ' <td><input type="hidden" name="to" value="$toc">$toh</tr>'
1072 ' <tr><td><a href="/fup?akey=$akey&to=$toc">recipient(s)</a>:'
1073 ' <td><input type="hidden" name="to" value="$toc">$toh</tr>'
1078 $autodelete = lc $autodelete;
1079 $keep = $keep_default unless $keep;
1080 my ($quota,$du) = check_sender_quota($muser||$from);
1082 ? "<tr><td>sender quota (used):<td>$quota ($du) MB</tr>"
1085 $bwl = qq'<input type="text" name="bwlimit" size="8" value="$bwlimit"> kB/s';
1087 foreach (@throttle) {
1088 if (/\[?(.+?)\]?:(\d+)$/) {
1091 # throttle ip address?
1092 if ($throttle =~ /^[\w:.-]+$/) {
1093 if (ipin($ra,$throttle)) {
1094 $bwl = qq'<input type="hidden" name="bwlimit" value="$limit"> $limit kB/s';
1098 # throttle e-mail address?
1100 # allow wildcard *, but not regexps
1101 $throttle =~ quotemeta $throttle;
1102 $throttle =~ s/\*/.*/g;
1103 if ($from =~ /^$throttle$/i) {
1104 $bwl = qq'<input type="hidden" name="bwlimit" value="$limit"> $limit kB/s';
1112 $autodelete = $autodelete{$to} if $autodelete{$to};
1116 if (/yes/i) { $adt = 'delete file after download' }
1117 elsif (/no/i) { $adt = 'do not delete file after download' }
1118 elsif (/delay/i) { $adt = 'delete file after download with delay' }
1119 elsif (/^\d+$/) { $adt = "delete file $autodelete days after download" }
1121 $adt .= qq'<input type="hidden" name="autodelete" value="$autodelete">';
1123 my $ctr = my $ktr = '';
1125 $ctr = qq'<em>no notification e-mail will be send</em>';
1127 $ctr = qq'<input type="text" name="comment" size="80" value="$comment">';
1130 $ktr = qq'$keep days<input type="hidden" name="keep" value="$keep">';
1132 $ktr = qq'$keep days<input type="hidden" name="keep" value="$keep">';
1135 ' <tr><td>autodelete:'
1138 ' <tr title="keep file max $keep days, then delete it"><td>keep:'
1142 ' <tr title="optional, full speed if empty"><td>bandwith limit:'
1145 ' <tr title="optional, will be included in notification e-mail"><td>comment:'
1148 ' <tr title="If you want to send more than one file, then put them in a zip or tar archive"><td>file:'
1149 ' <td><input type="file" name="file" size="80" value="$file" onchange="reportsize();">'
1151 ' <tr><td>file size:<td id="filesize"></td></tr>'
1154 ' <input type="submit" value="upload" onclick="checkupload()">'
1158 if ($akey and -f "$from/\@" and not $captive) {
1160 "<a href=\"/foc?akey=$akey\">user config & operation control</a>\n";
1162 if ($from eq $admin ) {
1165 '<a href="/fac">server config & admin control</a>'
1168 if (0 and -f "$docdir/FIX.jar" and not $okey) {
1170 if ($public) { print "<a href=\"/fix?from=$from&id=$public&to=$to\">" }
1171 elsif ($skey) { print "<a href=\"/fix?skey=$skey&to=$to\">" }
1172 elsif ($gkey) { print "<a href=\"/fix?gkey=$gkey&to=$to\">" }
1173 else { print "<a href=\"/fix?akey=$akey&to=$to\">" }
1174 print "Alternate Java client</a> (for files > 2 GB or sending of more than one file)\n";
1178 # printf "<hr><pre>%s</pre>\n",$ENV{HTTP_HEADER};
1179 print "</body></html>\n";
1183 present_locales('/fup');
1185 if ($ENV{REQUEST_METHOD} eq 'POST') {
1187 '<font color="red"><h3>'
1188 ' You have to fill out this form completely to continue.'
1194 '<form action="/fup"'
1196 ' accept-charset="UTF-8"'
1197 ' enctype="multipart/form-data">'
1200 ' <td><input type="text" name="from" size="40" value="$from"></tr>'
1202 ' <td><input type="password" name="id" size="16" value="$id" autocomplete="off"></tr>'
1205 if ($mail_authid and not ($fop_auth or $nomail)) {
1207 # 'If you enter "?" as your auth-ID then it will be sent by e-mail to you.'
1211 ' <input type="checkbox" name="ID_forgotten" value="ID_forgotten">'
1212 ' I have lost my auth-ID! Send it to me by e-mail! '
1213 ' (you must fill out sender field above)'
1217 ' <p><input type="submit" value="check ID and continue"><p>'
1219 if (not $nomail and (
1220 @local_domains and @local_hosts or
1221 @local_rdomains and @local_rhosts or
1225 'You can <a href="/fur">register yourself</a> '
1226 'if you do not have a F*EX account yet.<p>'
1229 if (@anonymous_upload and ipin($ra,@anonymous_upload)) {
1230 my $a = 'anonymous_'.int(rand(999999));
1232 'You may also use <a href="/fup?from=anonymous&to=$a">anonymous upload</a>'
1235 # if (-f "$docdir/sup.html") {
1238 # 'You may also use <a href="/sup.html">simple upload</a>'
1245 if ($debug and $debug>1) {
1246 print "<hr>\n<pre>\n";
1247 foreach $v (sort keys %ENV) {
1248 print "$v = $ENV{$v}\n";
1253 print "</body></html>\n";
1258 if ($from and $file and not @to) {
1259 check_rr($from,$from);
1261 $sup = 'fexyourself';
1262 $keep{$from} = readlink("$from/\@KEEP")||$keep_default;
1265 # all these variables should be defined here, but just to be sure...
1266 http_die("no file specified") unless $file;
1267 http_die("no sender specified") unless $from;
1268 http_die("no recipient specified") unless @to;
1269 unless ($okey and -l "$to/\@OKEY/$okey") {
1270 http_die("no auth-ID specified") unless $id;
1271 unless ($rid eq $id or $gkey or $skey) {
1272 faillog("user $from, id $id");
1273 http_die("wrong auth-ID specified");
1277 &check_status($from);
1280 foreach (@throttle) {
1281 if (/(.+):(\d+)$/) {
1284 if (not $bwlimit or $limit < $bwlimit) {
1285 # throttle ip address?
1286 if ($throttle =~ /^[\d.-]+$/) {
1287 if (ipin($ra,$throttle)) {
1292 # throttle e-mail address?
1294 # allow wildcard *, but not regexps
1295 $throttle =~ quotemeta $throttle;
1296 $throttle =~ s/\*/.*/g;
1297 if ($from =~ /^$throttle$/i) {
1307 # address rewriting for storage (swap sender and recipient), see also fop!
1308 if (not ($skey or $gkey) and $from =~ /^(anonymous|fexmail)/) {
1309 ($from,@to) = ("@to",$from);
1312 if (not $anonymous and $overwrite =~ /^n/i) {
1314 if (-f "$to/$from/$fkey/data") {
1315 http_die("<code>$file</code> already exists for <code>$to</code>");
1320 # additional last check
1321 unless (@group or $gkey or $skey or $public or $okey) {
1323 checkaddress($to) or
1324 http_die("<code>$to</code> is not a valid e-mail address");
1329 $to = join(',',@to);
1331 # file overwriting for anonymous is only possible if his client has the
1332 # download cookie - else request purging
1333 if ($anonymous and not $seek and my $dkey = readlink "$to/$from/$fkey/dkey") {
1334 if ($overwrite =~ /^n/i) {
1335 http_die("<code>$file</code> already exists for <code>$to</code>");
1337 if ($ENV{HTTP_COOKIE} !~ /$dkey/) {
1338 my $purge = "/fop/$dkey/$dkey?purge";
1339 # http_die("$file already exists $dkey:$ENV{HTTP_COOKIE}:");
1340 http_die("<code>$file</code> already exists - <a href=\"$purge\">purge it?!</a>");
1346 $comment = "[$group] $comment";
1348 $comment .= ' (public upload)';
1351 # file data still waits on STDIN ... get it now!
1354 if ($to eq $from and $file eq 'ADDRESS_BOOK') {
1355 unlink "$from/\@ADDRESS_BOOK";
1356 rename "$from/$from/ADDRESS_BOOK/upload","$from/\@ADDRESS_BOOK"
1357 or http_die("cannot save $from/\@ADDRESS_BOOK - $!\n");
1358 http_header('200 OK');
1359 print html_header($head);
1360 print "address book updated",
1367 foreach (@group?@group:@to) {
1369 $to =~ s/:\w+=.*//; # remove options from address
1370 $filed = "$to/$from/$fkey";
1371 $save = "$filed/data";
1372 $upload = "$filed/upload";
1373 $download = "$filed/download";
1374 $dkey{$to} = readlink "$filed/dkey";
1375 $overwrite{$to}++ if -f $save and not -f $download;
1376 unlink $save,$download;
1377 rename $upload,$save or http_die("cannot rename $upload to $save - $!\n");
1380 my $msg = sprintf "%s %s %s %s %s\n",
1381 isodate(time),$dkey{$to},$from,$to,$fkey;
1382 writelog('dkey.log',$msg);
1384 # send notification e-mails if necessary
1385 if (not $nomail and (readlink "$to/\@NOTIFICATION"||'') !~ /^no/i
1386 and ($comment or not $overwrite{$to})) {
1387 notify_locale($dkey{$to},'new');
1388 debuglog("notify $filed [$filename] '$comment'");
1394 $HTTP_HEADER = 'HTTP/1.1 200 OK';
1396 nvt_print($HTTP_HEADER,'Content-Type: text/html','');
1397 exit if $http_client =~ /^fexsend/;
1398 } elsif ($file eq 'STDFEX') {
1399 nvt_print($HTTP_HEADER,'');
1402 nvt_print($HTTP_HEADER);
1403 if ($xkey and not $restricted) {
1404 my $x = "$durl//$xkey";
1406 nvt_print("X-Location: $x");
1409 my $dkey = $dkey{$to};
1411 $cookie = $1 if $ENV{HTTP_COOKIE} =~ /anonymous=([\w:]+)/;
1412 $cookie .= ':'.$dkey if $cookie !~ /$dkey/;
1413 nvt_print("Set-Cookie: anonymous=$cookie");
1414 $keep{$to} = readlink("$to/\@KEEP")||$keep_default;
1416 foreach (@group?@group:@to) {
1418 $to =~ s/:\w+=.*//; # remove options from address
1419 my $file = "$to/$from/$fkey";
1420 my $options = sprintf "(autodelete=%s,keep=%s,locale=%s,notification=%s)",
1421 readlink("$file/autodelete")||$autodelete,
1422 readlink("$file/keep")||readlink("$to/\@KEEP")||$keep_default,
1423 readlink("$to/\@LOCALE")||readlink("$file/locale")||$default_locale,
1424 readlink("$to/\@NOTIFICATION")||'full';
1425 nvt_print("X-Recipient: $to $options");
1426 nvt_print("X-Location: $durl/$dkey{$to}/$fkey") unless $restricted;
1428 if ($http_client =~ /^(fexsend|schwuppdiwupp)/) {
1432 nvt_print('Content-Type: text/html','');
1437 print html_header($head);
1440 printf "%s (%s MB) received\n",$file,int($ndata/$MB);
1441 } elsif (not $restricted and ($anonymous or $from eq $to)) {
1442 my $size = $ndata<2*1024 ? sprintf "%s B",$ndata:
1443 $ndata<2*$MB ? sprintf "%s kB",int($ndata/1024):
1444 sprintf "%s MB",int($ndata/$MB);
1446 '<code>$file</code> ($size) received and saved<p>'
1447 'Download URL for copy & paste:'
1448 '<h2>$durl/$dkey{$to}/$fkey</h2>'
1449 'Link is valid for $keep{$to} days!<p>'
1452 if ($ndata<2*1024) {
1453 print "<code>$file</code> ($ndata B) received and saved<p>\n";
1454 if (not $boring and not $seek) {
1455 print "Ehh... $ndata <b>BYTES</b>?! You are kidding?<p>\n";
1457 } elsif ($ndata<2*$MB) {
1458 $ndata = int($ndata/1024);
1459 print "<code>$file</code> ($ndata kB) received and saved<p>\n";
1460 if ($ndata<1024 and not ($boring or $seek)) {
1461 print "Using F*EX for less than 1 MB: ",
1462 "ever heard of MIME e-mail? ☺<p>\n";
1465 $ndata = int($ndata/$MB);
1466 print "<code>$file</code> ($ndata MB) received and saved<p>\n";
1471 if ($nomail or $nomail{$to}) {
1473 rmrf("$to/$from/$fkey");
1474 print "<code>$file</code> removed because you are a restricted user ".
1475 "and recipient $to cannot receive e-mail<p>\n";
1478 '$to cannot receive e-mail →'
1479 '<h3><font color="red">'
1480 ' No notification e-mail has been sent to $to!'
1482 'Download URL for copy & paste:'
1485 my $x = "$durl{$to}//$xkey";
1487 print "<h2><code>$x</code></h2>\n";
1489 print "<h2>$durl/$dkey{$to}/$fkey</h2>\n";
1490 print "Link is valid for $keep{$to} days!<p>\n";
1493 } elsif ($overwrite{$to} and not $comment) {
1494 print "(old <code>$file</code> for $to overwritten)<p>\n"
1496 print "$to notified<p>\n"
1503 unlink "$to/\@OKEY/$okey";
1504 } elsif (not $anonymous and not $sup) {
1505 print "<a href=\"/fup?submit=again";
1506 if ($public) { print "&from=$from&to=$to&id=$id" }
1507 elsif ($skey) { print "&skey=$skey" }
1508 elsif ($gkey) { print "&gkey=$gkey" }
1509 elsif ($akey) { print "&akey=$akey&to=$to" }
1510 print "&bwlimit=$bwlimit&autodelete=$autodelete&keep=$keep\">";
1511 print "send another file</a>\n";
1512 if ($http_client !~ /fexsend/ and $http_client =~ /Linux/i) {
1513 print qq'<p>Hi Linux-user, try <a href="/FAQ/user.html#Why_should_I_use_a_special_F_EX_client">fexsend</a>! ☺<p>\n';
1518 print "</body></html>\n";
1522 # parse GET and POST requests
1527 my $qs = $ENV{QUERY_STRING};
1530 # get JUP parameters from environment (HTTP headers)
1531 while (($k,$v) = each %ENV) {
1532 if ($k =~ s/^FEX_//) {
1537 # decode base64 PATH_INFO to QUERY_STRING
1538 if ($ENV{PATH_INFO} =~ m:^/(\w+=*)$:) {
1540 $qs = sprintf("%s&%s",decode_b64($1),$qs);
1542 $qs = decode_b64($1);
1546 # parse HTTP QUERY_STRING (parameter=value pairs)
1548 foreach (split '&',$qs) {
1549 if (s/^(\w+)=(.*)//) {
1552 # decode URL-encoding
1553 $v =~ s/%([a-f0-9]{2})/chr(hex($1))/gie;
1555 if ($p eq 'AUTODELETE') {
1556 $specific{'autodelete'} = $autodelete = $v;
1558 if ($p eq 'KEEP' and /^\d+$/) {
1559 $specific{'keep'} = $keep = $v;
1565 # HTTP redirect does not work correctly with opera!
1566 # ==> locale handling is now done by fexsrv
1567 if (0 and $locale) {
1569 "HTTP/1.1 302 Found",
1570 "Location: $ENV{PROTO}://$ENV{HTTP_HOST}/fup",
1571 "Set-Cookie: locale=$locale",
1573 'Content-Length: 0',
1584 # check for akey, gkey and skey (from HTTP GET)
1587 if ($ENV{REQUEST_METHOD} eq 'POST' and $cl) {
1588 foreach $sig (keys %SIG) {
1589 if ($sig !~ /^(CHLD|CLD)$/) {
1590 $SIG{$sig} = \&sigexit;
1593 $SIG{PIPE} = 'IGNORE' if $ENV{PROTO} eq 'https'; # stunnel workaround
1594 $SIG{__DIE__} = \&sigdie;
1595 http_die("invalid Content-Length header \"$cl\"") if $cl !~ /^-?\d+$/;
1597 debuglog(sprintf("awaiting %d bytes from %s %s",
1598 $cl,$ENV{REMOTE_ADDR}||'',$ENV{REMOTE_HOST}||''),"\n");
1600 &check_space($cl) if $cl > 0;
1602 $SIG{ALRM} = sub { die "TIMEOUT\n" };
1604 binmode(STDIN,':raw');
1606 if (defined($ENV{FEX_FILENAME})) {
1607 # JUP via HTTP header
1608 $file = $param{'FILE'} = $ENV{FEX_FILENAME};
1609 $fileid = $ENV{FEX_FILEID} || 0;
1610 $fpsize = $ENV{X_CONTENT_LENGTH} || 0;
1612 } elsif ($contentlength) {
1613 # JUP via URL parameter
1614 $fpsize = $contentlength;
1618 if ($ENV{CONTENT_TYPE} =~ /boundary=\"?([\w\-\+\/_]+)/) {
1621 http_die("malformed HTTP POST (no boundary found)");
1624 READPOST: while (&nvt_read) {
1625 # the file itself - *must* be last part of POST!
1626 if (/^Content-Disposition:\s*form-data;\s*name="file";\s*filename="(.+)"/i) {
1628 $file = $param{'FILE'} = $1;
1631 $fileid = $1 if /^X-File-ID:\s*(.+)/;
1632 $fpsize = $1 if /^Content-Length:\s*(\d+)/;
1633 $flink = $1 if /^Content-Location:\s*(\/.+)/;
1636 # STDIN is now at begin of file, will be read later with get_file()
1639 # all other parameters
1640 if (/^Content-Disposition:\s*form-data;\s*name="([a-z]\w*)"/i) {
1642 nvt_skip_to('^\s*$');
1645 NEXTPART: while (&nvt_read) {
1646 last READPOST if /^--\Q$boundary--/;
1647 last NEXTPART if /^--\Q$boundary/;
1653 if (length($file)) {
1654 $file =~ s/%(\d+)/chr($1)/ge;
1655 $file = untaint(strip_path(normalize($file)));
1656 $file =~ s/[\\\/<>]/_/g; # filter out dangerous chars
1657 $file =~ s/^\|//; # filter out dangerous chars
1658 $file =~ s/\|$//; # filter out dangerous chars
1660 $fkey = urlencode($file);
1663 # check for akey, gkey and skey (from HTTP POST)
1669 unless ($skey or $gkey or $okey) {
1670 $from .= '@'.$mdomain if $mdomain and $from !~ /@/;
1671 if ($from ne 'anonymous' and not checkaddress($from)) {
1672 http_die("<code>$from</code> is not a valid e-mail address");
1675 $from = untaint($from);
1678 # collect multiple addresses and check for aliases (not group)
1679 if (@to and "@to" !~ /^@[\w-]+$/
1680 and not ($gkey or $addto or $command =~ /^LIST(RECEIVED)?$/))
1684 if ($from and open my $AB,'<',"$from/\@ADDRESS_BOOK") {
1685 my ($alias,$address,$autodelete,$locale,$keep);
1689 if (s/^\s*(\S+)[=\s]+(\S+)//) {
1690 ($alias,$address) = ($1,$2);
1691 $autodelete = $locale = $keep = '';
1692 $autodelete = $1 if /autodelete=(\w+)/;
1693 $locale = $1 if /locale=(\w+)/;
1694 $keep = $1 if /keep=(\d+)/;
1695 foreach my $address (split(",",$address)) {
1696 $address .= '@'.$mdomain if $mdomain and $address !~ /@/;
1697 push @{$ab{$alias}},$address;
1698 $autodelete{$alias} = $autodelete if $autodelete;
1699 $keep{$alias} = $keep if $keep;
1700 $locale{$alias} = $locale if $locale;
1707 # look for recipient's options and eliminate dupes
1709 foreach my $to (my @loop = @to) {
1710 # address book alias?
1711 if ($to !~ /@/ and $ab{$to}) {
1712 foreach my $address (my @loop = @{$ab{$to}}) {
1713 $address .= '@'.$mdomain if $mdomain and $address !~ /@/;
1714 $to{$address} = $address; # ignore dupes
1715 if ($specific{'autodelete'}) {
1716 $autodelete{$address} = $specific{'autodelete'};
1717 } elsif ($autodelete{$to}) {
1718 $autodelete{$address} = $autodelete{$to};
1720 $autodelete{$address} = readlink "$address/\@AUTODELETE"
1723 if (my $locale = readlink "$address/\@LOCALE") {
1724 $locale{$address} = $locale;
1725 } elsif ($locale{$to}) {
1726 $locale{$address} = $locale{$to};
1728 $locale{$address} = $::locale ;
1730 unless ($locale{$address}) {
1731 $locale{$address} = $default_locale || 'english';
1733 if ($specific{'keep'}) { $keep{$address} = $specific{'keep'} }
1734 elsif ($keep{$to}) { $keep{$address} = $keep{$to} }
1738 $to{$to} = $to; # ignore dupes
1739 unless ($autodelete{$to}) {
1740 $autodelete{$to} = readlink "$to/\@AUTODELETE" || $autodelete;
1742 $autodelete{$to} = $specific{'autodelete'} if $specific{'autodelete'};
1743 $keep{$to} = $keep_default;
1744 $keep{$to} = $keep if $keep;
1745 $keep{$to} = untaint(readlink "$to/\@KEEP") if -l "$to/\@KEEP";
1746 $keep{$to} = $specific{'keep'} if $specific{'keep'};
1747 # recipient specific parameters
1748 $keep{$to} = $1 if $to =~ /:keep=(\d+)/i;
1749 $autodelete{$to} = $1 if $to =~ /:autodelete=(\w+)/i;
1751 $autodelete{$to} = 'NO' if $to =~ /$amdl/; # mailing lists, etc
1752 if (-e "$to/\@CAPTIVE") {
1754 $v = readlink "$to/\@AUTODELETE" and $autodelete{$to} = $v;
1755 $v = readlink "$to/\@KEEP" and $keep{$to} = $v;
1760 if (scalar(@to) == 1) {
1762 $keep = $keep{$to} if $keep{$to};
1763 $autodelete = $autodelete{$to} if $autodelete{$to};
1766 # check recipients and eliminate dupes
1769 if ($to eq 'anonymous') {
1772 if ($to =~ /^@(.+)/) {
1773 http_die("You cannot send to more than one group") if @to > 1;
1774 http_die("Group <code>$to</code> does not exist") unless -f "$from/\@GROUP/$1";
1776 if ($skey or $gkey or $okey or checkaddress($to)) {
1777 $to .= '@'.$mdomain if $mdomain and $to !~ /@/;
1778 $to{$to} = untaint($to);
1780 http_die("<code>$to</code> is not a valid e-mail address");
1789 unless (checkforbidden($to)) {
1790 http_die("<code>$to</code> is not allowed");
1796 # show the status progress bar
1799 my ($upload,$data,$sfile,$ukey,$file);
1801 my ($t0,$t1,$t2,$tt,$ts,$tm);
1802 my ($osize,$percent,$npercent);
1805 $wclose = '<p><a href="#" onclick="window.close()">close</a>'."\n".
1806 '</body></html>'."\n";
1807 $ukey = "$ukeydir/$uid";
1808 $upload = "$ukey/upload";
1809 $data = "$ukey/data";
1810 $sfile = "$ukey/size";
1813 $tsize = readlink $sfile and last;
1815 # remark: stupid Internet Explorer *needs* the error represented in this
1816 # asynchronous popup window, because it cannot display the error in the
1817 # main window on HTTP POST!
1818 if (-f $ukey and open $ukey,'<',$ukey or
1819 -f "$ukey/error" and open $ukey,'<',"$ukey/error") {
1822 html_error($error,<$ukey> || 'unknown');
1827 if (defined $tsize and $tsize == 0) {
1828 print "<script type='text/javascript'>window.close()</script>\n";
1833 "no file data received - does your file exist or is it >2GB?")
1835 html_error($error,"file size unknown") unless $tsize =~ /^\d+$/;
1837 http_header('200 OK');
1838 if (open $ukey,'<',"$ukey/filename") {
1843 http_die("no filename?!") unless $file;
1846 if ($ssize<2097152) {
1847 $ssize = sprintf "%d kB",int($ssize/1024);
1849 $ssize = sprintf "%d MB",int($ssize/1048576);
1855 "<h1>Upload Status for<br><code>$file ($ssize)</code></h1>"
1856 '<img src="/action-fex-camel.gif" id="afc">'
1858 "<input type='text' id='percent' style='margin-left:1ex;color:black;background:transparent;border:none;width:32ex;' disabled='true' value='0%'>"
1859 "<div style='border:1px solid black;width:100%;height:20px;'>"
1860 "<div style='float:left;width:0%;background:black;height:20px;' id='bar'>"
1864 # wait for upload file
1866 last if -f $upload or -f $data;
1869 unless (-f $upload or -f $data) {
1870 print "<p><H3>ERROR: no upload received</H3>\n";
1875 $SIG{ALRM} = sub { die "TIMEOUT in showstatus: no (more) data received\n" };
1879 $osize = $percent = $npercent = 0;
1881 for ($percent = 0; $percent<100; sleep(1)) {
1883 $nsize = -s $upload;
1884 if (defined $nsize) {
1885 if ($nsize<$osize) {
1886 print "<p><h3>ABORTED</h3>\n";
1890 if ($nsize>$osize) {
1894 $npercent = int($nsize*100/$tsize);
1895 $showsize = calcsize($tsize,$nsize);
1898 $showsize = calcsize($tsize,$tsize);
1900 # hint: for ISDN (or even slower) links, 5 s tcp delay is minimum
1901 # so, updating more often is contra-productive
1902 if ($t2>$t1+5 or $npercent>$percent) {
1903 $percent = $npercent;
1905 $tm = int(($t2-$t0)/60);
1906 $ts = $t2-$t0-$tm*60;
1907 $tt = sprintf("%d:%02d",$tm,$ts);
1909 "<script type='text/javascript'>"
1910 " document.getElementById('bar').style.width = '$percent%';"
1911 " document.getElementById('percent').value = '$showsize, $tt, $percent %';"
1918 if ($npercent == 100) {
1919 print "<h3>file successfully transferred</h3>\n";
1921 print "<h3>file transfer aborted</h3>\n";
1924 "<script type='text/javascript'>"
1925 " document.getElementById('afc').src='/logo.jpg'"
1934 # get file from post request
1936 my ($to,$filed,$upload,$nupload,$speed,$download);
1941 my $fb = 0; # file bytes
1942 my $ebl = 0; # end boundary length
1946 $ebl = length($boundary)+8; # 8: 2 * CRLF + 2 * "--"
1951 # download already in progress?
1953 $to =~ s/:\w+=.*//; # remove options from address
1954 $filed = "$to/$from/$fkey";
1955 $download = "$filed/download";
1956 if (-f $download and open $download,'>>',$download) {
1957 flock($download,LOCK_EX|LOCK_NB) or
1958 http_die("<code>$filed</code> locked: a download is currently in progress");
1964 $to =~ s/:\w+=.*//; # remove options from address
1965 $filed = "$to/$from/$fkey";
1966 $nupload = "$filed/upload"; # upload for next recipient
1969 # upload already prepared (for first recipient)?
1971 # link upload for next recipient
1972 unless ($upload eq $nupload or
1973 -r $upload and -r $nupload and
1974 (stat $upload)[1] == (stat $nupload)[1])
1977 link $upload,$nupload;
1981 # first recipient => create upload
1984 unlink "$ukeydir/$uid";
1987 http_die("cannot resume on link upload");
1989 &nvt_read and $flink = $_;
1990 if ($flink !~ /^\//) {
1991 http_die("no file link name ($flink)");
1993 $flink = abs_path($flink);
1995 foreach (@file_link_dirs) {
1996 my $dir = abs_path($_);
1997 $fok = $flink if $flink =~ /^\Q$dir\//;
2000 http_die("<code>$flink</code> not allowed for linking");
2002 my @s = stat($flink);
2003 unless (@s and ($s[2] & S_IROTH) and -r $flink) {
2004 http_die("cannot read <code>$flink</code>");
2006 unless (-f $flink and not -l $flink) {
2007 http_die("<code>$flink</code> is not a regular file");
2009 # http_die("DEBUG: flink = $flink");
2012 unless (/^--\Q$boundary--/) {
2013 http_die("found no MIME end boundary in upload ($_)");
2016 symlink untaint($flink),$upload;
2018 unlink $upload if -l $upload;
2019 open $upload,'>>',$upload or http_die("cannot write $upload - $!");
2020 flock($upload,LOCK_EX|LOCK_NB) or
2021 http_die("<code>$file</code> locked: a transfer is already in progress");
2026 # already uploaded file data size
2028 # provide upload ID symlink for showstatus
2029 symlink "../$filed","$ukeydir/$uid";
2033 unlink "$filed/autodelete",
2035 "$filed/restrictions",
2047 unlink "$filed/size" unless $seek;
2049 # showstatus needs file name and size
2050 # fexsend needs full file size (+$seek)
2051 $fh = "$filed/filename";
2052 open $fh,'>',$fh or die "cannot write $fh - $!\n";
2053 print {$fh} $filename;
2055 if ($::filesize > 0 or $cl > 0) {
2056 if ($::filesize > 0) { $filesize = $fpsize || $::filesize }
2057 else { $filesize = $cl-$RB-$ebl+$seek }
2060 if ($::filesize > 0) {
2061 # total file size as reported by POST
2062 mksymlink("$filed/size",$::filesize)
2063 or die "cannot write $filed/size - $!\n";
2065 # file size as counted
2066 mksymlink("$filed/size",$filesize)
2067 or die "cannot write $filed/size - $!\n";
2072 if ($from eq "@to") {
2073 # special "fex yourself"
2074 mksymlink("$filed/autodelete",$specific{'autodelete'}||'NO');
2076 $autodelete{$to} = $autodelete unless $autodelete{$to};
2077 if ($autodelete{$to} =~ /^(DELAY|NO|\d+)$/i) {
2078 mksymlink("$filed/autodelete",$autodelete{$to});
2082 if (my $keep = $keep{$to} || $::keep) {
2083 mksymlink("$filed/keep",$keep);
2085 mksymlink("$filed/id",$fileid) if $fileid;
2086 mksymlink("$filed/ip",$ra) if $ra;
2087 if (my $uurl = $ENV{REQUEST_URL}) {
2088 mksymlink("$filed/uurl",$uurl);
2090 if ($http_client and open $http_client,'>',"$filed/useragent") {
2091 print {$http_client} $http_client,"\n";
2094 if ($_ = readlink "$to/\@LOCALE") {
2095 # mksymlink("$filed/locale",$_);
2096 } elsif ($locale{$to}) {
2097 mksymlink("$filed/locale",$locale{$to});
2098 } elsif ($locale and $locale ne $default_locale) {
2099 mksymlink("$filed/locale",$locale);
2101 if ($replyto and $replyto =~ /.@./) {
2102 mksymlink("$filed/replyto",$replyto);
2105 my $arh = "$from/\@ALLOWED_RHOSTS";
2107 copy($arh,"$filed/restrictions");
2110 if (@header and open $fh,'>',"$filed/header") {
2111 print {$fh} join("\n",@header),"\n";
2115 if ((readlink "$to/\@NOTIFICATION"||'') =~ /^no/i) {
2116 $nomail{$to} = 'NOTIFICATION';
2120 open $fh,'>',"$filed/notify" and close $fh;
2123 if (open $fh,'>',"$filed/comment") {
2124 print {$fh} encode_utf8($comment);
2129 # provide download ID key
2130 unless ($dkey = readlink("$filed/dkey") and -l "$dkeydir/$dkey") {
2131 $dkey = randstring(8);
2132 unlink "$dkeydir/$dkey";
2133 symlink "../$filed","$dkeydir/$dkey"
2134 or http_die("cannot symlink $dkeydir/$dkey ($!)");
2135 unlink "$filed/dkey";
2136 symlink $dkey,"$filed/dkey";
2141 # extra download (XKEY)?
2142 if ($anonymous and $fkey =~ /^afex_\d/ or
2143 $from eq "@to" and $comment =~ s:^//(.*)$:NOMAIL:)
2147 my $x = "$xkeydir/$xkey";
2148 unless (-l $x and readlink($x) eq "../$from/$from/$fkey") {
2150 http_die("extra download key $xkey already exists");
2152 symlink "../$from/$from/$fkey",$x
2153 or http_die("cannot symlink $x - $!\n");
2155 symlink $xkey,"$x/xkey";
2163 # upload link has been already created, no data to read any more
2164 $to = join(',',@to);
2165 fuplog($to,$fkey,0);
2166 debuglog("upload link successfull, dkey=$dkey");
2172 # at last, read (real) file data
2178 # read until EOF, including MIME end boundary
2179 # note: cannot use sysread because of previous buffered read!
2180 while ($n = read(STDIN,$_,$bs)) {
2183 syswrite $upload,$_ unless $nostore;
2186 # size of transferred file, without end boundary
2187 $ndata = untaint($fb-$ebl);
2190 # normal file with known file size
2194 debuglog(sprintf("still awaiting %d+%d = %d bytes",
2195 $fpsize,$ebl,$fpsize+$ebl));
2196 $cl = $RB+$fpsize+$ebl; # recalculate CONTENT_LENGTH
2199 $cl = $RB+$::filesize+$ebl; # recalculate CONTENT_LENGTH
2201 debuglog(sprintf("still awaiting %d-%d = %d bytes",
2204 # read until end boundary, not EOF
2205 while ($RB < $cl-$ebl) {
2207 $b = $bs if $b > $bs;
2208 # max wait for 1 kB/s, but at least 10 s
2209 # $timeout = $b/1024;
2210 # $timeout = 10 if $timeout < 10;
2212 if ($n = read(STDIN,$_,$b)) {
2215 # syswrite is much faster than print
2216 syswrite $upload,$_ unless $nostore;
2219 $tt = (time-$t0) || 1;
2220 while ($RB/$tt/1024 > $bwlimit) {
2230 # read end boundary - F*IX is broken!
2231 if ($ebl and $http_client !~ /F\*IX/) {
2234 unless (/^--\Q$boundary--/) {
2235 http_die("found no MIME end boundary in upload ($_)");
2239 $ndata = untaint($fb);
2245 close $upload; # or die "cannot close $upload - $!\n";;
2248 $tt = (time-$t0) || 1;
2249 mksymlink("$filed/speed",int($fb/1024/$tt));
2253 "No file data received!".
2254 " File name correct?".
2255 " File too big (browser-limit: 2 GB!)?"
2259 $to = join(',',@to);
2264 open $upload,'<',$upload or http_die("internal error - cannot read upload");
2265 seek $upload,$ndata+2,0;
2267 unless (/^--\Q$boundary--/) {
2268 http_die("found no MIME end boundary in upload ($_)");
2271 truncate $upload,$ndata;
2275 # truncate boundary string
2276 # truncate $upload,$ndata+$uss if -s $upload > $ndata+$uss;
2280 fuplog($to,$fkey,$ndata,'(aborted)');
2282 http_die("read $RB bytes, but Content-Length announces $fpsize bytes");
2284 http_die("read $RB bytes, but CONTENT_LENGTH announces $cl bytes");
2288 # multipost, not complete
2289 if ($::filesize > -s $upload) {
2290 http_header('206 Partial OK');
2295 if (-s $upload > ($::filesize||$filesize)) {
2296 fuplog($to,$fkey,$ndata,'(write error: upload > filesize)');
2297 http_die("internal server error while writing file data");
2301 fuplog($to,$fkey,$ndata);
2302 debuglog("upload successfull, dkey=$dkey");
2308 # check recipients restriction
2312 my $rr = "$from/\@ALLOWED_RECIPIENTS";
2313 my ($allowed,$to,$ar,$rd);
2315 if (-s $rr and open $rr,'<',$rr) {
2328 if (/^\@LOCAL_RDOMAINS/) {
2330 foreach (@local_rdomains) {
2332 # allow wildcard *, but not regexps
2334 $rd =~ s/\*/[\\w.-]+/g;
2335 $ar .= '|[^\@]+\@' . $rd;
2338 } elsif (/^\@LOCAL_USERS/ and -s "$to/@") {
2342 # allow wildcard *, but not regexps
2344 $ar =~ s/\\\*/[^@]*/g;
2347 if ($to =~ /^$ar$/i) {
2355 fuplog("ERROR: $from not allowed to fex to $to");
2356 debuglog("$to not in $spooldir/$from/\@ALLOWED_RECIPIENTS");
2357 http_die("You ($from) are not allowed to fex to $to");
2366 # add domain to user if necessary
2371 foreach my $u (my @loop = @users) {
2372 if ($u =~ /^anonymous(_\d+)?$/) {
2373 $u = "$u\@$hostname";
2375 if ($u eq 'nettest') {
2376 if ($mdomain and -d "$u\@$mdomain") {
2378 } elsif (-d "$u\@$hostname") {
2382 if ($u =~ /@/) { push @ua,$u }
2383 elsif ($mdomain) { push @ua,"$u\@$mdomain" }
2384 elsif (-d "$u\@$hostname") { push @ua,"$u\@$hostname" }
2385 else { push @ua,$u }
2388 return wantarray ? @ua : join(',',@ua);
2392 # forward-copy (bounce) an already uploaded file
2395 my ($nfile,$to,$AB);
2396 my ($filename,$keep);
2399 http_die("no file data for <code>$file</code>") unless -f "$file/data";
2401 $keep = $::keep||$keep_default;
2402 if (my $mt = mtime("$file/data")) { $keep += int((time-$mt)/$DS) }
2406 # check recipients restriction
2407 check_rr($from,@to);
2409 # read aliases from address book
2410 if (open $AB,'<',"$from/\@ADDRESS_BOOK") {
2414 if (s/^\s*(\S+)[=\s]+(\S+)//) {
2415 my ($alias,$address) = ($1,$2);
2416 foreach my $address (split(",",$address)) {
2417 $address .= '@'.$mdomain if $mdomain and $address !~ /@/;
2418 push @{$ab{$alias}},$address;
2426 foreach my $to (my @loop = @to) {
2428 foreach my $address (@{$ab{$to}}) {
2429 $to{$address} = $address;
2432 $to .= '@'.$mdomain if $mdomain and $to !~ /@/;
2439 http_header('200 OK');
2440 print html_header($head);
2442 foreach my $to (my @loop = @to) {
2443 $to =~ s/:\w+=.*//; # remove options from address
2445 $nfile =~ s:.*?/:$to/:;
2446 next if $nfile eq $file;
2448 http_die("cannot create directory $nfile") unless -d $nfile;
2449 unlink "$nfile/data",
2452 "$nfile/autodelete",
2454 "$nfile/restrictions",
2463 open $comment,'>',"$nfile/comment";
2464 print {$comment} $comment;
2467 if ($autodelete =~ /^(DELAY|NO|\d+)$/i) {
2468 symlink $autodelete,"$nfile/autodelete";
2470 symlink $keep, "$nfile/keep";
2471 copy("$file/id", "$nfile/id");
2472 copy("$file/ip", "$nfile/ip");
2473 copy("$file/speed", "$nfile/speed");
2474 copy("$file/replyto", "$nfile/replyto");
2475 $filename = copy("$file/filename", "$nfile/filename");
2476 link "$file/data", "$nfile/data"
2477 or die http_die("cannot create $nfile/data - $!");
2478 unless ($dkey = readlink("$nfile/dkey") and -l "$dkeydir/$dkey") {
2479 $dkey = randstring(8);
2480 unlink "$dkeydir/$dkey";
2481 symlink "../$nfile","$dkeydir/$dkey"
2482 or http_die("cannot symlink $dkeydir/$dkey");
2483 unlink "$nfile/dkey";
2484 symlink $dkey,"$nfile/dkey"
2485 or http_die("cannot create $nfile/dkey - $!");
2488 if ($nomail or $nomail{$to}) {
2490 my $url = "$durl/$dkey/".normalize_filename($filename);
2492 'Download-URL for $to:<br>'
2498 notify_locale($dkey,'new');
2499 fuplog($to,urlencode($filename),"(forwarded)");
2502 'File "$filename" copy-forwarded to $to and notified.'
2509 '<a href="/foc?akey=$akey">back to F*EX operation control</a>'
2513 $filename = filename($file);
2514 http_header('200 OK');
2515 print html_header($head);
2517 '<form name="upload"'
2520 ' accept-charset="UTF-8"'
2521 ' enctype="multipart/form-data">'
2522 ' <input type="hidden" name="akey" value="$akey">'
2523 ' <input type="hidden" name="dkey" value="$dkey">'
2524 ' <input type="hidden" name="command" value="FORWARD">'
2525 ' forward a copy of "<code>$filename</code>" to:<br>'
2526 ' <input type="text" name="to" size="80">'
2534 # modify file parameter
2537 my $filename = filename($file);
2538 my $dkey = readlink "$file/$dkey";
2542 http_die("no file data for <code>$file</code>") unless -f "$file/data";
2546 if ($specific{'keep'}) {
2547 mksymlink("$file/keep",$keep);
2548 utime time,time,"$file/filename";
2549 push @parameter,'KEEP';
2551 if ($specific{'autodelete'}) {
2552 mksymlink("$file/autodelete",$autodelete);
2553 push @parameter,'AUTODELETE';
2556 if (open $comment,'>',"$file/comment") {
2557 print {$comment} $comment;
2560 notify_locale($dkey,'new');
2561 push @parameter,'COMMENT';
2563 http_header('200 OK');
2564 print "Parameter ".join(',',@parameter)." modified for $filename for $to\n";
2569 my ($tsize,$nsize) = @_;
2570 if ($tsize<2097152) {
2571 return sprintf "%d kB",int($nsize/1024);
2573 return sprintf "%d MB",int($nsize/1048576);
2578 # set parameter variables
2583 $v = uc(despace($v));
2585 # if ($vv =~ /([<>])/) {
2586 # http_die(sprintf("\"&#%s;\" is not allowed in parameter $v",ord($1)));
2590 if ($v eq 'LOGOUT') {
2592 # skey and gkey are persistant!
2593 $akey = $1 if $ENV{QUERY_STRING} =~ /AKEY:(\w+)/i;
2594 unlink "$akeydir/$akey";
2595 $login = $FEXHOME.'/cgi-bin/login';
2597 $login = readlink $login || 'login';
2599 "HTTP/1.1 302 Found",
2600 "Location: $ENV{PROTO}://$ENV{HTTP_HOST}/$login",
2601 'Content-Length: 0',
2606 "HTTP/1.1 302 Found",
2607 "Location: $ENV{PROTO}://$ENV{HTTP_HOST}/fup",
2608 'Content-Length: 0',
2613 } elsif ($v eq 'LOCALE' and $vv =~ /^(\w+)$/) {
2615 } elsif ($v eq 'REDIRECT' and $vv =~ /^([\w?=]+)$/) {
2617 } elsif (($v eq 'KEY' or $v eq 'SKEY') and $vv =~ /^([\w:]+)$/) {
2620 } elsif ($v eq 'GKEY' and $vv =~ /^([\w:]+)$/) {
2621 $gkey = $1 unless $nomail;
2623 } elsif ($v eq 'DKEY' and $vv =~ /^(\w+)$/) {
2625 } elsif ($v eq 'AKEY' and $vv =~ /^(\w+)$/) {
2627 } elsif ($v eq 'FROM' or $v eq 'USER') {
2628 $from = normalize_email($vv);
2629 $from = untaint(expand($from));
2630 checkchars('from address',$from);
2631 # maybe FROM=SUBUSER !
2632 # checkaddress($from) or http_die("FROM $from is no legal e-mail address");
2633 } elsif ($v eq 'REPLYTO') {
2634 $replyto = normalize_email($vv);
2635 checkchars('replyto address',$replyto);
2636 checkaddress($replyto) or
2637 http_die("REPLYTO $replyto is no legal e-mail address");
2638 } elsif ($v eq 'ADDTO') {
2640 $addto = normalize_email($vv);
2641 } elsif ($v eq 'SUBMIT') {
2642 $submit = decode_utf8(normalize($vv));
2643 } elsif ($v eq 'FEXYOURSELF') {
2646 $specific{'autodelete'} = $autodelete = 'no';
2647 } elsif ($v eq 'TO') {
2648 # extract AUTODELETE and KEEP options
2649 if ($vv =~ s/[\s,]+AUTODELETE=(\w+)//i) {
2650 $specific{'autodelete'} = $autodelete = uc($1);
2652 if ($vv =~ s/[\s,]+KEEP=(\d+)//i) {
2654 $keep = $keep_max if $keep_max and $keep > $keep_max;
2655 $specific{'keep'} = $keep;
2657 $to = normalize(lc($vv));
2658 $to =~ s/[\n\s;,]+/,/g;
2662 unless ($specific{'autodelete'}) {
2663 $specific{'autodelete'} = $autodelete = 'no';
2668 unless ($specific{'autodelete'}) {
2669 $specific{'autodelete'} = $autodelete = 'no';
2674 checkchars('to address',$to);
2675 push @to,split(',',$to);
2676 } elsif ($v eq 'ID') {
2678 checkchars('auth-ID',$id);
2679 } elsif ($v eq 'TCE') {
2680 $test = despace($vv);
2681 } elsif ($v eq 'OKEY' and $vv =~ /^(\w+)$/) {
2684 } elsif ($v eq 'FILEID' and $vv =~ /^(\w+)$/) {
2686 } elsif ($v eq 'CONTENTLENGTH' and $vv =~ /^(\d+)$/) {
2687 $contentlength = $1;
2688 } elsif ($v eq 'FILE' or $v eq 'FILENAME') {
2689 $file = strip_path(normalize($vv));
2690 } elsif ($v eq 'UID' and $vv =~ /^(\w+)$/) {
2692 } elsif ($v eq 'ID_FORGOTTEN') {
2693 $id_forgotten = $vv;
2694 } elsif ($v eq 'SHOWSTATUS' and $vv =~ /^(\w+)$/) {
2695 $showstatus = $uid = $1;
2696 } elsif ($v eq 'COMMENT') {
2697 $comment = decode_utf8(normalize($vv));
2698 $comment =~ s/^\s*!\.!/!SHORTMAIL!/;
2699 $comment =~ s/^!#!/!NOMAIL!/;
2700 $comment =~ s/^!-!/!NOSTORE!/;
2701 $nomail = $comment if $comment =~ /NOMAIL/;
2702 $nostore = $nomail = $comment if $comment =~ /NOSTORE/;
2703 $bcc .= " $from" if $comment =~ s/\s*!bcc!?\s*//i;
2704 # backward compatibility
2705 foreach my $cmd (qw(
2706 DELETE LIST CHECKQUOTA CHECKRECIPIENT RECEIVEDLOG SENDLOG FOPLOG FORWARD
2707 )) { $command = $comment if $comment eq $cmd }
2708 } elsif ($v eq 'COMMAND') {
2709 $command = normalize($vv);
2710 } elsif ($v eq 'BWLIMIT' and $vv =~ /^(\d+)$/) {
2712 } elsif ($v eq 'SEEK' and $vv =~ /^(\d+)$/) {
2714 } elsif ($v eq 'FILESIZE' and $vv =~ /^(\d+)$/) {
2715 $filesize = $1; # complete filesize!
2716 &check_space($filesize-$seek);
2717 } elsif ($v eq 'AUTODELETE' and $vv =~ /^(\w+)$/) {
2718 $specific{'autodelete'} = $autodelete = uc($1);
2719 } elsif ($v eq 'KEEP' and $vv =~ /^(\d+)$/) {
2721 $keep = $keep_max if $keep_max and $keep > $keep_max;
2722 $specific{'keep'} = $keep;
2723 } elsif ($v eq 'TIMEOUT' and $vv =~ /^(\d+)$/) {
2724 $specific{'timeout'} = $timeout = $1;
2730 my ($id,$to,$subuser,$gm,$skey,$gkey,$url,$fup);
2735 $fup =~ s:/fop:/fup:;
2738 if (open $from,'<',"$from/\@") {
2739 $id = getline($from);
2743 $url = "$fup/".b64("from=$from&id=$id");
2744 mail_forgotten($from,qqq(qq(
2745 'Your reqested F*EX auth-ID for $fup?from=$from is:'
2755 foreach my $skey (glob("$skeydir/*")) {
2756 if (-f $skey and open $skey,'<',$skey) {
2759 if (/^(\w+)=(.+)/) {
2760 $subuser = $2 if $1 eq 'from';
2761 $to = $2 if $1 eq 'to';
2766 if ($from and $to and $from eq $subuser) {
2768 mail_forgotten($subuser,qqq(qq(
2769 'Your reqested F*EX login is:'
2778 foreach my $gkey (glob("$gkeydir/*")) {
2779 if (-f $gkey and open $gkey,'<',$gkey) {
2782 if (/^(\w+)=(.+)/) {
2783 $gm = $2 if $1 eq 'from';
2784 $to = $2 if $1 eq 'to';
2789 if ($gm and $to and $from eq $gm) {
2791 mail_forgotten($gm,qqq(qq(
2792 'Your reqested F*EX login is:'
2799 http_die("<code>$from</code> is not a F*EX user on this server");
2803 sub mail_forgotten {
2810 open P,'|-',$sendmail,$user,$bcc or http_die("cannot start sendmail - $!\n");
2814 'Subject: F*EX service $hostname'
2819 close P or http_die("cannot send mail - $!\n");
2820 http_header('200 OK');
2821 print html_header($head);
2822 print "<h3>Mail has been sent to you ($from)</h3>\n";
2823 print "</body></html>\n";
2827 # lookup akey, skey and gkey (full and sub user and group)
2830 # only one key can be valid
2831 $akey = $gkey = '' if $skey;
2832 $akey = $skey = '' if $gkey;
2836 if ($skey =~ s/^MD5H:(.+)/$1/) {
2838 foreach my $s (glob "$skeydir/*") {
2840 if ($skey eq md5_hex($s.$sid)) {
2846 if (open $skey,'<',"$skeydir/$skey") {
2849 if (/^(\w+)=(.+)/) {
2850 $from = $2 if lc($1) eq 'from';
2851 @to = ($muser = $2) if lc($1) eq 'to';
2852 $rid = $id = $2 if lc($1) eq 'id';
2858 http_die("invalid SKEY <code>$skey</code>");
2864 if ($gkey =~ s/^MD5H:(.+)/$1/) {
2866 foreach my $g (glob "$gkeydir/*") {
2868 if ($gkey eq md5_hex($g.$sid)) {
2874 if (open $gkey,'<',"$gkeydir/$gkey") {
2877 if (/^(\w+)=(.+)/) {
2878 $from = $2 if lc($1) eq 'from';
2879 $to = $muser = $2 if lc($1) eq 'to';
2880 $rid = $id = $2 if lc($1) eq 'id';
2881 # $user = $2 if lc($1) eq 'user';
2888 http_die("invalid GKEY <code>$gkey</code>");
2892 if ($akey and not $id) {
2895 # sid is not set with web browser
2896 # akey with sid is set with schwuppdiwupp & co
2897 $idf = "$akeydir/$akey/@";
2899 if (open $idf,'<',$idf and $id = getline($idf)) {
2901 $from = readlink "$akeydir/$akey"
2902 or http_die("internal server error: no $akey symlink");
2904 $from = untaint($from);
2905 if ($akey ne md5_hex("$from:$id")) {
2916 # check if there is enough space on spool
2919 my ($df,$free,$uprq);
2922 if (open $df,"df -k $spooldir|") {
2924 if (/^.+?\s+\d+\s+\d+\s+(\d+)/ and $req/1024 > $1) {
2925 $free = int($1/1024);
2926 $uprq = int($req/$MB);
2927 if (not $nomail and open P,"|$sendmail -t") {
2931 'Subject: F*EX spool out of space'
2933 'F*EX spool $spooldir on $ENV{SERVER_NAME} is out of space.'
2935 'Current free space: $free MB'
2936 'Upload request: $uprq MB'
2940 debuglog("aborting because not enough free space in spool ($free MB)");
2941 http_die("not enough free space for this upload");
2949 # global substitution as a function like in gawk
2964 $msg = sprintf "%s [%s_%s] %s (%s) %s\n",
2965 isodate(time),$$,$ENV{REQUESTCOUNT},$from,$fra,$msg;
2966 writelog($log,$msg);
2980 my $to = join(',',@to);
2982 $SIG{__DIE__} = 'DEFAULT';
2983 foreach (keys %SIG) { $SIG{$_} = 'DEFAULT' }
2985 $msg = @_ ? "@_" : '???';
2988 $msg = sprintf "%s %s (%s) %s %s caught SIGNAL %s %s\n",
2993 encode_Q($file||'-'),
2995 $RB?"(after $RB bytes)":"";
2997 writelog($log,$msg);
2999 if ($sig eq 'DIE') {
3003 die "SIGNAL $msg\n";
3008 sub present_locales {
3010 my @locales = @::locales; # from fex.ph
3015 $url =~ s/locale=\w+&//g;
3021 map { $_ = "$FEXHOME/locale/$_" } @locales;
3023 @locales = glob "$FEXHOME/locale/*";
3028 foreach my $locale (my @loop = @locales) {
3029 if (-x "$locale/cgi-bin/fup") {
3030 $lang = "$locale/lang.html";
3032 if (open $lang,'<',$lang and $lang = getline($lang)) {
3037 print "<a href=\"${url}locale=$locale\">$lang</a> ";
3049 if (open $logo,"$docdir/logo.jpg") {
3050 $camel = md5_hex(<$logo>) eq 'ad8a95bba8dd1a61d70bd38611bc2059';
3052 if ($camel and open $logo,"$docdir/action-fex-camel.gif") {
3053 $camel = md5_hex(<$logo>) eq '1f3d7acc70377496f95c5adddaf4ca7b';
3055 http_die("Missing camel") unless $camel;