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