Handle hostnames with upper-case letters
[webmin.git] / cluster-software / edit_host.cgi
1 #!/usr/local/bin/perl
2 # edit_host.cgi
3 # Show details of a managed host, and all the packages on it
4
5 require './cluster-software-lib.pl';
6 &foreign_require("servers", "servers-lib.pl");
7 &ReadParse();
8 &ui_print_header(undef, $text{'host_title'}, "", "edit_host");
9
10 @hosts = &list_software_hosts();
11 ($host) = grep { $_->{'id'} eq $in{'id'} } @hosts;
12 $server = &foreign_call("servers", "get_server", $in{'id'});
13 @packages = @{$host->{'packages'}};
14
15 # Show host details
16 print "<table border width=100%>\n";
17 print "<tr $tb> <td><b>$text{'host_header'}</b></td> </tr>\n";
18 print "<tr $cb> <td><table width=100%>\n";
19
20 print "<tr> <td><b>$text{'host_name'}</b></td>\n";
21 if ($server->{'id'}) {
22         $h = $server->{'realhost'} || $server->{'host'};
23         printf "<td><a href='/servers/link.cgi/%s/'>%s</a></td>\n",
24                 $server->{'id'}, $server->{'desc'} ? "$server->{'desc'} ($h:$server->{'port'})" : "$h:$server->{'port'}";
25         }
26 else {
27         print "<td><a href=/>$text{'this_server'}</a></td>\n";
28         }
29
30 if ($server->{'id'}) {
31         print "<td><b>$text{'host_type'}</b></td> <td>\n";
32         foreach $t (@servers::server_types) {
33                 print $t->[1] if ($t->[0] eq $server->{'type'});
34                 }
35         print "</td>\n";
36         }
37 print "</tr>\n";
38
39 print "<tr> <td><b>$text{'host_count'}</b></td>\n";
40 printf "<td>%d</td>\n", scalar(@packages);
41
42 print "<td><b>$text{'host_os'}</b></td>\n";
43 print "<td>$host->{'real_os_type'} $host->{'real_os_version'}</td> </tr>\n";
44
45 print "<tr> <td><b>$text{'host_system'}</b></td>\n";
46 $system = $host->{'package_system'} || $software::config{'package_system'};
47 print "<td>",uc($system),"</td>\n";
48
49 print "</tr>\n";
50
51 print "</table></td></tr></table>\n";
52
53 # Show delete and refresh buttons
54 print "<table width=100%><tr>\n";
55 print "<form action=delete_host.cgi>\n";
56 print "<input type=hidden name=id value=$in{'id'}>\n";
57 print "<td><input type=submit value='$text{'host_delete'}'></td>\n";
58 print "</form>\n";
59
60 print "<form action=refresh.cgi>\n";
61 print "<input type=hidden name=id value=$in{'id'}>\n";
62 print "<td align=right><input type=submit value='$text{'host_refresh'}'></td>\n";
63 print "</form>\n";
64 print "</tr></table>\n";
65
66 # Show tree of packages
67 $heir{""} = "";
68 foreach $c (sort { $a cmp $b } &unique(map { $_->{'class'} } @packages)) {
69         if (!$c) { next; }
70         @w = split(/\//, $c);
71         $p = join('/', @w[0..$#w-1]);
72         if (!defined($heir{$p})) {
73                 $pp = join('/', @w[0..$#w-2]);
74                 $heir{$pp} .= "$p\0";
75                 }
76         $heir{$p} .= "$c\0";
77         $hasclasses++;
78         }
79
80 # get the current open list
81 %heiropen = map { $_, 1 } &get_heiropen($in{'id'});
82 $heiropen{""}++;
83
84 # traverse the heirarchy
85 $spacer = "&nbsp;"x3;
86 print &ui_hr();
87 print &ui_subheading($text{'host_installed'});
88 print "<table width=100%>\n";
89 &traverse("", 0);
90 print "</table>\n";
91 if ($hasclasses) {
92         print "<a href='closeall.cgi?id=$in{'id'}'>$text{'host_close'}</a>\n";
93         print "<a href='openall.cgi?id=$in{'id'}'>$text{'host_open'}</a><p>\n";
94         }
95
96 &ui_print_footer("", $text{'index_return'});
97
98 sub traverse
99 {
100 local($s, $act, $i);
101 print "<tr> <td>", $spacer x $_[1];
102 if ($_[0]) {
103         print "<a name=\"$_[0]\"></a>\n";
104         $act = $heiropen{$_[0]} ? "close" : "open";
105         print "<a href=\"$act.cgi?id=$in{'id'}&what=",&urlize($_[0]),"\">";
106         $_[0] =~ /([^\/]+)$/;
107         print "<img border=0 src=images/$act.gif></a>&nbsp; $1</td>\n",
108         }
109 else { print "<img src=images/close.gif> <i>$text{'host_all'}</i></td>\n"; }
110 print "<td><br></td> </tr>\n";
111 if ($heiropen{$_[0]}) {
112         # print sub-folders followed by packages
113         foreach $i (@packages) {
114                 if ($i->{'class'} eq $_[0]) {
115                         print "<tr> <td>", $spacer x ($_[1]+1);
116                         print "<img border=0 src=images/pack.gif></a>&nbsp;\n";
117                         print "<a href=\"edit_pack.cgi?package=",
118                              &urlize($i->{'name'}),"\">$i->{'name'}</a></td>\n";
119                         print "<td>$i->{'desc'}</td>\n";
120                         print "</tr>\n";
121                         }
122                 }
123         foreach $s (&unique(split(/\0+/, $heir{$_[0]}))) {
124                 &traverse($s, $_[1]+1);
125                 }
126         }
127 }
128