【发布时间】:2021-02-28 20:19:12
【问题描述】:
对于我的树莓派项目,我想托管一个简单的网站,其中包含一些可以运行 sudo 命令的 html 按钮。我试过这个方法:
<?php
if (isset($_POST['button']))
{
exec('sudo reboot');
}
?>
<html>
<body>
<form method="post">
<p>
<button name="button">Run</button>
</p>
</form>
</body>
</html>
并将 www-data 添加到 sudo 组并确保 sudo 登录不需要密码,并在我的 sudoers 文件中替换此行
%sudo ALL=(ALL:ALL) NOPASSWD: ALL
但没有执行任何命令,甚至没有执行非 sudo 命令。
【问题讨论】:
-
你可以尝试使用“/usr/bin/sudo -S reboot”
-
检查您的 php.ini 文件中是否有包含“exec”的
disable_functions行。
标签: php html linux raspberry-pi