コード例 #1
0
ファイル: rcube_csv2vcard.php プロジェクト: BIGGANI/zpanelx
 /**
  *
  */
 public function import($csv)
 {
     // convert to UTF-8
     $head = substr($csv, 0, 4096);
     $charset = rcube_charset::detect($head, RCUBE_CHARSET);
     $csv = rcube_charset::convert($csv, $charset);
     $head = '';
     $this->map = array();
     // Parse file
     foreach (preg_split("/[\r\n]+/", $csv) as $line) {
         $elements = $this->parse_line($line);
         if (empty($elements)) {
             continue;
         }
         // Parse header
         if (empty($this->map)) {
             $this->parse_header($elements);
             if (empty($this->map)) {
                 break;
             }
         } else {
             $this->csv_to_vcard($elements);
         }
     }
 }
コード例 #2
0
 /**
  *
  */
 public function import($csv)
 {
     // convert to UTF-8
     $head = substr($csv, 0, 4096);
     $fallback = rcube::get_instance()->config->get('default_charset', 'ISO-8859-1');
     // fallback to Latin-1?
     $charset = rcube_charset::detect($head, RCUBE_CHARSET);
     $csv = rcube_charset::convert($csv, $charset);
     $head = '';
     $this->map = array();
     // Parse file
     foreach (preg_split("/[\r\n]+/", $csv) as $i => $line) {
         $elements = $this->parse_line($line);
         if (empty($elements)) {
             continue;
         }
         // Parse header
         if (empty($this->map)) {
             $this->parse_header($elements);
             if (empty($this->map)) {
                 break;
             }
         } else {
             $this->csv_to_vcard($elements);
         }
     }
 }
コード例 #3
0
ファイル: rcube_config.php プロジェクト: npk/roundcubemail
 /**
  * Load config from local config file
  *
  * @todo Remove global $CONFIG
  */
 private function load()
 {
     // load main config file
     if (!$this->load_from_file(RCMAIL_CONFIG_DIR . '/main.inc.php')) {
         $this->errors[] = 'main.inc.php was not found.';
     }
     // load database config
     if (!$this->load_from_file(RCMAIL_CONFIG_DIR . '/db.inc.php')) {
         $this->errors[] = 'db.inc.php was not found.';
     }
     // load host-specific configuration
     $this->load_host_config();
     // set skin (with fallback to old 'skin_path' property)
     if (empty($this->prop['skin'])) {
         if (!empty($this->prop['skin_path'])) {
             $this->prop['skin'] = str_replace('skins/', '', unslashify($this->prop['skin_path']));
         } else {
             $this->prop['skin'] = 'default';
         }
     }
     // fix paths
     $this->prop['log_dir'] = $this->prop['log_dir'] ? realpath(unslashify($this->prop['log_dir'])) : INSTALL_PATH . 'logs';
     $this->prop['temp_dir'] = $this->prop['temp_dir'] ? realpath(unslashify($this->prop['temp_dir'])) : INSTALL_PATH . 'temp';
     // fix default imap folders encoding
     foreach (array('drafts_mbox', 'junk_mbox', 'sent_mbox', 'trash_mbox') as $folder) {
         $this->prop[$folder] = rcube_charset::convert($this->prop[$folder], RCMAIL_CHARSET, 'UTF7-IMAP');
     }
     if (!empty($this->prop['default_folders'])) {
         foreach ($this->prop['default_folders'] as $n => $folder) {
             $this->prop['default_folders'][$n] = rcube_charset::convert($folder, RCMAIL_CHARSET, 'UTF7-IMAP');
         }
     }
     // set PHP error logging according to config
     if ($this->prop['debug_level'] & 1) {
         ini_set('log_errors', 1);
         if ($this->prop['log_driver'] == 'syslog') {
             ini_set('error_log', 'syslog');
         } else {
             ini_set('error_log', $this->prop['log_dir'] . '/errors');
         }
     }
     // enable display_errors in 'show' level, but not for ajax requests
     ini_set('display_errors', intval(empty($_REQUEST['_remote']) && $this->prop['debug_level'] & 4));
     // set timezone auto settings values
     if ($this->prop['timezone'] == 'auto') {
         $this->prop['_timezone_value'] = $this->client_timezone();
     } else {
         if (is_numeric($this->prop['timezone'])) {
             $this->prop['timezone'] = timezone_name_from_abbr("", $this->prop['timezone'] * 3600, 0);
         }
     }
     // remove deprecated properties
     unset($this->prop['dst_active']);
     // export config data
     $GLOBALS['CONFIG'] =& $this->prop;
 }
コード例 #4
0
 /**
  * Read available calendars for the current user and store them internally
  */
 private function _read_lists($force = false)
 {
     // already read sources
     if (isset($this->lists) && !$force) {
         return $this->lists;
     }
     // get all folders that have type "task"
     $this->folders = kolab_storage::get_folders('task');
     $this->lists = array();
     // convert to UTF8 and sort
     $names = array();
     $default_folder = null;
     foreach ($this->folders as $folder) {
         $names[$folder->name] = rcube_charset::convert($folder->name, 'UTF7-IMAP');
         $this->folders[$folder->name] = $folder;
         if ($folder->default) {
             $default_folder = $folder->name;
         }
     }
     asort($names, SORT_LOCALE_STRING);
     // put default folder (aka INBOX) on top of the list
     if ($default_folder) {
         $default_name = $names[$default_folder];
         unset($names[$default_folder]);
         $names = array_merge(array($default_folder => $default_name), $names);
     }
     $delim = $this->rc->get_storage()->get_hierarchy_delimiter();
     $listnames = array();
     $prefs = $this->rc->config->get('kolab_tasklists', array());
     foreach ($names as $utf7name => $name) {
         $folder = $this->folders[$utf7name];
         $path_imap = explode($delim, $name);
         $editname = array_pop($path_imap);
         // pop off raw name part
         $path_imap = join($delim, $path_imap);
         $name = kolab_storage::folder_displayname(kolab_storage::object_name($utf7name), $listnames);
         if ($folder->get_namespace() == 'personal') {
             $readonly = false;
             $alarms = true;
         } else {
             $alarms = false;
             $readonly = true;
             if (($rights = $folder->get_myrights()) && !PEAR::isError($rights)) {
                 if (strpos($rights, 'i') !== false) {
                     $readonly = false;
                 }
             }
         }
         $list_id = kolab_storage::folder_id($utf7name);
         $tasklist = array('id' => $list_id, 'name' => $name, 'editname' => $editname, 'color' => $folder->get_color('0000CC'), 'showalarms' => isset($prefs[$list_id]['showalarms']) ? $prefs[$list_id]['showalarms'] : $alarms, 'editable' => !$readonly, 'active' => $folder->is_active(), 'parentfolder' => $path_imap, 'default' => $folder->default, 'children' => true, 'class_name' => trim($folder->get_namespace() . ($folder->default ? ' default' : '')));
         $this->lists[$tasklist['id']] = $tasklist;
         $this->folders[$tasklist['id']] = $folder;
     }
 }
