From bf5df18170b208dee45a26887bb1649437cf9a61 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Tue, 22 Jan 2013 18:21:41 +0100 Subject: [PATCH] Added online check --- src/classes/utils/UPnP.php | 6 ++++++ src/classes/utils/Utils.php | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/classes/utils/UPnP.php b/src/classes/utils/UPnP.php index 1a67f8d9..dd3ba1d3 100644 --- a/src/classes/utils/UPnP.php +++ b/src/classes/utils/UPnP.php @@ -26,6 +26,9 @@ the Free Software Foundation, either version 3 of the License, or */ function UPnP_PortForward($port){ + if(Utils::$online === false){ + return false; + } if(Utils::getOS() != "win" or !class_exists("COM")){ return false; } @@ -44,6 +47,9 @@ function UPnP_PortForward($port){ } function UPnP_RemovePortForward($port){ + if(Utils::$online === false){ + return false; + } if(Utils::getOS() != "win" or !class_exists("COM")){ return false; } diff --git a/src/classes/utils/Utils.php b/src/classes/utils/Utils.php index 152abd2c..24e6f967 100644 --- a/src/classes/utils/Utils.php +++ b/src/classes/utils/Utils.php @@ -36,12 +36,19 @@ define("LITTLE_ENDIAN", 0x01); define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? BIG_ENDIAN:LITTLE_ENDIAN)); class Utils extends Thread{ - + public static $online = true; public function run(){ } + public static function isOnline(){ + return (checkdnsrr("google.com", "ANY") && checkdnsrr("yahoo.com", "ANY") && checkdnsrr("microsoft.com", "ANY")); + } + public static function getIP(){ + if(Utils::$online === false){ + return false; + } $ip = "";//trim(Utils::curl_get("http://automation.whatismyip.com/n09230945.asp")); if($ip != ""){ return $ip; @@ -332,6 +339,9 @@ class Utils extends Thread{ } public static function curl_get($page){ + if(Utils::$online === false){ + return false; + } $ch = curl_init($page); curl_setopt($ch, CURLOPT_HTTPHEADER, array("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0 PocketMine-MP")); curl_setopt($ch, CURLOPT_AUTOREFERER, true); @@ -346,6 +356,9 @@ class Utils extends Thread{ } public static function curl_post($page, $args, $timeout = 10){ + if(Utils::$online === false){ + return false; + } $ch = curl_init($page); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $args); @@ -516,4 +529,8 @@ class Utils extends Thread{ return strrev(str_pad($long->toBytes(true), 8, "\x00", STR_PAD_LEFT)); } +} + +if(Utils::isOnline() === false){ + Utils::$online = false; } \ No newline at end of file