当前位置: 首页>>代码示例>>PHP>>正文


PHP getservbyname函数代码示例

本文整理汇总了PHP中getservbyname函数的典型用法代码示例。如果您正苦于以下问题:PHP getservbyname函数的具体用法?PHP getservbyname怎么用?PHP getservbyname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getservbyname函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 function __construct($params)
 {
     if (isset($params['mailname'])) {
         $this->mailname = $params['mailname'];
     } else {
         if (function_exists('posix_uname')) {
             $uname = posix_uname();
             $this->mailname = $uname['nodename'];
         }
     }
     if (isset($params['port'])) {
         $this->_port = $params['port'];
     } else {
         $this->_port = getservbyname('smtp', 'tcp');
     }
     if (isset($params['timeout'])) {
         $this->timeout = $params['timeout'];
     }
     if (isset($params['verp'])) {
         $this->verp = $params['verp'];
     }
     if (isset($params['test'])) {
         $this->test = $params['test'];
     }
     if (isset($params['peardebug'])) {
         $this->test = $params['peardebug'];
     }
     if (isset($params['netdns'])) {
         $this->withNetDns = $params['netdns'];
     }
 }
开发者ID:MMU-TWT-Class-Oct-2015,项目名称:G10B_Sales_of_Point_System_for_Video_and_Audio_shop,代码行数:31,代码来源:smtpmx.php

示例2: normalize_url

function normalize_url($url)
{
    $purl = @parse_url($url);
    if (!$purl) {
        return false;
    }
    $scheme = $host = $port = $user = $pass = $path = $query = $fragment = false;
    extract($purl);
    if ($scheme) {
        $scheme = strtolower($scheme);
    }
    if ($host) {
        $host = strtolower($host);
    }
    if ($port and $port == getservbyname($scheme, 'tcp')) {
        $port = false;
    }
    foreach (array('user', 'pass', 'host', 'path') as $p) {
        if (${$p}) {
            ${$p} = preg_replace('/%[0-9a-f]{2}/ie', 'strtoupper("\\0")', ${$p});
        }
    }
    if ($path) {
        $path = _restore_allowed_chars(_remove_dot_segments($path));
    }
    if ($host && !$path) {
        $path = '/';
    }
    $newurl = $scheme . '://';
    if ($host) {
        if ($user) {
            $newurl .= $user;
            if ($pass) {
                $newurl .= ':' . $pass;
            }
            $newurl .= '@';
        }
        $newurl .= $host;
        if ($port) {
            $newurl .= ':' . $port;
        }
    }
    $newurl .= $path;
    if ($query) {
        $q = array();
        foreach (explode('&', $query) as $s) {
            if ($s and preg_match('/[^=]+=[^=]+/', $s)) {
                $q[] = $s;
            }
        }
        if ($q) {
            sort($q);
            $newurl .= '?' . implode('&', $q);
        }
    }
    if ($fragment) {
        $newurl .= '#' . $fragment;
    }
    return $newurl;
}
开发者ID:RazorMarx,项目名称:izend,代码行数:60,代码来源:validateurl.php

