[Mapbender-commits] r7656 - in trunk/mapbender: http/classes http/php http_auth/http owsproxy/http

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Sun Feb 27 07:32:08 EST 2011


Author: armin11
Date: 2011-02-27 04:32:08 -0800 (Sun, 27 Feb 2011)
New Revision: 7656

Modified:
   trunk/mapbender/http/classes/class_administration.php
   trunk/mapbender/http/classes/class_connector.php
   trunk/mapbender/http/php/wms.php
   trunk/mapbender/http_auth/http/index.php
   trunk/mapbender/owsproxy/http/index.php
Log:
Bugfixes from geoportal.rlp - concerning the http_auth, owsproxy and the connector class.

Modified: trunk/mapbender/http/classes/class_administration.php
===================================================================
--- trunk/mapbender/http/classes/class_administration.php	2011-02-26 15:57:18 UTC (rev 7655)
+++ trunk/mapbender/http/classes/class_administration.php	2011-02-27 12:32:08 UTC (rev 7656)
@@ -1216,6 +1216,13 @@
 	
 	// deprecated! use User->isLayerAccessible
 	function getLayerPermission($wms_id, $layer_name, $user_id){
+		//prohibit problems with layer names
+		$layer_name = urldecode($layer_name);
+		//
+		if (!is_int($layer_id)) {//TODO: do this also in User->isLayerAccessible
+			$e = new mb_exception("No id for the requested layer with name '".$layer_name."' found in database!");
+			return false;
+		}
 		$layer_id = $this->getLayerIdByLayerName($wms_id,$layer_name);
 		$array_guis = $this->getGuisByPermission($user_id,true);
 		$v = array();

Modified: trunk/mapbender/http/classes/class_connector.php
===================================================================
--- trunk/mapbender/http/classes/class_connector.php	2011-02-26 15:57:18 UTC (rev 7655)
+++ trunk/mapbender/http/classes/class_connector.php	2011-02-27 12:32:08 UTC (rev 7656)
@@ -201,6 +201,8 @@
 		curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); //for images
 		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+		//dont store and load cookies from previous sessions
+		curl_setopt($ch, CURLOPT_COOKIESESSION, true);
 		//allow https connections and handle certificates quite simply ;-)
 		curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
 		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

Modified: trunk/mapbender/http/php/wms.php
===================================================================
--- trunk/mapbender/http/php/wms.php	2011-02-26 15:57:18 UTC (rev 7655)
+++ trunk/mapbender/http/php/wms.php	2011-02-27 12:32:08 UTC (rev 7656)
@@ -19,23 +19,26 @@
 
 require_once(dirname(__FILE__)."/../../core/globalSettings.php");
 require_once(dirname(__FILE__)."/../classes/class_layer_monitor.php");
-
-ob_start();
-
+//ob_start(); //TODO why?
 //
 // make all parameters available as upper case
 //
 foreach($_GET as $key => $val) {
 	$_GET[strtoupper($key)] = $val;
 }
-
 $requestType = $_GET["REQUEST"];
 $version = $_GET["VERSION"];
 $service = strtoupper($_GET["SERVICE"]);
 $layerId = $_GET["LAYER_ID"];
 $updateSequence = intval($_GET["UPDATESEQUENCE"]);
-$mapbenderMetadataUrl = preg_replace("/(.*)frames\/login.php/", "$1php/mod_layerMetadata.php?id=", LOGIN);
-
+//$mapbenderMetadataUrl = preg_replace("/(.*)frames\/login.php/", "$1php/mod_showMetadata.php?resource=layer&id=", LOGIN);
+$mapbenderMetadaUrl = $_SERVER['HTTP_HOST']."/mapbender/php/mod_showMetadata.php?resource=layer&id=";
+if (isset($_SERVER["HTTPS"])){
+	$urlPrefix = "https://";
+} else {
+	$urlPrefix = "http://";
+}
+$mapbenderMetadataUrl = $urlPrefix.$mapbenderMetadataUrl;
 /**
  * Creates an XML Exception according to WMS 1.1.1
  * 
@@ -47,11 +50,9 @@
 	// see http://de2.php.net/manual/de/domimplementation.createdocumenttype.php
 	$imp = new DOMImplementation;
 	$dtd = $imp->createDocumentType("ServiceExceptionReport", "", "http://schemas.opengis.net/wms/1.1.1/exception_1_1_1.dtd");
-	
 	$doc = $imp->createDocument("", "", $dtd);
 	$doc->encoding = 'UTF-8';
 	$doc->standalone = false;
-	
 	$el = $doc->createElement("ServiceExceptionReport");
 	$exc = $doc->createElement("ServiceException", $errorMessage);
 	if ($errorCode) {
@@ -59,10 +60,8 @@
 	}
 	$el->appendChild($exc);
 	$doc->appendChild($el);
-	
 	return $doc->saveXML();
 }
-
 //
 // check if service param is set
 //
@@ -71,28 +70,23 @@
 	echo createExceptionXml("", "Parameter SERVICE invalid");
 	die;
 }
-
 //
 // check if request param is set
 //
 if (!isset($requestType) || $requestType === "" || 
-	($service == "WMS" && $requestType != "GetCapabilities")) {
-		
+	($service == "WMS" && $requestType != "GetCapabilities")) {	
 	header("Content-type: application/xhtml+xml; charset=UTF-8");
 	echo createExceptionXml("", "Parameter REQUEST invalid");
 	die;
 }
-
 //
 // check if version param is set
 //
 if (!isset($version) || $version === "" || 
-	($service == "WMS" && $version != "1.1.1")) {
-		
+	($service == "WMS" && $version != "1.1.1")) {	
 	// optional parameter, set to 1.1.1 if not set
 	$version = "1.1.1";
 }
-
 //
 // check if layer id is set
 //
@@ -105,7 +99,6 @@
 	);
 	die;
 }
-
 //
 // check if layer is stored in database
 //
@@ -115,7 +108,6 @@
 $t = array("i");
 $res_wms_sql = db_prep_query($wms_sql, $v, $t);
 $wms_row = db_fetch_array($res_wms_sql);
-
 if (!$wms_row["wms_id"]) {
 	// TO DO: create exception XML
 	header("Content-type: application/xhtml+xml; charset=UTF-8");
@@ -125,12 +117,10 @@
 	);
 	die;
 }
-
 //
 // check if update sequence is valid
 //
 $updateSequenceDb = intval($wms_row["wms_timestamp"]);
-
 if ($updateSequence) {
 	if ($updateSequence > $updateSequenceDb) {
 		// Exception: code=InvalidUpdateSequence
@@ -145,24 +135,20 @@
 		die;
 	}
 }
-
 //
 // increment layer count
 //
 $monitor = new Layer_load_count();
 $monitor->increment($layerId);
-
 // ---------------------------------------------------------------------------
 //
 // START TO CREATE CAPABILITIES DOC
 // (return most recent Capabilities XML)
 //
 // ---------------------------------------------------------------------------
-
 $doc = new DOMDocument('1.0');
 $doc->encoding = 'UTF-8';
 $doc->standalone = false;
-
 #Check for existing content in database
 #to be adopted TODO armin 
 function validate ($contactInformation_column) {
@@ -173,25 +159,20 @@
 		$contactinformationcheck = false;
 	}
 	return $contactinformationcheck;
-}
- 
-	
+}	
 #Creating the "WMT_MS_Capabilities" node
 $wmt_ms_capabilities = $doc->createElement("WMT_MS_Capabilities");
 $wmt_ms_capabilities->setAttribute("updateSequence", $wms_row["wms_timestamp"]);
 $wmt_ms_capabilities = $doc->appendChild($wmt_ms_capabilities);
 $wmt_ms_capabilities->setAttribute('version', '1.1.1');
-
 #Creatig the "Service" node 
 $service = $doc->createElement("Service");
 $service = $wmt_ms_capabilities->appendChild($service);
-
 #Creating the "Name" Node
 $name = $doc->createElement("Name");
 $name = $service->appendChild($name);
 $nameText = $doc->createTextNode("OGC:WMS");
 $nameText = $name->appendChild($nameText);
-
 #Creating the "Title" node
 if($wms_row['wms_title'] <> "" AND $wms_row['wms_title'] <> NULL) {
     $title = $doc->createElement("Title");
@@ -199,18 +180,16 @@
 	$titleText = $doc->createTextNode($wms_row['wms_title']);
 	$titleText = $title->appendChild($titleText);
 }
-
 #Creating the "Abstract" node
 if($wms_row['wms_abstract'] <> "" AND $wms_row['wms_abstract'] <> NULL) {
 	$abstract = $doc->createElement("Abstract");
 	$abstract = $service->appendChild($abstract);
 	$abstractText = $doc->createTextNode($wms_row['wms_abstract']);
 	$abstractText = $abstract->appendChild($abstractText);
-}
-	
+}	
 # switch URLs for OWSPROXY
 if($wms_row['wms_owsproxy'] <> "" AND $wms_row['wms_owsproxy'] <> NULL) {
-	$tmpOR = "http://".$_SERVER["HTTP_HOST"]."/owsproxy/".session_id()."/".$wms_row["wms_owsproxy"]."?";
+	$tmpOR = $urlPrefix.$_SERVER["HTTP_HOST"]."/owsproxy/".session_id()."/".$wms_row["wms_owsproxy"]."?";
 	$tmpOR = str_replace(SERVERIP, SERVERNAME, $tmpOR);
 	$wms_row['wms_getcapabilities'] = $tmpOR;
 	$wms_row['wms_getmap'] = $tmpOR;
@@ -233,9 +212,7 @@
 	$onlineResource->setAttribute("xlink:href", $onlRes);
 	$onlineResource->setAttribute("xlink:type", "simple");
 //}
-
 #Insert contact information
-
 #Creating "Contact Information" node
 if (validate($wms_row['contactperson']) &&
 	validate($wms_row['contactorganization']) &&
@@ -250,14 +227,12 @@
 {
 $contactInformation = $doc->createElement("ContactInformation");
 $contactInformation = $service->appendChild($contactInformation);
-
 #Creating "Contact Person Primary" node
 if(validate($wms_row['contactperson']) AND validate($wms_row['contactorganization']))
 {
 $contactPersonPrimary = $doc->createElement("ContactPersonPrimary");
 $contactPersonPrimary = $contactInformation->appendChild($contactPersonPrimary); 
 }
-
 #Creating the "ContactPerson" node
 if(validate($wms_row['contactperson']))
 {
@@ -266,7 +241,6 @@
     $contactPersonText = $doc->createTextNode($wms_row['contactperson']);
     $contactPersonText = $contactPerson->appendChild($contactPersonText);
 }
-
 #Creating the "ContactOrganization" node
 if(validate($wms_row['contactorganization']))
 {
@@ -275,8 +249,6 @@
     $contactOrganizationText = $doc->createTextNode($wms_row['contactorganization']);
     $contactOrganizationText = $contactOrganization->appendChild($contactOrganizationText);
 }
-
-
 #Creating the "ContactPosition" node
 if(validate($wms_row['contactposition']))
 {
@@ -285,29 +257,24 @@
     $contactPositionText = $doc->createTextNode($wms_row['contactposition']);
     $contactPositionText = $contactPosition->appendChild($contactPositionText);    
 }
-
 #Creating "ContactAddress" node
 if(validate($wms_row['address']) AND validate($wms_row['city']) AND validate($wms_row['stateorprovince']) AND               validate($wms_row['postcode']) /*AND validate($wms_row['country'])*/)
 {
 $contactAddress = $doc->createElement("ContactAddress");
 $contactAddress = $contactInformation->appendChild($contactAddress); 
 }
