Update of /cvsroot/phpweather/phpweather
In directory usw-pr-cvs1:/tmp/cvs-serv14242
Modified Files:
configurator.php data_retrieval.php defaults-dist.php
Log Message:
This adds support for proxy servers.
Index: configurator.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/configurator.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- configurator.php 2001/06/27 11:32:25 1.6
+++ configurator.php 2001/06/29 09:42:36 1.7
@@ -187,7 +187,7 @@
function get_config($new_data) {
list($default) = each($this->data);
if ($new_data != $default) {
- return $this->config_header . "'$new_data';\n\n";
+ return $this->config_header . "$new_data;\n\n";
} else {
return '';
}
@@ -209,6 +209,26 @@
'EKYT',
'This will be the default station used by PHP Weather. ' .
'You should enter a four-letter ICAO.');
+
+$properties['use_proxy'] =
+ new boolean('use_proxy',
+ array('false' => 'No',
+ 'true' => 'Yes'),
+ "Set this option to 'Yes' to enable support for " .
+ "proxy servers. If you do, you'll have to set the " .
+ "next two options as well.");
+
+$properties['proxy_host'] =
+ new text('proxy_host',
+ '',
+ "This is the hostname of the proxy server.");
+
+$properties['proxy_port'] =
+ new text('proxy_port',
+ '3128',
+ "This is the port number of the proxy server. The " .
+ "default is what is used by the Squid proxy server. " .
+ "Another common port number is '8080'");
$properties['db_hostname'] =
new text('db_hostname',
Index: data_retrieval.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/data_retrieval.php,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- data_retrieval.php 2001/06/27 11:20:01 1.10
+++ data_retrieval.php 2001/06/29 09:42:36 1.11
@@ -162,9 +162,36 @@
function get_metar_from_web($new_station) {
$metar = '';
$icao = $this->get_icao();
-
- /* We use the @file notation here because it might fail. */
- $file =
@file("http://weather.noaa.gov/pub/data/observations/metar/stations/$icao.TXT");
+
+ if ($this->properties['use_proxy']) { /* We use a proxy */
+ /* Inspirated by code from Paul Kairis <[EMAIL PROTECTED]> */
+
+ $fp = fsockopen($this->properties['proxy_host'],
+ $this->properties['proxy_port']);
+ if ($fp) {
+ fputs($fp, 'GET http://weather.noaa.gov/pub/data/' .
+ "observations/metar/stations/$icao.TXT HTTP/1.0\r\n\r\n");
+ /* We check the status line */
+ if (strpos(fgets($fp, 1024), '200 OK')) {
+ /* Then we seek until we find the empty line between the
+ headers and the contents. */
+ do {
+ $line = fgets($fp, 1024);
+ } while ($line != "\r\n");
+ /* We now know, that the following lines are the contents. */
+ unset($file);
+ while ($line = fgets($fp, 1024)) {
+ $file[] = $line;
+ }
+ fclose($fp);
+ }
+ }
+ } else { /* No proxy - we just fetch the file the normal way. */
+
+ /* We use the @file notation here because it might fail. */
+ $file = @file('http://weather.noaa.gov/pub/data/' .
+ "observations/metar/stations/$icao.TXT");
+ }
/* Here we test to see if we actually got a METAR. */
if (is_array($file)) {
/* The first line in the file is the date */
Index: defaults-dist.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/defaults-dist.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- defaults-dist.php 2001/06/27 11:25:07 1.6
+++ defaults-dist.php 2001/06/29 09:42:36 1.7
@@ -4,34 +4,39 @@
/* This file holds the original defaults used by PHP Weather. If you
* want to change something, you should follow these procedures:
*
+ * Use the script configurator.php. If you don't want to use that for
+ * some reason, then it's also simple to edit this file manually:
+ *
* 1) save this file as 'defaults.php'
* 2) remove everything you don't need
* 3) change the options you want
*
* That's it! You can keep your new file (defaults.php) when upgrading
- * PHP Weather, as it will only contain new version of this file.
- */
+ * PHP Weather, as it will only contain new version of this file. */
$this->properties['always_use_db'] = false; /* data_retrieval.php */
-$this->properties['icao'] = 'EKYT'; /* data_retrieval.php */
+$this->properties['icao'] = 'EKYT';
+$this->properties['use_proxy'] = false;
+$this->properties['proxy_host'] = '';
+$this->properties['proxy_port'] = 3128;
$this->properties['db_hostname'] = ''; /* db_common.php */
-$this->properties['db_database'] = ''; /* db_common.php */
-$this->properties['db_username'] = ''; /* db_common.php */
-$this->properties['db_password'] = ''; /* db_common.php */
-$this->properties['db_pconnect'] = false; /* db_common.php */
-$this->properties['db_port'] = ''; /* db_common.php */
+$this->properties['db_database'] = '';
+$this->properties['db_username'] = '';
+$this->properties['db_password'] = '';
+$this->properties['db_pconnect'] = false;
+$this->properties['db_port'] = '';
$this->properties['db_metars'] = 'metars'; /* db_dba.php */
-$this->properties['db_stations'] = 'stations'; /* db_dba.php */
-$this->properties['db_countries'] = 'countries'; /* db_dba.php */
+$this->properties['db_stations'] = 'stations';
+$this->properties['db_countries'] = 'countries';
$this->properties['db_type'] = 'null'; /* db_layer.php */
$this->properties['pref_units'] = 'both_metric'; /* locale_common.php */
-$this->properties['mark_begin'] = '<b>'; /* locale_common.php */
-$this->properties['mark_end'] = '</b>'; /* locale_common.php */
-$this->properties['exclude'] = array(); /* locale_common.php */
+$this->properties['mark_begin'] = '<b>';
+$this->properties['mark_end'] = '</b>';
+$this->properties['exclude'] = array();
$this->properties['language'] = 'en'; /* phpweather.php */
_______________________________________________
PHPWeather-checkins mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/phpweather-checkins