| | |
| | | */ |
| | | public static function https_check($port=null, $use_https=true) |
| | | { |
| | | global $RCMAIL; |
| | | |
| | | if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') { |
| | | return true; |
| | | } |
| | | if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https') { |
| | | 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 && isset($RCMAIL) && $RCMAIL->config->get('use_https')) { |
| | | if ($use_https && rcube::get_instance()->config->get('use_https')) { |
| | | return true; |
| | | } |
| | | |
| | |
| | | */ |
| | | public static function remote_addr() |
| | | { |
| | | if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
| | | $hosts = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'], 2); |
| | | return $hosts[0]; |
| | | } |
| | | // Check if any of the headers are set first to improve performance |
| | | if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) || !empty($_SERVER['HTTP_X_REAL_IP'])) { |
| | | $proxy_whitelist = rcube::get_instance()->config->get('proxy_whitelist', array()); |
| | | if (in_array($_SERVER['REMOTE_ADDR'], $proxy_whitelist)) { |
| | | if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
| | | foreach(array_reverse(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])) as $forwarded_ip) { |
| | | if (!in_array($forwarded_ip, $proxy_whitelist)) { |
| | | return $forwarded_ip; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!empty($_SERVER['HTTP_X_REAL_IP'])) { |
| | | return $_SERVER['HTTP_X_REAL_IP']; |
| | | if (!empty($_SERVER['HTTP_X_REAL_IP'])) { |
| | | return $_SERVER['HTTP_X_REAL_IP']; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!empty($_SERVER['REMOTE_ADDR'])) { |
| | |
| | | * |
| | | * @return object DateTime instance or false on failure |
| | | */ |
| | | public static function anytodatetime($date) |
| | | public static function anytodatetime($date, $timezone = null) |
| | | { |
| | | if (is_object($date) && is_a($date, 'DateTime')) { |
| | | return $date; |
| | |
| | | // try to parse string with DateTime first |
| | | if (!empty($date)) { |
| | | try { |
| | | $dt = new DateTime($date); |
| | | $dt = new DateTime($date, $timezone); |
| | | } |
| | | catch (Exception $e) { |
| | | // ignore |
| | |
| | | |
| | | /** |
| | | * Normalize the given string for fulltext search. |
| | | * Currently only optimized for Latin-1 characters; to be extended |
| | | * Currently only optimized for ISO-8859-1 and ISO-8859-2 characters; to be extended |
| | | * |
| | | * @param string Input string (UTF-8) |
| | | * @param boolean True to return list of words as array |
| | |
| | | // split by words |
| | | $arr = self::tokenize_string($str); |
| | | |
| | | // detect character set |
| | | if (utf8_encode(utf8_decode($str)) == $str) { |
| | | // ISO-8859-1 (or ASCII) |
| | | preg_match_all('/./u', 'äâàåáãæçéêëèïîìíñöôòøõóüûùúýÿ', $keys); |
| | | preg_match_all('/./', 'aaaaaaaceeeeiiiinoooooouuuuyy', $values); |
| | | |
| | | $mapping = array_combine($keys[0], $values[0]); |
| | | $mapping = array_merge($mapping, array('ß' => 'ss', 'ae' => 'a', 'oe' => 'o', 'ue' => 'u')); |
| | | } |
| | | else if (rcube_charset::convert(rcube_charset::convert($str, 'UTF-8', 'ISO-8859-2'), 'ISO-8859-2', 'UTF-8') == $str) { |
| | | // ISO-8859-2 |
| | | preg_match_all('/./u', 'ąáâäćçčéęëěíîłľĺńňóôöŕřśšşťţůúűüźžżý', $keys); |
| | | preg_match_all('/./', 'aaaaccceeeeiilllnnooorrsssttuuuuzzzy', $values); |
| | | |
| | | $mapping = array_combine($keys[0], $values[0]); |
| | | $mapping = array_merge($mapping, array('ß' => 'ss', 'ae' => 'a', 'oe' => 'o', 'ue' => 'u')); |
| | | } |
| | | |
| | | foreach ($arr as $i => $part) { |
| | | if (utf8_encode(utf8_decode($part)) == $part) { // is latin-1 ? |
| | | $arr[$i] = utf8_encode(strtr(strtolower(strtr(utf8_decode($part), |
| | | 'ÇçäâàåéêëèïîìÅÉöôòüûùÿøØáíóúñÑÁÂÀãÃÊËÈÍÎÏÓÔõÕÚÛÙýÝ', |
| | | 'ccaaaaeeeeiiiaeooouuuyooaiounnaaaaaeeeiiioooouuuyy')), |
| | | array('ß' => 'ss', 'ae' => 'a', 'oe' => 'o', 'ue' => 'u'))); |
| | | $part = mb_strtolower($part); |
| | | |
| | | if (!empty($mapping)) { |
| | | $part = strtr($part, $mapping); |
| | | } |
| | | else |
| | | $arr[$i] = mb_strtolower($part); |
| | | |
| | | $arr[$i] = $part; |
| | | } |
| | | |
| | | return $as_array ? $arr : join(" ", $arr); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Find out if the string content means true or false |
| | | * |
| | |
| | | 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; |
| | | } |
| | | } |
| | | } |