0

私は助けが必要です、私はphpでこのセクションを実行するwebinterfaceを持っています:

  $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 には、インターフェイスに関するすべての情報があります (ただし、すべてがダウンしていないため、上記のメッセージはうまく機能しません (このサービスはまだ実行されています))

このスクリプトは、deamon ユーザーを介して実行されます。

これは私の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

解決策:

  1. ルート (root:root) の rolus を使用して sctipt を作成し、必要なコマンド (sudo /usr/sbin/service ) コマンドには sudo が含まれている必要があります

  2. スクリプトをvisudo +に追加します私のスクリプトで意味されているすべてのコマンド:Visudoを含む:

    デーモン ALL=NOPASSWD: /usr/bin/sudo, /path_my_script/script.sh

  3. 呪いのクリプトには開くためのルールが必要なので、755 のルールを変更します。

  4. これで、デーモンでスクリプトを実行してみることができます。私は次のコマンドを使用します: sudo -u daemon /patch_of_script/script.sh

  5. 最後のポイントは、php にコマンドを追加することです: exect("sudo /path/./script.sh" )

    これで、php 経由でネットワークを再起動できます。ありがとうございます

于 2016-11-07T07:09:55.250 に答える