示例3: proxify

 public function proxify(\Erebot\URIInterface $proxyURI, \Erebot\URIInterface $nextURI)
 {
     $credentials = $proxyURI->getUserInfo();
     $host = $nextURI->getHost();
     $port = $nextURI->getPort();
     $scheme = $nextURI->getScheme();
     if ($port === null) {
         $port = getservbyname($scheme, 'tcp');
     }
     if (!is_int($port) || $port <= 0 || $port > 65535) {
         throw new \Erebot\InvalidValueException('Invalid port');
     }
     $request = "";
     $request .= sprintf("CONNECT %s:%d HTTP/1.0\r\n", $host, $port);
     $request .= sprintf("Host: %s:%d\r\n", $host, $port);
     $request .= "User-Agent: Erebot/dev-master\r\n";
     if ($credentials !== null) {
         $request .= sprintf("Proxy-Authorization: basic %s\r\n", base64_encode($credentials));
     }
     $request .= "\r\n";
     for ($written = 0, $len = strlen($request); $written < $len; $written += $fwrite) {
         $fwrite = fwrite($this->_socket, substr($request, $written));
         if ($fwrite === false) {
             throw new \Erebot\Exception('Connection closed by proxy');
         }
     }
     $line = stream_get_line($this->_socket, 4096, "\r\n");
     if ($line === false) {
         throw new \Erebot\InvalidValueException('Invalid response from proxy');
     }
     $this->_logger->debug('%(line)s', array('line' => addcslashes($line, "..")));
     $contents = array_filter(explode(" ", $line));
     switch ((int) $contents[1]) {
         case 200:
             break;
         case 407:
             throw new \Erebot\Exception('Proxy authentication required');
         default:
             throw new \Erebot\Exception('Connection rejected by proxy');
     }
     // Avoid an endless loop by limiting the number of headers.
     // No HTTP server is likely to send more than 2^10 headers anyway.
     $max = 1 << 10;
     for ($i = 0; $i < $max; $i++) {
         $line = stream_get_line($this->_socket, 4096, "\r\n");
         if ($line === false) {
             throw new \Erebot\InvalidValueException('Invalid response from proxy');
         }
         if ($line == "") {
             break;
         }
         $this->_logger->debug('%(line)s', array('line' => addcslashes($line, "..")));
     }
     if ($i === $max) {
         throw new \Erebot\InvalidValueException('Endless loop detected in proxy response');
     }
 }
开发者ID:erebot,项目名称:erebot,代码行数:57,代码来源:HTTP.php

示例4: RADIUS_AUTHENTICATION

function RADIUS_AUTHENTICATION($username, $password)
{
    global $debug;
    global $SERVER_ADDR;
    $radiushost = "";
    $sharedsecret = "";
    $suffix = "";
    init_radiusconfig(&$radiushost, &$radiusport, &$sharedsecret, &$suffix);
    // check your /etc/services. Some radius servers
    // listen on port 1812, some on 1645.
    if ($radiusport == 0) {
        $radiusport = getservbyname("radius", "udp");
    }
    $nasIP = explode(".", $SERVER_ADDR);
    $ip = gethostbyname($radiushost);
    // 17 is UDP, formerly known as PROTO_UDP
    $sock = socket_create(AF_INET, SOCK_DGRAM, 17);
    $retval = socket_connect($sock, $ip, $radiusport);
    if (!preg_match("/@/", $username)) {
        $username .= $suffix;
    }
    if ($debug) {
        echo "<br>radius-port: {$radiusport}<br>radius-host: {$radiushost}<br>username: {$username}<br>suffix: {$suffix}<hr>\n";
    }
    $RA = pack("CCCCCCCCCCCCCCCC", 1 + rand() % 255, 1 + rand() % 255, 1 + rand() % 255, 1 + rand() % 255, 1 + rand() % 255, 1 + rand() % 255, 1 + rand() % 255, 1 + rand() % 255, 1 + rand() % 255, 1 + rand() % 255, 1 + rand() % 255, 1 + rand() % 255, 1 + rand() % 255, 1 + rand() % 255, 1 + rand() % 255, 1 + rand() % 255);
    $encryptedpassword = Encrypt($password, $sharedsecret, $RA);
    $length = 4 + 16 + 6 + 2 + strlen($username) + 2 + strlen($encryptedpassword) + 6 + 6;
    // nasPort
    $thisidentifier = rand() % 256;
    //          v   v v     v   v   v     v     v
    $data = pack("CCCCa*CCCCCCCCa*CCa*CCCCCCCCCCCC", 1, $thisidentifier, $length / 256, $length % 256, $RA, 6, 6, 0, 0, 0, 1, 1, 2 + strlen($username), $username, 2, 2 + strlen($encryptedpassword), $encryptedpassword, 4, 6, $nasIP[0], $nasIP[1], $nasIP[2], $nasIP[3], 5, 3, 0, 0, 0, 0);
    socket_write($sock, $data, $length);
    if ($debug) {
        echo "<br>writing {$length} bytes<hr>\n";
    }
    //
    // Wait at most five seconds for the answer. Thanks to
    // Michael Long <hide@address.com> for his remark about this.
    //
    $set = socket_fd_alloc();
    socket_fd_zero($set);
    socket_fd_set($set, $sock);
    socket_select($set, null, null, 5);
    if (!socket_fd_isset($set, $sock)) {
        echo "No answer from radius server, aborting\n";
        exit(0);
    }
    socket_fd_free($set);
    $readdata = socket_read($sock, 1);
    socket_close($sock);
    return ord($readdata);
    // 2 -> Access-Accept
    // 3 -> Access-Reject
    // See RFC2138 for this.
}
开发者ID:NamingException,项目名称:PHP-Certificate-Authority-Server,代码行数:55,代码来源:radius_authentication.inc.php

示例5: getWithUriFallback

 /**
  * Get Host, falls back to Effective Request URI if not found
  *
  * @return string
  */
 public function getWithUriFallback()
 {
     if (($get = $this->export()) !== null) {
         // Host defined by the Host directive
         return $get;
     } elseif ($this->base !== $this->effective && parse_url($this->base, PHP_URL_HOST) === ($host = parse_url($this->effective, PHP_URL_HOST))) {
         // Host is the same, but Scheme or Port is different
         return getservbyname($scheme = parse_url($this->effective, PHP_URL_SCHEME), 'tcp') === parse_url($this->effective, PHP_URL_PORT) ? $scheme . '://' . $host : $this->effective;
     }
     // Return Host name only
     return parse_url($this->effective, PHP_URL_HOST);
 }
开发者ID:vipnytt,项目名称:robotstxtparser,代码行数:17,代码来源:HostClient.php

示例6: isListed

 /**
  * Is listed?
  *
  * @param string $uri
  * @return bool
  */
 public function isListed($uri)
 {
     $uriParser = new UriParser($uri);
     $uri = $uriParser->encode();
     $parts = ['scheme' => parse_url($uri, PHP_URL_SCHEME), 'host' => parse_url($uri, PHP_URL_HOST)];
     $parts['port'] = is_int($port = parse_url($uri, PHP_URL_PORT)) ? $port : getservbyname($parts['scheme'], 'tcp');
     $cases = [$parts['host'], $parts['host'] . ':' . $parts['port'], $parts['scheme'] . '://' . $parts['host'], $parts['scheme'] . '://' . $parts['host'] . ':' . $parts['port']];
     foreach ($this->host as $host) {
         if (in_array($host, $cases)) {
             return true;
         }
     }
     return false;
 }
开发者ID:vipnytt,项目名称:robotstxtparser,代码行数:20,代码来源:InlineHostClient.php

示例7: isServerSecure

 public function isServerSecure()
 {
     // Some of these settings are Apache 2.4 specific.
     // Checks for https on the server and aginst the load
     // balancer.
     $httpsPort = intval(getservbyname('https', 'tcp'));
     $requestSchemeHttps = isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] === "https" : null;
     $serverHttps = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off';
     $serverPortSecure = isset($_SERVER['SERVER_PORT']) ? $httpsPort === $_SERVER['SERVER_PORT'] : null;
     $forwardHttps = isset($_SERVER['HTTP_X_FORWARDED_PORT']) ? $_SERVER['HTTP_X_FORWARDED_PORT'] === 'https' : null;
     $forwardProtocolHttps = isset($_SERVER['HTTP_X_FORWARDED_PROTO']) ? $_SERVER['HTTP_X_FORWARDED_PROTO'] === "https" : null;
     if ($requestSchemeHttps || $serverHttps || $serverPortSecure || $forwardHttps || $forwardProtocolHttps) {
         return true;
     }
     return false;
 }
开发者ID:anhnt4288,项目名称:owaspsecuritywithphp,代码行数:16,代码来源:AbsolutePaths.php

