#!/usr/local/bin/perl
# index.cgi
# Display PAM services on the system

require './pam-lib.pl';
&header($text{'index_title'}, undef, undef, 1, 1, 0,
	&help_search_link("pam", "man", "howto", "doc"));
print "<hr>\n";

@pams = sort { $a->{'name'} cmp $b->{'name'} } &get_pam_config();
if (!@pams) {
	print "<p>",&text('index_none', "<tt>$config{'pam_dir'}</tt>",
			  "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
	print "<hr>\n";
	&footer("/", $text{'index'});
	exit;
	}

print "<a href='create_form.cgi'>$text{'index_add'}</a><br>\n";
$mid = int((@pams-1) / 2);
print "<table width=100%><tr> <td width=50% valign=top>\n";
&pam_table(@pams[0 .. $mid]);
print "</td> <td width=50% valign=top>\n";
&pam_table(@pams[$mid+1 .. $#pams]);
print "</td> </tr></table>\n";
print "<a href='create_form.cgi'>$text{'index_add'}</a><p>\n";

print "<hr>\n";
&footer("/", $text{'index'});

sub pam_table
{
print "<table border width=100%>\n";
print "<tr $tb> <td><b>$text{'index_name'}</b></td> ",
      "<td><b>$text{'index_desc'}</b></td> </tr>\n";
foreach $p (@_) {
	print "<tr $cb>\n";
	print "<td><a href='edit_pam.cgi?idx=$p->{'index'}'>",
	      &html_escape($p->{'name'}),"</a></td>\n";
	local $t = $text{'desc_'.$p->{'name'}};
	print "<td>",$p->{'desc'} ? $p->{'desc'} : $t ? $t : "<br>","</td>\n";
	print "</tr>\n";
	}
print "</table>\n";
}