-
 #Creating the "AddressType" and "Address" textnode
 if(validate($wms_row['address']))
-{
-	
+{	
     $addressType = $doc->createElement("AddressType");
     $addressType = $contactAddress->appendChild($addressType);
     $addresstypeText = $doc->createTextNode("postal");
     $addresstypeText = $addressType->appendChild($addresstypeText);
-    
     $address = $doc->createElement("Address");
     $address = $contactAddress->appendChild($address);
     $addressText = $doc->createTextNode($wms_row['address']);
     $addressText = $address->appendChild($addressText);
 }
-
 #Creatig the "City" node  
 if(validate($wms_row['city']))
 {
@@ -325,7 +292,6 @@
     $stateOrProvinceText = $doc->createTextNode($wms_row['stateorprovince']);
     $stateOrProvinceText = $stateOrProvince->appendChild($stateOrProvinceText);
 }
-
 #Creatig the "PostCode" node    
 if(validate($wms_row['postcode']))
 {
@@ -334,8 +300,6 @@
     $postCodeText = $doc->createTextNode($wms_row['postcode']);
     $postCodeText = $postCode->appendChild($postCodeText);
 }
-
- 
 #Creatig the "Country" node   
 if(isset($wms_row['country']) AND validate($wms_row['country']))
 {
@@ -344,7 +308,6 @@
     $countryText = $doc->createTextNode($wms_row['country']);
     $countryText = $country->appendChild($countryText);
 }
-
 #Creatig the "ContactVoiceTelephone" node
 if(validate($wms_row['contactvoicetelephone']))
 {
@@ -353,7 +316,6 @@
     $contactVoiceTelephoneText = $doc->createTextNode($wms_row['contactvoicetelephone']);
     $contactVoiceTelephoneText = $contactVoiceTelephone->appendChild($contactVoiceTelephoneText);
 }
-
 #Creatig the "ContactFacsimileTelephone" node
 if(validate($wms_row['contactfacsimiletelephone']))
 {
@@ -362,7 +324,6 @@
     $contactFacsimileTelephoneText = $doc->createTextNode($wms_row['contactfacsimiletelephone']);
     $contactFacsimileTelephoneText = $contactFacsimileTelephone->appendChild($contactFacsimileTelephoneText);
 }
-
 #Creatig the "ContactElectronicMailAddress" node
 if(validate($wms_row['contactelectronicmailaddress']))
 {
@@ -372,7 +333,6 @@
     $contactElectronicMailAddressText = $contactElectronicMailAddress->appendChild($contactElectronicMailAddressText);
 }
 }
-
 #Creatig the "Fees" node
 if(validate($wms_row['fees']))
 {
@@ -380,8 +340,7 @@
     $fees = $service->appendChild($fees);
     $feesText = $doc->createTextNode($wms_row['fees']);
     $feesText = $fees->appendChild($feesText);
-}
-   
+}  
 #Creating the "AccessConstraints" node
 if(validate($wms_row['accessconstraints']))
 {
@@ -390,22 +349,17 @@
     $accessConstraintsText = $doc->createTextNode($wms_row['accessconstraints']);
     $accessConstraintsText = $accessConstraints->appendChild($accessConstraintsText);
 }
-
- 
 #Creatig the "Capability" node 
 $capability = $doc->createElement("Capability");
 $capability = $wmt_ms_capabilities->appendChild($capability);
-
 #Creatig the "Request" node 
 $request = $doc->createElement("Request");
 $request = $capability->appendChild($request);
-
 ############################################################
 #GetCapabilities
 #Creatig the "GetCapabilities" node 
 $getCapabilities = $doc->createElement("GetCapabilities");
 $getCapabilities = $request->appendChild($getCapabilities);
