]>
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 &Header
::showhttpheaders
();
94 &Header
::openpage
($Lang::tr
{'hardware graphs'}, 1, '');
95 &Header
::openbigbox
('100%', 'left');
97 &Header
::getcgihash
(\
%sensorsettings);
99 if ( $sensorsettings{'ACTION'} eq $Lang::tr
{'save'} ) {
100 foreach(@sensorsgraphs){
102 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
103 my $label = $2.$3;$label=~ s/-//g;
104 if ( $sensorsettings{'LINE-'.$label} ne "on" ){
105 $sensorsettings{'LINE-'.$label} = 'off';
106 } elsif ($sensorsettings{'LINE-'.$label} eq "on" ){
107 $sensorsettings{'LINE-'.$label} = 'checked';
109 $sensorsettings{'LABEL-'.$label} =~ s/\W//g;
111 &General
::writehash
("${General::swroot}/sensors/settings", \
%sensorsettings);
114 # This should be save, because no user given content will be processed.
115 #my @disks = `ls -1 /sys/block | grep -E '^sd|^nvme' | sort | uniq`;
116 my @disks = &get_disks
();
121 my @array = split(/\//,$disk);
123 &Header
::openbox
('100%', 'center', "$array[$#array] $Lang::tr{'graph'}");
124 &Graphs
::makegraphbox
("hardwaregraphs.cgi",$array[$#array],"day");
128 if ( grep(/thermal-thermal_zone/, @sensorsgraphs) ) {
129 &Header
::openbox
('100%', 'center', "ACPI Thermal-Zone Temp $Lang::tr{'graph'}");
130 &Graphs
::makegraphbox
("hardwaregraphs.cgi","thermaltemp","day");
134 if ( grep(/temperature-/, @sensorsgraphs) ) {
135 &Header
::openbox
('100%', 'center', "hwtemp $Lang::tr{'graph'}");
136 &Graphs
::makegraphbox
("hardwaregraphs.cgi","hwtemp","day");
140 if ( grep(/fanspeed-/, @sensorsgraphs) ) {
141 &Header
::openbox
('100%', 'center', "hwfan $Lang::tr{'graph'}");
142 &Graphs
::makegraphbox
("hardwaregraphs.cgi","hwfan","day");
146 if ( grep(/voltage-/, @sensorsgraphs) ) {
147 &Header
::openbox
('100%', 'center', "hwvolt $Lang::tr{'graph'}");
148 &Graphs
::makegraphbox
("hardwaregraphs.cgi","hwvolt","day");
152 if ( @sensorsgraphs ) {
155 &Header
::closebigbox
();
156 &Header
::closepage
();
159 &Header
::openbox
('100%', 'center', "$Lang::tr{'mbmon settings'}");
162 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
163 <table width='100%' border='0' cellspacing='5' cellpadding='0' align='center'>
165 <td align='right' width='40%'><b>$Lang::tr{'mbmon display'}</b></td>
166 <td align='left'><b>$Lang::tr{'mbmon label'}</b></td>
171 foreach (@sensorsgraphs){
172 $_ =~ /\/(.*)sensors
-(.*)\
/(.*)\.rrd/;
173 my $label = $2.$3;$label=~ s/-//g;
174 $sensorsettings{'LABEL-'.$label}="$label";
175 $sensorsettings{'LINE-'.$label}="checked";
176 &General
::readhash
("${General::swroot}/sensors/settings", \
%sensorsettings);
177 print("<tr><td align='right'><input type='checkbox' name='LINE-$label' $sensorsettings{'LINE-'.$label} /></td>");
178 print("<td><input type='text' name='LABEL-$label' value='$sensorsettings{'LABEL-'.$label}' size='25' /></td></tr>\n");
183 <td align='center' colspan='2' ><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
195 # Open virtal sys FS and grab block devices.
196 opendir(SYS
, "/sys/block") or die "Could not opendir /sys/block/: $!\n";
198 # Grab all available block devices.
199 my @blockdevs = readdir(SYS
);
201 # Close directory handle.
204 # Loop through the array of blockdevs.
205 foreach my $dev (@blockdevs) {
206 # Skip all devices which does not start with "sd" or "nvme".
207 next unless (( $dev =~ /^sd/) || ($dev =~ /^nvme/));
209 # Add the device to the array of disks.
214 my @disks = &uniq
(@disks);
217 my @disks = sort(@disks);
223 # Tiny code snipped to get a uniq() like function.
226 return grep { !$seen{$_}++ } @_;