#!/usr/local/bin/perl
# index.cgi
# Output HTML for the file manager applet

require './file-lib.pl';
$theme_no_table = 1;
if ($access{'uid'} < 0 && !defined(getpwnam($remote_user))) {
	&error(&text('index_eremote', $remote_user));
	}
&header($text{'index_title'});
if ($gconfig{'referers_none'}) {
	# Because java applet HTTP requests don't always include a referer:
	# header, we need to use a DBM of trust keys to identify trusted applets
	if (defined(&seed_random)) { &seed_random(); }
	else { srand(time() ^ $$); }
	$trust = int(rand(1000000000));
	local $now = time();
	&open_trust_db();
	foreach $k (keys %trustdb) {
		if ($now - $trustdb{$k} > 30*24*60*60) {
			delete($trustdb{$k});
			}
		}
	$trustdb{$trust} = $now;
	dbmclose(%trustdb);
	}


$sharing = $access{'uid'} ? 0 : 1;
&read_acl(undef, \%acl);
$mc = @{$acl{$base_remote_user}};
if (!$gconfig{'gotoone'} || $mc > 1) {
	%minfo = &get_module_info();
	$return = "<param name=return value=\"$gconfig{'webprefix'}/?cat=$minfo{'category'}\">";
	}
print <<EOF;
<script>
function upload(dir)
{
open("upform.cgi?dir="+dir+"&trust=$trust", "upload", "toolbar=no,menubar=no,scrollbar=no,width=450,height=200");
}
</script>

<applet code=FileManager name=FileManager width=100% height=100% MAYSCRIPT>
<param name=root value="$access{'root'}">
<param name=follow value="$access{'follow'}">
<param name=ro value="$access{'ro'}">
<param name=sharing value="$sharing">
<param name=trust value="$trust">
<param name=goto value="$access{'goto'}">
$return
$text{'index_nojava'} <p>
</applet>
EOF
&footer();


