Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Editing dynamic content with WebDAV Internet
One of the problems with using WebDAV is that you can't open (GET) files that have any kind of server-side rendering, like PHP files. When you open these files, if you can open them over WebDAV at all, you're treated to the rendered page. That sucks!

Here's where mod_rewrite comes in. Apache comes with a very powerful rewriting engine, which allows you to change the content of just about everything on the fly. We can use this power to turn our dynamic pages into something static to suit our editing needs.

Chances are your WebDAV directory configuration in httpd.conf looks something like this:

<Directory /Library/WebServer/Documents/dav>
    DAV On
    AllowOverride AuthConfig
    Options FollowSymLinks Indexes
    AuthName "WebDAV Restricted"
    AuthType Basic
    Require valid-user file-owner file-group
</Directory>
Read the rest of the hint for the changes to implement mod_rewrite...

Now then, if we add the following two lines, in this case, to be able to edit PHP pages, we're in business:

    RewriteEngine on
    RewriteRule     (.*).php$ - [T=text/plain,L]
For the final product below:

<Directory /Library/WebServer/Documents>
    DAV On
    AllowOverride AuthConfig
    Options FollowSymLinks Indexes
    AuthName "WebDAV Restricted"
    AuthType Basic
    Require valid-user file-owner file-group
    RewriteEngine on
    RewriteRule     (.*).php$ - [T=text/plain,L]
</Directory>
So what's going on here? The first line tells Apache to turn on the Rewrite engine. Simple enough. In the second line, we're saying "All URLs that end with .php (the regular expression), do not rewrite the URL (the hyphen), but change the MIME-type to text/plain (the T=text/plain), and make this the last rewrite rule, so that we don't get stuck in a recursive loop (the L)".

There are other ways of accomplishing the same thing, but this is the one that worked for me. It should also work with any other file type. I tried it out for .html and .htm as well, just by changing the regular expression. Worked fine.

Only one caveat. This doesn't seem to work with Digest authentication or SSL (not even when connecting with a PC). I'm not sure why, but if I figure it out, I'll send another post.
    •    
  • Currently 4.00 / 5
  You rated: 4 / 5 (5 votes cast)
 
[8,238 views]  

Editing dynamic content with WebDAV | 11 comments | Create New Account
Click here to return to the 'Editing dynamic content with WebDAV' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Editing dynamic content with WebDAV
Authored by: twenex on Jul 29, '03 01:11:29PM
I've always used this method instead. It has no problems with SSL, doesn't require mod_rewrite and seems a little cleaner.

