php exec, sudo....

Discussion in 'Programming/Scripts' started by sojic, Oct 31, 2008.

  1. sojic

    sojic New Member

    I have some problem with php function exec.

    I'm trying to execute

    Code:
    exec("whoami");
    echo exec("whoami");
    ....
    
    
    but, I do not "receive" anything. Also I should use sudo.

    I have /root/start, /root/stop
    Code:
    #!/bin/sh
    #touch /var/lock/subsys/local
    # Firewall za port forward
    iptables -I FORWARD -p tcp -s $1 -d 192.168.168.2 -j ACCEPT
    
    I should execute from php:
    Code:
    exec("sudo /root/start ".$_SERVER['REMOTE_ADDR']);
    
    So... exec do not work, and how to set "sudo with apache"
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Exec is not returnung any output. Please take a look in the php documentation, there are other functions like system and passthru that give you the output back.
     
  3. Leszek

    Leszek Member

    For example shell_exec:

    Code:
     [COLOR=#000000] [COLOR=#0000BB]<?php
    $output [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]shell_exec[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'ls -lah'[/COLOR][COLOR=#007700]);
    echo [/COLOR][COLOR=#DD0000]"<pre>$output</pre>"[/COLOR][COLOR=#007700];
    [/COLOR][COLOR=#0000BB]?>[/COLOR] [/COLOR] 
         
    
    Functions mentioned in this thread are often blocked by admins because they can be dangerous for the server. It's ok as long as You run them on Your own server without such restrictions.
     
  4. sojic

    sojic New Member

    Still same problem, I get only <pre></pre>
     
  5. Leszek

    Leszek Member

    Make sure that "shell_exec" isn't disabled on Your server.
     
  6. sojic

    sojic New Member

    How to check it?
     
  7. Leszek

    Leszek Member

    Create a test page in document_root with <?php phpinfo(); ?> as the content and look for "disable_functions" in "PHP Core" section after opening it in the browser. It contains the names of blocked functions.
     
  8. sojic

    sojic New Member

    This is result:

    Code:
    disable_functions	no value	no value
    
     
  9. falko

    falko Super Moderator Howtoforge Staff

    Please make sure that PHP Safe Mode is disabled.
     

Share This Page