| 1 |
#!/usr/bin/perl -wT |
| 2 |
|
| 3 |
# F*EX CGI for public upload |
| 4 |
# |
| 5 |
# Author: Ulli Horlacher <[email protected]> |
| 6 |
# |
| 7 |
|
| 8 |
BEGIN { ($ENV{PERLINIT}||'') =~ /(.+)/s and eval $1 } |
| 9 |
|
| 10 |
# use utf8; |
| 11 |
|
| 12 |
# add fex lib |
| 13 |
(our $FEXLIB) = $ENV{FEXLIB} =~ /(.+)/; |
| 14 |
die "$0: no $FEXLIB\n" unless -d $FEXLIB; |
| 15 |
|
| 16 |
$| = 1; |
| 17 |
|
| 18 |
our $error = 'F*EX public upload ERROR'; |
| 19 |
our $head = "$ENV{SERVER_NAME} F*EX public upload"; |
| 20 |
our $locale = ''; |
| 21 |
|
| 22 |
# import from fex.ph |
| 23 |
our (@public_recipients,$hide_public_recipients); |
| 24 |
|
| 25 |
# import from fex.pp |
| 26 |
our ($FEXHOME); |
| 27 |
|
| 28 |
# load common code, local config: $FEXLIB/fex.ph |
| 29 |
require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n"; |
| 30 |
|
| 31 |
$from = $to = ''; |
| 32 |
|
| 33 |
chdir $spooldir or http_die("$spooldir - $!\n"); |
| 34 |
|
| 35 |
&check_maint; |
| 36 |
|
| 37 |
my $qs = $ENV{QUERY_STRING}; |
| 38 |
(my $multi) = $qs =~ s/(^|&)multi//; |
| 39 |
|
| 40 |
# parse HTTP QUERY_STRING (parameter=value pairs) |
| 41 |
if ($qs) { |
| 42 |
foreach (split '&',$qs) { |
| 43 |
if (s/^(\w+)=//) { |
| 44 |
my $x = $1; |
| 45 |
# decode URL-encoding |
| 46 |
s/%([a-f0-9]{2})/chr(hex($1))/gie; |
| 47 |
if (/([<>\'\`\"\000-\040])/) { |
| 48 |
http_die(sprintf( |
| 49 |
"\"&#%s;\" is not allowed in URL parameter", |
| 50 |
ord($1) |
| 51 |
)); |
| 52 |
} |
| 53 |
setparam($x,$_); |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
# parse HTTP POST body |
| 59 |
if ($ENV{REQUEST_METHOD} eq 'POST') { |
| 60 |
if ($ENV{CONTENT_TYPE} =~ /boundary=\"?([\w\-\+\/_]+)/) { |
| 61 |
$boundary = $1; |
| 62 |
} else { |
| 63 |
http_die("malformed HTTP POST (no boundary found)"); |
| 64 |
} |
| 65 |
|
| 66 |
binmode(STDIN,':raw'); |
| 67 |
|
| 68 |
READPOST: while (&nvt_read) { |
| 69 |
if (/^Content-Disposition:\s*form-data;\s*name="([a-z]\w*)"/i) { |
| 70 |
my $x = $1; |
| 71 |
while (&nvt_read) { last if /^\s*$/ } |
| 72 |
&nvt_read; |
| 73 |
setparam($x,$_); |
| 74 |
NEXTPART: while (&nvt_read) { |
| 75 |
last READPOST if /^--\Q$boundary--/; |
| 76 |
last NEXTPART if /^--\Q$boundary/; |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
unless (@public_recipients) { |
| 83 |
html_error($error,"No public recipients defined by administrator"); |
| 84 |
} |
| 85 |
|
| 86 |
if ($to and not grep /^\Q$to\E$/i,@public_recipients) { |
| 87 |
html_error($error,"$to is not a public recipient"); |
| 88 |
} |
| 89 |
|
| 90 |
if (not $to and ($hide_public_recipients||'') =~ /^y/i) { |
| 91 |
html_error($error,"public recipient address missing"); |
| 92 |
} |
| 93 |
|
| 94 |
if ($to and $from and checkaddress($from)) { |
| 95 |
nvt_print( |
| 96 |
"HTTP/1.1 302 Found", |
| 97 |
"Location: $ENV{PROTO}://$ENV{HTTP_HOST}/fup?from=$from&to=$to&id=PUBLIC", |
| 98 |
'Content-Length: 0', |
| 99 |
"" |
| 100 |
); |
| 101 |
exec($FEXHOME.'/bin/fexsrv') if $ENV{KEEP_ALIVE}; |
| 102 |
exit; |
| 103 |
} |
| 104 |
|
| 105 |
http_header('200 ok'); |
| 106 |
print html_header($head); |
| 107 |
|
| 108 |
my @locales; |
| 109 |
foreach my $locale (glob "$FEXHOME/locale/*") { |
| 110 |
if (-f "$locale/cgi-bin/pup") { |
| 111 |
my $langf = "$locale/lang.html"; |
| 112 |
$locale =~ s:.*/::; |
| 113 |
$lang = $locale; |
| 114 |
if (open $langf,'<',$langf) { |
| 115 |
$lang = getline($langf); |
| 116 |
close $langf; |
| 117 |
} |
| 118 |
push @locales,"<a href=\"/pup?to=$to&locale=$locale\">$lang</a>"; |
| 119 |
} |
| 120 |
} |
| 121 |
print "<h3>@locales</h3>\n" if @locales > 1; |
| 122 |
|
| 123 |
|
| 124 |
pq(qq( |
| 125 |
'<form name="upload"' |
| 126 |
' action="/fup"' |
| 127 |
' method="post"' |
| 128 |
' accept-charset="UTF-8"' |
| 129 |
' enctype="multipart/form-data">' |
| 130 |
' <input type="hidden" name="id" value="PUBLIC">' |
| 131 |
' <input type="hidden" name="autodelete" value="no">' |
| 132 |
' <table border="1">' |
| 133 |
)); |
| 134 |
|
| 135 |
if ($from) { |
| 136 |
pq(qq( |
| 137 |
' <tr><td>your email address:<td>$from</tr>' |
| 138 |
' <input type="hidden" name="from" value="$from">' |
| 139 |
)); |
| 140 |
} else { |
| 141 |
pq(qq( |
| 142 |
' <tr><td>your email address:<td><input type="text" name="from" size="80"></tr>' |
| 143 |
)); |
| 144 |
} |
| 145 |
|
| 146 |
if ($to) { |
| 147 |
pq(qq( |
| 148 |
' <tr><td>recipient:<td>$to</tr>' |
| 149 |
' <input type="hidden" name="to" value="$to">' |
| 150 |
)); |
| 151 |
} else { |
| 152 |
if ($multi) { |
| 153 |
foreach my $pr (@public_recipients) { |
| 154 |
push @pr,qq(<input type="checkbox" name="to" value="$pr">) |
| 155 |
."<code>$pr</code><br>"; |
| 156 |
} |
| 157 |
pq(qq( |
| 158 |
' <tr><td>recipient:<td>@pr</tr>' |
| 159 |
)); |
| 160 |
} else { |
| 161 |
foreach my $pr (@public_recipients) { |
| 162 |
push @pr,"<option>$pr</option>"; |
| 163 |
} |
| 164 |
pq(qq( |
| 165 |
' <tr><td>recipient:<td><select name="to" size="1">@pr</select></tr>' |
| 166 |
)); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
pq(qq( |
| 171 |
' </table>' |
| 172 |
' <p>' |
| 173 |
' <input type="submit" name="continue" value="continue">' |
| 174 |
'</form>' |
| 175 |
)); |
| 176 |
|
| 177 |
|
| 178 |
# set parameter variables |
| 179 |
sub setparam { |
| 180 |
my ($v,$vv) = @_; |
| 181 |
|
| 182 |
$v = uc(despace($v)); |
| 183 |
if ($v eq 'LOCALE' and $vv =~ /^(\w+)$/) { |
| 184 |
$locale = $1; |
| 185 |
} elsif ($v eq 'FROM') { |
| 186 |
$from = normalize_email($vv); |
| 187 |
} elsif ($v eq 'TO') { |
| 188 |
$to = normalize_email($vv); |
| 189 |
} |
| 190 |
} |