[Mapbender-commits] r1835 - branches/mapbender_sld/http/extensions

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Nov 23 08:44:02 EST 2007


Author: christoph
Date: 2007-11-23 08:44:02 -0500 (Fri, 23 Nov 2007)
New Revision: 1835

Added:
   branches/mapbender_sld/http/extensions/jqjson.js
Modified:
   branches/mapbender_sld/http/extensions/ext_featureInfoTunnel.php
   branches/mapbender_sld/http/extensions/geom2wfst.php
   branches/mapbender_sld/http/extensions/jquery.js
   branches/mapbender_sld/http/extensions/json.js
   branches/mapbender_sld/http/extensions/markResult.php
Log:
new or updated extensions

Modified: branches/mapbender_sld/http/extensions/ext_featureInfoTunnel.php
===================================================================
--- branches/mapbender_sld/http/extensions/ext_featureInfoTunnel.php	2007-11-23 13:43:16 UTC (rev 1834)
+++ branches/mapbender_sld/http/extensions/ext_featureInfoTunnel.php	2007-11-23 13:44:02 UTC (rev 1835)
@@ -16,20 +16,23 @@
 # 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__)."/../../conf/mapbender.conf");
 require_once("../classes/class_stripRequest.php");
 require_once("../classes/class_connector.php");
-import_request_variables("PG");
-session_start();
 $mr = new stripRequest(urldecode($_REQUEST["url"]));
 $nmr = $mr->encodeGET();
