]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/media.cgi
2dfc3a02ce80d722f6568a7f1b0d1115b8607bb5
[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 &Graphs::updatediskgraph ("week",$device);
43 &Graphs::updatediskgraph ("month",$device);
44 diskbox("$device");
45 }
46
47 &Header::openbox('100%', 'center', $Lang::tr{'disk usage'});
48 print "<table width='95%' cellspacing='5'>\n";
49 open(DF,'/bin/df -B M -x rootfs|');
50 while(<DF>)
51 {
52 if ($_ =~ m/^Filesystem/ )
53 {
54 print <<END
55 <tr>
56 <td align='center' class='boldbase'><b>$Lang::tr{'device'}</b></td>
57 <td align='center' class='boldbase'><b>$Lang::tr{'mounted on'}</b></td>
58 <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
59 <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
60 <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
61 <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
62 </tr>
63 END
64 ;
65 }
66 else
67 {
68 my ($device,$size,$used,$free,$percent,$mount) = split;
69 print <<END
70 <tr>
71 <td align='center'>$device</td>
72 <td align='center'>$mount</td>
73 <td align='center'>$size</td>
74 <td align='center'>$used</td>
75 <td align='center'>$free</td>
76 <td align='left'>
77 END
78 ;
79 &percentbar($percent);
80 print <<END
81 </td>
82 <td align='left'>$percent</td>
83 </tr>
84 END
85 ;
86 }
87 }
88 close DF;
89 print "<tr><td colspan='7'>&nbsp;\n<tr><td colspan='7'><h3>Inodes</h3>\n";
90
91 open(DF,'/bin/df -i -x rootfs|');
92 while(<DF>)
93 {
94 if ($_ =~ m/^Filesystem/ )
95 {
96 print <<END
97 <tr>
98 <td align='center' class='boldbase'><b>$Lang::tr{'device'}</b></td>
99 <td align='center' class='boldbase'><b>$Lang::tr{'mounted on'}</b></td>
100 <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
101 <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
102 <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
103 <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
104 </tr>
105 END
106 ;
107 }
108 else
109 {
110 my ($device,$size,$used,$free,$percent,$mount) = split;
111 print <<END
112 <tr>
113 <td align='center'>$device</td>
114 <td align='center'>$mount</td>
115 <td align='center'>$size</td>
116 <td align='center'>$used</td>
117 <td align='center'>$free</td>
118 <td>
119 END
120 ;
121 &percentbar($percent);
122 print <<END
123 </td>
124 <td align='left'>$percent</td>
125 </tr>
126 END
127 ;
128 }
129 }
130 close DF;
131 my @iostat1 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$1}');
132 my @iostat2 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$5}');
133 my @iostat3 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$6}');
134 print "<tr><td colspan='3'>&nbsp;\n<tr><td colspan='3'><h3>transfers</h3></td></tr>";
135 my $i=0;
136
137 for(my $i = 1; $i <= $#iostat1; $i++)
138 {
139 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>";}
140 else {print "<tr><td align='center'>@iostat1[$i]</td><td align='center'>@iostat2[$i]</td><td align='center'>@iostat3[$i]</td></tr>";}
141 }
142 print "</table>\n";
143 &Header::closebox();
144
145 &Header::closebigbox();
146
147 &Header::closepage();
148
149 sub percentbar
150 {
151 my $percent = $_[0];
152 my $fg = '#a0a0a0';
153 my $bg = '#e2e2e2';
154
155 if ($percent =~ m/^(\d+)%$/ )
156 {
157 print <<END
158 <table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
159 <tr>
160 END
161 ;
162 if ($percent eq "100%") {
163 print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
164 } elsif ($percent eq "0%") {
165 print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
166 } else {
167 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'>"
168 }
169 print <<END
170 <img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>
171 END
172 ;
173 }
174 }
175
176 sub diskbox {
177 my $disk = $_[0];
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";
186 if (-e "/usr/local/bin/hddshutdown-state") {
187 system("/usr/local/bin/hddshutdown-state $disk");
188 }
189 my $smart = `/usr/local/bin/smartctrl $disk`;
190 $smart = &Header::cleanhtml($smart);
191 print <<END
192 <br /><input type="button" onClick="swapVisibility('smart_$disk')" value="$Lang::tr{'smart information'}" />
193 <div id='smart_$disk' style='display: none'>
194 <hr /><table border=0><tr><td align=left><pre>$smart</pre></table>
195 </div>
196 END
197 ;
198 &Header::closebox();
199 }
200 }