Aleksander Machniak
2014-02-07 517c9f9a8dba8e83eaa37a7660f434102e967a77
program/lib/Roundcube/rcube_utils.php
@@ -622,6 +622,10 @@
     */
    public static function parse_host($name, $host = '')
    {
        if (!is_string($name)) {
            return $name;
        }
        // %n - host
        $n = preg_replace('/:\d+$/', '', $_SERVER['SERVER_NAME']);
        // %t - host name without first part, e.g. %n=mail.domain.tld, %t=domain.tld
@@ -642,8 +646,7 @@
            }
        }
        $name = str_replace(array('%n', '%t', '%d', '%h', '%z', '%s'), array($n, $t, $d, $h, $z, $s[2]), $name);
        return $name;
        return str_replace(array('%n', '%t', '%d', '%h', '%z', '%s'), array($n, $t, $d, $h, $z, $s[2]), $name);
    }
@@ -680,9 +683,17 @@
     */
    public static function remote_addr()
    {
        foreach (array('HTTP_X_FORWARDED_FOR','HTTP_X_REAL_IP','REMOTE_ADDR') as $prop) {
            if (!empty($_SERVER[$prop]))
                return $_SERVER[$prop];
        if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $hosts = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'], 2);
            return $hosts[0];
        }
        if (!empty($_SERVER['HTTP_X_REAL_IP'])) {
            return $_SERVER['HTTP_X_REAL_IP'];
        }
        if (!empty($_SERVER['REMOTE_ADDR'])) {
            return $_SERVER['REMOTE_ADDR'];
        }
        return '';
@@ -1034,4 +1045,16 @@
        return !in_array($str, array('false', '0', 'no', 'off', 'nein', ''), true);
    }
    /**
     * OS-dependent absolute path detection
     */
    public static function is_absolute_path($path)
    {
        if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
            return (bool) preg_match('!^[a-z]:[\\\\/]!i', $path);
        }
        else {
            return $path[0] == DIRECTORY_SEPARATOR;
        }
    }
}