コード例 #5
0
 /**
  *
  */
 public function import($csv)
 {
     // convert to UTF-8
     $head = substr($csv, 0, 4096);
     $charset = rcube_charset::detect($head, RCUBE_CHARSET);
     $csv = rcube_charset::convert($csv, $charset);
     $csv = preg_replace(array('/^[\\xFE\\xFF]{2}/', '/^\\xEF\\xBB\\xBF/', '/^\\x00+/'), '', $csv);
     // also remove BOM
     $head = '';
     $prev_line = false;
     $this->map = array();
     $this->gmail_map = array();
     // Parse file
     foreach (preg_split("/[\r\n]+/", $csv) as $line) {
         if (!empty($prev_line)) {
             $line = '"' . $line;
         }
         $elements = $this->parse_line($line);
         if (empty($elements)) {
             continue;
         }
         // Parse header
         if (empty($this->map)) {
             $this->parse_header($elements);
             if (empty($this->map)) {
                 break;
             }
         } else {
             // handle multiline elements (e.g. Gmail)
             if (!empty($prev_line)) {
                 $first = array_shift($elements);
                 if ($first[0] == '"') {
                     $prev_line[count($prev_line) - 1] = '"' . $prev_line[count($prev_line) - 1] . "\n" . substr($first, 1);
                 } else {
                     $prev_line[count($prev_line) - 1] .= "\n" . $first;
                 }
                 $elements = array_merge($prev_line, $elements);
             }
             $last_element = $elements[count($elements) - 1];
             if ($last_element[0] == '"') {
                 $elements[count($elements) - 1] = substr($last_element, 1);
                 $prev_line = $elements;
                 continue;
             }
             $this->csv_to_vcard($elements);
             $prev_line = false;
         }
     }
 }
コード例 #6
0
 /**
  * Fetch message body of a specific message from the server
  *
  * @param  int    $uid  Message UID
  *
  * @return string $part Message/part body
  * @see    rcube_imap::get_message_part()
  */
 public function get_body($uid, $part = 1)
 {
     $headers = $this->get_message_headers($uid);
     return rcube_charset::convert($this->get_message_part($uid, $part, null), $headers->charset ? $headers->charset : $this->default_charset);
 }
コード例 #7
0
 /**
  * Converts mailbox name from/to UTF7-IMAP from/to internal Sieve encoding
  * with delimiter replacement.
  *
  * @param string $mailbox Mailbox name
  * @param string $mode    Conversion direction ('in'|'out')
  *
  * @return string Mailbox name
  */
 protected function mod_mailbox($mailbox, $mode = 'out')
 {
     $delimiter = $_SESSION['imap_delimiter'];
     $replace_delimiter = $this->rc->config->get('managesieve_replace_delimiter');
     $mbox_encoding = $this->rc->config->get('managesieve_mbox_encoding', 'UTF7-IMAP');
     if ($mode == 'out') {
         $mailbox = rcube_charset::convert($mailbox, $mbox_encoding, 'UTF7-IMAP');
         if ($replace_delimiter && $replace_delimiter != $delimiter) {
             $mailbox = str_replace($replace_delimiter, $delimiter, $mailbox);
         }
     } else {
         $mailbox = rcube_charset::convert($mailbox, 'UTF7-IMAP', $mbox_encoding);
         if ($replace_delimiter && $replace_delimiter != $delimiter) {
             $mailbox = str_replace($delimiter, $replace_delimiter, $mailbox);
         }
     }
     return $mailbox;
 }
コード例 #8
0
 /**
  * Convert a variable into a javascript object notation
  *
  * @param mixed Input value
  *
  * @return string Serialized JSON string
  */
 public static function json_serialize($input)
 {
     $input = rcube_charset::clean($input);
     // sometimes even using rcube_charset::clean() the input contains invalid UTF-8 sequences
     // that's why we have @ here
     return @json_encode($input);
 }
コード例 #9
0
 /**
  * Returns UNICODE type based on BOM (Byte Order Mark)
  *
  * @param string Input string to test
  * @return string Detected encoding
  */
 private static function detect_encoding($string)
 {
     $fallback = rcube::get_instance()->config->get('default_charset', 'ISO-8859-1');
     // fallback to Latin-1
     return rcube_charset::detect($string, $fallback);
 }
コード例 #10
0
 /**
  * Process template and write to stdOut
  *
  * @param string HTML template
  * @param string Base for absolute paths
  */
 public function _write($templ = '', $base_path = '')
 {
     $output = trim($templ);
     if (empty($output)) {
         $output = $this->default_template;
         $is_empty = true;
     }
     // set default page title
     if (empty($this->pagetitle)) {
         $this->pagetitle = 'Roundcube Mail';
     }
     // replace specialchars in content
     $page_title = html::quote($this->pagetitle);
     $page_header = '';
     $page_footer = '';
     // include meta tag with charset
     if (!empty($this->charset)) {
         if (!headers_sent()) {
             header('Content-Type: text/html; charset=' . $this->charset);
         }
         $page_header = '<meta http-equiv="content-type"';
         $page_header .= ' content="text/html; charset=';
         $page_header .= $this->charset . '" />' . "\n";
     }
     // definition of the code to be placed in the document header and footer
     if (is_array($this->script_files['head'])) {
         foreach ($this->script_files['head'] as $file) {
             $page_header .= html::script($file);
         }
     }
     $head_script = $this->scripts['head_top'] . $this->scripts['head'];
     if (!empty($head_script)) {
         $page_header .= html::script(array(), $head_script);
     }
     if (!empty($this->header)) {
         $page_header .= $this->header;
     }
     // put docready commands into page footer
     if (!empty($this->scripts['docready'])) {
         $this->add_script('$(document).ready(function(){ ' . $this->scripts['docready'] . "\n});", 'foot');
     }
     if (is_array($this->script_files['foot'])) {
         foreach ($this->script_files['foot'] as $file) {
             $page_footer .= html::script($file);
         }
     }
     if (!empty($this->footer)) {
         $page_footer .= $this->footer . "\n";
     }
     if (!empty($this->scripts['foot'])) {
         $page_footer .= html::script(array(), $this->scripts['foot']);
     }
     // find page header
     if ($hpos = stripos($output, '</head>')) {
         $page_header .= "\n";
     } else {
         if (!is_numeric($hpos)) {
             $hpos = stripos($output, '<body');
         }
         if (!is_numeric($hpos) && ($hpos = stripos($output, '<html'))) {
             while ($output[$hpos] != '>') {
                 $hpos++;
             }
             $hpos++;
         }
         $page_header = "<head>\n<title>{$page_title}</title>\n{$page_header}\n</head>\n";
     }
     // add page hader
     if ($hpos) {
         $output = substr_replace($output, $page_header, $hpos, 0);
     } else {
         $output = $page_header . $output;
     }
     // add page footer
     if (($fpos = strripos($output, '</body>')) || ($fpos = strripos($output, '</html>'))) {
         $output = substr_replace($output, $page_footer . "\n", $fpos, 0);
     } else {
         $output .= "\n" . $page_footer;
     }
     // add css files in head, before scripts, for speed up with parallel downloads
     if (!empty($this->css_files) && !$is_empty && (($pos = stripos($output, '<script ')) || ($pos = stripos($output, '</head>')))) {
         $css = '';
         foreach ($this->css_files as $file) {
             $css .= html::tag('link', array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => $file, 'nl' => true));
         }
         $output = substr_replace($output, $css, $pos, 0);
     }
     $output = $this->parse_with_globals($this->fix_paths($output));
     // trigger hook with final HTML content to be sent
     $hook = $this->app->plugins->exec_hook("send_page", array('content' => $output));
     if (!$hook['abort']) {
         if ($this->charset != RCUBE_CHARSET) {
             echo rcube_charset::convert($hook['content'], RCUBE_CHARSET, $this->charset);
         } else {
             echo $hook['content'];
         }
     }
 }
