0

I need help, i have webinterface thar run this section in php:

  $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); For stop service is empty print_r($mes); For ifconfig=array have all information about interface (but all are up not down so above mesagge not work well (this service still run))

This script is running via deamon user.

This is my 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

Please do you know why this php script not work ? Thank you in advance

BR MK

Box Box Box Box
  • 5,094
  • 10
  • 49
  • 67
  • Please do not edit your question after an answer/comment has pointed out something, as that makes the answer/comment invalid. – Box Box Box Box Nov 05 '16 at 06:51
  • Now I find out solution. I create sctipt with rolus for root (root:root) and add it into VISUDO. my Script: sudo /usr/sbin/service networking stop Into visudo i must add all patch of created script and with php call script with sudo exect(''sudo /path/./script.sh" ) After this change all work well. – M. Krupicka Nov 07 '16 at 06:55

2 Answers2

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

Community
  • 1
  • 1
-1

Replace exac($cmd, $mes); with exec($cmd, $mes);

Sofiene Djebali
  • 4,398
  • 1
  • 21
  • 27