Aleksander Machniak
2015-08-25 f00e1f53339660fd57944f4cefdc18cf53c544b0
program/lib/Roundcube/rcube_utils.php
@@ -143,39 +143,7 @@
     */
    public static function check_ip($ip)
    {
        // IPv6, but there's no build-in IPv6 support
        if (strpos($ip, ':') !== false && !defined('AF_INET6')) {
            $parts = explode(':', $ip);
            $count = count($parts);
            if ($count > 8 || $count < 2) {
                return false;
            }
            foreach ($parts as $idx => $part) {
                $length = strlen($part);
                if (!$length) {
                    // there can be only one ::
                    if ($found_empty && $idx > 2) {
                        return false;
                    }
                    $found_empty = true;
                }
                // last part can be an IPv4 address
                else if ($idx == $count - 1) {
                    if (!preg_match('/^[0-9a-f]{1,4}$/i', $part)) {
                        return @inet_pton($part) !== false;
                    }
                }
                else if (!preg_match('/^[0-9a-f]{1,4}$/i', $part)) {
                    return false;
                }
            }
            return true;
        }
        return @inet_pton($ip) !== false;
        return filter_var($ip, FILTER_VALIDATE_IP) !== false;
    }
    /**
@@ -185,8 +153,9 @@
     */
    public static function check_referer()
    {
        $uri = parse_url($_SERVER['REQUEST_URI']);
        $uri     = parse_url($_SERVER['REQUEST_URI']);
        $referer = parse_url(self::request_header('Referer'));
        return $referer['host'] == self::request_header('Host') && $referer['path'] == $uri['path'];
    }
@@ -195,7 +164,7 @@
     *
     * @param  string  Input string
     * @param  string  Encoding type: text|html|xml|js|url
     * @param  string  Replace mode for tags: show|replace|remove
     * @param  string  Replace mode for tags: show|remove|strict
     * @param  boolean Convert newlines
     *
     * @return string  The quoted string
@@ -203,8 +172,8 @@
    public static function rep_specialchars_output($str, $enctype = '', $mode = '', $newlines = true)
    {
        static $html_encode_arr = false;
        static $js_rep_table = false;
        static $xml_rep_table = false;
        static $js_rep_table    = false;
        static $xml_rep_table   = false;
        if (!is_string($str)) {
            $str = strval($str);
@@ -219,8 +188,11 @@
            $encode_arr = $html_encode_arr;
            // don't replace quotes and html tags
            if ($mode == 'show' || $mode == '') {
            if ($mode == 'remove') {
                $str = strip_tags($str);
            }
            else if ($mode != 'strict') {
                // don't replace quotes and html tags
                $ltpos = strpos($str, '<');
                if ($ltpos !== false && strpos($str, '>', $ltpos) !== false) {
                    unset($encode_arr['"']);
@@ -228,9 +200,6 @@
                    unset($encode_arr['>']);
                    unset($encode_arr['&']);
                }
            }
            else if ($mode == 'remove') {
                $str = strip_tags($str);
            }
            $out = strtr($str, $encode_arr);
@@ -264,7 +233,7 @@
        // encode for plaintext
        if ($enctype == 'text') {
            return str_replace("\r\n", "\n", $mode=='remove' ? strip_tags($str) : $str);
            return str_replace("\r\n", "\n", $mode == 'remove' ? strip_tags($str) : $str);
        }
        if ($enctype == 'url') {