[Inteproxy-commits] r265 - in trunk: . server server/conf

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Aug 23 16:47:48 CEST 2010


Author: bh
Date: 2010-08-23 16:47:46 +0200 (Mon, 23 Aug 2010)
New Revision: 265

Modified:
   trunk/ChangeLog
   trunk/create-rewrite-rules.py
   trunk/server/README.txt
   trunk/server/conf/inteproxy.conf
Log:
Implement URL rewriting in capabilities responses in InteProxy Server

* create-rewrite-rules.py (create_config_parser): New option
--server-prefix to specify the URL prefix of the inteproxy to use
when rewriting server responses
(rule_for_owsproxy): Extend to also return the regular expression
to use when looking for URLs to rewrite in server responses
(substitution_rule): Create the apache Substitute rule for
response rewriting.
(create_rewrite_rules): Extend to also generate substitution rules
(main): Pass the server prefix to create_rewrite_rules.

* server/README.txt: Adapt to URL rewriting changes

* server/conf/inteproxy.conf: Define a filter chain for the URL
rewriting in capabilities responses


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2010-08-05 09:32:26 UTC (rev 264)
+++ trunk/ChangeLog	2010-08-23 14:47:46 UTC (rev 265)
@@ -1,3 +1,22 @@
+2010-08-23  Bernhard Herzog  <bh at intevation.de>
+
+	Implement URL rewriting in capabilities responses in InteProxy Server
+
+	* create-rewrite-rules.py (create_config_parser): New option
+	--server-prefix to specify the URL prefix of the inteproxy to use
+	when rewriting server responses
+	(rule_for_owsproxy): Extend to also return the regular expression
+	to use when looking for URLs to rewrite in server responses
+	(substitution_rule): Create the apache Substitute rule for
+	response rewriting.
+	(create_rewrite_rules): Extend to also generate substitution rules
+	(main): Pass the server prefix to create_rewrite_rules.
+
+	* server/conf/inteproxy.conf: Define a filter chain for the URL
+	rewriting in capabilities responses
+
+	* server/README.txt: Adapt to URL rewriting changes
+
 2010-08-05  Bjoern Schilberg <bjoern at intevation.de>
 	
     * server/doc/source/index.rst,server/doc/source/proxyRemote.rst: Added

Modified: trunk/create-rewrite-rules.py
===================================================================
--- trunk/create-rewrite-rules.py	2010-08-05 09:32:26 UTC (rev 264)
+++ trunk/create-rewrite-rules.py	2010-08-23 14:47:46 UTC (rev 265)
@@ -31,30 +31,52 @@
     if rule.user is None or rule.password is None:
         print >>sys.stderr, ("Missing credentials for url %r"
                              % orig_url)
-        return None
+        return None, None
     host_regex = pattern_to_regex(rule.host, character_set="[^/]")
     path_regex = pattern_to_regex(rule.path, character_set=".")
     port_regex = ""
     if rule.port is not None:
         port_regex = re.escape(":%d" % rule.port)
