Tuesday, March 25, 2008

Mounting network shares from a web browser.

Continuing my project of a php network file manager.

First problem i have come across is simply that you need to have super user rights to mount network shares.

The solution,
1) try and find out the username the web service uses when sending commands, this is managed by using the command:

?php system("whoami"); ?

this simply outputted the username "www-data" to the web browser.

2)allow user "www-data" to use the mount and umount command without prompting for a password.
This is done by making changes to the sudoers file. (WARNING FIRST TIME I DID THIS I MADE A MISTAKE AND SCREWED MY LINUX INSTALL)
- from the terminal run "sudo visudo -f /etc/sudoers" (you must use visudo to edit)
- under the user section add these lines:
"www-data ALL=NOPASSWD: /bin/mount"
"www-data ALL=NOPASSWD: /bin/umount"
- to save hold Ctrl and tap o, then make sure it saves as just "sudoers" Ctrl x to exit.
3) adding the mount command to the php page
(FOR MOUNT TO WORK YOU NEED TO INSTALL SMBFS "sudo apt-get install smbfs")
system("sudo mount -t smbfs //server/share /folder-to-mount-to -o username=username,password=password"); ?

4) running the page will now mount the share to the folder, this is very basic, but a good place to start, i will move on now to replacing this string with variables, and run with the idea of putting this command in the header and putting a umount in the footer.

I'm Back

Been a while since i posted anything, not because i forgot about this blog but mainly because i have been doing nothing interesting for a long time. Time to change!!!!