Here I get a querystring depending upon the value from the command shell_exec()
.
I am receiving a value the querystring but shell_exec()
is not working.
I am using a webcam connected to Raspberry pi 3 so the command in shell_exec()
is to turn the webcam ON an OFF.
$output=shell_exec('sudo /etc/init.d/motion start')
码:
<?php
$status=$_GET['status'];
if($status == 'on')
{
$output=shell_exec('sudo /etc/init.d/motion start');
}
if($status == 'off')
{
$output=shell_exec('sudo /etc/init.d/motion start');
}
我该如何解决执行问题?
而不是尝试赋予apache / http用户sudo权限,通常的方法是创建suid包装二进制文件,如下所示:
... and than in php to call
shell_exec("/path/to/suidmotion start/stop");
sudo gcc
will produce output binarysuidmotion
owned byroot:root
, andchmod +s
ensures that binary rights up on execution will be escalated to binary owner (root), regardless who run it.