]> git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/media.cgi
suricata: Change midstream policy to "pass-flow"
[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-2013 IPFire Team <info@ipfire.org> #
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 my %color = ();
34 my %mainsettings = ();
35 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
36 &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color);
37
38 #workaround to suppress a warning when a variable is used only once
39 my @dummy = ( ${Header::colourred} );
40 undef (@dummy);
41
42 my %cgiparams=();
43
44 my @devices = `ls -1 /sys/block | grep -E '^sd|^mmcblk|^nvme|^xvd|^vd|^md' | sort | uniq`;
45
46 &Header::showhttpheaders();
47 &Header::openpage($Lang::tr{'media information'}, 1, '');
48 &Header::openbigbox('100%', 'left');
49
50 foreach (@devices) {
51 my $device = $_;
52 chomp($device);
53 my @array = split(/\//,$device);
54 &Header::openbox('100%', 'center', "$array[$#array] $Lang::tr{'graph'}");
55 diskbox($array[$#array]);
56 &Graphs::makegraphbox("media.cgi",$array[$#array],"day");
57 &Header::closebox();
58 }
59
60
61 &Header::openbox('100%', 'center', $Lang::tr{'disk usage'});
62 print "<table width='95%' cellspacing='5'>\n";
63 open(DF,'/bin/df -P -B M -x rootfs|');
64 while(<DF>){
65 if ($_ =~ m/^Filesystem/ ){
66 print <<END
67 <tr>
68 <td align='center' class='boldbase'><b>$Lang::tr{'device'}</b></td>
69 <td align='center' class='boldbase'><b>$Lang::tr{'mounted on'}</b></td>
70 <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
71 <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
72 <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
73 <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
74 </tr>
75 END
76 ;
77 }else{
78 my ($device,$size,$used,$free,$percent,$mount) = split;
79 print <<END
80 <tr>
81 <td align='center'>$device</td>
82 <td align='center'>$mount</td>
83 <td align='center'>$size</td>
84 <td align='center'>$used</td>
85 <td align='center'>$free</td>
86 <td align='left'>
87 END
88 ;
89 &percentbar($percent);
90 print <<END
91 </td>
92 <td align='left'>$percent</td>
93 </tr>
94 END
95 ;
96 }
97 }
98 close DF;
99 print "<tr><td colspan='7'>&nbsp;\n<tr><td colspan='7'><h3>Inodes</h3>\n";
100
101 open(DF,'/bin/df -P -i -x rootfs|');
102 while(<DF>){
103 if ($_ =~ m/^Filesystem/ ){
104 print <<END
105 <tr>
106 <td align='center' class='boldbase'><b>$Lang::tr{'device'}</b></td>
107 <td align='center' class='boldbase'><b>$Lang::tr{'mounted on'}</b></td>
108 <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
109 <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
110 <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
111 <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
112 </tr>
113 END
114 ;
115 }else{
116 my ($device,$size,$used,$free,$percent,$mount) = split;
117 print <<END
118 <tr>
119 <td align='center'>$device</td>
120 <td align='center'>$mount</td>
121 <td align='center'>$size</td>
122 <td align='center'>$used</td>
123 <td align='center'>$free</td>
124 <td>
125 END
126 ;
127 &percentbar($percent);
128 print <<END
129 </td>
130 <td align='left'>$percent</td>
131 </tr>
132 END
133 ;
134 }
135 }
136 close DF;
137 my @iostat1 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$1}');
138 my @iostat2 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$6}');
139 my @iostat3 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$7}');
140 print "<tr><td colspan='3'>&nbsp;\n<tr><td colspan='3'><h3>transfers</h3></td></tr>";
141 my $i=0;
142
143 for(my $i = 1; $i <= $#iostat1; $i++){
144 if ( $i eq '1' ){
145 print "<tr><td align='center' class='boldbase'><b>$Lang::tr{'device'}</b></td><td align='center' class='boldbase'><b>$Lang::tr{'MB read'}</b></td><td align='center' class='boldbase'><b>$Lang::tr{'MB written'}</b></td></tr>";
146 }else{
147 print "<tr><td align='center'>$iostat1[$i]</td><td align='center'>$iostat2[$i]</td><td align='center'>$iostat3[$i]</td></tr>";
148 }
149 }
150 print "</table>\n";
151 &Header::closebox();
152
153 &Header::closebigbox();
154 &Header::closepage();
155
156 sub percentbar
157 {
158 my $percent = $_[0];
159 my $fg = '#a0a0a0';
160 my $bg = '#e2e2e2';
161
162 if ($percent =~ m/^(\d+)%$/ )
163 {
164 print <<END
165 <table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
166 <tr>
167 END
168 ;
169 if ($percent eq "100%") {
170 print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
171 } elsif ($percent eq "0%") {
172 print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
173 } else {
174 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'>"
175 }
176 print <<END
177 <img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>
178 END
179 ;
180 }
181 }
182
183 sub diskbox {
184 my $disk = $_[0];
185 chomp $disk;
186 my @status;
187 if (-e "/var/run/hddstatus"){
188 open(DATEI, "</var/run/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("/var/run/hddshutdown-$disk"))[9]);
198 print"<b>Disk $disk status:<span style='color:#FF0000'>".$status[1]."</b> ($Lang::tr{'since'} $ftime)";
199 }else{
200 print"<b>Disk $disk status:<span style='color:#00FF00'>".$status[1]."</b>";
201 }
202 }
203
204 my $smart = `/usr/local/bin/smartctrl $disk`;
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>
211 END
212 ;
213 }