1 |
unnilennium |
1.1 |
diff -Nur smeserver-groupmembers-panel-1.0.2.old/root/usr/share/perl5/site_perl/esmith/FormMagick/Panel/groupmembers.pm smeserver-groupmembers-panel-1.0.2/root/usr/share/perl5/site_perl/esmith/FormMagick/Panel/groupmembers.pm |
2 |
|
|
--- smeserver-groupmembers-panel-1.0.2.old/root/usr/share/perl5/site_perl/esmith/FormMagick/Panel/groupmembers.pm 2014-06-16 11:54:48.000000000 -0400 |
3 |
|
|
+++ smeserver-groupmembers-panel-1.0.2/root/usr/share/perl5/site_perl/esmith/FormMagick/Panel/groupmembers.pm 1969-12-31 19:00:00.000000000 -0500 |
4 |
|
|
@@ -1,307 +0,0 @@ |
5 |
|
|
-#!/usr/bin/perl -w |
6 |
|
|
- |
7 |
|
|
- |
8 |
|
|
-package esmith::FormMagick::Panel::groupmembers; |
9 |
|
|
- |
10 |
|
|
-use strict; |
11 |
|
|
- |
12 |
|
|
-use esmith::FormMagick; |
13 |
|
|
-use esmith::ConfigDB; |
14 |
|
|
-use esmith::AccountsDB; |
15 |
|
|
-use File::Basename; |
16 |
|
|
-use Exporter; |
17 |
|
|
-use Carp; |
18 |
|
|
- |
19 |
|
|
-our @ISA = qw(esmith::FormMagick Exporter); |
20 |
|
|
- |
21 |
|
|
-our @EXPORT = qw( |
22 |
|
|
- |
23 |
|
|
- show_initial |
24 |
|
|
- genUsers |
25 |
|
|
- modify_group |
26 |
|
|
- get_accounts_prop |
27 |
|
|
- get_description |
28 |
|
|
- get_cgi_param |
29 |
|
|
-); |
30 |
|
|
- |
31 |
|
|
-our $accounts = esmith::AccountsDB->open() || die "Couldn't open accounts"; |
32 |
|
|
-our $db = esmith::ConfigDB->open || die "Couldn't open config db"; |
33 |
|
|
- |
34 |
|
|
-our $VERSION = sprintf '%d.%03d', q$Revision: 1.38 $ =~ /: (\d+).(\d+)/; |
35 |
|
|
- |
36 |
|
|
- |
37 |
|
|
- |
38 |
|
|
-=pod |
39 |
|
|
- |
40 |
|
|
-=head1 NAME |
41 |
|
|
- |
42 |
|
|
-esmith::FormMagick::Panels::groups - useful panel functions |
43 |
|
|
- |
44 |
|
|
-=head1 SYNOPSIS |
45 |
|
|
- |
46 |
|
|
- use esmith::FormMagick::Panels::groups; |
47 |
|
|
- |
48 |
|
|
- my $panel = esmith::FormMagick::Panel::groups->new(); |
49 |
|
|
- $panel->display(); |
50 |
|
|
- |
51 |
|
|
-=head1 DESCRIPTION |
52 |
|
|
- |
53 |
|
|
-=cut |
54 |
|
|
- |
55 |
|
|
- |
56 |
|
|
-=head2 new(); |
57 |
|
|
- |
58 |
|
|
-Exactly as for esmith::FormMagick |
59 |
|
|
- |
60 |
|
|
-=begin testing |
61 |
|
|
- |
62 |
|
|
-$ENV{ESMITH_ACCOUNT_DB} = "10e-smith-base/accounts.conf"; |
63 |
|
|
-$ENV{ESMITH_CONFIG_DB} = "10e-smith-base/configuration.conf"; |
64 |
|
|
- |
65 |
|
|
-use_ok('esmith::FormMagick::Panel::groups'); |
66 |
|
|
-use vars qw($panel); |
67 |
|
|
-ok($panel = esmith::FormMagick::Panel::groups->new(), "Create panel object"); |
68 |
|
|
-isa_ok($panel, 'esmith::FormMagick::Panel::groups'); |
69 |
|
|
- |
70 |
|
|
-=end testing |
71 |
|
|
- |
72 |
|
|
-=cut |
73 |
|
|
- |
74 |
|
|
-sub new { |
75 |
|
|
- shift; |
76 |
|
|
- my $self = esmith::FormMagick->new(); |
77 |
|
|
- $self->{calling_package} = (caller)[0]; |
78 |
|
|
- bless $self; |
79 |
|
|
- return $self; |
80 |
|
|
-} |
81 |
|
|
- |
82 |
|
|
- |
83 |
|
|
-=head1 ACCESSORS |
84 |
|
|
- |
85 |
|
|
-=head2 get_cgi_param FM FIELD |
86 |
|
|
- |
87 |
|
|
-Returns the named CGI parameter as a string |
88 |
|
|
- |
89 |
|
|
-=cut |
90 |
|
|
- |
91 |
|
|
-sub get_cgi_param { |
92 |
|
|
- my $fm = shift; |
93 |
|
|
- my $param = shift; |
94 |
|
|
- |
95 |
|
|
- return ( $fm->{'cgi'}->param($param) ); |
96 |
|
|
-} |
97 |
|
|
- |
98 |
|
|
- |
99 |
|
|
-=head2 get_accounts_prop ITEM PROP |
100 |
|
|
- |
101 |
|
|
-A simple accessor for esmith::ConfigDB::Record::prop |
102 |
|
|
- |
103 |
|
|
-=cut |
104 |
|
|
- |
105 |
|
|
-sub get_accounts_prop { |
106 |
|
|
- my $fm = shift; |
107 |
|
|
- my $item = shift; |
108 |
|
|
- my $prop = shift; |
109 |
|
|
- |
110 |
|
|
- my $record = $accounts->get($item); |
111 |
|
|
- |
112 |
|
|
- if ($record) { |
113 |
|
|
- return $record->prop($prop); |
114 |
|
|
- } |
115 |
|
|
- else { |
116 |
|
|
- return ''; |
117 |
|
|
- } |
118 |
|
|
- |
119 |
|
|
-} |
120 |
|
|
- |
121 |
|
|
- |
122 |
|
|
-=head2 get_description |
123 |
|
|
- |
124 |
|
|
-Get the Description for the group named in the CGI argument "GroupName" |
125 |
|
|
- |
126 |
|
|
-=cut |
127 |
|
|
- |
128 |
|
|
-sub get_description { |
129 |
|
|
- my $fm = shift; |
130 |
|
|
- my $group = $fm->{'cgi'}->param('groupName'); |
131 |
|
|
- return ( $fm->get_accounts_prop( $group, 'Description' ) ); |
132 |
|
|
-} |
133 |
|
|
- |
134 |
|
|
-=head1 ACTION |
135 |
|
|
- |
136 |
|
|
- |
137 |
|
|
-=head2 show_initial FM |
138 |
|
|
- |
139 |
|
|
-Show the "start" page for this panel |
140 |
|
|
- |
141 |
|
|
-=cut |
142 |
|
|
- |
143 |
|
|
-sub show_initial () { |
144 |
|
|
- my $fm = shift; |
145 |
|
|
- my $q = $fm->{cgi}; |
146 |
|
|
- |
147 |
|
|
- my $UserName = $ENV{'REMOTE_USER'} ||''; |
148 |
|
|
- my $record = $accounts->get($UserName); |
149 |
|
|
- my $dg=$record->prop('delegatedGroups')||''; |
150 |
|
|
- $dg =~ s/ //g; |
151 |
|
|
- my @g = split(/,/, $dg); |
152 |
|
|
- my %delegatedGroups; |
153 |
|
|
- foreach my $k ( @g ) |
154 |
|
|
- { |
155 |
|
|
- $delegatedGroups{$k}=1; |
156 |
|
|
- } |
157 |
|
|
- |
158 |
|
|
- $q->Delete('groupName'); |
159 |
|
|
- |
160 |
|
|
- my $params = $fm->build_cgi_params(); |
161 |
|
|
- |
162 |
|
|
- my $numGroups = $accounts->groups; |
163 |
|
|
- |
164 |
|
|
- if ( $numGroups == 0 ) { |
165 |
|
|
- print $q->Tr($q->td( |
166 |
|
|
- '<p><b>' . $fm->localise("NO_GROUPS") . '</p></b>')); |
167 |
|
|
- |
168 |
|
|
- } |
169 |
|
|
- else { |
170 |
|
|
- print "<tr><th class=\"sme-border\">" |
171 |
|
|
- . $fm->localise("GROUP") |
172 |
|
|
- . "</th> <th class=\"sme-border\">" |
173 |
|
|
- . $fm->localise('DESCRIPTION') |
174 |
|
|
- . "</th><th class=\"sme-border\" colspan=\"2\">" |
175 |
|
|
- . $fm->localise('ACTION') |
176 |
|
|
- . "</th></tr>"; |
177 |
|
|
- foreach my $group ( $accounts->groups() ) { |
178 |
|
|
- next if %delegatedGroups and not $delegatedGroups{$group->key}; |
179 |
|
|
- $params = $fm->build_cgi_params( $group->key ); |
180 |
|
|
- print "<tr>" . "<td class=\"sme-border\">" |
181 |
|
|
- . $group->key . "</td>" . "<td class=\"sme-border\">" |
182 |
|
|
- . $group->prop('Description') . "</td>" |
183 |
|
|
- . "<td class=\"sme-border\"><a href=\"groupmembers?$params&wherenext=Modify\">" |
184 |
|
|
- . $fm->localise("MODIFY") . "</a></td>" |
185 |
|
|
- . "</tr>"; |
186 |
|
|
- |
187 |
|
|
- } |
188 |
|
|
- print $q->end_table,"\n"; |
189 |
|
|
- } |
190 |
|
|
- return; |
191 |
|
|
-} |
192 |
|
|
- |
193 |
|
|
- |
194 |
|
|
-=head2 modify_group FM |
195 |
|
|
- |
196 |
|
|
-Modify a group's description and membership roster |
197 |
|
|
- |
198 |
|
|
-=cut |
199 |
|
|
- |
200 |
|
|
-sub modify_group { |
201 |
|
|
- |
202 |
|
|
- my $fm = shift; |
203 |
|
|
- my $q = $fm->{'cgi'}; |
204 |
|
|
- |
205 |
|
|
- my @members = $q->param('groupMembers'); |
206 |
|
|
- my $groupName = $q->param('groupName'); |
207 |
|
|
- |
208 |
|
|
- $accounts->get($groupName)->set_prop( 'Members', join ( ',', @members ) ); |
209 |
|
|
- |
210 |
|
|
- # Untaint groupName before use in system() |
211 |
|
|
- ($groupName) = ($groupName =~ /^([a-z][\-\_\.a-z0-9]*)$/); |
212 |
|
|
- $fm->clear_params(); |
213 |
|
|
- return system("/sbin/e-smith/signal-event", "group-modify", "$groupName") ? |
214 |
|
|
- $fm->error('MODIFY_ERROR') : $fm->success('MODIFIED_GROUP'); |
215 |
|
|
-} |
216 |
|
|
- |
217 |
|
|
- |
218 |
|
|
-=head1 UTILITY FUNCTIONS |
219 |
|
|
- |
220 |
|
|
-=head2 build_cgi_params() |
221 |
|
|
- |
222 |
|
|
-Builds a CGI query string, using various sensible |
223 |
|
|
-defaults and esmith::FormMagick's props_to_query_string() method. |
224 |
|
|
- |
225 |
|
|
-=cut |
226 |
|
|
- |
227 |
|
|
-sub build_cgi_params { |
228 |
|
|
- my ( $fm, $group ) = @_; |
229 |
|
|
- |
230 |
|
|
- my %props = ( |
231 |
|
|
- page => 0, |
232 |
|
|
- page_stack => "", |
233 |
|
|
- ".id" => $fm->{cgi}->param('.id') || "", |
234 |
|
|
- groupName => $group, |
235 |
|
|
- ); |
236 |
|
|
- |
237 |
|
|
- return $fm->props_to_query_string( \%props ); |
238 |
|
|
-} |
239 |
|
|
- |
240 |
|
|
-=head2 genUsers MEMBERS |
241 |
|
|
- |
242 |
|
|
-Takes a comma delimited list of users and returns a string of |
243 |
|
|
-html checkboxes for all system users with the members of the group |
244 |
|
|
-in $fm->{cgi}->parm('groupName')checked. |
245 |
|
|
- |
246 |
|
|
-=cut |
247 |
|
|
- |
248 |
|
|
-sub genUsers () { |
249 |
|
|
- my $fm = shift; |
250 |
|
|
- my $members = ""; |
251 |
|
|
- my $group = $fm->{'cgi'}->param('groupName'); |
252 |
|
|
- |
253 |
|
|
- if ($accounts->get($group)) { |
254 |
|
|
- $members = $accounts->get($group)->prop('Members'); |
255 |
|
|
- } |
256 |
|
|
- my %members; |
257 |
|
|
- foreach my $member ( split ( /,/, $members ) ) { |
258 |
|
|
- $members{$member} = 1; |
259 |
|
|
- } |
260 |
|
|
- my @users = sort { $a->key() cmp $b->key() } $accounts->users(); |
261 |
|
|
- |
262 |
|
|
- # include Administrator at beginning of list |
263 |
|
|
- |
264 |
|
|
- my $out = "<tr>\n <td class=\"sme-noborders-label\">" |
265 |
|
|
- . $fm->localise('GROUP_MEMBERS') |
266 |
|
|
- . "</td>\n <td>\n" |
267 |
|
|
- . " <table border='0' cellspacing='0' cellpadding='0'>\n" |
268 |
|
|
- . " <tr>\n" |
269 |
|
|
- . " <td><input type=\"checkbox\" name=\"groupMembers\""; |
270 |
|
|
- if ( $members{'admin'} ) { |
271 |
|
|
- $out .= "checked"; |
272 |
|
|
- } |
273 |
|
|
- $out .= " value=\"admin\"></td>\n <td>Administrator (admin)</td>\n </tr>\n"; |
274 |
|
|
- foreach my $user (@users) { |
275 |
|
|
- my $checked = ""; |
276 |
|
|
- if ( $members{ $user->key() } ) { |
277 |
|
|
- $checked = "checked"; |
278 |
|
|
- } |
279 |
|
|
- my $name; |
280 |
|
|
- if ( $user eq 'admin' ) { $name = 'Administrator'; } |
281 |
|
|
- else { |
282 |
|
|
- $name = $user->prop('FirstName') . " " . $user->prop('LastName'); |
283 |
|
|
- } |
284 |
|
|
- |
285 |
|
|
- $out .=" <tr>\n" |
286 |
|
|
- . " <td><input type=\"checkbox\" name=\"groupMembers\" $checked value=\"" |
287 |
|
|
- . $user->key |
288 |
|
|
- . "\"></td>\n <td>$name (".$user->key.")</td>\n </tr>\n"; |
289 |
|
|
- |
290 |
|
|
- } |
291 |
|
|
- |
292 |
|
|
- $out .= " </table>\n </td>\n </tr>\n"; |
293 |
|
|
- return $out; |
294 |
|
|
-} |
295 |
|
|
- |
296 |
|
|
-=head2 clear_params |
297 |
|
|
- |
298 |
|
|
-This method clears-out the parameters used in form submission so that they are |
299 |
|
|
-not inadvertenly picked-up where they should not be. |
300 |
|
|
- |
301 |
|
|
-=cut |
302 |
|
|
- |
303 |
|
|
-sub clear_params |
304 |
|
|
-{ |
305 |
|
|
- my $self = shift; |
306 |
|
|
- my $q = $self->{cgi}; |
307 |
|
|
- |
308 |
|
|
- $q->delete('groupMembers'); |
309 |
|
|
- $q->delete('groupDesc'); |
310 |
|
|
- $q->delete('groupName'); |
311 |
|
|
-} |
312 |
|
|
diff -Nur smeserver-groupmembers-panel-1.0.2.old/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/groupmembers.pm smeserver-groupmembers-panel-1.0.2/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/groupmembers.pm |
313 |
|
|
--- smeserver-groupmembers-panel-1.0.2.old/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/groupmembers.pm 1969-12-31 19:00:00.000000000 -0500 |
314 |
|
|
+++ smeserver-groupmembers-panel-1.0.2/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/groupmembers.pm 2014-06-16 11:54:48.000000000 -0400 |
315 |
|
|
@@ -0,0 +1,307 @@ |
316 |
|
|
+#!/usr/bin/perl -w |
317 |
|
|
+ |
318 |
|
|
+ |
319 |
|
|
+package esmith::FormMagick::Panel::groupmembers; |
320 |
|
|
+ |
321 |
|
|
+use strict; |
322 |
|
|
+ |
323 |
|
|
+use esmith::FormMagick; |
324 |
|
|
+use esmith::ConfigDB; |
325 |
|
|
+use esmith::AccountsDB; |
326 |
|
|
+use File::Basename; |
327 |
|
|
+use Exporter; |
328 |
|
|
+use Carp; |
329 |
|
|
+ |
330 |
|
|
+our @ISA = qw(esmith::FormMagick Exporter); |
331 |
|
|
+ |
332 |
|
|
+our @EXPORT = qw( |
333 |
|
|
+ |
334 |
|
|
+ show_initial |
335 |
|
|
+ genUsers |
336 |
|
|
+ modify_group |
337 |
|
|
+ get_accounts_prop |
338 |
|
|
+ get_description |
339 |
|
|
+ get_cgi_param |
340 |
|
|
+); |
341 |
|
|
+ |
342 |
|
|
+our $accounts = esmith::AccountsDB->open() || die "Couldn't open accounts"; |
343 |
|
|
+our $db = esmith::ConfigDB->open || die "Couldn't open config db"; |
344 |
|
|
+ |
345 |
|
|
+our $VERSION = sprintf '%d.%03d', q$Revision: 1.38 $ =~ /: (\d+).(\d+)/; |
346 |
|
|
+ |
347 |
|
|
+ |
348 |
|
|
+ |
349 |
|
|
+=pod |
350 |
|
|
+ |
351 |
|
|
+=head1 NAME |
352 |
|
|
+ |
353 |
|
|
+esmith::FormMagick::Panels::groups - useful panel functions |
354 |
|
|
+ |
355 |
|
|
+=head1 SYNOPSIS |
356 |
|
|
+ |
357 |
|
|
+ use esmith::FormMagick::Panels::groups; |
358 |
|
|
+ |
359 |
|
|
+ my $panel = esmith::FormMagick::Panel::groups->new(); |
360 |
|
|
+ $panel->display(); |
361 |
|
|
+ |
362 |
|
|
+=head1 DESCRIPTION |
363 |
|
|
+ |
364 |
|
|
+=cut |
365 |
|
|
+ |
366 |
|
|
+ |
367 |
|
|
+=head2 new(); |
368 |
|
|
+ |
369 |
|
|
+Exactly as for esmith::FormMagick |
370 |
|
|
+ |
371 |
|
|
+=begin testing |
372 |
|
|
+ |
373 |
|
|
+$ENV{ESMITH_ACCOUNT_DB} = "10e-smith-base/accounts.conf"; |
374 |
|
|
+$ENV{ESMITH_CONFIG_DB} = "10e-smith-base/configuration.conf"; |
375 |
|
|
+ |
376 |
|
|
+use_ok('esmith::FormMagick::Panel::groups'); |
377 |
|
|
+use vars qw($panel); |
378 |
|
|
+ok($panel = esmith::FormMagick::Panel::groups->new(), "Create panel object"); |
379 |
|
|
+isa_ok($panel, 'esmith::FormMagick::Panel::groups'); |
380 |
|
|
+ |
381 |
|
|
+=end testing |
382 |
|
|
+ |
383 |
|
|
+=cut |
384 |
|
|
+ |
385 |
|
|
+sub new { |
386 |
|
|
+ shift; |
387 |
|
|
+ my $self = esmith::FormMagick->new(); |
388 |
|
|
+ $self->{calling_package} = (caller)[0]; |
389 |
|
|
+ bless $self; |
390 |
|
|
+ return $self; |
391 |
|
|
+} |
392 |
|
|
+ |
393 |
|
|
+ |
394 |
|
|
+=head1 ACCESSORS |
395 |
|
|
+ |
396 |
|
|
+=head2 get_cgi_param FM FIELD |
397 |
|
|
+ |
398 |
|
|
+Returns the named CGI parameter as a string |
399 |
|
|
+ |
400 |
|
|
+=cut |
401 |
|
|
+ |
402 |
|
|
+sub get_cgi_param { |
403 |
|
|
+ my $fm = shift; |
404 |
|
|
+ my $param = shift; |
405 |
|
|
+ |
406 |
|
|
+ return ( $fm->{'cgi'}->param($param) ); |
407 |
|
|
+} |
408 |
|
|
+ |
409 |
|
|
+ |
410 |
|
|
+=head2 get_accounts_prop ITEM PROP |
411 |
|
|
+ |
412 |
|
|
+A simple accessor for esmith::ConfigDB::Record::prop |
413 |
|
|
+ |
414 |
|
|
+=cut |
415 |
|
|
+ |
416 |
|
|
+sub get_accounts_prop { |
417 |
|
|
+ my $fm = shift; |
418 |
|
|
+ my $item = shift; |
419 |
|
|
+ my $prop = shift; |
420 |
|
|
+ |
421 |
|
|
+ my $record = $accounts->get($item); |
422 |
|
|
+ |
423 |
|
|
+ if ($record) { |
424 |
|
|
+ return $record->prop($prop); |
425 |
|
|
+ } |
426 |
|
|
+ else { |
427 |
|
|
+ return ''; |
428 |
|
|
+ } |
429 |
|
|
+ |
430 |
|
|
+} |
431 |
|
|
+ |
432 |
|
|
+ |
433 |
|
|
+=head2 get_description |
434 |
|
|
+ |
435 |
|
|
+Get the Description for the group named in the CGI argument "GroupName" |
436 |
|
|
+ |
437 |
|
|
+=cut |
438 |
|
|
+ |
439 |
|
|
+sub get_description { |
440 |
|
|
+ my $fm = shift; |
441 |
|
|
+ my $group = $fm->{'cgi'}->param('groupName'); |
442 |
|
|
+ return ( $fm->get_accounts_prop( $group, 'Description' ) ); |
443 |
|
|
+} |
444 |
|
|
+ |
445 |
|
|
+=head1 ACTION |
446 |
|
|
+ |
447 |
|
|
+ |
448 |
|
|
+=head2 show_initial FM |
449 |
|
|
+ |
450 |
|
|
+Show the "start" page for this panel |
451 |
|
|
+ |
452 |
|
|
+=cut |
453 |
|
|
+ |
454 |
|
|
+sub show_initial () { |
455 |
|
|
+ my $fm = shift; |
456 |
|
|
+ my $q = $fm->{cgi}; |
457 |
|
|
+ |
458 |
|
|
+ my $UserName = $ENV{'REMOTE_USER'} ||''; |
459 |
|
|
+ my $record = $accounts->get($UserName); |
460 |
|
|
+ my $dg=$record->prop('delegatedGroups')||''; |
461 |
|
|
+ $dg =~ s/ //g; |
462 |
|
|
+ my @g = split(/,/, $dg); |
463 |
|
|
+ my %delegatedGroups; |
464 |
|
|
+ foreach my $k ( @g ) |
465 |
|
|
+ { |
466 |
|
|
+ $delegatedGroups{$k}=1; |
467 |
|
|
+ } |
468 |
|
|
+ |
469 |
|
|
+ $q->Delete('groupName'); |
470 |
|
|
+ |
471 |
|
|
+ my $params = $fm->build_cgi_params(); |
472 |
|
|
+ |
473 |
|
|
+ my $numGroups = $accounts->groups; |
474 |
|
|
+ |
475 |
|
|
+ if ( $numGroups == 0 ) { |
476 |
|
|
+ print $q->Tr($q->td( |
477 |
|
|
+ '<p><b>' . $fm->localise("NO_GROUPS") . '</p></b>')); |
478 |
|
|
+ |
479 |
|
|
+ } |
480 |
|
|
+ else { |
481 |
|
|
+ print "<tr><th class=\"sme-border\">" |
482 |
|
|
+ . $fm->localise("GROUP") |
483 |
|
|
+ . "</th> <th class=\"sme-border\">" |
484 |
|
|
+ . $fm->localise('DESCRIPTION') |
485 |
|
|
+ . "</th><th class=\"sme-border\" colspan=\"2\">" |
486 |
|
|
+ . $fm->localise('ACTION') |
487 |
|
|
+ . "</th></tr>"; |
488 |
|
|
+ foreach my $group ( $accounts->groups() ) { |
489 |
|
|
+ next if %delegatedGroups and not $delegatedGroups{$group->key}; |
490 |
|
|
+ $params = $fm->build_cgi_params( $group->key ); |
491 |
|
|
+ print "<tr>" . "<td class=\"sme-border\">" |
492 |
|
|
+ . $group->key . "</td>" . "<td class=\"sme-border\">" |
493 |
|
|
+ . $group->prop('Description') . "</td>" |
494 |
|
|
+ . "<td class=\"sme-border\"><a href=\"groupmembers?$params&wherenext=Modify\">" |
495 |
|
|
+ . $fm->localise("MODIFY") . "</a></td>" |
496 |
|
|
+ . "</tr>"; |
497 |
|
|
+ |
498 |
|
|
+ } |
499 |
|
|
+ print $q->end_table,"\n"; |
500 |
|
|
+ } |
501 |
|
|
+ return; |
502 |
|
|
+} |
503 |
|
|
+ |
504 |
|
|
+ |
505 |
|
|
+=head2 modify_group FM |
506 |
|
|
+ |
507 |
|
|
+Modify a group's description and membership roster |
508 |
|
|
+ |
509 |
|
|
+=cut |
510 |
|
|
+ |
511 |
|
|
+sub modify_group { |
512 |
|
|
+ |
513 |
|
|
+ my $fm = shift; |
514 |
|
|
+ my $q = $fm->{'cgi'}; |
515 |
|
|
+ |
516 |
|
|
+ my @members = $q->param('groupMembers'); |
517 |
|
|
+ my $groupName = $q->param('groupName'); |
518 |
|
|
+ |
519 |
|
|
+ $accounts->get($groupName)->set_prop( 'Members', join ( ',', @members ) ); |
520 |
|
|
+ |
521 |
|
|
+ # Untaint groupName before use in system() |
522 |
|
|
+ ($groupName) = ($groupName =~ /^([a-z][\-\_\.a-z0-9]*)$/); |
523 |
|
|
+ $fm->clear_params(); |
524 |
|
|
+ return system("/sbin/e-smith/signal-event", "group-modify", "$groupName") ? |
525 |
|
|
+ $fm->error('MODIFY_ERROR') : $fm->success('MODIFIED_GROUP'); |
526 |
|
|
+} |
527 |
|
|
+ |
528 |
|
|
+ |
529 |
|
|
+=head1 UTILITY FUNCTIONS |
530 |
|
|
+ |
531 |
|
|
+=head2 build_cgi_params() |
532 |
|
|
+ |
533 |
|
|
+Builds a CGI query string, using various sensible |
534 |
|
|
+defaults and esmith::FormMagick's props_to_query_string() method. |
535 |
|
|
+ |
536 |
|
|
+=cut |
537 |
|
|
+ |
538 |
|
|
+sub build_cgi_params { |
539 |
|
|
+ my ( $fm, $group ) = @_; |
540 |
|
|
+ |
541 |
|
|
+ my %props = ( |
542 |
|
|
+ page => 0, |
543 |
|
|
+ page_stack => "", |
544 |
|
|
+ ".id" => $fm->{cgi}->param('.id') || "", |
545 |
|
|
+ groupName => $group, |
546 |
|
|
+ ); |
547 |
|
|
+ |
548 |
|
|
+ return $fm->props_to_query_string( \%props ); |
549 |
|
|
+} |
550 |
|
|
+ |
551 |
|
|
+=head2 genUsers MEMBERS |
552 |
|
|
+ |
553 |
|
|
+Takes a comma delimited list of users and returns a string of |
554 |
|
|
+html checkboxes for all system users with the members of the group |
555 |
|
|
+in $fm->{cgi}->parm('groupName')checked. |
556 |
|
|
+ |
557 |
|
|
+=cut |
558 |
|
|
+ |
559 |
|
|
+sub genUsers () { |
560 |
|
|
+ my $fm = shift; |
561 |
|
|
+ my $members = ""; |
562 |
|
|
+ my $group = $fm->{'cgi'}->param('groupName'); |
563 |
|
|
+ |
564 |
|
|
+ if ($accounts->get($group)) { |
565 |
|
|
+ $members = $accounts->get($group)->prop('Members'); |
566 |
|
|
+ } |
567 |
|
|
+ my %members; |
568 |
|
|
+ foreach my $member ( split ( /,/, $members ) ) { |
569 |
|
|
+ $members{$member} = 1; |
570 |
|
|
+ } |
571 |
|
|
+ my @users = sort { $a->key() cmp $b->key() } $accounts->users(); |
572 |
|
|
+ |
573 |
|
|
+ # include Administrator at beginning of list |
574 |
|
|
+ |
575 |
|
|
+ my $out = "<tr>\n <td class=\"sme-noborders-label\">" |
576 |
|
|
+ . $fm->localise('GROUP_MEMBERS') |
577 |
|
|
+ . "</td>\n <td>\n" |
578 |
|
|
+ . " <table border='0' cellspacing='0' cellpadding='0'>\n" |
579 |
|
|
+ . " <tr>\n" |
580 |
|
|
+ . " <td><input type=\"checkbox\" name=\"groupMembers\""; |
581 |
|
|
+ if ( $members{'admin'} ) { |
582 |
|
|
+ $out .= "checked"; |
583 |
|
|
+ } |
584 |
|
|
+ $out .= " value=\"admin\"></td>\n <td>Administrator (admin)</td>\n </tr>\n"; |
585 |
|
|
+ foreach my $user (@users) { |
586 |
|
|
+ my $checked = ""; |
587 |
|
|
+ if ( $members{ $user->key() } ) { |
588 |
|
|
+ $checked = "checked"; |
589 |
|
|
+ } |
590 |
|
|
+ my $name; |
591 |
|
|
+ if ( $user eq 'admin' ) { $name = 'Administrator'; } |
592 |
|
|
+ else { |
593 |
|
|
+ $name = $user->prop('FirstName') . " " . $user->prop('LastName'); |
594 |
|
|
+ } |
595 |
|
|
+ |
596 |
|
|
+ $out .=" <tr>\n" |
597 |
|
|
+ . " <td><input type=\"checkbox\" name=\"groupMembers\" $checked value=\"" |
598 |
|
|
+ . $user->key |
599 |
|
|
+ . "\"></td>\n <td>$name (".$user->key.")</td>\n </tr>\n"; |
600 |
|
|
+ |
601 |
|
|
+ } |
602 |
|
|
+ |
603 |
|
|
+ $out .= " </table>\n </td>\n </tr>\n"; |
604 |
|
|
+ return $out; |
605 |
|
|
+} |
606 |
|
|
+ |
607 |
|
|
+=head2 clear_params |
608 |
|
|
+ |
609 |
|
|
+This method clears-out the parameters used in form submission so that they are |
610 |
|
|
+not inadvertenly picked-up where they should not be. |
611 |
|
|
+ |
612 |
|
|
+=cut |
613 |
|
|
+ |
614 |
|
|
+sub clear_params |
615 |
|
|
+{ |
616 |
|
|
+ my $self = shift; |
617 |
|
|
+ my $q = $self->{cgi}; |
618 |
|
|
+ |
619 |
|
|
+ $q->delete('groupMembers'); |
620 |
|
|
+ $q->delete('groupDesc'); |
621 |
|
|
+ $q->delete('groupName'); |
622 |
|
|
+} |