public function __construct($username, $password, $host, $port, $usetls, $ruleset, $dir, $elsif = true) { $this->sieve = new Net_Sieve(); if (PEAR::isError($this->sieve->connect($host, $port, NULL, $usetls))) { return $this->_set_error(SIEVE_ERROR_CONNECTION); } if (PEAR::isError($this->sieve->login($username, $password))) { return $this->_set_error(SIEVE_ERROR_LOGIN); } $this->ruleset = $ruleset; $this->elsif = $elsif; if ($this->ruleset !== false) { $this->get_script(); } else { $this->ruleset = $this->get_active(); $this->get_script(); } // init importers $dir = slashify(realpath(slashify($dir) . 'importFilters/')); $handle = opendir($dir); while ($importer = readdir($handle)) { if ($importer == '.' || $importer == '..') { continue; } include $dir . $importer; $importer = substr($importer, 0, -4); $importer = 'srimport_' . $importer; if (class_exists($importer, false)) { $importerClass = new $importer(); $this->importers[$importer] = $importerClass; } } closedir($handle); }
private function read_squirrel_prefs($uname) { $this->load_config(); $rcmail = rcmail::get_instance(); if ($srcdir = $rcmail->config->get('squirrelmail_data_dir')) { $prefsfile = slashify($srcdir) . $uname . '.pref'; $abookfile = slashify($srcdir) . $uname . '.abook'; $sigfile = slashify($srcdir) . $uname . '.sig'; 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)); } // 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; } } } } } }
/** * rcube_shared.inc: slashify() */ function test_slashify() { $data = array('test' => 'test/', 'test/' => 'test/', '' => '/', "\\" => "\\/"); foreach ($data as $value => $expected) { $result = slashify($value); $this->assertEquals($expected, $result, "Invalid slashify() result for {$value}"); } }
public function __construct($username, $password, $host, $port, $auth_type = NULL, $usetls, $ruleset, $dir, $elsif = true, $auth_cid = NULL, $auth_pw = NULL, $socket_options = array()) { $this->sieve = new Net_Sieve(); $data = rcube::get_instance()->plugins->exec_hook('sieverules_connect', array('username' => $username, 'password' => $password, 'host' => $host, 'port' => $port, 'auth_type' => $auth_type, 'usetls' => $usetls, 'ruleset' => $ruleset, 'dir' => $dir, 'elsif' => $elsif, 'auth_cid' => $auth_cid, 'auth_pw' => $auth_pw, 'socket_options' => $options)); $username = $data['username']; $password = $data['password']; $host = $data['host']; $port = $data['port']; $auth_type = $data['auth_type']; $usetls = $data['usetls']; $ruleset = $data['ruleset']; $dir = $data['dir']; $elsif = $data['elsif']; $auth_cid = $data['auth_cid']; $auth_pw = $data['auth_pw']; $socket_options = $data['socket_options']; if (PEAR::isError($this->sieve->connect($host, $port, $socket_options, $usetls))) { return $this->_set_error(SIEVE_ERROR_CONNECTION); } if (!empty($auth_cid)) { $authz = $username; $username = $auth_cid; $password = $auth_pw; } if (PEAR::isError($this->sieve->login($username, $password, $auth_type ? strtoupper($auth_type) : NULL, $authz))) { return $this->_set_error(SIEVE_ERROR_LOGIN); } $this->ruleset = $ruleset; $this->elsif = $elsif; if ($this->ruleset !== false) { $this->get_script(); } else { $this->ruleset = $this->get_active(); $this->get_script(); } // init importers if ($dir = realpath(slashify($dir) . 'importFilters/')) { $dir = slashify($dir); $handle = opendir($dir); while ($importer = readdir($handle)) { if (preg_match('/\\.php$/', $importer) && is_file($dir . $importer) && is_readable($dir . $importer)) { include $dir . $importer; $importer = substr($importer, 0, -4); $importer = 'srimport_' . $importer; if (class_exists($importer, false)) { $importerClass = new $importer(); $this->importers[$importer] = $importerClass; } } } closedir($handle); } }
$sql = mysql_query($sql); if (false == $sql) { my_die(); } $aPhotos = array(); while ($row = mysql_fetch_assoc($sql)) { $aPhotos[] = $row; } //dbg($aPhotos); if (empty($aPhotos)) { $tplAlbum->assign('ThumbNail', 'В этом альбоме нет изображений'); } foreach ($aPhotos as $v) { $tplThumbNail = $tplAlbum->fetchBlock('ThumbNail'); $tplThumbNail->assign('link', slashify($sRequest) . $v['file']); $tplThumbNail->assign('img', slashify(ADDR_PHOTOS_THUMBNAILS) . $v['file']); $tplAlbum->assign('ThumbNail', $tplThumbNail); $tplThumbNail->reset(); } $tpl->assign('content', $tplAlbum); $tplAlbum->reset(); $_t->assign('ContentBlock', $tpl); $tpl->reset(); } else { $sql = "SELECT * FROM `" . DB_PREFIX . DB_TBL_IMAGES . "` \n\t\t\tWHERE `file` = '" . $aRequest[count($aRequest) - 1] . "'"; $sql = mysql_query($sql); if (false == $sql) { my_die(); } $aP = array(); while ($row = mysql_fetch_assoc($sql)) {
} $sql = "SELECT * FROM `" . DB_PREFIX . DB_TBL_COMMENTS . "` ORDER BY `t` DESC LIMIT " . $nStart . "," . POST_PER_PAGE; $sql = mysql_query($sql); if (false == $sql) { my_die(); } $aList = array(); while ($row = mysql_fetch_assoc($sql)) { $aList[] = $row; } //dbg($aList); if (empty($aList)) { $tpl->assign('Comment', 'Нет комментариев'); } foreach ($aList as $v) { $v['url'] = slashify($v['url']); $sql = "SELECT * FROM. `" . DB_PREFIX . DB_TBL_USERS . "` WHERE `id`=" . $v['user_id']; $sql = mysql_query($sql); if (false == $sql) { my_die(); } $aUser = array(); while ($row = mysql_fetch_assoc($sql)) { $aUser = $row; } // dbg($aUser); $v = array_merge($aUser, $v); // dbg($v); $tplComment = $tpl->fetchBlock('Comment'); $tplComment->assign($v); $tpl->assign('Comment', $tplComment);
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 }
/** * Private constructor */ private function __construct() { $this->dir = slashify(RCMAIL_PLUGINS_DIR); }
$tplSelectNews->assign('Paginator', ''); $tplSelectNews->assign('BottomPaginator', ''); } $page--; if ($page + NEWS_PER_PAGE > $row - 1) { $lastnews = $row - 1; } else { $lastnews = $page + NEWS_PER_PAGE; } for ($i = $page; $i < $lastnews; $i++) { $tplNews = $tplSelectNews->fetchBlock('News'); $tplNews->assign('way', $sWays); $tplNews->assign('Img', ''); if (!empty($aNews[$i]['image'])) { $tplImg = $tplNews->fetchBlock('Img'); $tplImg->assign('image', slashify(ADDR_USERFILES_NEWSPREV)); $tplImg->assign($aNews[$i]); $tplNews->assign('Img', $tplImg); $tplImg->reset(); } $tplNews->assign($aNews[$i]); $tplSelectNews->assign('News', $tplNews); $tplNews->reset(); } $tpl->assign('SelectNews', $tplSelectNews); } else { $tplSelectNews->assign('Paginator', ''); $tplSelectNews->assign('BottomPaginator', ''); $tplSelectNews->assign('News', ''); $tpl->assign('SelectNews', $tplSelectNews); $tpl->assign('SelectNews', 'Ќовостей в данной категории нет.');
/** * Get resource file content (with assets_dir support) * * @param string $name File name */ public function get_resource_content($name) { if (!strpos($name, '/')) { $name = "program/resources/{$name}"; } $assets_dir = $this->config->get('assets_dir'); if ($assets_dir) { $path = slashify($assets_dir) . $name; if (@file_exists($path)) { $name = $path; } } return file_get_contents($name, false); }
/** * Deletes ical properties and the appropriate calendar. * * @see database_driver::remove_calendar() */ public function remove_calendar($prop) { $removed = $this->_get_ical_props($prop['id'], self::OBJ_TYPE_ICAL); $protected = array(); $preinstalled_calendars = $this->rc->config->get('calendar_preinstalled_calendars', array()); foreach ($preinstalled_calendars as $idx => $properties) { if ($properties['driver'] == 'ical') { $url = str_replace('@', urlencode('@'), str_replace('%u', $this->rc->get_user_name(), $properties['ical_url'])); if (stripos($removed['url'], $url) === 0) { if (isset($properties['deleteable']) && !$properties['deleteable']) { $this->last_error = $this->rc->gettext('calendar.protected'); return false; } } } } if (is_array($removed)) { $removed = slashify($removed['url']); $removed = array_merge($this->rc->config->get('calendar_icals_removed', array()), array($removed => time())); $this->rc->user->save_prefs(array('calendar_icals_removed' => $removed)); } if (parent::remove_calendar($prop, $ical)) { $this->_remove_ical_props($prop['id'], self::OBJ_TYPE_ICAL); return true; } return false; }
/** * Provide path to the currently selected skin folder within the plugin directory * with a fallback to the default skin folder. * * @return string Skin path relative to plugins directory */ public function local_skin_path() { $rcmail = rcube::get_instance(); $skin_path = 'skins/' . $rcmail->config->get('skin'); if (!is_dir(realpath(slashify($this->home) . $skin_path))) { $skin_path = 'skins/default'; } return $skin_path; }
/** * Does a REPORT request * * @param string $url * @param array $properties List of requested properties must be specified as an array, in clark * notation. * @param array $event_urls If specified, a multiget report request will be initiated with the * specified event urls. * @param int $depth = 1 Depth should be either 0 or 1. A depth of 1 will cause a request to be * made to the server to also return all child resources. * @return array Hash with ics event path as key and a hash array with properties and appropriate values. */ public function prop_report($url, array $properties, array $event_urls = array(), $depth = 1) { $url = slashify($url); // iCloud $parent_tag = sizeof($event_urls) > 0 ? "c:calendar-multiget" : "d:propfind"; $method = sizeof($event_urls) > 0 ? 'REPORT' : 'PROPFIND'; $body = '<?xml version="1.0"?>' . "\n" . '<' . $parent_tag . ' xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">' . "\n"; $body .= ' <d:prop>' . "\n"; foreach ($properties as $property) { list($namespace, $elementName) = Sabre\DAV\XMLUtil::parseClarkNotation($property); if ($namespace === 'DAV:') { $body .= ' <d:' . $elementName . ' />' . "\n"; } else { $body .= ' <x:' . $elementName . ' xmlns:x="' . $namespace . '"/>' . "\n"; } } $body .= ' </d:prop>' . "\n"; // http://tools.ietf.org/html/rfc4791#page-90 // http://www.bedework.org/trac/bedework/wiki/Bedework/DevDocs/Filters /* if($start && $end) { $body.= ' <c:filter>'."\n". ' <c:comp-filter name="VCALENDAR">'."\n". ' <c:comp-filter name="VEVENT">'."\n". ' <c:time-range start="'.$start.'" end="'.$end.'" />'."\n". ' </c:comp-filter>'."\n". ' </c:comp-filter>'."\n". ' </c:filter>' . "\n"; } */ foreach ($event_urls as $event_url) { $body .= '<d:href>' . $event_url . '</d:href>' . "\n"; } $body .= '</' . $parent_tag . '>'; $response = $this->request($method, $url, $body, array('Depth' => $depth, 'Content-Type' => 'application/xml', 'User-Agent' => $this->user_agent)); $result = $this->parseMultiStatus($response['body']); // If depth was 0, we only return the top item if ($depth === 0) { reset($result); $result = current($result); return isset($result[200]) ? $result[200] : array(); } $new_result = array(); foreach ($result as $href => $status_list) { $new_result[$href] = isset($status_list[200]) ? $status_list[200] : array(); } return $new_result; }
/** * Provide path to the currently selected skin folder within the plugin directory * with a fallback to the default skin folder. * * @return string Skin path relative to plugins directory */ protected function local_skin_path() { $skin_path = 'skins/' . $this->api->config->get('skin'); if (!is_dir(realpath(slashify($this->home) . $skin_path))) { $skin_path = 'skins/default'; } return $skin_path; }
/** * Simplify CardDAV XML response * * @param string $response CardDAV XML response * @param boolean $include_vcards Include vCards or not * @return string Simplified CardDAV XML response */ private function simplify($response, $include_vcards = true) { $response = $this->clean_response($response); set_error_handler(function () { /* ignore errors */ }); try { $xml = new SimpleXMLElement($response); } catch (Exception $e) { return false; } restore_error_handler(); $simplified_xml = new XMLWriter(); $simplified_xml->openMemory(); $simplified_xml->setIndent(4); $simplified_xml->startDocument('1.0', 'utf-8'); $simplified_xml->startElement('response'); foreach ($xml->response as $response) { if (preg_match('/vcard/', $response->propstat->prop->getcontenttype) || preg_match('/vcf/', $response->href) || preg_match('/carddav/', $response->href) && slashify($response->href) != $response->href) { $id = basename($response->href); $id = str_replace($this->ext, null, $id); if (!empty($id)) { $simplified_xml->startElement('element'); $simplified_xml->writeElement('id', $id); $simplified_xml->writeElement('etag', str_replace('"', null, $response->propstat->prop->getetag)); $simplified_xml->writeElement('last_modified', $response->propstat->prop->getlastmodified); if ($include_vcards === true) { $simplified_xml->writeElement('vcard', $this->get_vcard($id)); } $simplified_xml->endElement(); } } else { if (preg_match('/unix-directory/', $response->propstat->prop->getcontenttype)) { if (isset($response->propstat->prop->href)) { $href = $response->propstat->prop->href; } else { if (isset($response->href)) { $href = $response->href; } else { $href = null; } } $url = str_replace($this->url_parts['path'], null, $this->url) . $href; $simplified_xml->startElement('addressbook_element'); $simplified_xml->writeElement('display_name', $response->propstat->prop->displayname); $simplified_xml->writeElement('url', $url); $simplified_xml->writeElement('last_modified', $response->propstat->prop->getlastmodified); $simplified_xml->endElement(); } } } $simplified_xml->endElement(); $simplified_xml->endDocument(); return $simplified_xml->outputMemory(); }
/** * Provide path to the currently selected skin folder within the plugin directory * with a fallback to the default skin folder. * * @return string Skin path relative to plugins directory */ public function local_skin_path() { $rcmail = rcube::get_instance(); foreach (array($rcmail->config->get('skin'), 'larry') as $skin) { $skin_path = 'skins/' . $skin; if (is_dir(realpath(slashify($this->home) . $skin_path))) { break; } } return $skin_path; }
/** * */ function import_events() { // Upload progress update if (!empty($_GET['_progress'])) { $this->rc->upload_progress(); } @set_time_limit(0); // process uploaded file if there is no error $err = $_FILES['_data']['error']; if (!$err && $_FILES['_data']['tmp_name']) { $calendar = rcube_utils::get_input_value('calendar', rcube_utils::INPUT_GPC); $rangestart = $_REQUEST['_range'] ? date_create("now -" . intval($_REQUEST['_range']) . " months") : 0; // extract zip file if ($_FILES['_data']['type'] == 'application/zip') { $count = 0; if (class_exists('ZipArchive', false)) { $zip = new ZipArchive(); if ($zip->open($_FILES['_data']['tmp_name'])) { $randname = uniqid('zip-' . session_id(), true); $tmpdir = slashify($this->rc->config->get('temp_dir', sys_get_temp_dir())) . $randname; mkdir($tmpdir, 0700); // extract each ical file from the archive and import it for ($i = 0; $i < $zip->numFiles; $i++) { $filename = $zip->getNameIndex($i); if (preg_match('/\\.ics$/i', $filename)) { $tmpfile = $tmpdir . '/' . basename($filename); if (copy('zip://' . $_FILES['_data']['tmp_name'] . '#' . $filename, $tmpfile)) { $count += $this->import_from_file($tmpfile, $calendar, $rangestart, $errors); unlink($tmpfile); } } } rmdir($tmpdir); $zip->close(); } else { $errors = 1; $msg = 'Failed to open zip file.'; } } else { $errors = 1; $msg = 'Zip files are not supported for import.'; } } else { // attempt to import teh uploaded file directly $count = $this->import_from_file($_FILES['_data']['tmp_name'], $calendar, $rangestart, $errors); } if ($count) { $this->rc->output->command('display_message', $this->gettext(array('name' => 'importsuccess', 'vars' => array('nr' => $count))), 'confirmation'); $this->rc->output->command('plugin.import_success', array('source' => $calendar, 'refetch' => true)); } else { if (!$errors) { $this->rc->output->command('display_message', $this->gettext('importnone'), 'notice'); $this->rc->output->command('plugin.import_success', array('source' => $calendar)); } else { $this->rc->output->command('plugin.import_error', array('message' => $this->gettext('importerror') . ($msg ? ': ' . $msg : ''))); } } } else { if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) { $msg = $this->gettext(array('name' => 'filesizeerror', 'vars' => array('size' => $this->rc->show_bytes(parse_bytes(ini_get('upload_max_filesize')))))); } else { $msg = $this->gettext('fileuploaderror'); } $this->rc->output->command('plugin.import_error', array('message' => $msg)); } $this->rc->output->send('iframe'); }
/** * Provide path to the currently selected skin folder within the plugin directory * with a fallback to the default skin folder. * * @return string Skin path relative to plugins directory */ public function local_skin_path() { $rcube = rcube::get_instance(); $skins = array_keys((array) $rcube->output->skins); if (empty($skins)) { $skins = (array) $rcube->config->get('skin'); } foreach ($skins as $skin) { $skin_path = 'skins/' . $skin; if (is_dir(realpath(slashify($this->home) . $skin_path))) { break; } } return $skin_path; }
/** * Private constructor */ protected function __construct() { $this->dir = slashify(RCUBE_PLUGINS_DIR); }
$aAlbums = $Img->getUserAlbums($album_own_id); $tpl->assign('user_id', $album_own_id); if (!empty($aAlbums)) { $tpl->assign('albums_num', count($aAlbums) . ' ' . pluralForm(count($aAlbums), 'альбом', 'альбома', 'альбомов')); foreach ($aAlbums as $v) { $tplAlbums = $tpl->fetchBlock('Albums'); $tplAlbums->assign('OwnEdit', ''); if ($v['user_id'] == $user_id) { $tplAlbums->assign('OwnEdit', $tplAlbums->fetchBlock('OwnEdit')); } $aPhotos = $Img->getPhotos($v['id']); if (!empty($aPhotos)) { $tplAlbums->assign('photos_num', count($aPhotos) . ' ' . pluralForm(count($aPhotos), 'фотография', 'фотографии', 'фотографий')); foreach ($aPhotos as $img) { if ($img['cover'] == 1) { $tplAlbums->assign('img', slashify(ADDR_PHOTOS_THUMBNAILS) . $img['file']); } } } else { $tplAlbums->assign('photos_num', '0 фотографий'); } $tplAlbums->assign($v); $tpl->assign('Albums', $tplAlbums); $tplAlbums->reset(); } } else { $tpl->assign('albums_num', 'нет загруженных альбомов'); } } // CLOSE $_t->assign('ContentBlock', $tpl);