Exec ping

Questions about HTTP Access/Mods may go here
Forum rules
Please note the disclaimer before modifying your Synology Product.
User avatar
OgeGOon
Apprentice
Apprentice
Posts: 82
Joined: Sat Mar 14, 2009 11:41 pm

Exec ping

Postby OgeGOon » Wed Apr 22, 2009 11:46 pm

Hi,

I have edited my php.ini file in order to be able to run something in php with the 'exec' or 'system' command from any path (and not only under /usr/syno/bin)

Now, I am able to execute commands like 'ps', 'ls', 'date', etc...

Ex.: this is working fine
<?
system('date');
system('ls');
system('ps');
?>

However, I cannot succeed in executing a 'ping'. This does not return anything:
<?
system('ping -c 1 -w 1 127.0.0.1');
?>

Does someone know what's possibly wrong with this ?

O.
haef67
Sharp
Sharp
Posts: 181
Joined: Sat Jan 19, 2008 12:58 pm
Location: France
Contact:

Re: Exec ping

Postby haef67 » Thu Apr 23, 2009 7:11 am

This is a user "rights" problem, you need to be "root" for executing the "ping" command

Patrick
DS-107+ (128Mo) | Firmware Version: 2.2-0959 | HDD: Samsung 500GB HD501LJ
DS-110j (128Mo) | Firmware Version: 2.3-1157 | HDD: Samsung 1TB HD103SJ
USBStation 2 (128Mo) | Alternative Firmware Version: 3.0-1417 (with IPKG)| 16Go Compact Flash card & 2.5" HDD 350GB
User avatar
OgeGOon
Apprentice
Apprentice
Posts: 82
Joined: Sat Mar 14, 2009 11:41 pm

Re: Exec ping

Postby OgeGOon » Sat Apr 25, 2009 10:17 am

Thanks a lot !

I did a quick test, running apache under the root account and it works fine.

I will now try to find how to execute a command with the root account without running apache with this account (which is really unsecure)

O.
bzhou
Knowledgeable
Knowledgeable
Posts: 344
Joined: Sat Jan 12, 2008 1:57 am

Re: Exec ping

Postby bzhou » Sun Apr 26, 2009 1:58 am

It kind of depends on what version of ping you are trying to run. If you have optware ipkg setup, you can install inetutils, that /opt/bin/ping binary can be run by any user.
User avatar
OgeGOon
Apprentice
Apprentice
Posts: 82
Joined: Sat Mar 14, 2009 11:41 pm

Re: Exec ping

Postby OgeGOon » Mon Apr 27, 2009 7:09 pm

Ho! Thx a lot for this advice Brian !

I didn't install ipkg (yet) as I thought the Disk Station Manager 2.0 (which is installed on my Synology DS 209+) would manage the same "package" as those installable via ipkg. But it appears that it's not the actual purpose of the "Package Management" feature of this Disk Station management, is it ? (I get an "Invalid file format" error while uploading the inetutils_1.5-5_arm.ipk)

After reading here and there about installing ipkg, I found this thread viewtopic.php?f=40&t=14156
I did the manual install but something possibly went wrong somewhere as executing/opt/bin/ipkg update, I get the error message: /opt/bin/ipkg: /opt/bin/ipkg: 1: Syntax error: word unexpected (expecting ")")

[Edit] After some further researches, I found a link to this blog: http://www.volkomenjuist.nl/blog/2009/0 ... /#more-197
Setup of ipkg is now successful !!
install of inetutils successful too

And finally, usage of /opt/bin/ping works fine with apache running as "nobody".

Thanks a lot for pointing me this solution 8)

O.
nvrsk
Beginner
Beginner
Posts: 21
Joined: Sat Mar 05, 2011 6:13 pm

Re: Exec ping

Postby nvrsk » Thu Mar 03, 2016 3:27 pm

a partial workaround solution for pinging a host fromout php on website without exec, system, and any other type of "dancing":

Code: Select all

<?php
function ping($host, $port, $timeout) {
   $tB = microtime(true);
   $fP = fSockOpen($host, $port, $errno, $errstr, $timeout);
   if (!$fP) { return "down"; } // if host unavailable
   $tA = microtime(true);
   return round((($tA - $tB) * 1000), 0)." ms"; // if host is up - show ping delay
   }
echo ping("tcp://forum.synology.com", 443, 5);
?>
please note, that this is NOT a real ICMP ping, since fSockOpen uses TCP/UDP with port numbers (which is layer4 protocol).
so, if your task is to check the availability of a certain service on remote host - this code may be handy.
but if you need real layer3 protocol ping - this won't do...

Return to “HTTP/Apache Mods”

Who is online

Users browsing this forum: No registered users and 1 guest