]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - html/cgi-bin/media.cgi
Forward Firewall: fixed 12 Bugs from forum.
[people/teissler/ipfire-2.x.git] / html / cgi-bin / media.cgi
CommitLineData
72fe12a9 1#!/usr/bin/perl
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
ea31a62a 5# Copyright (C) 2007-2013 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
22use strict;
23
24# enable only the following on debugging purpose
cb5e9c6c
CS
25#use warnings;
26#use CGI::Carp 'fatalsToBrowser';
72fe12a9
MT
27
28require '/var/ipfire/general-functions.pl';
29require "${General::swroot}/lang.pl";
30require "${General::swroot}/header.pl";
350b52c5 31require "${General::swroot}/graphs.pl";
72fe12a9 32
4e481c3a
CS
33my %color = ();
34my %mainsettings = ();
35&General::readhash("${General::swroot}/main/settings", \%mainsettings);
36&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
37
72fe12a9
MT
38#workaround to suppress a warning when a variable is used only once
39my @dummy = ( ${Header::colourred} );
40undef (@dummy);
41
42my %cgiparams=();
43
4e481c3a
CS
44my @querry = split(/\?/,$ENV{'QUERY_STRING'});
45$querry[0] = '' unless defined $querry[0];
46$querry[1] = 'hour' unless defined $querry[1];
72fe12a9 47
ea31a62a 48my @devices = `ls -1 /sys/block | grep -E '^sd|^mmcblk|^xvd|^vd|^md' | sort | uniq`;
72fe12a9 49
ea31a62a 50if ( $querry[0] =~ "sd?" || $querry[0] =~ "mmcblk?" || $querry[0] =~ "xvd??" || $querry[0] =~ "vd?" || $querry[0] =~ "md*" ){
4e481c3a
CS
51 print "Content-type: image/png\n\n";
52 binmode(STDOUT);
53
54 &Graphs::updatediskgraph($querry[0],$querry[1]);
55}else{
56 &Header::showhttpheaders();
57 &Header::openpage($Lang::tr{'media information'}, 1, '');
58 &Header::openbigbox('100%', 'left');
59
60 foreach (@devices) {
61 my $device = $_;
62 chomp($device);
63 my @array = split(/\//,$device);
64 &Header::openbox('100%', 'center', "$array[$#array] $Lang::tr{'graph'}");
65 diskbox($array[$#array]);
66 &Graphs::makegraphbox("media.cgi",$array[$#array],"day");
67 &Header::closebox();
68 }
69
70
71 &Header::openbox('100%', 'center', $Lang::tr{'disk usage'});
72 print "<table width='95%' cellspacing='5'>\n";
b18bad8a 73 open(DF,'/bin/df -P -B M -x rootfs|');
4e481c3a
CS
74 while(<DF>){
75 if ($_ =~ m/^Filesystem/ ){
76 print <<END
72fe12a9
MT
77<tr>
78<td align='center' class='boldbase'><b>$Lang::tr{'device'}</b></td>
79<td align='center' class='boldbase'><b>$Lang::tr{'mounted on'}</b></td>
80<td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
81<td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
82<td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
83<td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
84</tr>
85END
86;
4e481c3a
CS
87 }else{
88 my ($device,$size,$used,$free,$percent,$mount) = split;
89 print <<END
72fe12a9
MT
90<tr>
91<td align='center'>$device</td>
92<td align='center'>$mount</td>
93<td align='center'>$size</td>
94<td align='center'>$used</td>
95<td align='center'>$free</td>
96<td align='left'>
97END
98;
4e481c3a
CS
99 &percentbar($percent);
100 print <<END
72fe12a9
MT
101</td>
102<td align='left'>$percent</td>
103</tr>
104END
105;
4e481c3a
CS
106 }
107 }
108 close DF;
109 print "<tr><td colspan='7'>&nbsp;\n<tr><td colspan='7'><h3>Inodes</h3>\n";
72fe12a9 110
b18bad8a 111 open(DF,'/bin/df -P -i -x rootfs|');
4e481c3a
CS
112 while(<DF>){
113 if ($_ =~ m/^Filesystem/ ){
114 print <<END
72fe12a9
MT
115<tr>
116<td align='center' class='boldbase'><b>$Lang::tr{'device'}</b></td>
117<td align='center' class='boldbase'><b>$Lang::tr{'mounted on'}</b></td>
118<td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
119<td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
120<td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
121<td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
122</tr>
123END
124;
4e481c3a
CS
125 }else{
126 my ($device,$size,$used,$free,$percent,$mount) = split;
127 print <<END
72fe12a9
MT
128<tr>
129<td align='center'>$device</td>
130<td align='center'>$mount</td>
131<td align='center'>$size</td>
132<td align='center'>$used</td>
133<td align='center'>$free</td>
134<td>
135END
136;
4e481c3a
CS
137 &percentbar($percent);
138 print <<END
72fe12a9
MT
139</td>
140<td align='left'>$percent</td>
141</tr>
142END
143;
4e481c3a
CS
144 }
145 }
146 close DF;
147 my @iostat1 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$1}');
148 my @iostat2 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$5}');
149 my @iostat3 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$6}');
150 print "<tr><td colspan='3'>&nbsp;\n<tr><td colspan='3'><h3>transfers</h3></td></tr>";
151 my $i=0;
152
153 for(my $i = 1; $i <= $#iostat1; $i++){
154 if ( $i eq '1' ){
155 print "<tr><td align='center' class='boldbase'><b>Device</b></td><td align='center' class='boldbase'><b>MB read</b></td><td align='center' class='boldbase'><b>MB writen</b></td></tr>";
156 }else{
157 print "<tr><td align='center'>$iostat1[$i]</td><td align='center'>$iostat2[$i]</td><td align='center'>$iostat3[$i]</td></tr>";
158 }
159 }
160 print "</table>\n";
161 &Header::closebox();
72fe12a9 162
4e481c3a
CS
163 &Header::closebigbox();
164 &Header::closepage();
165}
72fe12a9
MT
166
167sub percentbar
168{
169 my $percent = $_[0];
170 my $fg = '#a0a0a0';
171 my $bg = '#e2e2e2';
172
173 if ($percent =~ m/^(\d+)%$/ )
174 {
175 print <<END
176<table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
177<tr>
178END
179;
180 if ($percent eq "100%") {
181 print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
182 } elsif ($percent eq "0%") {
183 print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
184 } else {
185 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'>"
186 }
187 print <<END
188<img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>
189END
190;
191 }
192}
193
194sub diskbox {
4e481c3a
CS
195 my $disk = $_[0];
196 chomp $disk;
197 my @status;
965f4547
AF
198 if (-e "/var/run/hddstatus"){
199 open(DATEI, "</var/run/hddstatus") || die "Datei nicht gefunden";
4e481c3a
CS
200 my @diskstate = <DATEI>;
201 close(DATEI);
202
203 foreach (@diskstate){
204 if ( $_ =~/$disk/ ){@status = split(/-/,$_);}
205 }
206
207 if ( $status[1]=~/standby/){
965f4547 208 my $ftime = localtime((stat("/var/run/hddshutdown-$disk"))[9]);
4e481c3a
CS
209 print"<B>Disk $disk status:<font color=#FF0000>".$status[1]."</font></B> (since $ftime)";
210 }else{
211 print"<B>Disk $disk status:<font color=#00FF00>".$status[1]."</font></B>";
212 }
213 }
214
215 my $smart = `/usr/local/bin/smartctrl $disk`;
216 $smart = &Header::cleanhtml($smart);
217 print <<END
218<br /><input type="button" onClick="swapVisibility('smart_$disk')" value="$Lang::tr{'smart information'}" />
219<div id='smart_$disk' style='display: none'>
220 <hr /><table border=0><tr><td align=left><pre>$smart</pre></table>
221</div>
72fe12a9
MT
222END
223;
72fe12a9 224}