svn commit: r643 - trunk/mapbender/http/php

christoph at osgeo.org christoph at osgeo.org
Wed Jul 5 10:57:41 EDT 2006


Author: christoph
Date: 2006-07-05 14:57:40+0000
New Revision: 643

Added:
   trunk/mapbender/http/php/mod_monitorCapabilities_main.php
   trunk/mapbender/http/php/mod_monitorCapabilities_read.php
   trunk/mapbender/http/php/mod_monitorCapabilities_write.php

Log:
wms monitoring (documentation will follow soon)

Added: trunk/mapbender/http/php/mod_monitorCapabilities_main.php
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/php/mod_monitorCapabilities_main.php?view=auto&rev=643
==============================================================================
--- (empty file)
+++ trunk/mapbender/http/php/mod_monitorCapabilities_main.php	2006-07-05 14:57:40+0000
@@ -0,0 +1,41 @@
+<?php
+# $Id: mod_monitorCapabilities.php 371 2006-05-31 12:45:24Z christoph $
+# 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");
+//session_start();
+//import_request_variables("PG");
+require_once("../classes/class_administration.php");
+$con = db_connect($DBSERVER,$OWNER,$PW);
+db_select_db(DB,$con);
+$admin = new administration();
+$ownguis = $admin->getGuisByOwner(1);
+$wms_id_own = $admin->getWmsByOwnGuis($ownguis);
+
+set_time_limit(300);
+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>";
+$time = time();
+for ($k=0; $k<count($wms_id_own); $k++) {
+#	$exec = "php mod_monitorCapabilities_write.php ".$wms_id_own[$k]." ".$time." 0 1 > output_" . $wms_id_own[$k] . "_" . $time . ".txt &";
+	$exec = "php mod_monitorCapabilities_write.php ".$wms_id_own[$k]." ".$time." 0 1 > output.txt &";
+	exec($exec);
+}
+echo "Monitoring Cycle completed (total: " . count($wms_id_own) . " wms).";
+?>

Added: trunk/mapbender/http/php/mod_monitorCapabilities_read.php
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/php/mod_monitorCapabilities_read.php?view=auto&rev=643
==============================================================================
--- (empty file)
+++ trunk/mapbender/http/php/mod_monitorCapabilities_read.php	2006-07-05 14:57:40+0000
@@ -0,0 +1,97 @@
+<?php
+# $Id: mod_monitorCapabilities.php 371 2006-05-31 12:45:24Z christoph $
+# 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");
+require_once("../classes/class_administration.php");
+session_start();
+import_request_variables("PG");
+$con = db_connect($DBSERVER,$OWNER,$PW);
+db_select_db(DB,$con);
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+
+<html>
+<head>
+<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.'">';	
+?>
+</head>
+<body>
+<?php
+
+for ($i=0; $i < $_POST['cbs']; $i++) {
+	$upd_wmsid = $_POST['cb'.$i]; 
+	if ($upd_wmsid) {
+		$exec = "php mod_monitorCapabilities_write.php ".$upd_wmsid." ".$_POST['max_id']." 1 0 > output.txt &";
+		exec($exec);
+		echo "updating WMS " . $upd_wmsid . "...<br>";
+	}
+}
+
+$admin = new administration();
+
+$sql = "SELECT MAX(upload_id) FROM mb_monitor";
+$v = array();
+$t = array();
+$res = db_prep_query($sql,$v,$t);
+while(db_fetch_row($res)){
+	$max = db_result($res,$cnt,0);
+}
+
+$sql = "SELECT upload_id, fkey_wms_id, status, status_comment, mb_timestamp, upload_url, updated FROM mb_monitor WHERE upload_id = " . $max;
+$v = array();
+$t = array();
+$res = db_prep_query($sql,$v,$t);
+$cnt=0;
+while(db_fetch_row($res)){
+	$upload_id[$cnt] = db_result($res,$cnt,"upload_id");
+	$wms_id[$cnt] = db_result($res,$cnt,"fkey_wms_id");
+	$status[$cnt] = intval(db_result($res,$cnt,"status"));
+	$comment[$cnt] = db_result($res,$cnt,"status_comment");
+	$timestamp[$cnt] = db_result($res,$cnt,"mb_timestamp");
+	$upload_url[$cnt] = db_result($res,$cnt,"upload_url");
+	$updated[$cnt] = db_result($res,$cnt,"updated");
+	$cnt++;
+}	
+
+$str = "<br><b>last monitoring cycle results</b> (" . date("F j, Y, g:i a", $upload_id[0]) . ", " . count($upload_id). " wms)<br><br>\n";
+$str .= "<form name = 'form1' method='post' target='".$PHP_SELF."?".SID."'>\n\t";
+$str .= "<table cellpadding=5 border=1>";
+for ($k=0; $k<count($upload_id); $k++) {
+	$img = "stop.bmp";
+	if ($status[$k]==0) $img = "wait.bmp";
+	elseif ($status[$k]==1) $img = "go.bmp";
+
+	if ($updated[$k] == "0" && $status[$k] == 0) $fill = "checked"; else $fill = "disabled";
+
+	$str .= "\n\t\t<tr>";
+	$str .= "\n\t\t\t<td><input name='cb".$k."' value='" . $wms_id[$k] . "' type=checkbox ".$fill." /></td>";
+	$str .= "\n\t\t\t<td><b>" . $wms_id[$k] . "</b><br>" . $admin->getWmsTitleByWmsId($wms_id[$k]) . "</td>";
+	$str .= "\n\t\t\t<td><a href='".$upload_url[$k]."' target=_blank><img border=0 src = '../img/trafficlights/". $img. "'></a></td>";
+	$str .= "\n\t\t\t<td>" . $comment[$k] . "</td>";
+#	$str .= "\n\t\t\t<td><a href='output_".$wms_id[$k]."_".$max.".txt' target=_blank>log</a></td>";
+	$str .= "\n\t\t</tr>";
+}
+$str .= "\n\t</table>\n\t<br/>\n\t<input type=submit value='update selected WMS'>\n<input type=hidden name=cbs value='".count($upload_id)."'>\n<input type=hidden name=max_id value='".$max."'></form>";
+echo $str;
+?>
+</body></html>
\ No newline at end of file

Added: trunk/mapbender/http/php/mod_monitorCapabilities_write.php
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/php/mod_monitorCapabilities_write.php?view=auto&rev=643
==============================================================================
--- (empty file)
+++ trunk/mapbender/http/php/mod_monitorCapabilities_write.php	2006-07-05 14:57:40+0000
@@ -0,0 +1,154 @@
+<?php
+# $Id: mod_monitorCapabilities.php 371 2006-05-31 12:45:24Z christoph $
+# 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("../classes/class_wms.php");
+require_once("../../conf/mapbender.conf");
+session_start();
+import_request_variables("PG");
+
+$con = db_connect($DBSERVER,$OWNER,$PW);
+db_select_db(DB,$con);
+
+if ($_SERVER["argc"] != 5) {
+	echo "Insufficient arguments! Monitoring aborted.";
+	die();
+}
+
+$wmsId = $_SERVER["argv"][1];
+$upload_id = $_SERVER["argv"][2];
+$auto_update = intval($_SERVER["argv"][3]);
+$db_entry = intval($_SERVER["argv"][4]);
+
+
+// get the wms version, capabilities, capabilities_doc
+$sql = "SELECT wms_title, wms_version, wms_getcapabilities, wms_getcapabilities_doc ";
+$sql .= "FROM wms WHERE wms_id = $1";
+$v = array($wmsId);
+$t = array('i');
+$res = db_prep_query($sql,$v,$t);
+$someArray = db_fetch_row($res);
+
+$wms_title = $someArray[0];
+$version = $someArray[1];
+$capabilities = $someArray[2]; 	
+$capabilities_doc = $someArray[3];
+
+// construct capabilities URL
+if ($version == "1.0.0" ) {
+	$myURL = $capabilities . "REQUEST=capabilities&WMTVER=1.0.0";
+}
+else {
+	$myURL = $capabilities . "REQUEST=GetCapabilities&SERVICE=wms&VERSION=" . $version;	
+}
+
+$comment = "";
+$updated = "0";
+$result = -1;
+$now = time();
+
+set_time_limit(30);
+
+
+if ($version == "1.1.1" || $version == "1.1.0" ||$version == "1.0.0") {
+	if ($myURL) {
+
+		// compare the capabilities XML documents
+		$localXml = $capabilities_doc;
+
+		$x = new connector($myURL);
+		$z = new wms();
+		$remoteXml = $x->file;
+#		$remoteXml = $z->char_encode($x->file);
+
+		if (!$remoteXml) {
+			$result = -1;
+			$comment = "Connection failed.";
+		}
+		elseif (!$localXml) {
+			$result = 0;
+		}
+		else {
+			
+			if ($localXml == $remoteXml) {
+				$result = 1;
+				$comment = "WMS is stable.";
+			}
+			else {
+				$result = 0;
+			}
+		}
+		if ($result == 0) {
+			$mywms = new wms();
+			$ok = $mywms->createObjFromXML($myURL);
+			
+			if ($ok) {
+				if ($auto_update) {
+					$mywms->updateObjInDB($wmsId);
+					$updated = "1";
+					$comment = "WMS has been updated.";
+				}
+				else {
+					$comment = "WMS is not up to date.";
+				}
+			}
+			else {
+				$result = -1;
+				$comment = "Invalid getCapabilities request or service exception.";
+			}    
+		}
+	}
+	else {
+		$result = -1;
+		$comment = "Invalid upload URL.";
+	}
+}
+else {
+	$result = -1;
+	$comment = "Invalid WMS version (" .$version . ").";
+}
+
+echo "wmsid: " . $wmsId . "\nupload_id: " . $upload_id . "\n";
+echo "autoupdate: " . $auto_update . "\ndb_entry: " . $db_entry . "\n";
+echo "result: " . $result . "\ncomment: " . $comment . "\n";
+echo "timestamp: " . $now . " (".date("F j, Y, g:i a",$now).")\n";
+echo "getCapabilities URL: " . $myURL . "\nupdated: " . $updated . "\n\n";
+echo "-------------------------------------------------------------------\n";
+echo "remote XML:\n\n" . $remoteXml . "\n\n";
+echo "-------------------------------------------------------------------\n";
+echo "local XML:\n\n" . $localXml . "\n\n";
+echo "-------------------------------------------------------------------\n";
+
+if ($db_entry) {
+	$sql = "INSERT INTO mb_monitor (upload_id, fkey_wms_id, status, status_comment, mb_timestamp, upload_url, updated) ";
+	$sql .= "VALUES ($1, $2, $3, $4, $5, $6, $7)";
+	$v = array($upload_id,$wmsId,$result,$comment, $now,$myURL,$updated);
+	$t = array('s', 'i', 's', 's', 's', 's', 's');
+	$res = db_prep_query($sql,$v,$t);
+}
+else {
+	if ($auto_update && $updated == 1) {
+		$sql = "UPDATE mb_monitor SET updated = 1, status_comment = $1 WHERE upload_id = $2 AND fkey_wms_id = $3";
+		$v = array($comment, $upload_id,$wmsId);
+		$t = array('s', 's', 'i');
+		$res = db_prep_query($sql,$v,$t);
+	}
+}
+
+?>
\ No newline at end of file




More information about the Mapbender_commits mailing list