Handle hostnames with upper-case letters
[webmin.git] / cluster-webmin / edit_group.cgi
1 #!/usr/local/bin/perl
2 # edit_group.cgi
3 # Display an existing Webmin group for editing
4
5 require './cluster-webmin-lib.pl';
6 &ReadParse();
7 &ui_print_header(undef, $text{'group_title2'}, "");
8
9 @hosts = &list_webmin_hosts();
10 @mods = &all_modules(\@hosts);
11 @wgroups = &all_groups(\@hosts);
12 @servers = &list_servers();
13 if ($in{'host'} ne '') {
14         ($host) = grep { $_->{'id'} == $in{'host'} } @hosts;
15         ($edgrp) = grep { $_->{'name'} eq $in{'group'} } @{$host->{'groups'}};
16         }
17 else {
18         foreach $h (@hosts) {
19                 local ($g) =grep { $_->{'name'} eq $in{'group'} } @{$h->{'groups'}};
20                 if ($g) {
21                         $host = $h;
22                         $edgrp = $g;
23                         last;
24                         }
25                 }
26         }
27 ($serv) = grep { $_->{'id'} == $host->{'id'} } @servers;
28 foreach $h (@hosts) {
29         local ($g) = grep { $_->{'name'} eq $in{'group'} } @{$h->{'groups'}};
30         if ($g) {
31                 push(@got, grep { $_->{'id'} == $h->{'id'} } @servers);
32                 }
33         }
34
35 print "<form action=save_group.cgi method=post>\n";
36 print "<input type=hidden name=old value=\"$in{'group'}\">\n";
37 print "<input type=hidden name=host value=\"$host->{'id'}\">\n";
38 print "<table border width=100%>\n";
39 print "<tr $tb> <td><b>",&text('group_header2', &server_name($serv)),
40       "</b></td> </tr>\n";
41 print "<tr $cb> <td><table width=100%>\n";
42
43 print "<tr> <td><b>$text{'group_name'}</b></td>\n";
44 printf "<td><input name=name size=15 value='%s'></td> </tr>\n",
45         $edgrp->{'name'};
46
47 @gm = @{$edgrp->{'members'}};
48 print "<tr> <td><b>$text{'group_mems'}</b></td>\n";
49 print "<td>",@gm ? join(" ", @gm) : $text{'group_nomems'},"</td> </tr>\n";
50
51 foreach $g (@{$host->{'groups'}}) {
52         if (&indexof($edgrp->{'name'}, @{$g->{'members'}}) >= 0) {
53                 $group = $g;
54                 last;
55                 }
56         }
57 print "<tr> <td><b>$text{'group_group'}</b></td> <td>\n";
58 printf "<input type=radio name=group_def value=1 checked> %s (%s)\n",
59         $text{'user_leave'}, $group ? $group->{'name'} : $text{'user_nogroup2'};
60 printf "<input type=radio name=group_def value=0> %s\n",
61         $text{'user_set'};
62 print "<select name=group>\n";
63 print "<option selected value=''>$text{'user_nogroup'}\n";
64 foreach $g (@wgroups) {
65         print "<option>$g->{'name'}\n";
66         }
67 print "</select></td> </tr>\n";
68
69 $mp = int((scalar(@mods)+2)/3);
70 @umods = $group ? @{$edgrp->{'ownmods'}} : @{$edgrp->{'modules'}};
71 map { $umods{$_}++ } @umods;
72 print "<tr> <td valign=top><b>$text{'group_mods'}</b><br>",
73       "$text{'group_groupmods'}</td> <td nowrap>\n";
74 print "<input type=radio name=mods_def value=1 checked> ",
75         &text('user_mleave', scalar(@umods)),"<br>\n";
76 print "<input type=radio name=mods_def value=2> $text{'user_modsel'}\n";
77 print "<input type=radio name=mods_def value=3> $text{'user_modadd'}\n";
78 print "<input type=radio name=mods_def value=0> $text{'user_moddel'}\n";
79 print "<br>\n";
80 print "<select name=mods1 size=$mp multiple>\n";
81 for($i=0; $i<$mp; $i++) {
82         printf "<option value=%s %s>%s\n",
83                 $mods[$i]->{'dir'}, $umods{$mods[$i]->{'dir'}} ? "selected" : "",
84                 $mods[$i]->{'desc'};
85         }
86 print "</select>\n";
87 print "<select name=mods2 size=$mp multiple>\n";
88 for($i=$mp; $i<$mp*2; $i++) {
89         printf "<option value=%s %s>%s\n",
90                 $mods[$i]->{'dir'}, $umods{$mods[$i]->{'dir'}} ? "selected" : "",
91                 $mods[$i]->{'desc'};
92         }
93 print "</select>\n";
94 print "<select name=mods3 size=$mp multiple>\n";
95 for($i=$mp*2; $i<@mods; $i++) {
96         printf "<option value=%s %s>%s\n",
97                 $mods[$i]->{'dir'}, $umods{$mods[$i]->{'dir'}} ? "selected" : "",
98                 $mods[$i]->{'desc'};
99         }
100 print "</select>\n";
101
102 print "<br>\n";
103 print "<a href='' onClick='for(i=0; i<document.forms[0].mods1.options.length; i++) { document.forms[0].mods1.options[i].selected = true; } for(i=0; i<document.forms[0].mods2.options.length; i++) { document.forms[0].mods2.options[i].selected = true; } for(i=0; i<document.forms[0].mods3.options.length; i++) { document.forms[0].mods3.options[i].selected = true; } return false'>$text{'user_sall'}</a>&nbsp;\n";
104 print "<a href='' onClick='for(i=0; i<document.forms[0].mods1.options.length; i++) { document.forms[0].mods1.options[i].selected = false; } for(i=0; i<document.forms[0].mods2.options.length; i++) { document.forms[0].mods2.options[i].selected = false; } for(i=0; i<document.forms[0].mods3.options.length; i++) { document.forms[0].mods3.options[i].selected = false; } return false'>$text{'user_snone'}</a>&nbsp;\n";
105 print "<a href='' onClick='for(i=0; i<document.forms[0].mods1.options.length; i++) { document.forms[0].mods1.options[i].selected = !document.forms[0].mods1.options[i].selected; } for(i=0; i<document.forms[0].mods2.options.length; i++) { document.forms[0].mods2.options[i].selected = !document.forms[0].mods2.options[i].selected; } for(i=0; i<document.forms[0].mods3.options.length; i++) { document.forms[0].mods3.options[i].selected = !document.forms[0].mods3.options[i].selected; } return false'>$text{'user_sinvert'}</a><br>\n";
106
107 print "</td> </tr>\n";
108
109 print "</table></td></tr></table>\n";
110 print "<table width=100%><tr>\n";
111 print "<td><input type=submit value='$text{'save'}'></td></form>\n";
112
113 %mdesc = map { $_->{'dir'}, $_->{'desc'} } @mods;
114 foreach $h (@hosts) {
115         local %ingroup;
116         foreach $g (@{$h->{'groups'}}) {
117                 map { $ingroup{$_}++ } @{$g->{'members'}};
118                 }
119         local ($g) = grep { $_->{'name'} eq $in{'group'} } @{$h->{'groups'}};
120         next if (!$g);
121         local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
122         local $d = &server_name($s);
123         $sel .= "<option value='$h->{'id'},'>".&text('user_aclhg', $d)."\n"
124                 if (!$ingroup{$in{'group'}});
125         foreach $m (@{$h->{'modules'}}) {
126                 local @gm = $ingroup{$in{'group'}} ? @{$g->{'ownmods'}}
127                                                    : @{$g->{'modules'}};
128                 next if (&indexof($m->{'dir'}, @gm) < 0);
129                 $sel .= "<option value='$h->{'id'},$m->{'dir'}'>".
130                         &text('user_aclh', $m->{'desc'}, $d)."\n";
131                 }
132         }
133 if ($sel) {
134         print "<form action=edit_acl.cgi><td align=center>\n";
135         print "<input type=hidden name=group value='$in{'group'}'>\n";
136         print "<input type=submit value='$text{'user_acl'}'>\n";
137         print "<select name=modhost>\n";
138         print $sel;
139         print "</select></td></form>\n";
140         }
141
142 print "<form action=delete_group.cgi>\n";
143 print "<input type=hidden name=group value=\"$in{'group'}\">\n";
144 print "<td align=right><input type=submit value='$text{'delete'}'></td></form>\n";
145 print "</tr></table>\n";
146
147 # Show hosts with the group
148 print &ui_hr();
149 print &ui_subheading($text{'group_hosts'});
150 @icons = map { "/servers/images/$_->{'type'}.gif" } @got;
151 @links = map { "edit_host.cgi?id=$_->{'id'}" } @got;
152 @titles = map { &server_name($_) } @got;
153 &icons_table(\@links, \@titles, \@icons);
154
155 &ui_print_footer("", $text{'index_return'});
156