Commit 19da91e5 authored by Vincent Bechu's avatar Vincent Bechu

[product/ERP5Type] Support wildcart in VirtualHostMonster

parent e3b804b0
......@@ -87,6 +87,7 @@ from Products.ERP5Type.patches import ZopePageTemplate
from Products.ERP5Type.patches import ZSQLMethod
from Products.ERP5Type.patches import MimetypesRegistry
from Products.ERP5Type.patches import users
from Products.ERP5Type.patches import VirtualHostMonster
# These symbols are required for backward compatibility
from Products.ERP5Type.patches.PropertyManager import ERP5PropertyManager
......
##############################################################################
#
# Copyright (c) 2001 Zope Foundation and Contributors.
# Copyright (c) 2015 Nexedi SA and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
from Products.SiteAccess.VirtualHostMonster import VirtualHostMonster
from ZPublisher.BaseRequest import quote
def __call__(self, client, request, response=None):
'''Traversing at home'''
vh_used = 0
stack = request['TraversalRequestNameStack']
path = None
while 1:
if stack and stack[-1] == 'VirtualHostBase':
vh_used = 1
stack.pop()
protocol = stack.pop()
host = stack.pop()
if ':' in host:
host, port = host.split(':')
request.setServerURL(protocol, host, port)
else:
request.setServerURL(protocol, host)
if '*' in stack:
stack[stack.index('*')] = host.split('.')[0]
path = list(stack)
# 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':
vh_used = 1
pp = ['']
at_end = (ii == len(stack) - 1)
if vh >= 0:
for jj in range(vh, ii):
pp.insert(1, stack[jj][4:])
stack[vh:ii + 1] = ['/'.join(pp), self.id]
ii = vh + 1
elif ii > 0 and stack[ii - 1][:1] == '/':
pp = stack[ii - 1].split('/')
stack[ii] = self.id
else:
stack[ii] = self.id
stack.insert(ii, '/')
ii += 1
path = stack[:ii]
# If the directive is on top of the stack, go ahead
# and process it right away.
if at_end:
request.setVirtualRoot(pp)
del stack[-2:]
break
elif vh < 0 and stack[ii][:4] == '_vh_':
vh = ii
if vh_used or not self.have_map:
if path is not None:
path.reverse()
vh_part = ''
if path and path[0].startswith('/'):
vh_part = path.pop(0)[1:]
if vh_part:
request['VIRTUAL_URL_PARTS'] = vup = (
request['SERVER_URL'],
vh_part, quote('/'.join(path)))
else:
request['VIRTUAL_URL_PARTS'] = vup = (
request['SERVER_URL'], quote('/'.join(path)))
request['VIRTUAL_URL'] = '/'.join(vup)
# new ACTUAL_URL
add = (path and
request['ACTUAL_URL'].endswith('/')) and '/' or ''
request['ACTUAL_URL'] = request['VIRTUAL_URL'] + add
return
vh_used = 1 # Only retry once.
# Try to apply the host map if one exists, and if no
# VirtualHost directives were found.
host = request['SERVER_URL'].split('://')[1].lower()
hostname, port = (host.split( ':', 1) + [None])[:2]
ports = self.fixed_map.get(hostname, 0)
if not ports and self.sub_map:
get = self.sub_map.get
while hostname:
ports = get(hostname, 0)
if ports:
break
if '.' not in hostname:
return
hostname = hostname.split('.', 1)[1]
if ports:
pp = ports.get(port, 0)
if pp == 0 and port is not None:
# Try default port
pp = ports.get(None, 0)
if not pp:
return
# If there was no explicit VirtualHostRoot, add one at the end
if pp[0] == '/':
pp = pp[:]
pp.insert(1, self.id)
stack.extend(pp)
VirtualHostMonster.__call__ = __call__
\ No newline at end of file
  • @jerome We got this patch merged in Zope : https://github.com/zopefoundation/Zope/pull/318 I need to update OfficeJS Appstore Serveur asap, JP said me to merge this patch, we could reverts this commit when Zope make a new release ? Or should i use a temporary erp5 branch for this project ?

  • https://github.com/zopefoundation/Zope/pull/318 is for zope master branch, which is for 4.x releases, but we are using 2.13.x releases, so the best would be to have this patch in 2.13 branch and have zope guys make a 2.13 release that we can use.

    For the IPv6 support, we did https://github.com/zopefoundation/Zope/pull/314 for master branch and then backported it 2.13 branch in https://github.com/zopefoundation/Zope/pull/395 and we are now waiting for someone in zope to make a release and then we'll use the new zope release in slapos. But in the ipv6 case, it's not really urgent, so it's no problem to wait.

    So the point is that even if we have https://github.com/zopefoundation/Zope/pull/318 accepted to be able to use it, we would need:

    • make another PR to backport on zope 2.13 branch
    • wait for zope to make a release
    • update ERP5 software release in slapos repository to use the new version of Zope egg

    which will take time (especially zope maintainers seems more interested about porting zope to python3 in 4.x branch than to make releases on 2.13 which is a "stable" branch )

    In the meantime, I (but it's just me) would prefer that we don't have a monkey patch (we already have so much and it's always causing problems - here for example if we apply this monkey patch, when we update zope we won't have the IPv6 support). Is it possible to use a temporary branch for officejs ? this seem the fastest solution.

    Or ... we never discussed this, but maybe this does not need a patch so low level, it's possible to call request.setVirtualRoot and request.setServerUrl at a higher level, in traversal hook or using an access rule

  • If you prefer, @romain or someone can decide, I'm just saying I prefer we don't have this applied as a monkey patch, but I can't decide.

  • Or this can be a patch in the software release, like we do for now in slapos!377 ? (cc @rafael )

    or this can be integrated in frontend ? If I understand correctly, it can be a variation of the zope frontend type that instead of rewriting:

    host.domain.com/(.*) => ^/VirtualHostBase/https//host.domain.com:443/VirtualHostRoot/path/$1

    would rewrite to

    ([a-zA-Z]*).domain.com/(.*) => ^/VirtualHostBase/https//host.domain.com:443/VirtualHostRoot/path/$2/$1/

    maybe @luke knows this ?

    It's hard for me to comment because I don't really understand the need for this patch. Is this done with @romain ?

  • Jérome Perrin @jerome

    mentioned in merge request slapos!377

    ·

    mentioned in merge request slapos!377

    Toggle commit list
  • maybe @luke knows this ?

    Hm, AFAIRC this feature of backend shall be full - no more trick on frontend.

    Anyway if ASAP is the requirement, I propose normal patch, officejs has its own SR, hasn't it?

  • @jp would like that this specific logic be placed at the apache on the backend rather them on frontend.

    The back end should be more flexible to handle this case.

  • Explicitly on the apache or just on the backend ? if we need flexibility it might be better to do it on zope and we already have a patch to do it on zope.

    What annoys me is that I'm discussing this, but I still don't really understand the reasons for this patch.

    I looked a bit more closely and I think it's just about doing

    ([a-zA-Z]*).domain.com/(.*) => ^/VirtualHostBase/https//$1.domain.com:443/VirtualHostRoot/path/$2

    so that the hostname is preserved ( note that [a-zA-Z] part of the regex is a bit simplified ). The test tests with path, but this is just intended to set hostname, is it ?

    Then, what's the need for flexibility ?

  • Thanks for feedback.

    @jerome Yes it is, but we move logic to backend to keep as simple as possible in frontends, from what i understand, we discuss that with @jp and @romain

  • mentioned in merge request officejs-appstore!10 (closed)

    Toggle commit list
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