コード例 #11
0
ファイル: rcmail.php プロジェクト: peknur/roundcubemail
 public function localize_folderpath($path)
 {
     $protect_folders = $this->config->get('protect_default_folders');
     $delimiter = $this->storage->get_hierarchy_delimiter();
     $path = explode($delimiter, $path);
     $result = array();
     foreach ($path as $idx => $dir) {
         $directory = implode($delimiter, array_slice($path, 0, $idx + 1));
         if ($protect_folders && $this->storage->is_special_folder($directory)) {
             unset($result);
             $result[] = $this->localize_foldername($directory);
         } else {
             $result[] = rcube_charset::convert($dir, 'UTF7-IMAP');
         }
     }
     return implode($delimiter, $result);
 }
コード例 #12
0
 protected function _rcmail_get_identity($id)
 {
     $rcmail = rcube::get_instance();
     if ($sql_arr = $rcmail->user->get_identity($id)) {
         $out = $sql_arr;
         $out['mailto'] = $sql_arr['email'];
         $out['string'] = format_email_recipient($sql_arr['email'], rcube_charset::convert($sql_arr['name'], RCUBE_CHARSET, $this->api->output->get_charset()));
         if ($rcmail->config->get('sieverules_from_format', 0) == 1) {
             $out['disp_string'] = $out['string'];
             $out['val_string'] = $out['string'];
         } else {
             $out['disp_string'] = $out['mailto'];
             $out['val_string'] = $out['mailto'];
         }
         return $out;
     }
     return false;
 }
コード例 #13
0
 /**
  * Normalize the given string for fulltext search.
  * 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
  *
  * @return mixed  Normalized string or a list of normalized tokens
  */
 public static function normalize_string($str, $as_array = false)
 {
     // replace 4-byte unicode characters with '?' character,
     // these are not supported in default utf-8 charset on mysql,
     // the chance we'd need them in searching is very low
     $str = preg_replace('/(' . '\\xF0[\\x90-\\xBF][\\x80-\\xBF]{2}' . '|[\\xF1-\\xF3][\\x80-\\xBF]{3}' . '|\\xF4[\\x80-\\x8F][\\x80-\\xBF]{2}' . ')/', '?', $str);
     // 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) {
         $part = mb_strtolower($part);
         if (!empty($mapping)) {
             $part = strtr($part, $mapping);
         }
         $arr[$i] = $part;
     }
     return $as_array ? $arr : join(" ", $arr);
 }
コード例 #14
0
ファイル: zipdownload.php プロジェクト: rasky/roundcubemail
 /**
  * Helper function to convert filenames to the configured charset
  */
 private function _convert_filename($str)
 {
     $str = rcube_charset::convert($str, RCUBE_CHARSET, $this->charset);
     return strtr($str, array(':' => '', '/' => '-'));
 }
コード例 #15
0
 private function read_squirrel_prefs($uname)
 {
     $rcmail = rcmail::get_instance();
     /**** File based backend ****/
     if ($rcmail->config->get('squirrelmail_driver') == 'file' && ($srcdir = $rcmail->config->get('squirrelmail_data_dir'))) {
         if (($hash_level = $rcmail->config->get('squirrelmail_data_dir_hash_level')) > 0) {
             $srcdir = slashify($srcdir) . chunk_split(substr(base_convert(crc32($uname), 10, 16), 0, $hash_level), 1, '/');
         }
         $prefsfile = slashify($srcdir) . $uname . '.pref';
         $abookfile = slashify($srcdir) . $uname . '.abook';
         $sigfile = slashify($srcdir) . $uname . '.sig';
         $sigbase = slashify($srcdir) . $uname . '.si';
         if (is_readable($prefsfile)) {
             $this->prefs = array();
             foreach (file($prefsfile) as $line) {
                 list($key, $value) = explode('=', $line);
                 $this->prefs[$key] = utf8_encode(rtrim($value));
             }
             // also read signature file if exists
             if (is_readable($sigfile)) {
                 $this->prefs['___signature___'] = utf8_encode(file_get_contents($sigfile));
             }
             if (isset($this->prefs['identities']) && $this->prefs['identities'] > 1) {
                 for ($i = 1; $i < $this->prefs['identities']; $i++) {
                     // read signature file if exists
                     if (is_readable($sigbase . $i)) {
                         $this->prefs['___sig' . $i . '___'] = utf8_encode(file_get_contents($sigbase . $i));
                     }
                 }
             }
             // parse addres book file
             if (filesize($abookfile)) {
                 foreach (file($abookfile) as $line) {
                     list($rec['name'], $rec['firstname'], $rec['surname'], $rec['email']) = explode('|', utf8_encode(rtrim($line)));
                     if ($rec['name'] && $rec['email']) {
                         $this->abook[] = $rec;
                     }
                 }
             }
         }
     } else {
         if ($rcmail->config->get('squirrelmail_driver') == 'sql') {
             $this->prefs = array();
             /* connect to squirrelmail database */
             $db = rcube_db::factory($rcmail->config->get('squirrelmail_dsn'));
             $db->set_debug($rcmail->config->get('sql_debug'));
             $db->db_connect('r');
             // connect in read mode
             /* retrieve prefs */
             $userprefs_table = $rcmail->config->get('squirrelmail_userprefs_table');
             $address_table = $rcmail->config->get('squirrelmail_address_table');
             $db_charset = $rcmail->config->get('squirrelmail_db_charset');
             if ($db_charset) {
                 $db->query('SET NAMES ' . $db_charset);
             }
             $sql_result = $db->query('SELECT * FROM ' . $userprefs_table . ' WHERE user=?', $uname);
             // ? is replaced with emailaddress
             while ($sql_array = $db->fetch_assoc($sql_result)) {
                 // fetch one row from result
                 $this->prefs[$sql_array['prefkey']] = rcube_charset::convert(rtrim($sql_array['prefval']), $db_charset);
             }
             /* retrieve address table data */
             $sql_result = $db->query('SELECT * FROM ' . $address_table . ' WHERE owner=?', $uname);
             // ? is replaced with emailaddress
             // parse addres book
             while ($sql_array = $db->fetch_assoc($sql_result)) {
                 // fetch one row from result
                 $rec['name'] = rcube_charset::convert(rtrim($sql_array['nickname']), $db_charset);
                 $rec['firstname'] = rcube_charset::convert(rtrim($sql_array['firstname']), $db_charset);
                 $rec['surname'] = rcube_charset::convert(rtrim($sql_array['lastname']), $db_charset);
                 $rec['email'] = rcube_charset::convert(rtrim($sql_array['email']), $db_charset);
                 $rec['notes'] = rcube_charset::convert(rtrim($sql_array['label']), $db_charset);
                 if ($rec['name'] && $rec['email']) {
                     $this->abook[] = $rec;
                 }
             }
         }
     }
     // end if 'sql'-driver
 }
コード例 #16
0
ファイル: password.php プロジェクト: NathanAUS/roundcubemail
 /**
  * Hashes a password and returns the hash based on the specified method
  *
  * Parts of the code originally from the phpLDAPadmin development team
  * http://phpldapadmin.sourceforge.net/
  *
  * @param string      Clear password
  * @param string      Hashing method
  * @param bool|string Prefix string or TRUE to add a default prefix
  *
  * @return string Hashed password
  */
 static function hash_password($password, $method = '', $prefixed = true)
 {
     $method = strtolower($method);
     $rcmail = rcmail::get_instance();
     if (empty($method) || $method == 'default') {
         $method = $rcmail->config->get('password_algorithm');
         $prefixed = $rcmail->config->get('password_algorithm_prefix');
         $default = true;
     } else {
         if ($method == 'crypt') {
             // deprecated
             if (!($method = $rcmail->config->get('password_crypt_hash'))) {
                 $method = 'md5';
             }
             if (!strpos($method, '-crypt')) {
                 $method .= '-crypt';
             }
         }
     }
     switch ($method) {
         case 'des':
         case 'des-crypt':
             $crypted = crypt($password, self::random_salt(2));
             $prefix = '{CRYPT}';
             break;
         case 'ext_des':
             // for BC
         // for BC
         case 'ext-des-crypt':
             $crypted = crypt($password, '_' . self::random_salt(8));
             $prefix = '{CRYPT}';
             break;
         case 'md5crypt':
             // for BC
         // for BC
         case 'md5-crypt':
             $crypted = crypt($password, '$1$' . self::random_salt(9));
             $prefix = '{CRYPT}';
             break;
         case 'sha256-crypt':
             $crypted = crypt($password, '$5$' . self::random_salt(16));
             $prefix = '{CRYPT}';
             break;
         case 'sha512-crypt':
             $crypted = crypt($password, '$6$' . self::random_salt(16));
             $prefix = '{CRYPT}';
             break;
         case 'blowfish':
             // for BC
         // for BC
         case 'blowfish-crypt':
             $cost = (int) $rcmail->config->get('password_blowfish_cost');
             $cost = $cost < 4 || $cost > 31 ? 12 : $cost;
             $prefix = sprintf('$2a$%02d$', $cost);
             $crypted = crypt($password, $prefix . self::random_salt(22));
             $prefix = '{CRYPT}';
             break;
         case 'md5':
             $crypted = base64_encode(pack('H*', md5($password)));
             $prefix = '{MD5}';
             break;
         case 'sha':
             if (function_exists('sha1')) {
                 $crypted = pack('H*', sha1($password));
             } else {
                 if (function_exists('hash')) {
                     $crypted = hash('sha1', $password, true);
                 } else {
                     if (function_exists('mhash')) {
                         $crypted = mhash(MHASH_SHA1, $password);
                     } else {
                         rcube::raise_error(array('code' => 600, 'file' => __FILE__, 'line' => __LINE__, 'message' => "Password plugin: Your PHP install does not have the mhash()/hash() nor sha1() function"), true, true);
                     }
                 }
             }
             $crypted = base64_encode($crypted);
             $prefix = '{SHA}';
             break;
         case 'ssha':
             $salt = substr(pack('h*', md5(mt_rand())), 0, 8);
             if (function_exists('mhash') && function_exists('mhash_keygen_s2k')) {
                 $salt = mhash_keygen_s2k(MHASH_SHA1, $password, $salt, 4);
                 $crypted = mhash(MHASH_SHA1, $password . $salt);
             } else {
                 if (function_exists('sha1')) {
                     $salt = substr(pack("H*", sha1($salt . $password)), 0, 4);
                     $crypted = sha1($password . $salt, true);
                 } else {
                     if (function_exists('hash')) {
                         $salt = substr(pack("H*", hash('sha1', $salt . $password)), 0, 4);
                         $crypted = hash('sha1', $password . $salt, true);
                     } else {
                         rcube::raise_error(array('code' => 600, 'file' => __FILE__, 'line' => __LINE__, 'message' => "Password plugin: Your PHP install does not have the mhash()/hash() nor sha1() function"), true, true);
                     }
                 }
             }
             $crypted = base64_encode($crypted . $salt);
             $prefix = '{SSHA}';
             break;
         case 'smd5':
             $salt = substr(pack('h*', md5(mt_rand())), 0, 8);
             if (function_exists('mhash') && function_exists('mhash_keygen_s2k')) {
                 $salt = mhash_keygen_s2k(MHASH_MD5, $password, $salt, 4);
                 $crypted = mhash(MHASH_MD5, $password . $salt);
             } else {
                 if (function_exists('hash')) {
                     $salt = substr(pack("H*", hash('md5', $salt . $password)), 0, 4);
                     $crypted = hash('md5', $password . $salt, true);
                 } else {
                     $salt = substr(pack("H*", md5($salt . $password)), 0, 4);
                     $crypted = md5($password . $salt, true);
                 }
             }
             $crypted = base64_encode($crypted . $salt);
             $prefix = '{SMD5}';
             break;
         case 'samba':
             if (function_exists('hash')) {
                 $crypted = hash('md4', rcube_charset::convert($password, RCUBE_CHARSET, 'UTF-16LE'));
                 $crypted = strtoupper($crypted_password);
             } else {
                 rcube::raise_error(array('code' => 600, 'file' => __FILE__, 'line' => __LINE__, 'message' => "Password plugin: Your PHP install does not have hash() function"), true, true);
             }
             break;
         case 'ad':
             $crypted = rcube_charset::convert('"' . $password . '"', RCUBE_CHARSET, 'UTF-16LE');
             break;
         case 'cram-md5':
             // deprecated
             require_once __DIR__ . '/../helpers/dovecot_hmacmd5.php';
             $crypted = dovecot_hmacmd5($password);
             $prefix = '{CRAM-MD5}';
             break;
         case 'dovecot':
             if (!($dovecotpw = $rcmail->config->get('password_dovecotpw'))) {
                 $dovecotpw = 'dovecotpw';
             }
             if (!($method = $rcmail->config->get('password_dovecotpw_method'))) {
                 $method = 'CRAM-MD5';
             }
             // use common temp dir
             $tmp_dir = $rcmail->config->get('temp_dir');
             $tmpfile = tempnam($tmp_dir, 'roundcube-');
             $pipe = popen("{$dovecotpw} -s '{$method}' > '{$tmpfile}'", "w");
             if (!$pipe) {
                 unlink($tmpfile);
                 return false;
             } else {
                 fwrite($pipe, $passwd . "\n", 1 + strlen($passwd));
                 usleep(1000);
                 fwrite($pipe, $passwd . "\n", 1 + strlen($passwd));
                 pclose($pipe);
                 $crypted = trim(file_get_contents($tmpfile), "\n");
                 unlink($tmpfile);
                 if (!preg_match('/^\\{' . $method . '\\}/', $newpass)) {
                     return false;
                 }
                 if (!$default) {
                     $prefixed = (bool) $rcmail->config->get('password_dovecotpw_with_method');
                 }
                 if (!$prefixed) {
                     $crypted = trim(str_replace('{' . $method . '}', '', $crypted));
                 }
                 $prefixed = false;
             }
             break;
         case 'hash':
             // deprecated
             if (!extension_loaded('hash')) {
                 rcube::raise_error(array('code' => 600, 'file' => __FILE__, 'line' => __LINE__, 'message' => "Password plugin: 'hash' extension not loaded!"), true, true);
             }
             if (!($hash_algo = strtolower($rcmail->config->get('password_hash_algorithm')))) {
                 $hash_algo = 'sha1';
             }
             $crypted = hash($hash_algo, $password);
             if ($rcmail->config->get('password_hash_base64')) {
                 $crypted = base64_encode(pack('H*', $crypted));
             }
             break;
         case 'clear':
             $crypted = $password;
     }
     if ($crypted === null || $crypted === false) {
         return false;
     }
     if ($prefixed && $prefixed !== true) {
         $prefix = $prefixed;
         $prefixed = true;
     }
     if ($prefixed === true && $prefix) {
         $crypted = $prefix . $crypted;
     }
     return $crypted;
 }
