svn commit: r146 - trunk/mapbender/http: javascripts php

christoph at osgeo.org christoph at osgeo.org
Tue Apr 25 11:22:51 EDT 2006


Author: christoph
Date: 2006-04-25 15:22:51+0000
New Revision: 146

Added:
   trunk/mapbender/http/javascripts/mod_displayObj_extended.js
   trunk/mapbender/http/javascripts/mod_insertMonitoredWmsIntoDb.php
   trunk/mapbender/http/php/mod_monitorWMS.php

Log:
new modules for wms monitoring

Added: trunk/mapbender/http/javascripts/mod_displayObj_extended.js
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/javascripts/mod_displayObj_extended.js?view=auto&rev=146
==============================================================================
--- (empty file)
+++ trunk/mapbender/http/javascripts/mod_displayObj_extended.js	2006-04-25 15:22:51+0000
@@ -0,0 +1,167 @@
+//$Id: mod_displayObj.js,v 1.9 2006/03/10 08:10:45 astrid_emde Exp $
+//$Header: /cvsroot/mapbender/mapbender/http/javascripts/mod_displayObj.js,v 1.9 2006/03/10 08:10:45 astrid_emde Exp $
+function mod_displayObj(){
+   var tg = "";
+   tg +="<head>";
+   tg += "<style type='text/css'>";
+   tg +="<!-- body{font-family:Verdana, Geneva, Arial, Helvetica, sans-serif;font-size:10pt}";
+   tg +="hr{color:blue;}";
+   tg +="table{border-width:1;font-size:10pt}";
+   tg +="th{background-color:#F08080;text-align:left;}";
+   tg +="tr{background-color:white;}";
+   tg +=".tr_head{font-weight:bold;background-color:silver;}";
+   tg +=".th_wfs{font-weight:bold;background-color:#BDBAF7;text-align:left;}";
+   tg +="--></style></head>";
+   
+   var myWin = null;
+   tg += "<body>\n";
+   tg += "<h3 >Mapbender Metadata</h3>\n";
+        tg += "<h4 >active maps</h4>\n";
+		
+   for(var i=0; i<mb_mapObj.length; i++){
+                tg += "<h4 >frame: "+ mb_mapObj[i].frameName+"</h4>\n";
+                tg += "<table cellspacing=10 border='1' width='98%' rules='rows'><tr>\n";
+      tg += "<th width='200'>wms:</th><th>request</th></tr>\n";
+      for(var ii=0; ii<mb_mapObj[i].wms.length; ii++){
+              tg +="<tr><td valign = middle align = center>\n";
+              if (!(mb_mapObj[i].mapURL[ii] == false || typeof(mb_mapObj[i].mapURL[ii]) == 'undefined' )) {
+	              tg +="<button name='Monitor' type='button' value='Monitor' ";
+	              tg += "onClick=\"";
+//	              tg += "alert(window.opener.document.getElementById('sendData').target);";
+//	              tg += "window.opener.document.getElementById('sendData').target=window.opener.frames['loadData'];";
+	              tg += "window.opener.document.getElementById('sendData').action='../javascripts/mod_insertMonitoredWmsIntoDb.php';";
+	              tg += "window.opener.document.getElementById('sendData').data.value = '"+mb_mapObj[i].wms[ii].wms_id+"____" + mb_mapObj[i].mapURL[ii]+"';";
+	              tg += "window.opener.document.getElementById('sendData').submit()\"'>Monitor</button>\n";
+	          }
+              tg +="</td><td width='200'>"+mb_mapObj[i].wms[ii].wms_title+"</td><td>\n";
+			  // if the mapURL is not defined or false, don't add a link
+              if (mb_mapObj[i].mapURL[ii] == false || typeof(mb_mapObj[i].mapURL[ii]) == 'undefined' ) {
+	              tg += mb_mapObj[i].mapURL[ii];
+              }
+              else {
+	              tg += "<a href='"+ mb_mapObj[i].mapURL[ii]+"' target='_blank'>"+ mb_mapObj[i].mapURL[ii]+"</a>\n";
+              }
+              tg +="</td></tr>\n";
+      }
+     tg += "</table><br>\n";
+   }
+   
+   tg += "<hr>\n";
+   
+   
+   for(var cnt=0; cnt<wms.length;cnt++){
+     tg += "<h4 >WMS: "+ cnt+ ": "+wms[cnt].wms_title+" ("+wms[cnt].wms_abstract+") </h4>";
+     tg += "<table border='1' rules='rows'><tr>";
+     tg += "<th >WMS nr:</th><th>" + cnt+ "</th></tr>";
+     tg += "<tr><td>wms_id:</td><td>" + wms[cnt].wms_id + "</td></tr>";
+     tg += "<tr><td>wms_version:</td><td>" + wms[cnt].wms_version + "</td></tr>";
+     tg += "<tr><td>wms_title: </td><td>" + wms[cnt].wms_title + "</td></tr>";
+     tg += "<tr><td>wms_abstract:</td><td>" + wms[cnt].wms_abstract + "</td></tr>";
+     tg += "<tr><td>wms_getmap: </td><td>" + wms[cnt].wms_getmap + "</td></tr>";
+     tg += "<tr><td>wms_getfeatureinfo: </td><td>" + wms[cnt].wms_getfeatureinfo + "</td></tr>";
+     tg += "<tr><td>wms_getlegendurl: </td><td>" + wms[cnt].wms_getlegendurl + "</td></tr>";
+     tg += "<tr><td>gui_wms_mapformat: </td><td>" + wms[cnt].gui_wms_mapformat + "</td></tr>";
+     tg += "<tr><td>gui_wms_featureinfoformat: </td><td>" + wms[cnt].gui_wms_featureinfoformat + "</td></tr>";
+     tg += "<tr><td>gui_wms_exceptionformat: </td><td>" + wms[cnt].gui_wms_exceptionformat + "</td></tr>";
+     tg += "<tr><td>gui_wms_epsg: </td><td>" + wms[cnt].gui_wms_epsg + "</td></tr>";
+     tg += "<tr><td>gui_wms_visible: </td><td>" + wms[cnt].gui_wms_visible + "</td></tr>" ;
+  
+    tg += "<tr class='tr_head'><td>Data: </td><td>.</td></tr>";
+     for(var i=0; i<wms[cnt].data_type.length; i++){
+        tg += "<tr><td>" + wms[cnt].data_type[i] + "</td><td>" + wms[cnt].data_format[i] + "</td></tr>" ;
+     }
+     for(var i=0; i<wms[cnt].gui_epsg.length; i++){
+      tg += "<tr class='tr_head'><td>epsg : </td><td>" + wms[cnt].gui_epsg[i] + "</td></tr>" ;
+      tg += "<tr><td>minx : </td><td>" + wms[cnt].gui_minx[i] + "</td></tr>" ;
+      tg += "<tr><td>miny : </td><td>" + wms[cnt].gui_miny[i] + "</td></tr>" ;
+      tg += "<tr><td>maxx : </td><td>" + wms[cnt].gui_maxx[i] + "</td></tr>" ;
+      tg += "<tr><td>maxy : </td><td>" + wms[cnt].gui_maxy[i]+"</td></tr>" ;
+     }
+     
+     tg += "</table><br>";
+     
+     tg += "<table border='1' rules='rows'><tr class='tr_head'>";
+     tg += "<td>layer_id</td>";
+     tg += "<td>layer_pos</td>";
+     tg += "<td>layer_parent</td>";
+     tg += "<td>layer_name</td>";
+     tg += "<td>layer_title</td>";
+     tg += "<td>layer_dataurl</td>";
+     tg += "<td>layer_queryable</td>";
+     tg += "<td>layer_minscale</td>";
+     tg += "<td>layer_maxscale</td>";
+     tg += "<td>gui_layer_wms_id</td>";
+     tg += "<td>gui_layer_status</td>";
+     tg += "<td>gui_layer_selectable</td>";
+     tg += "<td>gui_layer_visible</td>";
+     tg += "<td>gui_layer_queryable</td>";
+     tg += "<td>gui_layer_querylayer</td>";
+     tg += "<td>gui_layer_minscale</td>";
+     tg += "<td>gui_layer_maxscale</td>";
+     tg += "</tr>";
+          
+     for(var i=0; i<wms[cnt].objLayer.length; i++){
+         tg += "<tr>";
+         tg += "<td>"+wms[cnt].objLayer[i].layer_id + "</td>";
+         tg += "<td>"+wms[cnt].objLayer[i].layer_pos + "</td>";
+         tg += "<td>"+wms[cnt].objLayer[i].layer_parent+"</td>";
+         tg += "<td>"+wms[cnt].objLayer[i].layer_name+"</td>";
+         tg += "<td>"+wms[cnt].objLayer[i].layer_title+"</td>";
+         tg += "<td>"+wms[cnt].objLayer[i].layer_dataurl_href+"</td>";
+         tg += "<td>"+wms[cnt].objLayer[i].layer_queryable+"</td>";
+         tg += "<td>"+wms[cnt].objLayer[i].layer_minscale+"</td>";
+         tg += "<td>"+wms[cnt].objLayer[i].layer_maxscale+"</td>";
+         tg += "<td>"+wms[cnt].objLayer[i].gui_layer_wms_id+"</td>";
+         tg += "<td>"+wms[cnt].objLayer[i].gui_layer_status+"</td>";
+         tg += "<td>"+wms[cnt].objLayer[i].gui_layer_selectable+"</td>";
+         tg += "<td>"+wms[cnt].objLayer[i].gui_layer_visible+"</td>";
+         tg += "<td>"+wms[cnt].objLayer[i].gui_layer_queryable+"</td>";
+         tg += "<td>"+wms[cnt].objLayer[i].gui_layer_querylayer+"</td>";
+         tg += "<td>"+wms[cnt].objLayer[i].gui_layer_minscale+"</td>";
+         tg += "<td>"+wms[cnt].objLayer[i].gui_layer_maxscale+"</td>";
+
+         tg += "</tr>";
+     }
+             tg += "</table><br><br>";
+   }
+
+     if(wfs){
+      tg += "<hr>";
+      
+       for(var cnt=0; cnt<wfs.length;cnt++){
+         tg += "<br><h4 style='font-color:blue'>WFS: "+ cnt+ ": "+wfs[cnt].wfs_title+" ("+wfs[cnt].wfs_abstract+") </h4>";
+         tg+="<table border='1' rules='rows'><tr>";
+    
+         tg += "<th class='th_wfs' width='200'>WFS nr: </th><th class='th_wfs'>" + cnt+ "</th></tr>";
+         tg += "<tr><td>wfs_id:</td><td> " + wfs[cnt].wfs_id + "</td></tr>";
+         tg += "<tr><td>wfs_version: </td><td>" + wfs[cnt].wfs_version + "</td></tr>";
+         tg += "<tr><td>wfs_title: </td><td>" + wfs[cnt].wfs_title + "</td></tr>";
+         tg += "<tr><td>wfs_abstract:</td><td>" + wfs[cnt].wfs_abstract + "</td></tr>";
+         tg += "<tr><td>wfs_getcapabilities: </td><td><a href='"+ wfs[cnt].wfs_getcapabilities + "&VERSION=1.0.0&request=getcapabilities' target='_blank'>" + wfs[cnt].wfs_getcapabilities + "</a></td></tr>";
+         tg += "<tr><td>wfs_describefeaturetype:</td><td>" + wfs[cnt].wfs_describefeaturetype +  "</td></tr>";
+
+         tg += "</table><br>";
+     
+  
+         tg += "<table border='1' rules='rows' ><tr class='tr_head'>";
+         tg += "<td width='200'>wfs_featuretype</td>";
+         tg += "<td>featuretype_name</td></tr>";
+         
+         for(var i=0; i<wfs[cnt].wfs_featuretype.length; i++){
+            tg += "<tr><td>"+i+"</td>";
+            tg += "<td>" + wfs[cnt].wfs_featuretype[i].featuretype_name + "</td>";
+            tg += "<tr>";
+         }
+         
+         tg += "</table><br>";
+       }
+
+     }
+     //
+     tg += "<BR></body>";
+     myWin = window.open("","myWin","");
+     myWin.document.open("text/html");
+     myWin.document.write(tg);
+     myWin.document.close();
+     myWin.focus();  
+}
\ No newline at end of file

