]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/media.cgi
die fehlenden Anpassungen fuer die komischen Devicenamen
[people/pmueller/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) 2007 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 #workaround to suppress a warning when a variable is used only once
34 my @dummy = ( ${Header::colourred} );
35 undef (@dummy);
36
37 my %cgiparams=();
38
39 &Header::showhttpheaders();
40
41 &Header::getcgihash(\%cgiparams);
42
43 &Header::openpage($Lang::tr{'media information'}, 1, '');
44
45 &Header::openbigbox('100%', 'left');
46
47 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
48
49 foreach (@devices) {
50 my $device = $_;
51 chomp($device);
52 my @array = split(/\//,$device);
53 &Graphs::updatediskgraph ("day",$array[$#array]);
54 diskbox($array[$#array]);
55 }
56
57 &Header::openbox('100%', 'center', $Lang::tr{'disk usage'});
58 print "<table width='95%' cellspacing='5'>\n";
59 open(DF,'/bin/df -B M -x rootfs|');
60 while(<DF>)
61 {
62 if ($_ =~ m/^Filesystem/ )
63 {
64 print <<END
65 <tr>
66 <td align='center' class='boldbase'><b>$Lang::tr{'device'}</b></td>
67 <td align='center' class='boldbase'><b>$Lang::tr{'mounted on'}</b></td>
68 <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
69 <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
70 <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
71 <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
72 </tr>
73 END
74 ;
75 }
76 else
77 {
78 my ($device,$size,$used,$free,$percent,$mount) = split;
79 print <<END
80 <tr>
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'>
87 END
88 ;
89 &percentbar($percent);
90 print <<END
91 </td>
92 <td align='left'>$percent</td>
93 </tr>
94 END
95 ;
96 }
97 }
98 close DF;
99 print "<tr><td colspan='7'>&nbsp;\n<tr><td colspan='7'><h3>Inodes</h3>\n";
100
101 open(DF,'/bin/df -i -x rootfs|');
102 while(<DF>)
103 {
104 if ($_ =~ m/^Filesystem/ )
105 {
106 print <<END
107 <tr>
108 <td align='center' class='boldbase'><b>$Lang::tr{'device'}</b></td>
109 <td align='center' class='boldbase'><b>$Lang::tr{'mounted on'}</b></td>
110 <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
111 <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
112 <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
113 <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
114 </tr>
115 END
116 ;
117 }
118 else
119 {
120 my ($device,$size,$used,$free,$percent,$mount) = split;
121 print <<END
122 <tr>
123 <td align='center'>$device</td>
124 <td align='center'>$mount</td>
125 <td align='center'>$size</td>
126 <td align='center'>$used</td>
127 <td align='center'>$free</td>
128 <td>
129 END
130 ;
131 &percentbar($percent);
132 print <<END
133 </td>
134 <td align='left'>$percent</td>
135 </tr>
136 END
137 ;
138 }
139 }
140 close DF;
141 my @iostat1 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$1}');
142 my @iostat2 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$5}');
143 my @iostat3 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$6}');
144 print "<tr><td colspan='3'>&nbsp;\n<tr><td colspan='3'><h3>transfers</h3></td></tr>";
145 my $i=0;
146
147 for(my $i = 1; $i <= $#iostat1; $i++)
148 {
149 if ( $i eq '1' ){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>";}
150 else {print "<tr><td align='center'>$iostat1[$i]</td><td align='center'>$iostat2[$i]</td><td align='center'>$iostat3[$i]</td></tr>";}
151 }
152 print "</table>\n";
153 &Header::closebox();
154
155 &Header::closebigbox();
156
157 &Header::closepage();
158
159 sub percentbar
160 {
161 my $percent = $_[0];
162 my $fg = '#a0a0a0';
163 my $bg = '#e2e2e2';
164
165 if ($percent =~ m/^(\d+)%$/ )
166 {
167 print <<END
168 <table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
169 <tr>
170 END
171 ;
172 if ($percent eq "100%") {
173 print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
174 } elsif ($percent eq "0%") {
175 print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
176 } else {
177 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'>"
178 }
179 print <<END
180 <img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>
181 END
182 ;
183 }
184 }
185
186 sub diskbox {
187 my $disk = $_[0];
188 chomp $disk;
189 my @status;
190 if (-e "$Header::graphdir/disk-$disk-day.png") {
191 &Header::openbox('100%', 'center', "Disk $disk $Lang::tr{'graph'}");
192 my $ftime = localtime((stat("$Header::graphdir/disk-$disk-day.png"))[9]);
193 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
194 print "<a href='/cgi-bin/graphs.cgi?graph=disk-$disk'>";
195 print "<img alt='' src='/graphs/disk-$disk-day.png' border='0' />";
196 print "</a>";
197 print "<br />\n";
198
199 if (-e "/tmp/hddstatus") {
200 open(DATEI, "</tmp/hddstatus") || die "Datei nicht gefunden";
201 my @diskstate = <DATEI>;
202 close(DATEI);
203
204 foreach (@diskstate){
205 if ( $_ =~/$disk/ ){@status = split(/-/,$_);}
206 }
207
208 if ( $status[1]=~/standby/){
209 my $ftime = localtime((stat("/tmp/hddshutdown-$disk"))[9]);
210 print"<B>Disk $disk status:<font color=#FF0000>".$status[1]."</font></B> (since $ftime)";
211 }
212 else{
213 print"<B>Disk $disk status:<font color=#00FF00>".$status[1]."</font></B>";
214 }
215 }
216 my $smart = `/usr/local/bin/smartctrl $disk`;
217 $smart = &Header::cleanhtml($smart);
218 print <<END
219 <br /><input type="button" onClick="swapVisibility('smart_$disk')" value="$Lang::tr{'smart information'}" />
220 <div id='smart_$disk' style='display: none'>
221 <hr /><table border=0><tr><td align=left><pre>$smart</pre></table>
222 </div>
223 END
224 ;
225 &Header::closebox();
226 }
227 }