-
-$x = new connector($nmr);
-if (empty($x->file)) {
-     echo "<html><head><title>Kein Abfrageergebnis</title></head><body
-onload='window.close();'></body></html>";
-} 
-else {
-echo $x->file;
+$isOwsproxyRequest = (mb_strpos($nmr,OWSPROXY) === 0);
+if($isOwsproxyRequest){
+	header("Location: ".$nmr);
 }
+else{
+	$x = new connector($nmr);
+	if (empty($x->file)) {
+		//close window if featureInfo has no result
+		echo "<body onLoad=\"javascript:window.close()\">";
+	} 
+	else {
+		echo $x->file;
+	}	
+}
 ?>
\ No newline at end of file

Modified: branches/mapbender_sld/http/extensions/geom2wfst.php
===================================================================
--- branches/mapbender_sld/http/extensions/geom2wfst.php	2007-11-23 13:43:16 UTC (rev 1834)
+++ branches/mapbender_sld/http/extensions/geom2wfst.php	2007-11-23 13:44:02 UTC (rev 1835)
@@ -17,20 +17,100 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
+/**
+ * $_REQUEST["url"]
+ * $_REQUEST["filter"] 
+ */
 
+$wfs_conf_id = $_REQUEST["wfs_conf_id"];
+$featuretype_name = $_REQUEST["featuretype_name"];
+
+session_start();
 require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
 require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
+$con = db_connect(DBSERVER,OWNER,PW);
+db_select_db(DB,$con);
 
+function isValidVarName ($varname) {
+	if (preg_match("/[\$]{1}_[a-z]+\[\"[a-z_]+\"\]/i", $varname) != 0) {
+		return true;
+	}
+	return false;
+}
 
+function addParameterToFilter($filter, $featuretype_name, $wfs_conf_id) {
+	
+	/* wfs_conf_element */
+	$sql = "SELECT * FROM wfs_conf_element ";
+	$sql .= "JOIN wfs_element ON wfs_conf_element.f_id = wfs_element.element_id ";
+	$sql .= "WHERE wfs_conf_element.fkey_wfs_conf_id = $1 ";
+	$sql .= "ORDER BY wfs_conf_element.f_respos";
+			
+	$v = array($wfs_conf_id);
+	$t = array('i');
+	$res = db_prep_query($sql,$v,$t);
+	while($row = db_fetch_array($res)){
+		if (!empty($row["f_auth_varname"])) {
+			$auth_varname = $row["f_auth_varname"];
+			$element_name = $row["element_name"];
+		}
+	}
+	if (!empty($auth_varname)) {
+		$e = new mb_notice("geom2wfst: addParameterToFilter: auth_varname = " . $auth_varname);
+		$e = new mb_notice("geom2wfst: addParameterToFilter: element_name = " . $element_name);
+
+		if (isValidVarName($auth_varname)) {
+			$user = eval("return " . $auth_varname . ";");
+			
+			$e = new mb_notice("geom2wfst: addParameterToFilter: user should be " . $_SESSION["mb_user_id"]);
+			$e = new mb_notice("geom2wfst: addParameterToFilter: user is " . $user);
+			$patternUpdate = "(<wfs:Update[^>]*>)";
+			$patternInsert = "(<wfs:Insert[^>]*>)";
+			$patternDelete = "(<wfs:Delete[^>]*>)";
+
+			$e = new mb_notice("geom2wfst: addParameterToFilter: old filter was: " . $filter);
+
+			// insert: store authenticated user in database 
+			if (eregi($patternInsert, $filter)) {
+				$pattern = "(<" . $featuretype_name . ">)";
+				$replacement = "\\1<" . $element_name . ">" . $user . "</" . $element_name . ">";
+				$filter = eregi_replace($pattern, $replacement, $filter);
+			}
+			// update or delete: disallow access for other users
+			if (eregi($patternDelete, $filter) || eregi($patternUpdate, $filter)) {
+				$pattern = "(<ogc:Filter>)(<ogc:FeatureId[^>]*>)(</ogc:filter>)";
+				$replacement = "\\1<And>\\2<ogc:PropertyIsEqualTo><ogc:PropertyName>" . $element_name . "</ogc:PropertyName><ogc:Literal>" . $user . "</ogc:Literal></ogc:PropertyIsEqualTo></And>\\3"; 
+				$filter = eregi_replace($pattern, $replacement, $filter);
+			}
+			$e = new mb_notice("geom2wfst: addParameterToFilter: new filter is: " . $filter);
+		}
+		else {
+			$e = new mb_exception("geom2wfst: addParameterToFilter: invalid auth_varname (".$auth_varname.")");
+		}
+	}
+	else {
+		$e = new mb_notice("geom2wfst: addParameterToFilter: no auth_varname.");
+	}
+	return $filter;
+			
+}
+function checkVal($value){
+	$pattern = array("'",'"',"--");
+	$r = str_replace($pattern, "", $value);	
+	$r = addslashes($r);
+	return $r;
+}
+
+
 function sepNameSpace($s){
-	$c = strpos($s,":"); 
-	if($c>0) return substr($s,$c+1);
+	$c = mb_strpos($s,":"); 
+	if($c>0) return mb_substr($s,$c+1);
 	return $s;
 }
 function sendToHost($host,$port,$method,$path,$data){
 	$buf = '';
     if (empty($method)) $method = 'POST';
-    $method = strtoupper($method);
+    $method = mb_strtoupper($method);
     $fp = fsockopen($host, $port);
     fputs($fp, "$method $path HTTP/1.1\r\n");
     fputs($fp, "Host: $host\r\n");
@@ -52,71 +132,26 @@
 
 $path = $arURL["path"];
 $method = "POST";
-$filter = stripslashes($_REQUEST["filter"]);
+$filter = stripslashes(addParameterToFilter($_REQUEST["filter"], $featuretype_name, $wfs_conf_id));
 
 $data = sendToHost($host,$port,$method,html_entity_decode($path),$filter);
 
-$data = eregi_replace("^[^<]*", "", $data);
-$data = eregi_replace("[^>]*$", "", $data);
-
-/*
-$parser = xml_parser_create(CHARSET);
-xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
-xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
-xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
-xml_parse_into_struct($parser,$data,$values,$tags);
-$code = xml_get_error_code ($parser);
-if ($code) {
-	$result = "Error " . $code . " (" . xml_error_string($code) .  ")";
-	$error = true;
-}
-xml_parser_free($parser);
-if (!$error) {
-	$section;
-	foreach ($values as $element) {
-		$element[tag] = sepNameSpace($element[tag]);
-		if(strtoupper($element[tag]) == "SERVICEEXCEPTIONREPORT" && $element[type] == "open"){
-			$section = "serviceexceptionreport";
-		}
-		if ($section == "serviceexceptionreport" && strtoupper($element[tag]) == "SERVICEEXCEPTION") {
-//			$result = $element[value];
-			$result = "An error occured.";
-			$error = true;
-		}
-		if(strtoupper($element[tag]) == "STATUS" && $element[type] == "open"){
-			$section = "status";
-		}
-		if ($section == "status" && strtoupper($element[tag]) == "SUCCESS") {
-			$result = "Success.";
-			$error = false;
-		}
-	}
-}
-
-
-if ($error) {
-	$e = new mb_exception('WFS error at: host: '.$host.' port: '.$port.' filter: '.$_REQUEST["filter"].' - error message: '.$result);
-}
-else {
-	$e = new mb_exception('WFS successfull host: '.$host.' port: '.$port.' filter: '.$_REQUEST["filter"]);
-}
-*/
-
-$e = new mb_exception('WFS-T: '.$filter);
-
-header('Content-type: application/json');
+$data = mb_eregi_replace("^[^<]*", "", $data);
+$data = mb_eregi_replace("[^>]*$", "", $data);
+header('Content-type: text/html');
 echo "{";  
-if (stristr($data, "success") !== false) {
+if (mb_strpos(mb_strtoupper($data), "SUCCESS") !== false) {
 	$response = "success";
-	if (ereg("^.*ogc:FeatureId fid=\"(.+)\"/>.*$", $data)) {
-		$fid = ereg_replace("^.*ogc:FeatureId fid=\"(.+)\"/>.*$", "\\1", $data);
+	if (mb_ereg("^.*ogc:FeatureId fid=\"(.+)\"/>.*$", $data)) {
+		$fid = mb_ereg_replace("^.*ogc:FeatureId fid=\"(.+)\"/>.*$", "\\1", $data);
 		echo "\"fid\":\"".$fid."\",";
 	}
-	echo "\"success confirmation\":\"".str_replace("\"", "'", str_replace("\n", "", str_replace("\r", "", $data)))."\",";
+	echo "\"success confirmation\":\"".preg_replace("/\"/", "'", preg_replace("/\n/", "", preg_replace("/\r/", "", $data)))."\",";
 }
 else {
 	$response = "error";
 	echo "\"error message\":\"".addslashes($data)."\",";
 }
 echo "\"response\":\"".$response."\"}";
+$notice = new mb_notice("response:".$response);
 ?>
\ No newline at end of file

Added: branches/mapbender_sld/http/extensions/jqjson.js
===================================================================
--- branches/mapbender_sld/http/extensions/jqjson.js	                        (rev 0)
+++ branches/mapbender_sld/http/extensions/jqjson.js	2007-11-23 13:44:02 UTC (rev 1835)
@@ -0,0 +1,96 @@
+(function ($) {
+    var m = {
+            '\b': '\\b',
+            '\t': '\\t',
+            '\n': '\\n',
+            '\f': '\\f',
+            '\r': '\\r',
+            '"' : '\\"',
+            '\\': '\\\\'
+        },
+        s = {
+            'array': function (x) {
+                var a = ['['], b, f, i, l = x.length, v;
+                for (i = 0; i < l; i += 1) {
+                    v = x[i];
+                    f = s[typeof v];
+                    if (f) {
+                        v = f(v);
+                        if (typeof v == 'string') {
+                            if (b) {
+                                a[a.length] = ',';
+                            }
+                            a[a.length] = v;
+                            b = true;
+                        }
+                    }
+                }
+                a[a.length] = ']';
+                return a.join('');
+            },
+            'boolean': function (x) {
+                return String(x);
+            },
+            'null': function (x) {
+                return "null";
+            },
+            'number': function (x) {
+                return isFinite(x) ? String(x) : 'null';
+            },
+            'object': function (x) {
+                if (x) {
+                    if (x instanceof Array) {
+                        return s.array(x);
+                    }
+                    var a = ['{'], b, f, i, v;
+                    for (i in x) {
+                        v = x[i];
+                        f = s[typeof v];
+                        if (f) {
+                            v = f(v);
+                            if (typeof v == 'string') {
+                                if (b) {
+                                    a[a.length] = ',';
+                                }
+                                a.push(s.string(i), ':', v);
+                                b = true;
+                            }
+                        }
+                    }
+                    a[a.length] = '}';
+                    return a.join('');
+                }
+                return 'null';
+            },
+            'string': function (x) {
+                if (/["\\\x00-\x1f]/.test(x)) {
+                    x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
+                        var c = m[b];
+                        if (c) {
+                            return c;
+                        }
+                        c = b.charCodeAt();
+                        return '\\u00' +
+                            Math.floor(c / 16).toString(16) +
+                            (c % 16).toString(16);
+                    });
+                }
+                return '"' + x + '"';
+            }
+        };
+
+	$.toJSON = function(v) {
+		var f = isNaN(v) ? s[typeof v] : s['number'];
+		if (f) return f(v);
+	};
+	
+	$.parseJSON = function(v, safe) {
+		if (safe === undefined) safe = $.parseJSON.safe;
+		if (safe && !/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(v))
+			return undefined;
+		return eval('('+v+')');
+	};
+	
+	$.parseJSON.safe = false;
+
+})(jQuery);

Modified: branches/mapbender_sld/http/extensions/jquery.js
===================================================================
--- branches/mapbender_sld/http/extensions/jquery.js	2007-11-23 13:43:16 UTC (rev 1834)
+++ branches/mapbender_sld/http/extensions/jquery.js	2007-11-23 13:44:02 UTC (rev 1835)
@@ -37,6 +37,7 @@
 		else
 			return new jQuery( c ).find( a );
 	}
+	
 	return this.setArray(
 		// HANDLE: $(array)
 		a.constructor == Array && a ||
@@ -1043,6 +1044,7 @@
 
 		// And combine the results
 		jQuery.merge( done, ret );
+
 		return done;
 	},
 

Modified: branches/mapbender_sld/http/extensions/json.js
===================================================================
--- branches/mapbender_sld/http/extensions/json.js	2007-11-23 13:43:16 UTC (rev 1834)
+++ branches/mapbender_sld/http/extensions/json.js	2007-11-23 13:44:02 UTC (rev 1835)
@@ -4,12 +4,13 @@
 
     This file adds these methods to JavaScript:
 
-        array.toJSONString()
-        boolean.toJSONString()
-        date.toJSONString()
-        number.toJSONString()
-        object.toJSONString()
-        string.toJSONString()
+		toJSONString(obj)
+        arrayToJSONString(obj)
+        booleanToJSONString(obj)
+        dateToJSONString(obj)
+        numberToJSONString(obj)
+        objectToJSONString(obj)
+        stringToJSONString(obj)
             These methods produce a JSON text from a JavaScript value.
             It must not contain any cyclical references. Illegal values
             will be excluded.
@@ -18,7 +19,7 @@
             add a toJSONString method to any date object to get a different
             representation.
 
-        string.parseJSON(filter)
+        parseJSON(string, filter)
             This method parses a JSON text to produce an object or
             array. It can throw a SyntaxError exception.
 
@@ -41,153 +42,173 @@
     JavaScript Programming Language in the Fourth Edition of the
     ECMAScript standard in 2007.
 */
-if (!Object.prototype.toJSONString) {
-    Array.prototype.toJSONString = function () {
-        var a = ['['], b, i, l = this.length, v;
+function arrayToJSONString(ao){
+	var a = ['['], b, i, l = ao.length, v;
+	
+	function p(s) {
+		if (b) {
+			a.push(',');
+		}
+		a.push(s);
+		b = true;
+	}
 
-        function p(s) {
-            if (b) {
-                a.push(',');
-            }
-            a.push(s);
-            b = true;
-        }
+	for (i = 0; i < l; i += 1) {
+		v = ao[i];
+		switch (typeof v) {
+		case 'undefined':
+		case 'function':
+		case 'unknown':
+			break;
+		case 'object':
+			if (v) {
+				p(toJSONString(v));
+			} else {
+				p("null");
+			}
+			break;
+		default:
+			p(toJSONString(v));
+		}
+	}
+	a.push(']');
+	return a.join('');		
+}
+function boolToJSONString(bo) {
+	return String(bo);
+};
 
-        for (i = 0; i < l; i += 1) {
-            v = this[i];
-            switch (typeof v) {
-            case 'undefined':
-            case 'function':
-            case 'unknown':
-                break;
-            case 'object':
-                if (v) {
-                    if (typeof v.toJSONString === 'function') {
-                        p(v.toJSONString());
-                    }
-                } else {
-                    p("null");
-                }
-                break;
-            default:
-                p(v.toJSONString());
-            }
-        }
-        a.push(']');
-        return a.join('');
-    };
+function dateToJSONString(dao) {
+	function f(n) {
+		return n < 10 ? '0' + n : n;
+	}
 
-    Boolean.prototype.toJSONString = function () {
-        return String(this);
-    };
+	return '"' + dao.getFullYear() + '-' +
+		f(dao.getMonth() + 1) + '-' +
+		f(dao.getDate()) + 'T' +
+		f(dao.getHours()) + ':' +
+		f(dao.getMinutes()) + ':' +
+		f(dao.getSeconds()) + '"';
+};
+   
+function numberToJSONString(no) {
+	return isFinite(no) ? String(no) : "null";
+};
 
-    Date.prototype.toJSONString = function () {
-
-        function f(n) {
-            return n < 10 ? '0' + n : n;
-        }
-
-        return '"' + this.getFullYear() + '-' +
-                f(this.getMonth() + 1) + '-' +
-                f(this.getDate()) + 'T' +
-                f(this.getHours()) + ':' +
-                f(this.getMinutes()) + ':' +
-                f(this.getSeconds()) + '"';
-    };
-
-    Number.prototype.toJSONString = function () {
-        return isFinite(this) ? String(this) : "null";
-    };
-
-    Object.prototype.toJSONString = function () {
+function objectToJSONString(ob) {
 	
-        var a = ['{'], b, i, v;
+	var a = ['{'], b, i, v;
 
-        function p(s) {
-            if (b) {
-                a.push(',');
-            }
-            a.push(i.toJSONString(), ':', s);
-            b = true;
-        }
+	function p(s) {
+		if (b) {
+			a.push(',');
+		}
+		a.push(toJSONString(i), ':', s);
+		b = true;
+	}
 
-        for (i in this) {
-            if (this.hasOwnProperty(i)) {
-                v = this[i];
-                switch (typeof v) {
-                case 'undefined':
-                case 'function':
-                case 'unknown':
-                    break;
-                case 'object':
-                    if (v) {
-                        if (typeof v.toJSONString === 'function') {
-                            p(v.toJSONString());
-                        }
-                    } else {
-                        p("null");
-                    }
-                    break;
-                default:
-                    p(v.toJSONString());
-                }
-            }
-        }
-        a.push('}');
-        return a.join('');
-    };
+	for (i in ob) {
+		if (ob.hasOwnProperty(i)) {
+			v = ob[i];
+			switch (typeof v) {
+			case 'undefined':
+			case 'function':
+			case 'unknown':
+				break;
+			case 'object':
+				if (v) {
+					p(toJSONString(v));
+				} else {
+					p("null");
+				}
+				break;
+			default:
+				p(toJSONString(v));
+			}
+		}
+	}
+	a.push('}');
+	return a.join('');
+};
 
+function stringToJSONString(so){
+	var m = {
+		'\b': '\\b',
+		'\t': '\\t',
+		'\n': '\\n',
+		'\f': '\\f',
+		'\r': '\\r',
+		'"' : '\\"',
+		'\\': '\\\\'
+	};	
+	if (/["\\\x00-\x1f]/.test(so)) {
+		return '"' + so.replace(/([\x00-\x1f\\"])/g, function(a, b) {
+			var c = m[b];
+			if (c) {
+				return c;
+			}
+			c = b.charCodeAt();
+			return '\\u00' +
+				Math.floor(c / 16).toString(16) +
+				(c % 16).toString(16);
+		}) + '"';
+	}
+	return '"' + so + '"';
+}
 
-    (function (s) {
-        var m = {
-            '\b': '\\b',
-            '\t': '\\t',
-            '\n': '\\n',
-            '\f': '\\f',
-            '\r': '\\r',
-            '"' : '\\"',
-            '\\': '\\\\'
-        };
+function toJSONString(o){
+	switch(typeof o){
+	case 'undefined':
+	case 'function':
+	case 'unknown':
+		break;
+	case 'object':
+		if (o.constructor == Array){
+			return arrayToJSONString(o);
+		}else if(o.constructor == Date){
+			return dateToJSONString(o);
+		}else{
+			return objectToJSONString(o);
+		}
+	case 'number':
+		return numberToJSONString(o);
+	case 'string':
+		return stringToJSONString(o);
+	case 'boolean':
+		return boolToJSONString(o);
+	}
+}
 
-        s.parseJSON = function (filter) {
-            try {
-                if (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.
-                        test(this)) {
-                    var j = eval('(' + this + ')');
-                    if (typeof filter === 'function') {
-                        function walk(k, v) {
-                            if (v && typeof v === 'object') {
-                                for (var i in v) {
-                                    if (v.hasOwnProperty(i)) {
-                                        v[i] = walk(i, v[i]);
-                                    }
-                                }
-                            }
-                            return filter(k, v);
-                        }
-                        return walk('', j);
-                    }
-                    return j;
-                }
-            } catch (e) {
-            }
-            throw new SyntaxError("parseJSON");
-        };
-
-        s.toJSONString = function () {
-            if (/["\\\x00-\x1f]/.test(this)) {
-                return '"' + this.replace(/([\x00-\x1f\\"])/g, function(a, b) {
-                    var c = m[b];
-                    if (c) {
-                        return c;
-                    }
-                    c = b.charCodeAt();
-                    return '\\u00' +
-                        Math.floor(c / 16).toString(16) +
-                        (c % 16).toString(16);
-                }) + '"';
-            }
-            return '"' + this + '"';
-        };
-    })(String.prototype);
+function parseJSON(so, filter){
+	var m = {
+		'\b': '\\b',
+		'\t': '\\t',
+		'\n': '\\n',
+		'\f': '\\f',
+		'\r': '\\r',
+		'"' : '\\"',
+		'\\': '\\\\'
+	};	
+	try {
+		if (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.
+				test(so)) {
+			var j = eval('(' + so + ')');
+			if (typeof filter === 'function') {
+				function walk(k, v) {
+					if (v && typeof v === 'object') {
+						for (var i in v) {
+							if (v.hasOwnProperty(i)) {
+								v[i] = walk(i, v[i]);
+							}
+						}
+					}
+					return filter(k, v);
+				}
+				return walk('', j);
+			}
+			return j;
+		}
+	} catch (e) {
+	}
+	throw new SyntaxError("parseJSON");        
 }
\ No newline at end of file

Modified: branches/mapbender_sld/http/extensions/markResult.php
===================================================================
--- branches/mapbender_sld/http/extensions/markResult.php	2007-11-23 13:43:16 UTC (rev 1834)
+++ branches/mapbender_sld/http/extensions/markResult.php	2007-11-23 13:44:02 UTC (rev 1835)
@@ -38,7 +38,7 @@
 }
 
 if(!$_REQUEST["color"]){ $color = "255,0,0"; }
-$myCol = split(",", $color);
+$myCol = mb_split(",", $color);
 
 $image = imagecreate($width,$height);
 



More information about the Mapbender_commits mailing list