3 # This CGI generated the HTML for choosing a group or list of groups.
5 BEGIN { push(@INC, ".."); };
8 $trust_unknown_referers = 1;
10 if (&get_product_name() eq 'usermin') {
11 &switch_to_remote_user();
13 &ReadParse(undef, undef, 2);
14 %access = &get_module_acl();
16 # Build list of primary groups
18 while(@uinfo = getpwent()) {
19 push(@{$members{$uinfo[3]}}, $uinfo[0]);
21 endpwent() if ($gconfig{'os_type'} ne 'hpux');
24 # selecting multiple groups.
25 if ($in{'frame'} == 0) {
29 @ul = &split_quoted($in{'group'});
31 print "sel = new Array($len);\n";
32 print "selr = new Array($len);\n";
33 for($i=0; $i<$len; $i++) {
35 "e_escape($ul[$i], '"')."\";\n";
36 @ginfo = getgrnam($ul[$i]);
38 @mems = &unique( split(/ /, $ginfo[3]),
39 @{$members{$ginfo[2]}} );
40 if (@mems > 3) { @mems = (@mems[0..1], "..."); }
41 print "selr[$i] = \"",
42 "e_escape(join(' ', @mems), "'"),"\";\n";
44 else { print "selr[$i] = \"???\";\n"; }
47 print "<title>$text{'groups_title1'}</title>\n";
48 print "<frameset cols='50%,50%'>\n";
49 print "<frame src=\"group_chooser.cgi?frame=1&multi=1\">\n";
50 print "<frameset rows='*,50' frameborder=no>\n";
51 print " <frame src=\"group_chooser.cgi?frame=2&multi=1\">\n";
52 print " <frame src=\"group_chooser.cgi?frame=3&multi=1\" scrolling=no>\n";
53 print "</frameset>\n";
54 print "</frameset>\n";
56 elsif ($in{'frame'} == 1) {
57 # list of all groups to choose from
60 print "function addgroup(u, r)\n";
62 print "top.sel[top.sel.length] = u\n";
63 print "top.selr[top.selr.length] = r\n";
64 print "top.frames[1].location = top.frames[1].location\n";
65 print "return false;\n";
68 print "<font size=+1>$text{'groups_all'}</font>\n";
69 print "<table width=100%>\n";
70 foreach $u (&get_groups_list()) {
71 if ($in{'group'} eq $u->[0]) { print "<tr $cb>\n"; }
72 else { print "<tr>\n"; }
73 print "<td width=20%><a href=\"\" onClick='return addgroup(\"$u->[0]\", \"$u->[3]\")'>$u->[0]</a></td>\n";
74 print "<td>$u->[3]</td> </tr>\n";
79 elsif ($in{'frame'} == 2) {
82 print "<font size=+1>$text{'groups_sel'}</font>\n";
88 sel2 = new Array(); selr2 = new Array();
89 for(k=0,l=0; k<top.sel.length; k++) {
92 selr2[l] = top.selr[k];
96 top.sel = sel2; top.selr = selr2;
100 for(i=0; i<top.sel.length; i++) {
101 document.write("<tr>\n");
102 document.write("<td><a href=\"\" onClick='return sub("+i+")'>"+top.sel[i]+"</a></td>\n");
103 document.write("<td>"+top.selr[i]+"</td>\n");
110 elsif ($in{'frame'} == 3) {
111 # output OK and Cancel buttons
114 print "function qjoin(l)\n";
116 print "rv = \"\";\n";
117 print "for(i=0; i<l.length; i++) {\n";
118 print " if (rv != '') rv += ' ';\n";
119 print " if (l[i].indexOf(' ') < 0) rv += l[i];\n";
120 print " else rv += '\"'+l[i]+'\"'\n";
122 print "return rv;\n";
126 print "<input type=button value=\"$text{'groups_ok'}\" ",
127 " onClick='top.opener.ifield.value = qjoin(top.sel); ",
129 print "<input type=button value=\"$text{'groups_cancel'}\" ",
130 "onClick='top.close()'>\n";
131 print " <input type=button value=\"$text{'groups_clear'}\" onClick='top.sel = new Array(); top.selr = new Array(); top.frames[1].location = top.frames[1].location'>\n";
137 # selecting just one group .. display a list of all groups to
139 &popup_header($text{'groups_title2'});
141 print "function select(f)\n";
143 print "top.opener.ifield.value = f;\n";
144 print "top.close();\n";
145 print "return false;\n";
148 print "<table width=100%>\n";
149 foreach $u (&get_groups_list()) {
150 if ($in{'group'} eq $u->[0]) { print "<tr $cb>\n"; }
151 else { print "<tr>\n"; }
152 print "<td width=20%><a href=\"\" onClick='return select(\"$u->[0]\")'>$u->[0]</a></td>\n";
153 print "<td>$u->[3]</td> </tr>\n";
161 local(@ginfo, @groups, %gcan, %found);
162 if ($access{'gedit_mode'} == 2 || $access{'gedit_mode'} == 3) {
163 map { $gcan{$_}++ } split(/\s+/, $access{'gedit'});
166 while(@ginfo = getgrent()) {
167 @mems = &unique( split(/ /, $ginfo[3]), @{$members{$ginfo[2]}} );
168 if (@mems > 3) { @mems = (@mems[0..1], "..."); }
169 $ginfo[3] = join(' ', @mems);
170 if ($access{'gedit_mode'} == 0 ||
171 $access{'gedit_mode'} == 2 && $gcan{$ginfo[0]} ||
172 $access{'gedit_mode'} == 3 && !$gcan{$ginfo[0]} ||
173 $access{'gedit_mode'} == 4 &&
174 (!$access{'gedit'} || $ginfo[2] >= $access{'gedit'}) &&
175 (!$access{'gedit2'} || $ginfo[2] <= $access{'gedit2'})) {
176 push(@groups, [ @ginfo ]) if (!$found{$ginfo[0]}++);
179 endgrent() if ($gconfig{'os_type'} ne 'hpux');
180 return sort { $a->[0] cmp $b->[0] } @groups;
183 # split_quoted(string)
188 while($str =~ /^\s*(\S*"[^"]+"\S*)(.*)$/ || $str =~ /^\s*(\S+)(.*)$/) {