[Mapbender-commits] r8797 - in trunk/mapbender: http_auth/http owsproxy/http
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Mar 7 03:28:34 PST 2014
Author: armin11
Date: 2014-03-07 03:28:34 -0800 (Fri, 07 Mar 2014)
New Revision: 8797
Modified:
trunk/mapbender/http_auth/http/index.php
trunk/mapbender/owsproxy/http/index.php
Log:
Bugfix for proxys - external links and legends!
Modified: trunk/mapbender/http_auth/http/index.php
===================================================================
--- trunk/mapbender/http_auth/http/index.php 2014-03-06 15:32:21 UTC (rev 8796)
+++ trunk/mapbender/http_auth/http/index.php 2014-03-07 11:28:34 UTC (rev 8797)
@@ -9,8 +9,11 @@
//database connection
$db = db_connect($DBSERVER, $OWNER, $PW);
db_select_db(DB, $db);
-
+/* * *** conf **** */
$imageformats = array("image/png", "image/gif", "image/jpeg", "image/jpg");
+$width = 400;
+$height = 400;
+/* * *** conf **** */
//control if digest auth is set, if not set, generate the challenge with getNonce()
if (empty($_SERVER['PHP_AUTH_DIGEST'])) {
@@ -168,7 +171,9 @@
break;
case 'getlegendgraphic':
$url = getLegendUrl($wmsId);
- $e = new mb_exception("URL for getlegendgraphic: ");
+ if (isset($reqParams['sld']) && $reqParams['sld'] != "") {
+ $url = $url . getConjunctionCharacter($url) . "SLD=" . $reqParams['sld'];
+ }
if (isset($auth)) {
getImage($url, $auth);
} else {
@@ -234,7 +239,7 @@
}
}
-function throwImage($e)
+/*function throwImage($e)
{
global $reqParams;
if (!$reqParams['width'] || !$reqParams['height']) { //width or height are not set by ows request - maybe for legendgraphics
@@ -250,6 +255,33 @@
ImageString($image, 3, 5, $i * 20, $e[$i], $text_color);
}
responseImage($image);
+}*/
+
+function throwImage($e)
+{
+ global $width, $height;
+ $image = imagecreate($width, $height);
+ $transparent = ImageColorAllocate($image, 155, 155, 155);
+ ImageFilledRectangle($image, 0, 0, $width, $height, $transparent);
+ imagecolortransparent($image, $transparent);
+ $text_color = ImageColorAllocate($image, 233, 14, 91);
+ if (count($e) > 1) {
+ for ($i = 0; $i < count($e); $i++) {
+ $imageString = $e[$i];
+ ImageString($image, 3, 5, $i * 20, $imageString, $text_color);
+ }
+ } else {
+ if (is_array($e)) {
+ $imageString = $e[0];
+ } else {
+ $imageString = $e;
+ }
+ if ($imageString == "") {
+ $imageString = "An unknown error occured!";
+ }
+ ImageString($image, 3, 5, $i * 20, $imageString, $text_color);
+ }
+ responseImage($image);
}
function throwText($e)
@@ -261,6 +293,7 @@
{
global $reqParams;
$format = $reqParams['format'];
+ $format = "image/gif";
if ($format == 'image/png') {
header("Content-Type: image/png");
}
Modified: trunk/mapbender/owsproxy/http/index.php
===================================================================
--- trunk/mapbender/owsproxy/http/index.php 2014-03-06 15:32:21 UTC (rev 8796)
+++ trunk/mapbender/owsproxy/http/index.php 2014-03-07 11:28:34 UTC (rev 8797)
@@ -164,8 +164,11 @@
}
$e = new mb_notice("user id for authorization test: " . getUserFromSession());
$wmsId = $n->getWmsIdFromOwsproxyString($query->getOwsproxyServiceId());
+
//get authentication infos if they are available in wms table! if not $auth = false
-$auth = $n->getAuthInfoOfWMS($wmsId);
+if ($reqParams['request'] !== 'external') {
+ $auth = $n->getAuthInfoOfWMS($wmsId);
+}
if ($auth['auth_type'] == '') {
unset($auth);
}
@@ -242,7 +245,6 @@
$price);
}
if (isset($auth)) {
- #$mb_exception = new mb_exception("auth: ".$auth['auth_type']);
getImage($log_id, $request, $auth);
} else {
getImage($log_id, $request);
@@ -394,6 +396,7 @@
function getImage($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!
@@ -401,9 +404,9 @@
#
if (func_num_args() == 3) { //new for HTTP Authentication
$auth = func_get_arg(2);
- getDocumentContent($log_id, $or, $auth);
+ getDocumentContent($log_id, $or, $header, $auth);
} else {
- getDocumentContent($log_id, $or);
+ getDocumentContent($log_id, $or, $header);
}
}
@@ -418,7 +421,7 @@
global $reqParams;
if (func_num_args() == 3) { //new for HTTP Authentication
$auth = func_get_arg(2);
- getDocumentContent($log_id, $url, $auth);
+ getDocumentContent($log_id, $url, false, $auth);
} else {
getDocumentContent($log_id, $url);
}
@@ -551,23 +554,27 @@
function matchUrls($content)
{
- if (!isset($_SESSION["owsproxyUrls"])) {
- $_SESSION["owsproxyUrls"] = array();
- $_SESSION["owsproxyUrls"]["id"] = array();
- $_SESSION["owsproxyUrls"]["url"] = array();
- }
- $pattern = "/[\"|\'](https*:\/\/[^\"|^\']*)[\"|\']/";
- preg_match_all($pattern, $content, $matches);
- for ($i = 0; $i < count($matches[1]); $i++) {
- $req = $matches[1][$i];
- $notice = new mb_notice("owsproxy found URL " . $i . ": " . $req);
- #$notice = new mb_exception("owsproxy id:".$req);
- $id = registerURL($req);
- $extReq = setExternalRequest($id);
- $notice = new mb_notice("MD5 URL " . $id . " - external link: " . $extReq);
- $content = str_replace($req, $extReq, $content);
- }
- return $content;
+ //check if isset owsproxyUrls else create
+ $owsproxyUrls = Mapbender::session()->get('owsproxyUrls');
+ if ($owsproxyUrls == false) {
+ $e = new mb_notice("owsproxyUrls does not exist - create it!");
+ $owsproxyUrls = array();
+ $owsproxyUrls['id'] = array();
+ $owsproxyUrls['url'] = array();
+ Mapbender::session()->set('owsproxyUrls',$owsproxyUrls);
+ }
+ $pattern = "/[\"|\'](https*:\/\/[^\"|^\']*)[\"|\']/";
+ preg_match_all($pattern, $content, $matches);
+ for ($i = 0; $i < count($matches[1]); $i++) {
+ $req = $matches[1][$i];
+ $notice = new mb_notice("owsproxy found URL " . $i . ": " . $req);
+ #$notice = new mb_exception("owsproxy id:".$req);
+ $id = registerURL($req);
+ $extReq = setExternalRequest($id);
+ $notice = new mb_notice("MD5 URL " . $id . " - external link: " . $extReq);
+ $content = str_replace($req, $extReq, $content);
+ }
+ return $content;
}
function setExternalRequest($id)
@@ -580,31 +587,32 @@
function getExternalRequest($id)
{
- for ($i = 0; $i < count($_SESSION["owsproxyUrls"]["url"]); $i++) {
- if ($id == $_SESSION["owsproxyUrls"]["id"][$i]) {
- $cUrl = $_SESSION["owsproxyUrls"]["url"][$i];
- $query_string = removeOWSGetParams($_SERVER["QUERY_STRING"]);
- if ($query_string != '') {
- $cUrl .= getConjunctionCharacter($cUrl) . $query_string;
- }
- $metainfo = get_headers($cUrl, 1);
- // just for the stupid InternetExplorer
- header('Pragma: private');
- header('Cache-control: private, must-revalidate');
-
- header("Content-Type: " . $metainfo['Content-Type']);
-
- $content = getDocumentContent(false, $cUrl);
- #$content = matchUrls($content);
- echo $content;
- }
- }
+ //get owsproxyUrls from session
+ $owsproxyUrls = Mapbender::session()->get('owsproxyUrls');
+ for ($i = 0; $i < count($owsproxyUrls["url"]); $i++) {
+ if ($id == $owsproxyUrls["id"][$i]) {
+ $cUrl = $owsproxyUrls["url"][$i];
+ $query_string = removeOWSGetParams($_SERVER["QUERY_STRING"]);
+ if ($query_string != '') {
+ $cUrl .= getConjunctionCharacter($cUrl) . $query_string;
+ }
+ $metainfo = get_headers($cUrl, 1);
+ // just for the stupid InternetExplorer
+ header('Pragma: private');
+ header('Cache-control: private, must-revalidate');
+ header("Content-Type: " . $metainfo['Content-Type']);
+ //$content = getDocumentContent(false, $cUrl, headers_list());
+ $content = getDocumentContent(false, $cUrl, $metainfo);
+ #$content = matchUrls($content);
+ } else {
+ $e = new mb_exception("owsproxy/http/index.php: No key found for this URL in session!");
+ }
+ }
}
function removeOWSGetParams($query_string)
{
$r = preg_replace("/.*request=external&/", "", $query_string);
- #return $r;
return "";
}
@@ -627,18 +635,22 @@
function registerUrl($url)
{
- if (!in_array($url, $_SESSION["owsproxyUrls"]["url"])) {
- $id = md5($url);
- array_push($_SESSION["owsproxyUrls"]["url"], $url);
- array_push($_SESSION["owsproxyUrls"]["id"], $id);
- } else {
- for ($i = 0; $i < count($_SESSION["owsproxyUrls"]["url"]); $i++) {
- if ($url == $_SESSION["owsproxyUrls"]["url"][$i]) {
- $id = $_SESSION["owsproxyUrls"]["id"][$i];
- }
- }
- }
- return $id;
+ //get owsproxy urls from session
+ //
+ $owsproxyUrls = Mapbender::session()->get('owsproxyUrls');
+ if (!in_array($url, $owsproxyUrls["url"])) {
+ $id = md5($url);
+ array_push($owsproxyUrls["url"], $url);
+ array_push($owsproxyUrls["id"], $id);
+ } else {
+ for ($i = 0; $i < count($owsproxyUrls["url"]); $i++) {
+ if ($url == $owsproxyUrls["url"][$i]) {
+ $id = $owsproxyUrls["id"][$i];
+ }
+ }
+ }
+ Mapbender::session()->set('owsproxyUrls',$owsproxyUrls);
+ return $id;
}
function getCapabilities($url)
@@ -680,7 +692,13 @@
$sql .= "ON layer_style.fkey_layer_id = layer.layer_id ";
$sql .= "WHERE layer.layer_name = $2 AND layer.fkey_wms_id = $1 ";
$sql .= "AND layer_style.name = $3 AND layer_style.legendurlformat = $4";
- $v = array($wmsid, $reqParams['layer'], $reqParams['style'], $reqParams['format']);
+ if ($reqParams['style'] == '') {
+ $style = 'default';
+ } else {
+ $style = $reqParams['style'];
+ }
+ //$v = array($wmsid, $reqParams['layer'], $reqParams['style'], $reqParams['format']);
+ $v = array($wmsid, $reqParams['layer'], $style, $reqParams['format']);
$t = array("i", "s", "s", "s");
$res = db_prep_query($sql, $v, $t);
if ($row = db_fetch_array($res)) {
@@ -813,11 +831,11 @@
return $ret;
}
-function getDocumentContent($log_id, $url)
+function getDocumentContent($log_id, $url, $header = false)
{
global $reqParams, $n;
- if (func_num_args() == 3) { //new for HTTP Authentication
- $auth = func_get_arg(2);
+ if (func_num_args() == 4) { //new for HTTP Authentication
+ $auth = func_get_arg(3);
$d = new connector($url, $auth);
} else {
$d = new connector($url);
@@ -877,7 +895,10 @@
}
return true;
} else {
- return $content;
+ if (header !== false) {
+ header($header);
+ }
+ echo $content;
}
}
More information about the Mapbender_commits
mailing list