从php运行csf命令,而不是以root身份运行


running a csf command from php not as root

我正试图从php脚本中运行以下csf命令:

$ipNbr = 199.231.184.25 ;   // for example
$csfCommand = 'sudo  /usr/sbin/csf  --tempdeny ' . $ipNbr . ' 3600;'  ;    
$csfResult = shell_exec($csfCommand) ;  
$csfResult = exec($csfCommand) ; // i also tried exec rather than shell_exec

到目前为止,这根本没有任何作用,包括返回任何类型的错误/诊断消息。在我的日志文件中,我确实看到:

[Fri Nov 20 13:28:13 2015] [error] [client 66.201.41.254] sh: /usr/sbin/csf: Permission denied

我在visudo内部放置了以下行:

visudo ;
marksdomain.com    ALL=(ALL)       NOPASSWD: /usr/sbin/csf

我试过了我能想到的每一种组合:

/bin/sudo  /usr/sbin/csf    . . . . 
sudo  /usr/sbin/csf     . . . . 
/usr/sbin/csf     . . . .
csf     . . . .

有什么想法可以从php脚本中启动csf命令吗??

非常感谢大家。

我相信我现在已经开始工作了,这完全归功于上面所有善意和耐心的评论:

$csfCommand = '/usr/bin/sudo  -u root  -s  /usr/sbin/csf  --tempdeny ' . $ipNbr . ' 3600;'

visudo:

marksDomain(dot)com   ALL=(ALL:ALL)   NOPASSWD:       /bin/sh
marksDomain(dot)com   ALL=(ALL:ALL)   NOPASSWD:       /usr/sbin/csf