3 # FEX CGI for (user) operation control
5 # Author: Ulli Horlacher <framstag@rus.uni-stuttgart.de>
8 BEGIN { ($ENV{PERLINIT}||'') =~ /(.+)/s and eval $1 }
11 use Digest::MD5 qw(md5_hex);
14 ($FEXLIB) = $ENV{FEXLIB} =~ /(.+)/;
15 die "$0: no $FEXLIB\n" unless -d $FEXLIB;
17 our ($FEXHOME,$mdomain,$nomail,$faillog);
20 # load common code, local config : $HOME/lib/fex.ph
21 require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n";
23 my $error = 'F*EX operation control ERROR';
25 chdir $spooldir or die "$spooldir - $!\n";
27 $akeydir = "$spooldir/.akeys";
30 # look for CGI parameters
33 foreach my $v (keys %PARAM) {
35 # debuglog("Param: $v=\"$vv\"");
36 if ($v =~ /^akey$/i and $vv =~ /^(\w+)$/) {
38 } elsif ($v =~ /^(from|user)$/i) {
39 $user = normalize_email($vv);
40 $user .= '@'.$mdomain if $mdomain and $user !~ /@/;
41 } elsif ($v =~ /^id$/i) {
42 $id = checkchars($vv);
46 if ($akey and not $user and not $id) {
47 if (open $akey,'<',"$akeydir/$akey/@" and $id = getline($akey)) {
49 $user = readlink "$akeydir/$akey"
50 or http_die("internal server error: no $akey symlink");
52 $user = untaint($user);
53 if ($akey ne md5_hex("$user:$id")) {
59 $head = "$ENV{SERVER_NAME} F*EX operation control";
61 # display HTML form and request user data
64 unless (open $idf,'<',"$user/@") {
65 faillog("user $from, id $id");
66 html_error($error,"wrong user or auth-ID");
69 if (-e "$user/\@CAPTIVE") { html_error($error,"captive user") }
74 $akey = untaint(md5_hex("$user:$id"));
75 unlink "$akeydir/$akey";
76 symlink "../$user","$akeydir/$akey";
79 faillog("user $from, id $id");
80 html_error($error,"wrong user or auth-ID");
82 unlink $faillog if $faillog;
83 http_header("200 OK");
84 print html_header($head);
85 # authorized login URL
86 my $url = "$ENV{PROTO}://$ENV{HTTP_HOST}/fup/".b64("from=$user&id=$id");
88 '<h2>for user <a href="$url">$user</a></h2>'
91 ($quota,$du) = check_sender_quota($user);
94 <tr title="You as the sender have a server disk quota of $quota MB and currently using $du MB">
95 <td>sender quota (used):<td align=\"right\">$quota ($du) MB
99 ($quota,$du) = check_recipient_quota($user);
102 <tr title="You as the recipient have a server disk quota of $quota MB and currently using $du MB">
103 <td>recipient quota (used):<td align=\"right\">$quota ($du) MB
110 '<a href="/fup?akey=$akey&command=LISTRECEIVED">'
111 'Retrieve a list of all your received files</a> in F*EX spool.'
115 '<form action="/fuc?akey=$akey"'
117 ' accept-charset="UTF-8"'
118 ' enctype="multipart/form-data">'
119 ' <input type="hidden" name="user" value="$user">'
120 ' <input type="hidden" name="id" value="$id">'
121 ' <script>function show_id() {return(alert("auth-ID: $id"));}</script>'
122 ' Change your <a href="" onclick="show_id();" title="$id">auth-ID</a> to'
123 ' <input type="text" name="nid" size="16">'
124 ' <input type="submit" value="remember it!">'
126 if (-s "$user/\@ALLOWED_RECIPIENTS") {
128 # ' (You are a restricted user)';
132 # '<a href="/fup?akey=$akey&command=LISTSENT">'
133 # 'Show download URLs of files you have sent</a>.'
137 '<a href="/fup?akey=$akey&command=RENOTIFY">'
138 'Resend notification e-mails for files you have sent</a>.'
144 '<a href="/fup?akey=$akey&command=LIST&to=*">'
145 'Forward a copy of a file</a> you already have uploaded to another recipient.'
147 '<a href="/rup?akey=$akey">'
148 'Redirect files</a> you have uploaded to a wrong or misspelled recipient.'
153 '<a href="/fup?akey=$akey&command=RENOTIFY">'
154 'Resend notification e-mails for files you have sent</a>.'
159 ' Create a subuser who can send you files. Enter his e-mail address:<br>'
160 ' <input type="text" name="subuser" size="60">'
161 ' <input type="checkbox" name="otuser" value="once">for only one upload<br>'
165 ' <input type="submit" value="create subuser">'
169 ' Comment to send with information e-mail:<br>'
170 ' <input type="text" name="comment" size="80"><br>'
171 ' <input type="submit" value="create subuser and send e-mail">'
176 ' <a href="/fuc?akey=$akey">Manage your subusers and groups</a>'
178 ' <a href="/fuc?ab=load&akey=$akey">Edit your address book</a>'
182 ' <a href="/fuc?disclaimer=CHANGE&akey=$akey">'
183 ' Change the disclaimer</a> to be sent with notification e-mail.'
188 ' <a href="/fuc?encryption=CHANGE&akey=$akey">'
189 ' (De)activate e-mail encryption</a>.'
190 )) if -s "$ENV{HOME}/.gnupg/pubring.gpg";
191 if ((readlink "$user/\@NOTIFICATION"||'') =~ /short/i) {
194 ' Get <a href="/fuc?notification=detailed&akey=$akey">detailed</a> notification e-mails (current setting: <em>brief</em>).'
199 ' Get <a href="/fuc?notification=short&akey=$akey">brief</a> notification e-mails (current setting: <em>detailed</em>).'
202 if ((readlink "$user/\@REMINDER"||'') =~ /no/i) {
205 ' Get <a href="/fuc?reminder=yes&akey=$akey">reminder</a> notification e-mails (current setting: <em>no reminders</em>).'
210 ' Get <a href="/fuc?reminder=no&akey=$akey">no reminder</a> notification e-mails (current setting: <em>send reminders</em>).'
213 if (-e "$user/\@MIME") {
216 ' <a href="/fuc?mime=no&akey=$akey">Save</a> files after download (current setting: <em>display</em>).'
221 ' <a href="/fuc?mime=yes&akey=$akey">Display</a> files when downloading with web browser (current setting: <em>save</em>).'
226 ' <a href="/fup?akey=$akey">Back to fup (upload page)</a>'
230 print "</body></html>\n";
234 my $login = -x "$FEXHOME/login" ? 'login' : 'fup';
236 "HTTP/1.1 302 Found",
237 "Location: $ENV{PROTO}://$ENV{HTTP_HOST}/$login",