#!/usr/bin/perl #set $hw_cgi_dir_path to full path of hamweather cgi directory $hw_cgi_dir_path = "/home/powervision/public_html/weather"; unless (-e "$hw_cgi_dir_path") { $hw_cgi_dir_path = &get_dir_path; } ######################################################### $hamlib_path = "$hw_cgi_dir_path/hamlib"; $users_path = "$hw_cgi_dir_path/users"; ########################################################## # HAMweather 2.0 # This script is copyright(c) 2000 by HAMweather, LLC all rights reserved. # It is subject to the license agreement that can be found at the following # URL: https://www.hamweather.com/install/licenseinfo.html ######################################################### # Version Info # hamweather.cgi Pro Version 2.03 ######################################################### $hwversion{'hamweatherStandard'} = 2.036; #03/29/2000 9:24PM $hwversion{'hw2.0'} = 2.036; $| = 1; #print "Content-type: text/html\n\n"; print "DEBUG MODE ON
\n";
&hw_require (
1 => ["$hw_cgi_dir_path/hwconfig.txt", 0],
2 => ["$hamlib_path/hamlib.pl", 2.035],
3 => ["$hamlib_path/hw2lib.pl", 2.035]
);
#############################################
## Main Routine
#############################################
$foundplaceflag="false";
&parse_input;
&set_up;
&forecast_not_available(3) if ($zipcode_error);
$ENV{'HTTP_REFERER'} = $FORM{'referer'} if ($FORM{'referer'} && !$ENV{'HTTP_REFERER'});
####################################################
## Main routine
####################################################
$hicon = "na$gd_ext";
$hname = $hsky = $htempf = $htempc = $hrh = $hdewptf = $hhif = $hhic = $hdewptc = $hwc = $hhi ='N/A';
$hwind = $hpressure = $hremarks = $hforecastdate = $hquk = $hqul = 'N/A';
$forecastneeded = 'zandh' if ($stateneeded eq 'us' && ($forecastneeded eq 'zone' || $forecastneeded eq 'zandh'));
if ($forecastneeded eq "pass" && $pass_template ne "") {
if ($pass_templates{$pass_template}) {
$view_template = "$forecast_templates/$pass_templates{$pass_template}";
$foundplaceflag = "true";
}
}
else {
#require "$hamlib_path/hamweatherlib.pl";
hw_require (1 => ["$hamlib_path/hamweatherlib.pl", 2.035]);
if ($country eq 'ca') {hw_require (1 => ["$hamlib_path/hwcalib.pl", 2.035]); }
$forecastneeded = 'metar' if ($country !~ /^(?:us|ca)$/ && $icao && ($forecastneeded eq 'zandh' || $forecastneeded eq 'zone'));
# if we are busy mode thne we do not want to get METAR conditions unles we need
# to because they are slow!
$forecastneeded = 'zone' if ($busy_mode && $forecastneeded eq 'zandh' && $icao);
my $temp_place;
if ($forecastneeded eq 'statehourly') {
if (&fetch_forecast) {
$state_hourly = &process_state_hourly;
$foundplaceflag = 'true';
}
else {
$foundplaceflag = 0;
$state_hourly = $state_hourly_template_none;
}
}
elsif ($forecastneeded =~ m/hourly|zandh|metar/i) {
$no_error_display = 1 if ($forecastneeded eq "zandh");
#print "icao = $icao
\n";
if ($icao) {
my $old_forecastneeded = $forecastneeded;
$forecastneeded = "metar";
if (&fetch_forecast) {
$forecastneeded = $old_forecastneeded;
my ($hstate, $hcountry);
($foundhourly, $hname, $hstate, $hcountry, $hsky, $htempf, $hdewptf, $hrh, $hwind, $hpressure, $hforecastdate, $hhif, $hwc) = get_hourly_forecast(1);
if ($forecastneeded eq "metar") {
$place = $hname;
$state = $hstate;
$country= $hcountry;
$requested_place = $place;
}
} # end if (&fetch_forecast)
else {$found_hourly = 0;}
$forecastneeded = $old_forecastneeded;
}
else {
if (&fetch_forecast) {
if ($alt_cc_place) {
$temp_place = $place;
$place = $alt_cc_place;
}
($foundhourly, $hname, $hsky, $htempf, $hdewptf, $hrh, $hwind, $hpressure, $hremarks, $hforecastdate, $hhif, $hwc) = &get_hourly_forecast(0);
$place = $temp_place if ($temp_place);
}# end if (&fetch_forecast)
else {$found_hourly = 0;}
}
$hname = $place if ($alt_cc_code == 0 || $alt_cc_code == 2);
if ($foundhourly ne "true") {
$hicon = "na$gd_ext";
$hname = $hsky = $htempf = $htempc = $hrh = $hdewptf = $hdewptc = $hhif = $hhic = 'N/A';
$hwind = $hpressure = $hremarks = $hforecastdate ='N/A';
}
if ($alt_zone_place && $country ne 'ca') {
$temp_place = $place;
$place=$alt_zone_place;
}
else {$temp_place=$place;}
if ($forecastneeded eq "zandh") {
$forecastneeded = "zone";
$no_error_display = 1;
if ($country eq 'ca') {
&get_ca_zone_forecast;
if ($foundplaceflag eq "true" && !$alt_template) {
if ($foundhourly eq 'true') {
$view_template = "$forecast_templates/intzandh.html";
}
else {
$view_template = "$forecast_templates/intzone.html"
}
} # end if ($foundplaceflag eq "true" && !$alt_template)
}
else {
&get_forecast if ( &fetch_forecast);
}
print "foundplaceflag = $foundplaceflag
foundhourly = $foundhourly
\n" if $DEBUG;
if ($foundplaceflag ne 'true') {
if ($foundhourly eq 'true') {
$forecastneeded = 'hourly';
$forecastneeded = 'metar' if ($icao);
$foundplaceflag = 'true';
}
}
elsif ($foundhourly eq "true") {
$forecastneeded = "zandh";
} # end if
$place = $temp_place if (!$alt_zone_code || $alt_zone_place == 2);
} # end if
elsif ($foundhourly eq "true") {
$foundplaceflag = "true";
} # end elsif
if ($country eq 'us') {
#&update_radar if ($foundplaceflag eq "true" && !$country || $country eq 'us');
&check_warning($stateneeded, $find_zone, $find_county, 'warnings', 'Warning') if ($check_warning && ($find_zone || $find_county));
&check_warning($stateneeded, $find_zone, $find_county, 'watches', 'Watch') if ($check_watches && !$active_warning && ($find_zone || $find_county));
&check_warning($stateneeded, $find_zone, $find_county, 'special', 'Advisory') if ($check_special && !$active_warning && ($find_zone || $find_county));
}
}
else {
if ($country eq 'ca') {
&get_ca_zone_forecast;
$view_template = "$forecast_templates/intzone.html" if ($foundplaceflag eq "true" && !$alt_template);
}
else {
my $fetched_zone = &fetch_forecast;
my $temp_place;
if ($alt_zone_place) {
$temp_place = $place;
$place=$alt_zone_place;
}
&get_forecast if ($fetched_zone);
$place = $temp_place if ($temp_place);
&update_radar if ($foundplaceflag eq "true" && !$country || $country eq 'us');
#&check_warning($stateneeded, $find_zone, $find_county, 'warnings', 'Warning') if ($check_warning && ($find_zone || $find_county));
&check_warning($stateneeded, $find_zone, $find_county, 'watches', 'Watch') if ($check_watches && !$active_warning && ($find_zone || $find_county));
&check_warning($stateneeded, $find_zone, $find_county, 'special', 'Advisory') if ($check_special && !$active_warning && ($find_zone || $find_county));
}
}
} # end else
if ($map_mode != 2) {
if ($foundplaceflag ne "true") {
$view_template = "$forecast_templates/$view_no_forecast";
$zforecast = qq!The $forecastneeded forecast\/summary for $place, $state is currently unavailable at this time.
!;
&print_forecast;
} #end if
else {
&print_forecast;
}
}
exit;
#############################################
## update_radar
#############################################
sub update_radar {
}
#############################################
## hw_require
#############################################
sub get_dir_path {
my ($pwd, $dir_path, $cwd);
eval '$home = (getpwuid($< ))[7];';
if (!-e "C:/") {
$pwd = `pwd`; chop $pwd;
}
if (!eval 'use Cwd;') {
eval '$cwd = cwd();';
}
else {
$cwd = '';
}
if (!$pwd) {
$dir_path = $cwd;
} else {
$dir_path = $pwd;
}
return $dir_path;
}
#############################################
## hw_require
#############################################
sub hw_require {
my (%files) = @_;
my ($vname, $filename, $version);
foreach my $file_num (sort keys %files) {
($filename, $version) = @{ $files{$file_num} };
if ($filename =~ m/.*\/([^\/]+)$/) {
$vname = $1;
}
else {
$vname = $filename;
}
eval { require "$filename"; };
if ($@ || $hwversion{$vname} < $version) {
print "Content-type: text/html\n\n";
print "
\n$@
\n"; print "The load request originated from package $package, filename $filename at line $line
\n";
exit;
}
} # end foreach
if ($DEBUG) {
#print "Content-type: text/html\n\n";
print "
\n"; } } # end sub sub BEGIN { $START_TIME = (times)[0]; } sub END { if ($DEBUG) { printf "Total run time was %.2f seconds", ((times)[0] - $START_TIME); } }