Handle hostnames with upper-case letters
[webmin.git] / cluster-usermin / edit_mod.cgi
1 #!/usr/local/bin/perl
2 # edit_mod.cgi
3 # Display details of a module or theme
4
5 require './cluster-usermin-lib.pl';
6 &ReadParse();
7 $type = $in{'tedit'} || !$in{'mod'} ? 'theme' : 'mod';
8 $name = $in{$type};
9 &ui_print_header(undef, $text{"edit_title_$type"}, "");
10
11 # Find all hosts with the module or theme
12 @hosts = &list_usermin_hosts();
13 @servers = &list_servers();
14 foreach $h (@hosts) {
15         local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
16         foreach $m ($type eq 'theme' ? @{$h->{'themes'}}
17                                      : @{$h->{'modules'}}) {
18                 if ($m->{'dir'} eq $name) {
19                         $s->{'module'} = $m;
20                         push(@got, $s);
21                         push(@goth, $h);
22                         $mod = $m if (!$mod);
23                         if (!$checkon && ($s->{'id'} == $in{'host'} ||
24                                   !$s->{'id'} && !defined($in{'host'}))) {
25                                 $checkon = $s;
26                                 $checkonh = $h;
27                                 }
28                         }
29                 }
30         }
31
32 # Get the details from this host, or the first in the list
33 if (!$checkon) {
34         $checkonh = $goth[0];
35         $checkon = $got[0];
36         }
37 #&remote_foreign_require($checkon->{'host'}, "software", "software-lib.pl");
38 #@pinfo = &remote_foreign_call($checkon->{'host'}, "software", "package_info",
39 #                             $in{'package'});
40
41 # Show module/theme details
42 print "<table border width=100%>\n";
43 print "<tr $tb> <td><b>",&text("edit_header_$type", &server_name($checkon)),
44       "</b></td> </tr>\n";
45 print "<tr $cb> <td><table width=100%>\n";
46
47 print "<tr> <td><b>$text{'edit_desc'}</b></td>\n";
48 print "<td>",$mod->{'desc'},"</td>\n";
49
50 print "<td><b>$text{'edit_ver'}</b></td>\n";
51 print "<td>",$mod->{'version'} ? $mod->{'version'}
52                                : $text{'edit_nover'},"</td> </tr>\n";
53
54 if ($type eq 'mod') {
55         # Show details of module
56         foreach $m (@{$checkonh->{'modules'}}) {
57                 $modmap{$m->{'dir'}} = $m;
58                 foreach $d (split(/\s+/, $m->{'depends'})) {
59                         push(@{$ondeps{$d}}, $m);
60                         }
61                 }
62
63         &read_file("$usermin::config{'usermin_dir'}/webmin.catnames",
64                    \%catnames);
65         %utext = &get_usermin_text();
66         print "<tr> <td><b>$text{'edit_cat'}</b></td>\n";
67         $c = $mod->{'category'};
68         print "<td>",$catname{$c} ? $catname{$c} :
69                      $utext{"category_$c"} ? $utext{"category_$c"} :
70                                              $utext{"category_"},"</td>\n";
71
72         print "<td><b>$text{'edit_dir'}</b></td>\n";
73         print "<td><tt>$mod->{'dir'}</tt></td> </tr>\n";
74
75         # Show operating systems
76         print "<tr> <td valign=top><b>$text{'edit_os'}</b></td>\n";
77         print "<td colspan=3>\n";
78         $oss = $mod->{'os_support'};
79         if (!$oss) {
80                 print $text{'edit_osall'};
81                 }
82         else {
83                 open(OSLIST, "$root_directory/os_list.txt");
84                 while(<OSLIST>) {
85                         chop;
86                         if (/^([^\t]+)\t+([^\t]+)\t+(\S+)\t+(\S+)\t*(.*)$/) {
87                                 $osname{$3} = $1 if (!$osname{$3});
88                                 }
89                         }
90                 close(OSLIST);
91                 $osname{"*-linux"} = "Linux";
92                 while(1) {
93                         local ($os, $ver, $codes);
94                         if ($oss =~ /^([^\/\s]+)\/([^\{\s]+)\{([^\}]*)\}\s*(.*)$/) {
95                                 $os = $1; $ver = $2; $codes = $3; $oss = $4;
96                                 }
97                         elsif ($oss =~ /^([^\/\s]+)\/([^\/\s]+)\s*(.*)$/) {
98                                 $os = $1; $ver = $2; $oss = $3;
99                                 }
100                         elsif ($oss =~ /^([^\{\s]+)\{([^\}]*)\}\s*(.*)$/) {
101                                 $os = $1; $codes = $2; $oss = $3;
102                                 }
103                         elsif ($oss =~ /^\{([^\}]*)\}\s*(.*)$/) {
104                                 $codes = $1; $oss = $2;
105                                 }
106                         elsif ($oss =~ /^(\S+)\s*(.*)$/) {
107                                 $os = $1; $oss = $2;
108                                 }
109                         else { last; }
110                         print "&nbsp;,&nbsp;\n" if ($doneone++);
111                         $osn = $osname{$os} ? $osname{$os} : $os;
112                         $osn =~ s/\s/&nbsp;/g;
113                         if ($ver) {
114                                 print "$osn&nbsp;$ver";
115                                 }
116                         elsif ($os) {
117                                 print "$osn";
118                                 }
119                         if ($codes) {
120                                 $codes =~ s/\s/&nbsp;/g;
121                                 if ($os) {
122                                         print " (",&text('edit_codes',
123                                                         "<tt>$codes</tt>"),")";
124                                         }
125                                 else {
126                                         print &text('edit_codes',
127                                                     "<tt>$codes</tt>");
128                                         }
129                                 }
130                         }
131                 }
132         print "</td> </tr>\n";
133
134         # Show which modules this module depends upon
135         local @deps = grep { !/^[0-9\.]+$/ } split(/\s+/, $mod->{'depends'});
136         local @pdeps = split(/\s+/, $mod->{'perldepends'});
137         print "<tr> <td valign=top><b>$text{'edit_deps'}</b></td>\n";
138         print "<td valign=top>\n";
139         if (@deps || @pdeps) {
140                 foreach $d (@deps) {
141                         local $mm = $modmap{$d};
142                         print $mm->{'desc'}," (<tt>$mm->{'dir'}</tt>)<br>\n";
143                         }
144                 foreach $d (@pdeps) {
145                         print &text('edit_pdep', "<tt>$d</tt>"),"<br>\n";
146                         }
147                 }
148         else {
149                 print "$text{'edit_nodeps'}\n";
150                 }
151         print "</td>\n";
152
153         # Show which other modules depend on this one
154         print "<td valign=top><b>$text{'edit_ondeps'}</b></td>\n";
155         print "<td valign=top>\n";
156         if ($ondeps{$mod->{'dir'}}) {
157                 foreach $d (@{$ondeps{$mod->{'dir'}}}) {
158                         print $d->{'desc'}," (<tt>$d->{'dir'}</tt>)<br>\n";
159                         }
160                 }
161         else {
162                 print "$text{'edit_nodeps'}\n";
163                 }
164         print "</td> </tr>\n";
165         }
166 else {
167         # Show details of theme
168         }
169
170 print "</table></td></tr></table><p>\n";
171
172 print "<table width=100%><tr>\n";
173 print "<form action=delete_mod.cgi>\n";
174 print "<input type=hidden name=type value=\"$type\">\n";
175 print "<input type=hidden name=mod value=\"$name\">\n";
176 print "<td><input type=submit value='",$text{"edit_uninst_$type"},"'>\n";
177 print "<select name=server>\n";
178 print "<option value=-1>$text{'edit_all'}\n";
179 foreach $s (@got) {
180         print "<option value='$s->{'id'}'>",&server_name($s),"\n";
181         }
182 print "</select></td></form>\n";
183
184 print "</tr></table>\n";
185
186 # Show hosts with the module or theme
187 print &ui_hr();
188 print &ui_subheading($text{'edit_hosts'});
189 @icons = map { "/servers/images/$_->{'type'}.gif" } @got;
190 @links = map { "edit_host.cgi?id=$_->{'id'}" } @got;
191 @titles = map { &server_name($_).
192                 ($_->{'module'}->{'version'} ? " ($text{'host_version2'} $_->{'module'}->{'version'})" : "") } @got;
193 &icons_table(\@links, \@titles, \@icons);
194
195 &remote_finished();
196 &ui_print_footer("", $text{'index_return'});
197
198