[Zope] Virtual Hosting on ZServer Updated

abg@comco-inc.com abg@comco-inc.com
Thu, 31 May 2001 08:43:01 -0500


I'm pretty new to python, and am having a bit of difficulty with the 
AccessRule code Alan sugggested. I need to be able to map not only 
domains (bar.com), but virtual domains (foo.bar.com) to locations in 
Zope. This AccessRule works quite well for the former, but appears to 
ignore the prefix of the latter (foo).

Here's what I've tried so far:

I changed this bit of code:

hostname="_.string.split(_.string.lower(_.string.split(HTTP_HOST,
':')[0]),'.')[-2:]" 
          domainname="hostname[0] + '.' + hostname[1]" 
          vhmcode="VHosts.gethostfolder(_.None, _, host=domainname)"

To this:

hostname="_.string.split(_.string.lower(_.string.split(HTTP_HOST,
':')[0]),'.')[-3:]" 
          domainname="hostname[1] + '.' + hostname[2]"
	    domainname2="hostname[0] + '.' + hostname[1] + '.' +
hostname[2]"
          vhmcode="VHosts.gethostfolder(_.None, _, host=domainname)"

How do I tell AccessRule to use one method (gethostfolder) for those
requests that are in bar.com format, and another method for those requests
that are in foo.bar.com format?

Also, I'm really not sure if the changes I've made above are going to screw
anything up.

Any help will be greatly appreciated, and (hopefully) returned at a 
later time.

Thanks.

Aaron

> -----Original Message-----
> From:  "Capesius, Alan" <CapesiusA@S...>
> Date:  Thu Apr 5, 2001  6:22 pm
> Subject:  [Zope] Virtual Hosting on ZServer Updated
> 
>  
> Here's an update to my virtual hosting on ZServer solution. 
> The AccessRule
> has been enhanced to allow access to aliased host names that 
> are not in the
> host.domain.com form but rather in a host format. This is 
> useful if you use
> a hosts file with a name for a server (e.g. server01 instead of
> www.domain.com) The change prevents an index error in the accessrule.
> Request not in domain.com form will revert to the default site.
> 
> The solution uses TinyTable, Virtual Host Monster and AccessRule and a
> DTML method to process all inbound requests by domain name similar to
> the way in which SiteRoot script things. The best part is 
> that once set,
> the AccessRule does not need to be modified to add new hosts. Host to
> folder mapping is performed via entries in the TinyTable, the rest of
> the configuration is static.
> 
> Tested with Zope 2.3.0 and TinyTable 0-8-2.
> Virtual Host Monster and AccessRule support are built into 2.3.0
> 
> 
> Here it is:
> 
> Create a folder in Root called VHosts
> Inside VHosts create a folder for each Virtual host
> Inside each new Virtual host's folder , create a Virtual Host Monster
> called VHM
> 
> Inside VHosts, create a TinyTable called HostsTable
> Give the Tiny Table the following columns : domain, folder
> Create records for domain to folder mapping as shown here:
> "domain1.com", "Folder1"
> "domain2.com", "Folder2"
> Where the domain names are the virtual names for your server and the
> folder names are the folders created inside VHosts.
> Entries are CASE SENSITIVE and MUST match the folder names created in
> the earlier step. Enter all domains in lower case.
> 
> Inside VHosts create the following DTML Method:
> Name: gethostfolder
> <dtml-in "VHosts.HostsTable(domainname)">
>   <dtml-return folder>
> <dtml-else>
>   <dtml-return "'NULL'">
> </dtml-in>
> 
> In the Root, create a DTML called AccessRule
> AccessRule in Root Folder
> ===================
> <dtml-try>
> <dtml-let 
> hostname="_.string.split(_.string.lower(_.string.split(HTTP_HOST,
> ':')[0]),'.')[-2:]" 
>           domainname="hostname[0] + '.' + hostname[1]" 
>           vhmcode="VHosts.gethostfolder(_.None, _, host=domainname)">
> 
> <dtml-if "vhmcode<>'NULL'">
>   <dtml-if "_.string.split(_.string.lower(PATH_INFO), 
> '/')[-1:]==['manage']
> or 
>             _.string.split(_.string.lower(PATH_INFO),
> '/')[-1:]==['manage_main'] or 
>             _.string.split(_.string.lower(PATH_INFO),
> '/')[-1:]==['manage_workspace'] ">
>     <dtml-if "TraversalRequestNameStack[-2:]<>[vhmcode,'VHosts']">
>       <dtml-call 
> "REQUEST['TraversalRequestNameStack'].extend([vhmcode,
> 'VHosts'])">
>     </dtml-if>
>   <dtml-else>
>     <dtml-call 
> "REQUEST['TraversalRequestNameStack'].extend(['VHM', vhmcode,
> 'VHosts'])">
>   </dtml-if>
> </dtml-if>
> 
> </dtml-let>
> <dtml-except> 
> </dtml-try> 
> 
> 
> 
> It should look like this:
> Root-
>   AccessRule
>   VHosts-
>        HostsTable
>        gethostfolder
>        Folder1-
>              VHM
>              index_html
>        Folder2-
>              VHM
>              index_html
> 
> 
> 
> 
> 
> Security Settings:
> gethostfolder method:   no anonymous access, proxy as manager, manager
> has full rights.
> HostsTable: No anonymous access, manager full rights
> AccessRule: Proxy as manager
> 
> Now, to enable the system, Use the Root folder's Add->SetAccessRule
> option and enter "AccessRule" (without quotes) and click Set.
> Requests for domain1.com will be drawn from Folder1, 2 from 2 etc..
> Managent of the virtual domain will show only the VHosts 
> folder contents
> for the selected site.
> Management of the root site will show the root.
> Access to unsupported domains will fall back to root. (perhaps to be a
> redirect to a 404 page in the future)
> 
> Display the mappings with /VHosts/HostsTable or via the management
> interface.
> 
> Use http://hostname/_SUPPRESS_ACCESSRULE/manage to deactivate the
> AccessRule if you have any problems accessing the system.
> 
> All feedback welcome. To the list please.
> I will add the config to my tips site shortly.
> 
> Alan Capesius, MCSE
> Tech World, Inc.
> http://twsite.bizland.com/zopetips.htm
> 
>  
>