Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Webdav Rewrite to PHP to mkdir for user

9:23 pm on Apr 13, 2011 (gmt 0)

New User

5+ Year Member

joined:Apr 13, 2011
votes: 0

Hello, I am hoping that someone can assist me with this. I have been trying different things for days and I am not skilled enough to pull it off. I am also assuming this might be possible. What I am trying to do is have a webdav user redirected to a php file that will make their webdav folder and redirect to it if it does not exist.

I have a virtual host like below:

<VirtualHost *:80>
ServerName video.example.com
ServerAlias video.*
ServerAdmin webmaster@localhost
RewriteEngine On
RewriteLog /var/log/rewrite.log
RewriteLogLevel 9
RewriteCond /var/www/webdav/%{LA-U:REMOTE_USER} -d
RewriteRule ^/(.*) /var/www/webdav/%{LA-U:REMOTE_USER}/$1
RewriteCond /var/www/webdav/%{LA-U:REMOTE_USER} !-d
RewriteRule ^/(.*) /var/www/webdav/register/$1?username=%{LA-U:REMOTE_USER}
DocumentRoot /var/www/webdav
DirectoryIndex "index.php"
<Directory /var/www/webdav>
Options Indexes MultiViews +FollowSymlinks
AllowOverride None
Order allow,deny
Allow from all
AuthType Basic
AuthName "Drop Box"
AuthBasicProvider ldap
AuthLDAPURL ldap://odm.example.com:389/dc=odm,dc=example,dc=com?uid
Require valid-user

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined


index.php located at /var/www/webdav/register/

$username = $_GET['username'];
mkdir("/var/www/webdav/" . $username, 0777);

I know this is not safe, but at this point I am just trying to get it working. This is not a public facing server.

If I log on using my Mac, it creates the folder for me no problem, when I log in with cadaver, it logs in and redirects me to the /var/www/webdav/register folder and doesn't create the folder.

I can live with the fact that this is possibly not doable, just need to know that from a seasoned expert.

3:51 pm on Apr 14, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0

I don't know a thing about DAV or "cadaver" but despite that, it's obvious that this code (either Apache config code or your script) needs to handle (and perhaps flag) the case where Remote_User is not available:

# Modified "create new user" rule - Case where Remote_User is available and valid
RewriteCond /var/www/webdav/%{LA-U:REMOTE_USER} !-d
RewriteCond %{LA-U:REMOTE_USER} ^([a-z][a-z0-9_\-]+[a-z0-9])$ [NC]
RewriteRule ^/(.*) /var/www/webdav/register/$1?username=%1 [L]
# New "cannot create new user" rule - Case where Remote_User is unavailable, invalid, or already assigned
RewriteCond %{LA-U:REMOTE_USER} !^[a-z][a-z0-9_\-]+[a-z0-9]$ [NC]
RewriteRule ^/(.*) /var/www/webdav/cannot-register-new-remote-user.html [L]

It's quite possible that the remote_user is not available if "cadaver" is some sort of "telnet" or "console" type of tool. So in addition to making your method a little safer, it will also allow you to test this case unequivocally by rewriting the request to "cannot-register-new-remote-user.html" in that case.

7:02 pm on Apr 14, 2011 (gmt 0)

New User

5+ Year Member

joined:Apr 13, 2011
votes: 0

Thank You Jim for your time. The configuration is behaving the same way as before. I am thinking this is just not possible. I was trying to avoid needing my people to "register" using a php form to create their webdav folders if they have a working username and password account.

Cadaver is a command line webdav client. When I mount the server using OSX it behaves the same way, takes me to the directory but doesn't create the folder. I am guessing that the rewrite behind the scenes is not the same as when you launch the webpage using Safari where it behaves correctly and creates the folder using the php script.

Thanks again, I am giving up on the idea and will ask people to register manually before using webdav.