Debian Codegraph @

cgi-bin/foc

raw
1 #!/usr/bin/perl -wT
2
3 # FEX CGI for (user) operation control
4 #
5 # Author: Ulli Horlacher <[email protected]>
6 #
7
8 BEGIN { ($ENV{PERLINIT}||'') =~ /(.+)/s and eval $1 }
9
10 # use utf8;
11 use Fcntl qw(:flock);
12 use Digest::MD5 qw(md5_hex);
13
14 # add fex lib
15 ($FEXLIB) = $ENV{FEXLIB} =~ /(.+)/;
16 die "$0: no $FEXLIB\n" unless -d $FEXLIB;
17
18 our ($FEXHOME,$mdomain,$nomail,$faillog,$skeydir,$akeydir);
19 our ($archive_sharing,$document_exchange);
20 our $akey = '';
21
22 # load common code, local config : $HOME/lib/fex.ph
23 require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n";
24
25 my $error = 'F*EX operation control ERROR';
26
27 chdir $spooldir or die "$spooldir - $!\n";
28
29 $user = $id = '';
30
31 # look for CGI parameters
32 our %PARAM;
33 &parse_parameters;
34 foreach my $v (keys %PARAM) {
35 my $vv = $PARAM{$v};
36 # debuglog("Param: $v=\"$vv\"");
37 if ($v =~ /^akey$/i and $vv =~ /^(\w+)$/) {
38 $akey = $1;
39 } elsif ($v =~ /^(from|user)$/i) {
40 $user = normalize_email($vv);
41 $user .= '@'.$mdomain if $mdomain and $user !~ /@/;
42 } elsif ($v eq 'show') {
43 $show = normalize_email($vv);
44 } elsif ($v =~ /^id$/i) {
45 $id = checkchars($vv);
46 }
47 }
48
49 if ($akey and not $user and not $id) {
50 if ($id = readline1("$akeydir/$akey/@")) {
51 $user = readlink "$akeydir/$akey"
52 or http_die("internal server error: no $akey symlink");
53 $user =~ s:.*/::;
54 $user = untaint($user);
55 }
56 }
57
58 $head = "$ENV{SERVER_NAME} F*EX operation control";
59
60 # display HTML form and request user data
61 if ($user and $id) {
62 my $idf;
63 unless (open $idf,'<',"$user/@") {
64 faillog("user $user, id $id");
65 html_error($error,"wrong user or auth-ID");
66 }
67 &check_status($user);
68 if (-e "$user/\@CAPTIVE") { html_error($error,"captive user") }
69 $rid = getline($idf);
70 close $idf;
71 if ($id eq $rid) {
72 unless ($akey) {
73 $akey = genakey($user);
74 }
75 } else {
76 faillog("user $user, id $id");
77 html_error($error,"wrong user or auth-ID");
78 }
79 unlink $faillog if $faillog;
80 http_header("200 OK");
81 print html_header($head);
82 # authorized login URL
83 my $url = "$ENV{PROTO}://$ENV{HTTP_HOST}/fup/".b64("from=$user&id=$id");
84 # own subuser URL
85 my $skey = untaint(md5_hex($id));
86 mksymlink("$skeydir/$skey",$user);
87 my $surl = "$ENV{PROTO}://$ENV{HTTP_HOST}/fup?skey=$skey";
88 if ($show) {
89 pq(qq(
90 '<table>'
91 # '<tr><td>server: <td>$ENV{HTTP_HOST}</tr>'
92 '<tr><td>user: <td>$user</tr>'
93 '<tr><td>auth-ID: <td>$id</tr>'
94 '<tr><td>login URL:<td>$url</tr>'
95 '<tr><td>self URL: <td>$surl</tr>'
96 '</table>'
97 '<p>'
98 '<a href="#" onclick="window.close()">close</a>'
99 '</body></html>'
100 ));
101 exit;
102 }
103 pq(qq(
104 '<script>'
105 'function show_user() {'
106 ' window.open("/foc?show=$user","show user","width=1024,height=300");'
107 '}'
108 '</script>'
109 '<h2>for user <a href="#" onclick="show_user()" title="click to see account data"> $user</a></h2>'
110 '<table>'
111 ));
112 ($quota,$du) = check_sender_quota($user);
113 if ($quota) {
114 pq(qq(
115 '<tr title="You as the sender have a server disk quota of $quota MB and currently using $du MB">'
116 '<td>sender quota (used):<td align="right">$quota<td>($du) MB'
117 '</tr>'
118 ));
119 }
120 ($quota,$du) = check_recipient_quota($user);
121 if ($quota) {
122 pq(qq(
123 '<tr title="You as the recipient have a server disk quota of $quota MB and currently using $du MB">'
124 '<td>recipient quota (used):<td align="right">$quota<td>($du) MB'
125 '</tr>'
126 ));
127 }
128 pq(qq(
129 '</table>'
130 '<p><hr><p>'
131 '<ul>'
132 '<p><li>'
133 '<a href="/fup?command=LISTRECEIVED">'
134 'Retrieve a list of all your received files</a> in F*EX spool.'
135 '<p><li>'
136 '<form action="/fuc"'
137 ' method="post"'
138 ' accept-charset="UTF-8"'
139 ' enctype="multipart/form-data">'
140 ' <input type="hidden" name="user" value="$user">'
141 ' <input type="hidden" name="id" value="$id">'
142 ' <script>function show_id() {return(alert("auth-ID: $id"));}</script>'
143 ' Change your <a href="#" onclick="show_id();" title="$id">auth-ID</a> to'
144 ' <input type="text" name="nid" size="16">'
145 ' <input type="submit" value="remember it!">'
146 ));
147 if (-s "$user/\@ALLOWED_RECIPIENTS") {
148 # pq(qq(
149 # ' (You are a restricted user)';
150 # ' <p>'
151 # ));
152 # '<p><li>'
153 # '<a href="/fup?akey=$akey&command=LISTSENT">'
154 # 'Show download URLs of files you have sent</a>.'
155 unless ($nomail) {
156 pq(qq(
157 '<p><li>'
158 '<a href="/fup?command=RENOTIFY">'
159 'Resend notification emails for files you have sent</a>.'
160 ));
161 }
162 } else {
163 pq(qq(
164 '<p><li>'
165 '<a href="/fup?command=LIST&to=*">'
166 'Forward a copy of a file</a> you already have uploaded to another recipient.'
167 '<p><li>'
168 '<a href="/rup">'
169 'Redirect files</a> you have uploaded to a wrong or misspelled recipient.'
170 ));
171 unless ($nomail) {
172 pq(qq(
173 '<p><li>'
174 '<a href="/fup?command=RENOTIFY">'
175 'Resend notification emails for files you have sent</a>.'
176 ));
177 }
178 pq(qq(
179 '<p><li>'
180 ' <a href="/fup?from=$user&id=$id&COMMAND=GENUKEY">'
181 ' Create one day valid upload key and URL</a> (to give away)'
182 '<p><li>'
183 ' Create a subuser who can send you files. Enter his email address:<br>'
184 ' <input type="text" name="subuser" size="60">'
185 ' <input type="checkbox" name="otuser" value="once">for only one upload<br>'
186 ));
187 if ($nomail) {
188 pq(qq(
189 ' <input type="submit" value="create subuser">'
190 ));
191 } else {
192 pq(qq(
193 ' Comment to send with information email:<br>'
194 ' <input type="text" name="comment" size="80"><br>'
195 ' <input type="submit" value="create subuser and send email">'
196 ));
197 }
198 pq(qq(
199 '<p><li>'
200 ' <a href="/fuc">Manage your subusers and groups</a>'
201 ));
202 my $sharing = readlink_("$user/\@ARCHIVE_SHARING");
203 if ($sharing =~ /yes/i or $archive_sharing and $sharing !~ /no/i) {
204 pq(qq(
205 '<p><li>'
206 ' <a href="/fas">Manage your share archives and users</a>'
207 ));
208 }
209 my $doxua = readlink_("$user/\@DOCUMENT_EXCHANGE");
210 if ($doxua eq 'yes' or not $doxua and $document_exchange) {
211 pq(qq(
212 '<p><li>'
213 ' <a href="/dox">Manage your document exchange</a>'
214 ));
215 }
216 pq(qq(
217 '<p><li>'
218 ' <a href="/fuc?ab=load">Edit your address book</a>'
219 '<p><li>'
220 ' <a href="/fuc?disclaimer=CHANGE">'
221 ' Change the disclaimer</a> to be sent with notification email.'
222 ));
223 }
224 pq(qq(
225 '<p><li>'
226 ' <a href="/fuc?gpg=CHANGE">'
227 ' (De)activate email encryption</a>.'
228 )) if -s "$ENV{HOME}/.gnupg/pubring.gpg";
229 if ((readlink "$user/\@NOTIFICATION"||'') =~ /short/i) {
230 pq(qq(
231 '<p><li>'
232 ' Get <a href="/fuc?notification=detailed">detailed</a> notification emails (current setting: <em>brief</em>).'
233 ));
234 } else {
235 pq(qq(
236 '<p><li>'
237 ' Get <a href="/fuc?notification=short">brief</a> notification emails (current setting: <em>detailed</em>).'
238 ));
239 }
240 if ((readlink "$user/\@REMINDER"||'') =~ /no/i) {
241 pq(qq(
242 '<p><li>'
243 ' Get <a href="/fuc?reminder=yes">reminder</a> notification emails (current setting: <em>no reminders</em>).'
244 ));
245 } else {
246 pq(qq(
247 '<p><li>'
248 ' Get <a href="/fuc?reminder=no">no reminder</a> notification emails (current setting: <em>send reminders</em>).'
249 ));
250 }
251 if (-e "$user/\@MIME") {
252 pq(qq(
253 '<p><li>'
254 ' <a href="/fuc?mime=no">Save</a> files after download (current setting: <em>display</em>).'
255 ));
256 } else {
257 pq(qq(
258 '<p><li>'
259 ' <a href="/fuc?mime=yes">Display</a> files when downloading with web browser (current setting: <em>save</em>).'
260 ));
261 }
262 my $fidb64=b64("$ENV{PROTO}://$ENV{HTTP_HOST} $user $id");
263 pq(qq(
264 '</form>'
265 '</ul>'
266 '<p>'
267 'Hint: to create a local FEXID file for <a href="/tools.html">fexsend</a>, use:<br>'
268 '<b><code>fexsend -I FEXID=$fidb64</code></b>'
269 '<p><hr><p>'
270 '<a href="/fup">back to fup (upload page)</a>'
271 ));
272 print &logout;
273 print "</body></html>\n";
274 exit;
275 }
276
277 my $login = -x "$FEXHOME/login" ? 'login' : 'fup';
278 nvt_print(
279 "HTTP/1.1 302 Found",
280 "Location: $ENV{PROTO}://$ENV{HTTP_HOST}/$login",
281 'Expires: 0',
282 'Content-Length: 0',
283 ''
284 );
285 &reexec;