-
 #Creatig the "Format" node 
 $wms_format_sql ="SELECT data_format FROM wms_format WHERE fkey_wms_id = $1 AND data_type = 'capability'";
 $v = array($wms_row['wms_id']);
@@ -421,24 +375,17 @@
     $format = $doc->createElement("Format");
     $format = $getCapabilities->appendChild($format);
     $formatText = $doc->createTextNode('application/vnd.ogc.wms_xml');
-    $formatText = $format->appendChild($formatText); 
-
-
-
+    $formatText = $format->appendChild($formatText);
 #Creating the "DCPType" node
 $DCPType = $doc->createElement("DCPType");
 $DCPType = $getCapabilities->appendChild($DCPType);
-
 #Creating the "HTTP" node
 $HTTP = $doc->createElement("HTTP");
 $HTTP = $DCPType->appendChild($HTTP);
-
 #Creating the "Get" node
 $get = $doc->createElement("Get");
 $get = $HTTP->appendChild($get);
-
 #Creating the "OnlineResource" node
-
 //if ($wms_row['wms_getcapabilities'] <> "" AND $wms_row['wms_getcapabilities'] <> NULL) {
 	$onlineResource = $doc->createElement("OnlineResource");
 	$onlineResource = $get->appendChild($onlineResource);
@@ -454,11 +401,9 @@
 	$onlineResource->setAttribute("xlink:href", $onlRes);
 	$onlineResource->setAttribute("xlink:type", "simple");		
 //}
-
 #Creating the "Post" node
 $post = $doc->createElement("Post");
 $post = $HTTP->appendChild($post);
-
 #Creating the "OnlineResource" node
 //if ($wms_row['wms_getcapabilities'] <> "" AND $wms_row['wms_getcapabilities'] <> NULL) {
 	$onlineResource = $doc->createElement("OnlineResource");
@@ -475,7 +420,6 @@
 	$onlineResource->setAttribute("xlink:href", $onlRes);
 	$onlineResource->setAttribute("xlink:type", "simple");
 //}
-
 ##########################################################
 #GetMap	
 #Creatig the "GetMap" node 
@@ -1092,5 +1036,5 @@
 }	
 
 header("Content-type: application/xml; charset=UTF-8");
-echo $doc->saveXml();
+echo ltrim(" ",$doc->saveXml());
 ?>

Modified: trunk/mapbender/http_auth/http/index.php
===================================================================
--- trunk/mapbender/http_auth/http/index.php	2011-02-26 15:57:18 UTC (rev 7655)
+++ trunk/mapbender/http_auth/http/index.php	2011-02-27 12:32:08 UTC (rev 7656)
@@ -68,13 +68,13 @@
 }
 //if we are here - authentication has been done well!
 //let's do the proxy things (came from owsproxy.php):
-$postdata = $HTTP_RAW_POST_DATA;
-$layerId = $_REQUEST['layer_id'];
+$postdata = $HTTP_RAW_POST_DATA;
+$layerId = $_REQUEST['layer_id'];
 $query = new QueryHandler();
-
-// an array with keys and values toLoserCase -> caseinsensitiv
+
+// an array with keys and values toLoserCase -> caseinsensitiv
 $reqParams = $query->getRequestParams();
-
+
 $n = new administration();
 
 $wmsId = getWmsIdByLayerId($layerId);
@@ -94,44 +94,50 @@
 
 //what the proxy does
 switch (strtolower($reqParams['request'])) {
-
-	case 'getcapabilities':
-		$arrayOnlineresources = checkWmsPermission($wmsId,$userInformation[0]);
-		$query->setOnlineResource($arrayOnlineresources['wms_getcapabilities']);
-		$request = preg_replace("/(.*)frames\/login.php/", "$1php/wms.php?layer_id=".$layerId, LOGIN);
+
+	case 'getcapabilities':
+		$arrayOnlineresources = checkWmsPermission($wmsId,$userInformation[0]);
+		$query->setOnlineResource($arrayOnlineresources['wms_getcapabilities']);
+		//$request = preg_replace("/(.*)frames\/login.php/", "$1php/wms.php?layer_id=".$layerId, LOGIN);
+		if (isset($_SERVER["HTTPS"])){
+			$urlPrefix = "https://";
+		} else {
+			$urlPrefix = "http://";
+		}
+		$request = $urlPrefix.$_SERVER['HTTP_HOST']."/mapbender/php/wms.php?layer_id=".$layer_id;
 		$requestFull .= $request.'&REQUEST=GetCapabilities&VERSION=1.1.1&SERVICE=WMS';
-		if(isset($auth)){
+		if(isset($auth)){
 			getCapabilities($request,$requestFull,$auth);
 		}
 		else {
 			getCapabilities($request,$requestFull);
-		}
-		break;
-	case 'getfeatureinfo':
-		$arrayOnlineresources = checkWmsPermission($wmsId,$userInformation[0]);
+		}
+		break;
+	case 'getfeatureinfo':
+		$arrayOnlineresources = checkWmsPermission($wmsId,$userInformation[0]);
 		$query->setOnlineResource($arrayOnlineresources['wms_getfeatureinfo']);
 		$layers = checkLayerPermission($wmsId,$reqParams['layers'],$userInformation[0]);
 		if ($layers == '' ) {
 		throwE("GetFeatureInfo permission denied on layer with id".$layerId);
 		die();
-		}
+		}
 		$request = $query->getRequest();
