]>
Commit | Line | Data |
---|---|---|
3961e831 AF |
1 | #!/usr/bin/perl |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
1e18d32b | 5 | # Copyright (C) 2005-2011 IPFire Team # |
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 | ||
22 | use strict; | |
23 | ||
24 | # enable only the following on debugging purpose | |
bcad0fd0 CS |
25 | #use warnings; |
26 | #use CGI::Carp 'fatalsToBrowser'; | |
3961e831 AF |
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 | ||
2d281532 CS |
33 | my %color = (); |
34 | my %mainsettings = (); | |
35 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
8186b372 | 36 | &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color); |
2d281532 | 37 | |
3961e831 | 38 | my %sensorsettings = (); |
3961e831 | 39 | |
3961e831 | 40 | my @sensorsgraphs = (); |
2386d2ef | 41 | my @sensorsdir = &General::system_output("ls", "-dA", "$mainsettings{'RRDLOG'}/collectd/localhost/sensors-*/"); |
2d281532 | 42 | foreach (@sensorsdir){ |
3961e831 | 43 | chomp($_);chop($_); |
2386d2ef | 44 | foreach (&General::system_output("ls", "$_/*") ){ |
3961e831 AF |
45 | chomp($_); |
46 | push(@sensorsgraphs,$_); | |
47 | } | |
48 | } | |
49 | ||
2d281532 CS |
50 | my @querry = split(/\?/,$ENV{'QUERY_STRING'}); |
51 | $querry[0] = '' unless defined $querry[0]; | |
52 | $querry[1] = 'hour' unless defined $querry[1]; | |
53 | ||
54 | if ( $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]); | |
30189c50 AF |
66 | }elsif ( $querry[0] =~ "thermaltemp"){ |
67 | print "Content-type: image/png\n\n"; | |
68 | binmode(STDOUT); | |
69 | &Graphs::updatethermaltempgraph($querry[1]); | |
269e21c6 | 70 | }elsif ( $querry[0] =~ "sd?" ){ |
2d281532 CS |
71 | print "Content-type: image/png\n\n"; |
72 | binmode(STDOUT); | |
73 | &Graphs::updatehddgraph($querry[0],$querry[1]); | |
ca9c45b3 AF |
74 | }elsif ( $querry[0] =~ "nvme?" ){ |
75 | print "Content-type: image/png\n\n"; | |
76 | binmode(STDOUT); | |
77 | &Graphs::updatehddgraph($querry[0],$querry[1]); | |
2d281532 CS |
78 | }else{ |
79 | &Header::showhttpheaders(); | |
fb6446d2 | 80 | &Header::openpage($Lang::tr{'hardware graphs'}, 1, ''); |
2d281532 CS |
81 | &Header::openbigbox('100%', 'left'); |
82 | ||
83 | &Header::getcgihash(\%sensorsettings); | |
84 | ||
85 | if ( $sensorsettings{'ACTION'} eq $Lang::tr{'save'} ) { | |
86 | foreach(@sensorsgraphs){ | |
87 | chomp($_); | |
88 | $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/; | |
89 | my $label = $2.$3;$label=~ s/-//g; | |
e4e74858 CS |
90 | if ( $sensorsettings{'LINE-'.$label} ne "on" ){ |
91 | $sensorsettings{'LINE-'.$label} = 'off'; | |
92 | } elsif ($sensorsettings{'LINE-'.$label} eq "on" ){ | |
93 | $sensorsettings{'LINE-'.$label} = 'checked'; | |
94 | } | |
95 | $sensorsettings{'LABEL-'.$label} =~ s/\W//g; | |
2d281532 CS |
96 | } |
97 | &General::writehash("${General::swroot}/sensors/settings", \%sensorsettings); | |
3961e831 | 98 | } |
3961e831 | 99 | |
2386d2ef | 100 | # This should be save, because no user given content will be processed. |
ca9c45b3 | 101 | my @disks = `ls -1 /sys/block | grep -E '^sd|^nvme' | sort | uniq`; |
2d281532 CS |
102 | |
103 | foreach (@disks){ | |
104 | my $disk = $_; | |
105 | chomp $disk; | |
106 | my @array = split(/\//,$disk); | |
107 | ||
108 | &Header::openbox('100%', 'center', "$array[$#array] $Lang::tr{'graph'}"); | |
109 | &Graphs::makegraphbox("hardwaregraphs.cgi",$array[$#array],"day"); | |
110 | &Header::closebox(); | |
3961e831 | 111 | } |
2d281532 | 112 | |
2386d2ef | 113 | if ( &General::system_output("ls", "$mainsettings{'RRDLOG'}/collectd/localhost/thermal-thermal_zone*") ) { |
e4e74858 CS |
114 | &Header::openbox('100%', 'center', "ACPI Thermal-Zone Temp $Lang::tr{'graph'}"); |
115 | &Graphs::makegraphbox("hardwaregraphs.cgi","thermaltemp","day"); | |
116 | &Header::closebox(); | |
30189c50 AF |
117 | } |
118 | ||
2386d2ef | 119 | if ( &General::system_output("ls", "$mainsettings{'RRDLOG'}/collectd/localhost/sensors-*/temperature-*") ) { |
e4e74858 | 120 | &Header::openbox('100%', 'center', "hwtemp $Lang::tr{'graph'}"); |
a249ccd2 | 121 | &Graphs::makegraphbox("hardwaregraphs.cgi","hwtemp","day"); |
e4e74858 | 122 | Header::closebox(); |
30114625 | 123 | } |
2d281532 | 124 | |
2386d2ef | 125 | if ( &General::system_output("ls", "$mainsettings{'RRDLOG'}/collectd/localhost/sensors-*/fanspeed-*") ) { |
e4e74858 CS |
126 | &Header::openbox('100%', 'center', "hwfan $Lang::tr{'graph'}"); |
127 | &Graphs::makegraphbox("hardwaregraphs.cgi","hwfan","day"); | |
128 | &Header::closebox(); | |
30114625 | 129 | } |
2d281532 | 130 | |
2386d2ef | 131 | if ( &General::system_output("ls", "$mainsettings{'RRDLOG'}/collectd/localhost/sensors-*/voltage-*") ) { |
e4e74858 | 132 | &Header::openbox('100%', 'center', "hwvolt $Lang::tr{'graph'}"); |
a249ccd2 | 133 | &Graphs::makegraphbox("hardwaregraphs.cgi","hwvolt","day"); |
e4e74858 | 134 | &Header::closebox(); |
30114625 | 135 | } |
3961e831 | 136 | |
2386d2ef | 137 | if ( &General::system_output("ls", "$mainsettings{'RRDLOG'}/collectd/localhost/sensors-*") ) { |
e4e74858 | 138 | sensorsbox(); |
30189c50 | 139 | } |
2d281532 CS |
140 | &Header::closebigbox(); |
141 | &Header::closepage(); | |
3961e831 | 142 | |
3961e831 AF |
143 | } |
144 | ||
3961e831 | 145 | |
2d281532 CS |
146 | sub sensorsbox { |
147 | &Header::openbox('100%', 'center', "$Lang::tr{'mbmon settings'}"); | |
3961e831 | 148 | |
2d281532 CS |
149 | print <<END |
150 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
151 | <table width='100%' border='0' cellspacing='5' cellpadding='0' align='center'> | |
152 | <tr> | |
153 | <td align='right' width='40%'><b>$Lang::tr{'mbmon display'}</b></td> | |
154 | <td align='left'><b>$Lang::tr{'mbmon label'}</b></td> | |
155 | </tr> | |
3961e831 AF |
156 | END |
157 | ; | |
2d281532 CS |
158 | |
159 | foreach (@sensorsgraphs){ | |
160 | $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/; | |
161 | my $label = $2.$3;$label=~ s/-//g; | |
162 | $sensorsettings{'LABEL-'.$label}="$label"; | |
163 | $sensorsettings{'LINE-'.$label}="checked"; | |
164 | &General::readhash("${General::swroot}/sensors/settings", \%sensorsettings); | |
165 | print("<tr><td align='right'><input type='checkbox' name='LINE-$label' $sensorsettings{'LINE-'.$label} /></td>"); | |
166 | print("<td><input type='text' name='LABEL-$label' value='$sensorsettings{'LABEL-'.$label}' size='25' /></td></tr>\n"); | |
167 | } | |
168 | ||
169 | print <<END | |
170 | <tr> | |
1d55fccd | 171 | <td align='center' colspan='2' ><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td> |
2d281532 CS |
172 | </tr> |
173 | </table> | |
174 | </form> | |
3961e831 AF |
175 | END |
176 | ; | |
2d281532 | 177 | &Header::closebox(); |
3961e831 | 178 | } |