-    return ("RewriteRule ^/%s%s%s$ https:/$0?user=%s&password=%s [QSA,P]\n"
+    rule = ("RewriteRule ^/%s%s%s$ https:/$0?user=%s&password=%s [QSA,P]\n"
             % (host_regex, port_regex, path_regex,
                re.escape(quote_plus(rule.user)),
                re.escape(quote_plus(rule.password))))
+    subst_regex = host_regex + port_regex + path_regex
+    return rule, subst_regex
 
+def substitution_rule(regexes, prefix):
+    delimiter = "-"
+    def quote_delimiter(s, needs_backslash=True):
+        if needs_backslash:
+            backslash = "\\"
+        else:
+            backslash = ""
+        return s.replace(delimiter, backslash + "%03o" % ord(delimiter))
+    regexes = [quote_delimiter(regex, needs_backslash=False)
+               for regex in regexes]
+    if not prefix.endswith("/"):
+        prefix += "/"
+    prefix = quote_delimiter(prefix)
+    return ("Substitute s%(d)shttps?://(%(re)s)%(d)s%(prefix)s$1%(d)s\n"
+            % dict(d=delimiter, re="|".join(regexes), prefix=prefix))
 
-def create_rewrite_rules(config, outfile):
+
+def create_rewrite_rules(config, outfile, server_prefix):
     """Writes the RewriteRules from config to outfile"""
+    subst_expressions = []
     for rule in config.rules:
         if rule.scheme != "owsproxy":
             print >>sys.stderr, ("Unsupported scheme %r for %s/%s"
                                  % (rule.scheme, rule.host, rule.path))
             continue
-        rewrite_rule = rule_for_owsproxy(rule)
+        rewrite_rule, subst_regex = rule_for_owsproxy(rule)
         if rewrite_rule:
             outfile.write(rewrite_rule)
+        if subst_regex:
+            subst_expressions.append(subst_regex)
+    if subst_expressions:
+        outfile.write(substitution_rule(subst_expressions, server_prefix))
 
-
 def create_config_parser():
     """Creates an OptionParser instance for the script"""
     parser = optparse.OptionParser()
@@ -65,6 +87,9 @@
     parser.add_option("--output-file", "-o",
                       help=("Output file (by default output is written to"
                             " stdout)"))
+    parser.add_option("--server-prefix",
+                      help=("URL prefix of the InteProxy server,"
+                            " e.g. http://localhost:64609"))
     return parser
 
 
@@ -77,7 +102,7 @@
     if opts.output_file:
         outfile = open(opts.output_file, "w")
 
-    create_rewrite_rules(config, outfile)
+    create_rewrite_rules(config, outfile, server_prefix=opts.server_prefix)
 
 
 if __name__  == "__main__":

Modified: trunk/server/README.txt
===================================================================
--- trunk/server/README.txt	2010-08-05 09:32:26 UTC (rev 264)
+++ trunk/server/README.txt	2010-08-23 14:47:46 UTC (rev 265)
@@ -30,6 +30,8 @@
  - mod_proxy
  - mod_proxy_http
  - mod_ssl
+ - mod_filter
+ - mod_substitute
 
 It is recommended to run InteProxy Server in a separate Virtual Host.
 
@@ -44,10 +46,11 @@
 
 2. Convert InteProxy configuration.
 
-  ../create-rewrite-rules.py --config-file=... -o conf/inteproxy-rewrite.conf
+  ../create-rewrite-rules.py --config-file=... \
+      --server-prefix=http://localhost:64609/ -o conf/inteproxy-rewrite.conf
 
 create-rewrite-rules.py reads the InteProxy config file and writes Apache
-RewriteRule directives to the output file.
+RewriteRule and Substitute directives to the output file.
 
 
 Starting Apache

Modified: trunk/server/conf/inteproxy.conf
===================================================================
--- trunk/server/conf/inteproxy.conf	2010-08-05 09:32:26 UTC (rev 264)
+++ trunk/server/conf/inteproxy.conf	2010-08-23 14:47:46 UTC (rev 265)
@@ -11,6 +11,15 @@
 # RewriteLogLevel 0
 RewriteLog /opt/InteProxy-SERVER-1.0.0/server/logs/rewrite.log
 
+# Define filter chain to rewrite URLs in WMS capabilities responses.
+# WMS capabilities responses have the content type
+# application/vnd.ogc.wms_xml.  The slash in the content type value has
+# to be expressed with the octal escape \057 because the slash has to be
+# used as the delimeter of the regular expression
+FilterProvider fixurls SUBSTITUTE  Content-Type "/(application\057vnd.ogc.wms_xml|text\057xml)($|;)/"
+FilterChain fixurls
+
+
 # conf/inteproxy-rewrite.conf has to be generated if it doesn't exist
 # yet (see README.txt).  It contains the RewriteRules for the actual
 # InteProxy functionality.



More information about the Inteproxy-commits mailing list