]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - html/cgi-bin/hardwaregraphs.cgi
Add new hardwaregraphs to updater filelist
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / hardwaregraphs.cgi
CommitLineData
958d26ac
AF
1#!/usr/bin/perl\r
2###############################################################################\r
3# #\r
4# IPFire.org - A linux based firewall #\r
5# Copyright (C) 2007 Michael Tremer & Christian Schmidt #\r
6# #\r
7# This program is free software: you can redistribute it and/or modify #\r
8# it under the terms of the GNU General Public License as published by #\r
9# the Free Software Foundation, either version 3 of the License, or #\r
10# (at your option) any later version. #\r
11# #\r
12# This program is distributed in the hope that it will be useful, #\r
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #\r
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #\r
15# GNU General Public License for more details. #\r
16# #\r
17# You should have received a copy of the GNU General Public License #\r
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #\r
19# #\r
20###############################################################################\r
21\r
22use strict;\r
23\r
24# enable only the following on debugging purpose\r
25#use warnings;\r
26#use CGI::Carp 'fatalsToBrowser';\r
27\r
28require '/var/ipfire/general-functions.pl';\r
29require "${General::swroot}/lang.pl";\r
30require "${General::swroot}/header.pl";\r
31require "${General::swroot}/graphs.pl";\r
32\r
33my %sensorsettings = ();\r
34my %cgiparams=();\r
35my @cgigraphs=();\r
36my $rrdlog = "/var/log/rrd";\r
37\r
38&Header::showhttpheaders();\r
39\r
40my $graphdir = "/srv/web/ipfire/html/graphs";\r
41\r
42$ENV{'QUERY_STRING'} =~ s/&//g;\r
43@cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});\r
44$cgigraphs[1] = '' unless defined $cgigraphs[1];\r
45\r
46my @sensorsgraphs = ();\r
47my @sensorsdir = `ls -dA $rrdlog/collectd/localhost/sensors-*/`;\r
48foreach (@sensorsdir)\r
49{\r
50 chomp($_);chop($_);\r
51 foreach (`ls $_/*`){\r
52 chomp($_);\r
53 push(@sensorsgraphs,$_);\r
54 }\r
55}\r
56\r
57&Header::getcgihash(\%sensorsettings);\r
58\r
59if ( $sensorsettings{'ACTION'} eq $Lang::tr{'save'} ) {\r
60 foreach(@sensorsgraphs){\r
61 chomp($_);\r
62 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;\r
63 my $label = $2.$3;$label=~ s/-//g;\r
64 if ( $sensorsettings{'LINE-'.$label} ne "on" ){$sensorsettings{'LINE-'.$label} = 'off';}\r
65 elsif ( $sensorsettings{'LINE-'.$label} eq "on" ){$sensorsettings{'LINE-'.$label} = 'checked';}\r
66 }\r
67 &General::writehash("${General::swroot}/sensors/settings", \%sensorsettings);\r
68}\r
69\r
70my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;\r
71\r
72&Header::openpage($Lang::tr{'harddisk temperature graphs'}, 1, '');\r
73&Header::openbigbox('100%', 'left');\r
74\r
75if ($cgigraphs[1] =~ /hwtemp/) {&Graphs::updatehwtempgraph ("hour");&Graphs::updatehwtempgraph ("week");&Graphs::updatehwtempgraph ("month");&Graphs::updatehwtempgraph ("year");graphbox("hwtemp");}\r
76elsif ($cgigraphs[1] =~ /hwfan/) {&Graphs::updatehwfangraph ("hour");&Graphs::updatehwfangraph ("week");&Graphs::updatehwfangraph ("month");&Graphs::updatehwfangraph ("year");graphbox("hwfan");}\r
77elsif ($cgigraphs[1] =~ /hwvolt/) {&Graphs::updatehwvoltgraph ("hour");&Graphs::updatehwvoltgraph ("week");&Graphs::updatehwvoltgraph ("month");&Graphs::updatehwvoltgraph ("year");graphbox("hwvolt");}\r
78elsif ($cgigraphs[1] =~ /hddtemp/) {\r
79 foreach (@disks){\r
80 my $disk = $_;\r
81 chomp $disk;\r
82 my @array = split(/\//,$disk);\r
83 &Graphs::updatehddgraph ($array[$#array],"week");&Graphs::updatehddgraph ($array[$#array],"month");&Graphs::updatehddgraph ($array[$#array],"year");\r
84 hddtempbox($array[$#array]);\r
85 }\r
86}\r
87else\r
88{\r
89 &Graphs::updatehwtempgraph ("day");&Graphs::updatehwfangraph ("day");&Graphs::updatehwvoltgraph ("day");\r
90 foreach (@disks){\r
91 my $disk = $_;\r
92 chomp $disk;\r
93 my @array = split(/\//,$disk);\r
94 &Graphs::updatehddgraph ($array[$#array],"day");\r
95 if (-e "$graphdir/hddtemp-$disk-day.png") {\r
96\r
97 &Header::openbox('100%', 'center', "Disk $disk $Lang::tr{'graph'}");\r
98 my $ftime = localtime((stat("$graphdir/hddtemp-$disk-day.png"))[9]);\r
99 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";\r
100 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=hddtemp'>";\r
101 print "<img src='/graphs/hddtemp-$disk-day.png' border='0' />";\r
102 print "</a>";\r
103 print "<br />\n";\r
104 &Header::closebox();\r
105 }\r
106 }\r
107\r
108 my @graphs = ("hwtemp","hwfan","hwvolt");\r
109 foreach (@graphs){\r
110 &Header::openbox('100%', 'center', "$_ $Lang::tr{'graph'}");\r
111 if (-e "$graphdir/sensors-$_-day.png"){\r
112 my $ftime = localtime((stat("$graphdir/sensors-$_-day.png"))[9]);\r
113 print "<center>";\r
114 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";\r
115 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=$_'>";\r
116 print "<img src='/graphs/sensors-$_-day.png' border='0' />";\r
117 print "</a><hr />";\r
118 }\r
119 else{print $Lang::tr{'no information available'};}\r
120 &Header::closebox();\r
121 }\r
122 sensorsbox();\r
123}\r
124\r
125&Header::closebigbox();\r
126&Header::closepage();\r
127\r
128sub hddtempbox {\r
129 my $disk = $_[0];\r
130 if (-e "$graphdir/hddtemp-$disk-week.png") {\r
131\r
132 &Header::openbox('100%', 'center', "Disk $disk $Lang::tr{'graph'}");\r
133 my $ftime = localtime((stat("$graphdir/hddtemp-$disk-week.png"))[9]);\r
134 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";\r
135 print "<img src='/graphs/hddtemp-$disk-week.png' border='0' />";\r
136 print "<br />\n";\r
137 &Header::closebox();\r
138 }\r
139 if (-e "$graphdir/hddtemp-$disk-month.png") {\r
140\r
141 &Header::openbox('100%', 'center', "Disk $disk $Lang::tr{'graph'}");\r
142 my $ftime = localtime((stat("$graphdir/hddtemp-$disk-month.png"))[9]);\r
143 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";\r
144 print "<img src='/graphs/hddtemp-$disk-month.png' border='0' />";\r
145 print "<br />\n";\r
146 &Header::closebox();\r
147 }\r
148 if (-e "$graphdir/hddtemp-$disk-year.png") {\r
149\r
150 &Header::openbox('100%', 'center', "Disk $disk $Lang::tr{'graph'}");\r
151 my $ftime = localtime((stat("$graphdir/hddtemp-$disk-year.png"))[9]);\r
152 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";\r
153 print "<img src='/graphs/hddtemp-$disk-year.png' border='0' />";\r
154 print "<br />\n";\r
155 &Header::closebox();\r
156 }\r
157}\r
158\r
159sub graphbox {\r
160 my $graph = $_[0];\r
161 \r
162 &Header::openbox('100%', 'center', "$graph $Lang::tr{'graph'}");\r
163 if (-e "$graphdir/sensors-$graph-week.png"){\r
164 my $ftime = localtime((stat("$graphdir/sensors-$graph-week.png"))[9]);\r
165 print "<center>";\r
166 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";\r
167 print "<img src='/graphs/sensors-$graph-week.png' border='0' /><hr />";\r
168 }\r
169 else{print $Lang::tr{'no information available'};}\r
170 &Header::closebox();\r
171 &Header::openbox('100%', 'center', "$graph $Lang::tr{'graph'}");\r
172 if (-e "$graphdir/sensors-$graph-month.png"){\r
173 my $ftime = localtime((stat("$graphdir/sensors-$graph-month.png"))[9]);\r
174 print "<center>";\r
175 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";\r
176 print "<img src='/graphs/sensors-$graph-month.png' border='0' /><hr />";\r
177 }\r
178 else{print $Lang::tr{'no information available'};}\r
179 &Header::closebox();\r
180 &Header::openbox('100%', 'center', "$graph $Lang::tr{'graph'}");\r
181 if (-e "$graphdir/sensors-$graph-year.png"){\r
182 my $ftime = localtime((stat("$graphdir/sensors-$graph-year.png"))[9]);\r
183 print "<center>";\r
184 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";\r
185 print "<img src='/graphs/sensors-$graph-year.png' border='0' /><hr />";\r
186 }\r
187 else{print $Lang::tr{'no information available'};}\r
188 &Header::closebox();\r
189}\r
190\r
191sub sensorsbox{\r
192\r
193 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon settings'}");\r
194 if ( $cgiparams{'ACTION'} eq $Lang::tr{'save'} ){print "Test";}\r
195\r
196 print <<END\r
197 <form method='post' action='$ENV{'SCRIPT_NAME'}'>\r
198 <table width='100%' border='0' cellspacing='5' cellpadding='0' align='center'>\r
199 <tr><td align='right' width='40%'><b>$Lang::tr{'mbmon display'}</b></td>\r
200 <td align='left'><b>$Lang::tr{'mbmon label'}</b></td>\r
201 </tr>\r
202END\r
203;\r
204foreach (@sensorsgraphs){\r
205 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;\r
206 my $label = $2.$3;$label=~ s/-//g;\r
207 $sensorsettings{'LABEL-'.$label}="$label";\r
208 $sensorsettings{'LINE-'.$label}="checked";\r
209 &General::readhash("${General::swroot}/sensors/settings", \%sensorsettings);\r
210 print("<tr><td align='right'><input type='checkbox' name='LINE-$label' $sensorsettings{'LINE-'.$label} /></td>");\r
211 print("<td><input type='text' name='LABEL-$label' value='$sensorsettings{'LABEL-'.$label}' size='25' /></td></tr>\n");\r
212}\r
213 print <<END\r
214 <tr><td align='center' colspan='2' ><input type='submit' name='ACTION' value=$Lang::tr{'save'} /></td></tr>\r
215 </table>\r
216 </form>\r
217END\r
218;\r
219 &Header::closebox();\r
220}\r