3 # F*EX CGI for public upload
5 # Author: Ulli Horlacher <framstag@rus.uni-stuttgart.de>
8 BEGIN { ($ENV{PERLINIT}||'') =~ /(.+)/s and eval $1 }
13 (our $FEXLIB) = $ENV{FEXLIB} =~ /(.+)/;
14 die "$0: no $FEXLIB\n" unless -d $FEXLIB;
18 our $error = 'F*EX public upload ERROR';
19 our $head = "$ENV{SERVER_NAME} F*EX public upload";
23 our (@public_recipients);
28 # load common code, local config: $FEXLIB/fex.ph
29 require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n";
33 chdir $spooldir or http_die("$spooldir - $!\n");
37 my $qs = $ENV{QUERY_STRING};
38 (my $multi) = $qs =~ s/(^|&)multi//;
40 # parse HTTP QUERY_STRING (parameter=value pairs)
42 foreach (split '&',$qs) {
46 s/%([a-f0-9]{2})/chr(hex($1))/gie;
47 if (/([<>\'\`\"\000-\040])/) {
49 "\"&#%s;\" is not allowed in URL parameter",
58 # parse HTTP POST body
59 if ($ENV{REQUEST_METHOD} eq 'POST') {
60 if ($ENV{CONTENT_TYPE} =~ /boundary=\"?([\w\-\+\/_]+)/) {
63 http_die("malformed HTTP POST (no boundary found)");
66 binmode(STDIN,':raw');
68 READPOST: while (&nvt_read) {
69 if (/^Content-Disposition:\s*form-data;\s*name="([a-z]\w*)"/i) {
71 while (&nvt_read) { last if /^\s*$/ }
74 NEXTPART: while (&nvt_read) {
75 last READPOST if /^--\Q$boundary--/;
76 last NEXTPART if /^--\Q$boundary/;
82 unless (@public_recipients) {
83 html_error($error,"No public recipients defined by administrator");
86 if ($to and not grep /^\Q$to\E$/i,@public_recipients) {
87 html_error($error,"$to is not a public recipient");
90 if ($to and $from and checkaddress($from)) {
93 "Location: $ENV{PROTO}://$ENV{HTTP_HOST}/fup?from=$from&to=$to&id=PUBLIC",
97 exec($FEXHOME.'/bin/fexsrv') if $ENV{KEEP_ALIVE};
101 http_header('200 ok');
102 print html_header($head);
105 foreach my $locale (glob "$FEXHOME/locale/*") {
106 if (-f "$locale/cgi-bin/pup") {
107 my $langf = "$locale/lang.html";
110 if (open $langf,'<',$langf) {
111 $lang = getline($langf);
114 push @locales,"<a href=\"/pup?to=$to&locale=$locale\">$lang</a>";
117 print "<h3>@locales</h3>\n" if @locales > 1;
121 '<form name="upload"'
124 ' accept-charset="UTF-8"'
125 ' enctype="multipart/form-data">'
126 ' <input type="hidden" name="id" value="PUBLIC">'
127 ' <input type="hidden" name="autodelete" value="no">'
128 ' <table border="1">'
133 ' <tr><td>your e-mail address:<td>$from</tr>'
134 ' <input type="hidden" name="from" value="$from">'
138 ' <tr><td>your e-mail address:<td><input type="text" name="from" size="80"></tr>'
144 ' <tr><td>recipient:<td>$to</tr>'
145 ' <input type="hidden" name="to" value="$to">'
149 foreach my $pr (@public_recipients) {
150 push @pr,qq(<input type="checkbox" name="to" value="$pr">)
151 ."<code>$pr</code><br>";
154 ' <tr><td>recipient:<td>@pr</tr>'
157 foreach my $pr (@public_recipients) {
158 push @pr,"<option>$pr</option>";
161 ' <tr><td>recipient:<td><select name="to" size="1">@pr</select></tr>'
169 ' <input type="submit" name="continue" value="continue">'
174 # set parameter variables
178 $v = uc(despace($v));
179 if ($v eq 'LOCALE' and $vv =~ /^(\w+)$/) {
181 } elsif ($v eq 'FROM') {
182 $from = normalize_email($vv);
183 } elsif ($v eq 'TO') {
184 $to = normalize_email($vv);