[Mapbender-commits] r8613 - in trunk/mapbender/http: classes php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Mon May 6 01:49:02 PDT 2013
Author: armin11
Date: 2013-05-06 01:49:02 -0700 (Mon, 06 May 2013)
New Revision: 8613
Modified:
trunk/mapbender/http/classes/class_wms.php
trunk/mapbender/http/php/mb_getWmsData.php
trunk/mapbender/http/php/mod_updateWMS.php
Log:
Update wms enhancement. Possibility to update wms with authentication. Patch from obgr merged into trunk. See https://trac.osgeo.org/mapbender/ticket/886.
Now layer_name mapping and authentication is supported -> for 2.7.4.
Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php 2013-05-02 09:09:30 UTC (rev 8612)
+++ trunk/mapbender/http/classes/class_wms.php 2013-05-06 08:49:02 UTC (rev 8613)
@@ -2495,8 +2495,17 @@
}
function updateObjInDB($myWMS,$updateMetadataOnly=false,$changedLayers=null){ //TODO give return true or false to allow feedback to user!!!
-
- $this->wms_id = $myWMS;
+ if (func_num_args() == 4) { //new for HTTP Authentication
+ $auth = func_get_arg(3);
+ $username = $auth['username'];
+ $password = $auth['password'];
+ $authType = $auth['auth_type'];
+ } else {
+ $username = '';
+ $password = '';
+ $authType = '';
+ }
+ $this->wms_id = $myWMS;
//get some things out from database if not already given thru metadata editor: wms_network_access, wms_max_imagesize, inspire_download (on layer level)
//they don't come from the capabilities!
if (!$updateMetadataOnly) {
@@ -2538,21 +2547,24 @@
$sql .= "wms_remotewfs = $12, ";
$sql .= "wms_network_access = $13, ";
$sql .= "wms_max_imagesize = $16, ";
- $sql .= "fkey_mb_group_id = $14 ";
+ $sql .= "fkey_mb_group_id = $14, ";
+ $sql .= "wms_auth_type = $17, ";
+ $sql .= "wms_username = $18, ";
+ $sql .= "wms_password = $19 ";
#$sql .= "uuid = $15 ";
$sql .= " WHERE wms_id = $15";
$v = array($this->wms_version,$this->wms_getcapabilities,
$this->wms_getmap,$this->wms_getfeatureinfo,$this->wms_getlegendurl,
$admin->char_encode($this->wms_getcapabilities_doc),$this->wms_upload_url,strtotime("now"),
- $this->wms_supportsld,$this->wms_userlayer,$this->wms_userstyle,$this->wms_remotewfs,$this->wms_network_access, $this->fkey_mb_group_id ,$myWMS, $this->wms_max_imagesize);
- $t = array('s','s','s','s','s','s','s','i','s','s','s','s','i','i','i','i');
+ $this->wms_supportsld,$this->wms_userlayer,$this->wms_userstyle,$this->wms_remotewfs,$this->wms_network_access, $this->fkey_mb_group_id ,$myWMS, $this->wms_max_imagesize, $authType, $username, $password);
+ $t = array('s','s','s','s','s','s','s','i','s','s','s','s','i','i','i','i','s','s','s');
$res = db_prep_query($sql,$v,$t);
if(!$res){
db_rollback();
}
-
+ //update following metadata only if intended - mapbender.conf
if($this->overwrite == true){
$sql = "UPDATE wms SET ";
$sql .= "wms_title = $1 ,";
@@ -2817,7 +2829,11 @@
}
}
-
+ if ($authType != '') { //some authentication is needed!
+ $admin = new administration();
+ echo "WMS ID: ".$myWMS;
+ $admin->setWMSOWSstring($myWMS, 1);
+ }
return true;
}
Modified: trunk/mapbender/http/php/mb_getWmsData.php
===================================================================
--- trunk/mapbender/http/php/mb_getWmsData.php 2013-05-02 09:09:30 UTC (rev 8612)
+++ trunk/mapbender/http/php/mb_getWmsData.php 2013-05-06 08:49:02 UTC (rev 8613)
@@ -23,28 +23,43 @@
if ($command == "getWmsData") {
$wms = $_POST["wmsId"];
$url = $_POST["wmsUrl"];
+ $authType = $_POST["authType"];
+ $authName = $_POST["authName"];
+ $authPassword = $_POST["authPassword"];
+ if ($authType !== "none") {
+ $useAuthentication = true;
+ $auth['username'] = $authName;
+ $auth['password'] = $authPassword;
+ $auth['auth_type'] = $authType;
+ } else {
+ $useAuthentication = false;
+ }
//get existing DB wms information
- $sql = "SELECT * from layer WHERE fkey_wms_id = $1 ORDER BY layer_id";
- $v = array ($wms);
- $t = array ('i');
- $res = db_prep_query($sql, $v, $t);
+ $sql = "SELECT * from layer WHERE fkey_wms_id = $1 ORDER BY layer_id";
+ $v = array ($wms);
+ $t = array ('i');
+ $res = db_prep_query($sql, $v, $t);
- $dbObj = array();
+ $dbObj = array();
while ($row = db_fetch_array($res)) {
- $dbObj[] = array (
- //"id" => $row["layer_id"],
- "pos" => $row["layer_pos"],
- "parent" => $row["layer_parent"],
- "name" => $row["layer_name"]
- //"title" => $row["layer_title"]
- );
- }
+ $dbObj[] = array (
+ //"id" => $row["layer_id"],
+ "pos" => $row["layer_pos"],
+ "parent" => $row["layer_parent"],
+ "name" => $row["layer_name"]
+ //"title" => $row["layer_title"]
+ );
+ }
- //get xml wms information
+ //get xml wms information
$updateWms = new wms();
- $xml = $updateWms->createObjFromXML($url);
+ if ($useAuthentication) {
+ $xml = $updateWms->createObjFromXML($url, $auth);
+ } else {
+ $xml = $updateWms->createObjFromXML($url);
+ }
if($xml == "") {
echo "WMS could not be loaded, no valid XML. Please check WMS GetCapabilities";
die();
@@ -62,10 +77,21 @@
header("Content-type:application/json; charset=utf-8");
echo $layerJson;
-}
-else if($command == "updateWMS") {
- $myWMS = $_POST["wmsId"];
+} else if ($command == "updateWMS") {
+
+ $myWMS = $_POST["wmsId"];
$url = $_POST["wmsUrl"];
+ $authType = $_POST["authType"];
+ $authName = $_POST["authName"];
+ $authPassword = $_POST["authPassword"];
+ if ($authType !== "none") {
+ $useAuthentication = true;
+ $auth['username'] = $authName;
+ $auth['password'] = $authPassword;
+ $auth['auth_type'] = $authType;
+ } else {
+ $useAuthentication = false;
+ }
$changedLayerArray = array();
for ($i=0; $i<count($_POST['dbOldNames']); $i++) {
@@ -78,7 +104,11 @@
#$changedLayerObj = json_encode($changedLayerArray);
$mywms = new wms();
- $mywms->createObjFromXML($url);
+ if ($useAuthentication) {
+ $mywms->createObjFromXML($url, $auth);
+ } else {
+ $mywms->createObjFromXML($url);
+ }
$mywms->optimizeWMS();
echo "<br />";
if (!MD_OVERWRITE) {
@@ -91,7 +121,11 @@
if(empty($_POST['rss_news'])) {
$mywms->setGeoRss = false;
}
- $mywms->updateObjInDB($myWMS,false, $changedLayerArray);
+ if ($useAuthentication) {
+ $mywms->updateObjInDB($myWMS,false, $changedLayerArray, $auth);
+ } else {
+ $mywms->updateObjInDB($myWMS,false, $changedLayerArray);
+ }
$mywms->displayWMS();
// start (owners and subscribers of the updated wms will be notified by email)
Modified: trunk/mapbender/http/php/mod_updateWMS.php
===================================================================
--- trunk/mapbender/http/php/mod_updateWMS.php 2013-05-02 09:09:30 UTC (rev 8612)
+++ trunk/mapbender/http/php/mod_updateWMS.php 2013-05-06 08:49:02 UTC (rev 8613)
@@ -25,8 +25,20 @@
$selWMS = $_POST["selWMS"];
$capURL = $_POST["capURL"];
$myWMS = $_POST["myWMS"];
+
+$imrAuthName = !empty($_POST['imrAuthName']) ? $_POST['imrAuthName'] : '';
+$imrAuthPassword = !empty($_POST['imrAuthPassword']) ? $_POST['imrAuthPassword'] : '';
+$imrHttpAuth = !empty($_POST['imrHttpAuth']) ? $_POST['imrHttpAuth'] : '';
+$imrOldAuthType = !empty($_POST['imrOldAuthType']) ? $_POST['imrOldAuthType'] : '';
+$imrOldAuthName = !empty($_POST['imrOldAuthName']) ? $_POST['imrOldAuthName'] : '';
+$imrOldAuthPasswword = !empty($_POST['imrOldAuthPassword']) ? $_POST['imrOldAuthPassword'] : '';
+
$myURL = $_POST["myURL"];
+
+
+
+
$secParams = SID."&guiID=".$_REQUEST["guiID"]."&elementID=".$_REQUEST["elementID"];
$self = $_SERVER["SCRIPT_NAME"]."?".$secParams;
@@ -104,6 +116,25 @@
<script type='text/javascript' src='../extensions/jquery-ui-1.8.16.custom/js/jquery-ui-1.8.16.custom.min.js'></script>
<script type='text/javascript'>
+function toggleAuthDivVis() {
+ //alert(getRadioValue(document.form1.imrHttpAuth));
+ if (getRadioValue(document.form1.imrHttpAuth) != 'none' && getRadioValue(document.form1.imrHttpAuth) != 'keep') {
+ document.getElementById("imrAuthDiv").style.display = "block";
+ } else {
+ document.getElementById("imrAuthDiv").style.display = "none";
+ }
+ }
+
+ function getRadioValue(rObj) {
+ for (var i=0; i<rObj.length; i++) if (rObj[i].checked) return rObj[i].value;
+ return false;
+ }
+
+function reupload(){
+ document.form1.myURL.value = document.form1.capURL.value;
+ validate();
+}
+
function updateWms() {
$("#updateResult").remove();
var dbOldNameArray = [];
@@ -114,10 +145,26 @@
$(".dbCurrentName").each(function(index) {
dbCurrentNameArray.push($(this).val());
});
+ radioAuthValue = $('input:radio[name=imrHttpAuth]:checked').val();
+ if (radioAuthValue == "keep") {
+ authType = $("#imrOldAuthType").val();
+ authPassword = $("#imrOldAuthPassword").val();
+ authName = $("#imrOldAuthName").val();
+ } else {
+ $('input:radio[name=imrHttpAuth]:checked').val(radioAuthValue); //maybe 'none', 'digest' or 'basic'
+ authType = $('input:radio[name=imrHttpAuth]:checked').val();
+ authPassword = $("#imrAuthPassword").val();
+ authName = $("#imrAuthName").val();
+ }
+
var updateParams = {
+ //TODO add auth info!
"command": "updateWMS",
"wmsId": $("#myWMS").val(),
"wmsUrl" : $("#myURL").val(),
+ "authType" : authType,
+ "authName" : authName,
+ "authPassword" : authPassword,
"publishRss" : $("#rss_news").attr("checked"),
"publishTwitter" : $("#twitter_news").attr("checked"),
"dbOldNames": dbOldNameArray,
@@ -156,16 +203,30 @@
alert("No link to WMS Capabilities URL given.");
return;
}
- else{
+ else {
if($("#compare_dialog").attr("checked")) {
if (typeof $compareDialog == 'object') {
- $compareDialog.dialog("destroy");
- }
+ $compareDialog.dialog("destroy");
+ }
+ radioAuthValue = $('input:radio[name=imrHttpAuth]:checked').val();
+ if (radioAuthValue == "keep") {
+ authType = $("#imrOldAuthType").val();
+ authPassword = $("#imrOldAuthPassword").val();
+ authName = $("#imrOldAuthName").val();
+ } else {
+ $('input:radio[name=imrHttpAuth]:checked').val(radioAuthValue); //maybe 'none', 'digest' or 'basic'
+ authType = $('input:radio[name=imrHttpAuth]:checked').val();
+ authPassword = $("#imrAuthPassword").val();
+ authName = $("#imrAuthName").val();
+ }
var params = {
command:"getWmsData",
"wmsId": $("#myWMS").val(),
- "wmsUrl" : $("#myURL").val()
+ "wmsUrl" : $("#myURL").val(),
+ "authType" : authType,
+ "authName" : authName,
+ "authPassword" : authPassword
};
$.post("../php/mb_getWmsData.php", params, function (json, status) {
if (status == 'success') {
@@ -285,8 +346,19 @@
function sel(){
var ind = document.form1.selWMS.selectedIndex;
var wmsData = document.form1.selWMS.options[ind].value.split("###");
+ //alert(wmsData[3]);
+ if (wmsData[3] != '') {
+ document.form1.capURL.style.backgroundColor = "#ff0000";
+ document.form1.capURL.style.color = "#ffffff";
+ } else {
+ document.form1.capURL.style.backgroundColor = "#ffffff";
+ document.form1.capURL.style.color = "#000000";
+ }
document.form1.capURL.value = wmsData[1];
document.form1.myWMS.value = wmsData[0];
+ document.form1.imrOldAuthType.value = wmsData[3];
+ document.form1.imrOldAuthName.value = wmsData[4];
+ document.form1.imrOldAuthPassword.value = wmsData[5];
//new for showing metadata - 30.05.2008 AR
document.getElementById("metadatalink").href = "mod_layerMetadata.php?id="+wmsData[2];
document.getElementById("metadatatext").firstChild.nodeValue = "WMS-ID: "+wmsData[0];
@@ -311,8 +383,8 @@
$v = array();
$t = array();
$c = 1;
- //$sql = "SELECT wms_id, wms_title, wms_getcapabilities, wms_upload_url FROM wms ";
- $sql = "SELECT wms.wms_id, wms.wms_title, wms.wms_getcapabilities, wms.wms_upload_url, layer.layer_id FROM wms, layer ";
+ $sql = "SELECT wms.wms_id, wms.wms_title, wms.wms_getcapabilities, wms.wms_upload_url, wms.wms_auth_type, ";
+ $sql .= "wms.wms_username, wms.wms_password, layer.layer_id FROM wms, layer ";
$sql .= "WHERE wms_id IN(";
for($i=0; $i<count($wms_id_own); $i++){
if($wms_id_own[$i] != ''){
@@ -331,8 +403,7 @@
$cnt = 0;
echo "<select name='selWMS' size='15' onchange='sel()'>";
while($row = db_fetch_array($res)){
- //echo "<option value='".$row['wms_id']."###".$row['wms_upload_url']."'>".$row['wms_title']."</option>";
- echo "<option value='".$row['wms_id']."###".$row['wms_upload_url']."###".$row['layer_id']."'>".$row['wms_title']."</option>";
+ echo "<option value='".$row['wms_id']."###".$row['wms_upload_url']."###".$row['layer_id']."###".$row['wms_auth_type']."###".$row['wms_username']."###".$row['wms_password']."'>".$row['wms_title']."</option>";
$cnt++;
}
echo "</select><br /><br />";
@@ -341,14 +412,29 @@
view wms metadata: <a id='metadatalink' href='' onclick="window.open(this.href,'Metadaten','width=500,height=600,left=100,top=200,scrollbars=yes ,dependent=yes'); return false" target="_blank"><span id="metadatatext">no WMS selected</span></a><br><br>
<?php
- echo "Link to the last uploaded Online Resource URL:<br><input type='text' size='120' name='capURL'><br />";
+ echo "Link to the last uploaded Online Resource URL:<br><input type='text' size='120' name='capURL' id='capURL'><br />";
echo "<input type='hidden' name='myWMS' id='myWMS' value=''><br>";
echo "Add the following REQUEST to the Online Resource URL to obtain the Capabilities document:<br>";
echo "<i>(Triple click to select and copy)</i><br>";
echo "REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.1<br>";
echo "REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.1.0<br>";
echo "REQUEST=capabilities&WMTVER=1.0.0<br><br>";
- echo "Link to new WMS Capabilities URL:<br><input size='120' type='text' name='myURL' id='myURL'><br>";
+
+ echo "HTTP Authentication:<br>";
+ echo "<input type='radio' name='imrHttpAuth' value='none' onclick='toggleAuthDivVis();' checked='checked' /> None<br>";
+ echo "<input type='radio' name='imrHttpAuth' value='digest' onclick='toggleAuthDivVis();' /> Digest<br>";
+ echo "<input type='radio' name='imrHttpAuth' value='basic' onclick='toggleAuthDivVis();' /> Basic<br>";
+ echo "<input type='radio' name='imrHttpAuth' value='keep' onclick='toggleAuthDivVis();' /> Keep old values<br>";
+ echo "<input type='hidden' name='imrOldAuthType' id='imrOldAuthType' />";
+ echo "<input type='hidden' name='imrOldAuthName' id = 'imrOldAuthName' />";
+ echo "<input type='hidden' name='imrOldAuthPassword' id = 'imrOldAuthPassword'/>";
+ echo "<input type='hidden' name='imrAuthType' id = 'imrAuthType'/>";
+ echo "<br>";
+ echo "<div id='imrAuthDiv' style='display: none;'>";
+ echo "Username : <input type='text' name='imrAuthName' id='imrAuthName' /><br>";
+ echo "Password : <input type='text' name='imrAuthPassword' id='imrAuthPassword'/><br><br>";
+ echo "</div>";
+ echo "Link to new WMS Capabilities URL:<br><input size='120' type='text' name='myURL' id='myURL'><br>";
if (defined("TWITTER_NEWS") && TWITTER_NEWS == true) {
echo"<input type='checkbox' name='twitter_news' id='twitter_news' checked='checked'>Publish via Twitter<br>";
}
@@ -357,18 +443,34 @@
}
echo"<input type='checkbox' name='compare_dialog' id='compare_dialog'><label for='compare_dialog'>Use compare dialog</label><br>";
echo "<input type='button' value='Preview Capabilities' onclick='window.open(this.form.myURL.value,\"\",\"\")'> ";
- echo "<input type='button' value='Upload Capabilities' onclick='validate()'><br>";
+ echo "<input type='button' value='Upload Capabilities' onclick='validate()'> ";
+ echo "<input type='button' value='Reupload old service' onclick='reupload()'><br>";
if(isset($myURL) && $myURL != ''){
- $mywms = new wms();
- $xml = $mywms->createObjFromXML($myURL);
+ $mywms = new wms();
+
+ if (in_array($imrHttpAuth, array('basic','digest'))) {
+ $auth = array();
+ $auth['username'] = $imrAuthName;
+ $auth['password'] = $imrAuthPassword;
+ $auth['auth_type'] = $imrHttpAuth;
+ $mywms->createObjFromXML($myURL, $auth);
+ } elseif ($imrHttpAuth == 'keep') {
+ $auth = array();
+ $auth['username'] = $imrOldAuthName;
+ $auth['password'] = $imrOldAuthPasswword;
+ $auth['auth_type'] = $imrOldAuthType;
+ $mywms->createObjFromXML($myURL, $auth);
+ } else {
+ $mywms->createObjFromXML($myURL);
+ }
- if($xml == "") {
+ /*if($xml == "") {
echo "<br>WMS could not be loaded, no valid XML. Please check WMS GetCapabilities";
die();
- }
+ }*/
$mywms->optimizeWMS();
echo "<br />";
@@ -381,9 +483,15 @@
}
if(empty($_POST['rss_news'])) {
$mywms->setGeoRss = false;
- }
- $updateObj = $mywms->updateObjInDB($myWMS);
+ }
+ //set values for default variables -> 4 parameters for authenticated services 3 for services without authentication - no metadataUpdate = false, changedLayers = null
+ if ($imrHttpAuth != 'none') {
+ $mywms->updateObjInDB($myWMS,false,null,$auth);
+ } else {
+ $mywms->updateObjInDB($myWMS);
+ }
+
echo "<div id='updateResult'>";
$mywms->displayWMS();
echo "</div>";
More information about the Mapbender_commits
mailing list