在Google上打开并阅读每一个结果后,我认为是时候在某处创建自己的主题了.对不起,我需要问一个之前已经被问过的问题,我不能强调这一点,但我别无其他选择,因为没有其他问题帮我实现了我的目标.
我正在尝试通过由HTML(用于按钮/文本)和PHP(用于执行上述功能)提供支持的Web界面来设置重启/执行其他系统功能的方法.
我无法让这个工作.我已经读过我需要将web用户添加到sudoers文件中,我已经尝试过了.我在我的服务器上运行Nginx,如何在我的情况下将用户添加到sudoers?
此外,我知道安全风险.
以下是我到目前为止的情况:
HTML(index.html):
<body>
<h3>Restart</h3>
<p>
<form action="restart.php" method="get">
<input type="submit" value="Press me.">
</form>
</p>
</body>
Run Code Online (Sandbox Code Playgroud)
PHP(restart.php):
<?php
echo "This is a test";
echo "<br>";
echo "<br>";
echo shell_exec('ifconfig');
echo "<br>";
echo "<br>";
echo "Restarting server...";
exec ('/usr/bin/sudo /etc/init.d/portmap restart');
shell_exec("/sbin/reboot");
exec("/sbin/reboot");
system("/sbin/reboot");
?>
Run Code Online (Sandbox Code Playgroud)
请注意,在这里,我只有很多东西试图执行,所以我确保当其中一个有效时我会击中目标,如果这有意义的话.IFConfig只是一个测试,以确保它实际上能够执行.
sudoers的:
# User privilege specification
root ALL=(ALL:ALL) ALL
www-data reboot = NOPASSWD: /sbin/reboot
Run Code Online (Sandbox Code Playgroud)
这一切都在Ubuntu 14.04 LEMP上.