[Mapbender-commits] r9894 - trunk/mapbender/http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Apr 12 08:20:26 PDT 2018


Author: armin11
Date: 2018-04-12 08:20:26 -0700 (Thu, 12 Apr 2018)
New Revision: 9894

Modified:
   trunk/mapbender/http/php/mod_monitorCapabilities_read.php
   trunk/mapbender/http/php/mod_monitorCapabilities_read_single.php
   trunk/mapbender/http/php/mod_showCapDiff.php
Log:
New option to show wfs monitoring results

Modified: trunk/mapbender/http/php/mod_monitorCapabilities_read.php
===================================================================
--- trunk/mapbender/http/php/mod_monitorCapabilities_read.php	2018-04-12 14:16:50 UTC (rev 9893)
+++ trunk/mapbender/http/php/mod_monitorCapabilities_read.php	2018-04-12 15:20:26 UTC (rev 9894)
@@ -16,11 +16,21 @@
 # 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.
-
+$serviceType = "WMS";
 $e_id = "monitor_results";
 $gui_id = $_REQUEST["guiID"];
-$serviceType = $_REQUEST["serviceType"];
-
+//validate parameters
+if (isset($_REQUEST["serviceType"]) & $_REQUEST["serviceType"] != "") {
+	$testMatch = $_REQUEST["serviceType"];	
+ 	if (!($testMatch == 'wms' or $testMatch == 'wfs')){ 
+		//echo 'outputFormat: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		echo 'Parameter <b>serviceType</b> is not valid (wms, wfs).<br/>'; 
+		die(); 		
+ 	}
+	$serviceType = $testMatch;
+	$testMatch = NULL;
+}
+$serviceType= strtoupper($serviceType);
 //TODO: Check wether request parameters cannot be found! Since this is not handled, update will not be available!
 require_once(dirname(__FILE__)."/../php/mb_validatePermission.php");
 require_once(dirname(__FILE__)."/../classes/class_wms.php");
@@ -39,8 +49,6 @@
 <?php
 $admin = new administration();
 $user = new User();
-
-
 switch ($serviceType) {
 	case "WMS":
 		$checkboxes = intval($_POST['cbs']);
@@ -108,43 +116,130 @@
 		}
 		break;
 	case "WFS":
+		$checkboxes = intval($_POST['cbs']);
+		for ($i=0; $i < $checkboxes; $i++) {
+			echo $i;
+			if (!isset($_POST['cb'.$i]) || 
+				!isset($_POST['upl_id'.$i])
+			) {
+				continue;
+			}	
+			$upd_wfsid = intval($_POST['cb'.$i]);
+			$upload_id = intval($_POST['upl_id'.$i]);
+			if ($upd_wfsid) {
+				// get upload URL
+				$sql = "SELECT wfs_upload_url, wfs_owner FROM wfs WHERE wfs_id = $1";
+				$v = array($upd_wfsid);
+				$t = array("i");
+				$res = db_prep_query($sql, $v, $t);
+				$row = db_fetch_array($res);
+				$uploadUrl = $row["wfs_upload_url"];
+				$wfsOwner = $row["wfs_owner"];
+				if ($wfsOwner !== $user->id) {
+					echo "<br>Skipped: " . $upd_wfsid . "<br>";
+					continue;
+				}
+				$id = $upd_wfsid;
+				$url = $uploadUrl;
+				//get authentication information from db
+				$sql = "SELECT wfs_auth_type, wfs_username, wfs_password from wfs WHERE wfs_id = $1 ";
+				$v = array($id);
+				$t = array('i');
+				$res = db_prep_query($sql,$v,$t);
+				$row = db_fetch_assoc($res);
+				$auth['auth_type'] = $row["wfs_auth_type"];
+				$auth['username'] = $row["wfs_username"];
+				$auth['password'] = $row["wfs_password"];
+				$wfsFactory = new UniversalWfsFactory();
+				if ($auth['auth_type'] =='') {
+					$auth = false;
+				}
+				$myWfs = $wfsFactory->createFromUrl($url, $auth);
+				//if (!MD_OVERWRITE) {
+				//if($obj->overwrite_md) {
+				//	$myWfs->overwrite = true;
+				//} else {
+					$myWfs->overwrite=false;
+				//}
+				$myWfs->id = $id;
+
+					echo "<br>Updated: " . $upd_wfsid . "<br>";
+				/*
+				// start new monitoring for this WMS
+				$now = time();
+				$sql = "UPDATE mb_monitor SET status = '-2', status_comment = 'Monitoring is still in progress...', " . 
+				"timestamp_begin = $1, timestamp_end = $2 WHERE upload_id = $3 AND fkey_wms_id = $4";
+				$v = array($now, $now, $upload_id, $upd_wmsid);
+				$t = array('s', 's', 's', 'i');
+				$res = db_prep_query($sql,$v,$t);
+
+				$currentFilename = "wms_monitor_report_" . $upload_id . "_" . 
+				$upd_wmsid . "_" . $wmsOwner . ".xml";		
+				$exec = PHP_PATH . "php5 ../../tools/mod_monitorCapabilities_write.php " . 
+				$currentFilename. " 0";
+				echo exec(escapeshellcmd($exec));
+				*/
+			}
+			echo "<br>Please note: The updated services need to be monitored again in order to update the database.<br><br>";
+		}
 		break;
 }
 
 //$e = new mb_exception("mod_monitorCapabilities_read.php: userId: ".$_SESSION["mb_user_id"]);
