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