Handle hostnames with upper-case letters
[webmin.git] / cluster-usermin / index.cgi
1 #!/usr/local/bin/perl
2 # Shows hosts on which Usermin is installed
3
4 require './cluster-usermin-lib.pl';
5 &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1);
6
7 # Display hosts on which modules will be installed
8 print &ui_subheading($text{'index_hosts'});
9 @servers = &list_servers();
10 @hosts = &list_usermin_hosts();
11 if ($config{'sort_mode'} == 1) {
12         @hosts = sort { my ($as) = grep { $_->{'id'} == $a->{'id'} } @servers;
13                         my ($bs) = grep { $_->{'id'} == $b->{'id'} } @servers;
14                         lc($as->{'host'}) cmp lc($bs->{'host'}) } @hosts;
15         }
16 elsif ($config{'sort_mode'} == 2) {
17         @hosts = sort { my ($as) = grep { $_->{'id'} == $a->{'id'} } @servers;
18                         my ($bs) = grep { $_->{'id'} == $b->{'id'} } @servers;
19                         lc(&server_name($as)) cmp lc(&server_name($bs)) }@hosts;
20         }
21 $formno = 0;
22 foreach $h (@hosts) {
23         local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
24         next if (!$s);
25         push(@titles, &server_name($s)."<br>".
26                       &text('index_version', $h->{'version'}));
27         push(@links, "edit_host.cgi?id=$h->{'id'}");
28         push(@icons, "$gconfig{'webprefix'}/servers/images/$s->{'type'}.gif");
29         $gothost{$h->{'id'}}++;
30         }
31 if (@links) {
32         if ($config{'table_mode'}) {
33                 # Show as table
34                 print &ui_columns_start([ $text{'index_thost'},
35                                           $text{'index_tdesc'},
36                                           $text{'index_tver'},
37                                           $text{'index_ttype'} ]);
38                 foreach $h (@hosts) {
39                         local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
40                         next if (!$s);
41                         local ($type) = grep { $_->[0] eq $s->{'type'} }
42                                              @servers::server_types;
43                         print &ui_columns_row([
44                                 "<a href='edit_host.cgi?id=$h->{'id'}'>".
45                                 ($s->{'host'} || &get_system_hostname())."</a>",
46                                 $s->{'desc'},
47                                 $h->{'version'},
48                                 $type->[1],
49                                 ]);
50                         }
51                 print &ui_columns_end();
52                 }
53         else {
54                 # Show as icons
55                 &icons_table(\@links, \@titles, \@icons);
56                 }
57         }
58 else {
59         print "<b>$text{'index_nohosts'}</b><p>\n";
60         }
61
62 # Build common selectors
63 @wgroups = &all_groups(\@hosts);
64 $modsel2 = $modsel = "<select name=mod>\n";
65 $modsel2 .= "<option value=''>$text{'index_gacl'}\n";
66 foreach $m (&all_modules(\@hosts)) {
67         $modsel .= "<option value=$m->{'dir'}>$m->{'desc'}\n";
68         $modsel2 .= "<option value=$m->{'dir'}>$m->{'desc'}\n";
69         }
70 $modsel .= "</select>\n";
71 $modsel2 .= "</select>\n";
72 $themesel = "<select name=theme>\n";
73 foreach $t (&all_themes(\@hosts)) {
74         $themesel .= "<option value=$t->{'dir'}>$t->{'desc'}\n";
75         }
76 $themesel .= "</select>\n";
77
78 # Show button for adding server
79 print "<table width=100%><tr>\n";
80 @addservers = grep { !$gothost{$_->{'id'}} } @servers;
81 if (@addservers) {
82         print "<form action=add.cgi><td>\n";
83         print "<input type=submit name=add value='$text{'index_add'}'>\n";
84         print "<select name=server>\n";
85         foreach $s (@addservers) {
86                 print "<option value=$s->{'id'}>",&server_name($s),"\n";
87                 }
88         print "</select>\n";
89         print "</td></form>\n";
90         $formno++;
91         }
92 else { print "<td></td>\n"; }
93
94 # Show button for adding server group
95 @groups = &servers::list_all_groups(\@servers);
96 if (@groups) {
97         print "<form action=add.cgi><td align=right>\n";
98         print "<input type=submit name=gadd value='$text{'index_gadd'}'>\n";
99         print "<select name=group>\n";
100         foreach $g (@groups) {
101                 print "<option>$g->{'name'}\n";
102                 }
103         print "</select>\n";
104         print "</td></form>\n";
105         $formno++;
106         }
107 else { print "<td></td>\n"; }
108 print "</tr></table>\n";
109
110 if (@hosts) {
111         # Display modules lists and new module form
112         print &ui_hr();
113         print &ui_subheading($text{'index_modules'});
114         print "<table width=100%><tr>\n";
115         print "<form action=edit_mod.cgi><td>\n";
116         print "<input type=submit value=\"$text{'index_edit'}\">\n";
117         print $modsel;
118         print "</td>\n";
119
120         print "<td align=right><input type=submit name=tedit value=\"$text{'index_tedit'}\">\n";
121         print $themesel;
122         print "</td></form></tr>\n";
123         $formno++;
124
125         print "<tr> <form action=refresh.cgi><td align=left colspan=2>\n";
126         print "<input type=submit value='$text{'index_refresh'}'>\n";
127         &create_on_input(undef, 1, 1);
128         print "</td></form>\n";
129         $formno++;
130         print "</table><p>\n";
131
132         print "<form action=install.cgi method=post ",
133               "enctype=multipart/form-data>\n";
134         print "$text{'index_installmsg'}<p>\n";
135         print "<input type=radio name=source value=0 checked> $text{'index_local'}\n";
136         print "<input name=local size=50>\n";
137         print &file_chooser_button("local", 0, $formno); print "<br>\n";
138         print "<input type=radio name=source value=1> $text{'index_uploaded'}\n";
139         print "<input type=file name=upload size=20><br>\n";
140         print "<input type=radio name=source value=2> $text{'index_ftp'}\n";
141         print "<input name=url size=50><br>\n";
142         print "&nbsp;" x 5,"<input type=checkbox name=down value=1> ",
143               "$text{'index_down'}<p>\n";
144
145         print "<input type=checkbox name=nodeps value=1> ",
146               "$text{'index_nodeps'}<br>\n";
147
148         print "$text{'index_installon'}\n";
149         &create_on_input();
150         print "<p>\n";
151
152         print "<input type=submit value=\"$text{'index_installok'}\">\n";
153         print "</form>\n";
154         $formno++;
155
156         # Display upgrade form
157         &foreign_require("webmin", "webmin-lib.pl");
158         print &ui_hr();
159         print &ui_subheading($text{'index_upgrade'});
160         print "$text{'index_updesc'}<p>\n";
161
162         # what kind of install is the local system?
163         $mode = &usermin::get_install_type();
164
165         print "<form action=upgrade.cgi method=post enctype=multipart/form-data>\n";
166         print "<input type=hidden name=mode value='$mode'>\n";
167
168         print "<input type=radio name=source value=0> $text{'index_local'}\n";
169         print "<input name=file size=40>\n";
170         print &file_chooser_button("file", 0, $formno),"<br>\n";
171         print "<input type=radio name=source value=1> $text{'index_uploaded'}\n";
172         print "<input name=upload type=file size=30><br>\n";
173         print "<input type=radio name=source value=5> $text{'index_ftp'}\n";
174         print "<input name=url size=40><br>\n";
175         if ($in{'mode'} eq 'rpm' || !$in{'mode'}) {
176                 print "<input type=radio name=source value=2 checked> $webmin::text{'upgrade_ftp'}<br>\n";
177                 }
178         print "<p>\n";
179
180         print "<input type=checkbox name=delete value=1> ",
181                 "$webmin::text{'upgrade_delete'}<br>\n";
182         print "$text{'index_upgradeon'}\n";
183         &create_on_input();
184         print "<input type=submit value=\"$usermin::text{'upgrade_ok'}\">\n";
185         print "</form>\n";
186         $formno++;
187         }
188
189 &ui_print_footer("/", $text{'index'});
190