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

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

    I have /root/start, /root/stop
    #touch /var/lock/subsys/local
    # Firewall za port forward
    iptables -I FORWARD -p tcp -s $1 -d -j ACCEPT
    I should execute from php:
    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 New Member

    For example shell_exec:

     [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 New Member

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

    sojic New Member

    How to check it?
  7. Leszek

    Leszek New 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:

    disable_functions	no value	no value
  9. falko

    falko Super Moderator ISPConfig Developer

    Please make sure that PHP Safe Mode is disabled.

Share This Page