#!/usr/local/bin/perl
#use HTML::TableExtract;
use LWP::UserAgent;
use URI::Escape;
use HTTP::Request;
use HTML::TreeBuilder;
use Data::Dumper;
use DBI;
use HTTP::Cookies;
$debug=0;
#require("/home/reptima/public_html/config.pl");
#$telefono="8513185";
#$telefono="8547809";
open(TEST, "/home/reptima/public_html/min.pl") || die("Could not open $data_file");
@raw_data=;
close(TEST);
$min[0]=$raw_data[0];
$min[1]=$raw_data[1];
$min[2]=$raw_data[2];
$min[3]=$raw_data[3];
$min[4]=$raw_data[4];
$min[5]=$raw_data[5];
$min[6]=$raw_data[6];
$min[7]=$raw_data[7];
open(TEST2, "/home/reptima/public_html/max.pl") || die("Could not open $data_file");
@raw_data2=;
close(TEST2);
$max[0]=$raw_data2[0];
$max[1]=$raw_data2[1];
$max[2]=$raw_data2[2];
$max[3]=$raw_data2[3];
$max[4]=$raw_data2[4];
$max[5]=$raw_data2[5];
$max[6]=$raw_data2[6];
$max[7]=$raw_data2[7];
open(TEST3, "/home/reptima/public_html/phones.pl") || die("Could not open $data_file");
@raw_data3=;
close(TEST3);
$tel1=$raw_data3[0];
$tel2=$raw_data3[1];
$tel3=$raw_data3[2];
$tel4=$raw_data3[3];
open(TEST4, "/home/reptima/public_html/offsets.pl") || die("Could not open $data_file");
@raw_data4=;
close(TEST4);
$off[0]=$raw_data4[0];
$off[1]=$raw_data4[1];
$off[2]=$raw_data4[2];
$off[3]=$raw_data4[3];
$off[4]=$raw_data4[4];
$off[5]=$raw_data4[5];
$off[6]=$raw_data4[6];
$off[7]=$raw_data4[7];
$dbh = DBI->connect('dbi:mysql:base', 'user', 'pass' );
$ua = LWP::UserAgent->new;
$request = HTTP::Request->new(GET => 'ip');
$response = $ua->request($request);
my $tree = HTML::TreeBuilder->new();
$tree->parse($response->as_string());
$tree->eof;
$path="/home/reptima/public_html/t108";
$t=time;
#18.01.2005 14:40
($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(time);
my $Month = $Month + 1; # Months of the year are not zero-based
if($Month < 10)
{
$Month = "0" . $Month; # add a leading zero to one-digit months
}
if($Day < 10)
{
$Day = "0" . $Day; # add a leading zero to one-digit days
}
$Year += 1900;
$t= "$Year-$Month-$Day $Hour:$Minute:$Second";
#print $t."\n";
$trigger=0;
$file="t1.dat";
$ad="0.1.2.0.0.0";
$a11=$tree->address($ad)->as_text();
print "testing $a11";
($a1)=($a11 =~ /Min:(.*)Max/);
@a2=split(" ",$a1);
$t1Min=$a2[0];
$t1Cur=$a2[1];
$t1Cur=~ s/°//g;
`echo "$t1Cur" > $path/$file`;
`echo "$t1Cur" >> $path/$file`;
#`echo "$t1Min" >> $path/t1`;
($t1Max)=($a11 =~ /Max:(.*)/);
$t1Max=~ s/ //g;
#`echo "$t1Max" >> $path/t1`;
$dev=$tree->address($ad.".0.0");
$date=`/bin/date`;
$date=~ s/\n//g;
`echo "$date" >> $path/$file`;
`echo "$dev" >> $path/$file`;
$sth = $dbh->prepare("INSERT INTO data1 (date,outside,inside) VALUES ('$t','$t1Cur','$t1Cur')");
$sth->execute;
$sth->finish;
$title2="Tortoise";
if ((($t1Cur+$off[0]) < $min[0])){
mkmsg("low",$t1Cur+$off[0], $min[0],$title2);
$trigger++;
}
if ((($t1Cur+$off[0]) > $max[0])) {
mkmsg("high",$t1Cur+$off[0], $max[0],$title2);
$trigger++;
}
#$string=$string."Tortoise%20$t1Cur%0D%0A";
print "$title2 $t1Cur offset: $off[0]\n" if debug > 0;
#sub mkmsg {
#$problem=$_[0];
#$curr=$_[1];
#$limit=$_[2];
#$title3=$_[3];
#$string=$string.$title3."%20".$curr."F%0D%0Ais%20too%20".$problem."%0D%0Ashould%20be%20".$limit."F";
#}
$file="t2.dat";
$ad="0.1.2.0.0.1";
$a11=$tree->address($ad)->as_text();
($a1)=($a11 =~ /Min:(.*)Max/);
@a2=split(" ",$a1);
$t1Min=$a2[0];
$t1Cur=$a2[1];
$t1Cur=~ s/°//g;
`echo "$t1Cur" > $path/$file`;
`echo "$t1Cur" >> $path/$file`;
#`echo "$t1Min" >> $path/t1`;
($t1Max)=($a11 =~ /Max:(.*)/);
$t1Max=~ s/ //g;
#`echo "$t1Max" >> $path/t1`;
$dev=$tree->address($ad.".0.0");
$date=`/bin/date`;
$date=~ s/\n//g;
`echo "$date" >> $path/$file`;
`echo "$dev" >> $path/$file`;
$sth = $dbh->prepare("INSERT INTO data2 (date,outside,inside) VALUES ('$t','$t1Cur','$t1Cur')");
$sth->execute;
$sth->finish;
$title2="Dragon";
if ((($t1Cur+$off[1]) < $min[1])){
mkmsg("low",$t1Cur+$off[1], $min[1],$title2);
$trigger++;
}
if ((($t1Cur+$off[1]) > $max[1])) {
mkmsg("high",$t1Cur+$off[1], $max[1],$title2);
$trigger++;
}
print "$title2 $t1Cur offset: $off[1]\n" if debug > 0;
#$string=$string."Dragon%20$t1Cur%0D%0A";
$file="t3.dat";
$ad="0.1.2.0.1.0";
$a11=$tree->address($ad)->as_text();
($a1)=($a11 =~ /Min:(.*)Max/);
@a2=split(" ",$a1);
$t1Min=$a2[0];
$t1Cur=$a2[1];
$t1Cur=~ s/°//g;
`echo "$t1Cur" > $path/$file`;
`echo "$t1Cur" >> $path/$file`;
#`echo "$t1Min" >> $path/t1`;
($t1Max)=($a11 =~ /Max:(.*)/);
$t1Max=~ s/ //g;
#`echo "$t1Max" >> $path/t1`;
$dev=$tree->address($ad.".0.0");
$date=`/bin/date`;
$date=~ s/\n//g;
`echo "$date" >> $path/$file`;
`echo "$dev" >> $path/$file`;
$sth = $dbh->prepare("INSERT INTO data3 (date,outside,inside) VALUES ('$t','$t1Cur','$t1Cur')");
$sth->execute;
$sth->finish;
$title2="Chamaleon";
if ((($t1Cur+$off[2]) < $min[2])){
mkmsg("low",$t1Cur+$off[2], $min[2],$title2);
$trigger++;
}
if ((($t1Cur+$off[2]) > $max[2])) {
mkmsg("high",$t1Cur+$off[2], $max[2],$title2);
$trigger++;
}
print "$title2 $t1Cur\n" if debug > 0;
#$string=$string."Chamaleon%20$t1Cur%0D%0A";
$file="t4.dat";
$ad="0.1.2.0.1.1";
$a11=$tree->address($ad)->as_text();
($a1)=($a11 =~ /Min:(.*)Max/);
@a2=split(" ",$a1);
$t1Min=$a2[0];
$t1Cur=$a2[1];
$t1Cur=~ s/°//g;
`echo "$t1Cur" > $path/$file`;
`echo "$t1Cur" >> $path/$file`;
#`echo "$t1Min" >> $path/t1`;
($t1Max)=($a11 =~ /Max:(.*)/);
$t1Max=~ s/ //g;
#`echo "$t1Max" >> $path/t1`;
$dev=$tree->address($ad.".0.0");
$date=`/bin/date`;
$date=~ s/\n//g;
`echo "$date" >> $path/$file`;
`echo "$dev" >> $path/$file`;
$sth = $dbh->prepare("INSERT INTO data4 (date,outside,inside) VALUES ('$t','$t1Cur','$t1Cur')");
$sth->execute;
$sth->finish;
$title2="Cricket%20Eggs";
if ((($t1Cur+$off[3]) < $min[3])){
mkmsg("low",$t1Cur+$off[3], $min[3],$title2);
$trigger++;
}
if ((($t1Cur+$off[3]) > $max[3])) {
mkmsg("high",$t1Cur+$off[3], $max[3],$title2);
$trigger++;
}
print "$title2 $t1Cur offset: $off[3]\n" if debug > 0;
#$string=$string."Cricket%20$t1Cur%0D%0A";
$file="t5.dat";
$ad="0.1.2.0.2.0";
$a11=$tree->address($ad)->as_text();
($a1)=($a11 =~ /Min:(.*)Max/);
@a2=split(" ",$a1);
$t1Min=$a2[0];
$t1Cur=$a2[1];
$t1Cur=~ s/°//g;
`echo "$t1Cur" > $path/$file`;
`echo "$t1Cur" >> $path/$file`;
#`echo "$t1Min" >> $path/t1`;
($t1Max)=($a11 =~ /Max:(.*)/);
$t1Max=~ s/ //g;
#`echo "$t1Max" >> $path/t1`;
$dev=$tree->address($ad.".0.0");
$date=`/bin/date`;
$date=~ s/\n//g;
`echo "$date" >> $path/$file`;
`echo "$dev" >> $path/$file`;
$sth = $dbh->prepare("INSERT INTO data5 (date,outside,inside) VALUES ('$t','$t1Cur','$t1Cur')");
$sth->execute;
$sth->finish;
$title2="Incubator";
if ((($t1Cur+$off[4]) < $min[4])){
mkmsg("low",$t1Cur+$off[4], $min[4],$title2);
$trigger++;
}
if ((($t1Cur+$off[4]) > $max[4])) {
mkmsg("high",$t1Cur+$off[4], $max[4],$title2);
$trigger++;
}
print "$title2 $t1Cur offset: $off[4]\n" if debug > 0;
#$string=$string."Incubator%20$t1Cur%0D%0A";
$file="t6.dat";
$ad="0.1.2.0.2.1";
$a11=$tree->address($ad)->as_text();
($a1)=($a11 =~ /Min:(.*)Max/);
@a2=split(" ",$a1);
$t1Min=$a2[0];
$t1Cur=$a2[1];
$t1Cur=~ s/°//g;
`echo "$t1Cur" > $path/$file`;
`echo "$t1Cur" >> $path/$file`;
#`echo "$t1Min" >> $path/t1`;
($t1Max)=($a11 =~ /Max:(.*)/);
$t1Max=~ s/ //g;
#`echo "$t1Max" >> $path/t1`;
$dev=$tree->address($ad.".0.0");
$date=`/bin/date`;
$date=~ s/\n//g;
`echo "$date" >> $path/$file`;
`echo "$dev" >> $path/$file`;
$sth = $dbh->prepare("INSERT INTO data6 (date,outside,inside) VALUES ('$t','$t1Cur','$t1Cur')");
$sth->execute;
$sth->finish;
$title2="Cold Room 1";
if ((($t1Cur+$off[5]) < $min[5])){
mkmsg("low",($t1Cur+$off[5]), $min[5],$title2);
$trigger++;
}
if ((($t1Cur+$off[5]) > $max[5])) {
mkmsg("high",($t1Cur+$off[5]), $max[5],$title2);
$trigger++;
}
print "$title2 $t1Cur\n" if debug > 0;
#$string=$string."Spare%20$t1Cur%0D%0A";
$file="t7.dat";
$ad="0.1.2.0.3.0";
$a11=$tree->address($ad)->as_text();
($a1)=($a11 =~ /Min:(.*)Max/);
@a2=split(" ",$a1);
$t1Min=$a2[0];
$t1Cur=$a2[1];
$t1Cur=~ s/°//g;
`echo "$t1Cur" > $path/$file`;
`echo "$t1Cur" >> $path/$file`;
#`echo "$t1Min" >> $path/t1`;
($t1Max)=($a11 =~ /Max:(.*)/);
$t1Max=~ s/ //g;
#`echo "$t1Max" >> $path/t1`;
$dev=$tree->address($ad.".0.0");
$date=`/bin/date`;
$date=~ s/\n//g;
`echo "$date" >> $path/$file`;
`echo "$dev" >> $path/$file`;
$sth = $dbh->prepare("INSERT INTO data7 (date,outside,inside) VALUES ('$t','$t1Cur','$t1Cur')");
$sth->execute;
$sth->finish;
$title2="Cold Room 2";
if ((($t1Cur+$off[6]) < $min[6])){
mkmsg("low",($t1Cur+$off[6]), $min[6],$title2);
$trigger++;
}
if ((($t1Cur+$off[6]) > $max[6])) {
mkmsg("high",($t1Cur+$off[6]), $max[6],$title2);
$trigger++;
}
print "$title2 $t1Cur\n" if debug > 0;
#$string=$string."Spare%20$t1Cur%0D%0A";
$file="t8.dat";
$ad="0.1.2.0.3.1";
$a11=$tree->address($ad)->as_text();
($a1)=($a11 =~ /Min:(.*)Max/);
@a2=split(" ",$a1);
$t1Min=$a2[0];
$t1Cur=$a2[1];
$t1Cur=~ s/°//g;
`echo "$t1Cur" > $path/$file`;
`echo "$t1Cur" >> $path/$file`;
#`echo "$t1Min" >> $path/t1`;
($t1Max)=($a11 =~ /Max:(.*)/);
$t1Max=~ s/ //g;
#`echo "$t1Max" >> $path/t1`;
$dev=$tree->address($ad.".0.0");
$date=`/bin/date`;
$date=~ s/\n//g;
`echo "$date" >> $path/$file`;
`echo "$dev" >> $path/$file`;
$sth = $dbh->prepare("INSERT INTO data8 (date,outside,inside) VALUES ('$t','$t1Cur','$t1Cur')");
$sth->execute;
$sth->finish;
$title2="ColdRoom 3";
print $t1Cur+$off[7].":".$max[7];
if ((($t1Cur+$off[7]) < $min[7])){
mkmsg("low",($t1Cur+$off[7]), $min[7],$title2);
$trigger++;
}
if ((($t1Cur+$off[7]) > $max[7])) {
mkmsg("high",($t1Cur+$off[7]), $max[7],$title2);
$trigger++;
}
print "$title2 $t1Cur\n" if debug > 0;
#$string=$string."ColdRoom%20$t1Cur%0D%0A";
sub mkmsg {
$problem=$_[0];
$curr=$_[1];
$limit=$_[2];
$title3=$_[3];
$string=$string."%0D%0A".$title3."%20".$curr."F%0D%0Ais%20too%20".$problem."%0D%0Ashould%20be%20".$limit."F";
}
if ($trigger > 0) {
#check("$trigger%20Alarm%0D%0A".$string,$tel1);
#check("$trigger%20Alarm%0D%0A".$string,$tel2);
#check("$trigger%20Alarm%0D%0A".$string,$tel3);
#check("$trigger%20Alarm%0D%0A".$string,$tel4);
print "message sended: $string";
}
$dbh->disconnect();
sub check
{
$telefono=$_[1];
$string2=$_[0];
$cookie_jar = HTTP::Cookies->new( );
my $req = new HTTP::Request POST =>
"http://www.telecom.com.sv/notiavanzados/ProcessNotipersonal.asp";
$req->content_type('application/x-www-form-urlencoded');
$req->content("txtPhone=$telefono&areaMsg=$string2");
## $req->header('Cookie'=>'FromTelecom=1;Site=www%2Etelecom%2Ecom%2Esv');
$ua = LWP::UserAgent->new;
$ua->agent( 'Mozilla/4.0 (compatible; MSIE 5.12; Mac_PowerPC)' );
$cookie_jar->add_cookie_header($req);
$response = $ua->request($req);
print $response->content;
print $req->content;
}