Ueberarbeitung der Status-Seiten.
[people/teissler/ipfire-2.x.git] / html / cgi-bin / media.cgi
CommitLineData
72fe12a9
MT
1#!/usr/bin/perl
2#
3# SmoothWall CGIs
4#
5# This code is distributed under the terms of the GPL
6#
7# (c) The SmoothWall Team
8#
9#
10
11use strict;
12
13# enable only the following on debugging purpose
14use warnings;
15use CGI::Carp 'fatalsToBrowser';
16
17require '/var/ipfire/general-functions.pl';
18require "${General::swroot}/lang.pl";
19require "${General::swroot}/header.pl";
20
21#workaround to suppress a warning when a variable is used only once
22my @dummy = ( ${Header::colourred} );
23undef (@dummy);
24
25my %cgiparams=();
26
27&Header::showhttpheaders();
28
29&Header::getcgihash(\%cgiparams);
30
31&Header::openpage($Lang::tr{'media information'}, 1, '');
32
33&Header::openbigbox('100%', 'left');
34
35&Header::openbox('100%', 'center', "Disk $Lang::tr{'graph'}");
36if (-e "$Header::graphdir/disk-day.png") {
37 my $ftime = localtime((stat("$Header::graphdir/disk-day.png"))[9]);
38 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
39 print "<a href='/cgi-bin/graphs.cgi?graph=disk'>";
40 print "<img alt='' src='/graphs/disk-day.png' border='0' />";
41 print "</a>";
42} else {
43 print $Lang::tr{'no information available'};
44}
45print "<br />\n";
46&Header::closebox();
47
48my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
49
50foreach (@devices) {
51 my $device = $_;
52 chomp($device);
53 diskbox("$device");
54}
55
56&Header::openbox('100%', 'center', $Lang::tr{'disk usage'});
57print "<table width='95%' cellspacing='5'>\n";
58open(DF,'/bin/df -B M -x rootfs|');
59while(<DF>)
60{
61 if ($_ =~ m/^Filesystem/ )
62 {
63 print <<END
64<tr>
65<td align='center' class='boldbase'><b>$Lang::tr{'device'}</b></td>
66<td align='center' class='boldbase'><b>$Lang::tr{'mounted on'}</b></td>
67<td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
68<td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
69<td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
70<td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
71</tr>
72END
73;
74 }
75 else
76 {
77 my ($device,$size,$used,$free,$percent,$mount) = split;
78 print <<END
79<tr>
80<td align='center'>$device</td>
81<td align='center'>$mount</td>
82<td align='center'>$size</td>
83<td align='center'>$used</td>
84<td align='center'>$free</td>
85<td align='left'>
86END
87;
88 &percentbar($percent);
89 print <<END
90</td>
91<td align='left'>$percent</td>
92</tr>
93END
94;
95 }
96}
97close DF;
98print "<tr><td colspan='7'>&nbsp;\n<tr><td colspan='7'><h3>Inodes</h3>\n";
99
100open(DF,'/bin/df -i -x rootfs|');
101while(<DF>)
102{
103 if ($_ =~ m/^Filesystem/ )
104 {
105 print <<END
106<tr>
107<td align='center' class='boldbase'><b>$Lang::tr{'device'}</b></td>
108<td align='center' class='boldbase'><b>$Lang::tr{'mounted on'}</b></td>
109<td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
110<td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
111<td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
112<td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
113</tr>
114END
115;
116 }
117 else
118 {
119 my ($device,$size,$used,$free,$percent,$mount) = split;
120 print <<END
121<tr>
122<td align='center'>$device</td>
123<td align='center'>$mount</td>
124<td align='center'>$size</td>
125<td align='center'>$used</td>
126<td align='center'>$free</td>
127<td>
128END
129;
130 &percentbar($percent);
131 print <<END
132</td>
133<td align='left'>$percent</td>
134</tr>
135END
136;
137 }
138}
139close DF;
140my @iostat1 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$1}');
141my @iostat2 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$5}');
142my @iostat3 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$6}');
143print "<tr><td colspan='3'>&nbsp;\n<tr><td colspan='3'><h3>transfers</h3></td></tr>";
144my $i=0;
145
146for(my $i = 1; $i <= $#iostat1; $i++)
147{
148if ( $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>";}
149else {print "<tr><td align='center'>@iostat1[$i]</td><td align='center'>@iostat2[$i]</td><td align='center'>@iostat3[$i]</td></tr>";}
150}
151print "</table>\n";
152&Header::closebox();
153
154&Header::closebigbox();
155
156&Header::closepage();
157
158sub percentbar
159{
160 my $percent = $_[0];
161 my $fg = '#a0a0a0';
162 my $bg = '#e2e2e2';
163
164 if ($percent =~ m/^(\d+)%$/ )
165 {
166 print <<END
167<table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
168<tr>
169END
170;
171 if ($percent eq "100%") {
172 print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
173 } elsif ($percent eq "0%") {
174 print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
175 } else {
176 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'>"
177 }
178 print <<END
179<img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>
180END
181;
182 }
183}
184
185sub diskbox {
186 my $disk = $_[0];
187 if (-e "$Header::graphdir/disk-$disk-day.png") {
188 &Header::openbox('100%', 'center', "Disk /dev/$disk $Lang::tr{'graph'}");
189 my $ftime = localtime((stat("$Header::graphdir/disk-$disk-day.png"))[9]);
190 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
191 print "<a href='/cgi-bin/graphs.cgi?graph=disk-$disk'>";
192 print "<img alt='' src='/graphs/disk-$disk-day.png' border='0' />";
193 print "</a>";
194 print "<br />\n";
195 if (-e "/usr/local/bin/hddshutdown-state") {
196 system("/usr/local/bin/hddshutdown-state $disk");
197 }
198 my $smart = `smartctrl $disk`;
199 $smart = &Header::cleanhtml($smart);
200 print <<END
201 <br /><input type="button" onClick="swapVisibility('smart_$disk')" value="$Lang::tr{'smart information'}" />
202 <div id='smart_$disk' style='display: none'>
203 <hr /><table border=0><tr><td align=left><pre>$smart</pre></table>
204 </div>
205END
206;
207 &Header::closebox();
208 }
209
210
211}