Commit d7dedb9b authored by Evan Simpson's avatar Evan Simpson

Merge changes from 2.3 branch

parent 9b64c9e8
...@@ -16,18 +16,18 @@ class AccessRule(NameCaller): ...@@ -16,18 +16,18 @@ class AccessRule(NameCaller):
def __call__(self, container, request): def __call__(self, container, request):
if SUPPRESS_ACCESSRULE: return if SUPPRESS_ACCESSRULE: return
if '_SUPPRESS_ACCESSRULE' in _swallow(request): if '_SUPPRESS_ACCESSRULE' in _swallow(request, '_SUPPRESS'):
request.setVirtualRoot(request.steps) request.setVirtualRoot(request.steps)
return return
NameCaller.__call__(self, container, request) NameCaller.__call__(self, container, request)
def _swallow(request): def _swallow(request, prefix):
path = request['TraversalRequestNameStack'] path = request['TraversalRequestNameStack']
steps = request.steps steps = request.steps
i = len(steps) i = len(steps)
while i > 0 and steps[i - 1][:1] == '_': while i > 0 and steps[i - 1][:1] == '_':
i = i - 1 i = i - 1
while path and path[-1][:1] == '_': while path and path[-1][:len(prefix)] == prefix:
steps.append(path.pop()) steps.append(path.pop())
return steps[i:] return steps[i:]
......
...@@ -105,7 +105,7 @@ class SiteRoot(Traverser, Implicit): ...@@ -105,7 +105,7 @@ class SiteRoot(Traverser, Implicit):
def __call__(self, client, request, response=None): def __call__(self, client, request, response=None):
'''Traversing''' '''Traversing'''
if SUPPRESS_SITEROOT: return if SUPPRESS_SITEROOT: return
if '_SUPPRESS_SITEROOT' in _swallow(request): if '_SUPPRESS_SITEROOT' in _swallow(request, '_SUPPRESS'):
request.setVirtualRoot(request.steps) request.setVirtualRoot(request.steps)
return return
srd = [None, None] srd = [None, None]
......
...@@ -7,10 +7,12 @@ from Globals import DTMLFile, MessageDialog, Persistent ...@@ -7,10 +7,12 @@ from Globals import DTMLFile, MessageDialog, Persistent
from OFS.SimpleItem import Item from OFS.SimpleItem import Item
from Acquisition import Implicit, ImplicitAcquisitionWrapper from Acquisition import Implicit, ImplicitAcquisitionWrapper
from ExtensionClass import Base from ExtensionClass import Base
from string import split, strip from string import split, strip, join
from ZPublisher import BeforeTraverse from ZPublisher import BeforeTraverse
import os import os
from AccessRule import _swallow
class VirtualHostMonster(Persistent, Item, Implicit): class VirtualHostMonster(Persistent, Item, Implicit):
"""Provide a simple drop-in solution for virtual hosting. """Provide a simple drop-in solution for virtual hosting.
""" """
...@@ -74,21 +76,38 @@ class VirtualHostMonster(Persistent, Item, Implicit): ...@@ -74,21 +76,38 @@ class VirtualHostMonster(Persistent, Item, Implicit):
request.setServerURL(protocol, host, port) request.setServerURL(protocol, host, port)
else: else:
request.setServerURL(protocol, host) request.setServerURL(protocol, host)
#request.setVirtualRoot([]) # Find and convert VirtualHostRoot directive
# If it is followed by one or more path elements that each
# start with '_vh_', use them to construct the path to the
# virtual root.
vh = -1
for ii in range(len(stack)): for ii in range(len(stack)):
if stack[ii] == 'VirtualHostRoot': if stack[ii] == 'VirtualHostRoot':
if vh >= 0:
pp = ['']
for jj in range(vh, ii):
pp.insert(1, stack[jj][4:])
stack[vh:ii + 1] = [join(pp, '/'), self.id]
elif ii > 0 and stack[ii - 1][:1] == '/':
stack[ii] = self.id
else:
stack[ii] = self.id stack[ii] = self.id
stack.insert(ii, '/')
break break
elif vh < 0 and stack[ii][:4] == '_vh_':
vh = ii
def __bobo_traverse__(self, request, name): def __bobo_traverse__(self, request, name):
'''Traversing away''' '''Traversing away'''
if name in ('manage_main', 'manage_workspace'): if name[:1] != '/':
return self.manage_main return getattr(self, name)
parents = request.PARENTS parents = request.PARENTS
parents.pop() # I don't belong there parents.pop() # I don't belong there
if len(name) > 1:
request.setVirtualRoot(split(name[1:], '/'))
else:
request.setVirtualRoot([]) request.setVirtualRoot([])
stack = request['TraversalRequestNameStack']
stack.append(name)
return parents.pop() # He'll get put back on return parents.pop() # He'll get put back on
def manage_addVirtualHostMonster(self, id, REQUEST=None, **ignored): def manage_addVirtualHostMonster(self, id, REQUEST=None, **ignored):
......
...@@ -32,9 +32,7 @@ Base (if specified) should <strong>always</strong> start with ...@@ -32,9 +32,7 @@ Base (if specified) should <strong>always</strong> start with
Id Id
</div> </div>
</td> </td>
<td align="left" valign="top"> <td align="left" valign="top">SiteRoot</td>
<input type="text" name="id" size="40" />
</td>
</tr> </tr>
<tr> <tr>
<td align="left" valign="top"> <td align="left" valign="top">
......
...@@ -25,16 +25,6 @@ Base (if specified) should <strong>always</strong> start with "http://" ...@@ -25,16 +25,6 @@ Base (if specified) should <strong>always</strong> start with "http://"
<form action="manage_edit" method="POST"> <form action="manage_edit" method="POST">
<table cellspacing="0" cellpadding="2" border="0"> <table cellspacing="0" cellpadding="2" border="0">
<tr>
<td align="left" valign="top">
<div class="form-label">
Id
</div>
</td>
<td align="left" valign="top">
<input type="text" name="id" size="40" />
</td>
</tr>
<tr> <tr>
<td align="left" valign="top"> <td align="left" valign="top">
<div class="form-optional"> <div class="form-optional">
...@@ -64,7 +54,7 @@ Base (if specified) should <strong>always</strong> start with "http://" ...@@ -64,7 +54,7 @@ Base (if specified) should <strong>always</strong> start with "http://"
</div> </div>
</td> </td>
<td align="left" valign="top"> <td align="left" valign="top">
<input type="text" name="path" size="40" value="/" <input type="text" name="path" size="40"
value="<dtml-if path>&dtml-path;</dtml-if>" /> value="<dtml-if path>&dtml-path;</dtml-if>" />
</td> </td>
</tr> </tr>
......
...@@ -21,22 +21,38 @@ directive, or with a Zope Access Rule. ...@@ -21,22 +21,38 @@ directive, or with a Zope Access Rule.
<p class="form-help"> <p class="form-help">
If the URL path of a request begins with If the URL path of a request begins with
&quot;/VirtualHostBase/http/www.foo.com&quot;, for instance, then &quot;/VirtualHostBase/http/www.foo.com&quot;, for instance, then
URLs generated by Zope will start with <strong>http://www.foo.com</strong>. URLs generated by Zope will start with
<strong>http://www.foo.com</strong>.
Since the port number was not specified, it is left unchanged. If
your Zope is running on port 8080, and you want generated URLs not to
include this port number, you must use
&quot;/VirtualHostBase/http/www.foo.com:80&quot;.
</p> </p>
<p class="form-help"> <p class="form-help">
If the URL contains <em>VirtualHostRoot</em>, then If the URL contains <em>VirtualHostRoot</em>, then
all path elements up to that point are removed from generated URLs. all path elements up to that point are removed from generated URLs.
For instance, a request with path &quot;/a/b/c/VirtualHostRoot/d&quot; For instance, a request with path &quot;/a/b/c/VirtualHostRoot/d&quot;
will generate a URL with path <strong>/d</strong>. will traverse &quot;a/b/c/d&quot; and then generate a URL with
path <strong>/d</strong>.
</p>
<p class="form-help">
If <em>VirtualHostRoot</em> is followed by one or more path elements
that start with '_vh_', then these elements (without the '_vh_') will
be skipped and then added to the start of generated URLs.
For instance, a request with path &quot;/a/VirtualHostRoot/_vh_z/b&quot;
will traverse &quot;a/b&quot; and then generate a URL with
path <strong>/z/b</strong>.
</p> </p>
<p class="form-help"> <p class="form-help">
Combining both allows you to cause a subfolder to act as the root of a Combining both allows you to cause a subfolder to act as the root of a
site. For example, to publish Folder &quot;/foo&quot; as site. For example, suppose you want to publish Folder &quot;/foo&quot; as
<strong>http://www.foo.com/</strong>, put a Virtual Host Monster in the root <strong>http://www.foo.com/</strong>, where Zope is running on port
folder and rewrite requests for that URL to 8080 behind Apache running on port 80. You place a Virtual Host
<strong>/VirtualHostBase/http/www.foo.com/foo/VirtualHostRoot/</strong> Monster in the root Zope folder, and use Apache to rewrite &quot;/(.*)&quot;
to <strong>http://localhost:8080/VirtualHostBase/http/www.foo.com:80/foo/VirtualHostRoot/$1</strong>
</p> </p>
<p class="form-help"> <p class="form-help">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment