]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/media.cgi
Ein Paar Dateien fuer die GPLv3 angepasst.
[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) 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 &Graphs::updatediskgraph ("day",$device);
53 diskbox("$device");
54 }
55
56 &Header::openbox('100%', 'center', $Lang::tr{'disk usage'});
57 print "<table width='95%' cellspacing='5'>\n";
58 open(DF,'/bin/df -B M -x rootfs|');
59 while(<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>
72 END
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'>
86 END
87 ;
88 &percentbar($percent);
89 print <<END
90 </td>
91 <td align='left'>$percent</td>
92 </tr>
93 END
94 ;
95 }
96 }
97 close DF;
98 print "<tr><td colspan='7'>&nbsp;\n<tr><td colspan='7'><h3>Inodes</h3>\n";
99
100 open(DF,'/bin/df -i -x rootfs|');
101 while(<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>
114 END
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>
128 END
129 ;
130 &percentbar($percent);
131 print <<END
132 </td>
133 <td align='left'>$percent</td>
134 </tr>
135 END
136 ;
137 }
138 }
139 close DF;
140 my @iostat1 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$1}');
141 my @iostat2 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$5}');
142 my @iostat3 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$6}');
143 print "<tr><td colspan='3'>&nbsp;\n<tr><td colspan='3'><h3>transfers</h3></td></tr>";
144 my $i=0;
145
146 for(my $i = 1; $i <= $#iostat1; $i++)
147 {
148 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>";}
149 else {print "<tr><td align='center'>$iostat1[$i]</td><td align='center'>$iostat2[$i]</td><td align='center'>$iostat3[$i]</td></tr>";}
150 }
151 print "</table>\n";
152 &Header::closebox();
153
154 &Header::closebigbox();
155
156 &Header::closepage();
157
158 sub 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>
169 END
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>
180 END
181 ;
182 }
183 }
184
185 sub diskbox {
186 my $disk = $_[0];
187 chomp $disk;
188 my @status;
189 if (-e "$Header::graphdir/disk-$disk-day.png") {
190 &Header::openbox('100%', 'center', "Disk /dev/$disk $Lang::tr{'graph'}");
191 my $ftime = localtime((stat("$Header::graphdir/disk-$disk-day.png"))[9]);
192 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
193 print "<a href='/cgi-bin/graphs.cgi?graph=disk-$disk'>";
194 print "<img alt='' src='/graphs/disk-$disk-day.png' border='0' />";
195 print "</a>";
196 print "<br />\n";
197
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 /dev/$disk status:<font color=#FF0000>".$status[1]."</font></B> (since $ftime)";
210 }
211 else{
212 print"<B>Disk /dev/$disk status:<font color=#00FF00>".$status[1]."</font></B>";
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 &Header::closebox();
225 }
226 }