Handle hostnames with upper-case letters
[webmin.git] / cluster-webmin / 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-webmin-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 if ($user) {
73         $aref = &remote_eval($serv->{'host'}, "acl",
74                 "\%rv = &get_module_acl('$who', '$mod->{'dir'}'); \\%rv");
75         }
76 else {
77         $aref = &remote_eval($serv->{'host'}, "acl",
78                 "\%rv = &get_group_module_acl('$who', '$mod->{'dir'}'); \\%rv");
79         }
80 %access = %$aref;
81
82 # Display the editor form from this host
83 print &ui_form_start("save_acl.cgi", "post");
84 print &ui_hidden("_acl_mod", $in{'mod'}),"\n";
85 print &ui_hidden("_acl_host", $in{'host'}),"\n";
86 if ($in{'group'}) {
87         print &ui_hidden("_acl_group", $who),"\n";
88         }
89 else {
90         print &ui_hidden("_acl_user", $who),"\n";
91         }
92 print &ui_table_start(
93     $mod->{'dir'} ? &text('acl_options', $mod->{'desc'}, &server_name($serv))
94                   : &text('acl_optionsg', &server_name($serv)),
95     "width=100%", 4);
96
97 if ($mod->{'dir'}) {
98         # Show module config editing option
99         print &ui_table_row($text{'acl_config'},
100                 &ui_radio("noconfig", $access{'noconfig'} ? 1 : 0,
101                         [ [ 0, $text{'yes'} ], [ 1, $text{'no'} ] ]), 3);
102         }
103
104 $mdir = &module_root_directory($mod->{'dir'});
105 if (!&foreign_exists($mod->{'dir'})) {
106         # This server doesn't have the module .. use text editor
107         print &ui_table_hr() if ($mod->{'dir'});
108         local $raw;
109         foreach $k (sort { $a cmp $b } keys %access) {
110                 $raw .= "$k=$access{$k}\n";
111                 }
112         print &ui_table_row($text{'acl_raw'},
113                             &ui_textarea("_acl_raw", $raw, 10, 70));
114         }
115 elsif (-r "$mdir/acl_security.pl") {
116         # Show the module's ACL editor
117         print &ui_table_hr() if ($mod->{'dir'});
118         &foreign_require($mod->{'dir'}, "acl_security.pl");
119         &foreign_call($mod->{'dir'}, "acl_security_form", \%access);
120         }
121
122 print &ui_table_end();
123 print "<input type=submit name=all value='",&text('acl_save1'),"'>\n";
124 print "<input type=submit value='",&text('acl_save2', &server_name($serv)),"'>\n";
125 print &ui_form_end();
126 &ui_print_footer("", $text{'index_return'});
127