Handle hostnames with upper-case letters
[webmin.git] / blue-theme / right.cgi
1 #!/usr/local/bin/perl
2 # Show server or domain information
3
4 BEGIN { push(@INC, ".."); };
5 use WebminCore;
6 &init_config();
7 &ReadParse();
8 &load_theme_library();
9 if (&get_product_name() eq "usermin") {
10         $level = 3;
11         }
12 else {
13         $level = 0;
14         }
15 %text = &load_language($current_theme);
16 $bar_width = 300;
17 foreach $o (split(/\0/, $in{'open'})) {
18         push(@open, $o);
19         $open{$o} = 1;
20         }
21
22 $prehead = defined(&WebminCore::theme_prehead) ?
23                 &capture_function_output(\&WebminCore::theme_prehead) : "";
24 &popup_header(undef, $prehead);
25 print "<center>\n";
26
27 # Webmin logo
28 if (&get_product_name() eq 'webmin') {
29         print "<a href=http://www.webmin.com/ target=_new><img src=images/webmin-blue.png border=0></a><p>\n";
30         }
31
32 if ($level == 0) {
33         # Show general system information
34         print "<table width=70%>\n";
35
36         # Ask status module for collected info
37         &foreign_require("system-status");
38         $info = &system_status::get_collected_info();
39
40         # Hostname
41         $ip = $info && $info->{'ips'} ? $info->{'ips'}->[0]->[0] :
42                                 &to_ipaddress(get_system_hostname());
43         $ip = " ($ip)" if ($ip);
44         print "<tr> <td><b>$text{'right_host'}</b></td>\n";
45         print "<td>",&get_system_hostname(),$ip,"</td> </tr>\n";
46
47         # Operating system
48         print "<tr> <td><b>$text{'right_os'}</b></td>\n";
49         if ($gconfig{'os_version'} eq '*') {
50                 print "<td>$gconfig{'real_os_type'}</td> </tr>\n";
51                 }
52         else {
53                 print "<td>$gconfig{'real_os_type'} $gconfig{'real_os_version'}</td> </tr>\n";
54                 }
55
56         # Webmin version
57         print "<tr> <td><b>$text{'right_webmin'}</b></td>\n";
58         print "<td>",&get_webmin_version(),"</td> </tr>\n";
59
60         # System time
61         $tm = localtime(time());
62         print "<tr> <td><b>$text{'right_time'}</b></td>\n";
63         if (&foreign_available("time")) {
64                 $tm = "<a href=time/>$tm</a>";
65                 }
66         print "<td>$tm</td> </tr>\n";
67
68         # Kernel and CPU
69         if ($info->{'kernel'}) {
70                 print "<tr> <td><b>$text{'right_kernel'}</b></td>\n";
71                 print "<td>",&text('right_kernelon',
72                                    $info->{'kernel'}->{'os'},
73                                    $info->{'kernel'}->{'version'},
74                                    $info->{'kernel'}->{'arch'}),"</td> </tr>\n";
75                 }
76
77         # CPU type and cores
78         if ($info->{'load'}) {
79                 @c = @{$info->{'load'}};
80                 if (@c > 3) {
81                         print "<tr> <td><b>$text{'right_cpuinfo'}</b></td>\n";
82                         print "<td>",&text('right_cputype', @c),"</td> </tr>\n";
83                         }
84                 }
85
86         # System uptime
87         &foreign_require("proc");
88         my $uptime;
89         my ($d, $h, $m) = &proc::get_system_uptime();
90         if ($d) {
91                 $uptime = &text('right_updays', $d, $h, $m);
92                 }
93         elsif ($m) {
94                 $uptime = &text('right_uphours', $h, $m);
95                 }
96         elsif ($m) {
97                 $uptime = &text('right_upmins', $m);
98                 }
99         if ($uptime) {
100                 print "<tr> <td><b>$text{'right_uptime'}</b></td>\n";
101                 print "<td>$uptime</td> </tr>\n";
102                 }
103
104         # Running processes
105         if (&foreign_check("proc")) {
106                 @procs = &proc::list_processes();
107                 $pr = scalar(@procs);
108                 print "<tr> <td><b>$text{'right_procs'}</b></td>\n";
109                 if (&foreign_available("proc")) {
110                         $pr = "<a href=proc/>$pr</a>";
111                         }
112                 print "<td>$pr</td> </tr>\n";
113                 }
114
115         # Load averages
116         if ($info->{'load'}) {
117                 @c = @{$info->{'load'}};
118                 if (@c) {
119                         print "<tr> <td><b>$text{'right_cpu'}</b></td>\n";
120                         print "<td>",&text('right_load', @c),"</td> </tr>\n";
121                         }
122                 }
123
124         # CPU usage
125         if ($info->{'cpu'}) {
126                 @c = @{$info->{'cpu'}};
127                 print "<tr> <td><b>$text{'right_cpuuse'}</b></td>\n";
128                 print "<td>",&text('right_cpustats', @c),"</td> </tr>\n";
129                 }
130
131         # Memory usage
132         if ($info->{'mem'}) {
133                 @m = @{$info->{'mem'}};
134                 if (@m && $m[0]) {
135                         print "<tr> <td><b>$text{'right_real'}</b></td>\n";
136                         print "<td>",&text('right_used',
137                                 &nice_size($m[0]*1024),
138                                 &nice_size(($m[0]-$m[1])*1024)),
139                               "</td> </tr>\n";
140                         print "<tr> <td></td>\n";
141                         print "<td>",&bar_chart($m[0], $m[0]-$m[1], 1),
142                               "</td> </tr>\n";
143                         }
144
145                 if (@m && $m[2]) {
146                         print "<tr> <td><b>$text{'right_virt'}</b></td>\n";
147                         print "<td>",&text('right_used',
148                                 &nice_size($m[2]*1024),
149                                 &nice_size(($m[2]-$m[3])*1024)),
150                               "</td> </tr>\n";
151                         print "<tr> <td></td>\n";
152                         print "<td>",&bar_chart($m[2], $m[2]-$m[3], 1),
153                               "</td> </tr>\n";
154                         }
155                 }
156
157         # Disk space on local drives
158         if ($info->{'disk_total'}) {
159                 ($total, $free) = ($info->{'disk_total'}, $info->{'disk_free'});
160                 print "<tr> <td><b>$text{'right_disk'}</b></td>\n";
161                 print "<td>",&text('right_used',
162                            &nice_size($total),
163                            &nice_size($total-$free)),"</td> </tr>\n";
164                 print "<tr> <td></td>\n";
165                 print "<td>",&bar_chart($total, $total-$free, 1),
166                       "</td> </tr>\n";
167                 }
168
169         # Package updates
170         if ($info->{'poss'}) {
171                 print "<tr> <td><b>$text{'right_updates'}</b></td>\n";
172                 @poss = @{$info->{'poss'}};
173                 @secs = grep { $_->{'security'} } @poss;
174                 if (@poss && @secs) {
175                         $msg = &text('right_upsec', scalar(@poss),
176                                                     scalar(@secs));
177                         }
178                 elsif (@poss) {
179                         $msg = &text('right_upneed', scalar(@poss));
180                         }
181                 else {
182                         $msg = $text{'right_upok'};
183                         }
184                 if (&foreign_available("package-updates")) {
185                         $msg = "<a href='package-updates/index.cgi?mode=updates'>$msg</a>";
186                         }
187                 print "<td>$msg</td> </tr>\n";
188                 }
189
190         print "</table>\n";
191
192         # Check for incorrect OS
193         if (&foreign_check("webmin")) {
194                 &foreign_require("webmin", "webmin-lib.pl");
195                 &webmin::show_webmin_notifications();
196                 }
197         }
198 elsif ($level == 3) {
199         # Show Usermin user's information
200         print "<h3>$text{'right_header5'}</h3>\n";
201         print "<table width=70%>\n";
202
203         # Host and login info
204         print "<tr> <td><b>$text{'right_host'}</b></td>\n";
205         print "<td>",&get_system_hostname(),"</td> </tr>\n";
206
207         print "<tr> <td><b>$text{'right_os'}</b></td>\n";
208         if ($gconfig{'os_version'} eq '*') {
209                 print "<td>$gconfig{'real_os_type'}</td> </tr>\n";
210                 }
211         else {
212                 print "<td>$gconfig{'real_os_type'} $gconfig{'real_os_version'}</td> </tr>\n";
213                 }
214
215         print "<tr> <td><b>$text{'right_usermin'}</b></td>\n";
216         print "<td>",&get_webmin_version(),"</td> </tr>\n";
217
218         # System time
219         $tm = localtime(time());
220         print "<tr> <td><b>$text{'right_time'}</b></td>\n";
221         print "<td>$tm</td> </tr>\n";
222
223         # Disk quotas
224         if (&foreign_installed("quota")) {
225                 &foreign_require("quota", "quota-lib.pl");
226                 $n = &quota::user_filesystems($remote_user);
227                 $usage = 0;
228                 $quota = 0;
229                 for($i=0; $i<$n; $i++) {
230                         if ($quota::filesys{$i,'hblocks'}) {
231                                 $quota += $quota::filesys{$i,'hblocks'};
232                                 $usage += $quota::filesys{$i,'ublocks'};
233                                 }
234                         elsif ($quota::filesys{$i,'sblocks'}) {
235                                 $quota += $quota::filesys{$i,'sblocks'};
236                                 $usage += $quota::filesys{$i,'ublocks'};
237                                 }
238                         }
239                 if ($quota) {
240                         $bsize = $quota::config{'block_size'};
241                         print "<tr> <td><b>$text{'right_uquota'}</b></td>\n";
242                         print "<td>",&text('right_out',
243                                 &nice_size($usage*$bsize),
244                                 &nice_size($quota*$bsize)),"</td> </tr>\n";
245                         print "<tr> <td></td>\n";
246                         print "<td>",&bar_chart($quota, $usage, 1),
247                               "</td> </tr>\n";
248                         }
249                 }
250         print "</table>\n";
251         }
252
253 print "</center>\n";
254 &popup_footer();
255
256 # bar_chart(total, used, blue-rest)
257 # Returns HTML for a bar chart of a single value
258 sub bar_chart
259 {
260 local ($total, $used, $blue) = @_;
261 local $rv;
262 $rv .= sprintf "<img src=images/red.gif width=%s height=10>",
263         int($bar_width*$used/$total)+1;
264 if ($blue) {
265         $rv .= sprintf "<img src=images/blue.gif width=%s height=10>",
266                 $bar_width - int($bar_width*$used/$total)-1;
267         }
268 else {
269         $rv .= sprintf "<img src=images/white.gif width=%s height=10>",
270                 $bar_width - int($bar_width*$used/$total)-1;
271         }
272 return $rv;
273 }
274
275 # bar_chart_three(total, used1, used2, used3)
276 # Returns HTML for a bar chart of three values, stacked
277 sub bar_chart_three
278 {
279 local ($total, $used1, $used2, $used3) = @_;
280 local $rv;
281 local $w1 = int($bar_width*$used1/$total)+1;
282 local $w2 = int($bar_width*$used2/$total);
283 local $w3 = int($bar_width*$used3/$total);
284 $rv .= sprintf "<img src=images/red.gif width=%s height=10>", $w1;
285 $rv .= sprintf "<img src=images/purple.gif width=%s height=10>", $w2;
286 $rv .= sprintf "<img src=images/blue.gif width=%s height=10>", $w3;
287 $rv .= sprintf "<img src=images/grey.gif width=%s height=10>",
288         $bar_width - $w1 - $w2 - $w3;
289 return $rv;
290 }
291
292 # collapsed_header(text, name)
293 sub collapsed_header
294 {
295 local ($text, $name) = @_;
296 print "<br><font style='font-size:16px'>";
297 local $others = join("&", map { "open=$_" } grep { $_ ne $name } @open);
298 $others = "&$others" if ($others);
299 if ($open{$name}) {
300         print "<img src=images/open.gif border=0>\n";
301         print "<a href='right.cgi?$others'>$text</a>";
302         }
303 else {
304         print "<img src=images/closed.gif border=0>\n";
305         print "<a href='right.cgi?open=$name$others'>$text</a>";
306         }
307 print "</font><br>\n";
308 return $open{$name};
309 }
310