| 1 |
#!/usr/bin/perl -wT |
| 2 |
|
| 3 |
# FEX CGI for user control |
| 4 |
# (subuser, groups, address book, one time upload key, auth-ID, etc) |
| 5 |
# |
| 6 |
# Author: Ulli Horlacher <[email protected]> |
| 7 |
# |
| 8 |
|
| 9 |
BEGIN { ($ENV{PERLINIT}||'') =~ /(.+)/s and eval $1 } |
| 10 |
|
| 11 |
# use utf8; |
| 12 |
use Fcntl qw(:flock); |
| 13 |
use Digest::MD5 qw(md5_hex); |
| 14 |
|
| 15 |
# add fex lib |
| 16 |
($FEXLIB) = $ENV{FEXLIB} =~ /(.+)/; |
| 17 |
die "$0: no $FEXLIB\n" unless -d $FEXLIB; |
| 18 |
|
| 19 |
# import from fex.pp |
| 20 |
our ($FEXHOME); |
| 21 |
our ($mdomain,$admin,$hostname,$sendmail,$akeydir,$skeydir,$docdir,$durl,$bcc); |
| 22 |
our ($nomail,$faillog); |
| 23 |
our $akey = ''; |
| 24 |
|
| 25 |
# load common code, local config : $HOME/lib/fex.ph |
| 26 |
require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n"; |
| 27 |
|
| 28 |
my ($CASE,$ESAC); |
| 29 |
|
| 30 |
my $error = 'F*EX user config ERROR'; |
| 31 |
my $head = "$ENV{SERVER_NAME} F*EX user config"; |
| 32 |
|
| 33 |
my $fup = $durl; |
| 34 |
$fup =~ s:/fop:/fup:; |
| 35 |
|
| 36 |
chdir $spooldir or die "$spooldir - $!\n"; |
| 37 |
|
| 38 |
my $user = my $id = my $nid = my $ssid = my $comment = ''; |
| 39 |
my $notification = my $reminder = my $disclaimer = ''; |
| 40 |
my $gpg = my $pubkey = my $mime = ''; |
| 41 |
|
| 42 |
my $qs = $ENV{QUERY_STRING}; |
| 43 |
if ($qs) { |
| 44 |
if ($qs =~ /akey=(\w+)/i) { $akey = $1 } |
| 45 |
if ($qs =~ /ab=load/) { $ab = 'load' } |
| 46 |
} |
| 47 |
|
| 48 |
# look for CGI parameters |
| 49 |
our %PARAM; |
| 50 |
&parse_parameters; |
| 51 |
foreach my $v (keys %PARAM) { |
| 52 |
my $vv = $PARAM{$v}; |
| 53 |
# debuglog("Param: $v=\"$vv\""); |
| 54 |
if ($v =~ /^akey$/i) { |
| 55 |
$akey = $1 if $vv =~ /^(\w+)$/; |
| 56 |
next; |
| 57 |
} |
| 58 |
$CASE = |
| 59 |
$v =~ /^user$/i ? $user = normalize_email($vv): |
| 60 |
$v =~ /^subuser$/i ? $subuser = normalize_email($vv): |
| 61 |
$v =~ /^otuser$/i ? $otuser = normalize_email($vv): |
| 62 |
$v =~ /^notify$/i ? $notify = normalize_email($vv): |
| 63 |
$v =~ /^notification$/i ? $notification = checkchars('parameter',$vv): |
| 64 |
$v =~ /^disclaimer$/i ? $disclaimer = $vv: |
| 65 |
$v =~ /^gpg$/i ? $gpg = checkchars('parameter',$vv): |
| 66 |
$v =~ /^pubkey$/i ? $pubkey = $PARAM{$v}{data}: |
| 67 |
$v =~ /^reminder$/i ? $reminder = checkchars('parameter',$vv): |
| 68 |
$v =~ /^mime$/i ? $mime = checkchars('parameter',$vv): |
| 69 |
$v =~ /^comment$/i ? $comment = decode_utf8(normalize($vv)): |
| 70 |
$v =~ /^id$/i ? $id = checkchars('auth-ID',$vv): |
| 71 |
$v =~ /^nid$/i ? $nid = checkchars('auth-ID',$vv): |
| 72 |
$v =~ /^ssid$/i ? $ssid = $vv||' ': |
| 73 |
$v =~ /^group$/i ? $group = checkchars('group',$vv): |
| 74 |
$v =~ /^ab$/i ? $ab = $vv: |
| 75 |
$v =~ /^gm$/i ? $gm = $vv: |
| 76 |
$v =~ /^show$/i ? $show = checkchars('parameter',$vv): |
| 77 |
$ESAC; |
| 78 |
} |
| 79 |
|
| 80 |
if ($group and $group ne 'NEW') { |
| 81 |
$group = lc $group; |
| 82 |
$group =~ s/[^\w\*%^+=:,.!-]/_/g; |
| 83 |
} |
| 84 |
$group = '' if $nomail; |
| 85 |
$user .= '@'.$mdomain if $mdomain and $user !~ /@/; |
| 86 |
|
| 87 |
$nomail = $comment if $comment =~ /NOMAIL|!#!/; |
| 88 |
|
| 89 |
if ($show and $show eq 'tools') { |
| 90 |
nvt_print( |
| 91 |
"HTTP/1.1 302 Found", |
| 92 |
"Location: /tools.html", |
| 93 |
'Expires: 0', |
| 94 |
'Content-Length: 0', |
| 95 |
'' |
| 96 |
); |
| 97 |
&reexec; |
| 98 |
|
| 99 |
if (open $tools,"$docdir/tools.html") { |
| 100 |
while (<$tools>) { |
| 101 |
while (/\$([\w_]+)\$/) { |
| 102 |
my $var = $1; |
| 103 |
my $env = $ENV{$var} || ''; |
| 104 |
s/\$$var\$/$env/g; |
| 105 |
}; |
| 106 |
print; |
| 107 |
} |
| 108 |
} |
| 109 |
exit; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
if ($akey) { |
| 114 |
if ($id = readline1("$akeydir/$akey/@")) { |
| 115 |
if (readlink_("$akeydir/$akey") =~ m:.*/(.+):) { |
| 116 |
$user = $1; |
| 117 |
} else { |
| 118 |
http_die("internal server error: unknown akey $akey"); |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
&check_status($user) if $user; |
| 124 |
|
| 125 |
if ($user and $akey and $qs and $qs =~ /info=(.+?)&skey=(\w+)/) { |
| 126 |
$subuser = $1; |
| 127 |
$skey = $2; |
| 128 |
notify_subuser($user,$subuser,"$fup?skey=$skey?$user",$comment); |
| 129 |
http_header("200 OK"); |
| 130 |
print html_header($head); |
| 131 |
pq(qq( |
| 132 |
'An information email has been sent to your subuser $subuser' |
| 133 |
'<p><a href="javascript:history.back()">Go back</a>' |
| 134 |
'</body></html>' |
| 135 |
)); |
| 136 |
exit; |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
if ($user and $id) { |
| 141 |
if (-e "$user/\@CAPTIVE") { html_error($error,"captive user") } |
| 142 |
unless (open $idf,'<',"$user/@") { |
| 143 |
faillog("user $from, id $id"); |
| 144 |
html_error($error,"wrong user or auth-ID"); |
| 145 |
} |
| 146 |
$rid = getline($idf); |
| 147 |
close $idf; |
| 148 |
if ($id eq $rid) { |
| 149 |
$akey ||= genakey($from); |
| 150 |
} else { |
| 151 |
faillog("user $from, id $id"); |
| 152 |
html_error($error,"wrong user or auth-ID"); |
| 153 |
} |
| 154 |
} else { |
| 155 |
my $login = -x "$FEXHOME/login" ? 'login' : 'fup'; |
| 156 |
nvt_print( |
| 157 |
"HTTP/1.1 302 Found", |
| 158 |
"Location: $ENV{PROTO}://$ENV{HTTP_HOST}/$login", |
| 159 |
'Expires: 0', |
| 160 |
'Content-Length: 0', |
| 161 |
'' |
| 162 |
); |
| 163 |
&reexec; |
| 164 |
} |
| 165 |
|
| 166 |
# empty POST? ==> back to foc |
| 167 |
if ($ENV{REQUEST_METHOD} eq 'POST' and not |
| 168 |
($subuser or $notify or $nid or $ssid or $group or $ab or $gm |
| 169 |
or $disclaimer or $gpg or $pubkey)) |
| 170 |
{ |
| 171 |
nvt_print( |
| 172 |
"HTTP/1.1 302 Found", |
| 173 |
"Location: $ENV{PROTO}://$ENV{HTTP_HOST}/foc", |
| 174 |
'Expires: 0', |
| 175 |
'Content-Length: 0', |
| 176 |
'' |
| 177 |
); |
| 178 |
&reexec; |
| 179 |
} |
| 180 |
|
| 181 |
unlink $faillog if $faillog; |
| 182 |
|
| 183 |
http_header("200 OK"); |
| 184 |
print html_header($head); |
| 185 |
# foreach $v (keys %ENV) { print $v,' = "',$ENV{$v},"\"<br>\n" }; |
| 186 |
|
| 187 |
if ($gm and not $group) { |
| 188 |
pq(qq( |
| 189 |
'<h2>ERROR: no group name specified</h2>' |
| 190 |
'</body></html>' |
| 191 |
)); |
| 192 |
exit; |
| 193 |
} |
| 194 |
|
| 195 |
if ($group) { |
| 196 |
&handle_group; |
| 197 |
} |
| 198 |
|
| 199 |
# create one time upload key |
| 200 |
if ($subuser and $otuser) { |
| 201 |
$otuser = $subuser; |
| 202 |
if ($otuser !~ /^[^@]+@[\w.-]+[a-z]$/) { |
| 203 |
pq(qq( |
| 204 |
'$otuser is not a valid email address' |
| 205 |
'<p><a href="javascript:history.back()">Go back</a>' |
| 206 |
'</body></html>' |
| 207 |
)); |
| 208 |
exit; |
| 209 |
} |
| 210 |
my $okey = randstring(8); |
| 211 |
my $okeyd = "$user/\@OKEY"; |
| 212 |
mkdir $okeyd; |
| 213 |
symlink $otuser,"$okeyd/$okey" |
| 214 |
or http_die("cannot create OKEY $okeyd/$okey : $!\n"); |
| 215 |
my $url = "$fup?to=$user?okey=$okey"; |
| 216 |
pq(qq( |
| 217 |
'A one time upload URL for $otuser has been created:' |
| 218 |
'<p>' |
| 219 |
'<code>$url</code>' |
| 220 |
)); |
| 221 |
unless ($nomail) { |
| 222 |
¬ify_otuser($user,$otuser,$url,$comment); |
| 223 |
pq(qq( |
| 224 |
'<p>' |
| 225 |
'and an information email has been sent to this address.' |
| 226 |
'<p>' |
| 227 |
)); |
| 228 |
} |
| 229 |
pq(qq( |
| 230 |
'<a href="/foc">back to F*EX operation control</a>' |
| 231 |
'</body></html>' |
| 232 |
)); |
| 233 |
exit; |
| 234 |
} |
| 235 |
|
| 236 |
# direct single subuser entry |
| 237 |
if ($subuser and not $otuser) { |
| 238 |
if (-f "$subuser/@") { |
| 239 |
pq(qq( |
| 240 |
'$subuser is already a registered F*EX full user' |
| 241 |
'<p><a href="javascript:history.back()">Go back</a>' |
| 242 |
'</body></html>' |
| 243 |
)); |
| 244 |
exit; |
| 245 |
} |
| 246 |
if ($subuser !~ /^[^@]+@[\w.-]+[a-z]$/) { |
| 247 |
pq(qq( |
| 248 |
'$subuser is not a valid email address' |
| 249 |
'<p><a href="javascript:history.back()">Go back</a>' |
| 250 |
'</body></html>' |
| 251 |
)); |
| 252 |
exit; |
| 253 |
} |
| 254 |
$skey = ''; |
| 255 |
if (open $idf,'<',"$user/\@SUBUSER") { |
| 256 |
while (<$idf>) { |
| 257 |
chomp; |
| 258 |
if (/^\Q$subuser:/) { |
| 259 |
$skey = md5_hex("$user:$_"); |
| 260 |
last; |
| 261 |
} |
| 262 |
} |
| 263 |
close $idf; |
| 264 |
} |
| 265 |
if ($skey) { |
| 266 |
my $url = "$fup?skey=$skey"; |
| 267 |
if ($nomail) { |
| 268 |
pq(qq( |
| 269 |
'$subuser is already your subuser and has access URL:' |
| 270 |
'<p>' |
| 271 |
'<code>$url</code>' |
| 272 |
)); |
| 273 |
} else { |
| 274 |
pq(qq( |
| 275 |
'<a href=\"/fuc?info=$subuser&skey=$skey\">$subuser</a>' |
| 276 |
'is already your subuser and has access URL:' |
| 277 |
'<p>' |
| 278 |
'<code>$url</code>' |
| 279 |
'<p>' |
| 280 |
"Click on the subuser's email address link to send him an" |
| 281 |
"information email by the F*EX server.<p>" |
| 282 |
)); |
| 283 |
} |
| 284 |
} else { |
| 285 |
my $sid = randstring(8); |
| 286 |
my $skey = mkskey($user,$subuser,$sid); |
| 287 |
$url = "$fup?skey=$skey?$user"; |
| 288 |
open $idf,'>>',"$user/\@SUBUSER" or die "$user/\@SUBUSER - $!\n"; |
| 289 |
print {$idf} "$subuser:$sid\n"; |
| 290 |
close $idf; |
| 291 |
pq(qq( |
| 292 |
'Your subuser upload URL is:' |
| 293 |
'<p>' |
| 294 |
'<code>$url</code>' |
| 295 |
)); |
| 296 |
unless ($nomail) { |
| 297 |
¬ify_subuser($user,$subuser,$url,$comment); |
| 298 |
pq(qq( |
| 299 |
'<p>' |
| 300 |
'An information email has been sent to $subuser' |
| 301 |
)); |
| 302 |
} |
| 303 |
} |
| 304 |
pq(qq( |
| 305 |
'<p><a href="javascript:history.back()">back</a>' |
| 306 |
'</body></html>' |
| 307 |
)); |
| 308 |
exit; |
| 309 |
} |
| 310 |
|
| 311 |
# modify addressbook |
| 312 |
if ($user and $akey and defined $ab) { |
| 313 |
if ($ab eq 'load') { |
| 314 |
$ab = ''; |
| 315 |
if (open $ab,'<',"$user/\@ADDRESS_BOOK") { |
| 316 |
undef $/; |
| 317 |
$_ = <$ab>; |
| 318 |
s/\s*$/\n/; |
| 319 |
close $ab; |
| 320 |
$ab = htmlquote($_); |
| 321 |
} |
| 322 |
my $rows = ($ab =~ tr/\n//) + 5; |
| 323 |
pq(qq( |
| 324 |
'<h2>Edit address book</h2>' |
| 325 |
'<table border=0>' |
| 326 |
' <tr align="left"><th>Entry:<th>alias<th>email address<th># optional comment</tr>' |
| 327 |
' <tr align="left"><td>Example:<td>Framstag<td>framstag\@rus.uni-stuttgart.de<td># Ulli Horlacher</tr>' |
| 328 |
'</table>' |
| 329 |
'<form action="$ENV{SCRIPT_NAME}"' |
| 330 |
' method="post"' |
| 331 |
' accept-charset="UTF-8"' |
| 332 |
' enctype="multipart/form-data">' |
| 333 |
' <textarea name="ab" cols="160" rows="$rows">$ab</textarea><br>' |
| 334 |
' <input type="submit" value="submit">' |
| 335 |
'</form>' |
| 336 |
'<p>' |
| 337 |
'You may use these alias names as F*EX recipient addresses on ' |
| 338 |
'<a href="/fup">fup</a>' |
| 339 |
'<p>' |
| 340 |
'Alternatively you can fex a file ADDRESS_BOOK to yourself ' |
| 341 |
'($user) containing your alias definitions.' |
| 342 |
'<p>' |
| 343 |
'<a href="/foc">back to F*EX operation control</a>' |
| 344 |
'</body></html>' |
| 345 |
)); |
| 346 |
exit; |
| 347 |
} else { |
| 348 |
|
| 349 |
# save addressbook |
| 350 |
$ab =~ s/[\r<>]//g; |
| 351 |
$ab =~ s/\s*$/\n/; |
| 352 |
|
| 353 |
foreach (split(/\n/,$ab)) { |
| 354 |
s/^\s+//; |
| 355 |
s/\s+$//; |
| 356 |
if (s/\s*(#.*)//) { $comment = $1 } |
| 357 |
else { $comment = '' } |
| 358 |
next if /^\s*$/; |
| 359 |
@options = (); |
| 360 |
push @options,$1 if s/[\s,](autodelete=\w+)/ /i; |
| 361 |
push @options,$1 if s/[\s,](keep=\d+)/ /i; |
| 362 |
s/[,\s]+$//; |
| 363 |
if (s/([\S]+)\s+(\S+)//) { |
| 364 |
$alias = $1; |
| 365 |
$address = $2; |
| 366 |
$options = join(',',@options); |
| 367 |
push @abt,"<tr><td>$alias<td>$address<td>$options<td>$comment</tr>\n"; |
| 368 |
} else { |
| 369 |
push @badalias,$_; |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
if (@badalias) { |
| 374 |
print "<h2>ERROR: bad aliases:</h2>\n<ul>"; |
| 375 |
foreach my $ba (@badalias) { print "<li>$ba" } |
| 376 |
pq(qq( |
| 377 |
'</ul>' |
| 378 |
'<p>' |
| 379 |
'Not in format: <code>alias email-address</code>' |
| 380 |
'<p>' |
| 381 |
'<a href="javascript:history.back()">Go back</a>' |
| 382 |
'</body></html>' |
| 383 |
)); |
| 384 |
exit; |
| 385 |
} |
| 386 |
|
| 387 |
open my $AB,'>',"$user/\@ADDRESS_BOOK" |
| 388 |
or http_die("cannot open $user/\@ADDRESS_BOOK - $!\n"); |
| 389 |
print {$AB} $ab; |
| 390 |
close $AB; |
| 391 |
pq(qq( |
| 392 |
'<h2><a href ="/fuc?AB=load">address book</a></h2>' |
| 393 |
'<table border=1>' |
| 394 |
'<tr><th>alias<th>email address<th>options<th>comment</tr>' |
| 395 |
'@abt' |
| 396 |
'</table>' |
| 397 |
'<p>' |
| 398 |
'<a href="/foc">back to F*EX operation control</a>' |
| 399 |
'<p>' |
| 400 |
'<a href="/fup">back to fup (F*EX upload)</a>' |
| 401 |
'</body></html>' |
| 402 |
)); |
| 403 |
} |
| 404 |
exit; |
| 405 |
} |
| 406 |
|
| 407 |
if ($user and $notification eq 'detailed') { |
| 408 |
unlink "$user/\@NOTIFICATION"; |
| 409 |
pq(qq( |
| 410 |
'<h3>Notification emails now come in detailed format.<h3>' |
| 411 |
'<p>' |
| 412 |
'<a href="/foc">back to F*EX operation control</a>' |
| 413 |
'</body></html>' |
| 414 |
)); |
| 415 |
&reexec; |
| 416 |
} |
| 417 |
|
| 418 |
if ($user and $mime eq 'yes') { |
| 419 |
open $mime,'>',"$user/\@MIME" or http_die("cannot write $user/\@MIME - $!\n"); |
| 420 |
close $mime; |
| 421 |
pq(qq( |
| 422 |
'<h3>Downloads will now be displayed (if possible).<h3>' |
| 423 |
'<p>' |
| 424 |
'<a href="/foc">back to F*EX operation control</a>' |
| 425 |
'</body></html>' |
| 426 |
)); |
| 427 |
&reexec; |
| 428 |
} |
| 429 |
|
| 430 |
if ($user and $mime eq 'no') { |
| 431 |
unlink "$user/\@MIME"; |
| 432 |
pq(qq( |
| 433 |
'<h3>Downloads will now be saved.<h3>' |
| 434 |
'<p>' |
| 435 |
'<a href="/foc">back to F*EX operation control</a>' |
| 436 |
'</body></html>' |
| 437 |
)); |
| 438 |
&reexec; |
| 439 |
} |
| 440 |
|
| 441 |
if ($user and $notification eq 'short') { |
| 442 |
unlink "$user/\@NOTIFICATION"; |
| 443 |
symlink "short","$user/\@NOTIFICATION"; |
| 444 |
pq(qq( |
| 445 |
'<h3>Notification emails now come in short format.<h3>' |
| 446 |
'<p>' |
| 447 |
'<a href="/foc">back to F*EX operation control</a>' |
| 448 |
'</body></html>' |
| 449 |
)); |
| 450 |
&reexec; |
| 451 |
} |
| 452 |
|
| 453 |
if ($user and $disclaimer) { |
| 454 |
my $df = "$user/\@DISCLAIMER"; |
| 455 |
if ($disclaimer =~ /^[\s\"]*DEFAULT[\s\"]*$/i) { |
| 456 |
unlink $df; |
| 457 |
pq(qq( |
| 458 |
'<h3>Email disclaimer reset to default.</h3>' |
| 459 |
'<p>' |
| 460 |
'<a href="/foc">back to F*EX operation control</a>' |
| 461 |
'</body></html>' |
| 462 |
)); |
| 463 |
} elsif ($disclaimer eq 'CHANGE') { |
| 464 |
$disclaimer = slurp($df) || ''; |
| 465 |
$disclaimer =~ s/&/&/g; |
| 466 |
$disclaimer =~ s/</</g; |
| 467 |
pq(qq( |
| 468 |
'<form action="$ENV{SCRIPT_NAME}"' |
| 469 |
' method="post"' |
| 470 |
' accept-charset="UTF-8"' |
| 471 |
' enctype="multipart/form-data">' |
| 472 |
' <p><hr><p>' |
| 473 |
' Disclaimer to be sent with download notification email:<br>' |
| 474 |
' <textarea name="disclaimer" cols="80" rows="10">$disclaimer</textarea><br>' |
| 475 |
' <input type="submit" value="save">' |
| 476 |
' or <a href="$ENV{SCRIPT_NAME}?disclaimer=DEFAULT">' |
| 477 |
' reset the disclaimer to default</a>.' |
| 478 |
'</form>' |
| 479 |
'</body></html>' |
| 480 |
)); |
| 481 |
exit; |
| 482 |
} else { |
| 483 |
$disclaimer =~ s/^\s+//; |
| 484 |
$disclaimer =~ s/\s+$/\n/; |
| 485 |
open $df,'>',$df or http_die("cannot write $df - $!\n"); |
| 486 |
print {$df} $disclaimer; |
| 487 |
close $df; |
| 488 |
$disclaimer =~ s/&/&/g; |
| 489 |
$disclaimer =~ s/</</g; |
| 490 |
pq(qq( |
| 491 |
'<h2>Email disclaimer changed to:</h2>' |
| 492 |
'<pre>' |
| 493 |
'$disclaimer' |
| 494 |
'</pre>' |
| 495 |
'<p>' |
| 496 |
'<a href="/foc">back to F*EX operation control</a>' |
| 497 |
'</body></html>' |
| 498 |
)); |
| 499 |
} |
| 500 |
|
| 501 |
&reexec; |
| 502 |
} |
| 503 |
|
| 504 |
if ($user and $pubkey) { |
| 505 |
my $gf = "$user/\@GPG"; |
| 506 |
my $pk; |
| 507 |
local $/; |
| 508 |
local $_; |
| 509 |
|
| 510 |
open $pk,">$gf.pk" or http_die("cannot write $gf.pk - $!\n"); |
| 511 |
print {$pk} $pubkey; |
| 512 |
close $pk; |
| 513 |
unlink $gf; |
| 514 |
system "gpg --batch --no-default-keyring --keyring $gf --import". |
| 515 |
"< $gf.pk >/dev/null 2>&1"; |
| 516 |
if (`gpg --batch <$gf 2>/dev/null` =~ /^pub\s.*<\Q$user\E>/sm) { |
| 517 |
$pk = `gpg --batch <$gf 2>&1`; |
| 518 |
$pk =~ s/&/&/g; |
| 519 |
$pk =~ s/</</g; |
| 520 |
pq(qq( |
| 521 |
'<h2>Emails to you will be encrypted with the PGP/GPG key:</h2>' |
| 522 |
'<pre>' |
| 523 |
'$pk' |
| 524 |
'</pre>' |
| 525 |
'<p>' |
| 526 |
'<a href="/foc">back to F*EX operation control</a>' |
| 527 |
'</body></html>' |
| 528 |
)); |
| 529 |
unlink "$gf.pk","$gf~"; |
| 530 |
} else { |
| 531 |
$pk = `gpg --batch <$gf.pk 2>&1`; |
| 532 |
$pk =~ s/&/&/g; |
| 533 |
$pk =~ s/</</g; |
| 534 |
pq(qq( |
| 535 |
'<h2>Your uploaded file does not contain a PGP/GPG public key for' |
| 536 |
' $user</h2>' |
| 537 |
'<pre>' |
| 538 |
'$pk' |
| 539 |
'</pre>' |
| 540 |
'<p>' |
| 541 |
'<a href="javascript:history.back()">back</a>' |
| 542 |
'</body></html>' |
| 543 |
)); |
| 544 |
} |
| 545 |
&reexec; |
| 546 |
} |
| 547 |
|
| 548 |
if ($user and $gpg) { |
| 549 |
my $gf = "$user/\@GPG"; |
| 550 |
|
| 551 |
unless(-s "$ENV{HOME}/.gnupg/pubring.gpg") { |
| 552 |
html_error($error,"no GPG support activated"); |
| 553 |
} |
| 554 |
|
| 555 |
if ($gpg eq 'DELETE') { |
| 556 |
unlink $gf; |
| 557 |
pq(qq( |
| 558 |
'<h3>PGP/GPG key deleted.</h3>' |
| 559 |
'<h3>Emails to you will be sent not encrypted.</h3>' |
| 560 |
'<p>' |
| 561 |
'<a href="/foc">back to F*EX operation control</a>' |
| 562 |
)); |
| 563 |
} elsif ($gpg eq 'CHANGE') { |
| 564 |
pq(qq( |
| 565 |
'<form action="$ENV{SCRIPT_NAME}"' |
| 566 |
' method="post"' |
| 567 |
' accept-charset="UTF-8"' |
| 568 |
' enctype="multipart/form-data">' |
| 569 |
' Select your PGP/GPG public key file(*):<br>' |
| 570 |
' <input type="file" name="pubkey" size="80">' |
| 571 |
' <p>' |
| 572 |
' and <input type="submit" value="upload">' |
| 573 |
'</form>' |
| 574 |
)); |
| 575 |
if (-f $gf) { |
| 576 |
my $g = `gpg < $gf`; |
| 577 |
$g =~ s/</</g; |
| 578 |
pq(qq( |
| 579 |
'or <a href="$ENV{SCRIPT_NAME}?gpg=DELETE">' |
| 580 |
'delete your already uploaded public key</a>:' |
| 581 |
'<pre>' |
| 582 |
'$g' |
| 583 |
'</pre>' |
| 584 |
)); |
| 585 |
} |
| 586 |
pq(qq( |
| 587 |
'<p><hr><p>' |
| 588 |
'(*) To extract and verify your GPG public key use:' |
| 589 |
'<pre>' |
| 590 |
'gpg -a --export $user > pubkey.gpg' |
| 591 |
'gpg < pubkey.gpg' |
| 592 |
'</pre>' |
| 593 |
)); |
| 594 |
} |
| 595 |
print "</body></html>\n"; |
| 596 |
exit; |
| 597 |
} |
| 598 |
|
| 599 |
if ($user and $reminder eq 'yes') { |
| 600 |
unlink "$user/\@REMINDER"; |
| 601 |
pq(qq( |
| 602 |
'<h3>You will now get reminder notification emails.<h3>' |
| 603 |
'<p>' |
| 604 |
'<a href="/foc">back to F*EX operation control</a>' |
| 605 |
'</body></html>' |
| 606 |
)); |
| 607 |
&reexec; |
| 608 |
} |
| 609 |
|
| 610 |
if ($user and $reminder eq 'no') { |
| 611 |
unlink "$user/\@REMINDER"; |
| 612 |
symlink "no","$user/\@REMINDER"; |
| 613 |
pq(qq( |
| 614 |
'<h3>You will now get no reminder notification emails.<h3>' |
| 615 |
'<p>' |
| 616 |
'<a href="/foc">back to F*EX operation control</a>' |
| 617 |
'</body></html>' |
| 618 |
)); |
| 619 |
&reexec; |
| 620 |
} |
| 621 |
|
| 622 |
if ($nid) { |
| 623 |
$nid =~ s/^\s+//; |
| 624 |
$nid =~ s/\s+$//; |
| 625 |
|
| 626 |
$nid = randstring(6) if $nid eq '?'; |
| 627 |
|
| 628 |
open $idf,'>',"$user/@" or die "$user/@ - $!\n"; |
| 629 |
print {$idf} $nid,"\n"; |
| 630 |
close $idf; |
| 631 |
|
| 632 |
pq(qq( |
| 633 |
'<h3>new auth-ID "<code>$nid</code>" for $user saved</h3>' |
| 634 |
'<a href="/foc">back to F*EX operation control</a>' |
| 635 |
'</body></html>' |
| 636 |
)); |
| 637 |
&reexec; |
| 638 |
} |
| 639 |
|
| 640 |
# empty subuser list POST |
| 641 |
if (defined($PARAM{'ssid'}) and $ssid =~ /^\s*$/) { |
| 642 |
unlink "$user/\@SUBUSER"; |
| 643 |
pq(qq( |
| 644 |
'<h2>All subusers deleted</h2>\n<ul>' |
| 645 |
'<a href="/foc">back to F*EX operation control</a>' |
| 646 |
'</body></html>' |
| 647 |
)); |
| 648 |
&reexec; |
| 649 |
} |
| 650 |
|
| 651 |
# update sub-users |
| 652 |
if ($ssid) { |
| 653 |
my ($subuser,$subid,$skey); |
| 654 |
|
| 655 |
# delete old skeys |
| 656 |
if (open $idf,'<',"$user/\@SUBUSER") { |
| 657 |
while (<$idf>) { |
| 658 |
s/#.*//; |
| 659 |
if (/(.+\@.+):(.+)/) { |
| 660 |
($subuser,$subid) = ($1,$2); |
| 661 |
$skey = md5_hex("$user:$subuser:$subid"); |
| 662 |
unlink "$skeydir/$skey"; |
| 663 |
unlink "$subuser/\@MAINUSER/$user"; |
| 664 |
} |
| 665 |
} |
| 666 |
close $idf; |
| 667 |
} |
| 668 |
|
| 669 |
$ssid = strip($ssid); |
| 670 |
|
| 671 |
# collect (new) subusers |
| 672 |
foreach (split("\n",$ssid)) { |
| 673 |
s/#.*//; |
| 674 |
s/\s//g; |
| 675 |
if (/(.+\@[\w.-]+)/) { |
| 676 |
$subuser = lc $1; |
| 677 |
push @badaddress,$subuser unless checkaddress($subuser); |
| 678 |
} |
| 679 |
} |
| 680 |
|
| 681 |
if (@badaddress) { |
| 682 |
print "<h2>ERROR: bad addresses:</h2>\n<ul>"; |
| 683 |
foreach my $ba (@badaddress) { print "<li>$ba" } |
| 684 |
pq(qq( |
| 685 |
'</ul>' |
| 686 |
'<a href="javascript:history.back()">Go back</a>' |
| 687 |
'</body></html>' |
| 688 |
)); |
| 689 |
exit; |
| 690 |
} |
| 691 |
|
| 692 |
if ($ssid =~ /\S\@\w/) { |
| 693 |
open $idf,'>',"$user/\@SUBUSER" or die "$user/\@SUBUSER - $!\n"; |
| 694 |
print "Your subusers upload URLs are:<p><code>\n"; |
| 695 |
print "<table>\n"; |
| 696 |
foreach (split("\n",$ssid)) { |
| 697 |
s/#.*//; |
| 698 |
s/\s//g; |
| 699 |
if (/(\S+\@[\w.-]+)/) { |
| 700 |
$subuser = lc $1; |
| 701 |
if (/:(.+)/) { $subid = $1 } |
| 702 |
else { $subid = randstring(8) } |
| 703 |
print {$idf} "$subuser:$subid\n"; |
| 704 |
$skey = mkskey($user,$subuser,$subid); |
| 705 |
print qq'<tr><td>', |
| 706 |
qq'<a href="/fuc?info=$subuser&skey=$skey">$subuser</a> :', |
| 707 |
qq'<td>$fup?skey=$skey</tr>\n'; |
| 708 |
} |
| 709 |
} |
| 710 |
$skey = untaint(md5_hex(readline1("$user/@"))); |
| 711 |
mksymlink("$skeydir/$skey",$user); |
| 712 |
my $surl = "$fup?skey=$skey"; |
| 713 |
pq(qq( |
| 714 |
'<tr><td>$user :<td><a href="$surl">$surl</a></tr>' |
| 715 |
"</table>\n</code><p>" |
| 716 |
"You have to give these URLs to your subusers for fexing files to you." |
| 717 |
"<br>" |
| 718 |
"Or click on the subuser's email address link to send him an" |
| 719 |
"information email by the F*EX server.<p>" |
| 720 |
)); |
| 721 |
} |
| 722 |
print "<a href=\"/foc\">back to F*EX operation control</a>\n"; |
| 723 |
print "</body></html>\n"; |
| 724 |
close $idf; |
| 725 |
exit; |
| 726 |
} |
| 727 |
|
| 728 |
if (open my $subuser,'<',"$user/\@SUBUSER") { |
| 729 |
local $/; |
| 730 |
$ssid = <$subuser> || ''; |
| 731 |
close $subuser; |
| 732 |
} |
| 733 |
|
| 734 |
# display HTML form and request user data |
| 735 |
pq(qq( |
| 736 |
'<form action="$ENV{SCRIPT_NAME}"' |
| 737 |
' method="post"' |
| 738 |
' accept-charset="UTF-8"' |
| 739 |
' enctype="multipart/form-data">' |
| 740 |
)); |
| 741 |
|
| 742 |
# pq(qq( |
| 743 |
# ' <input type="hidden" name="user" value="$user">' |
| 744 |
# ' <input type="hidden" name="id" value="$id">' |
| 745 |
# ' Your F*EX account: <b>$user:$id</b><p>' |
| 746 |
# ' New auth-ID: <input type="text" name="nid" value="$id">' |
| 747 |
# ' (Remember your auth-ID when you change it!)' |
| 748 |
# )); |
| 749 |
|
| 750 |
if (-s "$user/\@ALLOWED_RECIPIENTS") { |
| 751 |
pq(qq( |
| 752 |
' <p>' |
| 753 |
' <input type="submit" value="submit">' |
| 754 |
'</form>' |
| 755 |
'</body></html>' |
| 756 |
)); |
| 757 |
exit; |
| 758 |
} |
| 759 |
|
| 760 |
if ($ssid) { |
| 761 |
$ssid = htmlquote(strip($ssid)); |
| 762 |
} |
| 763 |
|
| 764 |
pq(qq( |
| 765 |
' <p><hr><p>' |
| 766 |
' Allow special senders (= subusers) to fex files to you:<br>' |
| 767 |
' <textarea name="ssid" cols="60" rows="10">$ssid</textarea><br>' |
| 768 |
' <input type="submit" value="save and show upload URLs">' |
| 769 |
'</form>' |
| 770 |
'<p>' |
| 771 |
'<table border=0>' |
| 772 |
' <tr align="left"><td>This list has entries in format:<td><email address>:<encryption-ID><td></tr>' |
| 773 |
' <tr align="left"><td>Example:<td>framstag\@rus.uni-stuttgart.de:schwuppdiwupp<td></tr>' |
| 774 |
'</table>' |
| 775 |
'<p>' |
| 776 |
'These special senders may fex files <em>only</em> to you!<br>' |
| 777 |
'It is not necessary to add regular fex users to your list,' |
| 778 |
'because they already can fex.' |
| 779 |
'<p>' |
| 780 |
'The encryption-ID is necessary to generate a unique upload URL for this subuser.<br>' |
| 781 |
'If you omit the encryption-ID a random one will be used.' |
| 782 |
)); |
| 783 |
|
| 784 |
unless ($nomail) { |
| 785 |
pq(qq( |
| 786 |
'<p><hr><p>' |
| 787 |
'<h3 title="A F*EX group is similar to a mailing list, but for files">' |
| 788 |
'Edit your F*EX groups:</h3>' |
| 789 |
'<ul>' |
| 790 |
)); |
| 791 |
|
| 792 |
foreach $group (glob "$user/\@GROUP/*") { |
| 793 |
if (-f $group and not -l $group and $group !~ /~$/) { |
| 794 |
$group =~ s:.*/::; |
| 795 |
print " <li><a href=\"$ENV{SCRIPT_NAME}?group=$group\">\@$group</a>\n"; |
| 796 |
} |
| 797 |
} |
| 798 |
|
| 799 |
pq(qq( |
| 800 |
' <li><a href="$ENV{SCRIPT_NAME}?group=NEW"><em>new group</em></a>' |
| 801 |
'</ul>' |
| 802 |
)); |
| 803 |
} |
| 804 |
|
| 805 |
pq(qq( |
| 806 |
'<p><hr><p>' |
| 807 |
'<a href="/foc">back to F*EX operation control</a>' |
| 808 |
'</body></html>' |
| 809 |
)); |
| 810 |
|
| 811 |
exit; |
| 812 |
|
| 813 |
|
| 814 |
sub strip { |
| 815 |
local $_ = shift; |
| 816 |
s/[ \t]+//g; |
| 817 |
s/\s*[\r\n]+\s*/\n/g; |
| 818 |
return $_; |
| 819 |
} |
| 820 |
|
| 821 |
|
| 822 |
sub notify_otuser { |
| 823 |
my ($user,$otuser,$url,$comment) = @_; |
| 824 |
my $server = $hostname || $mdomain; |
| 825 |
my ($mfrom,$hfrom); |
| 826 |
|
| 827 |
return if $nomail; |
| 828 |
|
| 829 |
$user .= '@'.$mdomain if $mdomain and $user !~ /@/; |
| 830 |
($mfrom,$hfrom) = mhfrom($user); |
| 831 |
|
| 832 |
open my $mail,'|-',$sendmail,'-f',$mfrom,$otuser,$bcc |
| 833 |
or http_die("cannot start sendmail - $!\n"); |
| 834 |
pq($mail,qq( |
| 835 |
'From: <$mfrom> ($hfrom via F*EX service $server)' |
| 836 |
'To: $otuser' |
| 837 |
'Subject: Your upload URL' |
| 838 |
'X-Mailer: F*EX' |
| 839 |
'Content-Type: text/plain; charset=utf-8' |
| 840 |
'Content-Transfer-Encoding: 8bit' |
| 841 |
'' |
| 842 |
'This is an automatically generated email.' |
| 843 |
'' |
| 844 |
'Use' |
| 845 |
'' |
| 846 |
'$url' |
| 847 |
'' |
| 848 |
'to upload one file to $user' |
| 849 |
'' |
| 850 |
'$comment' |
| 851 |
'' |
| 852 |
'Questions? ==> F*EX admin: $admin' |
| 853 |
)); |
| 854 |
close $mail |
| 855 |
or http_die("cannot send notification email (sendmail error $!)\n"); |
| 856 |
} |
| 857 |
|
| 858 |
|
| 859 |
sub notify_subuser { |
| 860 |
my ($user,$subuser,$url,$comment) = @_; |
| 861 |
my $server = $hostname || $mdomain; |
| 862 |
my ($mfrom,$hfrom); |
| 863 |
|
| 864 |
return if $nomail; |
| 865 |
|
| 866 |
$user .= '@'.$mdomain if $mdomain and $user !~ /@/; |
| 867 |
($mfrom,$hfrom) = mhfrom($user); |
| 868 |
|
| 869 |
open my $mail,'|-',$sendmail,'-f',$mfrom,$subuser,$user,$bcc |
| 870 |
or http_die("cannot start sendmail - $!\n"); |
| 871 |
pq($mail,qq( |
| 872 |
'From: <$mfrom> ($hfrom via F*EX service $server)' |
| 873 |
'To: $subuser' |
| 874 |
'Cc: $user' |
| 875 |
'Subject: Your F*EX account on $server' |
| 876 |
'X-Mailer: F*EX' |
| 877 |
'Content-Type: text/plain; charset=utf-8' |
| 878 |
'Content-Transfer-Encoding: 8bit' |
| 879 |
'' |
| 880 |
'This is an automatically generated email.' |
| 881 |
'' |
| 882 |
'A F*EX (File EXchange) account has been created for you on $server' |
| 883 |
'Use' |
| 884 |
'' |
| 885 |
'$url' |
| 886 |
'' |
| 887 |
'to upload files to $user' |
| 888 |
'' |
| 889 |
'See http://$ENV{HTTP_HOST}/index.html for more information about F*EX.' |
| 890 |
'' |
| 891 |
'$comment' |
| 892 |
'' |
| 893 |
'Questions? ==> F*EX admin: $admin' |
| 894 |
)); |
| 895 |
close $mail |
| 896 |
or http_die("cannot send notification email (sendmail error $!)\n"); |
| 897 |
} |
| 898 |
|
| 899 |
|
| 900 |
sub notify_groupmember { |
| 901 |
my ($user,$gm,$group,$id,$url) = @_; |
| 902 |
my $server = $hostname || $mdomain; |
| 903 |
my ($mfrom,$hfrom); |
| 904 |
|
| 905 |
$user .= '@'.$mdomain if $mdomain and $user !~ /@/; |
| 906 |
($mfrom,$hfrom) = mhfrom($user); |
| 907 |
|
| 908 |
open my $mail,'|-',$sendmail,'-f',$mfrom,$gm,$user,$bcc |
| 909 |
or http_die("cannot start sendmail - $!\n"); |
| 910 |
pq($mail,qq( |
| 911 |
'From: <$mfrom> ($hfrom via F*EX service $server)' |
| 912 |
'To: $gm' |
| 913 |
'Cc: $user' |
| 914 |
'Subject: Your F*EX account on $server' |
| 915 |
'X-Mailer: F*EX' |
| 916 |
'' |
| 917 |
'A F*EX (File EXchange) account has been created for you on $server' |
| 918 |
'Use' |
| 919 |
'' |
| 920 |
'$url' |
| 921 |
'' |
| 922 |
'to upload files to F*EX group "$group"' |
| 923 |
'' |
| 924 |
'See http://$ENV{HTTP_HOST}/index.html for more information about F*EX.' |
| 925 |
'' |
| 926 |
'Questions? ==> F*EX admin: $admin' |
| 927 |
)); |
| 928 |
close $mail |
| 929 |
or http_die("cannot send notification email (sendmail error $!)\n"); |
| 930 |
} |
| 931 |
|
| 932 |
|
| 933 |
sub mkskey { |
| 934 |
my ($user,$subuser,$id) = @_; |
| 935 |
my $skey = md5_hex("$user:$subuser:$id"); |
| 936 |
|
| 937 |
open my $skf,'>',"$skeydir/$skey" or die "$skeydir/$skey - $!\n"; |
| 938 |
print {$skf} "from=$subuser\n", |
| 939 |
"to=$user\n", |
| 940 |
"id=$id\n"; |
| 941 |
close $skf or die "$skeydir/$skey - $!\n"; |
| 942 |
mkdirp("$subuser/\@MAINUSER"); |
| 943 |
symlink $skey,"$subuser/\@MAINUSER/$user"; |
| 944 |
return $skey; |
| 945 |
} |
| 946 |
|
| 947 |
|
| 948 |
sub mkgkey { |
| 949 |
my ($user,$group,$gm,$id) = @_; |
| 950 |
my $gkey = untaint(md5_hex("$user:$group:$gm:$id")); |
| 951 |
|
| 952 |
open my $gkf,'>',"$gkeydir/$gkey" or die "$gkeydir/$gkey - $!\n"; |
| 953 |
print {$gkf} "from=$gm\n", |
| 954 |
"to=\@$group\n", |
| 955 |
"user=$user\n", |
| 956 |
"id=$id\n"; |
| 957 |
close $gkf or die "$gkeydir/$gkey - $!\n"; |
| 958 |
return $gkey; |
| 959 |
} |
| 960 |
|
| 961 |
|
| 962 |
sub handle_group { |
| 963 |
my ($gf,$gd,$gl,$gid,$gkey); |
| 964 |
|
| 965 |
$group =~ s/^@+//; |
| 966 |
$group =~ s:[/&<>]::g; |
| 967 |
|
| 968 |
# $notify is group member |
| 969 |
if ($notify) { |
| 970 |
$gf = untaint("$notify/\@GROUP/$group"); |
| 971 |
unless ($_ = readlink $gf) { |
| 972 |
pq(qq( |
| 973 |
'<h2>ERROR: cannot read $gf - $!</h2>' |
| 974 |
'</body></html>' |
| 975 |
)); |
| 976 |
exit; |
| 977 |
} |
| 978 |
if (m{([^/]+\@[\w.-]+)/}) { |
| 979 |
$user = lc $1; |
| 980 |
} else { |
| 981 |
pq(qq( |
| 982 |
'<h2>INTERNAL ERROR: groupfile = $gf</h2>' |
| 983 |
'</body></html>' |
| 984 |
)); |
| 985 |
exit; |
| 986 |
} |
| 987 |
if (open $gf,'<',$gf) { |
| 988 |
while (<$gf>) { |
| 989 |
if (/\Q$notify\E:(\S+)/i) { |
| 990 |
$gid = $1; |
| 991 |
last; |
| 992 |
} |
| 993 |
} |
| 994 |
close $gf; |
| 995 |
} else { |
| 996 |
pq(qq( |
| 997 |
'<h2>ERROR: cannot open $gf - $!</h2>' |
| 998 |
'</body></html>' |
| 999 |
)); |
| 1000 |
exit; |
| 1001 |
} |
| 1002 |
unless ($gid) { |
| 1003 |
pq(qq( |
| 1004 |
'<h2>ERROR: $notify not found in $gf</h2>' |
| 1005 |
'</body></html>' |
| 1006 |
)); |
| 1007 |
exit; |
| 1008 |
} |
| 1009 |
$gkey = untaint(md5_hex("$user:$group:$notify:$gid")); |
| 1010 |
notify_groupmember( |
| 1011 |
$user, |
| 1012 |
$notify, |
| 1013 |
$group, |
| 1014 |
$gid, |
| 1015 |
# "$ENV{PROTO}://$ENV{HTTP_HOST}/fup?from=$notify&to=\@$group" |
| 1016 |
"$fup?gkey=$gkey" |
| 1017 |
); |
| 1018 |
pq(qq( |
| 1019 |
'<h2>Notification email to $notify has been sent</h2>' |
| 1020 |
'<p><a href="javascript:history.back()">Go back</a>' |
| 1021 |
'</body></html>' |
| 1022 |
)); |
| 1023 |
exit; |
| 1024 |
} |
| 1025 |
|
| 1026 |
$gf = untaint("$user/\@GROUP/$group"); |
| 1027 |
|
| 1028 |
if (defined $gm) { |
| 1029 |
if ($gm =~ /\S/) { |
| 1030 |
foreach (split /\n/,$gm) { |
| 1031 |
s/#.*//; |
| 1032 |
s/\s//g; |
| 1033 |
next if /^\w+=./; |
| 1034 |
next if /^$/; |
| 1035 |
if (s/:.+//) { |
| 1036 |
if (/(.+@[\w\.-]+)/ and checkaddress($_)) { |
| 1037 |
push @gm,lc $1; |
| 1038 |
} else { |
| 1039 |
push @badaddress,$_; |
| 1040 |
} |
| 1041 |
} else { |
| 1042 |
push @badformat,$_; |
| 1043 |
} |
| 1044 |
} |
| 1045 |
if (@badformat) { |
| 1046 |
print "<h2>ERROR: lines not in format <email address>:<encryption-ID></h2>\n<ul>"; |
| 1047 |
foreach my $ba (@badformat) { print "<li>$ba" } |
| 1048 |
print "</ul>\n"; |
| 1049 |
} |
| 1050 |
if (@badaddress) { |
| 1051 |
print "<h2>ERROR: bad addresses:</h2>\n<ul>"; |
| 1052 |
foreach my $ba (@badaddress) { print "<li>$ba" } |
| 1053 |
print "</ul>\n"; |
| 1054 |
} |
| 1055 |
if (@badformat or @badaddress) { |
| 1056 |
pq(qq( |
| 1057 |
'<a href="javascript:history.back()">Go back</a>' |
| 1058 |
'</body></html>' |
| 1059 |
)); |
| 1060 |
exit; |
| 1061 |
} |
| 1062 |
$gd = "$user/\@GROUP"; |
| 1063 |
unless (-d $gd or mkdir $gd,0700) { |
| 1064 |
print "<h2>ERROR: cannot create $gd - $!</h2>\n"; |
| 1065 |
print "</body></html>\n"; |
| 1066 |
exit; |
| 1067 |
} |
| 1068 |
if (-l $gf) { |
| 1069 |
if ($_ = readlink $gf and m{([^/]+\@[\w.-]+)/}) { |
| 1070 |
$user = $1; |
| 1071 |
pq(qq( |
| 1072 |
'<h2>ERROR: you are already in group \@$group owned by $user</h2>' |
| 1073 |
'<a href="javascript:history.back()">Go back</a>' |
| 1074 |
'and enter another group name' |
| 1075 |
'</body></html>' |
| 1076 |
)); |
| 1077 |
} else { |
| 1078 |
print "<h2>INTERNAL ERROR: $gf is a symlink. but not readable</h2>\n"; |
| 1079 |
print "</body></html>\n"; |
| 1080 |
} |
| 1081 |
exit; |
| 1082 |
} |
| 1083 |
# delete old gkeys |
| 1084 |
if (open $gf,'<',$gf) { |
| 1085 |
# delete old group links and gkeys |
| 1086 |
while (<$gf>) { |
| 1087 |
s/#.*//; |
| 1088 |
if (/(.+\@.+):(.+)/) { |
| 1089 |
$gkey = untaint(md5_hex("$user:$group:$1:$2")); |
| 1090 |
unlink "$gkeydir/$gkey"; |
| 1091 |
unlink "$1/\@GROUP/$group" if -l "$1/\@GROUP/$group"; |
| 1092 |
} |
| 1093 |
} |
| 1094 |
close $gf; |
| 1095 |
} |
| 1096 |
# write new group file and gkeys |
| 1097 |
if (open $gf,'>',$gf) { |
| 1098 |
$gm =~ s/[\r\n]+/\n/g; |
| 1099 |
foreach (split /\n/,$gm) { |
| 1100 |
print {$gf} "$_\n"; |
| 1101 |
s/#.*//; |
| 1102 |
s/\s//g; |
| 1103 |
if (/^\s*([^\/]+):(.+)/) { |
| 1104 |
mkgkey(lc $user,$group,lc $1,$2); |
| 1105 |
} |
| 1106 |
} |
| 1107 |
close $gf; |
| 1108 |
} else { |
| 1109 |
print "<h2>ERROR: cannot write $gf - $!</h2>\n"; |
| 1110 |
print "</body></html>\n"; |
| 1111 |
exit; |
| 1112 |
} |
| 1113 |
if (@gm) { |
| 1114 |
foreach $gm (@gm) { |
| 1115 |
next if $gm eq $user; |
| 1116 |
unless (-d $gm or mkdir $gm,0700) { |
| 1117 |
print "<h2>ERROR: cannot create $gm - $!</h2>\n"; |
| 1118 |
print "</body></html>\n"; |
| 1119 |
exit; |
| 1120 |
} |
| 1121 |
$gd = "$gm/\@GROUP"; |
| 1122 |
unless (-d $gd or mkdir $gd,0700) { |
| 1123 |
print "<h2>ERROR: cannot create $gd - $!</h2>\n"; |
| 1124 |
print "</body></html>\n"; |
| 1125 |
exit; |
| 1126 |
} |
| 1127 |
$gl = "$gm/\@GROUP/$group"; |
| 1128 |
unless (-l $gl or symlink "../../$user/\@GROUP/$group",$gl) { |
| 1129 |
print "<h2>ERROR: cannot create $gl - $!</h2>\n"; |
| 1130 |
print "</body></html>\n"; |
| 1131 |
exit; |
| 1132 |
} |
| 1133 |
} |
| 1134 |
pq(qq( |
| 1135 |
'<h2>Group \@$group has members:</h2>' |
| 1136 |
'<ul>' |
| 1137 |
)); |
| 1138 |
foreach $gm (@gm) { |
| 1139 |
if ($gm ne $user) { |
| 1140 |
print " <li><a href=\"$ENV{SCRIPT_NAME}?group=$group¬ify=$gm\">$gm</a>\n"; |
| 1141 |
} |
| 1142 |
} |
| 1143 |
pq(qq( |
| 1144 |
'</ul>' |
| 1145 |
'(click address to send a notification email to this user)' |
| 1146 |
)); |
| 1147 |
} else { |
| 1148 |
print "<h2>Group \@$group has no members</h2>\n"; |
| 1149 |
} |
| 1150 |
pq(qq( |
| 1151 |
'<p>' |
| 1152 |
'<a href="/foc">back to F*EX operation control</a>' |
| 1153 |
)); |
| 1154 |
print "</body></html>\n"; |
| 1155 |
exit; |
| 1156 |
} else { |
| 1157 |
# no group members -> delete group file |
| 1158 |
unlink $gf; |
| 1159 |
} |
| 1160 |
} else { |
| 1161 |
$gm = ''; |
| 1162 |
pq(qq( |
| 1163 |
'<h2>Edit F*EX group</h2>' |
| 1164 |
'A F*EX group is similar to a mailing list, but for files:<br>' |
| 1165 |
'When a member fexes a file to this list, ' |
| 1166 |
'then all other members will receive it.' |
| 1167 |
'<p>' |
| 1168 |
'<form action="$ENV{SCRIPT_NAME}"' |
| 1169 |
' method="post"' |
| 1170 |
' accept-charset="UTF-8"' |
| 1171 |
' enctype="multipart/form-data">' |
| 1172 |
)); |
| 1173 |
if ($group eq 'NEW') { |
| 1174 |
pq(qq( |
| 1175 |
' <font color="red">' |
| 1176 |
' New group name: <input type="text" name="group"> (You MUST fill out this field!)' |
| 1177 |
' </font>' |
| 1178 |
)); |
| 1179 |
$gm = $user.':'.randstring(8); |
| 1180 |
} else { |
| 1181 |
if (open $gf,'<',$gf) { |
| 1182 |
local $/; |
| 1183 |
$gm = <$gf>||''; |
| 1184 |
} |
| 1185 |
close $gf; |
| 1186 |
pq(qq( |
| 1187 |
' <input type="hidden" name="group" value="$group">' |
| 1188 |
' F*EX group <b>\@$group</b>:' |
| 1189 |
)); |
| 1190 |
} |
| 1191 |
my $rows = ($gm =~ tr/\n//) + 5; |
| 1192 |
pq(qq( |
| 1193 |
' <br><textarea name="gm" cols="80" rows="$rows">$gm</textarea><br>' |
| 1194 |
' <input type="submit" value="submit">' |
| 1195 |
'</form>' |
| 1196 |
'<p>' |
| 1197 |
'<table border=0>' |
| 1198 |
' <tr align="left"><td>This list must have entries in format:<td><email address>:<encryption-ID><td></tr>' |
| 1199 |
' <tr align="left"><td>Example:<td>framstag\@rus.uni-stuttgart.de:schwuppdiwupp<td></tr>' |
| 1200 |
'</table>' |
| 1201 |
'<p>' |
| 1202 |
'The encryption-ID is necessary to generate a unique upload URL for this subuser.' |
| 1203 |
'You can name any existing email address.' |
| 1204 |
)); |
| 1205 |
if (open my $ab,'<',"$user/\@ADDRESS_BOOK") { |
| 1206 |
pq(qq( |
| 1207 |
"<p><hr><p>" |
| 1208 |
"<h3>Your address book:</h3>" |
| 1209 |
"<pre>" |
| 1210 |
)); |
| 1211 |
while (<$ab>) { |
| 1212 |
s/#.*//; |
| 1213 |
print "$1\n" if /([\S]+\@[\S]+)/; |
| 1214 |
} |
| 1215 |
close $ab; |
| 1216 |
print "</pre>\n"; |
| 1217 |
} |
| 1218 |
print "</body></html>\n"; |
| 1219 |
exit; |
| 1220 |
} |
| 1221 |
} |