Author Topic: Pollution Script  (Read 701 times)

0 Members and 1 Guest are viewing this topic.

Offline ingogliar

  • Senior Member
  • **
  • Posts: 60
Pollution Script
« on: April 02, 2019, 06:06:51 PM »
Sorry to trouble you kind folks, but I am having an issue with the pollution script for my station:https://heightsweather.info. The air pollution graph (for NJ) used to show up fine (Saratoga scripts - "NJ Air Pollution") in Firefox; now, it does not show up (but it will show up in IE 9).

What do I need to do to make it appear again in Firefox?
« Last Edit: April 02, 2019, 06:10:54 PM by ingogliar »

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Pollution Script
« Reply #1 on: April 02, 2019, 09:44:52 PM »
It's likely that the iframe to http://www.njaqinow.net/DynamicTable.aspx?G_ID=0 is loading http content in an otherwise https page.

Various browsers handle this case differently.  Firefox (and likely Chrome) will not allow it on https pages.

IE9 is quite old and probably doesn't give a fig about mixed http/https content.

It also appears that www.njaqinow.net is http-only (no https available).

One way to 'fix' (read avoid) this issue is to 'proxy' the access on your page.  Something like
Code: [Select]
<?php
    $STRopts 
= array(
      
'http' => array(
        
'method' => "GET",
        
'protocol_version' => 1.1,
        
'header' => "Cache-Control: no-cache, must-revalidate\r\n" 
"Cache-control: max-age=0\r\n" 
"Connection: close\r\n" 
"User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0\r\n" 
"Accept: text/html\r\n"
      
) ,
      
'ssl' => array(
        
'method' => "GET",
        
'protocol_version' => 1.1,
        
'header' => "Cache-Control: no-cache, must-revalidate\r\n" 
"Cache-control: max-age=0\r\n" 
"Connection: close\r\n" 
"User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0\r\n" 
"Accept: text/html\r\n"
      
)
    );
    
$STRcontext stream_context_create($STRopts);



$stuff file_get_contents("http://www.njaqinow.net/DynamicTable.aspx?G_ID=0",false,$STRcontext);
preg_match('|<table cellspacing="0" rules="all"(.*)</table>|Uis',$stuff,$matches);
$justTable $matches[0];
$justTable strip_tags($justTable,'<div><table><tr><td><th>');

if(
strlen($stuff) > 400) {
print "<p>&nbsp</p>\n";
print $justTable;
} else {
  print 
"<h2>Sorry.. the AQI data is not currently available</h2>\n";
}
?>
   

instead of just having
Code: [Select]
<iframe src="http://www.njaqinow.net/DynamicTable.aspx?G_ID=0" width="1000" height="800" frameborder="0" scrolling="no"></iframe>
Edit: modified version.. they like to see request headers.  The returned result has broken image and hotlink addresses since this script does nothing to reprocess those.  But it does load (tested on my test site)

Edit2: modified the above to parse the page a bit, extract the table with the data so only the table tags are kept.  Then just print the table in the page.  Styling is a bit primitive, but the data is there and none of the links that cause problems remain.
« Last Edit: April 03, 2019, 12:12:53 AM by saratogaWX »
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline ingogliar

  • Senior Member
  • **
  • Posts: 60
Re: Pollution Script
« Reply #2 on: April 03, 2019, 06:54:23 AM »
Ken (and/or anyone else who helped),

First of all - a very big thanks for the help.

I pasted in the revised script and now all I get is a blank page. I am sure that I am doing something wrong, so - if time permits - please tell me what I am doing incorrectly:

<?php
############################################################################
# A Project of TNET Services, Inc. and Saratoga-Weather.org (Canada/World-ML template set)
############################################################################
#
#   Project:    Sample Included Website Design
#   Module:     sample.php
#   Purpose:    Sample Page
#   Authors:    Kevin W. Reed <kreed@tnet.com>
#               TNET Services, Inc.
#
#    Copyright:   (c) 1992-2007 Copyright TNET Services, Inc.
############################################################################
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
############################################################################
#   This document uses Tab 4 Settings
############################################################################
require_once("Settings.php");
require_once("common.php");
############################################################################
$TITLE = langtransstr($SITE['organ']) . " - " .langtransstr('Sample Blank Page');
$showGizmo = true;  // set to false to exclude the gizmo
include("top.php");
############################################################################
?>
</head>
<body>
<?php
############################################################################
include("header.php");
############################################################################
include("menubar.php");
############################################################################
?>

<div id="main-copy">
<center>
<p><b>Legend</b></p>
<img src="legend.jpg">
</center>
<center> 
   <h1><?php langtrans('AIR POLLUTION - NEW JERSEY'); ?></h1>
   <p>Source: <a href="http://www.njaqinow.net/">NJ Department of Environmental Protection - Air Monitoring Web Site</a></p>
