Hi there! This is my humble contribution inspired by the great work of the man nfodiz here in the forums. Thanks nfo!
This works 100% on My Book Live Duo too (I actually I have one of those!)
Overview
What this achieves is what I was trying to do the other day, to have a folder dedicated on the MBL/MBLD that was published to the world (friends or myself from any computer) filled with public files, easily downloadable from any browser, without logging in or doing some other stuff. Of course, because of the nature of this, you wouldnât put your taxes document and such in there I actually use it for sharings programs, utilities, to have them available when/if I have to repair a computer, to share files in college, with friends or coworkers, etc. etc.
One easy way was to enable directory listing (which is part of the Apache server) and that would simply publish the folders to the world in the ugliest way possible and without any added functionality. At first I settled for that, but then I started looking at different directory listing templates that build upon it, without any installation required; just some configuration. After trying a couple, I decided for h5ai (âa modern HTTP web server indexâ). These are some of the features it boosts:
breadcrumb for the current directory, linked to all parent directories
auto refresh
custom header and/or footer for each directory
select and download multiple files and folders at once, either as tar or zip archive
filter function for the displayed files and folders
folder sizes
localization with a lot of languages already included
link hover states between main view, breadcrumb and tree view
display HTTP web server details
image preview with keyboard support
text file preview with Markdown rendering and keyboard support
QR codes on hovering files
sort files and folders
status bar with additional information about files and folders
thumbnails for images, pdfs and movies
directory tree view
display breadcrumb in the browser title
As you can see, those are some awesome features to have on our own servers! Some of them donât work out of the box (more on that later), but what was most important to me (downloading zip files of entire directories) finally worked fine!
Results that Weâll Achieve
You will be able to access <your_ip>/public and have those files available anywhere. Whatever you drop on the Public folder will automatically be published on the web server and you can easily send those links to anybody to download directly from your MBL/MBLD
Requirements
- Youâll need to have access to SSH. Enable it via <your_ip>/UI/ssh
- Youâll need to have your port forwarded from your router (if you plan to access those files from the outside world). The inside port should be 80 and the outside port anything you like. If you change it from the default 80, then youâll have to specify it when you want to access the files. Example <your_ip:1234>/public, where 1234 is the defined port
- FileZilla, SCP or something to browse on and edit the files. You can also use nano if itâs easy for you (not for me! I started to like it ;)) and, of course, youâll need putty too
Guide
Bear with me, as this is my first guide. Any improvements/corrections are welcomed!
1) Download h5ai from here at the big blue button on the right (the version as of this writting is 0.22.1)
2) Open WinSCP or FileZilla (you could use the Portable versions) or any SFTP client and configure the SFTP access to your disk
In FileZilla / WinSCP / SFTP Client:
- backup the file /etc/apache2/sites-available/wdnas; either on your computer or on the same MBL/MBLD disk (save it was wdnas.bak)
- edit the file /etc/apache2/sites-available/wdnas with a text editor (Notepad++ for example):
1) add the following text right above â # block application folders from being served â:
<Directory /var/www/public/>
DirectoryIndex index.html index.php /_h5ai/server/php/index.php
</Directory>
2) add the following text inside â<Directory /var/www/> </Directory>â to redirect every access from outside of the LAN to the /public/ directory. It will also redirect not existent lookups (i.e <your_domain>/asdokasmdoaskdnasok will go to /public/). Change your LAN accordingly! (marked as XXX; tipically it would be 192.168.0, 10.0.0, etc.)
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^127\.0.0.1$
RewriteCond %{REMOTE_ADDR} !^XXX\.XXX\.XXX\.(.*)$RewriteCond %{REQUEST_URI} !^/_h5ai(.*)$
RewriteCond %{REQUEST_URI} !^/public(.*)$
RewriteRule $ /public/ [L,R=301]
- copy the _h5ai folder to /var/www/ . Now try to access <your_ip>/_h5ai with a web browser and you should get a â403 Forbiddenâ error
In putty:
- chmod -R 755 /var/www/_h5ai/
This gives access to the _h5ai dir to Apache
-
chmod o+w /var/www/_h5ai/cache/
This gives write access to the cache folder of _h5ai, needed for some functionalities (like zip batch downloading) -
ln -s /DataVolume/shares/Public/ /var/www/public
This creates a symlink to the Public folder. You could certainly use any other path of your chosing
- a2enmod autoindex
This enables the autoindex function of Apache for Directory Listing
- /etc/init.d/apache2 restart
This restarts the Apache server and enables all the customization done
h5ai Configuration:
You can manage all kinds of settings from a file. Everything is well documented and you should tune it to your liking. For example, you can enable download of multiple files as zip, allow remote deletion and renaming, enabling QR codes, etc. You can edit the file also with Notepad++. Thereâs no need to restart the server between changes!:
- /var/www/_h5ai/conf/options.json
This is the location of the configuration file for h5ai. Edit it and youâll see the documentation
Results Achieved
Now you will be able to access the Public folder from any device in the world! Just remember to open the 80 port on your router
Youâll get something like this (you can try a live demo here:
(Notice the red highlighted files. Thatâs the (rather obscure) way of multiselection. You have to press CTRL and click them in order to be able to download them as one compressed file). You can also drag the mouse around (as in Windows) to select multiple items
Why was this Good for me?
From my point of view, this is a nice option for sharing files. Because you are using the built in Apache server, thereâs no need to install more stuff (no overhead) or even have extra daemons running just to serve the files. You just take advantage of what you already have, and improve upon it. Sure, you could also use the vainilla Directory Listing, but youâll be missing a lot of âfree functionalityâ
Whatâs Missing? (Please Contribute if Possible! :))
1) When you access the _h5ai folder now through a browser, youâll actually verify all of the supported stuff of the server. Youâll see that some of the items are unsupported (I think these are all of them):
- Image Thumbnails (Require PHP-GD)
- PDF Thumbnails (Require convert command; apparently from ImageMagick)
- ZIP & Tar PHP support
As Iâm pretty much OCD myself, Iâd love to have them all on green! So, in my blindness I went and installed php5-gd to see if Image Thumbnails would work. I did (DO NOT RUN THIS) apt-get install php5-gd (DO NOT RUN THIS) and all bleep broke lose. The device bricked since php got uninstalled, Apache didnât even start, so I had to reimage the OS and start over. Then I tried installing the same package via OptWare. Although it didnât remove anything (as with apt-get), Apache still bricked and wouldnât start. Iâve tried ImageMagick too and the options kept showing as red, so I didnât know how to enable them.
You probably have a lot of Linux knowdlege; maybe you can help us with this (get all green as supported!) and Iâll update the guide accordingly
2)Another thing that sprung to mind. You know, when you access your root Apache server from the extranet, either by typing it manually in the browser or by clicking the breadcrumbs / go up icons in h5ai, you will get the WD error saying that you donât have access to UI/something. Itâs actually the WD dashboard and itâs a good thing that this happens! But what I would like is, no matter whatever address I type (i.e. mydomain.com/hello_word), it would redirect me to /public/. So, when I go to the root or someplace else, it would land on public. I think this can be achieved with php and the .htaccess file. Iâll look into it as soon as I debrick the device again and post if Iâm succesful. This is also a good measure to stop the outside world from knowing that you have a MBL/MBLD This should be working now!
Well, this is it, hope you like; maybe I missed something here, if it doesnât work please let me know and Iâll look through my notes again to check it up and reply back.
Enjoy!