]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/media.cgi
Debuginformationen aus den CGIs entfernt
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / media.cgi
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
11 use strict;
12
13 # enable only the following on debugging purpose
14 #use warnings;
15 #use CGI::Carp 'fatalsToBrowser';
16
17 require '/var/ipfire/general-functions.pl';
18 require "${General::swroot}/lang.pl";
19 require "${General::swroot}/header.pl";
20 require "${General::swroot}/graphs.pl";
21
22 #workaround to suppress a warning when a variable is used only once
23 my @dummy = ( ${Header::colourred} );
24 undef (@dummy);
25
26 my %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
36 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
37
38 foreach (@devices) {
39 my $device = $_;
40 chomp($device);
41 &Graphs::updatediskgraph ("day",$device);
42 diskbox("$device");
43 }
44
45 &Header::openbox('100%', 'center', $Lang::tr{'disk usage'});
46 print "<table width='95%' cellspacing='5'>\n";
47 open(DF,'/bin/df -B M -x rootfs|');
48 while(<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>
61 END
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'>
75 END
76 ;
77 &percentbar($percent);
78 print <<END
79 </td>
80 <td align='left'>$percent</td>
81 </tr>
82 END
83 ;
84 }
85 }
86 close DF;
87 print "<tr><td colspan='7'>&nbsp;\n<tr><td colspan='7'><h3>Inodes</h3>\n";
88
89 open(DF,'/bin/df -i -x rootfs|');
90 while(<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>
103 END
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>
117 END
118 ;
119 &percentbar($percent);
120 print <<END
121 </td>
122 <td align='left'>$percent</td>
123 </tr>
124 END
125 ;
126 }
127 }
128 close DF;
129 my @iostat1 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$1}');
130 my @iostat2 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$5}');
131 my @iostat3 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$6}');
132 print "<tr><td colspan='3'>&nbsp;\n<tr><td colspan='3'><h3>transfers</h3></td></tr>";
133 my $i=0;
134
135 for(my $i = 1; $i <= $#iostat1; $i++)
136 {
137 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>";}
138 else {print "<tr><td align='center'>$iostat1[$i]</td><td align='center'>$iostat2[$i]</td><td align='center'>$iostat3[$i]</td></tr>";}
139 }
140 print "</table>\n";
141 &Header::closebox();
142
143 &Header::closebigbox();
144
145 &Header::closepage();
146
147 sub 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>
158 END
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>
169 END
170 ;
171 }
172 }
173
174 sub diskbox {
175 my $disk = $_[0];
176 if (-e "$Header::graphdir/disk-$disk-day.png") {
177 &Header::openbox('100%', 'center', "Disk /dev/$disk $Lang::tr{'graph'}");
178 my $ftime = localtime((stat("$Header::graphdir/disk-$disk-day.png"))[9]);
179 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
180 print "<a href='/cgi-bin/graphs.cgi?graph=disk-$disk'>";
181 print "<img alt='' src='/graphs/disk-$disk-day.png' border='0' />";
182 print "</a>";
183 print "<br />\n";
184 if (-e "/usr/local/bin/hddshutdown-state") {
185 system("/usr/local/bin/hddshutdown-state $disk");
186 }
187 my $smart = `/usr/local/bin/smartctrl $disk`;
188 $smart = &Header::cleanhtml($smart);
189 print <<END
190 <br /><input type="button" onClick="swapVisibility('smart_$disk')" value="$Lang::tr{'smart information'}" />
191 <div id='smart_$disk' style='display: none'>
192 <hr /><table border=0><tr><td align=left><pre>$smart</pre></table>
193 </div>
194 END
195 ;
196 &Header::closebox();
197 }
198 }