[Mapbender-commits] r8761 - in trunk/mapbender: core lib owsproxy/http

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Jan 27 14:24:41 PST 2014


Author: armin11
Date: 2014-01-27 14:24:41 -0800 (Mon, 27 Jan 2014)
New Revision: 8761

Modified:
   trunk/mapbender/core/system.php
   trunk/mapbender/lib/class_Mapbender.php
   trunk/mapbender/lib/class_Mapbender_session.php
   trunk/mapbender/owsproxy/http/index.php
Log:
Allow memcached session management

Modified: trunk/mapbender/core/system.php
===================================================================
--- trunk/mapbender/core/system.php	2014-01-24 09:49:11 UTC (rev 8760)
+++ trunk/mapbender/core/system.php	2014-01-27 22:24:41 UTC (rev 8761)
@@ -25,9 +25,9 @@
 #
 # mapbender version
 #
-define("MB_VERSION_NUMBER", "2.7.4trunk");
+define("MB_VERSION_NUMBER", "2.7.8trunk");
 define("MB_VERSION_APPENDIX", "");
-define("MB_RELEASE_DATE", mktime(0,0,0,07,30,2013));//h, min,sec,month,day,year
+define("MB_RELEASE_DATE", mktime(0,0,0,01,31,2014));//h, min,sec,month,day,year
 
 #
 # constants from map.js