-$sql = "SELECT mb_wms_availability.* FROM mb_wms_availability, wms " . 
-	"WHERE mb_wms_availability.fkey_wms_id = wms.wms_id AND wms.wms_owner = $1";
-$res = db_prep_query($sql, array($_SESSION["mb_user_id"]), array("i"));
+switch ($serviceType) {
+	case "WMS":
+		$sql = "SELECT mb_wms_availability.* FROM mb_wms_availability, wms " . 
+			"WHERE mb_wms_availability.fkey_wms_id = wms.wms_id AND wms.wms_owner = $1";
+		$res = db_prep_query($sql, array($_SESSION["mb_user_id"]), array("i"));
+		break;
+	case "WFS":
+		$sql = "SELECT mb_wfs_availability.* FROM mb_wfs_availability, wfs " . 
+			"WHERE mb_wfs_availability.fkey_wfs_id = wfs.wfs_id AND wfs.wfs_owner = $1";
+		$res = db_prep_query($sql, array($_SESSION["mb_user_id"]), array("i"));
+		break;
+}
 
+
 $wms = array();
 $wms_id = array();
 
+$wfs = array();
+$wfs_id = array();
+
 $upload_id = array();
 $avg_response_time = array();
 $comment = array();
-$timestamp_begin = array();
-$timestamp_end = array();
 $upload_url = array();
 $updated = array();
-$mapurl = array();
-$image = array();
 $status = array();
 
 while($row = db_fetch_array($res)){
-	$wms[] = $row["fkey_wms_id"];
-	$wms_id[$row["fkey_wms_id"]] = $row["fkey_wms_id"];
-	$status[$row["fkey_wms_id"]] = $row["last_status"];
-	$comment[$row["fkey_wms_id"]] = $row["status_comment"];
-	$average_resp_time[$row["fkey_wms_id"]] = $row["average_resp_time"];
-	$upload_url[$row["fkey_wms_id"]] = $row["upload_url"];
-	$updated[$row["fkey_wms_id"]] = $row["fkey_upload_id"];
-	$upload_id[$row["fkey_wms_id"]] = $row["fkey_upload_id"];
-	$mapurl[$row["fkey_wms_id"]] = $row["map_url"];
-	$image[$row["fkey_wms_id"]] = $row["image"];
-	$cap_diff[$row["fkey_wms_id"]] = $row["cap_diff"];
-	$percentage[$row["fkey_wms_id"]] = $row["availability"];
-	$total[$row["fkey_wms_id"]] = $row["monitor_count"];
+	switch ($serviceType) {
+		case "WMS":
+			$serviceId = $row["fkey_wms_id"];
+			$wms[] = $serviceId;
+			$wms_id[$serviceId] = $serviceId;
+			$mapurl[$serviceId] = $row["map_url"];
+			$image[$serviceId] = $row["image"];
+			break;
+		case "WFS":
+			$serviceId = $row["fkey_wfs_id"];
+			$wfs[] = $serviceId;
+			$wfs_id[$serviceId] = $serviceId;
+			break;
+	}
+	$status[$serviceId] = $row["last_status"];
+	$comment[$serviceId] = $row["status_comment"];
+	$average_resp_time[$serviceId] = $row["average_resp_time"];
+	$upload_url[$serviceId] = $row["upload_url"];
+	$updated[$serviceId] = $row["fkey_upload_id"];
+	$upload_id[$serviceId] = $row["fkey_upload_id"];
+	$cap_diff[$serviceId] = $row["cap_diff"];
+	$percentage[$serviceId] = $row["availability"];
+	$total[$serviceId] = $row["monitor_count"];
 }
