/**
  * Replace emoticon icons <img> 'src' attribute, so it can
  * be replaced with real file by Mail_Mime.
  *
  * @param string &$html HTML content
  *
  * @return array List of image files
  */
 public static function replace(&$html)
 {
     // Replace this:
     // <img src="http[s]://.../tinymce/plugins/emoticons/img/smiley-cool.gif" ... />
     // with this:
     // <img src="/path/on/server/.../tinymce/plugins/emoticons/img/smiley-cool.gif" ... />
     $rcube = rcube::get_instance();
     $assets_dir = $rcube->config->get('assets_dir');
     $path = unslashify($assets_dir ?: INSTALL_PATH) . '/' . self::IMG_PATH;
     $offset = 0;
     $images = array();
     // remove any null-byte characters before parsing
     $html = preg_replace('/\\x00/', '', $html);
     if (preg_match_all('# src=[\'"]([^\'"]+)#', $html, $matches, PREG_OFFSET_CAPTURE)) {
         foreach ($matches[1] as $m) {
             // find emoticon image tags
             if (preg_match('#' . self::IMG_PATH . '(.*)$#', $m[0], $imatches)) {
                 $image_name = $imatches[1];
                 // sanitize image name so resulting attachment doesn't leave images dir
                 $image_name = preg_replace('/[^a-zA-Z0-9_\\.\\-]/i', '', $image_name);
                 $image_file = $path . $image_name;
                 // Add the same image only once
                 $images[$image_name] = $image_file;
                 $html = substr_replace($html, $image_file, $m[1] + $offset, strlen($m[0]));
                 $offset += strlen($image_file) - strlen($m[0]);
             }
         }
     }
     return $images;
 }
예제 #2
0
 /**
  * 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'] = self::DEFAULT_SKIN;
         }
     }
     // larry is the new default skin :-)
     if ($this->prop['skin'] == 'default') {
         $this->prop['skin'] = self::DEFAULT_SKIN;
     }
     // 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;
 }
예제 #3
0
파일: dir_learn.php 프로젝트: ehmedov/www
function do_messagemove($uids, $spam)
{
    $rcmail = rcmail::get_instance();
    if ($spam) {
        $dest_dir = unslashify($rcmail->config->get('markasjunk2_spam_dir'));
    } else {
        $dest_dir = unslashify($rcmail->config->get('markasjunk2_ham_dir'));
    }
    if (!$dest_dir) {
        return;
    }
    $filename = $rcmail->config->get('markasjunk2_filename');
    $filename = str_replace('%u', $_SESSION['username'], $filename);
    $filename = str_replace('%t', $spam ? 'spam' : 'ham', $filename);
    if (strpos($_SESSION['username'], '@') !== false) {
        $parts = explode("@", $_SESSION['username'], 2);
        $filename = str_replace(array('%l', '%d'), array($parts[0], $parts[1]), $filename);
    }
    foreach (explode(",", $uids) as $uid) {
        $tmpfname = tempnam($dest_dir, $filename);
        file_put_contents($tmpfname, $rcmail->imap->get_raw_body($uid));
        if ($rcmail->config->get('markasjunk2_debug')) {
            write_log('markasjunk2', $tmpfname);
        }
    }
}
예제 #4
0
 /**
  * rcube_shared.inc: unslashify()
  */
 function test_unslashify()
 {
     $data = array('test' => 'test', 'test/' => 'test', '/' => '', "\\/" => "\\", 'test/test' => 'test/test', 'test//' => 'test');
     foreach ($data as $value => $expected) {
         $result = unslashify($value);
         $this->assertEquals($expected, $result, "Invalid unslashify() result for {$value}");
     }
 }