コード例 #17
0
ファイル: bc.php プロジェクト: noikiy/roundcubemail
function rc_utf8_clean($input)
{
    return rcube_charset::clean($input);
}
コード例 #18
0
ファイル: rcube_output.php プロジェクト: jimjag/roundcubemail
 /**
  * Convert a variable into a javascript object notation
  *
  * @param mixed   $input  Input value
  * @param boolean $pretty Enable JSON formatting
  *
  * @return string Serialized JSON string
  */
 public static function json_serialize($input, $pretty = false)
 {
     $input = rcube_charset::clean($input);
     $options = 0;
     if ($pretty) {
         $options |= JSON_PRETTY_PRINT;
     }
     // sometimes even using rcube_charset::clean() the input contains invalid UTF-8 sequences
     // that's why we have @ here
     return @json_encode($input, $options);
 }
コード例 #19
0
 /**
  * Fix attachment name encoding if needed/possible
  */
 protected function fix_attachment_name($name, $part)
 {
     if ($name == rcube_charset::clean($name)) {
         return $name;
     }
     // find charset from part or its parent(s)
     if ($part->charset) {
         $charsets[] = $part->charset;
     } else {
         // check first part (common case)
         $n = strpos($part->mime_id, '.') ? preg_replace('/\\.[0-9]+$/', '', $part->mime_id) . '.1' : 1;
         if (($_part = $this->mime_parts[$n]) && $_part->charset) {
             $charsets[] = $_part->charset;
         }
         // check parents' charset
         $items = explode('.', $part->mime_id);
         for ($i = count($items) - 1; $i > 0; $i--) {
             $last = array_pop($items);
             $parent = $this->mime_parts[join('.', $items)];
             if ($parent && $parent->charset) {
                 $charsets[] = $parent->charset;
             }
         }
     }
     if ($this->headers->charset) {
         $charsets[] = $this->headers->charset;
     }
     if (empty($charsets)) {
         $rcube = rcube::get_instance();
         $charsets[] = rcube_charset::detect($name, $rcube->config->get('default_charset', RCUBE_CHARSET));
     }
     foreach (array_unique($charsets) as $charset) {
         $_name = rcube_charset::convert($name, $charset);
         if ($_name == rcube_charset::clean($_name)) {
             if (!$part->charset) {
                 $part->charset = $charset;
             }
             return $_name;
         }
     }
     return $name;
 }
コード例 #20
0
 /**
  * Returns header value
  */
 public function get($name, $decode = true)
 {
     $name = strtolower($name);
     if (isset($this->obj_headers[$name])) {
         $value = $this->{$this->obj_headers[$name]};
     } else {
         $value = $this->others[$name];
     }
     if ($decode) {
         if (is_array($value)) {
             foreach ($value as $key => $val) {
                 $value[$key] = rcube_mime::decode_header($val, $this->charset);
                 $value[$key] = rcube_charset::clean($val);
             }
         } else {
             $value = rcube_mime::decode_header($value, $this->charset);
             $value = rcube_charset::clean($value);
         }
     }
     return $value;
 }
コード例 #21
0
ファイル: rcube_config.php プロジェクト: jimjag/roundcubemail
 /**
  * Load config from local config file
  *
  * @todo Remove global $CONFIG
  */
 private function load()
 {
     // Load default settings
     if (!$this->load_from_file('defaults.inc.php')) {
         $this->errors[] = 'defaults.inc.php was not found.';
     }
     // load main config file
     if (!$this->load_from_file('config.inc.php')) {
         // Old configuration files
         if (!$this->load_from_file('main.inc.php') || !$this->load_from_file('db.inc.php')) {
             $this->errors[] = 'config.inc.php was not found.';
         } else {
             if (rand(1, 100) == 10) {
                 // log warning on every 100th request (average)
                 trigger_error("config.inc.php was not found. Please migrate your config by running bin/update.sh", E_USER_WARNING);
             }
         }
     }
     // load host-specific configuration
     $this->load_host_config();
     // set skin (with fallback to old 'skin_path' property)
     if (empty($this->prop['skin'])) {
         if (!empty($this->prop['skin_path'])) {
             $this->prop['skin'] = str_replace('skins/', '', unslashify($this->prop['skin_path']));
         } else {
             $this->prop['skin'] = self::DEFAULT_SKIN;
         }
     }
     // larry is the new default skin :-)
     if ($this->prop['skin'] == 'default') {
         $this->prop['skin'] = self::DEFAULT_SKIN;
     }
     // fix paths
     foreach (array('log_dir' => 'logs', 'temp_dir' => 'temp') as $key => $dir) {
         foreach (array($this->prop[$key], '../' . $this->prop[$key], RCUBE_INSTALL_PATH . $dir) as $path) {
             if ($path && ($realpath = realpath(unslashify($path)))) {
                 $this->prop[$key] = $realpath;
                 break;
             }
         }
     }
     // fix default imap folders encoding
     foreach (array('drafts_mbox', 'junk_mbox', 'sent_mbox', 'trash_mbox') as $folder) {
         $this->prop[$folder] = rcube_charset::convert($this->prop[$folder], RCUBE_CHARSET, 'UTF7-IMAP');
     }
     // set PHP error logging according to config
     if ($this->prop['debug_level'] & 1) {
         ini_set('log_errors', 1);
         if ($this->prop['log_driver'] == 'syslog') {
             ini_set('error_log', 'syslog');
         } else {
             ini_set('error_log', $this->prop['log_dir'] . '/errors');
         }
     }
     // enable display_errors in 'show' level, but not for ajax requests
     ini_set('display_errors', intval(empty($_REQUEST['_remote']) && $this->prop['debug_level'] & 4));
     // remove deprecated properties
     unset($this->prop['dst_active']);
     // export config data
     $GLOBALS['CONFIG'] =& $this->prop;
 }
