...

View Full Version : How to start a program from web browers using php



acrs
11-20-2010, 09:08 PM
Hi. I'm trying to make a open source kiosk like system. When the web browser starts all programs, it will run in the browser using PHP. I've found this link: Program execution Functions. It's using:

<?php
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run("WINWORD.exe", 7, false);
?>

I was able to start Microsoft Word on Windows, but I need to be able to do this on Linux. This is what I've tried on my Linux server:

<?php
exec("/var/www/test.sh");
?>

But nothing happens. I know that test.sh works because I ran if from the terminal. I use test.sh to start a Python script. The Python script starts a text editor. I've tested the Python script and it works. All I need know is how to start the script from PHP on Linux.

DrDOS
11-20-2010, 09:24 PM
Make sure you have full permissions on test.sh You might want to consider setting permissions at the start of the script and resetting them after the script is run, for security reasons. Also, you can try shell_exec.

PS: You can try this.
<?php



$vals = shell_exec("dir -1Q");

print $vals;



?>

firepages
11-21-2010, 07:30 AM
as you noticed linux is a little more secure than windows :)

who is the owner of test.sh? it needs to be apache/www-data/httpd, whatever your apache runs as.

if your script needs to run as root you need to add apache to the list of sudoers (see /etc/sudoers) and configure that file to allow apache (www-data/httpd whatever) to execute that script ... here is a very unsafe example that we use internally :)

(part of) /etc/sudoers


# Cmnd alias specification
#an alias for the stuff we want to allow
Cmnd_Alias MOUNTS = /bin/mount, /bin/umount
#give www-data ability to use the command alias without a password ~~~~
www-data ALL = (root) NOPASSWD: MOUNTS




$success = `sudo mount /dev/sdg1 /media/browse_backup`;


as you can imagine giving apache any root access is dangerous, so hopefully you wont have to, it depends what your script is trying to do.

acrs
11-21-2010, 12:17 PM
ok i got it to work using firepages example

(part of) /etc/sudoers
Code:

# Cmnd alias specification
#an alias for the stuff we want to allow
Cmnd_Alias MOUNTS = /bin/mount, /bin/umount
#give www-data ability to use the command alias without a password ~~~~
www-data ALL = (root) NOPASSWD: MOUNTS

PHP Code:
$success = `sudo mount /dev/sdg1 /media/browse_backup`;

0 down vote accept


I had to change the test.sh owner permission to www-data



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum