Add new useragents to updater
[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 #
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###############################################################################
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
MT
32
33#workaround to suppress a warning when a variable is used only once
34my @dummy = ( ${Header::colourred} );
35undef (@dummy);
36
37my %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
72fe12a9
MT
47my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
48
49foreach (@devices) {
50 my $device = $_;
51 chomp($device);
5384809b
CS
52 my @array = split(/\//,$device);
53 &Graphs::updatediskgraph ("day",$array[$#array]);
54 diskbox($array[$#array]);
72fe12a9
MT
55}
56
57&Header::openbox('100%', 'center', $Lang::tr{'disk usage'});
58print "<table width='95%' cellspacing='5'>\n";
59open(DF,'/bin/df -B M -x rootfs|');
60while(<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>
73END
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'>
87END
88;
89 &percentbar($percent);
90 print <<END
91</td>
92<td align='left'>$percent</td>
93</tr>
94END
95;
96 }
97}
98close DF;
99print "<tr><td colspan='7'>&nbsp;\n<tr><td colspan='7'><h3>Inodes</h3>\n";
100
101open(DF,'/bin/df -i -x rootfs|');
102while(<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>
115END
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>
129END
130;
131 &percentbar($percent);
132 print <<END
133</td>
134<td align='left'>$percent</td>
135</tr>
136END
137;
138 }
139}
140close DF;
141my @iostat1 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$1}');
142my @iostat2 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$5}');
143my @iostat3 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$6}');
144print "<tr><td colspan='3'>&nbsp;\n<tr><td colspan='3'><h3>transfers</h3></td></tr>";
145my $i=0;
146
147for(my $i = 1; $i <= $#iostat1; $i++)
148{
149if ( $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>";}
4e17adad 150else {print "<tr><td align='center'>$iostat1[$i]</td><td align='center'>$iostat2[$i]</td><td align='center'>$iostat3[$i]</td></tr>";}
72fe12a9
MT
151}
152print "</table>\n";
153&Header::closebox();
154
155&Header::closebigbox();
156
157&Header::closepage();
158
159sub 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>
170END
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>
181END
182;
183 }
184}
185
186sub diskbox {
187 my $disk = $_[0];
3bc32eab
CS
188 chomp $disk;
189 my @status;
72fe12a9 190 if (-e "$Header::graphdir/disk-$disk-day.png") {
5384809b 191 &Header::openbox('100%', 'center', "Disk $disk $Lang::tr{'graph'}");
72fe12a9
MT
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";
3bc32eab
CS
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]);
5384809b 210 print"<B>Disk $disk status:<font color=#FF0000>".$status[1]."</font></B> (since $ftime)";
3bc32eab
CS
211 }
212 else{
5384809b 213 print"<B>Disk $disk status:<font color=#00FF00>".$status[1]."</font></B>";
3bc32eab
CS
214 }
215 }
b94abc41 216 my $smart = `/usr/local/bin/smartctrl $disk`;
72fe12a9
MT
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>
223END
224;
225 &Header::closebox();
226 }
72fe12a9 227}