[Mapbender-commits] r9464 - in trunk/mapbender/http: classes php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu May 19 00:34:20 PDT 2016


Author: armin11
Date: 2016-05-19 00:34:20 -0700 (Thu, 19 May 2016)
New Revision: 9464

Modified:
   trunk/mapbender/http/classes/class_administration.php
   trunk/mapbender/http/php/mod_wmc2ol.php
Log:
Possibility to log invocation of external clients by referrer

Modified: trunk/mapbender/http/classes/class_administration.php
===================================================================
--- trunk/mapbender/http/classes/class_administration.php	2016-05-19 07:32:47 UTC (rev 9463)
+++ trunk/mapbender/http/classes/class_administration.php	2016-05-19 07:34:20 UTC (rev 9464)
@@ -676,6 +676,65 @@
 	}
 
     /**
+     * functions to log referrer for external invoced client api to database.
+     *
+     * @param referrer			http header referer! string
+     * @param wmc_serial_id		wmc_serial_id from mb_user_wmc table
+     * @param api_type		        id for the client type which is invoked: 1=openlayers, 2=mobileclient
+     * @return boolean			true or false 
+     */
+	function logClientUsage ($referrer, $wmc_serial_id, $api_type) {
+		if (DEFINED("EXTERNAL_CLIENT_LOG") && EXTERNAL_CLIENT_LOG == true && isset($referrer) && $referrer !=="" && $referrer !== false) {
+			$logId = $this->isClientLogEntryAlreadyInDB($referrer, $wmc_serial_id, $api_type);
+			if ($logId != false) {
+				$sql = <<<SQL
+UPDATE external_api_log SET log_count = log_count + 1 WHERE log_id = $1
+SQL;
+				$v = array(
+					$logId
+				);
+				$t = array('i');
+				$res = db_prep_query($sql,$v,$t);
+				return true;
+			} else {
+				//create new record cause api has not been invoced so far
+				$sql = <<<SQL
+INSERT INTO external_api_log (createdate, referrer, fkey_wmc_serial_id, api_type, log_count) VALUES (now(), $1, $2, $3, 1)
+SQL;
+				$v = array(
+					$referrer,
+					$wmc_serial_id,
+					$api_type
+				);
+				$t = array('s',i,i);
+				$res = db_prep_query($sql,$v,$t);
+				return true;
+			}
+		}
+	}
+
+	function isClientLogEntryAlreadyInDB($referrer, $wmc_serial_id, $api_type){
+		$sql = <<<SQL
+SELECT log_id FROM external_api_log WHERE fkey_wmc_serial_id = $2 AND api_type = $3 AND referrer = $1 ORDER BY lastchanged DESC
+SQL;
+		$v = array(
+			$referrer,
+			$wmc_serial_id,
+			$api_type
+		);
+		$t = array('s',i,i);
+		$res = db_prep_query($sql,$v,$t);
+		while ($row = db_fetch_array($res)){
+			$logId[] = $row['log_id'];	
+		}
+		if (count($logId) > 0) {
+			return $logId[0];
+		} else {	
+			return false;
+		}
+	}
+
+    /**
      * resets the login count of a given user to 0
      * @param integer	the user id
      * @return boolean 	could the login count be reseted?

Modified: trunk/mapbender/http/php/mod_wmc2ol.php
===================================================================
--- trunk/mapbender/http/php/mod_wmc2ol.php	2016-05-19 07:32:47 UTC (rev 9463)
+++ trunk/mapbender/http/php/mod_wmc2ol.php	2016-05-19 07:34:20 UTC (rev 9464)
@@ -37,8 +37,6 @@
 	$userId = PUBLIC_USER;
 }
 
-
-
 if (isset($_REQUEST["wmc_id"]) & $_REQUEST["wmc_id"] != "") {
 	//validate to csv integer list
 	$testMatch = $_REQUEST["wmc_id"];
@@ -52,11 +50,7 @@
 	$testMatch = NULL;
 }
 
-
-
-
 //dummy parameter for drawing georss points:
-
 $pointRadius = "10";
 $fillColor = "#666666"; //grey
 
@@ -865,4 +859,8 @@
 //end of function createOlfromWMC_id()
 
 createOlfromWMC_id($_GET["wmc_id"], $pointRadius, $fillColor);
+
+if (strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) === false {
+	$admin->logClientUsage('test', $wmc_id, 1);
+}
 ?>



More information about the Mapbender_commits mailing list