Checks for first IP in proxy string and returns it

@param string $proxyString
@return null|string
328131
private static function getFirstIP($proxyString = ''): ?string
    {
        \preg_match('/^(([0-9]{1,3}\.){3}[0-9]{1,3})/', $proxyString, $matches);
        return (\is_array($matches) && isset($matches[1])) ? $matches[1] : null;
    }
621840
private String proxyClassName()
  {
    String simpleName = _proxyClass.getSimpleName();
    int p = simpleName.lastIndexOf("__");
    
    if (p > 0) {
      return simpleName.substring(0, p);
    }
    else {
      return simpleName;
    }
  }
552249
private static function getProxyConfiguration($url)
    {
        $hostname = UrlHelper::getHostFromUrl($url);

        if (Url::isLocalHost($hostname)) {
            return array(null, null, null, null);
        }

        // proxy configuration
        $proxyHost = Config::getInstance()->proxy['host'];
        $proxyPort = Config::getInstance()->proxy['port'];
        $proxyUser = Config::getInstance()->proxy['username'];
        $proxyPassword = Config::getInstance()->proxy['password'];

        return array($proxyHost, $proxyPort, $proxyUser, $proxyPassword);
    }
1008531
protected function _getIp() {
    $ip = null;
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
      $ip = $_SERVER['HTTP_CLIENT_IP'];
    } else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
      $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else if (!empty($_SERVER['REMOTE_ADDR'])) {
      $ip = $_SERVER['REMOTE_ADDR'];
    }

		if ($this->_isValidIpv4($ip)) {
			return $ip;
		}

		// sometimes the value is multiple IPs separated by commas
		// (when there are multiple proxies, for example)
		$ips = explode(',', $ip, 2);
		$ip = trim($ips[0]);
		if ($this->_isValidIpv4($ip)) {
			return $ip;
		}

    return null;
  }
363759
public static function serverIP(): string
    {
        if (!empty($_SERVER['SERVER_ADDR'])) {
            $ip = $_SERVER['SERVER_ADDR'];
        } elseif (!empty($_SERVER['SERVER_NAME'])) {
            $ip = gethostbyname($_SERVER['SERVER_NAME']);
        } else {
            // for php-cli(phpunit etc.)
            $ip = defined('PHPUNIT_RUNNING')
                ? '127.0.0.1'
                : gethostbyname(gethostname());
        }
        return filter_var($ip, FILTER_VALIDATE_IP) ?: '127.0.0.1';
    }
759045
public function getClientIp(){

        if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
            // Use the forwarded IP address, typically set when the
            // client is using a proxy server.
            return $_SERVER['HTTP_X_FORWARDED_FOR'];
        }elseif (isset($_SERVER['HTTP_CLIENT_IP'])){
            // Use the forwarded IP address, typically set when the
            // client is using a proxy server.
            return $_SERVER['HTTP_CLIENT_IP'];
        }
        elseif (isset($_SERVER['REMOTE_ADDR'])){
            // The remote IP address
            return $_SERVER['REMOTE_ADDR'];
        }

        return null;
    }
31019
public function getHostName()
    {
        $remoteAddress = $this->server()->remoteAddress();

        $host = $this->server()->serverName();
        $fwdHost = $this->server()->get($this->getTrustedHeaders()['client_host']);
        if ($fwdHost && $fwdHost != '' && in_array($remoteAddress, $this->getTrustedProxies())) {
            $host = $fwdHost;
        }

        return strtolower($host);
    }
770730
private function getIp(ServerRequestInterface $request)
    {
        $remoteIp = $this->getRemoteIp();

        if (!empty($remoteIp)) {
            // Found IP address via remote service.
            return $remoteIp;
        }

        $localIp = $this->getLocalIp($request);

        if ($this->proxyIps && !$this->isInProxiedIps($localIp)) {
            // Local IP address does not point at a known proxy, do not attempt
            // to read proxied IP address.
            return $localIp;
        }

        $proxiedIp = $this->getProxiedIp($request);

        if (!empty($proxiedIp)) {
            // Found IP address via proxy-defined headers.
            return $proxiedIp;
        }

        return $localIp;
    }
1199005
public function getParsedString($string)
    {
        $member = $this->getMember();
        $page = $this->getPage();

        /**
         * @var \SilverStripe\ORM\FieldType\DBDatetime $createdDateObj
         */
        $createdDateObj = $member->obj('Created');

        $absoluteBaseURL = $this->BaseURL();
        $variables = array(
            '$SiteName'       => SiteConfig::current_site_config()->Title,
            '$LoginLink'      => Controller::join_links(
                $absoluteBaseURL,
                singleton(Security::class)->Link('login')
            ),
            '$ConfirmLink'    => Controller::join_links(
                $this->page->AbsoluteLink('confirm'),
                $member->ID,
                "?key={$member->ValidationKey}"
            ),
            '$LostPasswordLink' => Controller::join_links(
                $absoluteBaseURL,
                singleton(Security::class)->Link('lostpassword')
            ),
            '$Member.Created' => $createdDateObj->Nice()
        );
        foreach (array('Name', 'FirstName', 'Surname', 'Email') as $field) {
            $variables["\$Member.$field"] = $member->$field;
        }
        $this->extend('updateEmailVariables', $variables);

        return str_replace(array_keys($variables), array_values($variables), $string);
    }
820090
public function getProxyUriString()
    {
        $uri = isset($this->proxyConf['proto']) ? $this->proxyConf['proto'] : "http";
        // https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html
        $supportedProtocols = array(
            'http',
            'https',
            'socks4',
            'socks4a',
            'socks5',
            'socks5h',
        );

        if (in_array($uri, $supportedProtocols) === false) {
            // WPCS: XSS OK.
            echo "Unknown proxy protocol '" . $this->proxyConf['proto'] . "', supported protocols are " . implode(", ", $supportedProtocols) . PHP_EOL;
        }

        $uri .= "://";
        $uri .= isset($this->proxyConf['address']) ? $this->proxyConf['address'] : "localhost";

        if (isset($this->proxyConf['address']) === false) {
            // WPCS: XSS OK.
            echo "warning: proxy address not set defaulting to localhost" . PHP_EOL;
        }

        $uri .= ":";
        $uri .= isset($this->proxyConf['port']) ? $this->proxyConf['port'] : "1080";

        if (isset($this->proxyConf['address']) === false) {
            // WPCS: XSS OK.
            echo "warning: proxy port not set defaulting to 1080" . PHP_EOL;
        }

        return $uri;
    }
1244050
public function getIpAddress()
    {
        $pattern = new UriPattern();
        $pattern->matchHost($this->getHost(), $match);

        if (isset($match['IPv4address'])) {
            return $match['IPv4address'];
        } elseif (isset($match['IP_literal'])) {
            return preg_replace('/^\\[(v[^.]+\\.)?([^\\]]+)\\]$/', '$2', $match['IP_literal']);
        }

        return null;
    }
961578
public function getProxy()
    {
        $aProxy['ip'] = $this->proxyIP;
        $aProxy['port'] = $this->proxyPORT;
        $aProxy['username'] = $this->proxyUSER;
        $aProxy['password'] = $this->proxyPASS;

        return $aProxy;
    }
1170075
public function getProxyAuth()
    {
        $proxy_options = $this->getOption(EnumRequestOption::PROXY_OPTIONS, []);
        return isset($proxy_options[EnumProxyOption::PROXY_AUTH]) ? $proxy_options[EnumProxyOption::PROXY_AUTH] : null;
    }
789340
public static function ip(): string
    {
        if (static::$realIp !== null) {
            return static::$realIp;
        }

        $possibilities = [
          'HTTP_CLIENT_IP',
          'HTTP_X_FORWARDED_FOR',
          'HTTP_X_FORWARDED',
          'HTTP_X_CLUSTER_CLIENT_IP',
          'HTTP_FORWARDED_FOR',
          'HTTP_FORWARDED',
          'REMOTE_ADDR'
        ];

        foreach ($possibilities as $key) {
            if (isset($_SERVER[$key])) {
                foreach (explode(',', $_SERVER[$key]) as $ip) {
                    $ip = trim($ip);

                    if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) {
                        static::$realIp = $ip;
                        return $ip;
                    }
                }
            }
        }

        if (KOLDY_CLI) {
            static::$realIp = '127.0.0.1';
        } else if (isset($_SERVER['REMOTE_ADDR'])) {
            static::$realIp = $_SERVER['REMOTE_ADDR'];
        } else {
            throw new Exception('Unable to detect IP');
        }

        return static::$realIp;
    }
1272146
static public function getAddress()
    {
        foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'HTTP_X_CLIENT_IP', 'HTTP_X_CLUSTER_CLIENT_IP', 'REMOTE_ADDR') as $header) {
            if (!isset($_SERVER[$header]) || ($spoof = $_SERVER[$header]) === null) {
                continue;
            }
            sscanf($spoof, '%[^,]', $spoof);
            if (!filter_var($spoof, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
                $spoof = null;
            } else {
                return $spoof;
            }
        }
        return '0.0.0.0';
    }
371704
public static function getIPAddress()
    {
        if (isset($_SERVER['HTTP_CLIENT_IP'])) {
            return $_SERVER['HTTP_CLIENT_IP'];
        } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            ///to check ip is pass from proxy
            return $_SERVER['HTTP_X_FORWARDED_FOR'];
        } elseif (isset($_SERVER['REMOTE_ADDR'])) {
            return $_SERVER['REMOTE_ADDR'];
        }

        return null;
    }
219797
final public static function getConnection($cnxString) {
        $factory = self::getFactory(parse_url($cnxString, PHP_URL_SCHEME));
        return $factory->getConnection($cnxString);
    }