forked from riccardonobile/Bootstrap3-Webmin-Theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
body.cgi
295 lines (292 loc) · 9.21 KB
/
body.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/usr/bin/perl
BEGIN { push(@INC, ".."); };
use WebminCore;
&ReadParse();
&init_config();
&load_theme_library();
if (&get_product_name() eq "usermin") {
$level = 3;
}
else {
$level = 0;
}
%text = &load_language($current_theme);
&header($title);
print '<div id="wrapper" class="page">' . "\n";
print '<div class="container">' . "\n";
print '<div id="system-status" class="panel panel-default" style="margin-top: 20px">' . "\n";
print '<div class="panel-heading">' . "\n";
print '<h3 class="panel-title">' . &text('body_header0') . '</h3>' . "\n";
print '</div>';
print '<div class="panel-body">' . "\n";
if ($level == 0) {
# Ask status module for collected info
&foreign_require("system-status");
$info = &system_status::get_collected_info();
# Circle Progress Container
print '<div class="row" style="margin: 0;">' . "\n";
$col_width = &get_col_num($info, 12);
# CPU Usage
if ($info->{'cpu'}) {
@c = @{$info->{'cpu'}};
$used = $c[0]+$c[1]+$c[3];
&print_progressbar_colum(6, $col_width, $used, 'CPU');
}
# MEM e VIRT Usage
if ($info->{'mem'}) {
@m = @{$info->{'mem'}};
if (@m && $m[0]) {
$used = ($m[0]-$m[1])/$m[0]*100;
&print_progressbar_colum(6, $col_width, $used, 'MEM');
}
if (@m && $m[2]) {
$used = ($m[2]-$m[3])/$m[2]*100;
&print_progressbar_colum(6, $col_width, $used, 'VIRT');
}
}
# HDD Usage
if ($info->{'disk_total'}) {
($total, $free) = ($info->{'disk_total'}, $info->{'disk_free'});
$used = ($total-$free)/$total*100;
&print_progressbar_colum(6, $col_width, $used, 'HDD');
}
print '</div>' . "\n";
# Info table
print '<table class="table table-hover">' . "\n";
# Hostname Info
$ip = $info && $info->{'ips'} ? $info->{'ips'}->[0]->[0] : &to_ipaddress(get_system_hostname());
$ip = " ($ip)" if ($ip);
$host = &get_system_hostname() . $ip;
if (&foreign_available("net")) {
$host = '<a href="net/list_dns.cgi">' . $host . '</a>';
}
&print_table_row(&text('body_host'), $host);
# Operating System Info
if ($gconfig{'os_version'} eq '*') {
$os = $gconfig{'real_os_type'};
} else {
$os = $gconfig{'real_os_type'} . ' ' . $gconfig{'real_os_version'};
}
&print_table_row(&text('body_os'), $os);
# Webmin version
&print_table_row(&text('body_webmin'), &get_webmin_version());
#System Time
$tm = localtime(time());
if (&foreign_available("time")) {
$tm = '<a href=time/>' . $tm . '</a>';
}
&print_table_row(&text('body_time'), $tm);
# Kernel and CPU Info
if ($info->{'kernel'}) {
&print_table_row(&text('body_kernel'), &text('body_kernelon', $info->{'kernel'}->{'os'}, $info->{'kernel'}->{'version'}, $info->{'kernel'}->{'arch'}));
}
# CPU Type and cores
if ($info->{'load'}) {
@c = @{$info->{'load'}};
if (@c > 3) {
&print_table_row($text{'body_cpuinfo'}, &text('body_cputype', @c));
}
}
# Temperatures Info (if available)
if ($info->{'cputemps'}) {
foreach my $t (@{$info->{'cputemps'}}) {
$cputemp .= 'Core ' . $t->{'core'} . ': ' . int($t->{'temp'}) . '°C<br>';
}
&print_table_row($text{'body_cputemps'}, $cputemp);
}
if ($info->{'drivetemps'}) {
foreach my $t (@{$info->{'drivetemps'}}) {
my $short = $t->{'device'};
$short =~ s/^\/dev\///;
my $emsg;
if ($t->{'errors'}) {
$emsg .= ' (<span class="text-danger">' . &text('body_driveerr', $t->{'errors'}) . "</span>)";
}
elsif ($t->{'failed'}) {
$emsg .= ' (<span class="text-danger">' . &text('body_drivefailed') . '</span>)';
}
$hddtemp .= $short . ': ' . int($t->{'temp'}) . '°C<br>' . $emsg;
}
&print_table_row($text{'body_drivetemps'}, $hddtemp);
}
# System uptime
&foreign_require("proc");
my $uptime;
my ($d, $h, $m) = &proc::get_system_uptime();
if ($d) {
$uptime = &text('body_updays', $d, $h, $m);
}
elsif ($m) {
$uptime = &text('body_uphours', $h, $m);
}
elsif ($m) {
$uptime = &text('body_upmins', $m);
}
if ($uptime) {
if (&foreign_available("init")) {
$uptime = '<a href=init/>' . $uptime . '</a>';
}
&print_table_row($text{'body_uptime'}, $uptime);
}
# Running processes
if (&foreign_check("proc")) {
@procs = &proc::list_processes();
$pr = scalar(@procs);
if (&foreign_available("proc")) {
$pr = '<a href=proc/>' . $pr . '</a>';
}
&print_table_row($text{'body_procs'}, $pr);
}
# Load averages
if ($info->{'load'}) {
@c = @{$info->{'load'}};
if (@c) {
&print_table_row($text{'body_cpu'}, &text('body_load', @c));
}
}
# Package updates
if ($info->{'poss'}) {
@poss = @{$info->{'poss'}};
@secs = grep { $_->{'security'} } @poss;
if (@poss && @secs) {
$msg = &text('body_upsec', scalar(@poss), scalar(@secs));
}
elsif (@poss) {
$msg = &text('body_upneed', scalar(@poss));
}
else {
$msg = $text{'body_upok'};
}
if (&foreign_available("package-updates")) {
$msg = '<a href="package-updates/index.cgi?mode=updates">' . $msg . '</a>';
}
&print_table_row($text{'body_updates'}, $msg);
}
print '</table>' . "\n";
# Webmin notifications
print '</div>' . "\n";
if (&foreign_check("webmin")) {
&foreign_require("webmin", "webmin-lib.pl");
my @notifs = &webmin::get_webmin_notifications();
if (@notifs) {
print '<div class="panel-footer">' . "\n";
print "<center>\n",join("<hr>\n", @notifs),"</center>\n";
print '</div>' . "\n";
}
# print scalar(@notifs);
}
} elsif ($level == 3) {
print '<table class="table table-hover">' . "\n";
# Host and login info
&print_table_row(&text('body_host'), &get_system_hostname());
# Operating System Info
if ($gconfig{'os_version'} eq '*') {
$os = $gconfig{'real_os_type'};
} else {
$os = $gconfig{'real_os_type'} . ' ' . $gconfig{'real_os_version'};
}
&print_table_row(&text('body_os'), $os);
# Webmin version
&print_table_row(&text('body_usermin'), &get_webmin_version());
#System Time
$tm = localtime(time());
if (&foreign_available("time")) {
$tm = '<a href=time/>' . $tm . '</a>';
}
&print_table_row(&text('body_time'), $tm);
# Disk quotas -- !!!!!
if (&foreign_installed("quota")) {
&foreign_require("quota", "quota-lib.pl");
$n = "a::user_filesystems($remote_user);
$usage = 0;
$quota = 0;
for($i=0; $i<$n; $i++) {
if ($quota::filesys{$i,'hblocks'}) {
$quota += $quota::filesys{$i,'hblocks'};
$usage += $quota::filesys{$i,'ublocks'};
}
elsif ($quota::filesys{$i,'sblocks'}) {
$quota += $quota::filesys{$i,'sblocks'};
$usage += $quota::filesys{$i,'ublocks'};
}
}
if ($quota) {
$bsize = $quota::config{'block_size'};
print '<tr>' . "\n";
print '<td><strong>' . $text{'body_uquota'} . '</strong></td>' . "\n";
print '<td>' . &text('right_out', &nice_size($usage*$bsize), &nice_size($quota*$bsize)), '</td>' . "\n";
print '</tr>' . "\n";
print '<tr>' . "\n";
print '<td></td>' . "\n";
print '<td>' . "\n";
print '<div class="progress">' . "\n";
$used = $usage/$quota*100;
print '<div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="' . $used . '" aria-valuemin="0" aria-valuemax="100" style="width: ' . $used . '%">' . "\n";
print '</div>' . "\n";
print '</div>' . "\n";
print '</td>' . "\n";
print '</tr>' . "\n";
}
}
print '</table>' . "\n";
}
# End of page
print '</div>' . "\n";
#print '<p id="about">Template developed and written by <a href="https://www.facebook.com/RiccardoNob" target="_blank">Riccardo Nobile</a> & <a href="https://www.facebook.com/simone.cragnolini" target="_blank">Simone Cragnolini</a></p>' . "\n";
#print '<p id="about"><a href="http://winfuture.it/" target="_blank">WinFuture</a></p>' . "\n";
print '</div>' . "\n";
#print '</div>' . "\n";
&footer();
sub print_progressbar_colum {
my ($xs, $sm, $percent, $label) = @_;
use POSIX;
$percent = ceil($percent);
if ($percent < 75) {
$class = 'success';
} elsif ($percent < 90) {
$class = 'warning';
} else {
$class = 'danger';
}
print '<div class="col-xs-' . $xs . ' col-sm-' . $sm . '">' . "\n";
print '<div data-progress="' . $percent . '" class="progress progress-circle">' . "\n";
print '<div class="progress-bar-circle progress-bar-' . $class . '">' . "\n";
print '<div class="progress-bar-circle-mask progress-bar-circle-full">' . "\n";
print '<div class="progress-bar-circle-fill"></div>' . "\n";
print '</div>' . "\n";
print '<div class="progress-bar-circle-mask progress-bar-circle-half">' . "\n";
print '<div class="progress-bar-circle-fill"></div>' . "\n";
print '<div class="progress-bar-circle-fill progress-bar-circle-fix"></div>' . "\n";
print '</div>' . "\n";
print '<div class="progress-bar-circle-inset">' . "\n";
print '<div class="progress-bar-circle-title">' . "\n";
print '<strong class="text-muted">' . $label . '</strong>' . "\n";
print '</div>' . "\n";
print '<div class="progress-bar-circle-percent">' . "\n";
print '<span></span>' . "\n";
print '</div>' . "\n";
print '</div>' . "\n";
print '</div>' . "\n";
print '</div>' . "\n";
print '</div>' . "\n";
}
sub get_col_num {
my ($info, $max_col) = @_;
my $num_col = 0;
if ($info->{'cpu'}) { $num_col++; }
if ($info->{'mem'}) {
@m = @{$info->{'mem'}};
if (@m && $m[0]) { $num_col++; }
if (@m && $m[2]) { $num_col++; }
}
if ($info->{'disk_total'}) { $num_col++; }
my $col = $max_col / $num_col;
return $col;
}
sub print_table_row {
local ($title, $content) = @_;
print '<tr>' . "\n";
print '<td><strong>' . $title . '</strong></td>' . "\n";
print '<td>' . $content . '</td>' . "\n";
print '</tr>' . "\n";
}