Re: su idn't working from within php
| From: | Jas | Date: | Tue, 27 Jan 2004 15:49:01 +0000 |
| Subject: | Re: su idn't working from within php | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-175929@lists.php.net to get a copy of this message | ||
Marek Kilimajer wrote:
You need to edit /etc/sudoers file and allow apache to execute <command>. And you also need to be carefull what you are doing or you will create a security hole. Nitin Mehta wrote:[shell.sh] #!/bin/sh if test -f /path/to/file then echo "file found, proceeding to execute command as root" <code to be run as root> echo "removing temporary file used to signal process" rm -dfr /path/to/file else echo "file was not found, exiting shell gracefully" exit 0 fi [end shell.sh] [script.php] if(!emtpy($yourvariable)) { echo "variable found, creating temporary file to flag shell script to execute"; system("touch /path/to/file"); } else { echo "variable not present, exiting"; } [end script.php] [crontab <file>] */5 * * * * /path/to/shell.sh >>/tmp/php_log 2>&1 [end crontab <file>] *** make sure you are root when adding this command to your cron jobs This way your cronjob runs every five minutes and executes your shell script. Your shell script checks to see if a temporary file is present and if it is executes the command on the server as the root user. No privledge escalation holes. Hope this helps, let me know if it doesn't or if you don't have dedicated hosting. Jasbut how would i store keys for apache? ----- Original Message ----- From: "Marek Kilimajer" <kilimajer@webglobe.sk> To: "Nitin Mehta" <nitinmehta@kappa.net.in> Cc: <php-general@lists.php.net> Sent: Tuesday, January 27, 2004 4:03 PM Subject: Re: [PHP] su idn't working from within phpWhy do you need su? Set up sudo for apache user. Nitin Mehta wrote:my php script withhi all i was trying to execute some commands as an authorized user from withingenerated with keygen, as the scripts are run as apache/http user..........exec ("su <username> -c \"sudo <command>\" 2>&1;", $output); but it gives me standard in must be a tty how can i make it work? it runs perfectly at command prompt I even tried to ssh, but the problem is where should i copy the rsa-keyCan I recommend you don't try to add the apache webserver user to your sudoers file? Big no-no. If anyone tries to issue a 'su' command on your server from a web based form for example you could compromise your machine. I have a more elegant solution... create a shell script 'command.sh' and then setup a cron job to execute the script every so often. Let me show you an example...Plz help me out of this Thanx in advance Nitin-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php