[Mapbender-users] Connection = CURL - Frage zu Einstellungen

Ingo Lünsmann luensmann at ipsyscon.de
Wed May 27 07:54:18 EDT 2009


Dies hört sich nach einem ähnlichen Problem, was ich vor ca. 1,5 Jahren
hatte. Damals habe ich die getHTTP()-Methode in class_connector.php
gepatcht, so dass ich in die mapbender.conf Proxy-Ausnahmen eintragen kann.
Vielleicht hilft es ja weiter. Hier die gepatchte class_connector.php (im
Verzeichnis mapbender/http/classes):

<?php


# $Id$
# http://www.mapbender.org/index.php/class_connector
# Copyright (C) 2002 CCGIS 
#
# 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, 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.

require_once ("../../conf/mapbender.conf");

class connector {
	var $file;
	function connector($url) {
		if (CONNECTION == 'curl') {
			$this->file = $this->getCURL($url);
		}
		if (CONNECTION == 'http') {
			$this->file = $this->getHTTP($url);
		}
		if (CONNECTION == 'socket') {
			$this->file = $this->getSOCKET($url);
		}
	}
	function getCURL($url) {
		$ch = curl_init($url);
		//		curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
		if (CONNECTION_PROXY != "") {
			curl_setopt($ch, CURLOPT_PROXY, CONNECTION_PROXY . ":" .
CONNECTION_PORT);
		}
		if (CONNECTION_PASSWORD != "") {
			curl_setopt($ch, CURLOPT_PROXYUSERPWD, CONNECTION_USER . ':' .
CONNECTION_PASSWORD);
		}
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$file = curl_exec($ch);
		curl_close($ch);
		return $file;
	}
	function getHTTP($url) {
		//echo "PROXY: ".CONNECTION_PROXY.":".CONNECTION_PORT.", NON_PROXY_HOSTS:
".NON_PROXY_HOSTS;
		
		//Wurde ein Proxy konfiguriert?
		if (CONNECTION_PROXY != "") {

			//Sollte die aufgerufenen URL sich im konfigurierten
NON_PROXY_HOSTS-Parameter befinden,
			//wird der Proxy nicht verwendet.
			if (NON_PROXY_HOSTS != "") {
				$nonProxyHosts = explode("|", NON_PROXY_HOSTS);

				foreach ($nonProxyHosts as $host) {
					if (strstr($url, $host)) {
						return file_get_contents($url);
					}
				}
			}

			//Also doch ueber den Proxy...
			$aContext = array (
				'http' => array (
					'proxy' => 'tcp://' . CONNECTION_PROXY . ':' . CONNECTION_PORT
				),

				
			);
			$cxContext = stream_context_create($aContext);

			return file_get_contents($url, False, $cxContext);

		} else {
			return file_get_contents($url);
		}

		//return file_get_contents($url);
		/*$aContext = array(
				'http' => array(
				'proxy' => 'tcp://195.90.13.22:3128'), // This needs to be the server
and the port of the NTLM Authentication Proxy Server.
			);
		$cxContext = stream_context_create($aContext);
		
		if(strstr($url, 'localhost'))
			return file_get_contents($url);
			else
			return file_get_contents($url, False, $cxContext);*/
	}
	function getSOCKET($url) {
		$r = "";
		$fp = fsockopen(CONNECTION_PROXY, CONNECTION_PORT, $errno, $errstr, 30);
		if (!$fp) {
			echo "$errstr ($errno)<br />\n";
		} else {
			fputs($fp, "GET " . $url . " HTTP/1.0\r\n\r\n");
			while (!feof($fp)) {
				$r .= fgets($fp, 4096);
			}
			fclose($fp);
			return $r;
		}
	}
}
?>


----
Und die beispielhaften Eintraege in der mapbender.conf:

define("CONNECTION_PROXY", "proxy_server_ip");
define("CONNECTION_PORT", "3128");
define("CONNECTION_USER", "");
define("CONNECTION_PASSWORD", "");
define("NON_PROXY_HOSTS","localhost|janeway");

Bitte achte auf Groß- und Kleinschreibung...
-- 
View this message in context: http://n2.nabble.com/Connection-%3D-CURL----Frage-zu-Einstellungen-tp2974212p2980582.html
Sent from the mapbender-users mailing list archive at Nabble.com.



More information about the Mapbender_users mailing list