Handle hostnames with upper-case letters
[webmin.git] / cluster-software / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display hosts on which software packages are being managed, a form for
4 # finding existing packages and a form for installing more
5
6 require './cluster-software-lib.pl';
7 &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1);
8
9 # Display hosts on which software will be installed
10 print &ui_subheading($text{'index_hosts'});
11 @servers = &list_servers();
12 @hosts = &list_software_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         local $count = @{$h->{'packages'}};
28         push(@titles, ($s->{'desc'} ? $s->{'desc'} :
29                        $s->{'realhost'} ? "$s->{'realhost'}:$s->{'port'}" :
30                                      "$s->{'host'}:$s->{'port'}")."<br>".
31                       &text('index_count', $count));
32         push(@links, "edit_host.cgi?id=$h->{'id'}");
33         push(@icons, "$gconfig{'webprefix'}/servers/images/$s->{'type'}.gif");
34         push(@installed, $count);
35         $gothost{$h->{'id'}}++;
36         }
37 if (@links) {
38         if ($config{'table_mode'}) {
39                 # Show as table
40                 print &ui_columns_start([ $text{'index_thost'},
41                                           $text{'index_tdesc'},
42                                           $text{'index_tcount'},
43                                           $text{'index_ttype'} ]);
44                 foreach $h (@hosts) {
45                         local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
46                         next if (!$s);
47                         local ($type) = grep { $_->[0] eq $s->{'type'} }
48                                              @servers::server_types;
49                         print &ui_columns_row([
50                                 "<a href='edit_host.cgi?id=$h->{'id'}'>".
51                                 ($s->{'host'} || &get_system_hostname())."</a>",
52                                 $s->{'desc'},
53                                 scalar(@{$h->{'packages'}}),
54                                 $type->[1],
55                                 ]);
56                         }
57                 print &ui_columns_end();
58                 }
59         else {
60                 # Show as icons
61                 &icons_table(\@links, \@titles, \@icons);
62                 }
63         }
64 else {
65         print "<b>$text{'index_nohosts'}</b><p>\n";
66         }
67 $formno++;
68
69 # Show form for adding a server
70 print "<table width=100%><tr>\n";
71 @addservers = grep { !$gothost{$_->{'id'}} } @servers;
72 if (@addservers && $access{'add'}) {
73         print "<form action=add.cgi>\n";
74         print "<td width=33%>\n";
75         print "<input type=submit name=add value='$text{'index_add'}'>\n";
76         print "<select name=server>\n";
77         foreach $s (@addservers) {
78                 print "<option value=$s->{'id'}>",
79                         $s->{'desc'} || $s->{'realhost'} || $s->{'host'},"\n";
80                 }
81         print "</select></td>\n";
82         print "</form>\n";
83         }
84
85 # Show button for compare form
86 if (@hosts) {
87         print "<form action=compare_form.cgi>\n";
88         print "<td align=center width=33%>\n";
89         print "<input type=submit value='$text{'index_compare'}'>\n";
90         print "</td>\n";
91         print "</form>\n";
92         }
93
94 # Show form for adding a group of servers
95 @groups = &servers::list_all_groups(\@servers);
96 if (@groups && $access{'add'}) {
97         print "<form action=add.cgi>\n";
98         print "<td align=right width=33%>\n";
99         print "<input type=submit name=gadd value='$text{'index_gadd'}'>\n";
100         print "<select name=group>\n";
101         foreach $g (@groups) {
102                 print "<option>$g->{'name'}\n";
103                 }
104         print "</select></td>\n";
105         print "</form>\n";
106         }
107 print "</tr></table>\n";
108
109 if (@hosts) {
110         # Display search form
111         print &ui_hr();
112         print &ui_subheading($text{'index_installed'});
113         print "<table cellpadding=0 cellspacing=0 width=100%><tr><td>\n";
114         $formno += 2;
115         print "<form action=search.cgi>\n";
116         print "<input type=submit value=\"$text{'index_search'}\">\n";
117         print "<input name=search size=30>\n";
118         print "</form></td>\n";
119
120         print "<td align=right><form action=refresh.cgi>\n";
121         print "<input type=submit value=\"$text{'index_refresh'}\">\n";
122         &create_on_input(undef, 1, 1);
123         print "</form></td> </tr></table>\n";
124
125         # Display cross-cluster install form
126         print &ui_hr();
127         print &ui_subheading($text{'index_install'});
128         print "$text{'index_installmsg'}<p>\n";
129
130         $upid = time().$$;
131         print &ui_form_start("install_pack.cgi?id=$upid", "form-data", undef,
132                      &read_parse_mime_javascript($upid, [ "upload" ])),"\n";
133
134         @opts = ( );
135         push(@opts, [ 0, $text{'index_local'},
136                       &ui_textbox("local", undef, 50)."\n".
137                       &file_chooser_button("local", 0, 2) ]);
138         push(@opts, [ 1, $text{'index_uploaded'},
139                       &ui_upload("upload", 50) ]);
140         push(@opts, [ 2, $text{'index_ftp'},
141                       &ui_textbox("url", undef, 50)."<br>\n".
142                       &ui_checkbox("down", 1, $text{'index_down'}, 0) ]);
143         if ($software::has_update_system) {
144                 push(@opts, [ 3,
145                       $software::text{$software::update_system.'_input'},
146                       &ui_textbox("update", undef, 30)."\n".
147                       &software::update_system_button("update",
148                             $software::text{$software::update_system.'_find'})
149                       ]);
150                 }
151         print &ui_radio_table("source", 0, \@opts);
152         print &ui_submit($text{'index_installok'}),"\n";
153         print &ui_form_end();
154         }
155
156 &ui_print_footer("/", $text{'index'});
157