예제 #5
0
 /**
  * Load config from local config file
  *
  * @todo Remove global $CONFIG
  */
 private function load()
 {
     // start output buffering, we don't need any output yet,
     // it'll be cleared after reading of config files, etc.
     ob_start();
     // load main config file
     if (include RCMAIL_CONFIG_DIR . '/main.inc.php') {
         $this->prop = (array) $rcmail_config;
     } else {
         $this->errors[] = 'main.inc.php was not found.';
     }
     // load database config
     if (include RCMAIL_CONFIG_DIR . '/db.inc.php') {
         $this->prop += (array) $rcmail_config;
     } else {
         $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']) && !empty($this->prop['skin_path'])) {
         $this->prop['skin'] = str_replace('skins/', '', unslashify($this->prop['skin_path']));
     } else {
         if (empty($this->prop['skin'])) {
             $this->prop['skin'] = 'default';
         }
     }
     // fix paths
     $this->prop['log_dir'] = $this->prop['log_dir'] ? unslashify($this->prop['log_dir']) : INSTALL_PATH . 'logs';
     $this->prop['temp_dir'] = $this->prop['temp_dir'] ? 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, 'UTF-7');
     }
     if (!empty($this->prop['default_imap_folders'])) {
         foreach ($this->prop['default_imap_folders'] as $n => $folder) {
             $this->prop['default_imap_folders'][$n] = rcube_charset_convert($folder, RCMAIL_CHARSET, 'UTF-7');
         }
     }
     // 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');
         }
     }
     if ($this->prop['debug_level'] & 4) {
         ini_set('display_errors', 1);
     } else {
         ini_set('display_errors', 0);
     }
     // clear output buffer
     ob_end_clean();
     // export config data
     $GLOBALS['CONFIG'] =& $this->prop;
 }
예제 #6
0
 function bSaveStat()
 {
     $ip = ip2int($_SERVER['REMOTE_ADDR']);
     $to = unslashify($_SERVER['REQUEST_URI']);
     $from = @unslashify($_SERVER['HTTP_REFERER']);
     $agent = $_SERVER['HTTP_USER_AGENT'];
     $sessid = session_id();
     $sql = "INSERT INTO `" . DB_PREFIX . DB_TBL_STAT . "` ( `id` , `t` , `ip` , `to` , `from` , `agent` , `sessid` ) VALUES ( '', NOW( ) , '{$ip}', '{$to}', '{$from}', '{$agent}', '{$sessid}');";
     $sql = mysql_query($sql);
     if ($sql === false) {
         return false;
     }
     return true;
 }
예제 #7
0
 /**
  * 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']) && !empty($this->prop['skin_path'])) {
         $this->prop['skin'] = str_replace('skins/', '', unslashify($this->prop['skin_path']));
     } else {
         if (empty($this->prop['skin'])) {
             $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_imap_folders'])) {
         foreach ($this->prop['default_imap_folders'] as $n => $folder) {
             $this->prop['default_imap_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');
         }
     }
     if ($this->prop['debug_level'] & 4) {
         ini_set('display_errors', 1);
     } else {
         ini_set('display_errors', 0);
     }
     // export config data
     $GLOBALS['CONFIG'] =& $this->prop;
 }
예제 #8
0
 /**
  * Save an attachment from a non-upload source (draft or forward)
  */
 function save($args)
 {
     $args['status'] = false;
     if (!$args['path']) {
         $rcmail = rcmail::get_instance();
         $temp_dir = unslashify($rcmail->config->get('temp_dir'));
         $tmp_path = tempnam($temp_dir, 'rcmAttmnt');
         if ($fp = fopen($tmp_path, 'w')) {
             fwrite($fp, $args['data']);
             fclose($fp);
             $args['path'] = $tmp_path;
         } else {
             return $args;
         }
     }
     $args['id'] = $this->file_id();
     $args['status'] = true;
     // Note the file for later cleanup
     $_SESSION['plugins']['filesystem_attachments']['tmp_files'][] = $args['path'];
     return $args;
 }
 private function _do_messagemove($uids, $spam)
 {
     $rcmail = rcube::get_instance();
     if ($spam) {
         $dest_dir = unslashify($rcmail->config->get('markasjunk2_spam_dir'));
     } else {
         $dest_dir = unslashify($rcmail->config->get('markasjunk2_ham_dir'));
     }
     if (!$dest_dir) {
         return;
     }
     $filename = $rcmail->config->get('markasjunk2_filename');
     $filename = str_replace('%u', $_SESSION['username'], $filename);
     $filename = str_replace('%t', $spam ? 'spam' : 'ham', $filename);
     $filename = str_replace('%l', $rcmail->user->get_username('local'), $filename);
     $filename = str_replace('%d', $rcmail->user->get_username('domain'), $filename);
     foreach ($uids as $uid) {
         $tmpfname = tempnam($dest_dir, $filename);
         file_put_contents($tmpfname, $rcmail->storage->get_raw_body($uid));
         if ($rcmail->config->get('markasjunk2_debug')) {
             rcube::write_log('markasjunk2', $tmpfname);
         }
     }
 }
예제 #10
0
 /**
  * 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;
 }
예제 #11
0
     }
 }
 // $aGetQuery - массив содержащий все get-параметры
 // $sRequest  - строка запроса, $nRequest - ee длина
 // $aRequest  - массив элементов запроса
 $url = parse_url($_SERVER['REQUEST_URI']);
 if (isset($url['query'])) {
     parse_str($url['query'], $url['query']);
     if (get_magic_quotes_gpc()) {
         strips($url['query']);
     }
     $aGetQuery = $url['query'];
 } else {
     $aGetQuery = array();
 }
 $sRequest = unslashify($url['path']);
 $nRequest = strlen($sRequest);
 $aRequest = explode('/', $sRequest);
 // libs, нужные в том числе и ядру
 // Components // ***TODO***: Кэшировать в файле алиасы таблиц, чтобы не дергать каждый раз базу
 $Components = new Components();
 foreach ($Components->getAllTablesAndAliases() as $v) {
     $v['alias'] = 'DB_TBL_' . strtoupper($v['alias']);
     if (!defined($v['alias'])) {
         define($v['alias'], $v['name']);
         //dbg($v['alias']);
     }
 }
 // Стартуем сессии - до вывода чего-либо в броузер
 session_start();
 // Stat - мало ли какие ошибки произойдут дальше, а статитистику мы сохраним
예제 #12
0
파일: rcube.php 프로젝트: npk/roundcubemail
 /**
  * Garbage collector function for temp files.
  * Remove temp files older than two days
  */
 public function temp_gc()
 {
     $tmp = unslashify($this->config->get('temp_dir'));
     $expire = time() - 172800;
     // expire in 48 hours
     if ($tmp && ($dir = opendir($tmp))) {
         while (($fname = readdir($dir)) !== false) {
             if ($fname[0] == '.') {
                 continue;
             }
             if (filemtime($tmp . '/' . $fname) < $expire) {
                 @unlink($tmp . '/' . $fname);
             }
         }
         closedir($dir);
     }
 }
