Handle hostnames with upper-case letters
[webmin.git] / cluster-useradmin / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display hosts on which users are being managed, and inputs for adding more
4
5 require './cluster-useradmin-lib.pl';
6 &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1);
7
8 # Display hosts on which users will be managed
9 print &ui_subheading($text{'index_hosts'});
10 @servers = &list_servers();
11 @hosts = &list_useradmin_hosts();
12 if ($config{'sort_mode'} == 1) {
13         @hosts = sort { my ($as) = grep { $_->{'id'} == $a->{'id'} } @servers;
14                         my ($bs) = grep { $_->{'id'} == $b->{'id'} } @servers;
15                         lc($as->{'host'}) cmp lc($bs->{'host'}) } @hosts;
16         }
17 elsif ($config{'sort_mode'} == 2) {
18         @hosts = sort { my ($as) = grep { $_->{'id'} == $a->{'id'} } @servers;
19                         my ($bs) = grep { $_->{'id'} == $b->{'id'} } @servers;
20                         lc(&server_name($as)) cmp lc(&server_name($bs)) }@hosts;
21         }
22 $formno = 0;
23 foreach $h (@hosts) {
24         local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
25         next if (!$s);
26         push(@titles, $s->{'desc'} ? $s->{'desc'}
27                                    : "$s->{'host'}:$s->{'port'}");
28         push(@links, "edit_host.cgi?id=$h->{'id'}");
29         push(@icons, "$gconfig{'webprefix'}/servers/images/$s->{'type'}.gif");
30         push(@installed, @{$h->{'packages'}});
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_tucount'},
39                                           $text{'index_tgcount'},
40                                           $text{'index_ttype'} ]);
41                 foreach $h (@hosts) {
42                         local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
43                         next if (!$s);
44                         local ($type) = grep { $_->[0] eq $s->{'type'} }
45                                              @servers::server_types;
46                         print &ui_columns_row([
47                                 "<a href='edit_host.cgi?id=$h->{'id'}'>".
48                                 ($s->{'host'} || &get_system_hostname())."</a>",
49                                 $s->{'desc'},
50                                 scalar(@{$h->{'users'}}),
51                                 scalar(@{$h->{'groups'}}),
52                                 $type->[1],
53                                 ]);
54                         }
55                 print &ui_columns_end();
56                 }
57         else {
58                 # Show as icons
59                 &icons_table(\@links, \@titles, \@icons);
60                 }
61         }
62 else {
63         print "<b>$text{'index_nohosts'}</b><p>\n";
64         }
65 $formno++;
66 print "<form action=add.cgi>\n";
67 print "<table width=100%><tr>\n";
68 @addservers = grep { !$gothost{$_->{'id'}} } @servers;
69 if (@addservers) {
70         print "<td><input type=submit name=add value='$text{'index_add'}'>\n";
71         print "<select name=server>\n";
72         foreach $s (@addservers) {
73                 print "<option value=$s->{'id'}>",
74                         $s->{'desc'} ? $s->{'desc'} : $s->{'host'},"\n";
75                 }
76         print "</select></td>\n";
77         }
78 @groups = &servers::list_all_groups(\@servers);
79 if (@groups) {
80         print "<td align=right><input type=submit name=gadd ",
81               "value='$text{'index_gadd'}'>\n";
82         print "<select name=group>\n";
83         foreach $g (@groups) {
84                 print "<option>$g->{'name'}\n";
85                 }
86         print "</select></td>\n";
87         }
88 print "</tr></table></form>\n";
89
90 if (@hosts) {
91         # Display search and add forms
92         print &ui_hr();
93         print &ui_subheading($text{'index_users'});
94
95         print "<table width=100%><tr>\n";
96         print "<form action=search_user.cgi><td>\n";
97         print "<b>$text{'index_finduser'}</b> <select name=field>\n";
98         print "<option value=user checked>$text{'user'}\n";
99         print "<option value=real>$text{'real'}\n";
100         print "<option value=shell>$text{'shell'}\n";
101         print "<option value=home>$text{'home'}\n";
102         print "<option value=uid>$text{'uid'}\n";
103         print "</select> <select name=match>\n";
104         print "<option value=0 checked>$text{'index_equals'}\n";
105         print "<option value=4>$text{'index_contains'}\n";
106         print "<option value=1>$text{'index_matches'}\n";
107         print "<option value=5>$text{'index_ncontains'}\n";
108         print "<option value=3>$text{'index_nmatches'}\n";
109         print "</select> <input name=what size=15>&nbsp;&nbsp;\n";
110         print "<input type=submit value=\"$text{'find'}\"></td></form>\n";
111
112         print "<form action=user_form.cgi><td align=right>\n";
113         print "<input type=hidden name=new value=1>\n";
114         print "<input type=submit value='$text{'index_newuser'}'>\n";
115         print "</td></form></tr>\n";
116
117         print "<tr><form action=search_group.cgi><td>\n";
118         print "<b>$text{'index_findgroup'}</b> <select name=field>\n";
119         print "<option value=group checked>$text{'gedit_group'}\n";
120         print "<option value=members>$text{'gedit_members'}\n";
121         print "<option value=gid>$text{'gedit_gid'}\n";
122         print "</select> <select name=match>\n";
123         print "<option value=0 checked>$text{'index_equals'}\n";
124         print "<option value=4>$text{'index_contains'}\n";
125         print "<option value=1>$text{'index_matches'}\n";
126         print "<option value=5>$text{'index_ncontains'}\n";
127         print "<option value=3>$text{'index_nmatches'}\n";
128         print "</select> <input name=what size=15>&nbsp;&nbsp;\n";
129         print "<input type=submit value=\"$text{'find'}\"></td></form>\n";
130
131         print "<form action=group_form.cgi><td align=right>\n";
132         print "<input type=hidden name=new value=1>\n";
133         print "<input type=submit value='$text{'index_newgroup'}'>\n";
134         print "</td></form></tr>\n";
135
136         print "<tr><form action=refresh.cgi>\n";
137         print "<td><input type=submit value='$text{'index_refresh'}'>\n";
138         &create_on_input(undef, 1);
139         print "</td>\n";
140         print "</form>\n";
141
142         print "<form action=sync_form.cgi>\n";
143         print "<td align=right><input type=submit ",
144               "value='$text{'index_sync'}'></td>\n";
145         print "</form></tr> </table>\n";
146         }
147
148 &ui_print_footer("/", $text{'index'});
149