Search code examples
phplinuxapachedebianmount

Mounting a drive in debian from php code


I've been at this for two days now and haven't been able to find any way (good or bad) of doing that to work.

I have to be able of dynamically mounting drives over network from my website's pages (that part is inevitable).

I have no problems doing it directly on the console with the following command

mount -t cifs //IP-REMOTE-MACHINE/Folder -o username=username,password=password /mnt/share

Obviously trying to just do a shell_exec() of this command wouldn't work with no root rights.

I tried to shell_exec() a script in which I would switch to root user (via su or sudo mycommand) but both of them wouldn't work (never been able to succeed in doing a script who would automatically switch my user to root even with the root pwd hard coded (even if that feels an extremely bad idea I could have accepted that atm).

After that I tried to use pmountbut never found a way to access to a remote shared file (don't think it's even possible but I may have missed something here?)

All that is running on a Debian machine with apache2.


Solution

  • I have a wild idea...

    You could set a cron to run as root that checks for mount commands from your script. The script would simply set a mount command to be processed, and when the cron gets to it, runs the mount, marks the command as processed, and writes to a log file which you could then display.