瀏覽代碼

added serverIP function
added isLocalOrServer function
changed userIP function to return 127.0.0.1 if no ip found

CauseFX 4 年之前
父節點
當前提交
f500115355
共有 1 個文件被更改,包括 23 次插入1 次删除
  1. 23 1
      api/functions/normal-functions.php

+ 23 - 1
api/functions/normal-functions.php

@@ -253,7 +253,7 @@ trait NormalFunctions
 		} elseif (isset($_SERVER['REMOTE_ADDR'])) {
 			$ipaddress = $_SERVER['REMOTE_ADDR'];
 		} else {
-			$ipaddress = 'UNKNOWN';
+			$ipaddress = '127.0.0.1';
 		}
 		if (strpos($ipaddress, ',') !== false) {
 			list($first, $last) = explode(",", $ipaddress);
@@ -264,6 +264,14 @@ trait NormalFunctions
 		}
 	}
 	
+	public function serverIP()
+	{
+		if (array_key_exists('SERVER_ADDR', $_SERVER)) {
+			return $_SERVER['SERVER_ADDR'];
+		}
+		return '127.0.0.1';
+	}
+	
 	public function parseDomain($value, $force = false)
 	{
 		$badDomains = array('ddns.net', 'ddnsking.com', '3utilities.com', 'bounceme.net', 'freedynamicdns.net', 'freedynamicdns.org', 'gotdns.ch', 'hopto.org', 'myddns.me', 'myds.me', 'myftp.biz', 'myftp.org', 'myvnc.com', 'noip.com', 'onthewifi.com', 'redirectme.net', 'serveblog.net', 'servecounterstrike.com', 'serveftp.com', 'servegame.com', 'servehalflife.com', 'servehttp.com', 'serveirc.com', 'serveminecraft.net', 'servemp3.com', 'servepics.com', 'servequake.com', 'sytes.net', 'viewdns.net', 'webhop.me', 'zapto.org');
@@ -577,6 +585,20 @@ trait NormalFunctions
 		return $isLocal;
 	}
 	
+	public function isLocalOrServer()
+	{
+		$isLocalOrServer = false;
+		$isLocal = $this->isLocal();
+		if (!$isLocal) {
+			if ($this->userIP() == $this->serverIP()) {
+				$isLocalOrServer = true;
+			}
+		} else {
+			$isLocalOrServer = true;
+		}
+		return $isLocalOrServer;
+	}
+	
 	public function human_filesize($bytes, $dec = 2)
 	{
 		$bytes = number_format($bytes, 0, '.', '');