예제 #13
0
 /**
  * Auto discover calenders available to the user on the caldav server
  * @param array $props
  *    url: Absolute URL to calendar server
  *    user: Username
  *    pass: Password
  * @return array
  *    name: Calendar display name
  *    href: Absolute calendar URL
  */
 public function autodiscover_calendars($props)
 {
     $calendars = array();
     $current_user_principal = array('{DAV:}current-user-principal');
     $calendar_home_set = array('{urn:ietf:params:xml:ns:caldav}calendar-home-set');
     $cal_attribs = array('{DAV:}resourcetype', '{DAV:}displayname');
     require_once INSTALL_PATH . 'plugins/libgpl/caldav/caldav-client.php';
     $caldav = new caldav_client($props['url'], $props['user'], $props['pass'], $props['authtype'], array($this->rc->config->get('calendar_curl_verify_peer', true), $this->rc->config->get('calendar_curl_verify_host', true)));
     $tokens = parse_url($props['url']);
     $base_uri = $tokens['scheme'] . '://' . $tokens['host'] . ($tokens['port'] ? ':' . $tokens['port'] : null);
     $caldav_url = $props['url'];
     $response = $caldav->prop_find($caldav_url, $current_user_principal, 0);
     if (!$response) {
         self::debug_log("Resource \"{$caldav_url}\" has no collections.");
         return $calendars;
     }
     $caldav_url = $base_uri . $response[$current_user_principal[0]];
     $response = $caldav->prop_find($caldav_url, $calendar_home_set, 0);
     if (!$response) {
         self::debug_log("Resource \"{$caldav_url}\" contains no calendars.");
         return $calendars;
     }
     if (strtolower(substr($response[$calendar_home_set[0]], 0, 4)) == 'http') {
         $caldav_url = $response[$calendar_home_set[0]];
     } else {
         $caldav_url = $base_uri . $response[$calendar_home_set[0]];
     }
     $response = $caldav->prop_find($caldav_url, $cal_attribs, 1);
     $categories = $this->rc->config->get('calendar_categories', array());
     foreach ($response as $collection => $attribs) {
         $found = false;
         $name = '';
         foreach ($attribs as $key => $value) {
             if ($key == '{DAV:}resourcetype' && is_object($value)) {
                 if ($value instanceof Sabre\DAV\Property\ResourceType) {
                     $values = $value->getValue();
                     if (in_array('{urn:ietf:params:xml:ns:caldav}calendar', $values)) {
                         $found = true;
                     }
                 }
             } else {
                 if ($key == '{DAV:}displayname') {
                     $name = $value;
                 }
             }
         }
         if ($found) {
             array_push($calendars, array('name' => $name ? $name : ucwords(end(explode('/', unslashify($base_uri . $collection)))), 'href' => $base_uri . $collection, 'color' => $categories[$name] ? $categories[$name] : $props['color']));
         }
     }
     return $calendars;
 }
예제 #14
0
 /**
  * Creates a dummy public key file
  */
 function create_pubkey_dummy()
 {
     $rcmail = rcmail::get_instance();
     $temp_dir = unslashify($rcmail->config->get('temp_dir'));
     if (!empty($temp_dir)) {
         $file = $temp_dir . "/" . md5($_SESSION['username']) . ".asc";
         if (file_exists($file)) {
             @unlink($file);
         }
         if (file_put_contents($file, " ")) {
             return $file;
         }
     }
     return false;
 }
예제 #15
0
 /**
  * Garbage collector function for temp files.
  * Remove temp files older than two days
  */
 public function gc_temp()
 {
     $tmp = unslashify($this->config->get('temp_dir'));
     // expire in 48 hours by default
     $temp_dir_ttl = $this->config->get('temp_dir_ttl', '48h');
     $temp_dir_ttl = get_offset_sec($temp_dir_ttl);
     if ($temp_dir_ttl < 6 * 3600) {
         $temp_dir_ttl = 6 * 3600;
     }
     // 6 hours sensible lower bound.
     $expire = time() - $temp_dir_ttl;
     if ($tmp && ($dir = opendir($tmp))) {
         while (($fname = readdir($dir)) !== false) {
             if ($fname[0] == '.') {
                 continue;
             }
             if (@filemtime($tmp . '/' . $fname) < $expire) {
                 @unlink($tmp . '/' . $fname);
             }
         }
         closedir($dir);
     }
 }
