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