]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/hardwaregraphs.cgi
Merge branch 'master' of git://git.ipfire.org/ipfire-2.x
[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) 2008 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 %color = ();
34 my %mainsettings = ();
35 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
36 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
37
38 my %sensorsettings = ();
39 my $rrdlog = "/var/log/rrd";
40
41 my @sensorsgraphs = ();
42 my @sensorsdir = `ls -dA $rrdlog/collectd/localhost/sensors-*/`;
43 foreach (@sensorsdir){
44 chomp($_);chop($_);
45 foreach (`ls $_/*`){
46 chomp($_);
47 push(@sensorsgraphs,$_);
48 }
49 }
50
51 my @querry = split(/\?/,$ENV{'QUERY_STRING'});
52 $querry[0] = '' unless defined $querry[0];
53 $querry[1] = 'hour' unless defined $querry[1];
54
55 if ( $querry[0] =~ "hwtemp"){
56 print "Content-type: image/png\n\n";
57 binmode(STDOUT);
58 &Graphs::updatehwtempgraph($querry[1]);
59 }elsif ( $querry[0] =~ "hwfan"){
60 print "Content-type: image/png\n\n";
61 binmode(STDOUT);
62 &Graphs::updatehwfangraph($querry[1]);
63 }elsif ( $querry[0] =~ "hwvolt"){
64 print "Content-type: image/png\n\n";
65 binmode(STDOUT);
66 &Graphs::updatehwvoltgraph($querry[1]);
67 }elsif ( $querry[0] =~ "sd?" || $querry[0] =~ "hd?" ){
68 print "Content-type: image/png\n\n";
69 binmode(STDOUT);
70 &Graphs::updatehddgraph($querry[0],$querry[1]);
71 }else{
72 &Header::showhttpheaders();
73 &Header::openpage($Lang::tr{'harddisk temperature graphs'}, 1, '');
74 &Header::openbigbox('100%', 'left');
75
76 &Header::getcgihash(\%sensorsettings);
77
78 if ( $sensorsettings{'ACTION'} eq $Lang::tr{'save'} ) {
79 foreach(@sensorsgraphs){
80 chomp($_);
81 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
82 my $label = $2.$3;$label=~ s/-//g;
83 if ( $sensorsettings{'LINE-'.$label} ne "on" ){$sensorsettings{'LINE-'.$label} = 'off';}
84 elsif ( $sensorsettings{'LINE-'.$label} eq "on" ){$sensorsettings{'LINE-'.$label} = 'checked';}
85 }
86 &General::writehash("${General::swroot}/sensors/settings", \%sensorsettings);
87 }
88
89 my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
90
91 foreach (@disks){
92 my $disk = $_;
93 chomp $disk;
94 my @array = split(/\//,$disk);
95
96 &Header::openbox('100%', 'center', "$array[$#array] $Lang::tr{'graph'}");
97 &Graphs::makegraphbox("hardwaregraphs.cgi",$array[$#array],"day");
98 &Header::closebox();
99 }
100
101 &Header::openbox('100%', 'center', "hwtemp $Lang::tr{'graph'}");
102 &Graphs::makegraphbox("hardwaregraphs.cgi","hwtemp","day");
103 &Header::closebox();
104
105 &Header::openbox('100%', 'center', "hwfan $Lang::tr{'graph'}");
106 &Graphs::makegraphbox("hardwaregraphs.cgi","hwfan","day");
107 &Header::closebox();
108
109 &Header::openbox('100%', 'center', "hwvolt $Lang::tr{'graph'}");
110 &Graphs::makegraphbox("hardwaregraphs.cgi","hwvolt","day","375");
111 &Header::closebox();
112
113 sensorsbox();
114
115 &Header::closebigbox();
116 &Header::closepage();
117
118 }
119
120
121 sub sensorsbox {
122 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon settings'}");
123
124 print <<END
125 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
126 <table width='100%' border='0' cellspacing='5' cellpadding='0' align='center'>
127 <tr>
128 <td align='right' width='40%'><b>$Lang::tr{'mbmon display'}</b></td>
129 <td align='left'><b>$Lang::tr{'mbmon label'}</b></td>
130 </tr>
131 END
132 ;
133
134 foreach (@sensorsgraphs){
135 $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;
136 my $label = $2.$3;$label=~ s/-//g;
137 $sensorsettings{'LABEL-'.$label}="$label";
138 $sensorsettings{'LINE-'.$label}="checked";
139 &General::readhash("${General::swroot}/sensors/settings", \%sensorsettings);
140 print("<tr><td align='right'><input type='checkbox' name='LINE-$label' $sensorsettings{'LINE-'.$label} /></td>");
141 print("<td><input type='text' name='LABEL-$label' value='$sensorsettings{'LABEL-'.$label}' size='25' /></td></tr>\n");
142 }
143
144 print <<END
145 <tr>
146 <td align='center' colspan='2' ><input type='submit' name='ACTION' value=$Lang::tr{'save'} /></td>
147 </tr>
148 </table>
149 </form>
150 END
151 ;
152 &Header::closebox();
153 }