[Mapbender-commits] r4580 - in trunk/mapbender: http/classes http/php owsproxy/http resources/db/update

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Aug 31 06:05:09 EDT 2009


Author: christoph
Date: 2009-08-31 06:05:08 -0400 (Mon, 31 Aug 2009)
New Revision: 4580

Modified:
   trunk/mapbender/http/classes/class_administration.php
   trunk/mapbender/http/php/mod_owsproxy_conf.php
   trunk/mapbender/owsproxy/http/index.php
   trunk/mapbender/resources/db/update/update_2.7.sql
Log:
http://trac.osgeo.org/mapbender/ticket/523

Modified: trunk/mapbender/http/classes/class_administration.php
===================================================================
--- trunk/mapbender/http/classes/class_administration.php	2009-08-31 07:56:25 UTC (rev 4579)
+++ trunk/mapbender/http/classes/class_administration.php	2009-08-31 10:05:08 UTC (rev 4580)
@@ -458,7 +458,7 @@
      * @return array 	wms ids for the user
      */
 	function getWmsByWmsOwner($user_id){
-		$sql = "SELECT wms_id FROM wms WHERE wms_owner = $1";
+		$sql = "SELECT wms_id FROM wms WHERE wms_owner = $1 ORDER BY wms_id";
 		$v = array($user_id);
 		$t = array('i');
 		$res = db_prep_query($sql,$v,$t);
@@ -793,6 +793,22 @@
 		return $layer_id_array;
 	}
 
+ function getAllLayerByWms($wms_id){
+                $sql = "SELECT layer_id from layer WHERE fkey_wms_id = $1 GROUP BY layer_id, layer_title ORDER BY layer_title";
+                $v = array($wms_id);
+                $t = array('i');
+                $res = db_prep_query($sql,$v,$t);
+                $layer_id_array = array();
+                while($row = db_fetch_array($res)){
+                        $layer_id_array[count($layer_id_array)] = $row['layer_id'];
+                }
+                return $layer_id_array;
+        }
+
+
+
+
+
 	function getWmsOwner($wms_id){
 		$sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = $1 GROUP BY fkey_gui_id";
 		$v = array($wms_id);
@@ -944,8 +960,8 @@
    	function setWMSOWSstring($wms_id, $status){
    		$sql = "UPDATE wms SET wms_owsproxy = $1 WHERE wms_id = $2 ";
    		$t = array("s","i");
-   		if($status == 'on'){
-   			$time = md5(microtime(1));
+   		if($status == 1){
+   			$time = md5(uniqid());
 			$v = array($time,$wms_id);
    		}
    		else{
@@ -953,8 +969,117 @@
    		}
    		$res = db_prep_query($sql,$v,$t);
    	}
-	
+
 	/*
+	 * set the log tag of the wms
+	 * 
+	 * @param integer the wms-id 
+	 * 
+	 */
+
+   	function setWmsLogTag($wms_id,$value){
+   		$sql = "UPDATE wms set wms_proxylog=$2 WHERE  wms_id = $1 ";
+   		$t = array("i","i");
+		$v = array($wms_id,$value);
+   		$res = db_prep_query($sql,$v,$t);
+   	}	
+
+	/*
+	 * get the log tag of the wms
+	 * 
+	 * @param integer the wms-id 
+	 * @return 1 for active log and 0 or null for deactivated log
+	 */
+
+   	function getWmsLogTag($wms_id){
+   		$sql = "SELECT wms_proxylog from wms WHERE  wms_id = $1 ";
+   		$t = array("i");
+		$v = array($wms_id);
+   		$res = db_prep_query($sql,$v,$t);
+		if($row = db_fetch_array($res)){
+   			return $row["wms_proxylog"];
+   		}
+   		else{
+   			return false;
+   		}
+   	}	
+	/*
+	 * set the pricevolume of the wms
+	 * 
+	 * @param integer the wms-id 
+	 * @param integer the price for one kilobyte of wms data
+	 */
+
+   	function setWmsPrice($price,$wms_id){
+   		$sql = "UPDATE wms set wms_pricevolume=$1 WHERE  wms_id = $2 ";
+   		$t = array("i","i");
+		$v = array($price,$wms_id);
+   		$res = db_prep_query($sql,$v,$t);
+   	}	
+
+	/*
+	 * get the price for one kilobyte of wms data
+	 * 
+	 * @param integer the wms-id 
+	 * @return integer for price in cents for one kb of wms data
+	 */
+
+   	function getWmsPrice($wms_id){
+   		$sql = "SELECT wms_pricevolume from wms WHERE  wms_id = $1 ";
+   		$t = array("i");
+		$v = array($wms_id);
+   		$res = db_prep_query($sql,$v,$t);
+		if($row = db_fetch_array($res)){
+   			return $row["wms_pricevolume"];
+   		}
+   		else{
+   			return false;
+   		}
+   	}	
+
+
+	/*
+	 * log wms getmap proxy urls to db
+	 * 
+	 * @param 
+	 * @return
+	 */
+
+   	function logWmsProxyRequest($wms_id,$user_id,$getmap,$price){
+   		$sql = "INSERT INTO mb_proxy_log (fkey_wms_id,fkey_mb_user_id, request, pixel, price) VALUES ($1, $2, $3, $4,$5)";
+   		$t = array("i","i","s","i","r");
+		#extract height and width
+		#use regexpr
+		$pattern_height = '~HEIGHT=(\d+)&~i';
+		$pattern_width = '~WIDTH=(\d+)&~i';
+		preg_match($pattern_width, $getmap,$sub_width);
+		preg_match($pattern_height, $getmap,$sub_height);
+		$width=intval($sub_width[1]);
+		$height=intval($sub_height[1]);
+		$pixel=intval($width*$height);
+		$price=$pixel*$price/1000000;
+		$v = array(intval($wms_id),intval($user_id),$getmap,$pixel,$price);
+   	        #echo print_r($v,true)."<br>";
+		#var_dump($v);
+		#echo $sql."<br>";	
+		#echo "test<br>";
+		$res = db_prep_query($sql,$v,$t) or die(db_error());
+		#echo "test<br>";
+		if(!$res){
+			include_once(dirname(__FILE__)."/class_mb_exception.php");
+			$e = new mb_exception("class_log: Writing table mb_proxy_log failed.");
+			return false;
+		}
+		return true;
+		
+		#if($row = db_fetch_array($res)){
+   			#return $row["wms_proxylog"];
+   		#}
+   		#else{
+   			#return false;
+   		#}
+   	}	
+	/*
 	 * get the owsproxy-string of the current wfs
 	 * 
 	 * @param integer the wfs-id of the current wfs
@@ -1092,13 +1217,14 @@
 		$t = array('i','s');
 		$res = db_prep_query($sql,$v,$t);
 		if($row = db_fetch_array($res)){
-			return $row['layer_id'];
+			if (is_numeric($row['layer_id'])) {
+				return intval($row['layer_id']);
+			}
 		}
-		else{
-			return false;
-		}
+		$e = new mb_warning("Unknown Layer (WMS ID: " . $wms_id . ", layer name: " . $layer_name . ")");
+		return false;
 	}
-	
+
 	function getWmsIdByWmsGetmap($getmap) {
 		$sql = "SELECT wms_id FROM wms WHERE ";
 		$sql .= "wms_getmap LIKE $1 LIMIT 1";

Modified: trunk/mapbender/http/php/mod_owsproxy_conf.php
===================================================================
--- trunk/mapbender/http/php/mod_owsproxy_conf.php	2009-08-31 07:56:25 UTC (rev 4579)
+++ trunk/mapbender/http/php/mod_owsproxy_conf.php	2009-08-31 10:05:08 UTC (rev 4580)
@@ -17,13 +17,106 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-require_once(dirname(__FILE__)."/../php/mb_validatePermission.php");
-require_once(dirname(__FILE__)."/../classes/class_administration.php");
+include(dirname(__FILE__)."/../php/mb_validateSession.php");
+include(dirname(__FILE__)."/../classes/class_administration.php");
 $admin = new administration();
-$ownwms = $admin->getWmsByOwner(Mapbender::session()->get("mb_user_id"));
-if(isset($_REQUEST["wms_id"]) && isset($_REQUEST["status"])){
-	$admin->setWMSOWSstring(intval($_REQUEST["wms_id"]),$_REQUEST["status"]);	
+$ownwms = $admin->getWmsByWmsOwner($_SESSION["mb_user_id"]);
+#need admin functions: getWmsLogTag, getWmsPrice, setWmsLogTag, setWmsPrice
+#can set log only when proxy on, can set price only when log on
+#read out the request 
+ function array2str($array, $pre = '', $pad = '', $sep = ', ')  
+ {  
+     $str = '';  
+     if(is_array($array)) {  
+         if(count($array)) {  
+             foreach($array as $v) {  
+                 $str .= $pre.$v.$pad.$sep;  
+             }  
+             $str = substr($str, 0, -strlen($sep));  
+         }  
+     } else {  
+         $str .= $pre.$array.$pad;  
+     }  
+   
+     return $str;  
+ }  
+
+function validateint($inData) {
+  $intRetVal = 0;
+
+  $IntValue = intval($inData);
+  $StrValue = strval($IntValue);
+  if($StrValue == $inData) {
+    $intRetVal = $IntValue;
+  }
+
+  return $intRetVal;
 }
+
+
+
+
+if(isset($_REQUEST["save"])){
+#if(isset($_REQUEST["wms_id"]) && isset($_REQUEST["status"])){
+
+	#$admin->setWMSOWSstring(intval($_REQUEST["wms_id"]),$_REQUEST["status"]);
+#print_r($_POST);
+
+#TODO deactivate proxy, logs and prices for all owned wms
+#TODO
+#$wms_list=array2str($ownwms);
+#print $wms_list;
+
+
+
+//$admin->unsetWmsProxy($wms_list);#TODO not delete owsproxy urls but update each entry! -> this would not delete log or usage of proxy!!!
+#serialize ownwms - to list and do sql
+#for the definitions in the form set the params
+#sequentialy read out the post variables
+foreach ($_POST as $var => $value) {
+	#select those which are relevant (hidden fields for proxy and log)
+	#identify them
+	$parts=explode("_",$var);
+	#echo "All vars: <br>";
+	#echo $var." = ".$value."<br>";
+	$value=validateint($value);
+	if ($parts[0]!='status' && $parts[2]=='price'){ #for the pricing in the textfield
+		
+		$admin->setWmsPrice(intval($value),intval($parts[1]));
+	}
+	#check the hidden fields if some log should be set 
+	if ($parts[2]=='log' && $parts[0]=='status'){
+		#set the log value to 1 or 0
+		$admin->setWmsLogTag(intval($parts[1]),$value);
+		#if value is 0 then set the price to 0 to. there would be is no sense to have a price set - maybe change this behavior
+		if ($value==0) {
+			$admin->setWmsPrice(intval($value),intval($parts[1]));
+		}
+		#echo "log: $var = $value<br>";
+	}
+	#check proxy fields
+	if ($parts[0]=='status' && $parts[2]=='proxy'){ 
+		#echo ("proxy settings identified: WMS_ID: ".intval($parts[1])." Value: ".$value."<br>");	
+		#echo ("Is active?: ");
+		#if ($admin->getWMSOWSstring(intval($parts[1]))=="") {echo " no";} else {echo " yes";}
+		#echo ("<br>");
+		#check if proxy should be activated and is not set
+		if ($value==1 && $admin->getWMSOWSstring(intval($parts[1])) == "") {
+		#activate it!
+		$admin->setWMSOWSstring(intval($parts[1]),$value);
+		#echo "Activate Proxy for ".intval($parts[1])."<br>";
+		}
+		#check if active proxy should be deactivated
+		if ($value==0 && $admin->getWMSOWSstring(intval($parts[1])) !== "") {
+		#deactivate it
+		$admin->setWMSOWSstring(intval($parts[1]),$value);
+		#echo "Deactivate Proxy for ".intval($parts[1])."<br>";
+		}
+	}
+
+}
+	
+}
 ?>
 <html>
 <head>
@@ -38,29 +131,94 @@
 }
 </style>
 <script language="JavaScript" type="text/javascript">
-function set(wms_id, status){
-	document.location.href = "<?php echo $self; ?>&wms_id="+wms_id+"&status="+status; 
-}
+
 </script>
   
 </head>
 <body>
-<form>
+
 <table>
 <?php
+#$ownwmsconf['proxy']=array();
+#$ownwmsconf['log']=array();
+#$ownwmsconf['price']=array();
+#TODO Get root layer id for showing metadata! - function should be in admin class
+echo "<form  method=\"post\" action=\"".$_PHP_SELF."\">";
+echo "<i>Warning: Toggle proxy changes the url of the secured services!</i><br>";
+echo "<table border='1'>";
+echo "<tr valign = bottom>";
+echo "<td>";
+echo "WMS ID";
+echo "</td>";
+echo "<td>";
+echo "WMS Title";
+echo "</td>";
+echo "<td>";
+echo "Proxy";
+echo "</td>";
+echo "<td>";
+echo "Log";
+echo "</td>";
+echo "<td>";
+echo "Price(cent/Mpixel)";
+echo "</td>";
+echo "</tr>";
 for($i=0; $i<count($ownwms); $i++){
+	#read out current values in db
+	if($admin->getWMSOWSstring($ownwms[$i]) == false){ $status_proxy = 0 ;} else {$status_proxy = 1;};
+	if($admin->getWmsLogTag($ownwms[$i]) == 1){$status_log=1;} else {$status_log=0;};
+	if ($admin->getWmsPrice($ownwms[$i]) != 0 ){$status_price=$admin->getWmsPrice($ownwms[$i]);} else {$status_price=0;};
+
 	echo "<tr>";
+	echo "<td>".$ownwms[$i]."</td>";
+	echo "<td>".$admin->getWmsTitleByWmsId($ownwms[$i])."</td>";
 	echo "<td>";
-	echo "<input type='checkbox' onclick='if(this.checked){set(\"".$ownwms[$i]."\",\"on\")}else{set(\"".$ownwms[$i]."\",\"off\")}' ";
-	if($admin->getWMSOWSstring($ownwms[$i]) != false){ echo "checked";  }
+	#for owsproxy	
+	echo "<input type='checkbox' id='wms_".$ownwms[$i]."_proxy' name='wms_".$ownwms[$i]."_proxy' onclick='if(this.checked){document.getElementById(\"wms_\"+".$ownwms[$i]."+\"_log\").disabled=false;document.getElementById(\"wms_\"+".$ownwms[$i]."+\"_price\").disabled=true;document.getElementById(\"status_\"+".$ownwms[$i]."+\"_proxy\").value=\"1\"}else{document.getElementById(\"wms_\"+".$ownwms[$i]."+\"_log\").checked=false;document.getElementById(\"wms_\"+".$ownwms[$i]."+\"_log\").disabled=true;document.getElementById(\"wms_\"+".$ownwms[$i]."+\"_price\").disabled=true;document.getElementById(\"wms_\"+".$ownwms[$i]."+\"_price\").value=\"0\";document.getElementById(\"status_\"+".$ownwms[$i]."+\"_proxy\").value=\"0\";document.getElementById(\"status_\"+".$ownwms[$i]."+\"_log\").value=\"0\"}'";
+	
+	
+	#default
+	if($status_proxy == 1){ echo " checked";  } else {echo " unchecked"; };  //if a proxy string is set
 	echo ">";
+	#initialize hidden field for status proxy:
+
+	echo "<input type=\"hidden\" name=\"status_".$ownwms[$i]."_proxy\" id=\"status_".$ownwms[$i]."_proxy\" value=".$status_proxy.">";
+
 	echo "</td>";
-	echo "<td>".$ownwms[$i]."</td>";
-	echo "<td>".$admin->getWmsTitleByWmsId($ownwms[$i])."</td>";
-	echo "</tr>";	
+	#for logging
+	echo "<td><input type='checkbox' id='wms_".$ownwms[$i]."_log' name='wms_".$ownwms[$i]."_log' onclick='if(this.checked){document.getElementById(\"wms_\"+".$ownwms[$i]."+\"_price\").disabled=false;document.getElementById(\"status_\"+".$ownwms[$i]."+\"_log\").value=\"1\"}else{document.getElementById(\"wms_\"+".$ownwms[$i]."+\"_price\").disabled=true;document.getElementById(\"wms_\"+".$ownwms[$i]."+\"_price\").value=\"0\";document.getElementById(\"status_\"+".$ownwms[$i]."+\"_log\").value=\"0\";document.getElementById(\"status_\"+".$ownwms[$i]."+\"_price\").value=\"0\"}'";
+
+	
+	#default
+	if($status_proxy==0){ echo "disabled "; };
+	if($status_log == 1){ echo " checked";  };//if a log tag is set -> to activate
+	echo ">";
+	#initialize hidden field for status log:
+	
+	echo "<input type=\"hidden\" name=\"status_".$ownwms[$i]."_log\" id=\"status_".$ownwms[$i]."_log\" value=".$status_log.">";
+
+	echo "</td>";
+	#for pricing
+	echo "<td><input id='wms_".$ownwms[$i]."_price' name='wms_".$ownwms[$i]."_price' type='text' size='5' value='";
+	echo $status_price;
+	echo "' ";
+	#default
+	if($status_log != 1){ echo "disabled";  } else { echo "enabled";  };
+	//if($admin->getWmsPrice($ownwms[$i]) != 0){ echo "disabled";  }
+	echo ">";
+	#initialize hidden field for status price:
+	
+	echo "<input type=\"hidden\" name=\"status_".$ownwms[$i]."_price\" id=\"status_".$ownwms[$i]."_price\" value=".$status_price.">";
+
+
+	echo "</td>";
+echo "</tr>";
+	
 }
+echo "</table>";
+echo "<input type='submit' name='save' value='save'  ></form>";
 ?>
 </table>
 </form>
 </body>
-</html>
\ No newline at end of file
+</html>

Modified: trunk/mapbender/owsproxy/http/index.php
===================================================================
--- trunk/mapbender/owsproxy/http/index.php	2009-08-31 07:56:25 UTC (rev 4579)
+++ trunk/mapbender/owsproxy/http/index.php	2009-08-31 10:05:08 UTC (rev 4580)
@@ -82,6 +82,14 @@
 		}
 		$query->setParam("layers",$layers);
 		$request = $query->getRequest();
+		#log proxy requests
+		if($n->getWmsLogTag($arrayOnlineresources['wms_id'])==1) {
+			#do log to db
+			#TODO read out size of bbox and calculate price
+		        #get price out of db
+			$price=intval($n->getWmsPrice($arrayOnlineresources['wms_id']));
+			$n->logWmsProxyRequest($arrayOnlineresources['wms_id'],$_SESSION['mb_user_id'],$request,$price);
+		}
 		getImage($request);
 		break;
 	case 'map':
@@ -178,6 +186,11 @@
 function getImage($or){
 	global $reqParams;
 	header("Content-Type: ".$reqParams['format']);
+	#log the image_requests to database
+	#log the following to table mb_proxy_log
+	#timestamp,user_id,getmaprequest,amount pixel,price - but do this only for wms to log - therefor first get log tag out of wms!
+	#
+	#
 	echo getDocumentContent($or);
 }
 
@@ -327,8 +340,11 @@
 	preg_match_all($pattern,$content,$matches);
 	for($i=0; $i<count($matches[1]); $i++){
 		$req = $matches[1][$i];
+		$e = new mb_exception("Gefundene URL ".$i.": ".$req);
+		#$notice = new mb_notice("owsproxy id:".$req);
 		$id = registerURL($req);
 		$extReq = setExternalRequest($id);
+		$e = new mb_exception("MD5 URL ".$id."-Externer Link: ".$extReq);
 		$content = str_replace($req,$extReq,$content);
 	}
 	return $content;
@@ -336,6 +352,7 @@
 
 function setExternalRequest($id){
 	global $reqParams,$query;
+//	$extReq = "http://".$_SESSION['HTTP_HOST'] ."/owsproxy/". $reqParams['sid'] ."/".$id."?request=external";
 	$extReq = OWSPROXY ."/". $reqParams['sid'] ."/".$id."?request=external";
 	return $extReq;
 }
@@ -355,14 +372,15 @@
 			header("Content-Type: ".$metainfo['Content-Type']);
 			
 			$content = getDocumentContent($cUrl);
-			$content = matchUrls($content);			
+			#$content = matchUrls($content);			
 			echo $content; 
 		}	
 	} 
 }
 function removeOWSGetParams($query_string){
 	$r = preg_replace("/.*request=external&/","",$query_string);
-	return $r;
+	#return $r;
+	return "";
 }
 function getConjunctionCharacter($url){
 	if(strpos($url,"?")){ 

Modified: trunk/mapbender/resources/db/update/update_2.7.sql
===================================================================
--- trunk/mapbender/resources/db/update/update_2.7.sql	2009-08-31 07:56:25 UTC (rev 4579)
+++ trunk/mapbender/resources/db/update/update_2.7.sql	2009-08-31 10:05:08 UTC (rev 4580)
@@ -257,3 +257,22 @@
 INSERT INTO gui_element(fkey_gui_id, e_id, e_pos, e_public, e_comment, e_title, e_element, e_src, e_attributes, e_left, e_top, e_width, e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, e_mb_mod, e_target, e_requires, e_url) VALUES('admin1','monitor_results',2,1,'monitoring results','Monitoring results','a','','href = "../php/mod_monitorCapabilities_read.php?sessionID" target = "AdminFrame" ',8,1110,190,20,10,'font-family: Arial, Helvetica, sans-serif; font-size : 12px; text-decoration : none; color: #808080;','View monitoring results','a','','','','AdminFrame','http://www.mapbender.org/');
 
 ---------------------------------------------MONITORING END
+
+---------------------------
+-- OWS Proxy log
+CREATE TABLE mb_proxy_log (
+    
+    proxy_log_timestamp timestamp default now(),
+    fkey_wms_id integer NOT NULL,
+    fkey_mb_user_id integer NOT NULL,
+    request varchar(4096),
+    pixel bigint,
+    price real
+    
+)
+with oids;
+ALTER TABLE wms ADD COLUMN wms_proxylog integer;
+ALTER TABLE wms ALTER COLUMN wms_proxylog SET STORAGE PLAIN;
+ALTER TABLE wms ADD COLUMN wms_pricevolume integer;
+ALTER TABLE wms ALTER COLUMN wms_pricevolume SET STORAGE PLAIN;
+---------------------------



More information about the Mapbender_commits mailing list