[ Reply to This | # ]
Editing dynamic content with WebDAV
Authored by: nvdingo on Jul 29, '03 01:17:11PM

ok, but how do you access it without WebDAV?
Doesn't this conf make it so your PHP files don't get processed?
If so, what's the point of that?
I can understand setting up a separate vhost so that you can have the <Directory> block act differently

by separate vhost i mean setting it up as a separate port
so that WebDAV is on port 81 or any other off your choosing.

I am probably missing something, if so, please explain.



[ Reply to This | # ]
Editing dynamic content with WebDAV
Authored by: jabest on Jul 29, '03 04:31:07PM

Hi vmdingo,

You have it right. The Directory block is intended to be put into a VirtualHost block, as you probably wouldn't want to run WebDAV on port 80 anyways. If you were, you'd just turn off PHP, as others have mentioned. I run my WebDAV on 8080.

TTFN, James



[ Reply to This | # ]
Editing dynamic content with WebDAV
Authored by: JayBee on Jul 29, '03 03:15:21PM
erm, why don't you just turn PHP off? Seems much more like what you WANT to do, rather than messily rewriting stuff:
    DAV On
    php_flag engine off
    AllowOverride AuthConfig
    Options FollowSymLinks Indexes
    AuthName "WebDAV Restricted"
    AuthType Basic
    Require valid-user file-owner file-group
Or am I too missing something? (hmm, thinking about this, that'll only work for PHP files, but surely other engines have similar flags?)

[ Reply to This | # ]
Editing dynamic content with WebDAV
Authored by: JayBee on Jul 29, '03 03:16:16PM
erm, why don't you just turn PHP off? Seems much more like what you WANT to do, rather than messily rewriting stuff:
<Directory /Library/WebServer/Documents/dav>
    DAV On
    php_flag engine off
    AllowOverride AuthConfig
    Options FollowSymLinks Indexes
    AuthName "WebDAV Restricted"
    AuthType Basic
    Require valid-user file-owner file-group
</Directory>
Or am I too missing something? Dammit, the renderer killed my HTML code formatting! Note the Directory tags...

[ Reply to This | # ]
Easier, and more secure!
Authored by: below on Jul 29, '03 04:02:43PM
Nice idea, but I have to disagree with the means.
Instead of messing with mod_rewrite (which is a fine tool, don't get me wrong), just use:


DAV On
ForceType text/plain
...


This takes care that all files will be displayed as source, be they shtml, php, perl, whathaveyou.
Also, to get rid off the unencrypted authentification, get mod_auth_digest, which is accepted by both the Finder and iCal (to publish you calendars).
See also:
Getting to the source with WebDAV
The mod_auth_digest module

I have a nicely working setup running on Linux/Debian, and am happy to answer any other questions.

Alex

[ Reply to This | # ]
Easier, and more secure!
Authored by: below on Jul 29, '03 04:10:08PM
Code snippet should have been:

<Directory /Library/WebServer/Documents>
DAV On
ForceType text/plain
...
</Directory>


[ Reply to This | # ]
Permissions?
Authored by: fizgig on Jul 30, '03 12:26:54PM

Can you tell me how you have permissions set up for this?
I have a ton of virtual hosts, all with different usernames (we're a hosting company) but when I log in to DAV (which is a virtual host whose DocumentRoot is the same as my webroot) I can see the folders for my virtual hosts, but can't see any files inside them.



[ Reply to This | # ]
Permissions?
Authored by: jabest on Jul 30, '03 07:44:05PM

I can't speak for others, but I use mod_auth_apple for authentication. The source is available from Apple here:

http://www.opensource.apple.com/projects/darwin/darwinserver/source/apsl/mod_auth_apple-XS-10.1.tgz

Compile it up, install it, then add the following lines to your httpd.conf. First, in the LoadModule area, add this:


LoadModule apple_auth_module   libexec/httpd/mod_auth_apple.so

Next, in the AddModule area, add this line:


AddModule mod_auth_apple.c

Be sure to put these lines in the same place in terms of load order! If you put the LoadModule statement last, then the AddModule needs to be last as well.

Basically, that's it! The mod_apple_auth works just like the mod_auth that comes with Apache, but gets its authenication information from NetInfo. Therefore, within your or block, you'd have something like this:


<Directory /Library/WebServer/Documents>
	DAV On
	... additional directives ...
	AuthType Basic
	Require valid-user
	... additional directives ...
</Directory>

There's no need for an AuthUserFile directive. AuthType Basic will now go looking in NetInfo. It will allow users that are members of the same group as is assigned to the server (by default, this is 'www' or 'nogroup') to log in. To be sure, look in your httpd.conf for this directive:


Group www

It should be uncommented. From here, I expand my permissions further through the use of the 'file-owner' and 'file-group' attributes of the Require statment. These two will look at the file and group privileges on the file/folder, and allow access that way.

To sum up:

valid-user lets them in (provided they're in 'www')
file-owner and file-group give them access to the files

Hope this helps!

TTFN, James



[ Reply to This | # ]
Editing dynamic content with WebDAV
Authored by: jabest on Jul 29, '03 04:26:32PM

Hi all,

A quick few quick updates.

I was aware of the Header and ForceType solutions when I created this method. Neither of those would worked for me, so I came up with this one. It never hurts to find another way.

The solution is intended to be put into a VirtualHost block. My bad for not specifying that.

I've since used this method successfully with SSL. That ended up being a compilation error in PHP, not a problem with mod_rewrite. I should go back now and see if the Header or ForceType solutions work.

TTFN, James



[ Reply to This | # ]
Editing dynamic content with WebDAV
Authored by: mintXian on Jul 30, '03 06:02:12PM

This is what I am using with much success. I like it because it doesn't require two different log-ins, it is easy to make it work with more filetypes and it doesn't force a type of text/plain which can be bad for binary (image) files. It can be used anywhere DAV On can be used.

DAV On
SetHandler default-handler
RemoveHandler .php .cgi .pl .py .shtml .html


[ Reply to This | # ]