]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/media.cgi
Merge branch 'work'
[people/teissler/ipfire-2.x.git] / html / cgi-bin / media.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2008 Michael Tremer & Christian Schmidt #
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 ###############################################################################
21
22 use strict;
23
24 # enable only the following on debugging purpose
25 #use warnings;
26 #use CGI::Carp 'fatalsToBrowser';
27
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
31 require "${General::swroot}/graphs.pl";
32
33 my %color = ();
34 my %mainsettings = ();
35 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
36 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
37
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
44 my @querry = split(/\?/,$ENV{'QUERY_STRING'});
45 $querry[0] = '' unless defined $querry[0];
46 $querry[1] = 'hour' unless defined $querry[1];
47
48 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
49
50 if ( $querry[0] =~ "sd?" || $querry[0] =~ "hd?" ){
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";
73 open(DF,'/bin/df -B M -x rootfs|');
74 while(<DF>){
75 if ($_ =~ m/^Filesystem/ ){
76 print <<END
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>
85 END
86 ;
87 }else{
88 my ($device,$size,$used,$free,$percent,$mount) = split;
89 print <<END
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'>
97 END
98 ;
99 &percentbar($percent);
100 print <<END
101 </td>
102 <td align='left'>$percent</td>
103 </tr>
104 END
105 ;
106 }
107 }
108 close DF;
109 print "<tr><td colspan='7'>&nbsp;\n<tr><td colspan='7'><h3>Inodes</h3>\n";
110
111 open(DF,'/bin/df -i -x rootfs|');
112 while(<DF>){
113 if ($_ =~ m/^Filesystem/ ){
114 print <<END
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>
123 END
124 ;
125 }else{
126 my ($device,$size,$used,$free,$percent,$mount) = split;
127 print <<END
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>
135 END
136 ;
137 &percentbar($percent);
138 print <<END
139 </td>
140 <td align='left'>$percent</td>
141 </tr>
142 END
143 ;
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();
162
163 &Header::closebigbox();
164 &Header::closepage();
165 }
166
167 sub 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>
178 END
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>
189 END
190 ;
191 }
192 }
193
194 sub diskbox {
195 my $disk = $_[0];
196 chomp $disk;
197 my @status;
198 if (-e "/tmp/hddstatus"){
199 open(DATEI, "</tmp/hddstatus") || die "Datei nicht gefunden";
200 my @diskstate = <DATEI>;
201 close(DATEI);
202
203 foreach (@diskstate){
204 if ( $_ =~/$disk/ ){@status = split(/-/,$_);}
205 }
206
207 if ( $status[1]=~/standby/){
208 my $ftime = localtime((stat("/tmp/hddshutdown-$disk"))[9]);
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>
222 END
223 ;
224 }