ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Permissions. your PHP script is run as some user and that user needs to permission to run mount & umount. Once the PHP script is run by a user who has permission to run mount & umount that code will work. I recommend changing the permissions on mount & umount instead of running the PHP as root.
Originally posted by JoshFed Permissions. your PHP script is run as some user and that user needs to permission to run mount & umount. Once the PHP script is run by a user who has permission to run mount & umount that code will work. I recommend changing the permissions on mount & umount instead of running the PHP as root.
I would like to make a php-site that can mount a dir on the network (given by the website visitor) to a dir /home/www/downlaod so he can download the contents of the share on the network from the internet. But on the moment I'm stuck on the permissions of the dirs and scrips. Could you give me some hints how to manage it.
The command:
# mount -t smbfs -o guest //servername/share /home/www/download can be executed by the root user, but doesn't work in the commandline exec('mount .....') in a php script.
I would like to make a php-site that can mount a dir on the network (given by the website visitor) to a dir /home/www/downlaod so he can download the contents of the share on the network from the internet. But on the moment I'm stuck on the permissions of the dirs and scrips. Could you give me some hints how to manage it.
The command:
# mount -t smbfs -o guest //servername/share /home/www/download can be executed by the root user, but doesn't work in the commandline exec('mount .....') in a php script.
I'm basically trying to do the same thing here, with no idea where to begin. I'm trying to make a page pulling a list of images from a database, mount one of them from the list, and be able to unmount the same image when I am done with it. Any help would be greatly appreciated.
I have the DB setup and working, and connecting to php with no problems, its only the actual mount/unmount that I have no idea where to go with. Also if anyone has a better solution to this, by all means enlighten me. Doesnt have to be a php page, the *nix box is local, i just need access to iso files that are mounted and shared through smb
I have the DB setup and working, and connecting to php with no problems, its only the actual mount/unmount that I have no idea where to go with. Also if anyone has a better solution to this, by all means enlighten me. Doesnt have to be a php page, the *nix box is local, i just need access to iso files that are mounted and shared through smb
Thank you, Joe
Joe,
Later I fixed it in de rather dirty way. I wrote a bash script with root privilages. This script could be run by the user 'www-data' without any password, but can only by read and edited by the root user. This script can be called in a PHP script with attributes. You could do it nicer by making a special user with only mount privaliges, to make it more safe.
To give the www-data user root privaliges, use 'sudo visudo' and add to the bottom:
www-data ALL=NOPASSWD: <location of your script>/<scriptname>
My bash file looks like:
Code:
#! /bin/bash
urldecode () {
local bf=
local cb=
local hi=0
local le=0
local x=-1
for p in "$@"; do
le="${#p}"
while (( x++ < le-1 )); do
case "${p:${x}:1}" in
"%")
if (( hi == 0 )); then
(( hi++ ))
else
bf="${bf}${p:${x}:1}"
hi=0
fi
;;
"+")
bf="${bf} "
;;
*)
if (( hi == 0 )); then
bf="${bf}${p:${x}:1}"
fi
if (( hi == 2 )); then
cb="${cb}${p:${x}:1}"
bf="${bf}$(echo -e "\\x${cb}")"
hi=0
fi
if (( hi == 1 )); then
cb=${p:${x}:1}
(( hi++ ))
fi
;;
esac
done
done
echo -n "$bf";
}
if [ "$1" ]; then
PATTERN=$1
echo atribuut $PATTERN
else
echo geen attribuut meegegeven
exit
fi
TASK=$(urldecode $2)
#echo atribuut nr 2 $TASK
TARGET=$(urldecode $3)
#echo atrubuur nr 3 $TARGET
# kaksh
if [ $PATTERN = "-p" ]; then
if [ -n $TASK ]; then
smbclient -L $TASK
fi
fi
if [ $PATTERN = "-m" ]; then
if [ -n $TASK ]; then
if [ -n $TARGET ]; then
echo mounting
echo "mount -t smbfs -o guest $TASK /home/sjors/public_html/mnt/$TARGET"
mount -t smbfs -o guest $TASK /home/sjors/public_html/mnt/$TARGET
fi
fi
fi
if [ $PATTERN = "-u" ]; then
if [ -n $TASK ]; then
umount -l /home/sjors/public_html/mnt/$TASK
fi
fi
if [ $PATTERN = "-g" ]; then
if [ -n $TASK ]; then
if [ -n $TARGET ]; then
cd /home/sjors/public_html/mnt/$TARGET
/home/sjors/smbget-0.6/smbget -u guest -p "" smb:$TASK
fi
fi
fi
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.