Added: trunk/mapbender/http/javascripts/mod_insertMonitoredWmsIntoDb.php
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/javascripts/mod_insertMonitoredWmsIntoDb.php?view=auto&rev=146
==============================================================================
--- (empty file)
+++ trunk/mapbender/http/javascripts/mod_insertMonitoredWmsIntoDb.php	2006-04-25 15:22:51+0000
@@ -0,0 +1,75 @@
+<?php
+#$Id: mod_insertWmcIntoDb.php,v 1.19 2006/03/09 14:02:42 uli_rothstein Exp $
+#$Header: /cvsroot/mapbender/mapbender/http/javascripts/mod_insertWmcIntoDb.php,v 1.19 2006/03/09 14:02:42 uli_rothstein Exp $
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+include("../../conf/mapbender.conf");
+
+$gui_id = $_REQUEST["gui_id"];
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+
+<html>
+<head>
+<!-- 
+Licensing: See the GNU General Public License for more details.
+http://www.gnu.org/copyleft/gpl.html
+or:
+mapbender/licence/ 
+-->
+<meta http-equiv="cache-control" content="no-cache">
+<meta http-equiv="pragma" content="no-cache">
+<meta http-equiv="expires" content="0">
+<?php
+echo '<meta http-equiv="Content-Type" content="text/html; charset='.CHARSET.'">';	
+echo "<script type='text/javascript'>";
+include("../javascripts/mod_displayObj_extended.js");
+echo "</script>";
+?>
+<title>MB2 - <?php  echo  $_REQUEST["gui_id"];?></title>
+<?php
+
+$con = db_connect($DBSERVER,$OWNER,$PW);
+db_select_db(DB,$con);
+?>
+</head>
+<body>
+</body>
+</html>
+<?php
+if ($_POST["data"]) {
+	$d = explode("____", $_POST["data"]);	
+	
+//	$sql = "INSERT INTO wms_monitor VALUES ('" . $d[0] . "', '" . $d[1] . "', '" . time() . "', '" . time() . "')";
+	$sql = "INSERT INTO wms_monitor VALUES ('" . $d[0] . "', '" . $d[1] . "', '', '')";
+	
+	
+	$res = db_query($sql);
+	if (db_error()) {
+			 echo "<script>alert(\"fehler\");</script>";
+	}
+	else {
+			 echo "<script>alert(\"OK\");</script>";
+	}
+}
+function char_encode($s){
+		if(CHARSET == 'UTF-8'){
+			$s = utf8_encode($s);	
+		}
+		return $s;
+}
+?>
\ No newline at end of file

