Handle hostnames with upper-case letters
[webmin.git] / cluster-webmin / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display hosts on which webmin modules are being managed, a list of
4 # installed modules and a form for installing new ones
5
6 require './cluster-webmin-lib.pl';
7 &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1);
8
9 # Display hosts on which modules will be installed
10 print &ui_subheading($text{'index_hosts'});
11 @servers = &list_servers();
12 @hosts = &list_webmin_hosts();
13 if ($config{'sort_mode'} == 1) {
14         @hosts = sort { my ($as) = grep { $_->{'id'} == $a->{'id'} } @servers;
15                         my ($bs) = grep { $_->{'id'} == $b->{'id'} } @servers;
16                         lc($as->{'host'}) cmp lc($bs->{'host'}) } @hosts;
17         }
18 elsif ($config{'sort_mode'} == 2) {
19         @hosts = sort { my ($as) = grep { $_->{'id'} == $a->{'id'} } @servers;
20                         my ($bs) = grep { $_->{'id'} == $b->{'id'} } @servers;
21                         lc(&server_name($as)) cmp lc(&server_name($bs)) }@hosts;
22         }
23 $formno = 0;
24 foreach $h (@hosts) {
25         local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
26         next if (!$s);
27         push(@titles, &server_name($s)."<br>".
28                       &text('index_version', $h->{'version'}));
29         push(@links, "edit_host.cgi?id=$h->{'id'}");
30         push(@icons, "$gconfig{'webprefix'}/servers/images/$s->{'type'}.gif");
31         $gothost{$h->{'id'}}++;
32         }
33 if (@links) {
34         if ($config{'table_mode'}) {
35                 # Show as table
36                 print &ui_columns_start([ $text{'index_thost'},
37                                           $text{'index_tdesc'},
38                                           $text{'index_tver'},
39                                           $text{'index_ttype'} ]);
40                 foreach $h (@hosts) {
41                         local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
42                         next if (!$s);
43                         local ($type) = grep { $_->[0] eq $s->{'type'} }
44                                              @servers::server_types;
45                         print &ui_columns_row([
46                                 "<a href='edit_host.cgi?id=$h->{'id'}'>".
47                                 ($s->{'host'} || &get_system_hostname())."</a>",
48                                 $s->{'desc'},
49                                 $h->{'version'},
50                                 $type->[1],
51                                 ]);
52                         }
53                 print &ui_columns_end();
54                 }
55         else {
56                 # Show as icons
57                 &icons_table(\@links, \@titles, \@icons);
58                 }
59         }
60 else {
61         # Nothing to show
62         print "<b>$text{'index_nohosts'}</b><p>\n";
63         }
64
65 # Build common selectors
66 @wgroups = &all_groups(\@hosts);
67 $modsel2 = $modsel = "<select name=mod>\n";
68 $modsel2 .= "<option value=''>$text{'index_gacl'}\n";
69 foreach $m (&all_modules(\@hosts)) {
70         $modsel .= "<option value=$m->{'dir'}>$m->{'desc'}\n";
71         $modsel2 .= "<option value=$m->{'dir'}>$m->{'desc'}\n";
72         }
73 $modsel .= "</select>\n";
74 $modsel2 .= "</select>\n";
75 $themesel = "<select name=theme>\n";
76 foreach $t (&all_themes(\@hosts)) {
77         $themesel .= "<option value=$t->{'dir'}>$t->{'desc'}\n";
78         }
79 $themesel .= "</select>\n";
80 $usersel = "<select name=user>\n";
81 foreach $u (&all_users(\@hosts)) {
82         $usersel .= "<option>$u->{'name'}\n";
83         }
84 $usersel .= "</select>\n";
85 $groupsel = "<select name=group>\n";
86 foreach $u (@wgroups) {
87         $groupsel .= "<option>$u->{'name'}\n";
88         }
89 $groupsel .= "</select>\n";
90
91 print "<table width=100%><tr>\n";
92 @addservers = grep { !$gothost{$_->{'id'}} } @servers;
93 if (@addservers) {
94         print "<form action=add.cgi><td>\n";
95         print "<input type=submit name=add value='$text{'index_add'}'>\n";
96         print "<select name=server>\n";
97         foreach $s (@addservers) {
98                 print "<option value=$s->{'id'}>",&server_name($s),"\n";
99                 }
100         print "</select>\n";
101         print "</td></form>\n";
102         $formno++;
103         }
104 else { print "<td></td>\n"; }
105
106 @groups = &servers::list_all_groups(\@servers);
107 if (@groups) {
108         print "<form action=add.cgi><td align=right>\n";
109         print "<input type=submit name=gadd value='$text{'index_gadd'}'>\n";
110         print "<select name=group>\n";
111         foreach $g (@groups) {
112                 print "<option>$g->{'name'}\n";
113                 }
114         print "</select>\n";
115         print "</td></form>\n";
116         $formno++;
117         }
118 else { print "<td></td>\n"; }
119 print "</tr></table>\n";
120
121 if (@hosts) {
122         # Display user search forms and new user buttons
123         print &ui_hr();
124         print &ui_subheading($text{'index_users'});
125         print "<table width=100%>\n";
126
127         print "<tr><form action=edit_user.cgi><td>\n";
128         print "<input type=submit value='$text{'index_euser'}'>\n";
129         print $usersel;
130         print "</td></form>\n";
131         $formno++;
132
133         print "<form action=edit_acl.cgi><td>\n";
134         print "<input type=submit value='$text{'index_euseracl'}'>\n";
135         print $usersel;
136         print "$text{'index_inmod'}\n";
137         print $modsel2;
138         print "</td></form>\n";
139         $formno++;
140
141         print "<form action=user_form.cgi><td align=right>\n";
142         print "<input type=submit value='$text{'index_cuser'}'>\n";
143         print "</td></form></tr>\n";
144         $formno++;
145
146         if (@wgroups) {
147                 print "<tr><form action=edit_group.cgi><td>\n";
148                 print "<input type=submit value='$text{'index_egroup'}'>\n";
149                 print $groupsel;
150                 print "</td></form>\n";
151                 $formno++;
152
153                 print "<form action=edit_acl.cgi><td>\n";
154                 print "<input type=submit value='$text{'index_egroupacl'}'>\n";
155                 print $groupsel;
156                 print "$text{'index_inmod'}\n";
157                 print $modsel2;
158                 print "</td></form>\n";
159                 $formno++;
160                 }
161         else {
162                 print "<tr> <td colspan=2></td>\n";
163                 }
164
165         print "<form action=group_form.cgi><td align=right>\n";
166         print "<input type=submit value='$text{'index_cgroup'}'>\n";
167         print "</td></form></tr>\n";
168         $formno++;
169
170         print "<tr> <form action=refresh.cgi><td align=left colspan=2>\n";
171         print "<input type=submit value='$text{'index_refresh'}'>\n";
172         &create_on_input(undef, 1, 1);
173         print "</td></form>\n";
174         $formno++;
175
176         print "<form action=sync_form.cgi><td align=right>\n";
177         print "<input type=submit value='$text{'index_sync'}'>\n";
178         print "</td></form></tr>\n";
179         $formno++;
180
181         print "</table>\n";
182
183         # Display modules lists and new module form
184         print &ui_hr();
185         print &ui_subheading($text{'index_modules'});
186         print "<table width=100%><tr>\n";
187         print "<form action=edit_mod.cgi><td>\n";
188         print "<input type=submit value=\"$text{'index_edit'}\">\n";
189         print $modsel;
190         print "</td>\n";
191
192         print "<td align=right><input type=submit name=tedit value=\"$text{'index_tedit'}\">\n";
193         print $themesel;
194         print "</td></form></tr></table><p>\n";
195         $formno++;
196
197         print "<form action=install.cgi method=post ",
198               "enctype=multipart/form-data>\n";
199         print "$text{'index_installmsg'}<p>\n";
200         print "<input type=radio name=source value=0 checked> $text{'index_local'}\n";
201         print "<input name=local size=50>\n";
202         print &file_chooser_button("local", 0, $formno); print "<br>\n";
203         print "<input type=radio name=source value=1> $text{'index_uploaded'}\n";
204         print "<input type=file name=upload size=20><br>\n";
205         print "<input type=radio name=source value=2> $text{'index_ftp'}\n";
206         print "<input name=url size=50><br>\n";
207         print "&nbsp;" x 5,"<input type=checkbox name=down value=1> ",
208               "$text{'index_down'}<p>\n";
209
210         print "<input type=radio name=grant value=0 checked> ",
211               "$text{'index_grant2'}\n";
212         print "<input name=grantto size=30 value='$base_remote_user'><br>\n";
213         print "<input type=radio name=grant value=1> ",
214               "$text{'index_grant1'}<br>\n";
215
216         print "<input type=checkbox name=nodeps value=1> ",
217               "$text{'index_nodeps'}<p>\n";
218
219         print "$text{'index_installon'}\n";
220         &create_on_input();
221         print "<p>\n";
222
223         print "<input type=submit value=\"$text{'index_installok'}\">\n";
224         print "</form>\n";
225         $formno++;
226
227         # Display upgrade form
228         &foreign_require("webmin", "webmin-lib.pl");
229         print &ui_hr();
230         print &ui_subheading($text{'index_upgrade'});
231         print "$text{'index_updesc'}<p>\n";
232
233         # what kind of install is the local system?
234         $mode = &webmin::get_install_type();
235
236         print "<form action=upgrade.cgi method=post enctype=multipart/form-data>\n";
237         print "<input type=hidden name=mode value='$mode'>\n";
238
239         print "<input type=radio name=source value=0> $text{'index_local'}\n";
240         print "<input name=file size=40>\n";
241         print &file_chooser_button("file", 0, $formno),"<br>\n";
242         print "<input type=radio name=source value=1> $text{'index_uploaded'}\n";
243         print "<input name=upload type=file size=30><br>\n";
244         print "<input type=radio name=source value=5> $text{'index_ftp'}\n";
245         print "<input name=url size=40><br>\n";
246         if ($in{'mode'} eq 'rpm' || $mode eq 'deb' || !$in{'mode'}) {
247                 print "<input type=radio name=source value=2 checked> $webmin::text{'upgrade_ftp'}<br>\n";
248                 }
249         print "<p>\n";
250
251         printf "<input type=checkbox name=sig value=1> %s<br>\n",
252                 $webmin::text{'upgrade_sig'};
253         print "<input type=checkbox name=delete value=1> ",
254                 "$webmin::text{'upgrade_delete'}<br>\n";
255         print "<input type=checkbox name=only value=1> ",
256                 "$webmin::text{'upgrade_only'}<br>\n";
257         print "$text{'index_upgradeon'}\n";
258         &create_on_input();
259         print "<input type=submit value=\"$webmin::text{'upgrade_ok'}\">\n";
260         print "</form>\n";
261         $formno++;
262
263         # Show form for installing updates
264         print &ui_hr();
265         print &ui_subheading($text{'index_update'});
266         print "$text{'index_updatedesc'}<p>\n";
267         print "<form action=update.cgi>\n";
268
269         printf "<input type=radio name=source value=0 %s> %s<br>\n",
270                 $webmin::config{'upsource'} ? "" : "checked",
271                 $webmin::text{'update_webmin'};
272         printf "<input type=radio name=source value=1 %s> %s\n",
273                 $webmin::config{'upsource'} ? "checked" : "",
274                 $webmin::text{'update_other'};
275         printf "<input name=other size=30 value='%s'><p>\n",
276                 $webmin::config{'upsource'};
277
278         printf "<input type=checkbox name=show value=1 %s> %s<br>\n",
279                 $webmin::config{'upshow'} ? "checked" : "",
280                 $webmin::text{'update_show'};
281         printf "<input type=checkbox name=missing value=1 %s> %s<br>\n",
282                 $webmin::config{'upmissing'} ? "checked" : "",
283                 $webmin::text{'update_missing'};
284         printf "<input type=checkbox name=third value=1 %s> %s<br>\n",
285                 $webmin::config{'upthird'} ? "checked" : "",
286                 $webmin::text{'update_third'};
287
288         print "$text{'index_updateon'}\n";
289         &create_on_input(undef, 1);
290
291         print "<input type=submit value=\"$webmin::text{'update_ok'}\">\n";
292         print "</form>\n";
293         }
294
295 &ui_print_footer("/", $text{'index'});
296