]>
Commit | Line | Data |
---|---|---|
72fe12a9 | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
52f81186 | 5 | # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> # |
70df8302 MT |
6 | # # |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
72fe12a9 MT |
21 | |
22 | use strict; | |
23 | ||
24 | # enable only the following on debugging purpose | |
cb5e9c6c CS |
25 | #use warnings; |
26 | #use CGI::Carp 'fatalsToBrowser'; | |
72fe12a9 MT |
27 | |
28 | require '/var/ipfire/general-functions.pl'; | |
29 | require "${General::swroot}/lang.pl"; | |
30 | require "${General::swroot}/header.pl"; | |
350b52c5 | 31 | require "${General::swroot}/graphs.pl"; |
72fe12a9 | 32 | |
4e481c3a CS |
33 | my %color = (); |
34 | my %mainsettings = (); | |
35 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
8186b372 | 36 | &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color); |
4e481c3a | 37 | |
72fe12a9 MT |
38 | #workaround to suppress a warning when a variable is used only once |
39 | my @dummy = ( ${Header::colourred} ); | |
40 | undef (@dummy); | |
41 | ||
42 | my %cgiparams=(); | |
43 | ||
ca9c45b3 | 44 | my @devices = `ls -1 /sys/block | grep -E '^sd|^mmcblk|^nvme|^xvd|^vd|^md' | sort | uniq`; |
72fe12a9 | 45 | |
4190b2a6 LAH |
46 | &Header::showhttpheaders(); |
47 | &Header::openpage($Lang::tr{'media information'}, 1, ''); | |
48 | &Header::openbigbox('100%', 'left'); | |
49 | ||
50 | foreach (@devices) { | |
51 | my $device = $_; | |
52 | chomp($device); | |
53 | my @array = split(/\//,$device); | |
54 | &Header::openbox('100%', 'center', "$array[$#array] $Lang::tr{'graph'}"); | |
55 | diskbox($array[$#array]); | |
56 | &Graphs::makegraphbox("media.cgi",$array[$#array],"day"); | |
57 | &Header::closebox(); | |
58 | } | |
59 | ||
4e481c3a | 60 | |
4190b2a6 LAH |
61 | &Header::openbox('100%', 'center', $Lang::tr{'disk usage'}); |
62 | print "<table width='95%' cellspacing='5'>\n"; | |
63 | open(DF,'/bin/df -P -B M -x rootfs|'); | |
64 | while(<DF>){ | |
65 | if ($_ =~ m/^Filesystem/ ){ | |
66 | print <<END | |
72fe12a9 | 67 | <tr> |
4190b2a6 LAH |
68 | <td align='center' class='boldbase'><b>$Lang::tr{'device'}</b></td> |
69 | <td align='center' class='boldbase'><b>$Lang::tr{'mounted on'}</b></td> | |
70 | <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td> | |
71 | <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td> | |
72 | <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td> | |
73 | <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td> | |
72fe12a9 MT |
74 | </tr> |
75 | END | |
76 | ; | |
4190b2a6 LAH |
77 | }else{ |
78 | my ($device,$size,$used,$free,$percent,$mount) = split; | |
79 | print <<END | |
72fe12a9 | 80 | <tr> |
4190b2a6 LAH |
81 | <td align='center'>$device</td> |
82 | <td align='center'>$mount</td> | |
83 | <td align='center'>$size</td> | |
84 | <td align='center'>$used</td> | |
85 | <td align='center'>$free</td> | |
86 | <td align='left'> | |
72fe12a9 MT |
87 | END |
88 | ; | |
4190b2a6 LAH |
89 | &percentbar($percent); |
90 | print <<END | |
72fe12a9 | 91 | </td> |
4190b2a6 | 92 | <td align='left'>$percent</td> |
72fe12a9 MT |
93 | </tr> |
94 | END | |
95 | ; | |
4e481c3a | 96 | } |
4190b2a6 LAH |
97 | } |
98 | close DF; | |
52f81186 | 99 | print "<tr><td colspan='7'> \n<tr><td colspan='7'><h3>$Lang::tr{'inodes'}</h3>\n"; |
72fe12a9 | 100 | |
4190b2a6 LAH |
101 | open(DF,'/bin/df -P -i -x rootfs|'); |
102 | while(<DF>){ | |
103 | if ($_ =~ m/^Filesystem/ ){ | |
104 | print <<END | |
72fe12a9 | 105 | <tr> |
4190b2a6 LAH |
106 | <td align='center' class='boldbase'><b>$Lang::tr{'device'}</b></td> |
107 | <td align='center' class='boldbase'><b>$Lang::tr{'mounted on'}</b></td> | |
108 | <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td> | |
109 | <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td> | |
110 | <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td> | |
111 | <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td> | |
72fe12a9 MT |
112 | </tr> |
113 | END | |
114 | ; | |
4190b2a6 LAH |
115 | }else{ |
116 | my ($device,$size,$used,$free,$percent,$mount) = split; | |
117 | print <<END | |
72fe12a9 | 118 | <tr> |
4190b2a6 LAH |
119 | <td align='center'>$device</td> |
120 | <td align='center'>$mount</td> | |
121 | <td align='center'>$size</td> | |
122 | <td align='center'>$used</td> | |
123 | <td align='center'>$free</td> | |
72fe12a9 MT |
124 | <td> |
125 | END | |
126 | ; | |
4190b2a6 LAH |
127 | &percentbar($percent); |
128 | print <<END | |
72fe12a9 MT |
129 | </td> |
130 | <td align='left'>$percent</td> | |
131 | </tr> | |
132 | END | |
133 | ; | |
4e481c3a | 134 | } |
4190b2a6 LAH |
135 | } |
136 | close DF; | |
137 | my @iostat1 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$1}'); | |
844f40be MT |
138 | my @iostat2 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$6}'); |
139 | my @iostat3 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$7}'); | |
ae2d7a3f | 140 | print "<tr><td colspan='3'> \n<tr><td colspan='3'><h3>$Lang::tr{'transfers'}</h3></td></tr>"; |
4190b2a6 LAH |
141 | my $i=0; |
142 | ||
143 | for(my $i = 1; $i <= $#iostat1; $i++){ | |
144 | if ( $i eq '1' ){ | |
145 | print "<tr><td align='center' class='boldbase'><b>$Lang::tr{'device'}</b></td><td align='center' class='boldbase'><b>$Lang::tr{'MB read'}</b></td><td align='center' class='boldbase'><b>$Lang::tr{'MB written'}</b></td></tr>"; | |
146 | }else{ | |
147 | print "<tr><td align='center'>$iostat1[$i]</td><td align='center'>$iostat2[$i]</td><td align='center'>$iostat3[$i]</td></tr>"; | |
4e481c3a | 148 | } |
4190b2a6 LAH |
149 | } |
150 | print "</table>\n"; | |
151 | &Header::closebox(); | |
72fe12a9 | 152 | |
4190b2a6 LAH |
153 | &Header::closebigbox(); |
154 | &Header::closepage(); | |
72fe12a9 MT |
155 | |
156 | sub percentbar | |
157 | { | |
158 | my $percent = $_[0]; | |
159 | my $fg = '#a0a0a0'; | |
160 | my $bg = '#e2e2e2'; | |
161 | ||
162 | if ($percent =~ m/^(\d+)%$/ ) | |
163 | { | |
164 | print <<END | |
165 | <table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'> | |
166 | <tr> | |
167 | END | |
168 | ; | |
169 | if ($percent eq "100%") { | |
170 | print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>" | |
171 | } elsif ($percent eq "0%") { | |
172 | print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>" | |
173 | } else { | |
174 | print "<td width='$percent' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'></td><td width='" . (100-$1) . "%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>" | |
175 | } | |
176 | print <<END | |
177 | <img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table> | |
178 | END | |
179 | ; | |
180 | } | |
181 | } | |
182 | ||
183 | sub diskbox { | |
4e481c3a CS |
184 | my $disk = $_[0]; |
185 | chomp $disk; | |
186 | my @status; | |
965f4547 AF |
187 | if (-e "/var/run/hddstatus"){ |
188 | open(DATEI, "</var/run/hddstatus") || die "Datei nicht gefunden"; | |
4e481c3a CS |
189 | my @diskstate = <DATEI>; |
190 | close(DATEI); | |
191 | ||
192 | foreach (@diskstate){ | |
193 | if ( $_ =~/$disk/ ){@status = split(/-/,$_);} | |
194 | } | |
195 | ||
196 | if ( $status[1]=~/standby/){ | |
965f4547 | 197 | my $ftime = localtime((stat("/var/run/hddshutdown-$disk"))[9]); |
8b40eca5 | 198 | print"<b>Disk $disk status:<span style='color:#FF0000'>".$status[1]."</b> ($Lang::tr{'since'} $ftime)"; |
4e481c3a | 199 | }else{ |
8b40eca5 | 200 | print"<b>Disk $disk status:<span style='color:#00FF00'>".$status[1]."</b>"; |
4e481c3a CS |
201 | } |
202 | } | |
203 | ||
204 | my $smart = `/usr/local/bin/smartctrl $disk`; | |
205 | $smart = &Header::cleanhtml($smart); | |
206 | print <<END | |
207 | <br /><input type="button" onClick="swapVisibility('smart_$disk')" value="$Lang::tr{'smart information'}" /> | |
208 | <div id='smart_$disk' style='display: none'> | |
a4455e73 | 209 | <hr /><table border='0'><tr><td align='left'><pre>$smart</pre></table> |
4e481c3a | 210 | </div> |
72fe12a9 MT |
211 | END |
212 | ; | |
72fe12a9 | 213 | } |