示例8: checkSite

 /**
  * Tries to connect to the appropriate port
  *
  * @return boolean Returns true or false
  * @since 2014-11-17
  * @author Matthew Daly matthewbdaly@gmail.com
  */
 public function checkSite($url)
 {
     // Break up the URL data
     $url_data = parse_url($url);
     $scheme = $url_data['scheme'];
     $host = $url_data['host'];
     // Get port for URL
     $port = getservbyname($scheme, 'tcp');
     // Try to connect to it
     $fp = @fsockopen($host, $port, $errno, $errstr, 10);
     $status = $fp ? true : false;
     if ($fp) {
         fclose($fp);
     }
     unset($fp);
     // Return response
     return $status;
 }
开发者ID:priestd09,项目名称:SiteUpChecker,代码行数:25,代码来源:SiteUpChecker.php

示例9: getURL

 /**
  * @return string#
  */
 public function getURL() : string
 {
     $url = '';
     $url .= $this->parts['scheme'] ? $this->parts['scheme'] . ':' : '';
     $url .= '//';
     $url .= $this->parts['user'] ?: '';
     $url .= $this->parts['pass'] ? ':' . $this->parts['pass'] : '';
     $url .= $this->parts['user'] || $this->parts['pass'] ? '@' : '';
     $url .= $this->parts['host'];
     if ($this->parts['port']) {
         $port = @getservbyname($this->parts['scheme'], 'tcp');
         $port = $port !== false ? $port : @getservbyname($this->parts['scheme'], 'udp');
         $url .= $port != $this->parts['port'] ? ':' . $this->parts['port'] : '';
     }
     $url .= '/' . ltrim($this->parts['path'], '/');
     $url .= $this->parts['query'] ? '?' . $this->parts['query'] : '';
     $url .= $this->parts['fragment'] ? '#' . $this->parts['fragment'] : '';
     return $url;
 }
开发者ID:sgc-fireball,项目名称:libphp,代码行数:22,代码来源:URL.php

示例10: GetManagesieve

 private function GetManagesieve()
 {
     $this->app = rcmail::get_instance();
     // Add include path for internal classes
     $include_path = $this->app->plugins->dir . 'managesieve/lib' . PATH_SEPARATOR;
     $include_path .= ini_get('include_path');
     set_include_path($include_path);
     if (empty($this->params['port'])) {
         $this->params['port'] = getservbyname('sieve', 'tcp');
         if (empty($this->params['port'])) {
             $this->params['port'] = "4190";
         }
     }
     // try to connect to managesieve server
     $this->managesieve = new rcube_sieve(method_exists($this->app, get_user_name) ? $this->app->get_user_name() : $_SESSION['username'], method_exists($this->app, get_user_password) ? $this->app->get_user_password() : $this->app->decrypt($_SESSION['password']), $this->params['host'], $this->params['port'], null, $this->params['usetls']);
     if ($error = $this->managesieve->error()) {
         $this->ShowError($error);
     }
     return $error;
 }
开发者ID:zsmj513,项目名称:Roundcube-Plugins,代码行数:20,代码来源:managesieve.php

