#!/usr/local/bin/perl
# group_chooser.cgi
# This CGI generated the HTML for choosing a group or list of groups.
require './web-lib.pl';
&init_config();
&switch_to_remote_user();
&ReadParse();
%access = &get_module_acl();
# Build list of primary groups
setpwent();
while(@uinfo = getpwent()) {
push(@{$members{$uinfo[3]}}, $uinfo[0]);
}
endpwent() if ($gconfig{'os_type'} ne 'hpux');
if ($in{'multi'}) {
# selecting multiple groups.
if ($in{'frame'} == 0) {
# base frame
&PrintHeader();
print "\n";
print "
$text{'groups_title1'}\n";
print "\n";
}
elsif ($in{'frame'} == 1) {
# list of all groups to choose from
&header();
print "\n";
print "$text{'groups_all'}\n";
print "\n";
foreach $u (&get_groups_list()) {
if ($in{'group'} eq $u->[0]) { print "\n"; }
else { print "
\n"; }
print "$u->[0] | \n";
print "$u->[3] |
\n";
}
print "
\n";
}
elsif ($in{'frame'} == 2) {
# show chosen groups
&header();
print "$text{'groups_sel'}\n";
print <<'EOF';
EOF
}
elsif ($in{'frame'} == 3) {
# output OK and Cancel buttons
&header();
print "\n";
}
}
else {
# selecting just one group .. display a list of all groups to choose from
&header();
print "\n";
print "$text{'groups_title2'}\n";
print "\n";
foreach $u (&get_groups_list()) {
if ($in{'group'} eq $u->[0]) { print "\n"; }
else { print "
\n"; }
print "$u->[0] | \n";
print "$u->[3] |
\n";
}
print "
\n";
}
sub get_groups_list
{
local(@ginfo, @groups, %gcan, %found);
if ($access{'gedit_mode'} == 2 || $access{'gedit_mode'} == 3) {
map { $gcan{$_}++ } split(/\s+/, $access{'gedit'});
}
setgrent();
while(@ginfo = getgrent()) {
@mems = &unique( split(/ /, $ginfo[3]), @{$members{$ginfo[2]}} );
if (@mems > 3) { @mems = (@mems[0..1], "..."); }
$ginfo[3] = join(' ', @mems);
if ($access{'gedit_mode'} == 0 ||
$access{'gedit_mode'} == 2 && $gcan{$ginfo[0]} ||
$access{'gedit_mode'} == 3 && !$gcan{$ginfo[0]} ||
$access{'gedit_mode'} == 4 &&
(!$access{'gedit'} || $ginfo[2] >= $access{'gedit'}) &&
(!$access{'gedit2'} || $ginfo[2] <= $access{'gedit2'})) {
push(@groups, [ @ginfo ]) if (!$found{$ginfo[0]}++);
}
}
endgrent() if ($gconfig{'os_type'} ne 'hpux');
return sort { $a->[0] cmp $b->[0] } @groups;
}