]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/hardwaregraphs.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2005-2011 IPFire Team #
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. #
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. #
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/>. #
20 ###############################################################################
24 # enable only the following on debugging purpose
26 #use CGI::Carp 'fatalsToBrowser';
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";
34 my %mainsettings = ();
35 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
36 &General
::readhash
("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \
%color);
38 my %sensorsettings = ();
40 my @sensorsgraphs = ();
42 # Main directory where rrdlog puts the sensor data.
43 my $sensorsdir = "$mainsettings{'RRDLOG'}/collectd/localhost";
45 # Open sensors directory.
46 opendir(SENSORS
, "$sensorsdir") or die "Could not opendir $sensorsdir: $!\n";
48 # Read-in all sensors.
49 my @sensor_dirs = readdir(SENSORS
);
51 # Close directory handle.
54 # Loop through the grabbed sensors.
55 foreach my $sensor_dir (@sensor_dirs) {
56 # Skip everything which does not start with "sensors-".
57 next unless $sensor_dir =~ /^sensors-/;
59 # Check if the omitet element is a directory.
60 next unless (-d
"$sensorsdir/$sensor_dir");
62 # Open sensor directory and lookup for sensors.
63 opendir(SENSOR_DIR
, "$sensorsdir/$sensor_dir") or die "Could not opendir $sensorsdir/$sensor_dir: $!\n";
65 # Grab single sensors from the directory.
66 my @sensors = readdir(SENSOR_DIR
);
68 # Close directory handle.
71 # Loop through the omited sensors.
72 foreach my $sensor (@sensors) {
73 # Skip everything which is not a regular file.
74 next unless (-f
"$sensorsdir/$sensor_dir/$sensor");
76 # Add sensor to the array of sensorsgrapghs.
77 push(@sensorsgraphs, "$sensorsdir/$sensor_dir/$sensor");
81 # Look for ACPI Thermal Zone sensors.
82 my @thermal_zone_sensors = grep(/thermal-thermal_zone/, @sensor_dirs);
84 # If a thermal zone sensor has been found add it to the sensorsgraphs array.
85 if (@thermal_zone_sensors) {
86 # Loop through the array of thermal zone sensors.
87 foreach my $thermal_zone_sensor (@thermal_zone_sensors) {
88 # Add the sensor to the array.
89 push(@sensorsgraphs, "$sensorsdir/$thermal_zone_sensor");
93 my @querry = split(/\?/,$ENV{'QUERY_STRING'});
94 $querry[0] = '' unless defined $querry[0];
95 $querry[1] = 'hour' unless defined $querry[1];
97 if ( $querry[0] =~ "hwtemp"){
98 print "Content-type: image/png\n\n";
100 &Graphs
::updatehwtempgraph
($querry[1]);
101 }elsif ( $querry[0] =~ "hwfan"){
102 print "Content-type: image/png\n\n";
104 &Graphs
::updatehwfangraph
($querry[1]);
105 }elsif ( $querry[0] =~ "hwvolt"){
106 print "Content-type: image/png\n\n";
108 &Graphs
::updatehwvoltgraph
($querry[1]);
109 }elsif ( $querry[0] =~ "thermaltemp"){
110 print "Content-type: image/png\n\n";
112 &Graphs
::updatethermaltempgraph
($querry[1]);
113 }elsif ( $querry[0] =~ "sd?" ){
114 print "Content-type: image/png\n\n";
116 &Graphs
::updatehddgraph
($querry[0],$querry[1]);
117 }elsif ( $querry[0] =~ "nvme?" ){
118 print "Content-type: image/png\n\n";
120 &Graphs
::updatehddgraph
($querry[0],$querry[1]);
122 &Header
::showhttpheaders
();
123 &Header
::openpage
($Lang::tr
{'hardware graphs'}, 1, '');
124 &Header
::openbigbox
('100%', 'left');
126 &Header
::getcgihash
(\
%sensorsettings);
128 if ( $sensorsettings{'ACTION'} eq $Lang::tr
{'save'} ) {
129 foreach(@sensorsgraphs){
131 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
132 my $label = $2.$3;$label=~ s/-//g;
133 if ( $sensorsettings{'LINE-'.$label} ne "on" ){
134 $sensorsettings{'LINE-'.$label} = 'off';
135 } elsif ($sensorsettings{'LINE-'.$label} eq "on" ){
136 $sensorsettings{'LINE-'.$label} = 'checked';
138 $sensorsettings{'LABEL-'.$label} =~ s/\W//g;
140 &General
::writehash
("${General::swroot}/sensors/settings", \
%sensorsettings);
143 # This should be save, because no user given content will be processed.
144 #my @disks = `ls -1 /sys/block | grep -E '^sd|^nvme' | sort | uniq`;
145 my @disks = &get_disks
();
150 my @array = split(/\//,$disk);
152 &Header
::openbox
('100%', 'center', "$array[$#array] $Lang::tr{'graph'}");
153 &Graphs
::makegraphbox
("hardwaregraphs.cgi",$array[$#array],"day");
157 if ( grep(/thermal-thermal_zone/, @sensorsgraphs) ) {
158 &Header
::openbox
('100%', 'center', "ACPI Thermal-Zone Temp $Lang::tr{'graph'}");
159 &Graphs
::makegraphbox
("hardwaregraphs.cgi","thermaltemp","day");
163 if ( grep(/temperature-/, @sensorsgraphs) ) {
164 &Header
::openbox
('100%', 'center', "hwtemp $Lang::tr{'graph'}");
165 &Graphs
::makegraphbox
("hardwaregraphs.cgi","hwtemp","day");
169 if ( grep(/fanspeed-/, @sensorsgraphs) ) {
170 &Header
::openbox
('100%', 'center', "hwfan $Lang::tr{'graph'}");
171 &Graphs
::makegraphbox
("hardwaregraphs.cgi","hwfan","day");
175 if ( grep(/voltage-/, @sensorsgraphs) ) {
176 &Header
::openbox
('100%', 'center', "hwvolt $Lang::tr{'graph'}");
177 &Graphs
::makegraphbox
("hardwaregraphs.cgi","hwvolt","day");
181 if ( @sensorsgraphs ) {
184 &Header
::closebigbox
();
185 &Header
::closepage
();
191 &Header
::openbox
('100%', 'center', "$Lang::tr{'mbmon settings'}");
194 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
195 <table width='100%' border='0' cellspacing='5' cellpadding='0' align='center'>
197 <td align='right' width='40%'><b>$Lang::tr{'mbmon display'}</b></td>
198 <td align='left'><b>$Lang::tr{'mbmon label'}</b></td>
203 foreach (@sensorsgraphs){
204 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
205 my $label = $2.$3;$label=~ s/-//g;
206 $sensorsettings{'LABEL-'.$label}="$label";
207 $sensorsettings{'LINE-'.$label}="checked";
208 &General
::readhash
("${General::swroot}/sensors/settings", \
%sensorsettings);
209 print("<tr><td align='right'><input type='checkbox' name='LINE-$label' $sensorsettings{'LINE-'.$label} /></td>");
210 print("<td><input type='text' name='LABEL-$label' value='$sensorsettings{'LABEL-'.$label}' size='25' /></td></tr>\n");
215 <td align='center' colspan='2' ><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
227 # Open virtal sys FS and grab block devices.
228 opendir(SYS
, "/sys/block") or die "Could not opendir /sys/block/: $!\n";
230 # Grab all available block devices.
231 my @blockdevs = readdir(SYS
);
233 # Close directory handle.
236 # Loop through the array of blockdevs.
237 foreach my $dev (@blockdevs) {
238 # Skip all devices which does not start with "sd" or "nvme".
239 next unless (( $dev =~ /^sd/) || ($dev =~ /^nvme/));
241 # Add the device to the array of disks.
246 my @disks = &uniq
(@disks);
249 my @disks = sort(@disks);
255 # Tiny code snipped to get a uniq() like function.
258 return grep { !$seen{$_}++ } @_;