Modified: trunk/mapbender/lib/class_Mapbender.php
===================================================================
--- trunk/mapbender/lib/class_Mapbender.php	2014-01-24 09:49:11 UTC (rev 8760)
+++ trunk/mapbender/lib/class_Mapbender.php	2014-01-27 22:24:41 UTC (rev 8761)
@@ -18,8 +18,8 @@
  	}
  	
  	public static function singleton() {
-        return parent::singleton(__CLASS__);
-    }
+        	return parent::singleton(__CLASS__);
+    	}
 	
 	public static function postgisAvailable () {
 		$sql = "Select postgis_full_version()";

Modified: trunk/mapbender/lib/class_Mapbender_session.php
===================================================================
--- trunk/mapbender/lib/class_Mapbender_session.php	2014-01-24 09:49:11 UTC (rev 8760)
+++ trunk/mapbender/lib/class_Mapbender_session.php	2014-01-27 22:24:41 UTC (rev 8761)
@@ -117,11 +117,123 @@
 	}
 	
 	/*
+	 * test if session file or object on server exists
+	 */
+	public function storageExists($id) {
+		switch (ini_get('session.save_handler')) {
+			case "memcache":
+				$memcache_obj = new Memcache;
+				if (defined("MEMCACHED_IP") && MEMCACHED_IP != "" && defined("MEMCACHED_PORT") && MEMCACHED_PORT != "") {
+					$memcache_obj->connect(MEMCACHED_IP, MEMCACHED_PORT);
+				} else {
+					//use standard options
+					$memcache_obj->connect('localhost', 11211);
+				}
+				new mb_notice("sessions stored via memcache");
+				$session = $memcache_obj->get($id);
+				$memcache_obj->close();
+				if ($session !== false){
+					return true;
+				} else {
+					return false;
+				}
+			break;
+			case "memcached":
+				$memcached_obj = new Memcached;
+				if (defined("MEMCACHED_IP") && MEMCACHED_IP != "" && defined("MEMCACHED_PORT") && MEMCACHED_PORT != "") {
+					$memcached_obj->addServer(MEMCACHED_IP, MEMCACHED_PORT);
+				} else {
+					//use standard options
+					$memcached_obj->addServer('localhost', 11211);
+				}
+				new mb_notice("sessions stored via memcacheD");
+				$prefix = ini_get('memcached.sess_prefix');
+				if (empty($prefix) || $prefix =='') {
+					$prefix = "memc.sess.key.";
+				}
+				$session = $memcached_obj->get($prefix.$id);
+				//$memcached_obj->close();
+				if ($session !== false){
+					return true;
+				} else {
+					return false;
+				}
+			break;
+			case "files":
+				//check if file exists
+				if(file_exists(ini_get('session.save_path')."/sess_".$id)) {
+					return true;
+				} else {
+					return false;
+				}
+			break;
+		}
+	}	
+
+	/*
+	 * destroy session file or object on server
+	 */
+	public function storageDestroy($id) {
+		switch (ini_get('session.save_handler')) {
+			case "memcache":
+				$memcache_obj = new Memcache;
+				if (defined("MEMCACHED_IP") && MEMCACHED_IP != "" && defined("MEMCACHED_PORT") && MEMCACHED_PORT != "") {
+					$memcache_obj->connect(MEMCACHED_IP, MEMCACHED_PORT);
+				} else {
+					//use standard options
+					$memcache_obj->connect('localhost', 11211);
+				}
+				new mb_notice("sessions stored via memcache");
+				$session = $memcache_obj->get($id);
+				if ($session !== false){		
+					$memcache_obj->delete($id);
+					$memcache_obj->close();
+					return true;
+				} else {
+					$memcache_obj->close();
+					return false;
+				}
+			break;
+			case "memcached":
+				$memcached_obj = new Memcached;
+				if (defined("MEMCACHED_IP") && MEMCACHED_IP != "" && defined("MEMCACHED_PORT") && MEMCACHED_PORT != "") {
+					$memcached_obj->addServer(MEMCACHED_IP, MEMCACHED_PORT);
+				} else {
+					//use standard options
+					$memcached_obj->addServer('localhost', 11211);
+				}
+				new mb_notice("sessions stored via memcacheD");
+				$prefix = ini_get('memcached.sess_prefix');
+				if (empty($prefix) || $prefix =='') {
+					$prefix = "memc.sess.key.";
+				}
+				$session = $memcached_obj->get($prefix.$id);
+				if ($session !== false){
+					$memcached_obj->delete($prefix.$id);
+					//$memcached_obj->close();
+					return true;
+				} else {
+					//$memcached_obj->close();
+					return false;
+				}
+			break;
+			case "files":
+				//check if file exists
+				if(file_exists(ini_get('session.save_path')."/sess_".$id)) {
+					return @unlink(ini_get('session.save_path')."/sess_".$id);
+				} else {
+					return false;
+				}
+			break;
+		}
+	}
+	
+	/*
 	 * kills the current session
 	 */
 	 public function kill(){
 	 	if (isset($_COOKIE[session_name()])) {
-    	setcookie(session_name(), '', time()-42000, '/');
+    			setcookie(session_name(), '', time()-42000, '/');
 		}
 		if(session_id()){
 			session_destroy();

Modified: trunk/mapbender/owsproxy/http/index.php
===================================================================
--- trunk/mapbender/owsproxy/http/index.php	2014-01-24 09:49:11 UTC (rev 8760)
+++ trunk/mapbender/owsproxy/http/index.php	2014-01-27 22:24:41 UTC (rev 8761)
@@ -26,11 +26,6 @@
 $width = 400;
 $height = 400;
 /***** conf *****/
-if (ini_get('session.save_handler') == "memcache") {
-	$memcache_obj = new Memcache;
-	$memcache_obj->connect('localhost', 11211);
-	$e = new mb_notice("sessions stored to memcached");
-}
 $postdata = $HTTP_RAW_POST_DATA;
 $owsproxyService = $_REQUEST['wms']; //ToDo: change this to 'service' in the apache url-rewriting
 $query = new QueryHandler();
@@ -56,88 +51,57 @@
 //The session can be set by a given cookie value or was newly created by core/globalSettings.php
 //either empty (without mb_user_id value) - when the corresponding session file was lost or timed out
 //or filled, when there was an actual mapbender session before
+//
 //check if mb_user_id is given and is an string with an integer:
-if(!$_SESSION['mb_user_id'] && !is_int($_SESSION['mb_user_id'])){
-	$e = new mb_notice("Newly initialized session - no logged in mapbender user for this session!");
-}
-//Possibility to grap an existing session:
+$e = new mb_notice("userFromSession: ".getUserFromSession());
+
+//Possibility to grab an existing session:
 if (defined("OWSPROXY_ALLOW_SESSION_GRABBING") && OWSPROXY_ALLOW_SESSION_GRABBING == true) {
-	if ($grabbingAllowed) {
-		//first check is to find out if a session with the current sid exists! If so use this one, if not use the current one which was generated from globalSettings.php
-		switch (ini_get('session.save_handler')) {
-			//$e = new mb_notice("filesystem session found");
-			case "files":
-				$e = new mb_notice("filesystem session found");
-				if (file_exists(ini_get('session.save_path')."/sess_".$_REQUEST["sid"]) && session_id() !== $_REQUEST["sid"]) {
-					//there is a current session for the requested url
-					$e = new mb_notice("A current session exists for this url and will be used!");
-					$oldsessionId = session_id();
-					$tmpSessionFile = ini_get('session.save_path')."/sess_".session_id();
-					//do the following only, if a user is in this session - maybe it is a session which was generated from an external application and therefor it is empty!
-					session_id($_REQUEST["sid"]);
-					$e = new mb_notice("Grabbed session with id: ".session_id());
-					//kill dynamical session
-					//@unlink($tmpSessionFile);
-					$e = new mb_notice("Following user was found and will be used for authorization: ".Mapbender::session()->get('mb_user_id'));
-					$foundUserId = Mapbender::session()->get('mb_user_id');
-					if (!isset($foundUserId) || $foundUserId =='') {
-						$e = new mb_notice("No user found in the existing session - switch to the initial old one!");	
-						
-						session_id($oldsessionId);
-						//unset($tmpSessionFile);
-					} else {
-						//delete session as it will not be needed any longer
-						$e = new mb_notice("User found in grabbed session. Following temporary session will be deleted: ".$tmpSessionFile);
-						@unlink($tmpSessionFile);
-						unset($tmpSessionFile);
-					}
-				} else {
-				$e = new mb_notice("session exists but maybe no user in this session?");
+	if ($grabbingAllowed) { //for this ip
+		$currentSession = session_id();
+		//check for existing session in session storage - maybe the request came from outside - e.g. other browser, other application
+		$existSession = Mapbender::session()->storageExists($_REQUEST["sid"]);
+		if ($existSession) {
+			$e = new mb_notice("storage exists");
+		} else {
+			$e = new mb_notice("storage does not exist!");
+		}
+		if ($existSession && $currentSession !== $_REQUEST["sid"]) {
+			//there is a current session for the requested url
+			$e = new mb_notice("A current session exists for this url and will be used!");
+			//$oldsessionId = session_id();
+			$tmpSession = session_id();
+			//do the following only, if a user is in this session - maybe it is a session which was generated from an external application and therefor it is empty!
+			//grab session, cause it is allowed
+			session_id($_REQUEST["sid"]);
+			$e = new mb_notice("Grabbed session with id: ".session_id());
+			//kill dynamical session
+			//@unlink($tmpSessionFile);
+			$e = new mb_notice("Following user was found and will be used for authorization: ".Mapbender::session()->get('mb_user_id'));
+			//$foundUserId = Mapbender::session()->get('mb_user_id');
+			if (getUserFromSession() == false || getUserFromSession() <=  0) {
+				$e = new mb_notice("No user found in the existing session - switch to the initial old one!");	
+				session_id($tmpSession);
+			} else {
+				//delete session as it will not be needed any longer
+				$e = new mb_notice("Some reasonable user id found in grabbed session. Following temporary session will be deleted: ".$tmpSession);
+				Mapbender::session()->storageDestroy($tmpSession);
+				unset($tmpSession);
 			}
-			break;
-			case "memcache":
-				//check if a session exists for the SID param and if this session
-				$currentSession = $memcache_obj->get($_REQUEST["sid"]);
-				if ($currentSession !== false && session_id() !== $_REQUEST["sid"]) {
-					//there is a current session for the requested url
-					$e = new mb_notice("A current session exists for this url and will be used!");
-					//$oldsessionId = session_id();
-					//get actual session as key from memcached - new if not there
-					$tmpSessionFile = session_id();
-					//$tmpSessionFile = ini_get('session.save_path')."/sess_".session_id();
-					//do the following only, if a user is in this session - maybe it is a session which was generated from an external application and therefor it is empty!
-					session_id($_REQUEST["sid"]);
-					$e = new mb_notice("Grabbed session with id: ".session_id());
-					//kill dynamical session
-					//@unlink($tmpSessionFile);
-					$e = new mb_notice("Following user was found and will be used for authorization: ".Mapbender::session()->get('mb_user_id'));
-					$foundUserId = Mapbender::session()->get('mb_user_id');
-					if (!isset($foundUserId) || $foundUserId =='') {
-						$e = new mb_notice("No user found in the existing session - switch to the initial one!");
-						session_id($tmpSessionFile);
-						//unset($tmpSessionFile);
-					} else {
-						//delete old initial session  as it will not be needed any longer
-						$e = new mb_notice("Following temporary session will be deleted: ".$tmpSessionFile);
-						//delete session from memcached
-						//@unlink($tmpSessionFile);
-						$memcache_obj->delete($tmpSessionFile);
-						unset($tmpSessionFile);
-					}	
-				}
-			break;
+		} else {
+			$e = new mb_notice("Maybe either a session does not exist for the requested SID and/or the current session is equal to the requested SID. No grabbing should be done! The variable tmpSession will not be created.");
 		}
 	}
 }
+//After this there maybe the variable $tmpSession or not. If it is not there, an existing session was grabbed and shouldn't be deleted after, because a user is logged in or the logged in user requested the service!!!
 
-//check for user
-
 //check if current session has the same id as the session which is requested in the owsproxy url
-//exchange them, if they differ and redirect to an new one with the current session
+//exchange them, if they differ and redirect to an new one with the current session, they don't differ if the session was grabbed - e.g. when printing secured services via mapbender itself.
 if (session_id() !== $_REQUEST["sid"]) {
 	//get all request params which are original
 	//build reuquest
 	$redirectUrl = OWSPROXY."/".session_id()."/".$_REQUEST['wms'].$query->getRequest();
+	$redirectUrl = str_replace(":80:80",":80",$redirectUrl);
 	$e = new mb_notice("IDs differ - redirect to new owsproxy url: ".$redirectUrl);
 	header("Location: ".$redirectUrl);
 	die();
@@ -145,21 +109,17 @@
 	$e = new mb_notice("Current session_id() identical to requested SID!");
 }
 //this is the request which may have been redirected
-//check for given user session with user_id which can be tested again the authorization
-(integer)$foundUserId = Mapbender::session()->get('mb_user_id');
-$e = new mb_notice("Found user id: ".$foundUserId ." of type: ".gettype($foundUserId));
+//check for given user session with user_id which can be tested against the authorization
+/*$foundUserId = Mapbender::session()->get('mb_user_id');
+$e = new mb_exception("Found user id: ".$foundUserId ." of type: ".gettype($foundUserId));
+$foundUserId = (integer)$_SESSION['mb_user_id'];
+$e = new mb_exception("Found user id: ".$foundUserId ." of type: ".gettype($foundUserId));
+$foundUserId = getUserFromSession();*/
 
-
-if(is_int($foundUserId) &&  $foundUserId > 0){	
-	//Define the session to be temporary. This file can be deleted after the request was successful. It will be generated every time again.
-	switch (ini_get('session.save_handler')) {
-		case "files":
-			$tmpSessionFile = ini_get('session.save_path')."/sess_".session_id();
-		break;
-		case "memcache":
-			$tmpSessionFile = session_id();
-		break;
-	}
+if(getUserFromSession() == false || getUserFromSession() <=  0){	
+	//Define the session to be temporary - it should be deleted afterwards, cause there is no user in it! This file can be deleted after the request was more or less successful. It will be generated every time again.
+	$tmpSession = session_id();
+	$e = new mb_notice(" session_id(): ".session_id());
 	$e = new mb_notice("user_id not found in session!");
 	//if configured in mapbender.conf, create guest session so that also proxied service can be watched in external applications when they are available to the anonymous user
 	//only possible for webapplications - in case of desktop applications the user have to use his credentials and http_auth module
@@ -171,40 +131,32 @@
 		$e = new mb_notice("Permission allowed for public user with id: ".PUBLIC_USER);
 	} else {
 		$e = new mb_notice("Permission denied - public user not allowed to access ressource!");
-		//kill actual session file 
-		switch (ini_get('session.save_handler')) {
-			case "files":
-				$e = new mb_notice("delete temporary session file: ".$tmpSessionFile);
-				@unlink($tmpSessionFile);
-				throwE(array("Permission denied"," - no current session found and ","public user not allowed to access ressource!"));
-				unset($tmpSessionFile);
-				die();
-			break;
-			case "memcache":
-				$e = new mb_notice("delete temporary session ".session_id());
-				$memcache_obj->delete($tmpSessionFile);
-				//@unlink($tmpSessionFile);
-				throwE(array("Permission denied"," - no current session found and ","public user not allowed to access ressource!"));
-				unset($tmpSessionFile);
-				die();
-			break;
-		}
+		//kill actual session  
+		$e = new mb_notice("delete temporary session file: ".$tmpSession);
+		Mapbender::session()->storageDestroy($tmpSession);
+		throwE(array("Permission denied"," - no current session found and ","public user not allowed to access ressource!"));
+		unset($tmpSession);
+		die();
 	}
 } else {
-	$e = new mb_notice("mb_user_id found in session: ".$_SESSION['mb_user_id']);
-	$e = new mb_notice("tmpSessionFile: exists: ".isset($tmpSessionFile));
+	/*$e = new mb_exception("mb_user_id found in session: ".getUserFromSession());
+	if (isset($tmpSession)) {
+		$e = new mb_exception("tmpSessionFile: exists! - It was set before grabbing!");
+	} else {
+		$e = new mb_exception("tmpSessionFile: does not exist!");
+	}*/
 }
 //start the session to be able to write urls to it - for 
 session_start();//maybe it was started by globalSettings.php
 $n = new administration;
 //Extra security - IP check 
 if (defined("OWSPROXY_BIND_IP") && OWSPROXY_BIND_IP == true) {
-	if($_SESSION['mb_user_ip'] != $_SERVER['REMOTE_ADDR']){
+	if(Mapbender::session()->get('mb_user_ip') != $_SERVER['REMOTE_ADDR']){
 		throwE(array("Session not identified.","Permission denied.","Please authenticate."));
 		die();	
 	}
 }
-$e = new mb_notice("user id for authorization test: ".$_SESSION['mb_user_id']);
+$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
 $auth = $n->getAuthInfoOfWMS($wmsId);
@@ -266,7 +218,7 @@
 			$price=intval($n->getWmsPrice($arrayOnlineresources['wms_id']));
 			$n->logWmsProxyRequest($arrayOnlineresources['wms_id'],$_SESSION['mb_user_id'],$request,$price);
 		}
-		//$e = new mb_exception("owsproxy/http/index.php: ".$request);
+		//$e = new mb_notice("owsproxy/http/index.php: ".$request);
 		if(isset($auth)){
 			getImage($request,$auth);
 		}
@@ -326,21 +278,12 @@
 		
 }
 //why delete session here - only if it was temporary?
-switch (ini_get('session.save_handler')) {
-	case "files":
-		if (isset($tmpSessionFile) && file_exists($tmpSessionFile)) {
-			$e = new mb_notice("Following temporary session will be deleted: ".$tmpSessionFile);
-			@unlink($tmpSessionFile);
-		}
-	break;
-	case "memcache":
-		if (isset($tmpSessionFile) && $memcache_obj->get($tmpSessionFile) != false) {
-			$e = new mb_notice("Following temporary session will be deleted: ".$tmpSessionFile);
-			$memcache_obj->delete($tmpSessionFile);
-		}
-	break;
+if (isset($tmpSession) && Mapbender::session()->storageExists($tmpSession)) {
+	$e = new mb_notice("Following temporary session will be deleted: ".$tmpSession);
+	Mapbender::session()->storageDestroy($tmpSession);
 }
 
+
 /*********************************************************/
 function throwE($e){
 	global $reqParams, $imageformats;
@@ -377,9 +320,11 @@
 	}
 	responseImage($image);
 }
+
 function throwText($e){
 	echo join(" ", $e);
 }
+
 function responseImage($im){
 	global $reqParams;
 	$format = $reqParams['format'];
@@ -392,6 +337,7 @@
 	if($format == 'image/jpeg' || $format == 'image/jpg'){imagejpeg($im);}
 	if($format == 'image/gif'){imagegif($im);}	
 }
+
 function completeURL($url){
 	global $reqParams;
 	$mykeys = array_keys($reqParams);
@@ -457,7 +403,6 @@
  */
 function getFeature($url){
 	global $reqParams;
-	
 	header("Content-Type: ".$reqParams['info_format']);
 	$content = getDocumentContent($url);
 	$content = matchUrls($content);
@@ -476,7 +421,7 @@
  */
 
 function sendToHost($host,$port,$method,$path,$data){
-	$buf = '';
+    $buf = '';
     if (empty($method)) $method = 'POST';
     $method = mb_strtoupper($method);
     $fp = fsockopen($host, $port);
@@ -499,7 +444,7 @@
  */
 
 function getWfsFeaturesFromTransaction($data){
-	new mb_exception("owsproxy.getWfsFeaturesFromTransaction.data: ".$data);
+	new mb_notice("owsproxy.getWfsFeaturesFromTransaction.data: ".$data);
 	if(!$data || $data == ""){
 		return false;
 	}
@@ -510,16 +455,14 @@
 	xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
 	xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
 	xml_parse_into_struct($parser,$data,$values,$tags);
-
 	$code = xml_get_error_code ($parser);
 	if ($code) {
 		$line = xml_get_current_line_number($parser);
 		$col = xml_get_current_column_number($parser);
-		$mb_exception = new mb_exception("OWSPROXY invalid Tansaction XML: ".xml_error_string($code) .  " in line " . $line. " at character ". $col);
+		$mb_notice = new mb_notice("OWSPROXY invalid Tansaction XML: ".xml_error_string($code) .  " in line " . $line. " at character ". $col);
 		die();
 	}
 	xml_parser_free($parser);
-	
 	$insert = false;
 	$insertlevel = 0;
 	foreach ($values as $element) {
@@ -557,12 +500,10 @@
 	$arURL = parse_url($url);
 	$host = $arURL["host"];
 	$port = $arURL["port"]; 
-	if($port == '') $port = 80;	
-
+	if($port == '') $port = 80;
 	$path = $arURL["path"];
 	$method = "POST";
 	$result = sendToHost($host,$port,$method,html_entity_decode($path),$data);
-	
 	//delete header from result
 	$result = mb_eregi_replace("^[^<]*", "", $result);
 	$result = mb_eregi_replace("[^>]*$", "", $result);
@@ -580,11 +521,11 @@
 	preg_match_all($pattern,$content,$matches);
 	for($i=0; $i<count($matches[1]); $i++){
 		$req = $matches[1][$i];
-		$notice = new mb_exception("owsproxy found URL ".$i.": ".$req);
-		#$notice = new mb_exception("owsproxy id:".$req);
+		$notice = new mb_notice("owsproxy found URL ".$i.": ".$req);
+		#$notice = new mb_notice("owsproxy id:".$req);
 		$id = registerURL($req);
 		$extReq = setExternalRequest($id);
-		$notice = new mb_exception("MD5 URL ".$id." - external link: ".$extReq);
+		$notice = new mb_notice("MD5 URL ".$id." - external link: ".$extReq);
 		$content = str_replace($req,$extReq,$content);
 	}
 	return $content;
@@ -596,6 +537,7 @@
 	$extReq = 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]){
@@ -617,6 +559,7 @@
 		}	
 	} 
 }
+
 function removeOWSGetParams($query_string){
 	$r = preg_replace("/.*request=external&/","",$query_string);
 	#return $r;
@@ -637,6 +580,7 @@
 	} 
 	return $cchar;  
 }
+
 function registerUrl($url){	
 	if(!in_array($url,$_SESSION["owsproxyUrls"]["url"])){
 		$id = md5($url);
@@ -652,6 +596,7 @@
 	}
 	return $id;
 }
+
 function getCapabilities($url){
 	global $arrayOnlineresources;
 	global $sid,$wms;
@@ -693,7 +638,7 @@
 	$res = db_prep_query($sql, $v, $t);
 	if($row = db_fetch_array($res)) {
 		if (strpos($row["legendurl"],'http') !== 0) {
-			$e = new mb_exception("combine legendurls!");
+			$e = new mb_notice("combine legendurls!");
 			return $getLegendUrl.$row["legendurl"];
 		}
 		return $row["legendurl"];
@@ -726,7 +671,7 @@
 	}
 	
 	if(!$row || count($mywms) == 0){
-		throwE(array("No wms data available."));
+		throwE(array("No wms data for this user available."));
 		die();	
 	}
 	
@@ -747,13 +692,11 @@
 function checkWfsPermission($wfsOws, $features){
 	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();
 	}
-	
 	//get wfs
 	$sql = "SELECT * FROM wfs WHERE wfs_owsproxy = $1";
 	$v = array($wfsOws);
@@ -774,7 +717,6 @@
 	}
 	
 	foreach($features as $feature){
-	
 		//get appropriate wfs_conf
 		$sql = "SELECT wfs_conf.wfs_conf_id FROM wfs_conf ";
 		$sql.= "JOIN wfs_featuretype ";
@@ -785,27 +727,25 @@
 		$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_notice("Permissioncheck failed no wfs conf for wfs ".$service["wfs_id"]." with feturetype ".$feature);
 			throwE(array("No wfs_conf data for featuretype ".$feature));
 			die();	
 		}
 		$conf_id = $row["wfs_conf_id"];
-		
 		//check permission
 		if(!in_array($conf_id, $myconfs)){
-			$notice = new mb_exception("Permissioncheck failed:".$conf_id." not in ".implode(",", $myconfs));
+			$notice = new mb_notice("Permissioncheck failed:".$conf_id." not in ".implode(",", $myconfs));
 			throwE(array("Permission denied."," -> ".$conf_id, implode(",", $myconfs)));
 			die();
 		}
 	}
-
 	return $service;
 }
 
 function checkLayerPermission($wms_id,$l){
 	global $n, $owsproxyService;
 //	$notice = new mb_exception("owsproxy: checkLayerpermission: wms: ".$wms_id.", layer: ".$l);
-	$myl = split(",",$l);
+	$myl = explode(",",$l);
 	$r = array();
 	foreach($myl as $mysl){
 		if($n->getLayerPermission($wms_id, $mysl, $_SESSION["mb_user_id"]) === true){
@@ -815,6 +755,7 @@
 	$ret = implode(",",$r);
 	return $ret;
 }
+
 function getDocumentContent($url){
 	if (func_num_args() == 2) { //new for HTTP Authentication
        	$auth = func_get_arg(1);
@@ -826,4 +767,22 @@
 
 	return $d->file;
 }
+
+function getUserFromSession() {
+	if (Mapbender::session()->get('mb_user_id')) {
+		if ((integer)Mapbender::session()->get('mb_user_id') >= 0) {
+			$foundUserId = (integer)Mapbender::session()->get('mb_user_id');
+			//$e = new mb_exception("user id: ".$foundUserId." found in session");
+		} else {
+			$foundUserId = false;
+			//$e = new mb_exception("user id not found or not casted to integer");
+			//$e = new mb_exception("Newly initialized session - no logged in mapbender user for this session!");
+		}
+	} else {
+		$foundUserId = false;
+		//$e = new mb_exception("user id not found or not casted to integer");
+		//$e = new mb_exception("Newly initialized session - no logged in mapbender user for this session!");
+	}
+	return $foundUserId;
+}
 ?>



More information about the Mapbender_commits mailing list