Added: trunk/mapbender/http/php/mod_monitorWMS.php
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/php/mod_monitorWMS.php?view=auto&rev=146
==============================================================================
--- (empty file)
+++ trunk/mapbender/http/php/mod_monitorWMS.php	2006-04-25 15:22:51+0000
@@ -0,0 +1,172 @@
+<?php
+# $Id: mod_monitorCapabilities.php 137 2006-04-24 00:30:51Z arnulf $
+# http://www.mapbender.org/index.php/Monitor_Capabilities
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# 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("../php/mb_validateSession.php");
+require_once("../../conf/mapbender.conf");
+import_request_variables("PG");
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<?php
+echo '<meta http-equiv="Content-Type" content="text/html; charset='.CHARSET.'">';	
+?>
+<title>Monitor WMS Capabilities</title>
+<link rel="stylesheet" type="text/css" href="../css/administration_alloc.css">
+</head>
+<body>
+<?php
+require_once("../classes/class_wms.php");
+require_once("../classes/class_administration.php");
+
+$con = db_connect($DBSERVER,$OWNER,$PW);
+db_select_db(DB,$con);
+
+$admin = new administration();
+$ownguis = $admin->getGuisByOwner($_SESSION["mb_user_id"]);
+$permguis = $admin->getGuisByPermission($_SESSION["mb_user_id"]);
+$wms_id_own = $admin->getWmsByOwnGuis($ownguis);
+
+$sql = "SELECT fkey_wms_id, wms_getmap FROM wms_monitor";
+$res = db_query($sql);	
+$wmsList = array();
+$i=0;
+while($row = db_fetch_array($res)){
+	$wmsList[$i] = array();
+	$wmsList[$i]["id"] = $row['fkey_wms_id'];
+	$wmsList[$i]["getmap"] = $row['wms_getmap'];
+	$i++; 
+}		
+
+
+//$someUrl = "http://www2.demis.nl/wms/wms.asp?wms=WorldMap&VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&LAYERS=Bathymetry,Countries,Topogghraphy,Hillshading,Builtup%20areas,Coastlines,Waterbodies,Inundated,Rivers,Streams,Railroads,Highways,Roads,Trails,Borders,Cities,Settlements,Spot%20elevations,Airports,Ocean%20features&STYLES=,,,,,,,,,,,,,,,,,,,&SRS=EPSG:4326&BBOX=-106.8888888888889,-80,80.8888888888889,89&WIDTH=500&HEIGHT=450&FORMAT=image/png&BGCOLOR=0xffffff&TRANSPARENT=TRUE";
+//$remoteXml = fetchUrlWithoutHanging($someUrl);
+//$remoteXml = implode("", file($someUrl));
+//echo $remoteXml;
+function microtime_float()
+{
+   list($usec, $sec) = explode(" ", microtime());
+   return ((float)$usec + (float)$sec);
+}
+
+function fetchUrlWithoutHanging($url){
+	// Set maximum number of seconds to wait for feed before displaying page without feed
+	$numberOfSeconds=20;
+	// Suppress error reporting so Web site visitors are unaware if the feed fails
+	error_reporting(0);
+	// Extract resource path and domain from URL ready for fsockopen
+	$url = str_replace("http://","",$url);
+	$urlComponents = explode("/",$url);
+	$domain = $urlComponents[0];
+	$resourcePath = str_replace($domain,"",$url);
+	$resourcePath = str_replace(" ", "%20", $resourcePath);
+	
+	// Establish a connection
+	$socketConnection = fsockopen($domain, 80, $errno, $errstr, $numberOfSeconds);
+	if (!$socketConnection) {
+		// You may wish to remove the following debugging line on a live Web site
+		print("<!-- Network error: $errstr ($errno) -->");
+		return false;
+	}	// end if
+	else {
+		$xml = '';
+ 	    fputs($socketConnection, "GET /$resourcePath HTTP/1.0\r\nHost: $domain\r\n\r\n");
+ 	    
+ 		// Loop until end of file
+		while (!feof($socketConnection)){
+			$xml .= fgets($socketConnection, 128);
+		}    // end while
+		fclose ($socketConnection);
+	} // end else
+	return($xml);
+} // end function
+
+//for ($k=0; $k<count($wms_id_own) && 0 == 1; $k++) {
+echo "Starting monitoring cycle...<br><br>";
+echo "WMS services are requested for availabiltiy. "; 
+echo "Capabilities documents are requested and all changes synchronized with the database cache.<br><br>";
+echo "<table cellspacing=10 cellpadding = 8 border = 1>";
+for ($k=0; $k<count($wmsList); $k++) {
+	$wmsId = $wmsList[$k]["id"];
+	$wmsGetmap = $wmsList[$k]["getmap"];
+	echo "<tr><td><b>Processing WMS</b> (ID = " . $wmsId . ")<br>";
+
+	$sql = "SELECT wms_title FROM wms WHERE wms_id = '" . $wmsId . "'";
+	$res = db_query($sql);
+	$someArray = db_fetch_row($res);
+	$wms_title = $someArray[0];
+
+	echo "WMS Title: <b><i>" . $wms_title . "</i></b><br/>";
+	echo "<a href='" . $wmsGetmap . "' target=_blank>getmap</a><br/><br />";
+	set_time_limit(30);
+
+	$wmsGetmap = eregi_replace("EXCEPTIONS=[^&]*","EXCEPTIONS=application/vnd.ogc.se_xml",$wmsGetmap);
+
+	$request_start = microtime_float();
+	$remoteXml = fetchUrlWithoutHanging($wmsGetmap);
+	$request_end = microtime_float();
+	$duration = $request_end - $request_start;  
+	$duration_str = "<br><span style=\"font-size:70%\">query time: " . round($duration,3) . " s</span>";
+
+	if ($remoteXml == false) {
+		echo "Connection failed." . $duration_str. "</td><td><img src ='../img/trafficlights/stop.bmp'></td></tr>";
+	}
+	else {
+		if (strpos($remoteXml, "Content-Type: image")) {
+			echo "Connection established, getmap query successful.".$duration_str."</td><td><img src ='../img/trafficlights/go.bmp'></td></tr>";
+		}
+		else {
+			echo "Connection established, getmap query failed.".$duration_str."</td><td><img src ='../img/trafficlights/wait.bmp'></td></tr>";
+		}
+	}
+	
+	#echo $remoteXml;
+		//print_r($localXmlArray);
+		//print_r($remoteXmlArray);			
+#		if (!$remoteXml) {
+#			$result = -1;
+//			echo "Can't connect to " . $myURL . "";
+#			echo "Connection failed.</td><td><img src ='../img/trafficlights/stop.bmp'></td></tr>";
+#		}
+#		elseif (!$localXml) {
+#			$result = 0;
+#		}
+#		else {
+#			if ($localXml == $remoteXml) {
+#				$result = 1;
+#				echo "WMS is stable.";
+#			}
+#			else {
+#				$result = 0;
+#			}
+#		}
+#		if ($result == 0) {
+#			echo "Updating WMS " . $wmsId . "...";
+#			$mywms = new wms();
+#			$mywms->createObjFromXML($myURL);    
+#			$mywms->optimizeWMS();
+#			$mywms->updateObjInDB($wmsId);
+#		}
+#	}
+}
+echo "</table>";
+echo "<br>Monitoring Cycle completed.";
+?>
+</body>
+</html>
\ No newline at end of file




More information about the Mapbender_commits mailing list