+
+
 $newArray = $status;
 if ($_GET['sortby']) {
 	if ($_GET['sortby'] == "wms") {
@@ -151,6 +246,10 @@
 		$newArray = $wms_id;
 		asort($newArray);
 	}
+	if ($_GET['sortby'] == "wfs") {
+		$newArray = $wfs_id;
+		asort($newArray);
+	}
 	elseif ($_GET['sortby'] == "status") {
 		$newArray = $status;
 		asort($newArray);
@@ -173,16 +272,30 @@
 	}
 }
 
-$script = $_SERVER["SCRIPT_NAME"]."?guiID=".$gui_id."&";
+$script = $_SERVER["SCRIPT_NAME"]."?serviceType=".$_REQUEST['serviceType']."&guiID=".$gui_id."&";
 
 $str = "<span style='font-size:30'>monitoring results</span><hr><br>\n";
 $str .= "<form name = 'form1' method='post' action='".$script."sortby=".$_GET['sortby']."'>\n\t";
-$str .= "\n\t<input type=submit value='update selected WMS'>\n";
+$str .= "\n\t<input type=submit value='update selected Service'>\n";
 $str .= "\n\t<input type=button onclick=\"window.location.href='".$script."sortby=".$_GET['sortby']."'\" value='refresh'>\n<br/><br/>\n	";
 $str .= "<table cellpadding=10 cellspacing=0 border=0>";
-$str .= "<tr bgcolor='#dddddd'><th></th><th align='left'><a href='".$script."sortby=wms'>wms</a></th>";
+switch ($serviceType) {
+	case "WMS":
+		$str .= "<tr bgcolor='#dddddd'><th></th><th align='left'><a href='".$script."sortby=wms'>wms</a></th>";
+		break;
+	case "WFS":
+		$str .= "<tr bgcolor='#dddddd'><th></th><th align='left'><a href='".$script."sortby=wfs'>wfs</a></th>";
+		break;
+}
 $str .= "<th align='left' colspan = 2><a href='".$script."sortby=status'>current status</a></th>";
-$str .= "<th align='left'><a href='".$script."sortby=image'>image</a></th>";
+switch ($serviceType) {
+	case "WMS":
+		$str .= "<th align='left'><a href='".$script."sortby=image'>image</a></th>";
+		break;
+	case "WFS":
+		//
+		break;
+}
 $str .= "<th align='left'><a href='".$script."sortby=avgresp'>avg. response time</a></th>";
 $str .= "<th align='left'><a href='".$script."sortby=avail'>overall availability</a></th><th></th><th>Diff</th></tr>";
 $cnt = 0;
@@ -192,18 +305,31 @@
 	elseif ($status[$k]==1) $img = "go.bmp";
 
 	if ($updated[$k] == "0" && $status[$k] == 0) $fill = "checked"; else $fill = "disabled";
+//switch ($serviceType) {
+//	case "WMS":
+		if (fmod($cnt, 2) == 1) {
+			$str .= "\n\t\t<tr bgcolor='#e6e6e6'>";
+		}
+		else {
+			$str .= "\n\t\t<tr bgcolor='#f0f0f0'>";
+		}
+//		break;
+//}
+switch ($serviceType) {
+	case "WMS":
+		$str .= "\n\t\t\t<td><input name='cb".$cnt."' value='" . $wms_id[$k] . "' type=checkbox ".$fill." /><input type=hidden name='upl_id".$cnt."' value='".$upload_id[$k]."'></td>";
+		$str .= "\n\t\t\t<td valign='top'><b>" . $wms_id[$k] . "</b><br>" . $admin->getWfsTitleByWfsId($wfs_id[$k]) . "</td>";
+		break;
+	case "WFS":
+		$str .= "\n\t\t\t<td><input name='cb".$cnt."' value='" . $wfs_id[$k] . "' type=checkbox ".$fill." /><input type=hidden name='upl_id".$cnt."' value='".$upload_id[$k]."'></td>";
+		$str .= "\n\t\t\t<td valign='top'><b>" . $wfs_id[$k] . "</b><br>" . $admin->getWfsTitleByWfsId($wfs_id[$k]) . "</td>";
+		break;
+}
+	$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>";
 
-	if (fmod($cnt, 2) == 1) {
-		$str .= "\n\t\t<tr bgcolor='#e6e6e6'>";
-	}
-	else {
-		$str .= "\n\t\t<tr bgcolor='#f0f0f0'>";
-	}
-	$str .= "\n\t\t\t<td><input name='cb".$cnt."' value='" . $wms_id[$k] . "' type=checkbox ".$fill." /><input type=hidden name='upl_id".$cnt."' value='".$upload_id[$k]."'></td>";
-	$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'>" . $comment[$k] . "<br><div style='font-size:12'>".$upload_id[$k]."</div></td>";
+if ($serviceType == "WMS") {
 	$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) {
@@ -222,7 +348,7 @@
 	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";
@@ -251,10 +377,21 @@
 		}
 	}
 	$str .= "</tr></table></td>";
-	$str .= "\n\t\t<td><input type=button value='details' onclick=\"var newWindow = window.open('../php/mod_monitorCapabilities_read_single.php?wmsid=".$wms_id[$k]."','wms','width=500,height=700,scrollbars');newWindow.focus();\"></td>";
-	$str .= "\n\t\t\t<td>";	
-	if ($cap_diff[$k] != "" && $status[$k] == 0)
-		$str .= "<input type=button value='show' onclick=\"var newWindow = window.open('../php/mod_showCapDiff.php?wmsid=".$wms_id[$k]."','Caps Diff','width=700,height=300,scrollbars');newWindow.focus();\">";
+switch ($serviceType) {
+	case "WMS":
+		$str .= "\n\t\t<td><input type=button value='details' onclick=\"var newWindow = window.open('../php/mod_monitorCapabilities_read_single.php?serviceType=wms&id=".$wms_id[$k]."','wms','width=500,height=700,scrollbars');newWindow.focus();\"></td>";
+		$str .= "\n\t\t\t<td>";	
+		if ($cap_diff[$k] != "" && $status[$k] == 0)
+			$str .= "<input type=button value='show' onclick=\"var newWindow = window.open('../php/mod_showCapDiff.php?serviceType=wms&id=".$wms_id[$k]."','Caps Diff','width=700,height=300,scrollbars');newWindow.focus();\">";
+		break;
+	case "WFS":
+		$str .= "\n\t\t<td><input type=button value='details' onclick=\"var newWindow = window.open('../php/mod_monitorCapabilities_read_single.php?serviceType=wfs&id=".$wfs_id[$k]."','wfs','width=500,height=700,scrollbars');newWindow.focus();\"></td>";
+		$str .= "\n\t\t\t<td>";	
+		if ($cap_diff[$k] != "" && $status[$k] == 0)
+			$str .= "<input type=button value='show' onclick=\"var newWindow = window.open('../php/mod_showCapDiff.php?serviceType=wfs&id=".$wfs_id[$k]."','Caps Diff','width=700,height=300,scrollbars');newWindow.focus();\">";
+		break;
+}
+
 	$str .= "</td></tr>";
 	$cnt++;
 }

Modified: trunk/mapbender/http/php/mod_monitorCapabilities_read_single.php
===================================================================
--- trunk/mapbender/http/php/mod_monitorCapabilities_read_single.php	2018-04-12 14:16:50 UTC (rev 9893)
+++ trunk/mapbender/http/php/mod_monitorCapabilities_read_single.php	2018-04-12 15:20:26 UTC (rev 9894)
@@ -19,7 +19,6 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 require_once(dirname(__FILE__)."/../../core/globalSettings.php");
 require_once(dirname(__FILE__)."/../classes/class_administration.php");
-
 /*  
  * @security_patch irv done
  */ 
@@ -41,21 +40,40 @@
 <body>
 <?php
 $admin = new administration();
-
-if ($_GET['wmsid']) {
-	$wms_id = intval($_GET['wmsid']); 
+if (isset($_REQUEST["serviceType"]) & $_REQUEST["serviceType"] != "") {
+	$testMatch = $_REQUEST["serviceType"];	
+ 	if (!($testMatch == 'wms' or $testMatch == 'wfs')){ 
+		//echo 'outputFormat: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		echo 'Parameter <b>serviceType</b> is not valid (wms, wfs).<br/>'; 
+		die(); 		
+ 	}
+	$serviceType = $testMatch;
+	$testMatch = NULL;
 }
-else {
-	echo "Invalid WMS ID.";
-	die;
+if (isset($_REQUEST["id"]) & $_REQUEST["id"] != "") {
+        //validate integer
+        $testMatch = $_REQUEST["id"];
+        //give max 99 entries - more will be to slow
+        $pattern = '/^[0-9]*$/';  
+        if (!preg_match($pattern,$testMatch)){
+                echo 'Parameter <b>id</b> is not valid (integer).<br/>';
+                die();
+        }
+        $id = $testMatch;
+        $testMatch = NULL;
 }
-
 $sql = "SELECT upload_id, status, status_comment, timestamp_begin, timestamp_end, upload_url, updated FROM mb_monitor ";
-$sql .= "WHERE fkey_wms_id = $1 AND NOT status = '-2' ORDER BY upload_id DESC";
-$v = array($wms_id);
+switch ($serviceType) {
+	case "wms":
+		$sql .= "WHERE fkey_wms_id = $1 AND NOT status = '-2' ORDER BY upload_id DESC";
+		break;
+	case "wfs":
+		$sql .= "WHERE fkey_wfs_id = $1 AND NOT status = '-2' ORDER BY upload_id DESC";
+		break;
+}
+$v = array($id);
 $t = array('i');
 $res = db_prep_query($sql,$v,$t);
-
 $cnt=0;
 while ($row = db_fetch_array($res)) {
 	$upload_id[$cnt] = db_result($res,$cnt,"upload_id");
@@ -72,10 +90,15 @@
 	}
 	$cnt++;
 }
-	
-
 $str = "<span style='font-size:30'>"._mb("Monitoring results")."</span><hr><br>\n";//Monitoring Ergebnisse
-$str .= "<b>" . $wms_id . "</b><br>" . $admin->getWmsTitleByWmsId($wms_id) . "<br><br><br>\n";
+switch ($serviceType) {
+	case "wms":
+		$str .= "<b>" . $id . "</b><br>" . $admin->getWmsTitleByWmsId($id) . "<br><br><br>\n";
+		break;
+	case "wfs":
+		$str .= "<b>" . $id . "</b><br>" . $admin->getWfsTitleByWfsId($id) . "<br><br><br>\n";
+		break;
+}
 $str .= "<table cellpadding=10 cellspacing=0 border=0>";
 $str .= "<tr bgcolor='#dddddd'><th align='left'>date</th><th align='left' colspan = 2>"._mb("Status")."</th><th align='center'>"._mb("Response time")."</th></tr>";//Status Antwortzeit
 

Modified: trunk/mapbender/http/php/mod_showCapDiff.php
===================================================================
--- trunk/mapbender/http/php/mod_showCapDiff.php	2018-04-12 14:16:50 UTC (rev 9893)
+++ trunk/mapbender/http/php/mod_showCapDiff.php	2018-04-12 15:20:26 UTC (rev 9894)
@@ -20,25 +20,42 @@
 require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
 require_once(dirname(__FILE__)."/../classes/class_administration.php");
 require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
-$wms_id = intval($_REQUEST["wmsid"]);
-if (isset($wms_id)){
-	if (!is_int($wms_id)) {
-		echo 'Error: wms_id is no integer<br>';
-		die();
-	}
-	} else {
-		echo 'Error: wms_id not requested<br>';
-	die();
+//validate parameters
+if (isset($_REQUEST["serviceType"]) & $_REQUEST["serviceType"] != "") {
+	$testMatch = $_REQUEST["serviceType"];	
+ 	if (!($testMatch == 'wms' or $testMatch == 'wfs')){ 
+		//echo 'outputFormat: <b>'.$testMatch.'</b> is not valid.<br/>'; 
+		echo 'Parameter <b>serviceType</b> is not valid (wms, wfs).<br/>'; 
+		die(); 		
+ 	}
+	$serviceType = $testMatch;
+	$testMatch = NULL;
 }
-$sql = "SELECT cap_diff FROM mb_wms_availability WHERE fkey_wms_id = $1";
-$v = array($wms_id);
+if (isset($_REQUEST["id"]) & $_REQUEST["id"] != "") {
+        //validate integer
+        $testMatch = $_REQUEST["id"];
+        //give max 99 entries - more will be to slow
+        $pattern = '/^[0-9]*$/';  
+        if (!preg_match($pattern,$testMatch)){
+                echo 'Parameter <b>id</b> is not valid (integer).<br/>';
+                die();
+        }
+        $id = $testMatch;
+        $testMatch = NULL;
+}
+switch ($serviceType) {
+	case "wms":
+		$sql = "SELECT cap_diff FROM mb_wms_availability WHERE fkey_wms_id = $1";
+		$v = array($id);
+		break;
+	case "wfs":
+		$sql = "SELECT cap_diff FROM mb_wfs_availability WHERE fkey_wfs_id = $1";
+		$v = array($id);
+		break;
+}
 $t = array('i');
 $res = db_prep_query($sql,$v,$t);
-
 $cap_diff_row = db_fetch_row($res);
 $html = urldecode($cap_diff_row[0]);
-
 echo $html;
-
-
 ?>



More information about the Mapbender_commits mailing list