3 # FEX CGI for (user) operation control
5 # Author: Ulli Horlacher <framstag@rus.uni-stuttgart.de>
9 use CGI::Carp qw(fatalsToBrowser);
11 use Digest::MD5 qw(md5_hex);
13 $CGI::LIST_CONTEXT_WARN = 0;
14 $CGI::LIST_CONTEXT_WARN = 0;
17 ($FEXLIB) = $ENV{FEXLIB} =~ /(.+)/;
18 die "$0: no $FEXLIB\n" unless -d $FEXLIB;
20 our ($FEXHOME,$mdomain,$nomail,$faillog);
23 # load common code, local config : $HOME/lib/fex.ph
24 require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n";
26 my $error = 'F*EX operation control ERROR';
28 chdir $spooldir or die "$spooldir - $!\n";
30 $akeydir = "$spooldir/.akeys";
33 # look for CGI parameters
34 foreach my $v (param) {
36 debuglog("Param: $v=\"$vv\"");
37 if ($v =~ /^akey$/i and $vv =~ /^(\w+)$/) {
39 } elsif ($v =~ /^(from|user)$/i) {
40 $user = normalize_email($vv);
41 $user .= '@'.$mdomain if $mdomain and $user !~ /@/;
42 } elsif ($v =~ /^id$/i) {
43 $id = checkchars($vv);
47 if ($akey and not $user and not $id) {
48 if (open $akey,'<',"$akeydir/$akey/@" and $id = getline($akey)) {
50 $user = readlink "$akeydir/$akey"
51 or http_die("internal server error: no $akey symlink");
53 $user = untaint($user);
54 if ($akey ne md5_hex("$user:$id")) {
60 $head = "$ENV{SERVER_NAME} F*EX operation control";
62 # display HTML form and request user data
65 unless (open $idf,'<',"$user/@") {
66 faillog("user $from, id $id");
67 html_error($error,"wrong user or auth-ID");
70 if (-e "$user/\@CAPTIVE") { html_error($error,"captive user") }
75 $akey = untaint(md5_hex("$user:$id"));
76 unlink "$akeydir/$akey";
77 symlink "../$user","$akeydir/$akey";
80 faillog("user $from, id $id");
81 html_error($error,"wrong user or auth-ID");
83 unlink $faillog if $faillog;
84 http_header("200 OK");
85 print html_header($head);
86 # authorized login URL
87 my $url = "$ENV{PROTO}://$ENV{HTTP_HOST}/fup/".b64("from=$user&id=$id");
89 '<h2>for user <a href="$url">$user</a></h2>'
92 ($quota,$du) = check_sender_quota($user);
95 <tr title="You as the sender have a server disk quota of $quota MB and currently using $du MB">
96 <td>sender quota (used):<td align=\"right\">$quota ($du) MB
100 ($quota,$du) = check_recipient_quota($user);
103 <tr title="You as the recipient have a server disk quota of $quota MB and currently using $du MB">
104 <td>recipient quota (used):<td align=\"right\">$quota ($du) MB
111 '<a href="/fup?akey=$akey&command=LISTRECEIVED">'
112 'Retrieve a list of all your received files</a> in F*EX spool.'
116 '<form action="/fuc?akey=$akey"'
118 ' accept-charset="UTF-8"'
119 ' enctype="multipart/form-data">'
120 ' <input type="hidden" name="user" value="$user">'
121 ' <input type="hidden" name="id" value="$id">'
122 ' <script>function show_id() {return(alert("auth-ID: $id"));}</script>'
123 ' Change your <a href="" onclick="show_id();" title="$id">auth-ID</a> to'
124 ' <input type="text" name="nid" size="16">'
125 ' <input type="submit" value="remember it!">'
127 if (-s "$user/\@ALLOWED_RECIPIENTS") {
129 # ' (You are a restricted user)';
133 # '<a href="/fup?akey=$akey&command=LISTSENT">'
134 # 'Show download URLs of files you have sent</a>.'
138 '<a href="/fup?akey=$akey&command=RENOTIFY">'
139 'Resend notification e-mails for files you have sent</a>.'
145 '<a href="/fup?akey=$akey&command=LIST&to=*">'
146 'Forward a copy of a file</a> you already have uploaded to another recipient.'
148 '<a href="/rup?akey=$akey">'
149 'Redirect files</a> you have uploaded to a wrong or misspelled recipient.'
154 '<a href="/fup?akey=$akey&command=RENOTIFY">'
155 'Resend notification e-mails for files you have sent</a>.'
160 ' Create a subuser who can send you files. Enter his e-mail address:<br>'
161 ' <input type="text" name="subuser" size="60">'
162 ' <input type="checkbox" name="otuser" value="once">for only one upload<br>'
166 ' <input type="submit" value="create subuser">'
170 ' Comment to send with information e-mail:<br>'
171 ' <input type="text" name="comment" size="80"><br>'
172 ' <input type="submit" value="create subuser and send e-mail">'
177 ' <a href="/fuc?akey=$akey">Manage your subusers and groups</a>'
179 ' <a href="/fuc?ab=load&akey=$akey">Edit your address book</a>'
183 ' <a href="/fuc?disclaimer=CHANGE&akey=$akey">'
184 ' Change the disclaimer</a> to be sent with notification e-mail.'
189 ' <a href="/fuc?encryption=CHANGE&akey=$akey">'
190 ' (De)activate e-mail encryption</a>.'
191 )) if -s "$ENV{HOME}/.gnupg/pubring.gpg";
192 if ((readlink "$user/\@NOTIFICATION"||'') =~ /short/i) {
195 ' Get <a href="/fuc?notification=detailed&akey=$akey">detailed</a> notification e-mails (current setting: <em>brief</em>).'
200 ' Get <a href="/fuc?notification=short&akey=$akey">brief</a> notification e-mails (current setting: <em>detailed</em>).'
203 if ((readlink "$user/\@REMINDER"||'') =~ /no/i) {
206 ' Get <a href="/fuc?reminder=yes&akey=$akey">reminder</a> notification e-mails (current setting: <em>no reminders</em>).'
211 ' Get <a href="/fuc?reminder=no&akey=$akey">no reminder</a> notification e-mails (current setting: <em>send reminders</em>).'
214 if (-e "$user/\@MIME") {
217 ' <a href="/fuc?mime=no&akey=$akey">Save</a> files after download (current setting: <em>display</em>).'
222 ' <a href="/fuc?mime=yes&akey=$akey">Display</a> files when downloading with web browser (current setting: <em>save</em>).'
227 ' <a href="/fup?akey=$akey">Back to fup (upload page)</a>'
231 print "</body></html>\n";
235 my $login = -x "$FEXHOME/login" ? 'login' : 'fup';
237 "HTTP/1.1 302 Found",
238 "Location: $ENV{PROTO}://$ENV{HTTP_HOST}/$login",