#!/usr/local/bin/perl
# index.cgi

require './dfs-lib.pl';
&header("NFS Shares", "", "intro", 1, 1, 0,
	&help_search_link("dfstab share", "man"));
print "<hr>\n";
%access = &get_module_acl();

@shlist = &list_shares();
if (@shlist && $access{'icons'}) {
	# Display shares as icons
	print "<a href=\"edit_share.cgi\">Start sharing a new directory</a>. <br>\n";
	foreach $s (@shlist) {
		next if ($s->{'type'} ne 'nfs');
		push(@icons, "images/share.gif");
		push(@titles, $s->{'dir'});
		push(@links, "edit_share.cgi?$s->{'index'}");
		}
	&icons_table(\@links, \@titles, \@icons);
	}
elsif (@shlist) {
	# Display shares as table
	print "<a href=\"edit_share.cgi\">Start sharing a new directory</a>. <br>\n";
	print "<table border width=100%>\n";
	print "<tr $tb><td width=20%><b>Directory</b></td> ",
	      "<td><b>Clients</b></td> </tr>\n";
	foreach $s (@shlist) {
		next if ($s->{'type'} ne 'nfs');
		&parse_options($s->{'opts'});
		print "<tr $cb>\n";
		if (defined($options{'public'})) {
			print "<td><b><a href=\"edit_share.cgi?$s->{'index'}\">",&html_escape($s->{'dir'}),"</a></b></td>\n";
			}
		else {
			print "<td><a href=\"edit_share.cgi?$s->{'index'}\">",&html_escape($s->{'dir'}),"</a></td>\n";
			}
		undef(%clients);
		foreach (split(/:/, $options{"ro"})) { $clients{$_}++; }
		foreach (split(/:/, $options{"rw"})) { $clients{$_}++; }
		foreach (split(/:/, $options{"root"})) { $clients{$_}++; }
		if (%clients) {
			$clients = join(' &nbsp;|&nbsp; ' , sort { $a cmp $b }
			    map { &html_escape($_ =~ /^\@(.*)/ ? "$1.*" : $_) }
				     (keys %clients) );
			if (length($clients) > 80) {
				$clients = substr($clients, 0, 80)."...";
				}
			}
		else { $clients = "Everyone"; }
		print "<td>$clients</td>\n";
		print "</tr>\n";
		}
	print "</table>\n";
	}
else {
	print "<b>No directories are currently being exported on ",
	      "this system</b>. <p>\n";
	}
print "<a href=\"edit_share.cgi\">Start sharing a new directory</a>. <p>\n";

print "<hr>\n";
print "<table width=100%> <tr>\n";
print "<td><form action=restart_sharing.cgi>\n";
print "<input type=submit value=\"Apply Changes\">\n";
print "</form></td>\n";
print "<td valign=top> Click this button to apply the current file sharing\n";
print "configuration. This will make all the directories listed above\n";
print "available with the options specified.</td>\n";
print "</tr> <tr> </table>\n";

print "<hr>\n";
&footer("/", "index");

