LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-23-2005, 05:53 PM   #1
Dhamon
LQ Newbie
 
Registered: Aug 2005
Posts: 3

Rep: Reputation: 0
Running the mount command from PHP


Debian, kernel 2.4.27, php 5, apache 2.0.52
connecting to a Windows XP share(everyone full control)

What I need it to do is mount a smbfs, work with a txt file then unmount it.

PHP Code:
exec("mount -t smbfs  //computer/share /mnt");
exec("umount /mnt"); 
These are the only 2 commands that don't seem to be working in my script. If I manually mount the smbfs everything works fine.

Anyone out there able to shed some light on the problem?
 
Old 08-23-2005, 06:29 PM   #2
JoshFed
LQ Newbie
 
Registered: Apr 2004
Location: Atlanta, GA, USA
Distribution: Slackware 9.1, 10 Gentoo
Posts: 24

Rep: Reputation: 15
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.
 
Old 08-24-2005, 09:14 AM   #3
Dhamon
LQ Newbie
 
Registered: Aug 2005
Posts: 3

Original Poster
Rep: Reputation: 0
Great! thanks for the tip!
 
Old 09-20-2005, 02:06 PM   #4
sshark
LQ Newbie
 
Registered: Sep 2005
Posts: 2

Rep: Reputation: 0
Quote:
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.
 
Old 04-09-2009, 08:31 PM   #5
jszoladi
LQ Newbie
 
Registered: Apr 2009
Posts: 1

Rep: Reputation: 0
Quote:
Originally Posted by sshark View Post
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

Thank you, Joe
 
Old 04-10-2009, 03:32 AM   #6
sshark
LQ Newbie
 
Registered: Sep 2005
Posts: 2

Rep: Reputation: 0
Quote:
Originally Posted by jszoladi View Post
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

Good luck with it,

Kind regards,

SShark
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mount -r while fsck is running? aaccomazzi Linux - Hardware 1 10-20-2004 04:00 PM
php running as CGI twk Programming 1 05-25-2004 08:26 AM
how to get php running on slackware fatum Linux - Software 2 01-20-2004 12:32 PM
Running a terminal/prompt from PHP james_cwy Linux - Newbie 1 12-15-2003 12:09 AM
Ftp and php running very slow. 360 Linux - Software 0 05-29-2002 04:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration