apache webdav with web-interface and capability to hide dot files of mac osx

this is my “perfect setup” of an apache webdav share with a nice webinterface based on Chris Chabot’s WebFM and most importantly, the capability of hiding those dot-files which mac’s running osx put in those shares to annoy windows and somtiems also linux users.

i strongly recommend you to publish your share on a ssl encrypted page. i have read somewhere that windows xp requires webdav to be ssl encrypted unless you do some registry hacks. but i’d rather spend my time preparing ssl encryption that hacking my windows to support unsecure transfers.

apache’s mod_dav already comes with some html directory listing capabilities, but it doesn’t look very up-to-date and even worse, you can’t manipulate files at all with this interface. that’s why i am using a slightly modified WebFM: it offers file upload and download as well as copying and pasting of files and the creation of directories. last but not least it has a much better looking interface :)

WebFM 0.2

The OSX dot-file problem

Apple’s OS X uses a stupid filesystem which is not capable of storing meta data for files allthough mac osx wants to save some meta data (for example, when you have this big mess of randomly mixed icons in a folder, it saves this and displays the same mess to you again when you open the folder for the next time, wow, what a super feature ;) ) but i’m not here to judge on osx features… the problem is, because it can’t save these informations in the filesystem, mac osx creates those hidden metadata files like .DS_Store and .filename and such. As long as only mac clients are using the webdav share this is no problem at all, but as soon as for example windows users use it, they can see those “hidden” files perfectly well and they just start to annoy everybody. so i have programmed a little custom filter for apache which filters those hidden files out and actually hides them. the good thing for you mac users out there is, that it still allowes to save those files and it even allows to read from them, but only if you know the filename. so osx is still capable of doing all its meta data rubbish without disturbing anybody else.
i also modified WebFM so it can now hide those dot-files and you can disable WebFM’s own authentication which just gets in your way when you are using apache’s authentication to protect your webdav share.

this is how it’s done

first of all create a directory where you want all the stuff to be. optimally the directory where the webdav data is stored is a subdirectory in another directory which then holds the necessary php files for the webgui and the apache filter.

for example this:


mkdir /var/www/webdav
mkdir /var/www/webdav/docs

/var/www/webdav/docs will be the document root for our webdav share, whatever is in /var/www/webdav is not published through this webdav share.

make sure your docs directory is writeable by the user apache runs as.

now download the webdav_helpers.tar.gz file and extract it into your /var/www/webdav folder.


cd /var/www/webdav
wget http://blog.psuter.ch/wp-content/uploads/2008/11/webdav_helperstar.gz
tar xzvf webdav_helpers.tar.gz 
rm webdav_helpers.tar.gz

make sure that filter.php is executable and make sure you have php-cli installed (apt-get isntall php5-cli)

next lets configure the apache webserver. here’s my virtualhost entry in the apache configuration. you can probably also do most of this with a .htaccess file but don’t ask me how.. google it, there are plenty of howto’s around.


NameVirtualHost *:443
<VirtualHost *:443>
	ServerAdmin webmaster@localhost
	
	SSLEngine On
        SSLCertificateFile /etc/apache2/ssl/apache.pem

	DocumentRoot /var/www/webdav/docs
	
	
	ExtFilterDefine hide-dot-files mode=output cmd="/var/www/webdav/filter.php"

	<Directory /var/www/webdav/docs>
		DAV on
		IndexIgnore .DS_Store
		Options +Indexes
		AllowOverride AuthConfig
		AuthType Basic
		AuthName "My WebDAV Share"
		AuthUserFile /var/webdav/users
		Require valid-user
		SetOutputFilter hide-dot-files
	</Directory>
	Alias /index.php "/var/www/webdav/fm.php"
	Alias /fmicons "/var/www/webdav/fmicons"
	CustomLog /var/log/apache2/access.log combined
	ServerSignature On

</VirtualHost>

the filter is applied before the data is sent out to the client. it will find those dot-file entries and erase them before it sends out the answer to the client. this might have a performance impact, but i have so far not felt it. if you request a dot-file manually you can still download it or enter a hidden directory and then see the contents of it. only ls -al on a linux client won’t display the files allthough it does on a local folder in linux.
in order to use this filter stuff you need to install mod_filter and mod_ext_filter which allowes you to use custom filters.

the aliases for the fm.php and the fmimages directory allow to have webfm as a front-end when opening the webdav url in a webbrowser like firefox but the files don’t appear in the directory listing.

now you need to create the /var/webdav/users file which contains your webdav users and allowes them to connect to your webdav share:


htpasswd -c /var/webdav/users paul

-c is only used the first time, when you create the file, afterwards, to add more users, just leave the -c away and it will append the other users to the password file.

make sure your ssl keys are in place and then restart apache.

you should be all done now.

Leave a Reply