3 # This CGI generated the HTML for choosing a group or list of groups.
5 $trust_unknown_referers = 1;
6 require './web-lib.pl';
8 &ReadParse(undef, undef, 2);
9 %access = &get_module_acl();
11 # Build list of primary groups
13 while(@uinfo = getpwent()) {
14 push(@{$members{$uinfo[3]}}, $uinfo[0]);
16 endpwent() if ($gconfig{'os_type'} ne 'hpux');
19 # selecting multiple groups.
20 if ($in{'frame'} == 0) {
24 @ul = &split_quoted($in{'group'});
26 print "sel = new Array($len);\n";
27 print "selr = new Array($len);\n";
28 for($i=0; $i<$len; $i++) {
30 "e_escape($ul[$i], '"')."\";\n";
31 @ginfo = getgrnam($ul[$i]);
33 @mems = &unique( split(/ /, $ginfo[3]),
34 @{$members{$ginfo[2]}} );
35 if (@mems > 3) { @mems = (@mems[0..1], "..."); }
36 print "selr[$i] = \"",
37 "e_escape(join(' ', @mems), "'"),"\";\n";
39 else { print "selr[$i] = \"???\";\n"; }
42 print "<title>$text{'groups_title1'}</title>\n";
43 print "<frameset cols='50%,50%'>\n";
44 print "<frame src=\"/group_chooser.cgi?frame=1&multi=1\">\n";
45 print "<frameset rows='*,50' frameborder=no>\n";
46 print " <frame src=\"/group_chooser.cgi?frame=2&multi=1\">\n";
47 print " <frame src=\"/group_chooser.cgi?frame=3&multi=1\" scrolling=no>\n";
48 print "</frameset>\n";
49 print "</frameset>\n";
51 elsif ($in{'frame'} == 1) {
52 # list of all groups to choose from
55 print "function addgroup(u, r)\n";
57 print "top.sel[top.sel.length] = u\n";
58 print "top.selr[top.selr.length] = r\n";
59 print "top.frames[1].location = top.frames[1].location\n";
60 print "return false;\n";
63 print "<font size=+1>$text{'groups_all'}</font>\n";
64 print "<table width=100%>\n";
65 foreach $u (&get_groups_list()) {
66 if ($in{'group'} eq $u->[0]) { print "<tr $cb>\n"; }
67 else { print "<tr>\n"; }
68 print "<td width=20%><a href=\"\" onClick='return addgroup(\"$u->[0]\", \"$u->[3]\")'>$u->[0]</a></td>\n";
69 print "<td>$u->[3]</td> </tr>\n";
74 elsif ($in{'frame'} == 2) {
77 print "<font size=+1>$text{'groups_sel'}</font>\n";
83 sel2 = new Array(); selr2 = new Array();
84 for(k=0,l=0; k<top.sel.length; k++) {
87 selr2[l] = top.selr[k];
91 top.sel = sel2; top.selr = selr2;
95 for(i=0; i<top.sel.length; i++) {
96 document.write("<tr>\n");
97 document.write("<td><a href=\"\" onClick='return sub("+i+")'>"+top.sel[i]+"</a></td>\n");
98 document.write("<td>"+top.selr[i]+"</td>\n");
105 elsif ($in{'frame'} == 3) {
106 # output OK and Cancel buttons
109 print "function qjoin(l)\n";
111 print "rv = \"\";\n";
112 print "for(i=0; i<l.length; i++) {\n";
113 print " if (rv != '') rv += ' ';\n";
114 print " if (l[i].indexOf(' ') < 0) rv += l[i];\n";
115 print " else rv += '\"'+l[i]+'\"'\n";
117 print "return rv;\n";
121 print "<input type=button value=\"$text{'groups_ok'}\" ",
122 " onClick='top.opener.ifield.value = qjoin(top.sel); ",
124 print "<input type=button value=\"$text{'groups_cancel'}\" ",
125 "onClick='top.close()'>\n";
126 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";
132 # selecting just one group .. display a list of all groups to
134 &popup_header($text{'groups_title2'});
136 print "function select(f)\n";
138 print "top.opener.ifield.value = f;\n";
139 print "top.close();\n";
140 print "return false;\n";
143 print "<table width=100%>\n";
144 foreach $u (&get_groups_list()) {
145 if ($in{'group'} eq $u->[0]) { print "<tr $cb>\n"; }
146 else { print "<tr>\n"; }
147 print "<td width=20%><a href=\"\" onClick='return select(\"$u->[0]\")'>$u->[0]</a></td>\n";
148 print "<td>$u->[3]</td> </tr>\n";
156 local(@ginfo, @groups, %gcan, %found);
157 if ($access{'gedit_mode'} == 2 || $access{'gedit_mode'} == 3) {
158 map { $gcan{$_}++ } split(/\s+/, $access{'gedit'});
161 while(@ginfo = getgrent()) {
162 @mems = &unique( split(/ /, $ginfo[3]), @{$members{$ginfo[2]}} );
163 if (@mems > 3) { @mems = (@mems[0..1], "..."); }
164 $ginfo[3] = join(' ', @mems);
165 if ($access{'gedit_mode'} == 0 ||
166 $access{'gedit_mode'} == 2 && $gcan{$ginfo[0]} ||
167 $access{'gedit_mode'} == 3 && !$gcan{$ginfo[0]} ||
168 $access{'gedit_mode'} == 4 &&
169 (!$access{'gedit'} || $ginfo[2] >= $access{'gedit'}) &&
170 (!$access{'gedit2'} || $ginfo[2] <= $access{'gedit2'})) {
171 push(@groups, [ @ginfo ]) if (!$found{$ginfo[0]}++);
174 endgrent() if ($gconfig{'os_type'} ne 'hpux');
175 return sort { $a->[0] cmp $b->[0] } @groups;
178 # split_quoted(string)
183 while($str =~ /^\s*(\S*"[^"]+"\S*)(.*)$/ || $str =~ /^\s*(\S+)(.*)$/) {