<?php
    $STRopts = array(
      'http' => array(
        'method' => "GET",
        'protocol_version' => 1.1,
        'header' => "Cache-Control: no-cache, must-revalidate\r\n" .
               "Cache-control: max-age=0\r\n" .
               "Connection: close\r\n" .
               "User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0\r\n" .
               "Accept: text/html\r\n"
      ) ,
      'ssl' => array(
        'method' => "GET",
        'protocol_version' => 1.1,
        'header' => "Cache-Control: no-cache, must-revalidate\r\n" .
               "Cache-control: max-age=0\r\n" .
</center>
</div><!-- end main-copy -->

<?php
############################################################################
include("footer.php");
############################################################################
# End of Page
############################################################################
?>

Offline txweather.org

  • Forecaster
  • *****
  • Posts: 1597
    • Texas Weather
Re: Pollution Script
« Reply #3 on: April 03, 2019, 08:02:54 AM »
Can you please post the link directly to your pollution report page?

Thanks!

----
Davis Vantage Pro2 Plus +FARS|Meteobridge Nano SD|Meteohub|Meteobridge MR-3020|WU KTXSPRIN75/PWS JRARGWX75/CWOP EW2972/WBB TXWDVUE75/Blitzortung ID: 1142|AWEKAS: 12095
Donations are welcome: https://paypal.me/ffuentesb

Offline the beteljuice

  • the beteljuice
  • Forecaster
  • *****
  • Posts: 316
    • test site
Re: Pollution Script
« Reply #4 on: April 03, 2019, 09:32:14 AM »
Half the code is missing ! ........

Code: [Select]
        'protocol_version' => 1.1,
        'header' => "Cache-Control: no-cache, must-revalidate\r\n" .
               "Cache-control: max-age=0\r\n" .

?????????????
?????????????
?????????????


</center>
Cut'n'Paste problem ?
Imagine what you will KNOW tomorrow !

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Pollution Script
« Reply #5 on: April 03, 2019, 10:40:29 AM »
Yes, only the top part of the code was selected/copy/pasted into the page.

The full page should appear as
Quote
<?php
############################################################################
# A Project of TNET Services, Inc. and Saratoga-Weather.org (Canada/World-ML template set)
############################################################################
#
#   Project:    Sample Included Website Design
#   Module:     sample.php
#   Purpose:    Sample Page
#   Authors:    Kevin W. Reed <kreed@tnet.com>
#               TNET Services, Inc.
#
#    Copyright:   (c) 1992-2007 Copyright TNET Services, Inc.
############################################################################
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
############################################################################
#   This document uses Tab 4 Settings
############################################################################
require_once("Settings.php");
require_once("common.php");
############################################################################
$TITLE = langtransstr($SITE['organ']) . " - " .langtransstr('Sample Blank Page');
$showGizmo = true;  // set to false to exclude the gizmo
include("top.php");
############################################################################
?>
</head>
<body>
<?php
############################################################################
include("header.php");
############################################################################
include("menubar.php");
############################################################################
?>

<div id="main-copy">
<center>
<p><b>Legend</b></p>
<img src="legend.jpg">
</center>
<center>
   <h1><?php langtrans('AIR POLLUTION - NEW JERSEY'); ?></h1>
   <p>Source: <a href="http://www.njaqinow.net/">NJ Department of Environmental Protection - Air Monitoring Web Site</a></p>
<?php
    $STRopts = array(
      'http' => array(
        'method' => "GET",
        'protocol_version' => 1.1,
        'header' => "Cache-Control: no-cache, must-revalidate\r\n" .
"Cache-control: max-age=0\r\n" .
"Connection: close\r\n" .
"User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0\r\n" .
"Accept: text/html\r\n"
      ) ,
      'ssl' => array(
        'method' => "GET",
        'protocol_version' => 1.1,
        'header' => "Cache-Control: no-cache, must-revalidate\r\n" .
"Cache-control: max-age=0\r\n" .
"Connection: close\r\n" .
"User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0\r\n" .
"Accept: text/html\r\n"
      )
    );
    $STRcontext = stream_context_create($STRopts);



$stuff = file_get_contents("http://www.njaqinow.net/DynamicTable.aspx?G_ID=0",false,$STRcontext);
preg_match('|<table cellspacing="0" rules="all"(.*)</table>|Uis',$stuff,$matches);
$justTable = $matches[0];
$justTable = strip_tags($justTable,'<div><table><tr><td><th>');

if(strlen($stuff) > 400) {
print "<p>&nbsp</p>\n";
print $justTable;
} else {
  print "<h2>Sorry.. the AQI data is not currently available</h2>\n";
}
?>  </center>
</div><!-- end main-copy -->

<?php
############################################################################
include("footer.php");
############################################################################
# End of Page
############################################################################
?>
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline ingogliar

  • Senior Member
  • **
  • Posts: 60
Re: Pollution Script
« Reply #6 on: April 03, 2019, 02:10:19 PM »
Ken (and everyone),

Thank you so much - I cannot believe how stupid I am. Thank you so much for helping me - I really appreciate it. It works perfectly. When time permits (after the end of the semester), I am going to sit down and pull apart - line by line - how this was fixed so that I can understand what was done and - incidentally - not bother anyone.

Again, thanks.