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):
def __call__(self, container, request):
if SUPPRESS_ACCESSRULE: return
if '_SUPPRESS_ACCESSRULE' in _swallow(request):
if '_SUPPRESS_ACCESSRULE' in _swallow(request, '_SUPPRESS'):
request.setVirtualRoot(request.steps)
return
NameCaller.__call__(self, container, request)
def _swallow(request):
def _swallow(request, prefix):
path = request['TraversalRequestNameStack']
steps = request.steps
i = len(steps)
while i > 0 and steps[i - 1][:1] == '_':
i = i - 1
while path and path[-1][:1] == '_':
while path and path[-1][:len(prefix)] == prefix:
steps.append(path.pop())
return steps[i:]
......
......@@ -105,7 +105,7 @@ class SiteRoot(Traverser, Implicit):
def __call__(self, client, request, response=None):
'''Traversing'''
if SUPPRESS_SITEROOT: return
if '_SUPPRESS_SITEROOT' in _swallow(request):
if '_SUPPRESS_SITEROOT' in _swallow(request, '_SUPPRESS'):
request.setVirtualRoot(request.steps)
return
srd = [None, None]
......
......@@ -7,10 +7,12 @@ from Globals import DTMLFile, MessageDialog, Persistent
from OFS.SimpleItem import Item
from Acquisition import Implicit, ImplicitAcquisitionWrapper
from ExtensionClass import Base
from string import split, strip
from string import split, strip, join
from ZPublisher import BeforeTraverse
import os
from AccessRule import _swallow
class VirtualHostMonster(Persistent, Item, Implicit):
"""Provide a simple drop-in solution for virtual hosting.
"""
......@@ -74,21 +76,38 @@ class VirtualHostMonster(Persistent, Item, Implicit):
request.setServerURL(protocol, host, port)
else:
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)):
if stack[ii] == 'VirtualHostRoot':
stack[ii] = self.id
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.insert(ii, '/')
break
elif vh < 0 and stack[ii][:4] == '_vh_':
vh = ii
def __bobo_traverse__(self, request, name):
'''Traversing away'''
if name in ('manage_main', 'manage_workspace'):
return self.manage_main
if name[:1] != '/':
return getattr(self, name)
parents = request.PARENTS
parents.pop() # I don't belong there
request.setVirtualRoot([])
stack = request['TraversalRequestNameStack']
stack.append(name)
if len(name) > 1:
request.setVirtualRoot(split(name[1:], '/'))
else:
request.setVirtualRoot([])
return parents.pop() # He'll get put back on
def manage_addVirtualHostMonster(self, id, REQUEST=None, **ignored):
......
......@@ -32,9 +32,7 @@ Base (if specified) should <strong>always</strong> start with
Id
</div>
</td>
<td align="left" valign="top">
<input type="text" name="id" size="40" />
</td>
<td align="left" valign="top">SiteRoot</td>
</tr>
<tr>
<td align="left" valign="top">
......
......@@ -25,16 +25,6 @@ Base (if specified) should <strong>always</strong> start with "http://"
<form action="manage_edit" method="POST">
<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>
<td align="left" valign="top">
<div class="form-optional">
......@@ -64,7 +54,7 @@ Base (if specified) should <strong>always</strong> start with "http://"
</div>
</td>
<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>" />
</td>
</tr>
......
......@@ -21,22 +21,38 @@ directive, or with a Zope Access Rule.
<p class="form-help">
If the URL path of a request begins with
&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 class="form-help">
If the URL contains <em>VirtualHostRoot</em>, then
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;
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 class="form-help">
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
<strong>http://www.foo.com/</strong>, put a Virtual Host Monster in the root
folder and rewrite requests for that URL to
<strong>/VirtualHostBase/http/www.foo.com/foo/VirtualHostRoot/</strong>
site. For example, suppose you want to publish Folder &quot;/foo&quot; as
<strong>http://www.foo.com/</strong>, where Zope is running on port
8080 behind Apache running on port 80. You place a Virtual Host
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 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