[Mapbender-commits] r1754 - in trunk/mapbender/http: classes php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Oct 26 10:15:56 EDT 2007
Author: christoph
Date: 2007-10-26 10:15:56 -0400 (Fri, 26 Oct 2007)
New Revision: 1754
Added:
trunk/mapbender/http/classes/class_monitor.php
Modified:
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:
checks if a wms that is reachable returns images or just error msgs
see http://trac.osgeo.org/mapbender/ticket/130
Added: trunk/mapbender/http/classes/class_monitor.php
===================================================================
--- trunk/mapbender/http/classes/class_monitor.php (rev 0)
+++ trunk/mapbender/http/classes/class_monitor.php 2007-10-26 14:15:56 UTC (rev 1754)
@@ -0,0 +1,478 @@
+<?php
+# $Id: class_layer_monitor.php 791 2007-08-10 10:36:04Z baudson $
+# http://www.mapbender.org/index.php/
+# 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(dirname(__FILE__)."/../classes/class_wms.php");
+require_once(dirname(__FILE__)."/../classes/class_bbox.php");
+require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+
+define("MONITOR_DEFAULT_SCALE", 500000);
+define("MONITOR_IMG_WIDTH", 20);
+define("MONITOR_IMG_HEIGHT", 20);
+define("MB_RESOLUTION", 28.35);
+
+class Monitor {
+ /**
+ * 1 = reachable and in sync with db
+ * 0 = reachable and out of sync with db
+ * -1 = unreachable
+ * -2 = monitoring in progress
+ *
+ */
+ var $result = -1;
+
+ /**
+ * 1 = the get map request DEFINITELY returns a valid map image
+ * 0 = the WMS doesn't support XML error format. Who knows if the image is really a map?
+ * -1 = the get map request doesn't return an image
+ */
+ var $returnsImage;
+
+ var $comment = "";
+ var $updated = "0";
+ var $supportsXMLException = false;
+
+ var $timestamp;
+ var $capabilitiesURL;
+ var $mapURL;
+
+ var $remoteXML;
+ var $localXML;
+
+ function __construct($wmsId, $uploadId, $autoUpdate) {
+ $this->wmsId = $wmsId;
+ $this->uploadId = $uploadId;
+ $this->autoUpdate = $autoUpdate;
+
+ $this->capabilitiesURL = $this->getUploadURL($this->wmsId, $this->uploadId);
+
+ set_time_limit(TIME_LIMIT);
+
+
+ $this->timestamp = time();
+
+ if ($this->capabilitiesURL) {
+
+ $remoteWms = new wms();
+ $remoteWms->createObjFromXML($this->capabilitiesURL);
+ $this->remoteXML = $remoteWms->wms_getcapabilities_doc;
+ $this->localXML = $this->getCapabilitiesDocByWMS($this->wmsId);
+
+ // service unreachable
+ if (!$this->remoteXML) {
+ $this->result = -1;
+ $this->comment = "Connection failed.";
+ }
+ /*
+ * service available;
+ * no local copy of capabilities file,
+ * so it has to be updated anyway
+ */
+ elseif (!$this->localXML) {
+ $this->result = 0;
+ }
+ /*
+ * service available;
+ * check if local copy is different
+ * to remote capabilties document
+ */
+ else {
+ /*
+ * compare to local capabilities document
+ */
+ // capabilities files match
+ if ($this->localXML == $this->remoteXML) {
+ $this->result = 1;
+ $this->comment = "WMS is stable.";
+ }
+ // capabilities files don't match
+ else {
+ $this->result = 0;
+ }
+ }
+ /*
+ * if the WMS is available,
+ * 1) get a map image
+ * 2) update the local backup of the capabilities doc if necessary
+ */
+ if ($this->result != -1) {
+
+ $this->mapURL = $this->getMapRequest($this->wmsId);
+
+ if ($this->isImage($this->mapURL)) {
+ $this->returnsImage = 1;
+ }
+ else {
+ $this->returnsImage = -1;
+ }
+
+ /*
+ * if the local backup of the capabilities document
+ * is deprecated, update the local backup
+ */
+ if ($this->result == 0) {
+ $mywms = new wms();
+
+ /*
+ * if the capabilities document is valid,
+ * update it OR mark it as "not up to date"
+ */
+ if ($mywms->createObjFromXML($this->capabilitiesURL)) {
+ if ($this->autoUpdate) {
+ $mywms->updateObjInDB($this->wmsId);
+ $this->updated = "1";
+ $this->comment = "WMS has been updated.";
+ }
+ else {
+ $this->comment = "WMS is not up to date.";
+ }
+ }
+ // capabilities document is invalid
+ else {
+ $this->result = -1;
+ $this->comment = "Invalid getCapabilities request/document or service exception.";
+ }
+ }
+ }
+ }
+ else {
+ $this->result = -1;
+ $this->comment = "Invalid upload URL.";
+ }
+ $e = new mb_notice("class_monitor: constructor: result = " . $this->result);
+ $e = new mb_notice("class_monitor: constructor: comment = " . $this->comment);
+ $e = new mb_notice("class_monitor: constructor: returnsImage = " . $this->returnsImage);
+ }
+
+ /**
+ *
+ */
+ public function __toString() {
+ $str = "";
+ $str .= "wmsid: " . $this->wmsId . "\nupload_id: " . $this->uploadId . "\n";
+ $str .= "autoupdate: " . $this->autoUpdate . "\n";
+ $str .= "result: " . $this->result . "\ncomment: " . $this->comment . "\n";
+ $str .= "timestamp: " . $this->timestamp . " (".date("F j, Y, G:i:s", $this->timestamp).")\n";
+ $str .= "getCapabilities URL: " . $this->capabilitiesURL . "\nupdated: " . $this->updated . "\n\n";
+ $str .= "getMap URL: " . $this->mapURL . "\nis image: " . $this->returnsImage . "\n\n";
+ $str .= "-------------------------------------------------------------------\n";
+ $str .= "remote XML:\n\n" . $this->remoteXML . "\n\n";
+ $str .= "-------------------------------------------------------------------\n";
+ $str .= "local XML:\n\n" . $this->localXML . "\n\n";
+ $str .= "-------------------------------------------------------------------\n";
+ return (string) $str;
+ }
+
+ /**
+ * Update database
+ */
+ function updateInDB() {
+ $sql = "UPDATE mb_monitor SET updated = $1, status = $2, image = $3, status_comment = $4, upload_url = $5, timestamp_end = $6, map_url = $7 WHERE upload_id = $8 AND fkey_wms_id = $9";
+ $v = array($this->updated, $this->result, $this->returnsImage, $this->comment, $this->capabilitiesURL, $this->timestamp, $this->mapURL, $this->uploadId, $this->wmsId);
+ $t = array('s', 'i', 'i', 's', 's', 's', 's', 's', 'i');
+ $res = db_prep_query($sql,$v,$t);
+ }
+
+ /*
+ * Checks if the mapUrl returns an image or an exception
+ */
+ private function isImage($url) {
+ $headers = get_headers($url, 1);
+ $e = new mb_notice("class_monitor: isImage: map URL is " . $url);
+ $e = new mb_notice("class_monitor: isImage: Content-Type is " . $headers["Content-Type"]);
+ if (preg_match("/xml/", $headers["Content-Type"])) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Returns the upload url of some WMS
+ */
+ private function getUploadURL($wmsId, $upload_id) {
+ $e = new mb_notice("class_monitor: getUploadURL: wms = " . $wmsId);
+ $e = new mb_notice("class_monitor: getUploadURL: upload_id = " . $upload_id);
+ $sql = "SELECT upload_url FROM mb_monitor WHERE fkey_wms_id = $1 AND upload_id = $2";
+ $v = array($wmsId, $upload_id);
+ $t = array('i', 'i');
+ $res = db_prep_query($sql,$v,$t);
+ $someArray = db_fetch_array($res);
+ $e = new mb_notice("class_monitor: getUploadURL: url = " . $someArray["upload_url"]);
+ return $someArray["upload_url"];
+ }
+
+ /**
+ * Returns the character that needs to be appended to
+ * a given online resource, in order to append other GET
+ * parameters.
+ *
+ * Possible characters: "?", "&", ""
+ */
+ private function mb_getConjunctionCharacter($onlineresource){
+ // index of character ? in online resource
+ $indexOfChar = mb_strpos($onlineresource,"?");
+
+ if($indexOfChar) {
+ // no conjunction character needed
+ if($indexOfChar == mb_strlen($onlineresource)-1){
+ return "";
+ }
+ // no conjunction character needed
+ else if (mb_substr($onlineresource, mb_strlen($onlineresource)-1) == "&") {
+ return "";
+ }
+ else{
+ return "&";
+ }
+ }
+ return "?";
+ }
+
+ /**
+ * retrieves all information necessary to build a map request,
+ * concatenates them and returns a valid get map request
+ */
+ private function getMapRequest($wmsId) {
+
+ // get map (wms_getmap)
+ // version (wms_version)
+ $sql = "SELECT wms_getmap, wms_version FROM wms WHERE wms_id = $1";
+ $res = db_prep_query($sql, array($wmsId), array('i'));
+ $row = db_fetch_array($res);
+ $getmap = $row["wms_getmap"];
+ $version = $row["wms_version"];
+
+ //map format
+ $sql = "SELECT * FROM wms_format WHERE data_type = 'map' AND fkey_wms_id = $1";
+ $res = db_prep_query($sql, array($wmsId), array('i'));
+ $row = db_fetch_array($res);
+ $mapFormat = "";
+ while ($row = db_fetch_array($res)) {
+ $mapFormat = urlencode($row["data_format"]);
+ if (preg_match("/png/", $mapFormat) || preg_match("/gif/", $mapFormat) || preg_match("/jp.{1}g/", $mapFormat)) {
+ break;
+ }
+ }
+
+ // layers (all layers)
+ $sql = "SELECT layer_name FROM layer WHERE fkey_wms_id = $1 AND layer_parent <> '' AND layer_pos > 0";
+ $res = db_prep_query($sql, array($wmsId), array('i'));
+ $layerArray = array();
+ while ($row = db_fetch_array($res)) {
+ array_push($layerArray, urlencode($row["layer_name"]));
+ }
+ $layerList = implode(",", $layerArray);
+
+ // srs (layer_epsg: epsg)
+ // bbox (layer_epsg: minx, miny, maxx, maxy)
+ $sql = "SELECT epsg, minx, miny, maxx, maxy ";
+ $sql .= "FROM layer_epsg, (SELECT fkey_wms_id, layer_id FROM layer WHERE fkey_wms_id = $1 AND layer_parent = '' AND layer_pos = 0) AS l ";
+ $sql .= "WHERE l.layer_id = layer_epsg.fkey_layer_id AND l.fkey_wms_id = $1";
+ $res = db_prep_query($sql, array($wmsId), array('i'));
+ $bboxArray = array();
+ while ($row = db_fetch_array($res)) {
+ array_push($bboxArray, new Mapbender_bbox($row["minx"], $row["miny"], $row["maxx"], $row["maxy"], $row["epsg"]));
+ }
+
+ // get a bbox in a preferably non WGS84 epsg to use the scalehints
+ for ($i=0; $i < count($bboxArray); $i++) {
+ $bbox = $bboxArray[$i];
+ if ($bboxArray[$i]->epsg != "EPSG:4326") {
+ break;
+ }
+ }
+
+ /*
+ * transform to 31466 if is 4326
+ * TODO: extend to other EPSG apart from 31466
+ */
+ if ($bbox->epsg == "EPSG:4326") {
+ $bbox->transform("EPSG:31466");
+ }
+
+ /*
+ * get map and check if result is image
+ */
+ // check if this WMS supports exception type XML
+ $sql = "SELECT data_format FROM wms_format WHERE fkey_wms_id = $1 AND data_type = 'exception'";
+ $v = array($wmsId);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ while ($row = db_fetch_array($res)) {
+ $exceptionFormat = $row["data_format"];
+ // set the exception type to xml (if possible)
+ if (preg_match('/xml/', $exceptionFormat)) {
+ $this->supportsXMLException = true;
+ break;
+ }
+ }
+
+ // correct bbox according to scale
+ $scale = $this->getScaleForWMS($wmsId);
+ $bbox = $this->getBBoxInScale($bbox, $scale);
+
+ return $this->concatenateMapRequest($getmap, $version, $mapFormat, $layerList, $bbox, MONITOR_IMG_WIDTH, MONITOR_IMG_HEIGHT, $exceptionFormat);
+ }
+
+ /**
+ * updates a given BBox according to a given scale
+ *
+ * @param bbox
+ * @param scale
+ */
+ private function getBBoxInScale($bbox, $scale) {
+ $e = new mb_notice("class_monitor: getMapRequest: old bbox = " . $bbox);
+ $e = new mb_notice("class_monitor: getMapRequest: old bbox = " . $bbox->min->x . "," . $bbox->min->y . "," . $bbox->max->x . "," . $bbox->max->y);
+ $e = new mb_notice("class_monitor: getMapRequest: scale = " . $scale);
+ if ($scale) {
+ $center = $bbox->min->plus($bbox->max)->times(0.5);
+ $e = new mb_notice("class_monitor: getMapRequest: center = " . $center);
+
+ /*
+ * TODO: this formula should have documentation
+ */
+ $offset = MONITOR_IMG_WIDTH / (MB_RESOLUTION * 100 * 2) * $scale;
+ $offsetPoint = new Mapbender_point($offset, $offset, $bbox->epsg);
+ $min = $center->minus($offsetPoint);
+ $max = $center->plus($offsetPoint);
+ $bbox->min = $min;
+ $bbox->max = $max;
+ $e = new mb_notice("class_monitor: getMapRequest: new bbox = " . $bbox);
+ $e = new mb_notice("class_monitor: getMapRequest: new bbox = " . $bbox->min->x . "," . $bbox->min->y . "," . $bbox->max->x . "," . $bbox->max->y);
+ }
+ return $bbox;
+ }
+
+
+ /**
+ * Returns an online resource representing a get map request
+ */
+ private function concatenateMapRequest( $getmap, $wmsVersion, $mapFormat, $layerList,
+ $bbox, $width, $height, $exceptionFormat) {
+ /*
+ * getMap URL
+ */
+ $mapRequest = $getmap;
+ $mapRequest .= $this->mb_getConjunctionCharacter($getmap);
+
+ /*
+ * WMS version
+ */
+ if ($wmsVersion == "1.0.0") {
+ $mapRequest .= "WMTVER=" . $wmsVersion . "&REQUEST=map&";
+ }
+ else {
+ $mapRequest .= "VERSION=" . $wmsVersion . "&REQUEST=GetMap&SERVICE=WMS&";
+ }
+
+ /*
+ * Layer list
+ */
+ $mapRequest .= "LAYERS=" . $layerList . "&";
+
+ /*
+ * Format
+ */
+ $mapRequest .= "FORMAT=" . $mapFormat . "&";
+
+ /*
+ * SRS and BBox
+ */
+ $mapRequest .= "SRS=" . $bbox->epsg . "&";
+ $mapRequest .= "BBOX=" . $bbox->min->x . "," . $bbox->min->y . "," . $bbox->max->x . "," . $bbox->max->y . "&";
+
+ /*
+ * Width and height
+ */
+ $mapRequest .= "WIDTH=" . $width . "&";
+ $mapRequest .= "HEIGHT=" . $height . "&";
+
+ /*
+ * BGColor
+ */
+ $mapRequest .= "BGCOLOR=0xffffff&";
+
+ /*
+ * Transparency
+ */
+ if (preg_match("/png/", $mapFormat) || preg_match("/gif/", $mapFormat)) {
+ $mapRequest .= "TRANSPARENT=TRUE&";
+ }
+
+ /*
+ * Exception format
+ */
+ $mapRequest .= "EXCEPTIONS=" . $exceptionFormat . "&";
+
+// return urlencode($mapRequest);
+ return $mapRequest;
+ }
+
+ /**
+ * Checks if the given WMS has ScaleHints. If yes, a scale is selected and returned.
+ */
+ private function getScaleForWMS($wmsId) {
+ // get the scalehints
+ $sql = "SELECT layer_minscale, layer_maxscale FROM layer WHERE fkey_wms_id = $1 AND layer_pos = 0 AND layer_parent = '' AND layer_minscale <> layer_maxscale LIMIT 1";
+ $v = array($wmsId);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ $scaleHintArray = db_fetch_array($res);
+
+ /*
+ * determine the scalehint
+ */
+ // if a scalehint exists
+ if ($scaleHintArray) {
+ // if upper boundary
+ if ($scaleHintArray["layer_minscale"] < $scaleHintArray["layer_maxscale"]) {
+ // TODO: find a better algorithm with a less obscure scale
+ $scaleHint = round($scaleHintArray["layer_maxscale"] - $scaleHintArray["layer_minscale"]) / 2;
+ }
+ // if lower boundary
+ else {
+ if ($scaleHintArray["layer_minscale"] < MONITOR_DEFAULT_SCALE) {
+ $scaleHint = MONITOR_DEFAULT_SCALE;
+ }
+ else {
+ // TODO: find a better algorithm with a less obscure scale
+ $scaleHint = $scaleHintArray["layer_minscale"] + 1000;
+ }
+ }
+ }
+ // otherwise, use a default value
+ else {
+ $scaleHint = MONITOR_DEFAULT_SCALE;
+ }
+ return $scaleHint;
+ }
+
+ /**
+ * Returns the local backup of the given WMS' capabilities document
+ */
+ private function getCapabilitiesDocByWMS($wmsId) {
+ $sql = "SELECT wms_getcapabilities_doc FROM wms WHERE wms_id = $1";
+ $v = array($wmsId);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ $someArray = db_fetch_array($res);
+ return $someArray["wms_getcapabilities_doc"];
+ }
+
+}
+?>
\ No newline at end of file
Modified: trunk/mapbender/http/php/mod_monitorCapabilities_main.php
===================================================================
--- trunk/mapbender/http/php/mod_monitorCapabilities_main.php 2007-10-26 13:59:20 UTC (rev 1753)
+++ trunk/mapbender/http/php/mod_monitorCapabilities_main.php 2007-10-26 14:15:56 UTC (rev 1754)
@@ -1,5 +1,5 @@
<?php
-# $Id: mod_monitorCapabilities.php 371 2006-05-31 12:45:24Z christoph $
+# $Id: mod_monitorCapabilities_main.php 1240 2007-10-24 09:27:00Z baudson $
# http://www.mapbender.org/index.php/Monitor_Capabilities
# Copyright (C) 2002 CCGIS
#
@@ -32,8 +32,8 @@
function getConjunctionCharacter($onlineresource){
- if(mb_strpos($onlineresource, "?")) {
- $lastChar = mb_substr($onlineresource,mb_strlen($onlineresource)-1, 1);
+ if(strstr($onlineresource, "?")) {
+ $lastChar = substr($onlineresource,strlen($onlineresource)-1, 1);
if ($lastChar == "?" || $lastChar == "&") {return "";}
else{return "&";}
}
@@ -53,10 +53,10 @@
//command line
$p1 = $_SERVER["argv"][1];
$p2 = $_SERVER["argv"][2];
- if (mb_substr($p1, 0,5) == "user:") {
- $user = mb_substr($p1, 5);
- if (mb_substr($p2, 0,4) == "gui:") {
- $gui = mb_substr($p2, 4);
+ if (substr($p1, 0,5) == "user:") {
+ $user = substr($p1, 5);
+ if (substr($p2, 0,4) == "gui:") {
+ $gui = substr($p2, 4);
}
}
}
@@ -66,24 +66,39 @@
$userid = $admin->getUserIdByUserName($user);
+/*
+ * if the current user is a valid user...
+ */
if ($userid) {
$ownguis = $admin->getGuisByOwner($userid,true);
+ /*
+ * if monitoring is restricted to a single GUI...
+ */
if ($gui) {
+ // ... abort if the GUI doesn't exist
if (!$admin->guiExists($gui)) {
echo "GUI " . $gui . " doesn't exist.\n"; die();
}
+ // ... add the GUI to the array of GUIs that will be monitored
elseif (in_array($gui, $ownguis)) {
$ownguis = array($gui);
}
+ // ... abort if the GUI is not owned by the current user
else {
echo "User " . $user . " is not owner of GUI " . $gui . ".\n"; die();
}
}
}
+/*
+ * if current user is not a valid user, abort
+ */
else {
echo $user . " is not a valid username.\n"; die();
}
+/**
+ * Array of WMS IDs. These are the WMS that the user owns.
+ */
$wms_id_own = $admin->getWmsByOwnGuis($ownguis);
// initialise monitoring processes
@@ -131,10 +146,10 @@
for ($k=0; $k<count($wms_id_own); $k++) {
if (intval(AUTO_UPDATE)) {
- $exec = PHP_PATH . "php mod_monitorCapabilities_write.php ".$wms_id_own[$k]." ".$time." 1 > ../tmp/output_".$time."_".$wms_id_own[$k].".txt &";
+ $exec = PHP_PATH . "php5 mod_monitorCapabilities_write.php ".$wms_id_own[$k]." ".$time." 1 > ../tmp/output_".$time."_".$wms_id_own[$k].".txt &";
}
else {
- $exec = PHP_PATH . "php mod_monitorCapabilities_write.php ".$wms_id_own[$k]." ".$time." 0 > ../tmp/output_".$time."_".$wms_id_own[$k].".txt &";
+ $exec = PHP_PATH . "php5 mod_monitorCapabilities_write.php ".$wms_id_own[$k]." ".$time." 0 > ../tmp/output_".$time."_".$wms_id_own[$k].".txt &";
}
exec($exec);
}
@@ -169,7 +184,7 @@
if ($status[$i] == -2 && intval(time())-intval($timestamp_begin[$i]) > intval(TIME_LIMIT)) {
$comment[$i] = "Monitoring process timed out.";
$status[$i] = -1;
- $new_sql = "UPDATE mb_monitor SET status = '-1', status_comment = 'Monitoring process timed out.', timestamp_end = $1 WHERE fkey_wms_id = $2 AND upload_id = $3";
+ $new_sql = "UPDATE mb_monitor SET status = '-1', isImage = '-1', status_comment = 'Monitoring process timed out.', timestamp_end = $1 WHERE fkey_wms_id = $2 AND upload_id = $3";
$new_v = array((intval($upload_id[$i])+intval(TIME_LIMIT)), $wms_id[$i], $time);
$new_t = array('s', 'i', 's');
$new_res = db_prep_query($new_sql,$new_v,$new_t);
@@ -186,7 +201,7 @@
if ($body) {
$error_msg = "";
if ($admin->getEmailByUserId($userid)) {
- $admin->sendEmail(MAILADMIN, MAILADMINNAME, $admin->getEmailByUserId($userid), $user, "WMS monitor report " . date("F j, Y, G:i:s", $time), utf8_decode($body), &$error_msg);
+// $admin->sendEmail(MAILADMIN, MAILADMINNAME, $admin->getEmailByUserId($userid), $user, "WMS monitor report " . date("F j, Y, G:i:s", $time), utf8_decode($body), &$error_msg);
}
else {
$error_msg = "Email address of user '" . $admin->getUserNameByUserId($userid) . "' unknown!\n";
Modified: trunk/mapbender/http/php/mod_monitorCapabilities_read.php
===================================================================
--- trunk/mapbender/http/php/mod_monitorCapabilities_read.php 2007-10-26 13:59:20 UTC (rev 1753)
+++ trunk/mapbender/http/php/mod_monitorCapabilities_read.php 2007-10-26 14:15:56 UTC (rev 1754)
@@ -1,6 +1,6 @@
<?php
-# $Id: mod_monitorCapabilities_read.php 76 2006-08-15 12:25:34Z heuser $
+# $Id: mod_monitorCapabilities_read.php 1283 2007-10-25 15:20:25Z baudson $
# http://www.mapbender.org/index.php/Monitor_Capabilities
# Copyright (C) 2002 CCGIS
#
@@ -87,7 +87,7 @@
$avg_response_time[$wms[$i]] = round(db_result($res,0,1)-db_result($res,0,0), 1);
}
- $sql = "SELECT status, status_comment, timestamp_begin, timestamp_end, upload_url, updated FROM mb_monitor ";
+ $sql = "SELECT status, status_comment, timestamp_begin, timestamp_end, upload_url, updated, image, map_url FROM mb_monitor ";
$sql .= "WHERE upload_id = $1 AND fkey_wms_id = $2 ORDER BY status, status_comment, timestamp_end, fkey_wms_id";
$v = array($upload_id[$wms[$i]], $wms_id[$wms[$i]]);
$t = array('s', 'i');
@@ -99,6 +99,8 @@
$timestamp_end[$wms[$i]] = db_result($res,0,"timestamp_end");
$upload_url[$wms[$i]] = db_result($res,0,"upload_url");
$updated[$wms[$i]] = db_result($res,0,"updated");
+ $mapurl[$wms[$i]] = db_result($res,0,"map_url");
+ $image[$wms[$i]] = db_result($res,0,"image");
if ($status[$wms[$i]] == -2 && intval(time())-intval($timestamp_begin[$wms[$i]]) > intval(TIME_LIMIT)) {
$comment[$wms[$i]] = "Monitoring process timed out.";
@@ -147,6 +149,10 @@
$newArray = $upload_id;
arsort($newArray);
}
+ elseif ($_GET['image'] == "last") {
+ $newArray = $image;
+ arsort($newArray);
+ }
}
@@ -158,6 +164,7 @@
$str .= "<table cellpadding=10 cellspacing=0 border=0>";
$str .= "<tr bgcolor='#dddddd'><th></th><th align='left'><a href='".$PHP_SELF."?sortby=wms'>wms</a></th>";
$str .= "<th align='left' colspan = 2><a href='".$PHP_SELF."?sortby=status'>current status</a></th>";
+$str .= "<th align='left'><a href='".$PHP_SELF."?sortby=image'>image</a></th>";
$str .= "<th align='left'><a href='".$PHP_SELF."?sortby=avgresp'>avg. response time</a></th>";
$str .= "<th align='left'><a href='".$PHP_SELF."?sortby=avail'>overall availability</a></th><th></th></tr>";
@@ -179,6 +186,27 @@
$str .= "\n\t\t\t<td valign='top'><b>" . $wms_id[$k] . "</b><br>" . $admin->getWmsTitleByWmsId($wms_id[$k]) . "</td>";
$str .= "\n\t\t\t<td valign='top'><a href='".$upload_url[$k]."' target=_blank><img title='Connect to service' border=0 src = '../img/trafficlights/". $img. "'></a></td>";
$str .= "\n\t\t\t<td valign='top'>" . $comment[$k] . "<br><div style='font-size:12'>".date("F j, Y, G:i:s", $upload_id[$k])."</div></td>";
+ $str .= "\n\t\t\t<td valign='top'>";
+
+ $str .= "<table bgcolor='black' border=1 cellspacing=1 cellpadding=0><tr><td height=20 width=20 align=center valign=middle bgcolor='";
+
+ if ($image[$k] == -1) {
+ $str .= "red";
+ }
+ elseif ($image[$k] == 0) {
+ $str .= "yellow";
+ }
+ elseif ($image[$k] == 1) {
+ $str .= "green";
+ }
+
+ if ($image[$k] != -1) {
+ $str .= "'><a href='".$mapurl[$k]."'>o</a></td></tr></table></td>";
+ }
+ else {
+ $str .= "'><a href='".$mapurl[$k]."'>x</a></td></tr></table></td>";
+ }
+
$str .= "\n\t\t\t<td valign='top' align = 'left'>";
if ($avg_response_time[$k] == NULL) {
$str .= "n/a";
Modified: trunk/mapbender/http/php/mod_monitorCapabilities_write.php
===================================================================
--- trunk/mapbender/http/php/mod_monitorCapabilities_write.php 2007-10-26 13:59:20 UTC (rev 1753)
+++ trunk/mapbender/http/php/mod_monitorCapabilities_write.php 2007-10-26 14:15:56 UTC (rev 1754)
@@ -1,5 +1,5 @@
<?php
-# $Id: mod_monitorCapabilities_write.php 76 2006-08-15 12:25:34Z heuser $
+# $Id: mod_monitorCapabilities_write.php 1235 2007-10-23 15:42:55Z baudson $
# http://www.mapbender.org/index.php/Monitor_Capabilities
# Copyright (C) 2002 CCGIS
#
@@ -16,113 +16,26 @@
# 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(dirname(__FILE__)."/../php/mb_validateSession.php");
-require_once(dirname(__FILE__)."/../classes/class_wms.php");
-require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
session_start();
-import_request_variables("PG");
-$con = db_connect($DBSERVER,$OWNER,$PW);
-db_select_db(DB,$con);
+require_once(dirname(__FILE__)."/../classes/class_monitor.php");
+/*
+ * incoming parameters from command line
+ */
if ($_SERVER["argc"] != 4) {
echo "Insufficient arguments! Monitoring aborted.";
die();
}
$wmsId = $_SERVER["argv"][1];
-$upload_id = $_SERVER["argv"][2];
-$auto_update = intval($_SERVER["argv"][3]);
+$uploadId = $_SERVER["argv"][2];
+$autoUpdate = intval($_SERVER["argv"][3]);
-// get the uploadURL
-$sql = "SELECT upload_url FROM mb_monitor WHERE fkey_wms_id = $1 AND upload_id = $2";
-$v = array($wmsId, $upload_id);
-$t = array('i', 's');
-$res = db_prep_query($sql,$v,$t);
-$someArray = db_fetch_row($res);
-$myURL = $someArray[0];
+$monitor = new Monitor($wmsId, $uploadId, $autoUpdate);
-// get the capabilities doc
-$sql = "SELECT wms_getcapabilities_doc FROM wms WHERE wms_id = $1";
-$v = array($wmsId);
-$t = array('i');
-$res = db_prep_query($sql,$v,$t);
-$someArray = db_fetch_row($res);
-$capabilities_doc = $someArray[0];
+echo $monitor;
-$comment = "";
-$updated = "0";
-$result = -1;
-
-set_time_limit(TIME_LIMIT);
-
-if ($myURL) {
-
- $remoteWms = new wms();
- $remoteWms->createObjFromXML($myURL);
- $now = time();
- $remoteXml = $remoteWms->wms_getcapabilities_doc;
-
- // compare the capabilities XML documents
- $localXml = $capabilities_doc;
-
- 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();
-
- if ($mywms->createObjFromXML($myURL)) {
- 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/document or service exception.";
- }
- }
-}
-else {
- $result = -1;
- $comment = "Invalid upload URL.";
- $now = time();
-}
-
-echo "wmsid: " . $wmsId . "\nupload_id: " . $upload_id . "\n";
-echo "autoupdate: " . $auto_update . "\n";
-echo "result: " . $result . "\ncomment: " . $comment . "\n";
-echo "timestamp: " . $now . " (".date("F j, Y, G:i:s",$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";
-
-
-$sql = "UPDATE mb_monitor SET updated = $1, status = $2, status_comment = $3, upload_url = $4, timestamp_end = $5 WHERE upload_id = $6 AND fkey_wms_id = $7";
-$v = array($updated, $result, $comment, $myURL, $now, $upload_id, $wmsId);
-$t = array('s', 's', 's', 's', 's', 's', 'i');
-$res = db_prep_query($sql,$v,$t);
+$monitor->updateInDB();
?>
\ No newline at end of file
More information about the Mapbender_commits
mailing list