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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Jan 18 08:01:54 PST 2016


Author: armin11
Date: 2016-01-18 08:01:54 -0800 (Mon, 18 Jan 2016)
New Revision: 9372

Modified:
   trunk/mapbender/owsproxy/http/index.php
Log:
First draft for allowing owsproxy functions for wfs

Modified: trunk/mapbender/owsproxy/http/index.php
===================================================================
--- trunk/mapbender/owsproxy/http/index.php	2016-01-18 16:01:16 UTC (rev 9371)
+++ trunk/mapbender/owsproxy/http/index.php	2016-01-18 16:01:54 UTC (rev 9372)
@@ -45,6 +45,9 @@
 $reqParams = $query->getRequestParams();
 $e = new mb_notice("incoming request: " . OWSPROXY . "/" . $_REQUEST['sid'] . "/" . $_REQUEST['wms'] . $query->getRequest());
 $e = new mb_notice("owsproxy requested from: " . $_SERVER["REMOTE_ADDR"]);
+$e = new mb_exception("owsproxy requested: " . $query->getRequest());
+$sid = $_REQUEST['sid'];
+$serviceId =  $_REQUEST['wms'];
 
 if (defined("OWSPROXY_SESSION_GRABBING_WHITELIST")) {
     $whiteListArray = explode(",", OWSPROXY_SESSION_GRABBING_WHITELIST);
@@ -168,18 +171,7 @@
     }
 }
 $e = new mb_notice("user id for authorization test: " . getUserFromSession());