-		if(isset($auth)){
+		if(isset($auth)){
 			getFeatureInfo($request,$auth);
 		}
 		else {
 			getFeatureInfo($request);
-		}
-		break;
-	case 'getmap':
-		$arrayOnlineresources = checkWmsPermission($wmsId,$userInformation[0]);
-		$query->setOnlineResource($arrayOnlineresources['wms_getmap']);
+		}
+		break;
+	case 'getmap':
+		$arrayOnlineresources = checkWmsPermission($wmsId,$userInformation[0]);
+		$query->setOnlineResource($arrayOnlineresources['wms_getmap']);
 		$layers = checkLayerPermission($wmsId,$reqParams['layers'],$userInformation[0]);
 		if ($layers == '' ) {
 			throwE("GetMap permission denied on layer with id ".$layerId);
 		die();
-		}
-		$query->setParam("layers",$layers);
+		}
+		$query->setParam("layers",urldecode($layers));
 		$request = $query->getRequest();
 		#log proxy requests
 		if($n->getWmsLogTag($wmsId)==1) {
@@ -141,7 +147,7 @@
 			$price=intval($n->getWmsPrice($wmsId));
 			$n->logWmsProxyRequest($wmsId,$userInformation[0],$request,$price);
 		}
-		if(isset($auth)){
+		if(isset($auth)){
 			getImage($request,$auth);
 		}
 		else {
@@ -151,15 +157,15 @@
 	case 'getlegendgraphic':
 		$url = getLegendUrl($wmsId);
 		$e = new mb_exception("URL for getlegendgraphic: ");
-		if(isset($auth)){	
+		if(isset($auth)){	
 			getImage($url,$auth);
 		}
 		else {
 			getImage($url);
 		}
 		break;
-	default:
-echo 'Your are logged in as: <b>' .$requestHeaderArray['username'].'</b> and requested the layer with id=<b>'.$layerId.'</b> but your request is not a valid OWS request';
+	default:
+echo 'Your are logged in as: <b>' .$requestHeaderArray['username'].'</b> and requested the layer with id=<b>'.$layerId.'</b> but your request is not a valid OWS request';
 }
 //functions for http_auth 
 //**********************************************************************************************
@@ -204,186 +210,186 @@
 //**********************************************************************************************
 //functions of owsproxy/http/index.php
 //**********************************************************************************************
-function throwE($e){
+function throwE($e){
 	global $reqParams, $imageformats;
-	
-	if(in_array($reqParams['format'],$imageformats)){
-		throwImage($e);
-	}
-	else{
-		throwText($e);	
-	}
+	
+	if(in_array($reqParams['format'],$imageformats)){
+		throwImage($e);
+	}
+	else{
+		throwText($e);	
+	}
 }
-
+
 function throwImage($e){
 	global $reqParams;
 	if (!$reqParams['width'] || !$reqParams['height']) { //width or height are not set by ows request - maybe for legendgraphics
 		$width = 300;
 		$height = 20;
-	}
-	$image = imagecreate($width,$height);
-	$transparent = ImageColorAllocate($image,155,155,155); 
-	ImageFilledRectangle($image,0,0,$width,$height,$transparent);
-	imagecolortransparent($image, $transparent);
-	$text_color = ImageColorAllocate ($image, 233, 14, 91);
-	for($i=0; $i<count($e); $i++){
-		ImageString ($image, 3, 5, $i*20, $e[$i], $text_color);
-	}
-	responseImage($image);
-}
-function throwText($e){
-	echo join(" ", $e);
-}
-function responseImage($im){
-	global $reqParams;
-	$format = $reqParams['format'];
-	if($format == 'image/png'){header("Content-Type: image/png");}
-	if($format == 'image/jpeg' || $format == 'image/jpg'){header("Content-Type: image/jpeg");}
-	if($format == 'image/gif'){header("Content-Type: image/gif");}	 
-	if($format == 'image/png'){imagepng($im);}
-	if($format == 'image/jpeg' || $format == 'image/jpg'){imagejpeg($im);}
-	if($format == 'image/gif'){imagegif($im);}	
-}
-function completeURL($url){
-	global $reqParams;
-	$mykeys = array_keys($reqParams);
-	for($i=0; $i<count($mykeys);$i++){
-		if($i > 0){ $url .= "&"; }
-		$url .= $mykeys[$i]."=".urlencode($reqParams[$mykeys[$i]]);
-	}
-	return $url;
-}
+	}
+	$image = imagecreate($width,$height);
+	$transparent = ImageColorAllocate($image,155,155,155); 
+	ImageFilledRectangle($image,0,0,$width,$height,$transparent);
+	imagecolortransparent($image, $transparent);
+	$text_color = ImageColorAllocate ($image, 233, 14, 91);
+	for($i=0; $i<count($e); $i++){
+		ImageString ($image, 3, 5, $i*20, $e[$i], $text_color);
+	}
+	responseImage($image);
+}
+function throwText($e){
+	echo join(" ", $e);
+}
+function responseImage($im){
+	global $reqParams;
+	$format = $reqParams['format'];
+	if($format == 'image/png'){header("Content-Type: image/png");}
+	if($format == 'image/jpeg' || $format == 'image/jpg'){header("Content-Type: image/jpeg");}
+	if($format == 'image/gif'){header("Content-Type: image/gif");}	 
+	if($format == 'image/png'){imagepng($im);}
+	if($format == 'image/jpeg' || $format == 'image/jpg'){imagejpeg($im);}
+	if($format == 'image/gif'){imagegif($im);}	
+}
+function completeURL($url){
+	global $reqParams;
+	$mykeys = array_keys($reqParams);
+	for($i=0; $i<count($mykeys);$i++){
+		if($i > 0){ $url .= "&"; }
+		$url .= $mykeys[$i]."=".urlencode($reqParams[$mykeys[$i]]);
+	}
+	return $url;
+}
 
 /**
  * fetch and returns an image to client
  * 
  * @param string the original url of the image to send
  */
-
-function getImage($or){
-	global $reqParams;
+
+function getImage($or){
+	global $reqParams;
 	header("Content-Type: ".$reqParams['format']);
 	if (func_num_args() == 2) { //new for HTTP Authentication
 		$auth = func_get_arg(1);
 		echo getDocumentContent($or,$auth);
 	}
 	else
-	{
+	{
 		echo getDocumentContent($or);
-	}
-}
-
-/**
- * fetchs and returns the content of the FeatureInfo Response
- * 
- * @param string the url of the FeatureInfoRequest
- * @return string the content of the FeatureInfo document
- */
-function getFeatureInfo($url){
-	global $info_format;
-	$e = new mb_exception("owsproxy: Try to fetch FeatureInfoRequest: ".$url);
+	}
+}
+
+/**
+ * fetchs and returns the content of the FeatureInfo Response
+ * 
+ * @param string the url of the FeatureInfoRequest
+ * @return string the content of the FeatureInfo document
+ */
+function getFeatureInfo($url){
+	global $info_format;
+	$e = new mb_exception("owsproxy: Try to fetch FeatureInfoRequest: ".$url);
 	header("Content-Type: ".$info_format);
 	if (func_num_args() == 2) { //new for HTTP Authentication
 		$auth = func_get_arg(1);
 		echo getDocumentContent($url,$auth);
 	}
 	else
-	{
+	{
 		echo getDocumentContent($url);
-	}
+	}
 }
 
 
 
-
-function matchUrls($content){
-	if(!session_is_registered("owsproxyUrls")){
-		$_SESSION["owsproxyUrls"] = array();
-		$_SESSION["owsproxyUrls"]["id"] = array();
-		$_SESSION["owsproxyUrls"]["url"] = array();
-	}
-	$pattern = "/[\"|\'](https*:\/\/[^\"|^\']*)[\"|\']/";
-	preg_match_all($pattern,$content,$matches);
-	for($i=0; $i<count($matches[1]); $i++){
-		$req = $matches[1][$i];
+
+function matchUrls($content){
+	if(!session_is_registered("owsproxyUrls")){
+		$_SESSION["owsproxyUrls"] = array();
+		$_SESSION["owsproxyUrls"]["id"] = array();
+		$_SESSION["owsproxyUrls"]["url"] = array();
+	}
+	$pattern = "/[\"|\'](https*:\/\/[^\"|^\']*)[\"|\']/";
+	preg_match_all($pattern,$content,$matches);
+	for($i=0; $i<count($matches[1]); $i++){
+		$req = $matches[1][$i];
 		$e = new mb_exception("Gefundene URL ".$i.": ".$req);
 		#$notice = new mb_notice("owsproxy id:".$req);
-		$id = registerURL($req);
-		$extReq = setExternalRequest($id);
+		$id = registerURL($req);
+		$extReq = setExternalRequest($id);
 		$e = new mb_exception("MD5 URL ".$id."-Externer Link: ".$extReq);
-		$content = str_replace($req,$extReq,$content);
-	}
-	return $content;
+		$content = str_replace($req,$extReq,$content);
+	}
+	return $content;
 }
-
-function setExternalRequest($id){
-	global $reqParams,$query;
-	$extReq = "http://".$_SESSION['HTTP_HOST'] ."/owsproxy/". $reqParams['sid'] ."/".$id."?request=external";
-	return $extReq;
-}
-function getExternalRequest($id){
-	for($i=0; $i<count($_SESSION["owsproxyUrls"]["url"]); $i++){
-		if($id == $_SESSION["owsproxyUrls"]["id"][$i]){
-			$cUrl = $_SESSION["owsproxyUrls"]["url"][$i];
-			$query_string = removeOWSGetParams($_SERVER["QUERY_STRING"]);
-			if($query_string != ''){
-				$cUrl .= getConjunctionCharacter($cUrl).$query_string;
-			}	
-			$metainfo = get_headers($cUrl,1);
-			// just for the stupid InternetExplorer
-			header('Pragma: private');
-			header('Cache-control: private, must-revalidate');
-			
-			header("Content-Type: ".$metainfo['Content-Type']);
-			
-			$content = getDocumentContent($cUrl,false);
-			#$content = matchUrls($content); //In the case of http_auth - this is not possible cause we cannot save them in the header - maybe we could create a special session to do so later on? 			
-			echo $content; 
-		}	
-	} 
-}
-function removeOWSGetParams($query_string){
-	$r = preg_replace("/.*request=external&/","",$query_string);
-	#return $r;
+
+function setExternalRequest($id){
+	global $reqParams,$query;
+	$extReq = "http://".$_SESSION['HTTP_HOST'] ."/owsproxy/". $reqParams['sid'] ."/".$id."?request=external";
+	return $extReq;
+}
+function getExternalRequest($id){
+	for($i=0; $i<count($_SESSION["owsproxyUrls"]["url"]); $i++){
+		if($id == $_SESSION["owsproxyUrls"]["id"][$i]){
+			$cUrl = $_SESSION["owsproxyUrls"]["url"][$i];
+			$query_string = removeOWSGetParams($_SERVER["QUERY_STRING"]);
+			if($query_string != ''){
+				$cUrl .= getConjunctionCharacter($cUrl).$query_string;
+			}	
+			$metainfo = get_headers($cUrl,1);
+			// just for the stupid InternetExplorer
+			header('Pragma: private');
+			header('Cache-control: private, must-revalidate');
+			
+			header("Content-Type: ".$metainfo['Content-Type']);
+			
+			$content = getDocumentContent($cUrl,false);
+			#$content = matchUrls($content); //In the case of http_auth - this is not possible cause we cannot save them in the header - maybe we could create a special session to do so later on? 			
+			echo $content; 
+		}	
+	} 
+}
+function removeOWSGetParams($query_string){
+	$r = preg_replace("/.*request=external&/","",$query_string);
+	#return $r;
 	return "";
-}
-function getConjunctionCharacter($url){
-	if(strpos($url,"?")){ 
-		if(strpos($url,"?") == strlen($url)){ 
-			$cchar = "";
-		}else if(strpos($url,"&") == strlen($url)){
-			$cchar = "";
-		}else{
-			$cchar = "&";
-		}
-	}
-	if(strpos($url,"?") === false){
-		$cchar = "?";
-	} 
-	return $cchar;  
-}
-function registerUrl($url){	
-	if(!in_array($url,$_SESSION["owsproxyUrls"]["url"])){
+}
+function getConjunctionCharacter($url){
+	if(strpos($url,"?")){ 
+		if(strpos($url,"?") == strlen($url)){ 
+			$cchar = "";
+		}else if(strpos($url,"&") == strlen($url)){
+			$cchar = "";
+		}else{
+			$cchar = "&";
+		}
+	}
+	if(strpos($url,"?") === false){
+		$cchar = "?";
+	} 
+	return $cchar;  
+}
+function registerUrl($url){	
+	if(!in_array($url,$_SESSION["owsproxyUrls"]["url"])){
 		$e = new mb_exception("Is noch net drin!");
-		$id = md5($url);
+		$id = md5($url);
 		$e = new mb_exception("ID: ".$id."  URL: ".$url." will be written to session");	
-		array_push($_SESSION["owsproxyUrls"]["url"],$url);
-		array_push($_SESSION["owsproxyUrls"]["id"], $id);
-	}
-	else{
+		array_push($_SESSION["owsproxyUrls"]["url"],$url);
+		array_push($_SESSION["owsproxyUrls"]["id"], $id);
+	}
+	else{
 		$e = new mb_exception("It was found! Search content and return ID!");
-		for($i=0; $i<count($_SESSION["owsproxyUrls"]["url"]); $i++){
+		for($i=0; $i<count($_SESSION["owsproxyUrls"]["url"]); $i++){
 		$e = new mb_exception("Content ".$i." : proxyurl:".$_SESSION["owsproxyUrls"]["url"][$i]." - new: ".$url);
-		if($url == $_SESSION["owsproxyUrls"]["url"][$i]){
+		if($url == $_SESSION["owsproxyUrls"]["url"][$i]){
 			$e = new mb_exception("Identical! ID:".$_SESSION["owsproxyUrls"]["id"][$i]." will be used");
-			$id = $_SESSION["owsproxyUrls"]["id"][$i];
-			}			
-		}
-	}
-	return $id;
+			$id = $_SESSION["owsproxyUrls"]["id"][$i];
+			}			
+		}
+	}
+	return $id;
 }
-
-function getCapabilities($request,$requestFull){
+
+function getCapabilities($request,$requestFull){
 	global $arrayOnlineresources;
 	global $layerId;
 	header("Content-Type: application/xml");
@@ -405,8 +411,8 @@
 	$new = "href=\"".HTTP_AUTH_PROXY ."/". $layerId."?$1\"";
 	$pattern = "#href=\"".str_replace('?','\?',str_replace('/','\/',$request))."\"#";
 	$content = preg_replace($pattern,$new,$content);
-
-	echo $content;
+
+	echo $content;
 }
 
 /**
@@ -445,58 +451,58 @@
  * 
  * @param wmsId integer, userId - integer
  * @return array array with detailed information about requested wms
- */
-function checkWmsPermission($wmsId,$userId){
+ */
+function checkWmsPermission($wmsId,$userId){
 	global $con, $n;
-	$myguis = $n->getGuisByPermission($userId,true);
-	$mywms = $n->getWmsByOwnGuis($myguis);
-
-	$sql = "SELECT * FROM wms WHERE wms_id = $1";
-	$v = array($wmsId);
-	$t = array("s");
-	$res = db_prep_query($sql, $v, $t);
-	$service = array();
-	if($row = db_fetch_array($res)){
-		$service["wms_id"] = $row["wms_id"];
-		$service["wms_getcapabilities"] = $row["wms_getcapabilities"];	
-		$service["wms_getmap"] = $row["wms_getmap"];
-		$service["wms_getfeatureinfo"] = $row["wms_getfeatureinfo"];
-		$service["wms_getcapabilities_doc"] = $row["wms_getcapabilities_doc"];
-	}
-	if(!$row || count($mywms) == 0){
-		throwE(array("No wms data available."));
-		die();	
-	}
-	
-	if(!in_array($service["wms_id"], $mywms)){
-		throwE(array("Permission denied."," -> ".$service["wms_id"], implode(",", $mywms)));
-		die();
-	}
-	return $service;
+	$myguis = $n->getGuisByPermission($userId,true);
+	$mywms = $n->getWmsByOwnGuis($myguis);
+
+	$sql = "SELECT * FROM wms WHERE wms_id = $1";
+	$v = array($wmsId);
+	$t = array("s");
+	$res = db_prep_query($sql, $v, $t);
+	$service = array();
+	if($row = db_fetch_array($res)){
+		$service["wms_id"] = $row["wms_id"];
+		$service["wms_getcapabilities"] = $row["wms_getcapabilities"];	
+		$service["wms_getmap"] = $row["wms_getmap"];
+		$service["wms_getfeatureinfo"] = $row["wms_getfeatureinfo"];
+		$service["wms_getcapabilities_doc"] = $row["wms_getcapabilities_doc"];
+	}
+	if(!$row || count($mywms) == 0){
+		throwE(array("No wms data available."));
+		die();	
+	}
+	
+	if(!in_array($service["wms_id"], $mywms)){
+		throwE(array("Permission denied."," -> ".$service["wms_id"], implode(",", $mywms)));
+		die();
+	}
+	return $service;
 }
-
-function checkLayerPermission($wms_id,$l,$userId){
-	global $n, $owsproxyService;
-	$e = new mb_exception("owsproxy: checkLayerpermission: wms: ".$wms_id.", layer: ".$l.' user_id: '.$userId);
-	$myl = split(",",$l);
-	$r = array();
-	foreach($myl as $mysl){
-		if($n->getLayerPermission($wms_id, $mysl, $userId) === true){
-			array_push($r, $mysl);
-		}		
-	}
-	$ret = implode(",",$r);
-	return $ret;
-}
+
+function checkLayerPermission($wms_id,$l,$userId){
+	global $n, $owsproxyService;
+	$e = new mb_exception("owsproxy: checkLayerpermission: wms: ".$wms_id.", layer: ".$l.' user_id: '.$userId);
+	$myl = split(",",$l);
+	$r = array();
+	foreach($myl as $mysl){
+		if($n->getLayerPermission($wms_id, $mysl, $userId) === true){
+			array_push($r, $mysl);
+		}		
+	}
+	$ret = implode(",",$r);
+	return $ret;
+}
 function getDocumentContent($url){
 	if (func_num_args() == 2) { //new for HTTP Authentication
             	$auth = func_get_arg(1);
 		$d = new connector($url, $auth);
 	}
-	else {
+	else {
 		$d = new connector($url);
-	}
-	return $d->file;
+	}
+	return $d->file;
 }
 //**********************************************************************************************
 //extra functions TODO: push them in class_administration.php 

Modified: trunk/mapbender/owsproxy/http/index.php
===================================================================
--- trunk/mapbender/owsproxy/http/index.php	2011-02-26 15:57:18 UTC (rev 7655)
+++ trunk/mapbender/owsproxy/http/index.php	2011-02-27 12:32:08 UTC (rev 7656)
@@ -100,7 +100,7 @@
 			throwE("Permission denied");
 			die();
 		}
-		$query->setParam("layers",$layers);
+		$query->setParam("layers",urldecode($layers));//the decoding of layernames dont make problems - but not really good names will be requested also ;-)
 		$request = $query->getRequest();
 		#log proxy requests
 		if($n->getWmsLogTag($arrayOnlineresources['wms_id'])==1) {
@@ -126,7 +126,7 @@
 			throwE("Permission denied");
 			die();
 		}
-		$query->setParam("layers",$layers);
+		$query->setParam("layers",urldecode($layers));
 		$request = $query->getRequest();
 		if(isset($auth)){
 			getImage($url,$auth);



More information about the Mapbender_commits mailing list