homepage Welcome to WebmasterWorld Guest from 54.167.173.250
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Webdav Rewrite to PHP to mkdir for user
zimurgy




msg:4297168
 9:23 pm on Apr 13, 2011 (gmt 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
DAV On
AuthType Basic
AuthName "Drop Box"
AuthBasicProvider ldap
AuthLDAPURL ldap://odm.example.com:389/dc=odm,dc=example,dc=com?uid
Require valid-user
</Directory>

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

</VirtualHost>

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

<?php
$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.

Cheers!
Z

 

jdMorgan




msg:4297615
 3:51 pm on Apr 14, 2011 (gmt 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.

Jim

zimurgy




msg:4297797
 7:02 pm on Apr 14, 2011 (gmt 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.

Cheers,
Z

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved