[Mapbender-commits] r1663 - trunk/mapbender/owsproxy/http

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Aug 21 04:39:48 EDT 2007


Author: uli
Date: 2007-08-21 04:39:47 -0400 (Tue, 21 Aug 2007)
New Revision: 1663

Modified:
   trunk/mapbender/owsproxy/http/index.php
Log:
external request included
the multibyte string-functions are lost....

Modified: trunk/mapbender/owsproxy/http/index.php
===================================================================
--- trunk/mapbender/owsproxy/http/index.php	2007-08-21 06:46:45 UTC (rev 1662)
+++ trunk/mapbender/owsproxy/http/index.php	2007-08-21 08:39:47 UTC (rev 1663)
@@ -22,19 +22,23 @@
 require("../../http/classes/class_administration.php");
 require("../../http/classes/class_connector.php");
 require_once("../../http/classes/class_mb_exception.php");
+
 /***** conf *****/
 $imageformats = array("image/png","image/gif","image/jpeg", "image/jpg");
-$mbkeys = array("sid",mb_strtolower(ini_get("session.name")),"wms");
+$mbkeys = array("sid",strtolower(ini_get("session.name")),"wms");
 /***** conf *****/
 
+$con = db_connect(DBSERVER,OWNER,PW);
+db_select_db(DB,$con);
+
 $reqParams = array();
 $myKeys = array_keys($_REQUEST);
 // create an associative array with request parameters (get)
 for($i=0; $i<count($myKeys); $i++){
-	$tmp[$i] = removeQM(mb_strtolower($myKeys[$i]));
+	$tmp[$i] = removeQM(strtolower($myKeys[$i]));
 	$$tmp[$i]  = $_REQUEST[$myKeys[$i]];
-	if(!in_array(removeQM(mb_strtolower($myKeys[$i])),$mbkeys)){
-		$reqParams[removeQM(mb_strtolower($myKeys[$i]))] = $_REQUEST[$myKeys[$i]];
+	if(!in_array(removeQM(strtolower($myKeys[$i])),$mbkeys)){
+		$reqParams[removeQM(strtolower($myKeys[$i]))] = $_REQUEST[$myKeys[$i]];
 	}
 }
 
@@ -47,57 +51,36 @@
 //	die();	
 //}
 
-// permission 
-$con = db_connect(DBSERVER,OWNER,PW);
-db_select_db(DB,$con);
-
+/*************  workflow ************/
 $n = new administration();
-$myguis = $n->getGuisByPermission($_SESSION["mb_user_id"],true);
-$mywms = $n->getWmsByOwnGuis($myguis);
-
-$sql = "SELECT * FROM wms WHERE wms_owsproxy = $1";
-$v = array($wms);
-$t = array("s");
-$res = db_prep_query($sql, $v, $t);
-if($row = db_fetch_array($res)){
-	$wms_id = $row["wms_id"];
-	$wms_getcapabilities = $row["wms_getcapabilities"];	
-	$wms_getmap = $row["wms_getmap"];
-	$wms_getfeatureinfo = $row["wms_getfeatureinfo"];
-	$wms_getcapabilities_doc = $row["wms_getcapabilities_doc"];
-}
-else{
-	throwE(array("No wms data available."));
-	die();	
-}
-
-if(!in_array($wms_id, $mywms)){
-	throwE(array("Permission denied."," -> ".$wms_id, implode(",", $mywms)));
-	die();
-}
-
-/*************  prepare and send the response ************/
-
-switch (mb_strtolower($request)) {
+switch (strtolower($request)) {
 	case 'getcapabilities':
-		$or = $n->checkURL($row["wms_getcapabilities"]);
+		$arrayOnlineresources = checkWmsPermission($wms);
+		$or = $n->checkURL($arrayOnlineresources["wms_getcapabilities"]);
 		$or = completeURL($or);
 		getCapabilities($or);
 		break;
 	case 'getfeatureinfo':
-		$or = $n->checkURL($row["wms_getfeatureinfo"]);
+		$arrayOnlineresources = checkWmsPermission($wms);
+		$or = $n->checkURL($arrayOnlineresources["wms_getfeatureinfo"]);
 		$or = completeURL($or);
 		getFeatureInfo($or);
 		break;
-	default:
-		$or = $n->checkURL($row["wms_getcapabilities"]);
-		$reqParams["layers"] = checkLayerPermission($layers);
+	case 'getmap':
+		$arrayOnlineresources = checkWmsPermission($wms);
+		$or = $n->checkURL($arrayOnlineresources["wms_getcapabilities"]);
+		$reqParams["layers"] = checkLayerPermission($arrayOnlineresources["wms_id"],$layers);
 		$or = completeURL($or);
 		getMap($or);
+	case 'external':
+		getExternalRequest($wms);	
+	default:
+		
 }
 /*********************************************************/
 function throwE($e){
 	global $format, $imageformats;
+	echo $format."---";
 	if(in_array($format,$imageformats)){
 		throwImage($e);
 	}
@@ -135,40 +118,156 @@
 	$mykeys = array_keys($reqParams);
 	for($i=0; $i<count($mykeys);$i++){
 		if($i > 0){ $url .= "&"; }
-		$url .= $mykeys[$i]."=".$reqParams[$mykeys[$i]];
+		$url .= $mykeys[$i]."=".urlencode($reqParams[$mykeys[$i]]);
 	}
 	return $url;
 }
 function removeQM($t){
-	if(mb_strpos($t,"?") === 0){
-		$t = mb_substr($t,1);	
+	if(strpos($t,"?") === 0){
+		$t = substr($t,1);	
 	}	
 	return $t;
 }
 function getMap($or){
-	global $format;
+	global $format, $width, $height;
 	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");}
 	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_notice("owsproxy: Try to fetch FeatureInfoRequest: ".$url);
 	header("Content-Type: ".$info_format);
-	echo getDocumentContent($url);
+	$content = getDocumentContent($url);
+	$content = matchUrls($content);
+	echo $content;
 }
+
+
+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];
+		$id = registerURL($req);
+		$extReq = setExternalRequest($id);
+		$content = str_replace($req,$extReq,$content);
+	}
+	return $content;
+}
+function setExternalRequest($id){
+	global $sid;
+	$extReq = OWSPROXY ."/". $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);
+			$content = matchUrls($content);			
+			echo $content; 
+		}	
+	} 
+}
+function removeOWSGetParams($query_string){
+	$r = preg_replace("/.*request=external&/","",$query_string);
+	return $r;
+}
+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"])){
+		$id = md5($url);
+		array_push($_SESSION["owsproxyUrls"]["url"],$url);
+		array_push($_SESSION["owsproxyUrls"]["id"], $id);
+	}
+	else{
+		for($i=0; $i<count($_SESSION["owsproxyUrls"]["url"]); $i++){
+			if($url == $_SESSION["owsproxyUrls"]["url"][$i]){
+				$id = $_SESSION["owsproxyUrls"]["id"][$i];
+			}			
+		}
+	}
+	return $id;
+}
 function getCapabilities($url){
-	global $wms_getcapabilities,$wms_getmap,$wms_getfeatureinfo,$wms_getcapabilities_doc;
+	global $arrayOnlineresources;
 	global $sid,$wms;
-	$t = array(htmlentities($wms_getcapabilities),htmlentities($wms_getmap),htmlentities($wms_getfeatureinfo));
+	$t = array(htmlentities($arrayOnlineresources["wms_getcapabilities"]),htmlentities($arrayOnlineresources["wms_getmap"]),htmlentities($arrayOnlineresources["$wms_getfeatureinfo"]));
 	$new = OWSPROXY ."/". $sid ."/".$wms."?";
-	$r = preg_replace($t,$new,$wms_getcapabilities_doc);
+	$r = str_replace($t,$new,$arrayOnlineresources["wms_getcapabilities_doc"]);
 	header("Content-Type: application/xml");
 	echo $r;
 }
-function checkLayerPermission($l){
-	global $n,$wms_id;
-	$myl = mb_split(",",$l);
+function checkWmsPermission($wms){
+	global $con, $n;
+	$myguis = $n->getGuisByPermission($_SESSION["mb_user_id"],true);
+	$mywms = $n->getWmsByOwnGuis($myguis);
+
+	$sql = "SELECT * FROM wms WHERE wms_owsproxy = $1";
+	$v = array($wms);
+	$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){
+	global $n;
+	$myl = split(",",$l);
 	$r = array();
 	foreach($myl as $mysl){
 		if($n->getLayerPermission($wms_id, $mysl, $_SESSION["mb_user_id"]) === true){
@@ -183,4 +282,5 @@
 	return $d->file;
 }
 
+
 ?>
\ No newline at end of file



More information about the Mapbender_commits mailing list