]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/hardwaregraphs.cgi
Fixed network.cgi
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / hardwaregraphs.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 my %mbmonsettings = ();
34 my %cgiparams=();
35 my @cgigraphs=();
36
37 &Header::showhttpheaders();
38
39 my $graphdir = "/srv/web/ipfire/html/graphs";
40
41 $ENV{'QUERY_STRING'} =~ s/&//g;
42 @cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});
43 $cgigraphs[1] = '' unless defined $cgigraphs[1];
44
45 my @mbmongraphs = ();
46 if ( -e "/var/log/rrd/collectd/localhost/mbmon" ){@mbmongraphs = `ls /var/log/rrd/collectd/localhost/mbmon/`;}
47
48 &Header::getcgihash(\%mbmonsettings);
49
50 if ( $mbmonsettings{'ACTION'} eq $Lang::tr{'save'} ) {
51 foreach (@mbmongraphs){
52 chomp($_);
53 my @name=split(/\./,$_);
54 if ( $mbmonsettings{'LINE-'.$name[0]} ne "on" ){$mbmonsettings{'LINE-'.$name[0]} = 'off';}
55 elsif ( $mbmonsettings{'LINE-'.$name[0]} eq "on" ){$mbmonsettings{'LINE-'.$name[0]} = 'checked';}
56 }
57 &General::writehash("${General::swroot}/mbmon/settings", \%mbmonsettings);
58 }
59
60 my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
61
62 &Header::openpage($Lang::tr{'harddisk temperature graphs'}, 1, '');
63 &Header::openbigbox('100%', 'left');
64
65 if ($cgigraphs[1] =~ /hwtemp/) {&Graphs::updatehwtempgraph ("hour");&Graphs::updatehwtempgraph ("week");&Graphs::updatehwtempgraph ("month");&Graphs::updatehwtempgraph ("year");graphbox("hwtemp");}
66 elsif ($cgigraphs[1] =~ /hwfan/) {&Graphs::updatehwfangraph ("hour");&Graphs::updatehwfangraph ("week");&Graphs::updatehwfangraph ("month");&Graphs::updatehwfangraph ("year");graphbox("hwfan");}
67 elsif ($cgigraphs[1] =~ /hwvolt/) {&Graphs::updatehwvoltgraph ("hour");&Graphs::updatehwvoltgraph ("week");&Graphs::updatehwvoltgraph ("month");&Graphs::updatehwvoltgraph ("year");graphbox("hwvolt");}
68 elsif ($cgigraphs[1] =~ /hddtemp/) {
69 foreach (@disks){
70 my $disk = $_;
71 chomp $disk;
72 my @array = split(/\//,$disk);
73 &Graphs::updatehddgraph ($array[$#array],"week");&Graphs::updatehddgraph ($array[$#array],"month");&Graphs::updatehddgraph ($array[$#array],"year");
74 hddtempbox($array[$#array]);
75 }
76 }
77 else
78 {
79 &Graphs::updatehwtempgraph ("day");&Graphs::updatehwfangraph ("day");&Graphs::updatehwvoltgraph ("day");
80 foreach (@disks){
81 my $disk = $_;
82 chomp $disk;
83 my @array = split(/\//,$disk);
84 &Graphs::updatehddgraph ($array[$#array],"day");
85 if (-e "$graphdir/hddtemp-$disk-day.png") {
86
87 &Header::openbox('100%', 'center', "Disk $disk $Lang::tr{'graph'}");
88 my $ftime = localtime((stat("$graphdir/hddtemp-$disk-day.png"))[9]);
89 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
90 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=hddtemp'>";
91 print "<img src='/graphs/hddtemp-$disk-day.png' border='0' />";
92 print "</a>";
93 print "<br />\n";
94 &Header::closebox();
95 }
96 }
97
98 my @graphs = ("hwtemp","hwfan","hwvolt");
99 foreach (@graphs){
100 &Header::openbox('100%', 'center', "$_ $Lang::tr{'graph'}");
101 if (-e "$graphdir/mbmon-$_-day.png"){
102 my $ftime = localtime((stat("$graphdir/mbmon-$_-day.png"))[9]);
103 print "<center>";
104 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
105 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=$_'>";
106 print "<img src='/graphs/mbmon-$_-day.png' border='0' />";
107 print "</a><hr />";
108 }
109 else{print $Lang::tr{'no information available'};}
110 &Header::closebox();
111 }
112 if ( -e "/var/log/rrd/collectd/localhost/mbmon" ){mbmonbox();}
113 }
114
115 &Header::closebigbox();
116 &Header::closepage();
117
118 sub hddtempbox {
119 my $disk = $_[0];
120 if (-e "$graphdir/hddtemp-$disk-week.png") {
121
122 &Header::openbox('100%', 'center', "Disk $disk $Lang::tr{'graph'}");
123 my $ftime = localtime((stat("$graphdir/hddtemp-$disk-week.png"))[9]);
124 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
125 print "<img src='/graphs/hddtemp-$disk-week.png' border='0' />";
126 print "<br />\n";
127 &Header::closebox();
128 }
129 if (-e "$graphdir/hddtemp-$disk-month.png") {
130
131 &Header::openbox('100%', 'center', "Disk $disk $Lang::tr{'graph'}");
132 my $ftime = localtime((stat("$graphdir/hddtemp-$disk-month.png"))[9]);
133 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
134 print "<img src='/graphs/hddtemp-$disk-month.png' border='0' />";
135 print "<br />\n";
136 &Header::closebox();
137 }
138 if (-e "$graphdir/hddtemp-$disk-year.png") {
139
140 &Header::openbox('100%', 'center', "Disk $disk $Lang::tr{'graph'}");
141 my $ftime = localtime((stat("$graphdir/hddtemp-$disk-year.png"))[9]);
142 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
143 print "<img src='/graphs/hddtemp-$disk-year.png' border='0' />";
144 print "<br />\n";
145 &Header::closebox();
146 }
147 }
148
149 sub graphbox {
150 my $graph = $_[0];
151
152 &Header::openbox('100%', 'center', "$graph $Lang::tr{'graph'}");
153 if (-e "$graphdir/mbmon-$graph-week.png"){
154 my $ftime = localtime((stat("$graphdir/mbmon-$graph-week.png"))[9]);
155 print "<center>";
156 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
157 print "<img src='/graphs/mbmon-$graph-week.png' border='0' /><hr />";
158 }
159 else{print $Lang::tr{'no information available'};}
160 &Header::closebox();
161 &Header::openbox('100%', 'center', "$graph $Lang::tr{'graph'}");
162 if (-e "$graphdir/mbmon-$graph-month.png"){
163 my $ftime = localtime((stat("$graphdir/mbmon-$graph-month.png"))[9]);
164 print "<center>";
165 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
166 print "<img src='/graphs/mbmon-$graph-month.png' border='0' /><hr />";
167 }
168 else{print $Lang::tr{'no information available'};}
169 &Header::closebox();
170 &Header::openbox('100%', 'center', "$graph $Lang::tr{'graph'}");
171 if (-e "$graphdir/mbmon-$graph-year.png"){
172 my $ftime = localtime((stat("$graphdir/mbmon-$graph-year.png"))[9]);
173 print "<center>";
174 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
175 print "<img src='/graphs/mbmon-$graph-year.png' border='0' /><hr />";
176 }
177 else{print $Lang::tr{'no information available'};}
178 &Header::closebox();
179 }
180
181 sub mbmonbox{
182
183 foreach (@mbmongraphs){
184 chomp($_);
185 my @name=split(/\./,$_);my $label = $name[0]; $label=~ s/-//;
186 $mbmonsettings{'LABEL-'.$name[0]}="$label";
187 $mbmonsettings{'LINE-'.$name[0]}="checked";
188 }
189 &General::readhash("${General::swroot}/mbmon/settings", \%mbmonsettings);
190
191 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon settings'}");
192 if ( $cgiparams{'ACTION'} eq $Lang::tr{'save'} ){print "Test";}
193
194 print <<END
195 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
196 <table width='100%' border='0' cellspacing='5' cellpadding='0' align='center'>
197 <tr><td align='right' width='40%'><b>$Lang::tr{'mbmon display'}</b></td>
198 <td align='left'><b>$Lang::tr{'mbmon label'}</b></td>
199 </tr>
200 END
201 ;
202 foreach (@mbmongraphs){
203 chomp($_);my @name=split(/\./,$_);
204 print("<tr><td align='right'><input type='checkbox' name='LINE-$name[0]' $mbmonsettings{'LINE-'.$name[0]} /></td>");
205 print("<td><input type='text' name='LABEL-$name[0]' value='$mbmonsettings{'LABEL-'.$name[0]}' size='25' /></td></tr>\n");
206 }
207 print <<END
208 <tr><td align='center' colspan='2' ><input type='submit' name='ACTION' value=$Lang::tr{'save'} /></td></tr>
209 </table>
210 </form>
211 END
212 ;
213 &Header::closebox();
214 }