[Mapbender-commits] r9147 - in trunk/mapbender: http/classes http_auth/http
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Jan 21 07:27:33 PST 2015
Author: verenadiewald
Date: 2015-01-21 07:27:33 -0800 (Wed, 21 Jan 2015)
New Revision: 9147
Modified:
trunk/mapbender/http/classes/class_administration.php
trunk/mapbender/http_auth/http/index.php
Log:
some improvements for logging in http auth
Modified: trunk/mapbender/http/classes/class_administration.php
===================================================================
--- trunk/mapbender/http/classes/class_administration.php 2015-01-13 09:13:13 UTC (rev 9146)
+++ trunk/mapbender/http/classes/class_administration.php 2015-01-21 15:27:33 UTC (rev 9147)
@@ -1182,8 +1182,9 @@
*/
function logWmsProxyRequest($wms_id,$user_id,$getmap,$price){
- $sql = "INSERT INTO mb_proxy_log (fkey_wms_id,fkey_mb_user_id, request, pixel, price) VALUES ($1, $2, $3, $4,$5)";
- $t = array("i","i","s","i","r");
+ $sql = "INSERT INTO mb_proxy_log (fkey_wms_id,fkey_mb_user_id, request, pixel, price, got_result)"
+ ." VALUES ($1, $2, $3, $4, $5, $6)";
+ $t = array("i","i","s","i","r", "i");
#extract height and width
#use regexpr
$pattern_height = '~HEIGHT=(\d+)&~i';
@@ -1193,8 +1194,8 @@
$width=intval($sub_width[1]);
$height=intval($sub_height[1]);
$pixel=intval($width*$height);
- $price=$pixel*$price/1000000;
- $v = array(intval($wms_id),intval($user_id),$getmap,$pixel,$price);
+ $pricePx=$pixel*$price/1000000;
+ $v = array(intval($wms_id),intval($user_id),$getmap,$pixel,$pricePx, 0);
#echo print_r($v,true)."<br>";
#var_dump($v);
#echo $sql."<br>";
@@ -1216,11 +1217,11 @@
#}
}
- function logFullWmsProxyRequest($wms_id,$user_id,$getmap,$price){
+ function logFullWmsProxyRequest($wms_id,$user_id,$getmap,$price,$got_result,$set0Pixels=false){
$sql = "INSERT INTO mb_proxy_log "
- ."(fkey_wms_id,fkey_mb_user_id, request, pixel, price, layer_featuretype_list, request_type) "
- ."VALUES ($1, $2, $3, $4, $5, $6, 'getMap')";
- $t = array("i","i","s","i","r","s");
+ ."(fkey_wms_id,fkey_mb_user_id, request, pixel, price, layer_featuretype_list, request_type, got_result) "
+ ."VALUES ($1, $2, $3, $4, $5, $6, 'getMap', $7)";
+ $t = array("i","i","s","i","r","s","i");
#extract height and width
#use regexpr
$pattern_height = '~HEIGHT=(\d+)&~i';
@@ -1232,9 +1233,9 @@
$layers = explode("=", $sub_layers[0]);
$width=intval($sub_width[1]);
$height=intval($sub_height[1]);
- $pixel=intval($width*$height);
- $price=$pixel*$price/1000000;
- $v = array(intval($wms_id),intval($user_id),$getmap,$pixel,$price,isset($layers[1]) ? urldecode($layers[1]) : '');
+ $pixel= $got_result === -1 ? 0 : ($set0Pixels ? 0 : intval($width*$height));
+ $pricePx=$pixel*$price/1000000;
+ $v = array(intval($wms_id),intval($user_id),$getmap,$pixel,$pricePx,isset($layers[1]) ? urldecode($layers[1]) : '',$got_result);
#echo print_r($v,true)."<br>";
#var_dump($v);
#echo $sql."<br>";
@@ -1260,8 +1261,8 @@
}
}
function updateWmsLog($got_result, $error_message, $error_mime_type, $log_id){
- $sql = "UPDATE mb_proxy_log SET got_result=$1"
- .",error_message=$2,error_mime_type=$3 WHERE log_id=$4";
+ $sql = "UPDATE mb_proxy_log SET got_result=$1,error_message=$2,error_mime_type=$3"
+ . ($got_result === -1 ? ',pixel=0' : '') ." WHERE log_id=$4";
$t = array("i","s","s","i");
$v = array($got_result, $error_message, $error_mime_type, $log_id);
$res = db_prep_query($sql,$v,$t) or die(db_error());
Modified: trunk/mapbender/http_auth/http/index.php
===================================================================
--- trunk/mapbender/http_auth/http/index.php 2015-01-13 09:13:13 UTC (rev 9146)
+++ trunk/mapbender/http_auth/http/index.php 2015-01-21 15:27:33 UTC (rev 9147)
@@ -143,10 +143,20 @@
throwE("GetFeatureInfo permission denied on layer with id" . $layerId);
die();
}
+ //Ergaenzungen secured UMN Requests
+ $log_id = false;
+ if ($n->getWmsfiLogTag($arrayOnlineresources['wms_id']) == 1) {
+ #do log to db
+ #get price out of db
+ $price = intval($n->getWmsfiPrice($arrayOnlineresources['wms_id']));
+ $log_id = $n->logWmsGFIProxyRequest($arrayOnlineresources['wms_id'], $_SESSION['mb_user_id'], $request,
+ $price);
+ }
+
if (isset($auth)) {
- getFeatureInfo($request, $auth);
+ getFeatureInfo($log_id, $request, $auth);
} else {
- getFeatureInfo($request);
+ getFeatureInfo($log_id, $request);
}
break;
case 'getmap':
@@ -159,18 +169,20 @@
}
$query->setParam("layers", urldecode($layers));
$request = $query->getRequest();
+ // Ergaenzungen secured UMN Requests
#log proxy requests
+ $log_id = false;
if ($n->getWmsLogTag($wmsId) == 1) {
#do log to db
#TODO read out size of bbox and calculate price
#get price out of db
$price = intval($n->getWmsPrice($wmsId));
- $n->logWmsProxyRequest($wmsId, $userInformation[0], $request, $price);
+ $log_id = $n->logFullWmsProxyRequest($arrayOnlineresources['wms_id'], $userInformation[0], $request, $price, 0);
}
if (isset($auth)) {
- getImage($request, $auth);
+ getImageII($log_id, $request, $auth);
} else {
- getImage($request);
+ getImageII($log_id, $request);
}
break;
case 'getlegendgraphic':
@@ -349,21 +361,43 @@
}
/**
+ * fetch and returns an image to client
+ *
+ * @param string the original url of the image to send
+ */
+function getImageII($log_id, $or)
+{
+ global $reqParams;
+ $header = "Content-Type: " . $reqParams['format'];
+ #log the image_requests to database
+ #log the following to table mb_proxy_log
+ #timestamp,user_id,getmaprequest,amount pixel,price - but do this only for wms to log - therefor first get log tag out of wms!
+ #
+ #
+ if (func_num_args() == 3) { //new for HTTP Authentication
+ $auth = func_get_arg(2);
+ getDocumentContentII($log_id, $or, $header, $auth);
+ } else {
+ getDocumentContentII($log_id, $or, $header);
+ }
+}
+
+/**
* fetchs and returns the content of the FeatureInfo Response
*
* @param string the url of the FeatureInfoRequest
* @return string the content of the FeatureInfo document
*/
-function getFeatureInfo($url)
+function getFeatureInfo($log_id, $url)
{
global $reqParams;
$e = new mb_notice("owsproxy: Try to fetch FeatureInfoRequest: " . $url);
header("Content-Type: " . $reqParams['info_format']);
- if (func_num_args() == 2) { //new for HTTP Authentication
- $auth = func_get_arg(1);
- echo getDocumentContent($url, $auth);
+ if (func_num_args() == 3) { //new for HTTP Authentication
+ $auth = func_get_arg(2);
+ getDocumentContent($log_id, $url, false, $auth);
} else {
- echo getDocumentContent($url);
+ getDocumentContent($log_id, $url);
}
}
@@ -647,15 +681,75 @@
return $ret;
}
-function getDocumentContent($url)
+function getDocumentContent($log_id, $url, $header = false)
{
- if (func_num_args() == 2) { //new for HTTP Authentication
- $auth = func_get_arg(1);
+ global $reqParams, $n;
+ if (func_num_args() == 4) { //new for HTTP Authentication
+ $auth = func_get_arg(3);
$d = new connector($url, $auth);
} else {
$d = new connector($url);
}
- return $d->file;
+ $content = $d->file;
+ if (strtoupper($reqParams["request"]) == "GETMAP") { // getmap
+ $pattern_exc = '~EXCEPTION~i';
+ preg_match($pattern_exc, $content, $exception);
+ if (!$content) {
+ if ($log_id != null && is_integer($log_id)) {
+ $n->updateWmsLog(0, "Mb2OWSPROXY - unable to load: " . $url, "text/plain", $log_id);
+ }
+ header("Content-Type: text/plain");
+ echo "Mb2OWSPROXY - unable to load: " . $url;
+ } else if (count($exception) > 0) {
+ if ($log_id != null && is_integer($log_id)) {
+ $n->updateWmsLog(0, $content, $reqParams["exceptions"], $log_id);
+ }
+ header("Content-Type: " . $reqParams["exceptions"]);
+ echo $content;
+ } else {
+ $source = new Imagick();
+ $source->readImageBlob($content);
+ $numColors = $source->getImageColors();
+ if ($log_id != null && is_integer($log_id)) {
+ $n->updateWmsLog($numColors <= 1 ? -1 : 1, null, null, $log_id);
+ }
+ header("Content-Type: " . $reqParams['format']);
+ echo $content;
+ }
+ return true;
+ } else if (strtoupper($reqParams["request"]) == "GETFEATUREINFO") { // getmap
+// header("Content-Type: ".$reqParams['info_format']);
+// $content = matchUrls($content);
+// echo $content;
+ $pattern_exc = '~EXCEPTION~i';
+ preg_match($pattern_exc, $content, $exception);
+ if (!$content) {
+ if ($log_id != null) {
+ $n->updateWmsFiLog("Mb2OWSPROXY - unable to load: " . $url, "text/plain", $log_id);
+ }
+ header("Content-Type: text/plain");
+ echo "Mb2OWSPROXY - unable to load: " . $url;
+ } else if (count($exception) > 0) {
+ if ($log_id != null) {
+ $n->updateWmsFiLog($content, "application/xml", $log_id);
+ }
+ header("Content-Type: application/xml");
+ echo $content;
+ } else {
+ header("Content-Type: " . $reqParams['info_format']);
+ if ($log_id != null) {
+ $n->updateWmsFiLog(null, null, $log_id);
+ }
+ $content = matchUrls($content);
+ echo $content;
+ }
+ return true;
+ } else {
+ if (header !== false) {
+ header($header);
+ }
+ echo $content;
+ }
}
//**********************************************************************************************
@@ -680,4 +774,75 @@
return false;
}
+function getDocumentContentII($log_id, $url, $header = false)
+{
+ global $reqParams, $n;
+ if (func_num_args() == 4) { //new for HTTP Authentication
+ $auth = func_get_arg(3);
+ $d = new connector($url, $auth);
+ } else {
+ $d = new connector($url);
+ }
+ $content = $d->file;
+ if (strtoupper($reqParams["request"]) == "GETMAP") { // getmap
+ $pattern_exc = '~EXCEPTION~i';
+ preg_match($pattern_exc, $content, $exception);
+ if (!$content) {
+ if ($log_id != null && is_integer($log_id)) {
+ $n->updateWmsLog(0, "Mb2OWSPROXY - unable to load: " . $url, "text/plain", $log_id);
+ }
+ header("Content-Type: text/plain");
+ echo "Mb2OWSPROXY - unable to load: " . $url;
+ } else if (count($exception) > 0) {
+ if ($log_id != null && is_integer($log_id)) {
+ $n->updateWmsLog(0, $content, $reqParams["exceptions"], $log_id);
+ }
+ header("Content-Type: " . $reqParams["exceptions"]);
+ echo $content;
+ } else {
+ $source = new Imagick();
+ $source->readImageBlob($content);
+ $numColors = $source->getImageColors();
+ if ($log_id != null && is_integer($log_id)) {
+ $n->updateWmsLog($numColors <= 1 ? -1 : 1, null, null, $log_id);
+ }
+ header("Content-Type: " . $reqParams['format']);
+ echo $content;
+ }
+ return true;
+ } else if (strtoupper($reqParams["request"]) == "GETFEATUREINFO") { // getmap
+// header("Content-Type: ".$reqParams['info_format']);
+// $content = matchUrls($content);
+// echo $content;
+ $pattern_exc = '~EXCEPTION~i';
+ preg_match($pattern_exc, $content, $exception);
+ if (!$content) {
+ if ($log_id != null) {
+ $n->updateWmsFiLog("Mb2OWSPROXY - unable to load: " . $url, "text/plain", $log_id);
+ }
+ header("Content-Type: text/plain");
+ echo "Mb2OWSPROXY - unable to load: " . $url;
+ } else if (count($exception) > 0) {
+ if ($log_id != null) {
+ $n->updateWmsFiLog($content, "application/xml", $log_id);
+ }
+ header("Content-Type: application/xml");
+ echo $content;
+ } else {
+ header("Content-Type: " . $reqParams['info_format']);
+ if ($log_id != null) {
+ $n->updateWmsFiLog(null, null, $log_id);
+ }
+ $content = matchUrls($content);
+ echo $content;
+ }
+ return true;
+ } else {
+ if (header !== false) {
+ header($header);
+ }
+ echo $content;
+ }
+}
+
?>
More information about the Mapbender_commits
mailing list