]> git.treefish.org Git - fex.git/blobdiff - cgi-bin/fup
Original release 20160328
[fex.git] / cgi-bin / fup
index 7d222f9a3b9b14445914dc0b9e93a4f40ef72e2b..2a799acd3293d2d2cf7768dbfdc2762ae4664f04 100755 (executable)
@@ -58,6 +58,7 @@ my @header;           # HTTP entity header
 my $fileid;            # file ID
 my $captive;
 my $muser;             # main user fur sub or group user
+my %specific;          # upload specific KEEP and AUTODELETE parameters
 
 # load common code, local config: $FEXLIB/fex.ph
 require "$FEXLIB/fex.pp";
@@ -109,7 +110,8 @@ if ($addto) {
   my %to;
   foreach $to (@to) { $to{$to} = 1 }
   push @to,$addto unless $to{$addto};
-  if ($submit and @to == 1) { $addto = '' }
+  # user has submitted with [select from your address book] ?
+  # if ($submit and @to == 1) { $addto = '' }
 }
 
 $to = join(',',@to);
@@ -631,11 +633,12 @@ if (($from and $id and $rid eq $id or $gkey or $skey) and $command) {
     foreach my $to (@group?@group:@to) {
       # my $options = sprintf "(autodelete=%s,keep=%s,locale=%s)",
       # readlink "$to/\@LOCALE"||$locale||$locale{$to}||$default_locale;
-      my $options = sprintf "(autodelete=%s,keep=%s,locale=%s,notification=%s)",
+      # my $options = sprintf "(autodelete=%s,keep=%s,locale=%s,notification=%s)",
+      my $options = sprintf "(autodelete=%s,keep=%s,locale=%s)",
         $autodelete{$to}||$autodelete,
         $keep{$to}||$keep_default,
-        readlink("$to/\@LOCALE")||$default_locale,
-        readlink("$to/\@NOTIFICATION")||'full';
+        readlink("$to/\@LOCALE")||$locale{$to}||$default_locale;
+        readlink("$to/\@NOTIFICATION")||'full';
       nvt_print("X-Recipient: $to $options");
     }
     nvt_print('');
@@ -840,6 +843,8 @@ unless ($file) {
   {
     present_locales('/fup');
 
+    # print "[$addto] [$submit] [@to]<p>\n";
+
     @ab = ("<option></option>");
 
     # select menu from server address book
@@ -849,6 +854,7 @@ unless ($file) {
         if (/(\S+)[=\s]+(\S+@[\w.-]+\S*)/) {
           $_ = "$1 &lt;$2>";
           s/,.*/,.../g;
+          s/:.*/>/;
           push @ab,"<option>$_</option>";
         }
       }
@@ -948,9 +954,6 @@ unless ($file) {
       print "Alternate Java client</a> (for files > 2 GB or sending of more than one file)\n";
     }
     print &logout;
-    if (-x "$FEXHOME/cgi-bin/login") {
-      print $info_login||$info_1;
-    }
     pq(qq(
       '<p><hr><p>'
       '<b>'
@@ -962,8 +965,9 @@ unless ($file) {
       '<p>'
       'Use a <a href="/tools.html">F*EX client</a> if you want to send more than one file or resume an interrupted upload.'
       '</body></html>'
-      '<p>
+      '<p>'
    ));
+    print $info_1;
     exit;
   }
 
@@ -1240,7 +1244,7 @@ unless ($file) {
   # }
   print "</form>\n";
 
-  print $info_1;
+  print $info_login||$info_1;
 
   if ($debug and $debug>1) {
     print "<hr>\n<pre>\n";
@@ -1417,11 +1421,12 @@ if ($nostore) {
     my $to = $_;
     $to =~ s/:\w+=.*//; # remove options from address
     my $file = "$to/$from/$fkey";
-    my $options = sprintf "(autodelete=%s,keep=%s,locale=%s,notification=%s)",
+    # my $options = sprintf "(autodelete=%s,keep=%s,locale=%s,notification=%s)",
+    my $options = sprintf "(autodelete=%s,keep=%s,locale=%s)",
       readlink("$file/autodelete")||$autodelete,
       readlink("$file/keep")||readlink("$to/\@KEEP")||$keep_default,
-      readlink("$to/\@LOCALE")||readlink("$file/locale")||$default_locale,
-      readlink("$to/\@NOTIFICATION")||'full';
+      readlink("$to/\@LOCALE")||readlink("$file/locale")||$default_locale;
+      readlink("$to/\@NOTIFICATION")||'full';
     nvt_print("X-Recipient: $to $options");
     nvt_print("X-Location: $durl/$dkey{$to}/$fkey") unless $restricted;
   }
@@ -1510,7 +1515,13 @@ if ($okey) {
   print "&bwlimit=$bwlimit&autodelete=$autodelete&keep=$keep\">";
   print "send another file</a>\n";
   if ($http_client !~ /fexsend/ and $http_client =~ /Linux/i) {
-    print qq'<p>Hi Linux-user, try <a href="/FAQ/user.html#Why_should_I_use_a_special_F_EX_client">fexsend</a>! &#9786;<p>\n';
+    print '<p>Hi Linux-user, try ',
+          '<a href="/FAQ/user.html#Why_should_I_use_a_special_F_EX_client">',
+          "fexsend</a>! &#9786;<p>\n";
+  }
+  if ($http_client !~ /fexit/ and $http_client =~ /Windows/i) {
+    print '<p>Hi Windows-user, try <a href="/fexit.html">fexit</a>! ',
+          "&#9786;<p>\n";
   }
   print &logout;
 }
@@ -1558,6 +1569,9 @@ sub parse_request {
         if ($p eq 'KEEP' and /^\d+$/) {
           $specific{'keep'} = $keep = $v;
         }
+        # if ($p eq 'LOCALE') {
+        #   $specific{'locale'} = $locale = $v;
+        # }
       }
     }
   }
@@ -1677,23 +1691,39 @@ sub parse_request {
 
   # collect multiple addresses and check for aliases (not group)
   if (@to and "@to" !~ /^@[\w-]+$/
-      and not ($gkey or $addto or $command =~ /^LIST(RECEIVED)?$/))
-  {
-
+      and not ($gkey or $addto or $command =~ /^LIST(RECEIVED)?$/)) {
     # read address book
     if ($from and open my $AB,'<',"$from/\@ADDRESS_BOOK") {
-      my ($alias,$address,$autodelete,$locale,$keep);
+      my ($alias,$addresses,$autodelete,$locale,$keep);
       while (<$AB>) {
         s/#.*//;
         $_ = lc $_;
         if (s/^\s*(\S+)[=\s]+(\S+)//) {
-          ($alias,$address) = ($1,$2);
+          ($alias,$addresses) = ($1,$2);
+          # alias specific options?
           $autodelete = $locale = $keep = '';
           $autodelete = $1 if /autodelete=(\w+)/;
           $locale     = $1 if /locale=(\w+)/;
           $keep       = $1 if /keep=(\d+)/;
-          foreach my $address (split(",",$address)) {
-            $address .= '@'.$mdomain if $mdomain and $address !~ /@/;
+          foreach my $address (split(",",$addresses)) {
+            # alias address specific :options?
+            if ($address =~ s/(.+?):(.+)/$1/) {
+              my @options = split(':',$2);
+              $address = expand($address);
+              foreach (@options) {
+                if (/^keep=(\d+)$/i) {
+                  $alias_keep{$alias}{$address} = $1
+                }
+                if (/^autodelete=(yes|no|delay)$/i) {
+                  $alias_autodelete{$alias}{$address} = $1
+                }
+                if (/^locale=(\w+)$/i) {
+                  $alias_locale{$alias}{$address} = $1
+                }
+              }
+            } else {
+              $address = expand($address);
+            }
             push @{$ab{$alias}},$address;
             $autodelete{$alias} = $autodelete if $autodelete;
             $keep{$alias}       = $keep       if $keep;
@@ -1707,46 +1737,86 @@ sub parse_request {
     # look for recipient's options and eliminate dupes
     %to = ();
     foreach my $to (my @loop = @to) {
-     # address book alias?
-      if ($to !~ /@/ and $ab{$to}) {
-        foreach my $address (my @loop = @{$ab{$to}}) {
-          $address .= '@'.$mdomain if $mdomain and $address !~ /@/;
+      # address book alias?
+      if ($to !~ /@/ and ($ab{$to} or $to =~ /(.+?):(.+)/ and $ab{$1})) {
+        my $alias = $to;
+        my @options = ();
+        $alias =~ s/:(.*)// and @options = split(':',$1);
+        if (@options) {
+          # alias with :options
+          $alias =~ s/:.*//;
+          foreach my $address (my @loop = @{$ab{$alias}}) {
+            $to{$address} = $address; # ignore dupes
+            foreach (@options) {
+              $keep{$address} = $1       if /^keep=(\d+)$/i;
+              $autodelete{$address} = $1 if /^autodelete=(yes|no|delay)$/i;
+              $locale{$address} = $1     if /^locale=(\w+)$/i;
+            }
+          }
+        }
+        foreach my $address (my @loop = @{$ab{$alias}}) {
           $to{$address} = $address; # ignore dupes
-          if ($specific{'autodelete'}) {
-            $autodelete{$address} = $specific{'autodelete'};
-          } elsif ($autodelete{$to}) {
-            $autodelete{$address} = $autodelete{$to};
-          } else {
-            $autodelete{$address} = readlink "$address/\@AUTODELETE"
-                                    || $autodelete;
+          unless ($keep{$address}) {
+            $keep{$address} = $keep{$alias} if $keep{$alias};
+            if ($specific{'keep'}) {
+              $keep{$address} = $specific{'keep'}
+            } elsif (my $keep = $alias_keep{$alias}{$address}) {
+              $keep{$address} = $keep;
+            } elsif ($keep{$alias}) {
+              $keep{$address} = $keep{$alias}
+            }
           }
-          if (my $locale = readlink "$address/\@LOCALE") {
-            $locale{$address} = $locale;
-          } elsif ($locale{$to}) {
-            $locale{$address} = $locale{$to};
-          } else {
-            $locale{$address} = $::locale ;
+          unless ($autodelete{$address}) {
+            if ($specific{'autodelete'}) {
+              $autodelete{$address} = $specific{'autodelete'};
+            } elsif (my $autodelete = $alias_autodelete{$alias}{$address}) {
+              $autodelete{$address} = $keep;
+            } elsif ($autodelete{$alias}) {
+              $autodelete{$address} = $autodelete{$alias};
+            } else {
+              $autodelete{$address} = readlink "$address/\@AUTODELETE"
+                                      || $autodelete;
+            }
           }
           unless ($locale{$address}) {
-            $locale{$address} = $default_locale || 'english';
+            if (my $locale = readlink "$address/\@LOCALE") {
+              $locale{$address} = $locale;
+            } elsif ($locale{$alias}) {
+              $locale{$address} = $locale{$alias};
+            } elsif ($locale = $alias_locale{$alias}{$address}) {
+              $locale{$address} = $locale;
+            } else {
+              $locale{$address} = $::locale ;
+            }
+            $locale{$address} ||= $default_locale || 'english';
           }
-          if ($specific{'keep'}) { $keep{$address} = $specific{'keep'} }
-          elsif ($keep{$to})     { $keep{$address} = $keep{$to} }
         }
       } else {
+        # regular address, not an alias
+        if ($to =~ s/(.+?):(.+)/$1/) {
+          my @options = split(':',$2);
+          $to = expand($to);
+          foreach (@options) {
+            $keep{$to} = $1       if /^keep=(\d+)$/i;
+            $autodelete{$to} = $1 if /^autodelete=(yes|no|delay)$/i;
+            $locale{$to} = $1     if /^locale=(\w+)$/i;
+          }
+        }
         $to = expand($to);
         $to{$to} = $to; # ignore dupes
         unless ($autodelete{$to}) {
-          $autodelete{$to} = readlink "$to/\@AUTODELETE" || $autodelete;
+          $autodelete{$to} = untaint(readlink("$to/\@AUTODELETE")
+                                     ||$autodelete);
+          if ($specific{'autodelete'}) {
+            $autodelete{$to} = $specific{'autodelete'};
+          }
+        }
+        unless ($keep{$to}) {
+          $keep{$to} = $keep_default;
+          $keep{$to} = $keep                          if $keep;
+          $keep{$to} = untaint(readlink "$to/\@KEEP") if -l "$to/\@KEEP";
+          $keep{$to} = $specific{'keep'}              if $specific{'keep'};
         }
-        $autodelete{$to} = $specific{'autodelete'}  if $specific{'autodelete'};
-        $keep{$to} = $keep_default;
-        $keep{$to} = $keep                          if $keep;
-        $keep{$to} = untaint(readlink "$to/\@KEEP") if -l "$to/\@KEEP";
-        $keep{$to} = $specific{'keep'}              if $specific{'keep'};
-        # recipient specific parameters
-        $keep{$to}       = $1 if $to =~ /:keep=(\d+)/i;
-        $autodelete{$to} = $1 if $to =~ /:autodelete=(\w+)/i;
       }
       $autodelete{$to} = 'NO' if $to =~ /$amdl/; # mailing lists, etc
       if (-e "$to/\@CAPTIVE") {
@@ -2435,7 +2505,7 @@ sub forward {
     }
 
     @to = keys %to;
-    
+
     http_header('200 OK');
     print html_header($head);
 
@@ -2614,15 +2684,15 @@ sub setparam {
     $locale = $1;
   } elsif ($v eq 'REDIRECT' and $vv =~ /^([\w?=]+)$/) {
     $redirect = $1;
-  } elsif (($v eq 'KEY' or $v eq 'SKEY') and $vv =~ /^([\w:]+)$/) {
+  } elsif ($v eq 'SKEY' and $vv =~ /^([\w:]+)/) {
     $skey = $1;
     $restricted = $v;
-  } elsif ($v eq 'GKEY' and $vv =~ /^([\w:]+)$/) {
+  } elsif ($v eq 'GKEY' and $vv =~ /^([\w:]+)/) {
     $gkey = $1 unless $nomail;
     $restricted = $v;
-  } elsif ($v eq 'DKEY' and $vv =~ /^(\w+)$/) {
+  } elsif ($v eq 'DKEY' and $vv =~ /^(\w+)/) {
     $dkey = $1;
-  } elsif ($v eq 'AKEY' and $vv =~ /^(\w+)$/) {
+  } elsif ($v eq 'AKEY' and $vv =~ /^(\w+)/) {
     $akey = $1;
   } elsif ($v eq 'FROM' or $v eq 'USER') {
     $from = normalize_email($vv);
@@ -2721,7 +2791,7 @@ sub setparam {
     $keep = $keep_max if $keep_max and $keep > $keep_max;
     $specific{'keep'} = $keep;
   } elsif ($v eq 'TIMEOUT' and $vv =~ /^(\d+)$/) {
-    $specific{'timeout'} = $timeout = $1;
+     $specific{'timeout'} = $timeout = $1;
   }
 }
 
@@ -2827,6 +2897,11 @@ sub mail_forgotten {
 # lookup akey, skey and gkey (full and sub user and group)
 sub check_keys {
 
+  if (@to and "@to" ne '_') {
+    http_die("you cannot mix TO and SKEY URL parameters") if $skey;
+    http_die("you cannot mix TO and GKEY URL parameters") if $gkey;
+  }
+
   # only one key can be valid
   $akey = $gkey = '' if $skey;
   $akey = $skey = '' if $gkey;