Check if working in SSL mode

@param integer $port      HTTPS port number
@param boolean $use_https Enables 'use_https' option checking

@return boolean
506887
public static function https_check($port=null, $use_https=true)
    {
        if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') {
            return true;
        }
        if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])
            && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https'
            && in_array($_SERVER['REMOTE_ADDR'], rcube::get_instance()->config->get('proxy_whitelist', array()))
        ) {
            return true;
        }
        if ($port && $_SERVER['SERVER_PORT'] == $port) {
            return true;
        }
        if ($use_https && rcube::get_instance()->config->get('use_https')) {
            return true;
        }

        return false;
    }
717335
public static function isSecure() {
        $s = &$_SERVER;
        $ssl = (!empty($s['HTTPS']) && $s['HTTPS'] == 'on') ? true : false;
        return $ssl;
    }
1345809
private static function isStandardPort($port, $scheme = null, $host = null)
    {
        if ($host === null || $scheme === null) {
            return false;
        }

        return array_key_exists($scheme, static::$schemes) && $port === static::$schemes[$scheme];
    }
1140941
public function getServerName($port = false, $protocol = false)
	{
		$servername = '';
		if (isset($_SERVER['SERVER_NAME']) && !empty($_SERVER['SERVER_NAME']))
			$servername = $_SERVER['SERVER_NAME'];
		else if(isset($_SERVER['HTTP_HOST']) && !empty($_SERVER['HTTP_HOST']))
			$servername = $_SERVER['HTTP_HOST'];
		else
			$servername = $_SERVER['SERVER_ADDR'];

		if ($port && isset($_SERVER['SERVER_PORT']))
			$servername .= ':' . $_SERVER['SERVER_PORT'];

		if ($protocol)
			$servername = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://") . $servername;

		return $servername;
	}
479732
static boolean usesStandardPort(URI uri) {
        int portNumber = uri.getPort();
        if (portNumber == -1) {
            return true;
        }
        String schema = uri.getScheme();
        int standardPort = schema.equals("https") ? 443 : 80;
        return portNumber == standardPort;
    }
409400
public function isSecure() : bool
    {
        if ($this->isUsingTrustedProxy() && $this->server->has(self::$trustedHeaderNames[RequestHeaders::CLIENT_PROTO])) {
            $protoString = $this->server->get(self::$trustedHeaderNames[RequestHeaders::CLIENT_PROTO]);
            $protoArray = explode(',', $protoString);

            return count($protoArray) > 0 && in_array(strtolower($protoArray[0]), ['https', 'ssl', 'on']);
        }

        return $this->server->has('HTTPS') && $this->server->get('HTTPS') !== 'off';
    }
973041
public function checkPurpose(int $purpose, array $cainfo = [], string $untrusted = NULL): bool {
        if($untrusted === NULL) {
            $status = openssl_x509_checkpurpose($this->getHandle(), $purpose, $cainfo);
        }
        else {
            $status = openssl_x509_checkpurpose($this->getHandle(), $purpose, $cainfo, $untrusted);
        }
        if(!is_bool($status)) {
            throw new RuntimeException('Failed to check purpose');
        }
        return $status;
    }
500291
public function validatePort($port = null)
    {
        if ($port === null) {
            $port = $this->_port;
        }

        // If the port is empty, then it is considered valid
        if (strlen($port) === 0) {
            return true;
        }

        // Check the port against the allowed values
        return ctype_digit((string) $port) and 1 <= $port and $port <= 65535;
    }
391470
public static function isPortInUse($port, $hostname = null)
    {
        $fp = @fsockopen($hostname !== null ? $hostname : '127.0.0.1', $port, $errno, $errstr, 10);
        if ($fp !== false) {
            fclose($fp);

            return true;
        }

        return false;
    }
910721
public function isDefaultPort(int $port = null)
	{
		$port = $port ?: $this->port;
		return $port === null || $port === (self::$allowedSchemes[$this->_scheme] ?? null);
	}
305720
public static function is_https($trust_proxy_headers = false)
    {
        // Check standard HTTPS header
        if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
           return isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off';
        }

        // Check proxy headers if allowed
        return $trust_proxy_headers && isset($_SERVER['X-FORWARDED-PROTO']) && $_SERVER['X-FORWARDED-PROTO'] == 'https';

        // Default to not SSL
        return false;
    }
616544
public static function isHttps($trust_proxy_headers = false){
        // Verifique o cabeçalho HTTPS padrão
        if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
           return isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off';
        }
        // Verifique os cabeçalhos de proxy, se permitido
        return $trust_proxy_headers && isset($_SERVER['X-FORWARDED-PROTO']) && $_SERVER['X-FORWARDED-PROTO'] == 'https';
        // Padrão para não SSL
        return false;
    }
369677
def port_is_used(port, host='127.0.0.1'):
    
    unused = _can_bind(port, host) and _refuses_connection(port, host)
    return not unused
1062252
def verify_ports(port_list):
    
    result = True  # empty list is ok
    for item in port_list:
        try:
            (port, protocol) = item.split(PORT_SEPARATOR)
            port_num = int(port)
        except ValueError:
            result = False
            break
        result &= protocol in ALLOWED_PROTOCOLS
        result &= port == str(port_num)
    return result
984848
public static function validatePort($port)
    {
        if (!is_numeric($port) || $port <= 1023 || $port > 65535) {
            return false;
        }

        return !in_array($port, self::$unsafePorts);
    }
708804
private static function check() {

        foreach(['openssl'] as $extension) {

            if(false === extension_loaded($extension)) {
                return trigger_error(sprintf('Extension "%s" should be loaded to use %s', $extension, __CLASS__), E_USER_ERROR);
            }
        }
    }
650949
protected function checkAndSetServerOptions()
    {

        // Specific query port defined
        if (array_key_exists(self::SERVER_OPTIONS_QUERY_PORT, $this->options)) {
            $this->port_query = (int)$this->options[self::SERVER_OPTIONS_QUERY_PORT];
        } else {
            // Do math based on the protocol class
            $this->port_query = $this->protocol->findQueryPort($this->port_client);
        }
    }