-$wmsId = $n->getWmsIdFromOwsproxyString($query->getOwsproxyServiceId());
-
-//get authentication infos if they are available in wms table! if not $auth = false
-if ($reqParams['request'] !== 'external') {
-	$auth = $n->getAuthInfoOfWMS($wmsId);
-}
-if ($auth['auth_type'] == '') {
-    unset($auth);
-}
-/* * ***********  workflow *********** */
-$n = new administration();
-
+//
 if (count($_REQUEST) > 0) {
     foreach ($_REQUEST as $key => $value) {
         if (strtoupper($key) === "SERVICE")
@@ -188,16 +180,60 @@
     if (!$found)
         $query->setParam("service", "WMS");
 }
+//check for kind of service
+switch (strtolower($reqParams['service'])) {
+	case 'wms':
+		$wmsId = $n->getWmsIdFromOwsproxyString($query->getOwsproxyServiceId());
+		//get authentication infos if they are available in wms table! if not $auth = false
+		if ($reqParams['request'] !== 'external') {
+			$auth = $n->getAuthInfoOfWMS($wmsId);
+		}
+		if ($auth['auth_type'] == '') {
+    			unset($auth);
+		}
+	break;
+		
+	case 'wfs':
+		$wfsId = $n->getWfsIdFromOwsproxyString($query->getOwsproxyServiceId());
+		//get authentication infos if they are available in wfs table! if not $auth = false
+		if ($reqParams['request'] !== 'external') {
+			$auth = $n->getAuthInfoOfWFS($wfsId);
+		}
+		if ($auth['auth_type'] == '') {
+    			unset($auth);
+		}
+	break;
+}
+
+
+/* * ***********  workflow *********** */
+
+
 switch (strtolower($reqParams['request'])) {
     case 'getcapabilities':
-        $arrayOnlineresources = checkWmsPermission($query->getOwsproxyServiceId());
-        $query->setOnlineResource($arrayOnlineresources['wms_getcapabilities']);
-        $request = $query->getRequest();
-        if (isset($auth)) {
-            getCapabilities($request, $auth);
-        } else {
-            getCapabilities($request);
-        }
+	switch (strtolower($reqParams['service'])) {
+		case 'wfs':
+			$arrayOnlineresources = checkWfsPermission($query->getOwsproxyServiceId(), false);
+        		$query->setOnlineResource($arrayOnlineresources['wfs_getcapabilities']);
+        		$request = $query->getRequest();  
+			if (isset($auth)) {
+            			getWfsCapabilities($request, $auth);
+        		} else {
+            			getWfsCapabilities($request);
+        		}		
+		break;
+		case 'wms':
+        		$arrayOnlineresources = checkWmsPermission($query->getOwsproxyServiceId());
+        		$query->setOnlineResource($arrayOnlineresources['wms_getcapabilities']);
+        		$request = $query->getRequest();
+        		if (isset($auth)) {
+            			getCapabilities($request, $auth);
+        		} else {
+            			getCapabilities($request);
+        		}
+		break;
+	
+	}
         break;
     case 'getfeatureinfo':
         $arrayOnlineresources = checkWmsPermission($query->getOwsproxyServiceId());
@@ -291,8 +327,24 @@
         $query->setOnlineResource($arrayOnlineresources['wfs_getfeature']);
         $request = $query->getRequest();
         $request = stripslashes($request);
-        getFeature($request);
+        if (isset($auth)) {
+            getFeature($request, $auth);
+        } else {
+            getFeature($request);
+        }
         break;
+    case 'describefeaturetype':
+        $arrayFeatures = array($reqParams['typename']);
+        $arrayOnlineresources = checkWfsPermission($query->getOwsproxyServiceId(), $arrayFeatures);
+        $query->setOnlineResource($arrayOnlineresources['wfs_describefeaturetype']);
+        $request = $query->getRequest();
+        $request = stripslashes($request);
+        if (isset($auth)) {
+            describeFeaturetype($request, $auth);
+        } else {
+            describeFeaturetype($request);
+        }
+        break;
     // case wfs transaction (because of raw POST the request param is empty)
     case '':
         $arrayFeatures = getWfsFeaturesFromTransaction($HTTP_RAW_POST_DATA);
@@ -302,6 +354,8 @@
         doTransaction($request, $HTTP_RAW_POST_DATA);
         break;
     default:
+	throwText(array("Request parameter not known to mapbender security proxy!"));
+	break;
 }
 //why delete session here - only if it was temporary?
 if (isset($tmpSession) && Mapbender::session()->storageExists($tmpSession)) {
@@ -438,16 +492,26 @@
  * @param string the url of the GetFeature request
  * @return echo the content of the GetFeature document
  */
-function getFeature($url)
+function getFeature($url, $auth = false)
 {
     global $reqParams;
+    $content = getDocumentContent(false, $url, "Content-Type: application/xml", $auth);
+}
 
-    header("Content-Type: " . $reqParams['info_format']);
-    $content = getDocumentContent(false, $url);
-    $content = matchUrls($content);
-    echo $content;
+/**
+ * fetchs and returns the content of WFS DescribeFeaturetype response
+ * 
+ * @param string the url of the DescribeFeaturetype request
+ * @return echo the content of the DescribeFeaturetype document
+ */
+function describeFeaturetype($url, $auth = false)
+{
+    global $reqParams;
+    $content = getDocumentContent(false, $url, "Content-Type: application/xml", $auth);
 }
 
+
+
 /**
  * simulates a post request to host
  * 
@@ -665,15 +729,37 @@
 function getCapabilities($url)
 {
     global $arrayOnlineresources;
-    global $sid, $wms;
+    global $sid, $serviceId;
     $t = array(htmlentities($arrayOnlineresources["wms_getcapabilities"]), htmlentities($arrayOnlineresources["wms_getmap"]),
         htmlentities($arrayOnlineresources["wms_getfeatureinfo"]));
-    $new = OWSPROXY . "/" . $sid . "/" . $wms . "?";
+    $new = OWSPROXY . "/" . $sid . "/" . $serviceId . "?";
     $r = str_replace($t, $new, $arrayOnlineresources["wms_getcapabilities_doc"]);
+    //delete trailing amp; 's
+    $r = str_replace('amp;', '', $r);
     header("Content-Type: application/xml");
     echo $r;
 }
 
+function getWfsCapabilities($request, $auth = false)
+{
+    global $arrayOnlineresources;
+    global $sid, $serviceId;
+    $t = array(htmlentities($arrayOnlineresources["wfs_getcapabilities"]), htmlentities($arrayOnlineresources["wfs_getmap"]),
+        htmlentities($arrayOnlineresources["wfs_getfeatureinfo"]));
+    $new = OWSPROXY . "/" . $sid . "/" . $serviceId . "?";
+	
+    //get actual capabilities from external server
+    if (!$auth) {
+	$wfsCaps = new connector($arrayOnlineresources["wfs_getcapabilities"].$request);
+    } else {
+	$wfsCaps = new connector($arrayOnlineresources["wfs_getcapabilities"].$request, $auth);
+    }
+    $r = str_replace($t, $new, $wfsCaps->file);
+    //delete trailing amp; 's
+    $r = str_replace('amp;', '', $r);
+    header("Content-Type: application/xml");
+    echo $r;
+}
 /**
  * gets the original url of the requested legend graphic
  * 
@@ -771,11 +857,12 @@
 {
     global $con, $n;
     $myconfs = $n->getWfsConfByPermission($_SESSION["mb_user_id"]);
-
-    //check if we know the features requested
-    if (count($features) == 0) {
-        throwE(array("No wfs_feature data available."));
-        die();
+    if ($features !== false) {
+	//check if we know the features requested
+	if (count($features) == 0) {
+	        throwE(array("No wfs_feature data available."));
+        	die();
+    	}	
     }
 
     //get wfs
@@ -808,7 +895,7 @@
         $t = array("i", "s");
         $res = db_prep_query($sql, $v, $t);
         if (!($row = db_fetch_array($res))) {
-            $notice = new mb_exception("Permissioncheck failed no wfs conf for wfs " . $service["wfs_id"] . " with feturetype " . $feature);
+            $notice = new mb_exception("Permissioncheck failed no wfs conf for wfs " . $service["wfs_id"] . " with featuretype " . $feature);
             throwE(array("No wfs_conf data for featuretype " . $feature));
             die();
         }
@@ -903,6 +990,39 @@
             echo $content;
         }
         return true;
+    } elseif (strtoupper($reqParams["request"]) == "GETFEATURE") {
+	$e = new mb_exception("getfeature invoked");
+	//parse featureCollection and get number of objects
+	libxml_use_internal_errors(true);
+	try {
+		$featureCollectionXml = simplexml_load_string($content);
+		if ($featureCollectionXml === false) {
+			foreach(libxml_get_errors() as $error) {
+        			$err = new mb_exception("owsproxy/index.php:".$error->message);
+    			}
+			throw new Exception("owsproxy/index.php:".'Cannot parse featureCollection XML!');
+			//TODO give error message
+		}
+	}
+	catch (Exception $e) {
+    		$err = new mb_exception("owsproxy/index.php:".$e->getMessage());
+		//TODO give error message
+	}
+	if ($featureCollectionXml !== false) {
+		$featureCollectionXml->registerXPathNamespace("gmd", "http://www.isotc211.org/2005/gmd");
+		$featureCollectionXml->registerXPathNamespace("gco", "http://www.isotc211.org/2005/gco");
+		$featureCollectionXml->registerXPathNamespace("gml", "http://www.opengis.net/gml");
+		$featureCollectionXml->registerXPathNamespace("xlink", "http://www.w3.org/1999/xlink");
+		$featureCollectionXml->registerXPathNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
+		$featureCollectionXml->registerXPathNamespace("default", "");
+		$numberOfFeatures = $featureCollectionXml->xpath('//wfs:FeatureCollection/@numberOfFeatures');
+		$numberOfFeatures = $numberOfFeatures[0];
+		$e = new mb_exception("owsproxy/index.php: ".$numberOfFeatures." delivered features from wfs ");
+		if (header !== false) { 
+			header($header);
+		}
+        	echo $content;
+	}
     } else {
 	if (header !== false) { 
 		header($header);



More information about the Mapbender_commits mailing list