]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - html/cgi-bin/hardwaregraphs.cgi
Removed the old svn commands and started with git.
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / hardwaregraphs.cgi
CommitLineData
60cbd6e7 1#!/usr/bin/perl
70df8302
MT
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###############################################################################
60cbd6e7
MT
21
22use strict;
23
24# enable only the following on debugging purpose
e1e3dbe5
CS
25#use warnings;
26#use CGI::Carp 'fatalsToBrowser';
60cbd6e7
MT
27
28require '/var/ipfire/general-functions.pl';
29require "${General::swroot}/lang.pl";
30require "${General::swroot}/header.pl";
350b52c5 31require "${General::swroot}/graphs.pl";
60cbd6e7 32
e1e3dbe5 33my %mbmonsettings = ();
60cbd6e7
MT
34my %cgiparams=();
35my @cgigraphs=();
60cbd6e7
MT
36
37&Header::showhttpheaders();
38
fd0763dc 39my $graphdir = "/srv/web/ipfire/html/graphs";
60cbd6e7
MT
40
41$ENV{'QUERY_STRING'} =~ s/&//g;
42@cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});
43$cgigraphs[1] = '' unless defined $cgigraphs[1];
44
e1e3dbe5
CS
45my @mbmongraphs = ();
46if ( -e "/var/log/rrd/collectd/localhost/mbmon" ){@mbmongraphs = `ls /var/log/rrd/collectd/localhost/mbmon/`;}
52345790 47
e1e3dbe5 48&Header::getcgihash(\%mbmonsettings);
52345790 49
e1e3dbe5
CS
50if ( $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);
52345790
MT
58}
59
e1e3dbe5 60my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
52345790 61
60cbd6e7 62&Header::openpage($Lang::tr{'harddisk temperature graphs'}, 1, '');
60cbd6e7
MT
63&Header::openbigbox('100%', 'left');
64
e1e3dbe5
CS
65if ($cgigraphs[1] =~ /hwtemp/) {&Graphs::updatehwtempgraph ("hour");&Graphs::updatehwtempgraph ("week");&Graphs::updatehwtempgraph ("month");&Graphs::updatehwtempgraph ("year");graphbox("hwtemp");}
66elsif ($cgigraphs[1] =~ /hwfan/) {&Graphs::updatehwfangraph ("hour");&Graphs::updatehwfangraph ("week");&Graphs::updatehwfangraph ("month");&Graphs::updatehwfangraph ("year");graphbox("hwfan");}
67elsif ($cgigraphs[1] =~ /hwvolt/) {&Graphs::updatehwvoltgraph ("hour");&Graphs::updatehwvoltgraph ("week");&Graphs::updatehwvoltgraph ("month");&Graphs::updatehwvoltgraph ("year");graphbox("hwvolt");}
68elsif ($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 }
52345790 76}
e1e3dbe5 77else
52345790 78{
e1e3dbe5
CS
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") {
52345790 86
e1e3dbe5
CS
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 }
52345790 96 }
52345790 97
e1e3dbe5
CS
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();}
52345790
MT
113}
114
60cbd6e7
MT
115&Header::closebigbox();
116&Header::closepage();
9217f236
MT
117
118sub hddtempbox {
119 my $disk = $_[0];
e1e3dbe5
CS
120 if (-e "$graphdir/hddtemp-$disk-week.png") {
121
5384809b 122 &Header::openbox('100%', 'center', "Disk $disk $Lang::tr{'graph'}");
e1e3dbe5 123 my $ftime = localtime((stat("$graphdir/hddtemp-$disk-week.png"))[9]);
9217f236 124 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
8fb804b5 125 print "<img src='/graphs/hddtemp-$disk-week.png' border='0' />";
9217f236
MT
126 print "<br />\n";
127 &Header::closebox();
128 }
e1e3dbe5
CS
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";
8fb804b5 134 print "<img src='/graphs/hddtemp-$disk-month.png' border='0' />";
e1e3dbe5
CS
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
149sub graphbox {
150 my $graph = $_[0];
151
152 &Header::openbox('100%', 'center', "$graph $Lang::tr{'graph'}");
153 if (-e "$graphdir/mbmon-$graph-week.png"){
4a52eae4 154 my $ftime = localtime((stat("$graphdir/mbmon-$graph-week.png"))[9]);
e1e3dbe5
CS
155 print "<center>";
156 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
4a52eae4 157 print "<img src='/graphs/mbmon-$graph-week.png' border='0' /><hr />";
e1e3dbe5
CS
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
181sub 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>
200END
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>
211END
212;
213 &Header::closebox();
9217f236 214}