0

我需要帮助,我有在 php 中运行此部分的 web 界面:

  $cmd="/usr/sbin/sudo /usr/sbin/service networking stop"
exec($cmd, $mes);

print_r($mes);  #this is emptz message

$cmd="/sbin/ifconfig"
exec($cmd, $mes);

print_r($mes); 

print_r($mes); 停止服务为空 print_r($mes); 对于 ifconfig=array 有关于接口的所有信息(但所有信息都没有关闭,所以上面的消息不能正常工作(这个服务仍然运行))

该脚本通过守护程序用户运行。

这是我的 visudo:

# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d
www-data ALL =NOPASSWD: /bin/nc, /bin/cp, /bin/chmod, /bin/chown, /etc/init.d/, /usr/sbin/service
deamon ALL = NOPASSWD: /bin/cp, /bin/chmod, /bin/chown, /etc/init.d/, /usr/sbin/service, /home/optokonlmcp/sss.php, /sbin/ifconfig

请问你知道为什么这个 php 脚本不起作用吗?先感谢您

BR MK

4

2 回答 2

0

SOLUTIONS:

  1. Create sctipt with rolus for root (root:root) and command what i need to do(sudo /usr/sbin/service ) command must contain sudo

  2. add script into visudo+ all command that are meantioned in my Script: Visudo containing:

    daemon ALL=NOPASSWD: /usr/bin/sudo, /path_my_script/script.sh

  3. Of curse cript must have rule for opening so i change rules for 755.

  4. Now you can try run script with daemon, i use this command: sudo -u daemon /patch_of_script/script.sh

  5. last point is add command into php: exect("sudo /path/./script.sh" )

    Now i can restart network via php. Thank you BR MK

于 2016-11-07T07:09:55.250 回答
-1

替换exac($cmd, $mes);exec($cmd, $mes);

于 2016-11-04T16:19:30.100 回答