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