[Mapbender-commits] r10106 - trunk/mapbender/http/php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Apr 17 06:16:13 PDT 2019
Author: armin11
Date: 2019-04-17 06:16:13 -0700 (Wed, 17 Apr 2019)
New Revision: 10106
Added:
trunk/mapbender/http/php/mod_sessionWrapper.php
Log:
New module to wrap allow access to mapbender session variables via http. This allows the simple integration in python (django) applications.
Added: trunk/mapbender/http/php/mod_sessionWrapper.php
===================================================================
--- trunk/mapbender/http/php/mod_sessionWrapper.php (rev 0)
+++ trunk/mapbender/http/php/mod_sessionWrapper.php 2019-04-17 13:16:13 UTC (rev 10106)
@@ -0,0 +1,128 @@
+<?php
+require_once(dirname(__FILE__) . "/../../core/globalSettings.php");
+require_once(dirname(__FILE__) . "/../classes/class_user.php");
+$hostName = $_SERVER['HTTP_HOST'];
+$operation = "get";
+$key = "mb_user_id";
+$value = null;
+$allowedOperations = array("get", "set");
+$allowedKeys = array("mb_user_id", "gml");
+
+$resultObj['result'] = '';
+$resultObj['success'] = false;
+$resultObj['message'] = 'no message';
+
+if (!($hostName !== 'localhost' or $hostName !== '127.0.0.1')) {
+ $resultObj['message'] ='hostName not allowed - only local connections possible (localhost,127.0.0.1)';
+ $resultObj['result'] = null;
+ echo json_encode($resultObj);
+ die();
+}
+
+if (isset($_REQUEST["sessionId"]) & $_REQUEST["sessionId"] != "") {
+ //echo "<br>Requested sessionId: ".$_REQUEST["sessionId"]."<br>";
+} else {
+ $resultObj['message'] ='No sessioId given - please give parameter!';
+ $resultObj['result'] = null;
+ echo json_encode($resultObj);
+ die();
+}
+$existSession = Mapbender::session()->storageExists($_REQUEST["sessionId"]);
+if ($existSession) {
+ $e = new mb_exception("storage exists");
+} else {
+ $e = new mb_exception("storage does not exist!");
+ $resultObj['message'] ='Requested session does not exists on server - please use existing identifier!';
+ $resultObj['result'] = null;
+ echo json_encode($resultObj);
+ die();
+}
+//parse operation
+if (isset($_REQUEST["operation"]) & $_REQUEST["operation"] != "") {
+ $testMatch = $_REQUEST["operation"];
+ if (!in_array($testMatch, $allowedOperations)){
+ $resultObj['message'] ='Parameter operation is not valid '.implode(',', $allowedOperations);
+ $resultObj['result'] = null;
+ echo json_encode($resultObj);
+ die();
+ }
+ $operation = $testMatch;
+ $testMatch = NULL;
+} else {
+ $resultObj['message'] ="Parameter operation not set - please set either ".implode(' or ', $allowedOperations);
+ $resultObj['result'] = null;
+ echo json_encode($resultObj);
+ die();
+}
+//parse operation
+if (isset($_REQUEST["key"]) & $_REQUEST["key"] != "") {
+ $testMatch = $_REQUEST["key"];
+ if (!in_array($testMatch, $allowedKeys)){
+ $resultObj['message'] = 'Parameter key is not valid '.implode(',', $allowedKeys);
+ $resultObj['result'] = null;
+ echo json_encode($resultObj);
+ die();
+ }
+ $key = $testMatch;
+ $testMatch = NULL;
+} else {
+ $resultObj['message'] = 'Parameter key not set - please set either '.implode(' or ', $allowedKeys);
+ $resultObj['result'] = null;
+ echo json_encode($resultObj);
+ die();
+}
+switch ($operation) {
+ case "get":
+ $resultObj['success'] = true;
+ $resultObj['message'] = 'Extracted session variable successfully!';
+ $resultObj['result']->key = $key;
+ $resultObj['result']->value = Mapbender::session()->get($key);
+ echo json_encode($resultObj);
+ die();
+ break;
+ case "set":
+ switch ($key) {
+ case "gml":
+ //validate gml!
+ //parse operation
+ if (isset($_REQUEST["value"]) & $_REQUEST["value"] != "") {
+ $testMatch = $_REQUEST["value"];
+ //example from old portal solution:
+ /*
+$GML = "<FeatureCollection xmlns:gml='http://www.opengis.net/gml'><boundedBy><Box srsName='EPSG:".$newEPSG."'>";
+$GML .= "<coordinates>".$newBbox[0].",".$newBbox[1]." ".$newBbox[2];
+$GML .= ",".$newBbox[3]."</coordinates></Box>";
+$GML .= "</boundedBy><featureMember><gemeinde><title>BBOX</title><the_geom><MultiPolygon srsName=\"EPSG:";
+$GML .= $newEPSG."\"><polygonMember><Polygon><outerBoundaryIs><LinearRing><coordinates>";
+$GML .= $newBbox[0].",".$newBbox[1]." ".$newBbox[2].",";
+$GML .= $newBbox[1]." ".$newBbox[2].",".$newBbox[3]." ";
+$GML .= $newBbox[0].",".$newBbox[3]." ".$newBbox[0].",".$newBbox[1];
+$GML .= "</coordinates></LinearRing></outerBoundaryIs></Polygon></polygonMember></MultiPolygon></the_geom></gemeinde></featureMember></FeatureCollection>";
+ */
+ /*if (!in_array($testMatch, $allowedKeys)){
+ $resultObj['message'] = 'Parameter key is not valid '.implode(',', $allowedKeys);
+ $resultObj['result'] = null;
+ echo json_encode($resultObj);
+ die();
+ }*/
+ $value = $testMatch;
+ $testMatch = NULL;
+ } else {
+ $resultObj['message'] = 'Parameter value for key '.$key.' not given!';
+ $resultObj['result'] = null;
+ echo json_encode($resultObj);
+ die();
+ }
+ Mapbender::session()->set('GML',$value);
+ break;
+ case "":
+ break;
+ default:
+ $resultObj['message'] = 'Not allowed to set key: '.$key.' via http!';
+ $resultObj['result'] = null;
+ echo json_encode($resultObj);
+ break;
+ }
+ break;
+}
+?>
More information about the Mapbender_commits
mailing list