コード例 #22
0
ファイル: password.php プロジェクト: alecchisi/roundcubemail
 function password_save()
 {
     $this->register_handler('plugin.body', array($this, 'password_form'));
     $rcmail = rcmail::get_instance();
     $rcmail->output->set_pagetitle($this->gettext('changepasswd'));
     $confirm = $rcmail->config->get('password_confirm_current');
     $required_length = intval($rcmail->config->get('password_minimum_length'));
     $check_strength = $rcmail->config->get('password_require_nonalpha');
     if ($confirm && !isset($_POST['_curpasswd']) || !isset($_POST['_newpasswd'])) {
         $rcmail->output->command('display_message', $this->gettext('nopassword'), 'error');
     } else {
         $charset = strtoupper($rcmail->config->get('password_charset', 'ISO-8859-1'));
         $rc_charset = strtoupper($rcmail->output->get_charset());
         $sespwd = $rcmail->decrypt($_SESSION['password']);
         $curpwd = $confirm ? rcube_utils::get_input_value('_curpasswd', rcube_utils::INPUT_POST, true, $charset) : $sespwd;
         $newpwd = rcube_utils::get_input_value('_newpasswd', rcube_utils::INPUT_POST, true);
         $conpwd = rcube_utils::get_input_value('_confpasswd', rcube_utils::INPUT_POST, true);
         // check allowed characters according to the configured 'password_charset' option
         // by converting the password entered by the user to this charset and back to UTF-8
         $orig_pwd = $newpwd;
         $chk_pwd = rcube_charset::convert($orig_pwd, $rc_charset, $charset);
         $chk_pwd = rcube_charset::convert($chk_pwd, $charset, $rc_charset);
         // WARNING: Default password_charset is ISO-8859-1, so conversion will
         // change national characters. This may disable possibility of using
         // the same password in other MUA's.
         // We're doing this for consistence with Roundcube core
         $newpwd = rcube_charset::convert($newpwd, $rc_charset, $charset);
         $conpwd = rcube_charset::convert($conpwd, $rc_charset, $charset);
         if ($chk_pwd != $orig_pwd) {
             $rcmail->output->command('display_message', $this->gettext('passwordforbidden'), 'error');
         } else {
             if ($conpwd != $newpwd) {
                 $rcmail->output->command('display_message', $this->gettext('passwordinconsistency'), 'error');
             } else {
                 if ($confirm && $sespwd != $curpwd) {
                     $rcmail->output->command('display_message', $this->gettext('passwordincorrect'), 'error');
                 } else {
                     if ($required_length && strlen($newpwd) < $required_length) {
                         $rcmail->output->command('display_message', $this->gettext(array('name' => 'passwordshort', 'vars' => array('length' => $required_length))), 'error');
                     } else {
                         if ($check_strength && (!preg_match("/[0-9]/", $newpwd) || !preg_match("/[^A-Za-z0-9]/", $newpwd))) {
                             $rcmail->output->command('display_message', $this->gettext('passwordweak'), 'error');
                         } else {
                             if ($sespwd == $newpwd && !$rcmail->config->get('password_force_save')) {
                                 $rcmail->output->command('display_message', $this->gettext('successfullysaved'), 'confirmation');
                             } else {
                                 if (!($res = $this->_save($curpwd, $newpwd))) {
                                     $rcmail->output->command('display_message', $this->gettext('successfullysaved'), 'confirmation');
                                     // allow additional actions after password change (e.g. reset some backends)
                                     $plugin = $rcmail->plugins->exec_hook('password_change', array('old_pass' => $curpwd, 'new_pass' => $newpwd));
                                     // Reset session password
                                     $_SESSION['password'] = $rcmail->encrypt($plugin['new_pass']);
                                     // Log password change
                                     if ($rcmail->config->get('password_log')) {
                                         rcube::write_log('password', sprintf('Password changed for user %s (ID: %d) from %s', $rcmail->get_user_name(), $rcmail->user->ID, rcube_utils::remote_ip()));
                                     }
                                 } else {
                                     $rcmail->output->command('display_message', $res, 'error');
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $rcmail->overwrite_action('plugin.password');
     $rcmail->output->send('plugin');
 }
コード例 #23
0
ファイル: rcube_imap.php プロジェクト: ehabqino/roundcubemail
 /**
  * Sort folders first by default folders and then in alphabethical order
  *
  * @param array $a_folders    Folders list
  * @param bool  $skip_default Skip default folders handling
  *
  * @return array Sorted list
  */
 public function sort_folder_list($a_folders, $skip_default = false)
 {
     $specials = array_merge(array('INBOX'), array_values($this->get_special_folders()));
     $folders = array();
     // convert names to UTF-8
     foreach ($a_folders as $folder) {
         // for better performance skip encoding conversion
         // if the string does not look like UTF7-IMAP
         $folders[$folder] = strpos($folder, '&') === false ? $folder : rcube_charset::convert($folder, 'UTF7-IMAP');
     }
     // sort folders
     // asort($folders, SORT_LOCALE_STRING) is not properly sorting case sensitive names
     uasort($folders, array($this, 'sort_folder_comparator'));
     $folders = array_keys($folders);
     if ($skip_default) {
         return $folders;
     }
     // force the type of folder name variable (#1485527)
     $folders = array_map('strval', $folders);
     $out = array();
     // finally we must put special folders on top and rebuild the list
     // to move their subfolders where they belong...
     $specials = array_unique(array_intersect($specials, $folders));
     $folders = array_merge($specials, array_diff($folders, $specials));
     $this->sort_folder_specials(null, $folders, $specials, $out);
     return $out;
 }
コード例 #24
0
 /**
  * Factory method to import a vcard file
  *
  * @param string vCard file content
  * @return array List of rcube_vcard objects
  */
 public static function import($data)
 {
     $out = array();
     // check if charsets are specified (usually vcard version < 3.0 but this is not reliable)
     if (preg_match('/charset=/i', substr($data, 0, 2048))) {
         $charset = null;
     } else {
         if (($charset = self::detect_encoding($data)) && $charset != RCMAIL_CHARSET) {
             $data = rcube_charset::convert($data, $charset);
             $data = preg_replace(array('/^[\\xFE\\xFF]{2}/', '/^\\xEF\\xBB\\xBF/', '/^\\x00+/'), '', $data);
             // also remove BOM
             $charset = RCMAIL_CHARSET;
         }
     }
     $vcard_block = '';
     $in_vcard_block = false;
     foreach (preg_split("/[\r\n]+/", $data) as $i => $line) {
         if ($in_vcard_block && !empty($line)) {
             $vcard_block .= $line . "\n";
         }
         $line = trim($line);
         if (preg_match('/^END:VCARD$/i', $line)) {
             // parse vcard
             $obj = new rcube_vcard(self::cleanup($vcard_block), $charset, true, self::$fieldmap);
             if (!empty($obj->displayname) || !empty($obj->email)) {
                 $out[] = $obj;
             }
             $in_vcard_block = false;
         } else {
             if (preg_match('/^BEGIN:VCARD$/i', $line)) {
                 $vcard_block = $line . "\n";
                 $in_vcard_block = true;
             }
         }
     }
     return $out;
 }
コード例 #25
0
ファイル: rcube_mime.php プロジェクト: bbspike/sentora-core
 /**
  * Decode a mime-encoded string to internal charset
  *
  * @param string $input    Header value
  * @param string $fallback Fallback charset if none specified
  *
  * @return string Decoded string
  */
 public static function decode_mime_string($input, $fallback = null)
 {
     $default_charset = !empty($fallback) ? $fallback : self::get_charset();
     // rfc: all line breaks or other characters not found
     // in the Base64 Alphabet must be ignored by decoding software
     // delete all blanks between MIME-lines, differently we can
     // receive unnecessary blanks and broken utf-8 symbols
     $input = preg_replace("/\\?=\\s+=\\?/", '?==?', $input);
     // encoded-word regexp
     $re = '/=\\?([^?]+)\\?([BbQq])\\?([^\\n]*?)\\?=/';
     // Find all RFC2047's encoded words
     if (preg_match_all($re, $input, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
         // Initialize variables
         $tmp = array();
         $out = '';
         $start = 0;
         foreach ($matches as $idx => $m) {
             $pos = $m[0][1];
             $charset = $m[1][0];
             $encoding = $m[2][0];
             $text = $m[3][0];
             $length = strlen($m[0][0]);
             // Append everything that is before the text to be decoded
             if ($start != $pos) {
                 $substr = substr($input, $start, $pos - $start);
                 $out .= rcube_charset::convert($substr, $default_charset);
                 $start = $pos;
             }
             $start += $length;
             // Per RFC2047, each string part "MUST represent an integral number
             // of characters . A multi-octet character may not be split across
             // adjacent encoded-words." However, some mailers break this, so we
             // try to handle characters spanned across parts anyway by iterating
             // through and aggregating sequential encoded parts with the same
             // character set and encoding, then perform the decoding on the
             // aggregation as a whole.
             $tmp[] = $text;
             if ($next_match = $matches[$idx + 1]) {
                 if ($next_match[0][1] == $start && $next_match[1][0] == $charset && $next_match[2][0] == $encoding) {
                     continue;
                 }
             }
             $count = count($tmp);
             $text = '';
             // Decode and join encoded-word's chunks
             if ($encoding == 'B' || $encoding == 'b') {
                 // base64 must be decoded a segment at a time
                 for ($i = 0; $i < $count; $i++) {
                     $text .= base64_decode($tmp[$i]);
                 }
             } else {
                 //if ($encoding == 'Q' || $encoding == 'q') {
                 // quoted printable can be combined and processed at once
                 for ($i = 0; $i < $count; $i++) {
                     $text .= $tmp[$i];
                 }
                 $text = str_replace('_', ' ', $text);
                 $text = quoted_printable_decode($text);
             }
             $out .= rcube_charset::convert($text, $charset);
             $tmp = array();
         }
         // add the last part of the input string
         if ($start != strlen($input)) {
             $out .= rcube_charset::convert(substr($input, $start), $default_charset);
         }
         // return the results
         return $out;
     }
     // no encoding information, use fallback
     return rcube_charset::convert($input, $default_charset);
 }
コード例 #26
0
ファイル: rcube_mime.php プロジェクト: CDN-Sparks/owncloud
 /**
  * Recursive method to convert a Mail_mimeDecode part into a rcube_message_part object
  *
  * @param object  A message part struct
  * @param int     Part count
  * @param string  Parent MIME ID
  *
  * @return object rcube_message_part
  */
 private static function structure_part($part, $count = 0, $parent = '')
 {
     $struct = new rcube_message_part();
     $struct->mime_id = $part->mime_id ? $part->mime_id : (empty($parent) ? (string) $count : "{$parent}.{$count}");
     $struct->headers = $part->headers;
     $struct->ctype_primary = $part->ctype_primary;
     $struct->ctype_secondary = $part->ctype_secondary;
     $struct->mimetype = $part->ctype_primary . '/' . $part->ctype_secondary;
     $struct->ctype_parameters = $part->ctype_parameters;
     if ($part->headers['content-transfer-encoding']) {
         $struct->encoding = $part->headers['content-transfer-encoding'];
     }
     if ($part->ctype_parameters['charset']) {
         $struct->charset = $part->ctype_parameters['charset'];
     }
     $part_charset = $struct->charset ? $struct->charset : self::get_charset();
     // determine filename
     if (($filename = $part->d_parameters['filename']) || ($filename = $part->ctype_parameters['name'])) {
         $struct->filename = rcube_mime::decode_mime_string($filename, $part_charset);
     }
     // copy part body and convert it to UTF-8 if necessary
     $struct->body = $part->ctype_primary == 'text' || !$part->ctype_parameters['charset'] ? rcube_charset::convert($part->body, $part_charset) : $part->body;
     $struct->size = strlen($part->body);
     $struct->disposition = $part->disposition;
     foreach ((array) $part->parts as $child_part) {
         $struct->parts[] = self::structure_part($child_part, ++$count, $struct->mime_id);
     }
     return $struct;
 }
コード例 #27
0
ファイル: rcube_imap.php プロジェクト: BIGGANI/zpanelx
 /**
  * Sort folders first by default folders and then in alphabethical order
  *
  * @param array $a_folders    Folders list
  * @param bool  $skip_default Skip default folders handling
  *
  * @return array Sorted list
  */
 public function sort_folder_list($a_folders, $skip_default = false)
 {
     $a_out = $a_defaults = $folders = array();
     $delimiter = $this->get_hierarchy_delimiter();
     // find default folders and skip folders starting with '.'
     foreach ($a_folders as $folder) {
         if ($folder[0] == '.') {
             continue;
         }
         if (!$skip_default && ($p = array_search($folder, $this->default_folders)) !== false && !$a_defaults[$p]) {
             $a_defaults[$p] = $folder;
         } else {
             $folders[$folder] = rcube_charset::convert($folder, 'UTF7-IMAP');
         }
     }
     // sort folders and place defaults on the top
     asort($folders, SORT_LOCALE_STRING);
     ksort($a_defaults);
     $folders = array_merge($a_defaults, array_keys($folders));
     // finally we must rebuild the list to move
     // subfolders of default folders to their place...
     // ...also do this for the rest of folders because
     // asort() is not properly sorting case sensitive names
     while (list($key, $folder) = each($folders)) {
         // set the type of folder name variable (#1485527)
         $a_out[] = (string) $folder;
         unset($folders[$key]);
         $this->rsort($folder, $delimiter, $folders, $a_out);
     }
     return $a_out;
 }
コード例 #28
0
 private function convert_charset($str, $charset = null)
 {
     if (!$charset) {
         return utf8_encode($sig);
     }
     return rcube_charset::convert($str, $charset, RCMAIL_CHARSET);
 }
コード例 #29
0
 /**
  * Parse/validate input value. See self::get_input_value()
  * Performs stripslashes() and charset conversion if necessary
  *
  * @param  string   Input value
  * @param  boolean  Allow HTML tags in field value
  * @param  string   Charset to convert into
  *
  * @return string   Parsed value
  */
 public static function parse_input_value($value, $allow_html = FALSE, $charset = NULL)
 {
     global $OUTPUT;
     if (empty($value)) {
         return $value;
     }
     if (is_array($value)) {
         foreach ($value as $idx => $val) {
             $value[$idx] = self::parse_input_value($val, $allow_html, $charset);
         }
         return $value;
     }
     // strip single quotes if magic_quotes_sybase is enabled
     if (ini_get('magic_quotes_sybase')) {
         $value = str_replace("''", "'", $value);
     } else {
         if (get_magic_quotes_gpc() || get_magic_quotes_runtime()) {
             $value = stripslashes($value);
         }
     }
     // remove HTML tags if not allowed
     if (!$allow_html) {
         $value = strip_tags($value);
     }
     $output_charset = is_object($OUTPUT) ? $OUTPUT->get_charset() : null;
     // remove invalid characters (#1488124)
     if ($output_charset == 'UTF-8') {
         $value = rcube_charset::clean($value);
     }
     // convert to internal charset
     if ($charset && $output_charset) {
         $value = rcube_charset::convert($value, $output_charset, $charset);
     }
     return $value;
 }
コード例 #30
0
ファイル: ldap.php プロジェクト: 62BRAINS/EPESI
 /**
  * Code originaly from the phpLDAPadmin development team
  * http://phpldapadmin.sourceforge.net/
  *
  * Hashes a password and returns the hash based on the specified enc_type
  */
 static function hash_password($password_clear, $encodage_type)
 {
     $encodage_type = strtolower($encodage_type);
     switch ($encodage_type) {
         case 'crypt':
             $crypted_password = '******' . crypt($password_clear, self::random_salt(2));
             break;
         case 'ext_des':
             /* Extended DES crypt. see OpenBSD crypt man page */
             if (!defined('CRYPT_EXT_DES') || CRYPT_EXT_DES == 0) {
                 /* Your system crypt library does not support extended DES encryption */
                 return false;
             }
             $crypted_password = '******' . crypt($password_clear, '_' . self::random_salt(8));
             break;
         case 'md5crypt':
             if (!defined('CRYPT_MD5') || CRYPT_MD5 == 0) {
                 /* Your system crypt library does not support md5crypt encryption */
                 return false;
             }
             $crypted_password = '******' . crypt($password_clear, '$1$' . self::random_salt(9));
             break;
         case 'blowfish':
             if (!defined('CRYPT_BLOWFISH') || CRYPT_BLOWFISH == 0) {
                 /* Your system crypt library does not support blowfish encryption */
                 return false;
             }
             /* Hardcoded to second blowfish version and set number of rounds */
             $crypted_password = '******' . crypt($password_clear, '$2a$12$' . self::random_salt(13));
             break;
         case 'md5':
             $crypted_password = '******' . base64_encode(pack('H*', md5($password_clear)));
             break;
         case 'sha':
             if (function_exists('sha1')) {
                 /* Use PHP 4.3.0+ sha1 function, if it is available */
                 $crypted_password = '******' . base64_encode(pack('H*', sha1($password_clear)));
             } else {
                 if (function_exists('hash')) {
                     $crypted_password = '******' . base64_encode(hash('sha1', $password_clear, true));
                 } else {
                     if (function_exists('mhash')) {
                         $crypted_password = '******' . base64_encode(mhash(MHASH_SHA1, $password_clear));
                     } else {
                         /* Your PHP install does not have the mhash()/hash() nor sha1() function */
                         return false;
                     }
                 }
             }
             break;
         case 'ssha':
             mt_srand((double) microtime() * 1000000);
             $salt = substr(pack('h*', md5(mt_rand())), 0, 8);
             if (function_exists('mhash') && function_exists('mhash_keygen_s2k')) {
                 $salt = mhash_keygen_s2k(MHASH_SHA1, $password_clear, $salt, 4);
                 $password = mhash(MHASH_MD5, $password_clear . $salt);
             } else {
                 if (function_exists('sha1')) {
                     $salt = substr(pack("H*", sha1($salt . $password_clear)), 0, 4);
                     $password = sha1($password_clear . $salt, true);
                 } else {
                     if (function_exists('hash')) {
                         $salt = substr(pack("H*", hash('sha1', $salt . $password_clear)), 0, 4);
                         $password = hash('sha1', $password_clear . $salt, true);
                     }
                 }
             }
             if ($password) {
                 $crypted_password = '******' . base64_encode($password . $salt);
             } else {
                 /* Your PHP install does not have the mhash()/hash() nor sha1() function */
                 return false;
             }
             break;
         case 'smd5':
             mt_srand((double) microtime() * 1000000);
             $salt = substr(pack('h*', md5(mt_rand())), 0, 8);
             if (function_exists('mhash') && function_exists('mhash_keygen_s2k')) {
                 $salt = mhash_keygen_s2k(MHASH_MD5, $password_clear, $salt, 4);
                 $password = mhash(MHASH_MD5, $password_clear . $salt);
             } else {
                 if (function_exists('hash')) {
                     $salt = substr(pack("H*", hash('md5', $salt . $password_clear)), 0, 4);
                     $password = hash('md5', $password_clear . $salt, true);
                 } else {
                     $salt = substr(pack("H*", md5($salt . $password_clear)), 0, 4);
                     $password = md5($password_clear . $salt, true);
                 }
             }
             $crypted_password = '******' . base64_encode($password . $salt);
             break;
         case 'samba':
             if (function_exists('hash')) {
                 $crypted_password = hash('md4', rcube_charset::convert($password_clear, RCUBE_CHARSET, 'UTF-16LE'));
                 $crypted_password = strtoupper($crypted_password);
             } else {
                 /* Your PHP install does not have the hash() function */
                 return false;
             }
             break;
         case 'ad':
             $crypted_password = rcube_charset::convert('"' . $password_clear . '"', RCUBE_CHARSET, 'UTF-16LE');
             break;
         case 'clear':
         default:
             $crypted_password = $password_clear;
     }
     return $crypted_password;
 }