3 # F*EX CGI for public upload
5 # Author: Ulli Horlacher <framstag@rus.uni-stuttgart.de>
8 use CGI::Carp qw(fatalsToBrowser);
11 (our $FEXLIB) = $ENV{FEXLIB} =~ /(.+)/;
12 die "$0: no $FEXLIB\n" unless -d $FEXLIB;
16 our $error = 'F*EX public upload ERROR';
17 our $head = "$ENV{SERVER_NAME} F*EX public upload";
21 our (@public_recipients);
26 # load common code, local config: $FEXLIB/fex.ph
27 require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n";
31 chdir $spooldir or http_die("$spooldir - $!\n");
35 my $qs = $ENV{QUERY_STRING};
36 (my $multi) = $qs =~ s/(^|&)multi//;
38 # parse HTTP QUERY_STRING (parameter=value pairs)
40 foreach (split '&',$qs) {
44 s/%([a-f0-9]{2})/chr(hex($1))/gie;
45 if (/([<>\'\`\"\000-\040])/) {
47 "\"&#%s;\" is not allowed in URL parameter",
56 # parse HTTP POST body
57 if ($ENV{REQUEST_METHOD} eq 'POST') {
58 if ($ENV{CONTENT_TYPE} =~ /boundary=\"?([\w\-\+\/_]+)/) {
61 http_die("malformed HTTP POST (no boundary found)");
64 binmode(STDIN,':raw');
66 READPOST: while (&nvt_read) {
67 if (/^Content-Disposition:\s*form-data;\s*name="([a-z]\w*)"/i) {
69 while (&nvt_read) { last if /^\s*$/ }
72 NEXTPART: while (&nvt_read) {
73 last READPOST if /^--\Q$boundary--/;
74 last NEXTPART if /^--\Q$boundary/;
80 unless (@public_recipients) {
81 html_error($error,"No public recipients defined by administrator");
84 if ($to and not grep /^\Q$to\E$/i,@public_recipients) {
85 html_error($error,"$to is not a public recipient");
88 if ($to and $from and checkaddress($from)) {
91 "Location: $ENV{PROTO}://$ENV{HTTP_HOST}/fup?from=$from&to=$to&id=PUBLIC",
95 exec($FEXHOME.'/bin/fexsrv') if $ENV{KEEP_ALIVE};
99 http_header('200 ok');
100 print html_header($head);
103 foreach my $locale (glob "$FEXHOME/locale/*") {
104 if (-f "$locale/cgi-bin/pup") {
105 my $langf = "$locale/lang.html";
108 if (open $langf,'<',$langf) {
109 $lang = getline($langf);
112 push @locales,"<a href=\"/pup?to=$to&locale=$locale\">$lang</a>";
115 print "<h3>@locales</h3>\n" if @locales > 1;
119 '<form name="upload"'
122 ' accept-charset="UTF-8"'
123 ' enctype="multipart/form-data">'
124 ' <input type="hidden" name="id" value="PUBLIC">'
125 ' <input type="hidden" name="autodelete" value="no">'
126 ' <table border="1">'
131 ' <tr><td>your e-mail address:<td>$from</tr>'
132 ' <input type="hidden" name="from" value="$from">'
136 ' <tr><td>your e-mail address:<td><input type="text" name="from" size="80"></tr>'
142 ' <tr><td>recipient:<td>$to</tr>'
143 ' <input type="hidden" name="to" value="$to">'
147 foreach my $pr (@public_recipients) {
148 push @pr,qq(<input type="checkbox" name="to" value="$pr">)
149 ."<code>$pr</code><br>";
152 ' <tr><td>recipient:<td>@pr</tr>'
155 foreach my $pr (@public_recipients) {
156 push @pr,"<option>$pr</option>";
159 ' <tr><td>recipient:<td><select name="to" size="1">@pr</select></tr>'
167 ' <input type="submit" name="continue" value="continue">'
172 # set parameter variables
176 $v = uc(despace($v));
177 if ($v eq 'LOCALE' and $vv =~ /^(\w+)$/) {
179 } elsif ($v eq 'FROM') {
180 $from = normalize_email($vv);
181 } elsif ($v eq 'TO') {
182 $to = normalize_email($vv);
187 # read one line from STDIN (net socket) and assign it to $_
188 # returns number of read bytes
192 if (defined ($_ = <STDIN>)) {