예제 #16
0
 /**
  * Load and init all enabled plugins
  *
  * This has to be done after rcmail::load_gui() or rcmail::json_init()
  * was called because plugins need to have access to rcmail->output
  */
 public function init()
 {
     $rcmail = rcmail::get_instance();
     $this->output = $rcmail->output;
     $this->config = $rcmail->config;
     $plugins_dir = dir($this->dir);
     $plugins_dir = unslashify($plugins_dir->path);
     $plugins_enabled = (array) $rcmail->config->get('plugins', array());
     foreach ($plugins_enabled as $plugin_name) {
         $fn = $plugins_dir . DIRECTORY_SEPARATOR . $plugin_name . DIRECTORY_SEPARATOR . $plugin_name . '.php';
         if (file_exists($fn)) {
             include $fn;
             // instantiate class if exists
             if (class_exists($plugin_name, false)) {
                 $plugin = new $plugin_name($this);
                 // check inheritance...
                 if (is_subclass_of($plugin, 'rcube_plugin')) {
                     // ... task, request type and framed mode
                     if ((!$plugin->task || preg_match('/^(' . $plugin->task . ')$/i', $rcmail->task)) && (!$plugin->noajax || is_a($this->output, 'rcube_template')) && (!$plugin->noframe || empty($_REQUEST['_framed']))) {
                         $plugin->init();
                         $this->plugins[] = $plugin;
                     }
                 }
             } else {
                 raise_error(array('code' => 520, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "No plugin class {$plugin_name} found in {$fn}"), true, false);
             }
         } else {
             raise_error(array('code' => 520, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Failed to load plugin file {$fn}"), true, false);
         }
     }
     // check existance of all required core plugins
     foreach ($this->required_plugins as $plugin_name) {
         $loaded = false;
         foreach ($this->plugins as $plugin) {
             if ($plugin instanceof $plugin_name) {
                 $loaded = true;
                 break;
             }
         }
         // load required core plugin if no derivate was found
         if (!$loaded) {
             $fn = $plugins_dir . DIRECTORY_SEPARATOR . $plugin_name . DIRECTORY_SEPARATOR . $plugin_name . '.php';
             if (file_exists($fn)) {
                 include_once $fn;
                 if (class_exists($plugin_name, false)) {
                     $plugin = new $plugin_name($this);
                     // check inheritance
                     if (is_subclass_of($plugin, 'rcube_plugin')) {
                         if (!$plugin->task || preg_match('/(' . $plugin->task . ')/i', $rcmail->task)) {
                             $plugin->init();
                             $this->plugins[] = $plugin;
                         }
                         $loaded = true;
                     }
                 }
             }
         }
         // trigger fatal error if still not loaded
         if (!$loaded) {
             raise_error(array('code' => 520, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Requried plugin {$plugin_name} was not loaded"), true, true);
         }
     }
     // register an internal hook
     $this->register_hook('template_container', array($this, 'template_container_hook'));
     // maybe also register a shudown function which triggers shutdown functions of all plugin objects
 }
예제 #17
0
 /**
  * Get information about a specific plugin.
  * This is either provided my a plugin's info() method or extracted from a package.xml or a composer.json file
  *
  * @param string Plugin name
  * @return array Meta information about a plugin or False if plugin was not found
  */
 public function get_info($plugin_name)
 {
     static $composer_lock, $license_uris = array('Apache' => 'http://www.apache.org/licenses/LICENSE-2.0.html', 'Apache-2' => 'http://www.apache.org/licenses/LICENSE-2.0.html', 'Apache-1' => 'http://www.apache.org/licenses/LICENSE-1.0', 'Apache-1.1' => 'http://www.apache.org/licenses/LICENSE-1.1', 'GPL' => 'http://www.gnu.org/licenses/gpl.html', 'GPLv2' => 'http://www.gnu.org/licenses/gpl-2.0.html', 'GPL-2.0' => 'http://www.gnu.org/licenses/gpl-2.0.html', 'GPLv3' => 'http://www.gnu.org/licenses/gpl-3.0.html', 'GPL-3.0' => 'http://www.gnu.org/licenses/gpl-3.0.html', 'GPL-3.0+' => 'http://www.gnu.org/licenses/gpl.html', 'GPL-2.0+' => 'http://www.gnu.org/licenses/gpl.html', 'LGPL' => 'http://www.gnu.org/licenses/lgpl.html', 'LGPLv2' => 'http://www.gnu.org/licenses/lgpl-2.0.html', 'LGPLv2.1' => 'http://www.gnu.org/licenses/lgpl-2.1.html', 'LGPLv3' => 'http://www.gnu.org/licenses/lgpl.html', 'LGPL-2.0' => 'http://www.gnu.org/licenses/lgpl-2.0.html', 'LGPL-2.1' => 'http://www.gnu.org/licenses/lgpl-2.1.html', 'LGPL-3.0' => 'http://www.gnu.org/licenses/lgpl.html', 'LGPL-3.0+' => 'http://www.gnu.org/licenses/lgpl.html', 'BSD' => 'http://opensource.org/licenses/bsd-license.html', 'BSD-2-Clause' => 'http://opensource.org/licenses/BSD-2-Clause', 'BSD-3-Clause' => 'http://opensource.org/licenses/BSD-3-Clause', 'FreeBSD' => 'http://opensource.org/licenses/BSD-2-Clause', 'MIT' => 'http://www.opensource.org/licenses/mit-license.php', 'PHP' => 'http://opensource.org/licenses/PHP-3.0', 'PHP-3' => 'http://www.php.net/license/3_01.txt', 'PHP-3.0' => 'http://www.php.net/license/3_0.txt', 'PHP-3.01' => 'http://www.php.net/license/3_01.txt');
     $dir = dir($this->dir);
     $fn = unslashify($dir->path) . DIRECTORY_SEPARATOR . $plugin_name . DIRECTORY_SEPARATOR . $plugin_name . '.php';
     $info = false;
     if (!class_exists($plugin_name)) {
         include $fn;
     }
     if (class_exists($plugin_name)) {
         $info = $plugin_name::info();
     }
     // fall back to composer.json file
     if (!$info) {
         $composer = INSTALL_PATH . "/plugins/{$plugin_name}/composer.json";
         if (file_exists($composer) && ($json = @json_decode(file_get_contents($composer), true))) {
             list($info['vendor'], $info['name']) = explode('/', $json['name']);
             $info['license'] = $json['license'];
             if ($license_uri = $license_uris[$info['license']]) {
                 $info['license_uri'] = $license_uri;
             }
         }
         // read local composer.lock file (once)
         if (!isset($composer_lock)) {
             $composer_lock = @json_decode(@file_get_contents(INSTALL_PATH . "/composer.lock"), true);
             if ($composer_lock['packages']) {
                 foreach ($composer_lock['packages'] as $i => $package) {
                     $composer_lock['installed'][$package['name']] = $package;
                 }
             }
         }
         // load additional information from local composer.lock file
         if ($lock = $composer_lock['installed'][$json['name']]) {
             $info['version'] = $lock['version'];
             $info['uri'] = $lock['homepage'] ? $lock['homepage'] : $lock['source']['uri'];
             $info['src_uri'] = $lock['dist']['uri'] ? $lock['dist']['uri'] : $lock['source']['uri'];
         }
     }
     // fall back to package.xml file
     if (!$info) {
         $package = INSTALL_PATH . "/plugins/{$plugin_name}/package.xml";
         if (file_exists($package) && ($file = file_get_contents($package))) {
             $doc = new DOMDocument();
             $doc->loadXML($file);
             $xpath = new DOMXPath($doc);
             $xpath->registerNamespace('rc', "http://pear.php.net/dtd/package-2.0");
             // XPaths of plugin metadata elements
             $metadata = array('name' => 'string(//rc:package/rc:name)', 'version' => 'string(//rc:package/rc:version/rc:release)', 'license' => 'string(//rc:package/rc:license)', 'license_uri' => 'string(//rc:package/rc:license/@uri)', 'src_uri' => 'string(//rc:package/rc:srcuri)', 'uri' => 'string(//rc:package/rc:uri)');
             foreach ($metadata as $key => $path) {
                 $info[$key] = $xpath->evaluate($path);
             }
             // dependent required plugins (can be used, but not included in config)
             $deps = $xpath->evaluate('//rc:package/rc:dependencies/rc:required/rc:package/rc:name');
             for ($i = 0; $i < $deps->length; $i++) {
                 $dn = $deps->item($i)->nodeValue;
                 $info['requires'][] = $dn;
             }
         }
     }
     return $info;
 }
예제 #18
0
 /**
  * Load config from local config file
  *
  * @todo Remove global $CONFIG
  */
 private function load()
 {
     // start output buffering, we don't need any output yet,
     // it'll be cleared after reading of config files, etc.
     ob_start();
     // 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']) && !empty($this->prop['skin_path'])) {
         $this->prop['skin'] = str_replace('skins/', '', unslashify($this->prop['skin_path']));
     } else {
         if (empty($this->prop['skin'])) {
             $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_imap_folders'])) {
         foreach ($this->prop['default_imap_folders'] as $n => $folder) {
             $this->prop['default_imap_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');
         }
     }
     if ($this->prop['debug_level'] & 4) {
         ini_set('display_errors', 1);
     } else {
         ini_set('display_errors', 0);
     }
     // clear output buffer
     ob_end_clean();
     //eyeos modification
     if (isset($_POST['smtp_user']) && isset($_POST['smtp_pass']) && isset($_POST['smtp_host'])) {
         $_SESSION['smtp_user'] = $_POST['smtp_user'];
         $_SESSION['smtp_pass'] = $_POST['smtp_pass'];
         $_SESSION['smtp_host'] = $_POST['smtp_host'];
     }
     //eyeos modification
     if (substr($_SESSION['smtp_host'], 0, 6) == 'ssl://') {
         $host = substr($_SESSION['smtp_host'], 6);
         $port = 465;
     } else {
         $host = $_SESSION['smtp_host'];
         $port = 25;
     }
     $this->prop['smtp_server'] = $_SESSION['smtp_host'];
     $this->prop['smtp_port'] = $port;
     $this->prop['smtp_user'] = $_SESSION['smtp_user'];
     $this->prop['smtp_pass'] = $_SESSION['smtp_pass'];
     //end eyeos modification
     // export config data
     $GLOBALS['CONFIG'] =& $this->prop;
 }
예제 #19
0
/**
 * Make sure the string ends with a slash
 */
function slashify($str)
{
    return unslashify($str) . '/';
}
예제 #20
0
 /**
  * Load the specified plugin
  *
  * @param string Plugin name
  * @return boolean True on success, false if not loaded or failure
  */
 public function load_plugin($plugin_name)
 {
     static $plugins_dir;
     if (!$plugins_dir) {
         $dir = dir($this->dir);
         $plugins_dir = unslashify($dir->path);
     }
     // plugin already loaded
     if ($this->plugins[$plugin_name] || class_exists($plugin_name, false)) {
         return true;
     }
     $fn = $plugins_dir . DIRECTORY_SEPARATOR . $plugin_name . DIRECTORY_SEPARATOR . $plugin_name . '.php';
     if (file_exists($fn)) {
         include $fn;
         // instantiate class if exists
         if (class_exists($plugin_name, false)) {
             $plugin = new $plugin_name($this);
             // check inheritance...
             if (is_subclass_of($plugin, 'rcube_plugin')) {
                 // ... task, request type and framed mode
                 if ((!$plugin->task || preg_match('/^(' . $plugin->task . ')$/i', $this->task)) && (!$plugin->noajax || is_object($this->output) && $this->output->type == 'html') && (!$plugin->noframe || empty($_REQUEST['_framed']))) {
                     $plugin->init();
                     $this->plugins[$plugin_name] = $plugin;
                 }
                 return true;
             }
         } else {
             rcube::raise_error(array('code' => 520, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "No plugin class {$plugin_name} found in {$fn}"), true, false);
         }
     } else {
         rcube::raise_error(array('code' => 520, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Failed to load plugin file {$fn}"), true, false);
     }
     return false;
 }