#!/usr/bin/perl -wT #---------------------------------------------------------------------- # Description : Server Temperature # # $Id: temperature,v 1.2 2002/12/22 21:09:03 wellsi Exp $ #---------------------------------------------------------------------- package esmith; use strict; use CGI ':all'; use CGI::Carp qw(fatalsToBrowser); use esmith::cgi; use esmith::db; use esmith::util; sub showInitial ($); sub checkSensorTemp ($); BEGIN { # Clear PATH and related environment variables so that calls to # external programs do not cause results to be tainted. See # "perlsec" manual page for details. $ENV {'PATH'} = '/bin:/usr/bin'; $ENV {'SHELL'} = '/bin/bash'; delete $ENV {'ENV'}; } $CGI::POST_MAX=1024 * 100; # max 100K posts $CGI::DISABLE_UPLOADS = 1; # no uploads my %conf; tie %conf, 'esmith::config'; #------------------------------------------------------------ # Read the current sensor information # Change this as needed for your sensor. #------------------------------------------------------------ my @sensorOutput = `/usr/bin/sensors via686a-isa-6000`; #------------------------------------------------------------ # examine state parameter and display the appropriate form #------------------------------------------------------------ my $q = new CGI; if (! grep (/^state$/, $q->param)) { showInitial ($q); } else { esmith::cgi::genStateError ($q, \%conf); } exit (0); #------------------------------------------------------------ # subroutine to display initial form #------------------------------------------------------------ sub showInitial ($) { my $CPUtemp = checkSensorTemp("CPU"); my $SYStemp = checkSensorTemp("SYS"); my ($q) = @_; print $q->header; print $q->start_html(-title=>'Server Temperature'); print $q->h1('Server Temperature'); print $q->p ("$SYStemp System Temperature"); print $q->p ("$CPUtemp CPU Temperature"); print $q->end_html; } sub checkSensorTemp ($) { # Determine the temperature from a given sensor my $sensor = $_[0]; my $temperature=""; # The default will be to return nothing foreach my $line (@sensorOutput ){ if ($line =~ m/$sensor.*(.\d\d.\d..)/){ # Let's assume that the temperature will be +xx.x $temperature = $1; # save the required temperature } } return $temperature; }