Handle hostnames with upper-case letters
[webmin.git] / cluster-usermin / edit_acl.cgi
1 #!/usr/local/bin/perl
2 # edit_acl.cgi
3 # Display a form for editing the ACL for some module for some user or group
4
5 require './cluster-usermin-lib.pl';
6 &ReadParse();
7
8 # Get hosts and module details
9 @hosts = &list_webmin_hosts();
10 if ($in{'whohost'} =~ /^(\d+),(\S*)$/) {
11         # Coming from the module page, so know which host to look at
12         ($host) = grep { $_->{'id'} == $1 } @hosts;
13         local ($u) = grep { $_->{'name'} eq $2 } @{$host->{'users'}};
14         local ($g) = grep { $_->{'name'} eq $2 } @{$host->{'groups'}};
15         $user = $u if ($u);
16         $group = $g if ($g);
17         ($mod) = grep { $_->{'dir'} eq $in{'mod'} } @{$host->{'modules'}};
18         }
19 elsif ($in{'modhost'} =~ /^(\d+),(\S*)$/) {
20         # Coming from the user or group page, so know which host to look at
21         ($host) = grep { $_->{'id'} == $1 } @hosts;
22         ($mod) = grep { $_->{'dir'} eq $2 } @{$host->{'modules'}};
23         if ($in{'user'}) {
24                 ($user) = grep { $_->{'name'} eq $in{'user'} } @{$host->{'users'}};
25                 }
26         else {
27                 ($group) = grep { $_->{'name'} eq $in{'group'} } @{$host->{'groups'}};
28                 }
29         }
30 else {
31         # Find a host that has the user and module
32         foreach $h (sort { $a->{'id'} <=> $b->{'id'} } @hosts) {
33                 local ($m) = grep { $_->{'dir'} eq $in{'mod'} } @{$h->{'modules'}};
34                 if ($in{'user'}) {
35                         local ($u) = grep { $_->{'name'} eq $in{'user'} }
36                                           @{$h->{'users'}};
37                         if ($u && (&indexof($in{'mod'}, @{$u->{'modules'}}) >= 0 ||
38                                    !$in{'mod'})) {
39                                 $user = $u;
40                                 $host = $h;
41                                 $mod = $m;
42                                 last;
43                                 }
44                         }
45                 else {
46                         local ($g) = grep { $_->{'name'} eq $in{'group'} }
47                                           @{$h->{'groups'}};
48                         if ($g && (&indexof($in{'mod'}, @{$g->{'modules'}}) >= 0 ||
49                                    !$in{'mod'})) {
50                                 $group = $g;
51                                 $host = $h;
52                                 $mod = $m;
53                                 last;
54                                 }
55                         }
56                 }
57         $host || &error(&text('acl_efound',
58                         $in{'user'} ? $in{'user'} : $in{'group'}, $in{'mod'}));
59         }
60 $who = $user ? $user->{'name'} : $group->{'name'};
61 @servers = &list_servers();
62 ($serv) = grep { $_->{'id'} == $host->{'id'} } @servers;
63 $d = &server_name($serv);
64
65 $ga = "_ga" if (!$mod->{'dir'});
66 $desc = &text($user ? 'acl_title2'.$ga : 'acl_title3'.$ga,
67                 "<b>$who</b>", "<b>$mod->{'desc'}</b>", "<b>$d</b>");
68 &ui_print_header($desc, $text{'acl_title'}, "");
69
70 # Get the host's ACL options
71 &remote_foreign_require($serv->{'host'}, "acl", "acl-lib.pl");
72 $aref = &remote_eval($serv->{'host'}, "acl", "\%rv = &get_module_acl('$who', '$mod->{'dir'}'); \\%rv");
73 %access = %$aref;
74
75 # Display the editor form from this host
76 print "<form method=post action=save_acl.cgi>\n";
77 print "<input type=hidden name=_acl_mod value='$mod->{'dir'}'>\n";
78 print "<input type=hidden name=_acl_host value='$host->{'id'}'>\n";
79 if ($in{'group'}) {
80         print "<input type=hidden name=_acl_group value='$group->{'name'}'>\n";
81         }
82 else {
83         print "<input type=hidden name=_acl_user value='$user->{'name'}'>\n";
84         }
85 print "<table border width=100%>\n";
86 print "<tr $tb> <td><b>",
87         $mod->{'dir'} ? &text('acl_options', $mod->{'desc'}, &server_name($serv))
88                       : &text('acl_optionsg', &server_name($serv)),
89       "</b></td> </tr>\n";
90 print "<tr $cb> <td><table width=100%>\n";
91
92 if ($mod->{'dir'}) {
93         print "<tr> <td><b>$text{'acl_config'}</b></td> <td>\n";
94         printf "<input type=radio name=noconfig value=0 %s> $text{'yes'}\n",
95                 $access{'noconfig'} ? "" : "checked";
96         printf "<input type=radio name=noconfig value=1 %s> $text{'no'}</td>\n",
97                 $access{'noconfig'} ? "checked" : "";
98         print "<td width=50% colspan=2></td> </tr>\n";
99         }
100
101 $mdir = &module_root_directory($mod->{'dir'});
102 if (!&foreign_exists($mod->{'dir'})) {
103         # This server doesn't have the module .. use text editor
104         print "<tr> <td colspan=4><hr></td> </tr>\n" if ($mod->{'dir'});
105         print "<tr> <td colspan=4><b>$text{'acl_raw'}</b><br>\n";
106         print "<textarea rows=10 cols=70 name=_acl_raw>\n";
107         foreach $k (sort { $a cmp $b } keys %access) {
108                 print "$k=$access{$k}\n";
109                 }
110         print "</textarea></td> </tr>\n";
111         }
112 elsif (-r "$mdir/acl_security.pl") {
113         print "<tr> <td colspan=4><hr></td> </tr>\n" if ($mod->{'dir'});
114         &foreign_require($mod->{'dir'}, "acl_security.pl");
115         &foreign_call($mod->{'dir'}, "acl_security_form", \%access);
116         }
117
118 print "</table></td></tr></table>\n";
119 print "<input type=submit name=all value='",&text('acl_save1'),"'>\n";
120 print "<input type=submit value='",&text('acl_save2', &server_name($serv)),"'>\n";
121 print "</form>\n";
122 &ui_print_footer("", $text{'index_return'});
123