示例11: unset

            $pconfig['address'] = $a_aliases[$id]['aliasurl'];
        }
    }
}
if ($_POST) {
    unset($input_errors);
    $vertical_bar_err_text = gettext("Vertical bars (|) at start or end, or double in the middle of descriptions not allowed. Descriptions have been cleaned. Check and save again.");
    /* input validation */
    $reqdfields = explode(" ", "name");
    $reqdfieldsn = array(gettext("Name"));
    do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
    $x = is_validaliasname($_POST['name']);
    if (!isset($x)) {
        $input_errors[] = gettext("Reserved word used for alias name.");
    } else {
        if ($_POST['type'] == "port" && (getservbyname($_POST['name'], "tcp") || getservbyname($_POST['name'], "udp"))) {
            $input_errors[] = gettext("Reserved word used for alias name.");
        } else {
            if (is_validaliasname($_POST['name']) == false) {
                $input_errors[] = gettext("The alias name must be less than 32 characters long, may not consist of only numbers, and may only contain the following characters") . " a-z, A-Z, 0-9, _.";
            }
        }
    }
    /* check for name conflicts */
    foreach ($a_aliases as $key => $alias) {
        if ($alias['name'] == $_POST['name'] && (empty($a_aliases[$id]) || $key != $id)) {
            $input_errors[] = gettext("An alias with this name already exists.");
            break;
        }
    }
    /* Check for reserved keyword names */
开发者ID:jefersonJim,项目名称:pfsense,代码行数:31,代码来源:firewall_aliases_edit.php

示例12: _iframeGrabProxy

 /**
  * Handles a proxied grab request
  *
  * @return bool true to end the response, false to continue trying to handle it
  * @access private
  */
 function _iframeGrabProxy()
 {
     if (!isset($_REQUEST['Iframe_XHR_id'])) {
         trigger_error('Invalid iframe ID');
         return false;
     }
     $this->_iframe = $_REQUEST['Iframe_XHR_id'];
     $this->_payload = isset($_REQUEST['Iframe_XHR_data']) ? $_REQUEST['Iframe_XHR_data'] : '';
     $url = urldecode($_GET['px']);
     $url_parts = parse_url($url);
     $urlregex = '#^https?://#i';
     if (!preg_match($urlregex, $url) || $url_parts['host'] != $_SERVER['HTTP_HOST']) {
         trigger_error('Invalid URL for grab proxy');
         return true;
     }
     $method = isset($_REQUEST['Iframe_XHR_HTTP_method']) ? strtoupper($_REQUEST['Iframe_XHR_HTTP_method']) : 'GET';
     // validate method
     if ($method != 'GET' && $method != 'POST') {
         trigger_error('Invalid grab URL');
         return true;
     }
     // validate headers
     $headers = '';
     if (isset($_REQUEST['Iframe_XHR_headers'])) {
         foreach ($_REQUEST['Iframe_XHR_headers'] as $header) {
             if (strpos($header, "\r") !== false || strpos($header, "\n") !== false) {
                 trigger_error('Invalid grab header');
                 return true;
             }
             $headers .= $header . "\r\n";
         }
     }
     // tries to make request with file_get_contents()
     if (ini_get('allow_url_fopen') && version_compare(phpversion(), '5.0.0' . '>=')) {
         $opts = array($url_parts['scheme'] => array('method' => $method, 'headers' => $headers, 'content' => $this->_payload));
         $ret = @file_get_contents($url, false, stream_context_create($opts));
         if (!empty($ret)) {
             $this->_sendResponse($ret);
             return true;
         }
     }
     // tries to make request using the curl extension
     if (function_exists('curl_setopt')) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_HEADER, $headers);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         $ret = curl_exec($ch);
         if ($ret !== false) {
             curl_close($ch);
             $this->_sendResponse($ret);
             return true;
         }
     }
     if (isset($url_parts['port'])) {
         $port = $url_parts['port'];
     } else {
         $port = getservbyname(strtolower($url_parts['scheme']), 'tcp');
         if ($port === false) {
             trigger_error('Grab proxy: Unknown port or service, defaulting to 80', E_USER_WARNING);
             $port = 80;
         }
     }
     if (!isset($url_parts['path'])) {
         $url_parts['path'] = '/';
     }
     if (!empty($url_parts['query'])) {
         $url_parts['path'] .= '?' . $url_parts['query'];
     }
     $request = "{$method} {$url_parts['path']} HTTP/1.0\r\n" . "Host: {$url['host']}\r\n" . "Connection: close\r\n" . "{$headers}\r\n";
     // tries to make request using the socket functions
     $fp = fsockopen($_SERVER['HTTP_HOST'], $port, $errno, $errstr, 4);
     if ($fp) {
         fputs($fp, $request);
         $ret = '';
         $done_headers = false;
         while (!feof($fp)) {
             $ret .= fgets($fp, 2048);
             if ($done_headers || ($contentpos = strpos($ret, "\r\n\r\n")) === false) {
                 continue;
             }
             $done_headers = true;
             $ret = substr($ret, $contentpos + 4);
         }
         fclose($fp);
         $this->_sendResponse($ret);
         return true;
     }
     // tries to make the request using the socket extension
     $host = gethostbyname($url['host']);
     if (($socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0 || ($connected = socket_connect($socket, $host, $port)) < 0 || ($written = socket_write($socket, $request)) < strlen($request)) {
         trigger_error('Grab proxy failed: ' . socket_strerror($socket));
         return true;
     }
//.........这里部分代码省略.........
开发者ID:veritech,项目名称:pare-project,代码行数:101,代码来源:AJAX.php

示例13: __construct

 /**
  * @param array $params  Additional options:
  *   - debug: (boolean) Activate SMTP debug mode?
  *            DEFAULT: false
  *   - mailname: (string) The name of the local mail system (a valid
  *               hostname which matches the reverse lookup)
  *               DEFAULT: Auto-determined
  *   - netdns: (boolean) Use PEAR:Net_DNS2 (true) or the PHP builtin
  *             getmxrr().
  *             DEFAULT: true
  *   - port: (integer) Port.
  *           DEFAULT: Auto-determined
  *   - test: (boolean) Activate test mode?
  *           DEFAULT: false
  *   - timeout: (integer) The SMTP connection timeout (in seconds).
  *              DEFAULT: 10
  *   - verp: (boolean) Whether to use VERP.
  *           If not a boolean, the string value will be used as the VERP
  *           separators.
  *           DEFAULT: false
  *   - vrfy: (boolean) Whether to use VRFY.
  *           DEFAULT: false
  */
 public function __construct(array $params = array())
 {
     /* Try to find a valid mailname. */
     if (!isset($params['mailname']) && function_exists('posix_uname')) {
         $uname = posix_uname();
         $params['mailname'] = $uname['nodename'];
     }
     if (!isset($params['port'])) {
         $params['port'] = getservbyname('smtp', 'tcp');
     }
     $this->_params = array_merge(array('debug' => false, 'mailname' => 'localhost', 'netdns' => true, 'port' => 25, 'test' => false, 'timeout' => 10, 'verp' => false, 'vrfy' => false), $params);
     /* SMTP requires CRLF line endings. */
     $this->sep = "\r\n";
 }
开发者ID:evltuma,项目名称:moodle,代码行数:37,代码来源:Smtpmx.php

示例14: normalize

 /** 
  * Returns a normalized Net_URL2 instance.
  *
  * @return  Net_URL2
  */
 public function normalize()
 {
     // See RFC 3886, section 6
     // Schemes are case-insensitive
     if ($this->_scheme) {
         $this->_scheme = strtolower($this->_scheme);
     }
     // Hostnames are case-insensitive
     if ($this->_host) {
         $this->_host = strtolower($this->_host);
     }
     // Remove default port number for known schemes (RFC 3986, section 6.2.3)
     if ($this->_port && $this->_scheme && $this->_port == getservbyname($this->_scheme, 'tcp')) {
         $this->_port = false;
     }
     // Normalize case of %XX percentage-encodings (RFC 3986, section 6.2.2.1)
     foreach (array('_userinfo', '_host', '_path') as $part) {
         if ($this->{$part}) {
             $this->{$part} = preg_replace('/%[0-9a-f]{2}/ie', 'strtoupper("\\0")', $this->{$part});
         }
     }
     // Path segment normalization (RFC 3986, section 6.2.2.3)
     $this->_path = self::removeDotSegments($this->_path);
     // Scheme based normalization (RFC 3986, section 6.2.3)
     if ($this->_host && !$this->_path) {
         $this->_path = '/';
     }
 }
开发者ID:orcoliver,项目名称:oneye,代码行数:33,代码来源:URL2.php

示例15: start

 /**
  * Loads configuration, initializes plugin (including sieve connection)
  */
 function start($mode = null)
 {
     // register UI objects
     $this->rc->output->add_handlers(array('filterslist' => array($this, 'filters_list'), 'filtersetslist' => array($this, 'filtersets_list'), 'filterframe' => array($this, 'filter_frame'), 'filterform' => array($this, 'filter_form'), 'filtersetform' => array($this, 'filterset_form')));
     // Get connection parameters
     $host = $this->rc->config->get('managesieve_host', 'localhost');
     $port = $this->rc->config->get('managesieve_port');
     $tls = $this->rc->config->get('managesieve_usetls', false);
     $host = rcube_utils::parse_host($host);
     $host = rcube_utils::idn_to_ascii($host);
     // remove tls:// prefix, set TLS flag
     if (($host = preg_replace('|^tls://|i', '', $host, 1, $cnt)) && $cnt) {
         $tls = true;
     }
     if (empty($port)) {
         $port = getservbyname('sieve', 'tcp');
         if (empty($port)) {
             $port = self::PORT;
         }
     }
     $plugin = $this->rc->plugins->exec_hook('managesieve_connect', array('user' => $_SESSION['username'], 'password' => $this->rc->decrypt($_SESSION['password']), 'host' => $host, 'port' => $port, 'usetls' => $tls, 'auth_type' => $this->rc->config->get('managesieve_auth_type'), 'disabled' => $this->rc->config->get('managesieve_disabled_extensions'), 'debug' => $this->rc->config->get('managesieve_debug', false), 'auth_cid' => $this->rc->config->get('managesieve_auth_cid'), 'auth_pw' => $this->rc->config->get('managesieve_auth_pw')));
     // try to connect to managesieve server and to fetch the script
     $this->sieve = new rcube_sieve($plugin['user'], $plugin['password'], $plugin['host'], $plugin['port'], $plugin['auth_type'], $plugin['usetls'], $plugin['disabled'], $plugin['debug'], $plugin['auth_cid'], $plugin['auth_pw']);
     if (!($error = $this->sieve->error())) {
         // Get list of scripts
         $list = $this->list_scripts();
         // reset current script when entering filters UI (#1489412)
         if ($this->rc->action == 'plugin.managesieve') {
             $this->rc->session->remove('managesieve_current');
         }
         if ($mode != 'vacation') {
             if (!empty($_GET['_set']) || !empty($_POST['_set'])) {
                 $script_name = rcube_utils::get_input_value('_set', rcube_utils::INPUT_GPC, true);
             } else {
                 if (!empty($_SESSION['managesieve_current'])) {
                     $script_name = $_SESSION['managesieve_current'];
                 }
             }
         }
         if ($script_name === null || $script_name === '') {
             // get (first) active script
             if (!empty($this->active[0])) {
                 $script_name = $this->active[0];
             } else {
                 if ($list) {
                     $script_name = $list[0];
                 } else {
                     // if script not exists build default script contents
                     $script_file = $this->rc->config->get('managesieve_default');
                     $script_name = $this->rc->config->get('managesieve_script_name');
                     if (empty($script_name)) {
                         $script_name = 'roundcube';
                     }
                     if ($script_file && is_readable($script_file)) {
                         $content = file_get_contents($script_file);
                     }
                     // add script and set it active
                     if ($this->sieve->save_script($script_name, $content)) {
                         $this->activate_script($script_name);
                         $this->list[] = $script_name;
                     }
                 }
             }
         }
         if ($script_name) {
             $this->sieve->load($script_name);
         }
         $error = $this->sieve->error();
     }
     // finally set script objects
     if ($error) {
         switch ($error) {
             case SIEVE_ERROR_CONNECTION:
             case SIEVE_ERROR_LOGIN:
                 $this->rc->output->show_message('managesieve.filterconnerror', 'error');
                 rcube::raise_error(array('code' => 403, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Unable to connect to managesieve on {$host}:{$port}"), true, false);
                 break;
             default:
                 $this->rc->output->show_message('managesieve.filterunknownerror', 'error');
                 break;
         }
         // reload interface in case of possible error when specified script wasn't found (#1489412)
         if ($script_name !== null && !empty($list) && !in_array($script_name, $list)) {
             $this->rc->output->command('reload', 500);
         }
         // to disable 'Add filter' button set env variable
         $this->rc->output->set_env('filterconnerror', true);
         $this->script = array();
     } else {
         $this->exts = $this->sieve->get_extensions();
         $this->init_script();
         $this->rc->output->set_env('currentset', $this->sieve->current);
         $_SESSION['managesieve_current'] = $this->sieve->current;
     }
     return $error;
 }
开发者ID:zamentur,项目名称:roundcube_ynh,代码行数:99,代码来源:rcube_sieve_engine.php


注:本文中的getservbyname函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。