note 71466 deleted from function.system by mazzanet
| From: | mazzanet@php.net | Date: | Wed, 14 Feb 2007 09:53:01 +0000 |
| Subject: | note 71466 deleted from function.system by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-123354@lists.php.net to get a copy of this message | ||
Note Submitter: bespoleznyak[at]narod[dot]ru
----
run programm as super-user (*nix):
<?php
function sudoExecute($command)
{
$tmp = array();
preg_match('/^([^ ]+?)( |$)/', trim($command), $tmp);
$command_to_execute = $tmp[1];
$sudo_output =
sudo -l;
preg_match_all('/ (\/[\w\/]+?)(,|$)/', $sudo_output, $tmp);
if (count($tmp) > 1) {
$allowed_commands = $tmp[1];
if (array_search($command_to_execute, $allowed_commands) === false) {
return false;
}
} else {
return false;
}
return system("/usr/local/bin/sudo $command 2>&1");
}
?>