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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Nov 6 21:27:40 PST 2019


Author: armin11
Date: 2019-11-06 21:27:40 -0800 (Wed, 06 Nov 2019)
New Revision: 10322

Removed:
   trunk/mapbender/http/php/mod_exportISOMetadata.php
Log:
Metadata generator will be only available from cli - not via http - for security reasons!

Deleted: trunk/mapbender/http/php/mod_exportISOMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_exportISOMetadata.php	2019-11-07 05:26:57 UTC (rev 10321)
+++ trunk/mapbender/http/php/mod_exportISOMetadata.php	2019-11-07 05:27:40 UTC (rev 10322)
@@ -1,227 +0,0 @@
-<?php
-#http://www.geoportal.rlp.de/mapbender/php/mod_exportISOMetadata.php?
-# $Id: mod_exportISOMetadata.php 235
-# http://www.mapbender.org/index.php/Inspire_Metadata_Editor
-# 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__) . "/../../core/globalSettings.php");
-require_once(dirname(__FILE__) . "/../classes/class_connector.php");
-
-if (file_exists(dirname(__FILE__)."/../../conf/exportIsoMetadata.json")) {
-     $configObject = json_decode(file_get_contents("../../conf/exportIsoMetadata.json"));
-}
-
-$con = db_connect(DBSERVER,OWNER,PW);
-db_select_db(DB,$con);
-
-//define the view or table where to read out the layer ids for which metadatafiles should be generated
-$wmsView = "search_wms_view";
-
-//would have been called from web
-//parse request parameter
-//make all parameters available as upper case
-foreach($_REQUEST as $key => $val) {
-	$_REQUEST[strtoupper($key)] = $val;
-}
-//validate request params
-if (!isset($_REQUEST['TYPE'])) {
-	echo 'GET Parameter Type lacks'; 
-	die();
-}
-if (isset($_REQUEST['TYPE']) and $_REQUEST['TYPE'] != "ALL") {
-	echo 'validate: <b>'.$_REQUEST['TYPE'].'</b> is not valid.<br/>'; 
-	die();
-}
-
-$sql = "update mb_metadata set export2csw = false where position('GetRecordById' in data) <> 0 and position('GetRecordById' in data) is not null";
-if (isset($configObject->excludeFromCswExportRule) && count($configObject->excludeFromCswExportRule) > 0) {
-    $sql .= " AND metadata_id NOT IN (".implode(",", $configObject->excludeFromCswExportRule).")";
-}
-$res = db_query($sql);
-
-$sql = "SELECT layer_id ";
-$sql .= "FROM ".$wmsView." WHERE export2csw = true";
-//$sql .= "FROM layer WHERE layer_id IN (20203,20202)";
-$v = array();
-$t = array();
-$res = db_prep_query($sql,$v,$t);
-
-$generatorScript = '/mapbender/php/mod_layerISOMetadata.php?';
-$generatorScriptMetadata = '/mapbender/php/mod_dataISOMetadata.php?';
-$generatorScriptDlsOption = '/mapbender/php/mod_getDownloadOptions.php?';
-$generatorScriptDls = '/mapbender/php/mod_inspireAtomFeedISOMetadata.php?';
-$generatorScriptDlsWfs2 = '/mapbender/php/mod_featuretypeISOMetadata.php?'; //SERVICE=WFS&outputFormat=iso19139&Id=2699'
-
-$generatorBaseUrl = 'http://'.$_SERVER['HTTP_HOST'].$generatorScript;
-$generatorBaseUrlMetadata = 'http://'.$_SERVER['HTTP_HOST'].$generatorScriptMetadata;
-$generatorBaseUrlDlsOption = 'http://'.$_SERVER['HTTP_HOST'].$generatorScriptDlsOption;
-$generatorBaseUrlDls = 'http://'.$_SERVER['HTTP_HOST'].$generatorScriptDls;
-$generatorBaseUrlDlsWfs2 = 'http://'.$_SERVER['HTTP_HOST'].$generatorScriptDlsWfs2;
-
-$countLayer = 0;
-$countMetadataURL = 0;
-$countDls = 0;
-echo date('Y-m-d - H:i:s', time())."<br>";
-//remove files from METADATA_DIR!
-if ($handle = opendir(METADATA_DIR)) {
-	echo "Delete files from temporary metadata folder:<br>";
-    	/* This is the correct way to loop over the directory. */
-    	while (false !== ($file = readdir($handle))) {
-		//check if file name begin with "mapbender";
-		$pos = strpos($file, "mapbender");
-		if ($pos !== false) {
-			//delete file with unlink
-			unlink(METADATA_DIR."/".$file); 
-			echo METADATA_DIR."/".$file." has been deleted!<br>";
-		} else {
-        		echo "$file will not be deleted!<br>";
-		}
-    	}
-   	closedir($handle);
-}
-echo "Begin to create new metadata: ".date('Y-m-d - H:i:s', time())."<br>";
-while($row = db_fetch_array($res)){
-	$generatorUrl = $generatorBaseUrl."SERVICE=WMS&outputFormat=iso19139&id=".$row['layer_id'];
-	echo "URL requested : ".$generatorUrl."<br>";
-	$generatorInterfaceObject = new connector($generatorUrl);
-	$ISOFile = $generatorInterfaceObject->file;
-	$layerId = $row['layer_id'];
-	echo "File for layer ".$layerId." will be generated<br>";
-	//generate temporary files under tmp
-	if($h = fopen(METADATA_DIR."/mapbenderServiceMetadata_".$layerId."_iso19139.xml","w")){
-		if(!fwrite($h,$ISOFile)){
-			$e = new mb_exception("mod_exportISOMetadata.php: cannot write to file: ".METADATA_DIR."/mapbenderLayerMetadata_".$row['layer_id']."_iso19139.xml");
-		}
-	echo "Service metadata file for layer ".$layerId." written to ".METADATA_DIR."<br>";
-	fclose($h);
-	}
-
-	//get all connected metadata for this layer and save it too	
-	$sql = <<<SQL
-
-SELECT metadata_id, uuid, link, linktype, md_format, origin, export2csw FROM mb_metadata 
-INNER JOIN (SELECT * from ows_relation_metadata 
-WHERE fkey_layer_id = $layerId ) as relation ON 
-mb_metadata.metadata_id = relation.fkey_metadata_id
-
-SQL;
-	
-	$res_metadata = db_query($sql);
-	while ($row_metadata = db_fetch_array($res_metadata)) {
-		//export only metadata which should be exported to the external csw interface
-		if ($row_metadata["export2csw"] == "t") {
-			$generatorUrlMetadata = $generatorBaseUrlMetadata."outputFormat=iso19139&id=".$row_metadata['uuid'];
-			echo "<BLOCKQUOTE>URL requested : ".$generatorUrlMetadata."<br>";
-			$generatorInterfaceObject = new connector($generatorUrlMetadata);
-			$ISOFile = $generatorInterfaceObject->file;
-			echo "Metadata uuid: ".$row_metadata['uuid']."<br>";
-			//generate temporary files under tmp
-			if($h = fopen(METADATA_DIR."/mapbenderDataMetadata_".$layerId."_".$row_metadata['uuid']."_iso19139.xml","w")){
-				if(!fwrite($h,$ISOFile)){
-					$e = new mb_exception("mod_exportISOMetadata.php: cannot write to file: ".METADATA_DIR."/metadata/mapbenderMetadata_".$layerId."_".$row_metadata['uuid']."_iso19139.xml");
-				}
-				echo "Data metadate file for layer ".$row['layer_id']." and metadata ".$row_metadata['uuid']." written to ".METADATA_DIR."</BLOCKQUOTE><br>";
-				fclose($h);
-				$countMetadataURL++;	
-			}
-		}
-		//generate the downloadservice metadata files thru walking over the coupled dls for this metadata uuid!
-		//e.g. http://www.geoportal.rlp.de/mapbender/php/mod_inspireAtomFeedISOMetadata.php?Id=1487b57f-f087-d84a-3de3-e341312ecd6e&outputFormat=iso19139&generateFrom=wfs&wfsid=271
-		//get download options for specific metadata
-		
-		$downloadOptionsConnector = new connector($generatorBaseUrlDlsOption."id=".$row_metadata["uuid"]);
-		$downloadOptions = json_decode($downloadOptionsConnector->file);
-		if ($downloadOptions != null) {
-			echo "Coupled DLS: <br>";
-			foreach ($downloadOptions->{$row_metadata["uuid"]}->option as $option) {
-				unset($dlsOption);
-				switch ($option->type) {
-					case "wmslayergetmap":
-						$generatorDlsUrl =  $generatorBaseUrlDls."Id=".$row_metadata["uuid"]."&outputFormat=iso19139&generateFrom=wmslayer&layerid=".$option->resourceId;
-						$dlsOption = $option->type;
-						$dlsOptionId = $option->resourceId;
-						break;
-					case "wmslayerdataurl":
-						$generatorDlsUrl = $generatorBaseUrlDls."Id=".$row_metadata["uuid"]."&outputFormat=iso19139&generateFrom=dataurl&layerid=".$option->resourceId;
-						$dlsOption = $option->type;						
-						$dlsOptionId = $option->resourceId;
-						break;
-					case "wfsrequest":
-						$generatorDlsUrl = $generatorBaseUrlDls."Id=".$row_metadata["uuid"]."&outputFormat=iso19139&generateFrom=wfs&wfsid=".$option->serviceId;
-						$dlsOption = $option->type;						
-						$dlsOptionId = $option->serviceId;
-						break;
-					case "downloadlink":
-						$generatorDlsUrl = $generatorBaseUrlDls."Id=".$row_metadata["uuid"]."&outputFormat=iso19139&generateFrom=metadata";
-						$dlsOption = $option->type;
-						//generate downloadservice uuid from metadata_uuid and hash of link 		
-						$mdPart = explode('-',$row_metadata["uuid"]);
-						$linkPart = md5($option->link);
-						$dlsOptionId = $mdPart[0]."-".$mdPart[1]."-".$mdPart[2]."-".substr($linkPart, -12, 4)."-".substr($linkPart, -8, 8);
-						break;
-				}
-				echo "<br>".$generatorDlsUrl."<br>";
-				//load the xml and store it to filesystem
-				if (isset($dlsOption) && $dlsOption != '') {
-					$generatorInterfaceObject = new connector($generatorDlsUrl);
-					$ISOFile = $generatorInterfaceObject->file;
-					if($h = fopen(METADATA_DIR."/mapbenderDlsMetadata_".$row_metadata["uuid"]."_".$dlsOption."_".$dlsOptionId."_iso19139.xml","w")){
-						if(!fwrite($h,$ISOFile)){
-							$e = new mb_exception("mod_exportISOMetadata.php: cannot write to file: ".METADATA_DIR."/mapbenderDlsMetadata_".$row_metadata["uuid"]."_".$dlsOption."_".$dlsOptionId."_iso19139.xml");
-						}
-						fclose($h);
-						$countDls++;	
-					}
-				}
-				//test if download option via wfsrequest is based on WFS > 2.0 - first also generate metadata for wfs 1.1.0
-				if ($option->type == "wfsrequest") {
-					//select featuretypeid, wfs_version, ...
-					$sqlWfs2 = <<<SQL
-
-					SELECT wfs_version, fkey_wfs_id, featuretype_id FROM (SELECT fkey_wfs_id, featuretype_id FROM wfs_featuretype WHERE featuretype_id 
-					IN (select fkey_featuretype_id from mb_metadata LEFT JOIN ows_relation_metadata ON metadata_id = fkey_metadata_id where 
-					 fkey_featuretype_id IS NOT NULL)) ft LEFT JOIN wfs ON 
-					ft.fkey_wfs_id = wfs_id WHERE wfs_version = '2.0.0' OR wfs_version = '2.0.2' ;
-
-SQL;
-					$v = array();
-					$t = array();
-					$res_wfs2 = db_prep_query($sqlWfs2,$v,$t);
-					while ($row_wfs2 = db_fetch_array($res_wfs2)) {
-						$generatorDlsUrlWfs2 = $generatorBaseUrlDlsWfs2."SERVICE=WFS&outputFormat=iso19139&Id=".$row_wfs2['featuretype_id'];
-						$generatorInterfaceObject = new connector($generatorDlsUrlWfs2);
-						$ISOFile = $generatorInterfaceObject->file;
-						if($h = fopen(METADATA_DIR."/mapbenderDlsWfs2Metadata_".$row_metadata["uuid"]."_".$row_wfs2['featuretype_id']."_iso19139.xml","w")){
-							if(!fwrite($h,$ISOFile)){
-								$e = new mb_exception("mod_exportISOMetadata.php: cannot write to file: ".METADATA_DIR."/mapbenderDlsWfs2Metadata_".$row_metadata["uuid"]."_".$row_wfs2['featuretype_id']."_iso19139.xml");
-							}
-							fclose($h);
-							$countDls++;	
-						}
-					}
-									
-				}
-			}	
-		}
-		
-	}
-	$countLayer++;
-}
-echo "Number of generated View Service Metadata Records (one for each layer): ".$countLayer."<br>";
-echo "Number of generated Data Metadata Records (multiple for each layer): ".$countMetadataURL."<br>";
-echo "Number of generated Download Service Metadata Records (multiple for each metadataset): ".$countDls."<br>";
-echo date('Y-m-d - H:i:s', time())."<br>";



More information about the Mapbender_commits mailing list