The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

ping using php ... permission problem

Discussion in 'General Discussion' started by Radio_Head, Apr 29, 2003.

  1. Radio_Head

    Radio_Head Well-Known Member

    Joined:
    Feb 15, 2002
    Messages:
    2,051
    Likes Received:
    1
    Trophy Points:
    38
    Hello,

    when I try to ping my box using this simple php script

    <?
    $domain="yahoo.com";
    $run = shell_exec("/bin/ping -c5 -n -q -w5 $domain 2>&1");
    echo $run;
    ?>

    I receive a permission error .

    Probably because php scripts run as nobody , and nobody is not allowed to execute ping .

    Is there any way to go over it , I need to execute php ping to monitor my site with a cron job.

    Thank you
     
  2. jamesbond

    jamesbond Well-Known Member

    Joined:
    Oct 9, 2002
    Messages:
    738
    Likes Received:
    1
    Trophy Points:
    18
    Maybe you have php safemode enabled, or disabled the use of shell_exec in your php.ini?
    Oterwise it should work.
     
  3. Radio_Head

    Radio_Head Well-Known Member

    Joined:
    Feb 15, 2002
    Messages:
    2,051
    Likes Received:
    1
    Trophy Points:
    38
    on my account , safe mode is off , shell_exec is not disabled .

    It should not work because php run nobody , and to execute
    ping it's required and user or probably only root .
     
    #3 Radio_Head, Apr 30, 2003
    Last edited: Apr 30, 2003
  4. jamesbond

    jamesbond Well-Known Member

    Joined:
    Oct 9, 2002
    Messages:
    738
    Likes Received:
    1
    Trophy Points:
    18
    That is incorrect.
    You can't execute shell commands because safemode is on.

    If you really need to keep safemode on you could add ping to the safe-mode-exec-dir :

    http:/www.php.net/manual/en/features.safe-mode.php#ini.safe-mode-exec-dir

    Haven't tried this myself though.
     
  5. Radio_Head

    Radio_Head Well-Known Member

    Joined:
    Feb 15, 2002
    Messages:
    2,051
    Likes Received:
    1
    Trophy Points:
    38
    ops sorry , I wanted say safe mode on my account is OFF , sorry.
    Perhpas the only solution is to chgrp /bin/ping nobody , however I am not really safe to do that .
     
    #5 Radio_Head, Apr 30, 2003
    Last edited: Apr 30, 2003
  6. jamesbond

    jamesbond Well-Known Member

    Joined:
    Oct 9, 2002
    Messages:
    738
    Likes Received:
    1
    Trophy Points:
    18
    That's strange, if safe mode is off then you should be able to execute shell commands like ping, unless there are some other restrictions in place.
     
  7. Radio_Head

    Radio_Head Well-Known Member

    Joined:
    Feb 15, 2002
    Messages:
    2,051
    Likes Received:
    1
    Trophy Points:
    38
    Try it ;)
     
  8. jamesbond

    jamesbond Well-Known Member

    Joined:
    Oct 9, 2002
    Messages:
    738
    Likes Received:
    1
    Trophy Points:
    18
    Well on my server only root is allowed to use ping, maybe that's the way you have set it up as well?

    I tried the script anyway, I get :

    ping: icmp open socket: Operation not permitted
     
  9. Radio_Head

    Radio_Head Well-Known Member

    Joined:
    Feb 15, 2002
    Messages:
    2,051
    Likes Received:
    1
    Trophy Points:
    38
    Same for me . Also if you chown chgrp your file root:root you will not be allowed because php scripts run nobody .

    The only solution to run the script above seems to be perl , or phpsuxec .
     
  10. jamesbond

    jamesbond Well-Known Member

    Joined:
    Oct 9, 2002
    Messages:
    738
    Likes Received:
    1
    Trophy Points:
    18
    Well what you could try is do a chmod 4555 or 2555 on ping.
    I believe 4 is set-UID and 2 is set-GID.

    But then everyone on your server can use ping as user nobody.
     
  11. Radio_Head

    Radio_Head Well-Known Member

    Joined:
    Feb 15, 2002
    Messages:
    2,051
    Likes Received:
    1
    Trophy Points:
    38
    yep , and I don't know if it could cause a problem , probably yes if they use ping without the w and c options.

    Bye
     
Loading...

Share This Page