Forum Moderators: phranque

Message Too Old, No Replies

WebDAV Internal Rewrite based on Login

WebDav configuration within a vhost and alias

         

codevyper

6:20 am on Mar 21, 2011 (gmt 0)

10+ Year Member



I am having problems trying to setup a vhost using webdav through an alias that points to a directory structure outside of the vhost's document root. What I want to do is when a user logs in through basic auth to the alias /dav/, the server should know, based on their username to show them and work with, the contents of a subdirectory in /davfiles/. The subdirectory's name will match their username so that's how it will know what folder they belong in. To the user though, this should be transparent and as far as they are concerned, they are simply making a webdav connection to FQND/dav/. Most of the DAV portion of my config has been cobbled together from examples I have found elsewhere on the internet or from the Apache site so bear with me if it looks wrong. I'm not even certain that the way I'm trying to do this is the best way. Anyway, here's what I have in the vhost's config file:

<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/
<Directory />
Options -Indexes FollowSymLinks
AllowOverride None
</Directory>

<Directory /var/www/>
Options -Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

RewriteLog /var/log/rewrite.log
RewriteLogLevel 3

Alias /dav/ /davfiles/

<Location /dav/>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/dav/$
RewriteRule ^/davfiles/(.*) /davfiles/%{REMOTE_USER}/$1 [PT]

DAV On
Options Indexes FollowSymLinks
AuthType Basic
AuthName "Drop Box Access"
AuthUserFile /etc/apache2/htpasswds/test
Require valid-user
</Location>

ErrorLog /var/log/apache2/error.log
LogLevel warn
CustomLog /var/log/apache2/access.log combined

</VirtualHost>


When I use a webdav client and login as jimtest1 to access the dav alias on the server I see the following in the rewrite log:

10.0.10.2 - jimtest1 [19/Mar/2011:12:36:31 --0700] [10.0.11.121/sid#9bfd438][rid#9d989d0/initial] (3) [perdir /dav/] applying pattern '^/davfiles/(.*)' to uri '/davfiles/'
10.0.10.2 - jimtest1 [19/Mar/2011:12:36:31 --0700] [10.0.11.121/sid#9bfd438][rid#9d989d0/initial] (2) [perdir /dav/] rewrite '/davfiles/' -> '/davfiles/jimtest1/'
10.0.10.2 - jimtest1 [19/Mar/2011:12:36:31 --0700] [10.0.11.121/sid#9bfd438][rid#9d989d0/initial] (2) [perdir /dav/] forcing '/davfiles/jimtest1/' to get passed through to next API URI-to-filename handler
10.0.10.2 - jimtest1 [19/Mar/2011:12:36:31 --0700] [10.0.11.121/sid#9bfd438][rid#9d989d0/initial] (1) [perdir /dav/] internal redirect with /davfiles/jimtest1/ [INTERNAL REDIRECT]
10.0.10.2 - jimtest1 [19/Mar/2011:12:36:31 --0700] [10.0.11.121/sid#9bfd438][rid#9da29f8/subreq] (3) [perdir /dav/] applying pattern '^/davfiles/(.*)' to uri '/davfiles/'
10.0.10.2 - jimtest1 [19/Mar/2011:12:36:31 --0700] [10.0.11.121/sid#9bfd438][rid#9da29f8/subreq] (2) [perdir /dav/] rewrite '/davfiles/' -> '/davfiles/jimtest1/'
10.0.10.2 - jimtest1 [19/Mar/2011:12:36:31 --0700] [10.0.11.121/sid#9bfd438][rid#9da29f8/subreq] (2) [perdir /dav/] forcing '/davfiles/jimtest1/' to get passed through to next API URI-to-filename handler
10.0.10.2 - jimtest1 [19/Mar/2011:12:36:31 --0700] [10.0.11.121/sid#9bfd438][rid#9da29f8/subreq] (1) [perdir /dav/] internal redirect with /davfiles/jimtest1/ [INTERNAL REDIRECT]


The client errors on connection and doesn't see the folder as a webdav resource. If I pull the rewrite rule out, dav works but it shows you the contents of /davfiles/ which contains each user's own subfolder. But I need it to drop them into their own subfolder much like mod_userdir would do, yet appear to the client like they were just sitting in /dav/.

Is there a way to do this? Judging by the rewrite log I feel I'm on the right path and close, but I can't seem to get the last bit of it going. This is Apache 2.2.9 if that helps. It's Debian Linux. I am not an Apache guru and this is really the first time I've tried something like this, so any help is greatly appreciated.

Thanks

g1smd

7:53 am on Mar 21, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you need the [PT] flag here, or should it be just [L] for an internal rewrite? What's the thinking?

codevyper

12:22 am on Mar 22, 2011 (gmt 0)

10+ Year Member



Thanks for the response g1smd. I threw the [PT] in there figuring it was needed to pass the rewritten internal directory to the Dav On (and subsequent) commands. I don't know that it is needed or not at this point. I just tried switching it to [L] and got a nasty rewrite loop which may be a sign of a step in the right direction or something else flawed in my config. Not sure which at this point.