Import Ruty

This commit is contained in:
2024-03-11 00:58:34 +01:00
parent 34a31bb184
commit 985f1ab418
618 changed files with 225414 additions and 0 deletions
+146
View File
@@ -0,0 +1,146 @@
<?php
/**
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
| |
| Copyright (C) The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Display error message page |
+-----------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> |
+-----------------------------------------------------------------------+
*/
class rcmail_action_utils_error extends rcmail_action
{
/**
* Request handler.
*
* @param array $args Arguments from the previous step(s)
*/
public function run($args = [])
{
$rcmail = rcmail::get_instance();
$ERROR_CODE = !empty($args['code']) ? $args['code'] : 500;
$ERROR_MESSAGE = !empty($args['message']) ? $args['message'] : null;
// authorization error
if ($ERROR_CODE == 401) {
$error_title = $rcmail->gettext('errauthorizationfailed');
$error_text = nl2br($rcmail->gettext('errunauthorizedexplain')
. "\n" . $rcmail->gettext('errcontactserveradmin'));
}
// forbidden due to request check
else if ($ERROR_CODE == 403) {
if ($_SERVER['REQUEST_METHOD'] == 'GET' && $rcmail->request_status == rcube::REQUEST_ERROR_URL) {
$url = $rcmail->url($_GET, true, false, true);
$add = html::a($url, $rcmail->gettext('clicktoresumesession'));
}
else {
$add = $rcmail->gettext('errcontactserveradmin');
}
$error_title = $rcmail->gettext('errrequestcheckfailed');
$error_text = nl2br($rcmail->gettext('errcsrfprotectionexplain')) . '<p>' . $add . '</p>';
}
// failed request (wrong step in URL)
else if ($ERROR_CODE == 404) {
$request_url = htmlentities($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
$error_title = $rcmail->gettext('errnotfound');
$error_text = nl2br($rcmail->gettext('errnotfoundexplain')
. "\n" . $rcmail->gettext('errcontactserveradmin'));
$error_text .= '<p><i>' . $rcmail->gettext('errfailedrequest') . ": $request_url</i></p>";
}
// Gone, e.g. message cached but not in the storage
else if ($ERROR_CODE == 410) {
$error_title = $rcmail->gettext('servererror');
$error_text = $rcmail->gettext('messageopenerror');
}
// invalid compose ID
else if ($ERROR_CODE == 450 && $_SERVER['REQUEST_METHOD'] == 'GET' && $rcmail->action == 'compose') {
$url = $rcmail->url('compose');
$error_title = $rcmail->gettext('errcomposesession');
$error_text = nl2br($rcmail->gettext('errcomposesessionexplain'))
. '<p>' . html::a($url, $rcmail->gettext('clicktocompose')) . '</p>';
}
// database connection error
else if ($ERROR_CODE == 601) {
$error_title = "Configuration error";
$error_text = nl2br($ERROR_MESSAGE) . "<br />Please read the INSTALL instructions!";
}
// database connection error
else if ($ERROR_CODE == 603) {
$error_title = $rcmail->gettext('dberror');
$error_text = nl2br($rcmail->gettext('dbconnerror') . "\n" . $rcmail->gettext('errcontactserveradmin'));
}
// system error
else {
$error_title = $rcmail->gettext('servererror');
$error_text = sprintf('Error No. [%s]', $ERROR_CODE);
}
// inform plugins
if ($rcmail->plugins) {
$plugin = $rcmail->plugins->exec_hook('error_page', [
'code' => $ERROR_CODE,
'title' => $error_title,
'text' => $error_text,
]);
if (!empty($plugin['title'])) {
$error_title = $plugin['title'];
}
if (!empty($plugin['text'])) {
$error_text = $plugin['text'];
}
}
$HTTP_ERR_CODE = $ERROR_CODE && $ERROR_CODE < 600 ? $ERROR_CODE : 500;
// Ajax request
if ($rcmail->output && $rcmail->output->type == 'js') {
$rcmail->output->sendExit('', ["HTTP/1.0 $HTTP_ERR_CODE $error_title"]);
}
// compose page content
$page_content = '<div class="boxerror">'
.'<h3 class="error-title">' . mb_strtoupper($error_title) . '</h3>'
.'<div class="error-text">' . $error_text . '</div>'
.'</div>';
if ($rcmail->output && $rcmail->output->template_exists('error')) {
$GLOBALS['__page_content'] = $page_content;
$task = empty($rcmail->user) || empty($rcmail->user->ID) ? '-login' : '';
$rcmail->output->reset();
$rcmail->output->set_env('error_task', 'error' . $task);
$rcmail->output->set_env('server_error', $ERROR_CODE);
$rcmail->output->set_env('comm_path', $rcmail->comm_path);
$rcmail->output->send('error');
}
$skin = $rcmail->config->get('skin', 'default');
$product = $rcmail->config->get('product_name', 'Roundcube Webmail');
$output = '<!doctype html><html><head>'
. '<title>' . $product . ':: ERROR</title>'
. '<link rel="stylesheet" type="text/css" href="skins/$skin/common.css" />'
. '</head><body>'
. '<table border="0" cellspacing="0" cellpadding="0" width="100%" height="80%">'
. '<tr><td align="center">' . $page_content . '</td></tr>'
. '</table>'
. '</body></html>';
$rcmail->output->sendExit($output);
}
}
@@ -0,0 +1,41 @@
<?php
/**
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
| |
| Copyright (C) The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Convert HTML message to plain text |
+-----------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> |
+-----------------------------------------------------------------------+
*/
class rcmail_action_utils_html2text extends rcmail_action
{
public static $source = 'php://input';
/**
* Request handler.
*
* @param array $args Arguments from the previous step(s)
*/
public function run($args = [])
{
$html = file_get_contents(self::$source);
$params['links'] = (bool) rcube_utils::get_input_value('_do_links', rcube_utils::INPUT_GET);
$params['width'] = (int) rcube_utils::get_input_value('_width', rcube_utils::INPUT_GET);
$rcmail = rcmail::get_instance();
$text = $rcmail->html2text($html, $params);
$rcmail->output->sendExit($text, ['Content-Type: text/plain; charset=' . RCUBE_CHARSET]);
}
}
@@ -0,0 +1,66 @@
<?php
/**
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
| |
| Copyright (C) The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Delete rows from cache tables |
+-----------------------------------------------------------------------+
| Author: Dennis P. Nikolaenko <dennis@nikolaenko.ru> |
+-----------------------------------------------------------------------+
*/
class rcmail_action_utils_killcache extends rcmail_action
{
/**
* Request handler.
*
* @param array $args Arguments from the previous step(s)
*/
public function run($args = [])
{
$rcmail = rcmail::get_instance();
// don't allow public access if not in devel_mode
if (!$rcmail->config->get('devel_mode')) {
header("HTTP/1.0 401 Access denied");
die("Access denied!");
}
// @TODO: transaction here (if supported by DB) would be a good thing
$res = $rcmail->db->query("DELETE FROM " . $rcmail->db->table_name('cache', true));
if ($err = $rcmail->db->is_error($res)) {
exit($err);
}
$res = $rcmail->db->query("DELETE FROM " . $rcmail->db->table_name('cache_shared', true));
if ($err = $rcmail->db->is_error($res)) {
exit($err);
}
$res = $rcmail->db->query("DELETE FROM " . $rcmail->db->table_name('cache_messages', true));
if ($err = $rcmail->db->is_error($res)) {
exit($err);
}
$res = $rcmail->db->query("DELETE FROM " . $rcmail->db->table_name('cache_index', true));
if ($err = $rcmail->db->is_error($res)) {
exit($err);
}
$res = $rcmail->db->query("DELETE FROM " . $rcmail->db->table_name('cache_thread', true));
if ($err = $rcmail->db->is_error($res)) {
exit($err);
}
echo "Cache cleared\n";
exit;
}
}
@@ -0,0 +1,73 @@
<?php
/**
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
| |
| Copyright (C) The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Modify CSS source from a URL |
+-----------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> |
| Author: Aleksander Machniak <alec@alec.pl> |
+-----------------------------------------------------------------------+
*/
class rcmail_action_utils_modcss extends rcmail_action
{
/**
* Request handler.
*
* @param array $args Arguments from the previous step(s)
*/
public function run($args = [])
{
$url = preg_replace('![^a-z0-9.-]!i', '', $_GET['_u']);
if ($url === null || !($realurl = $_SESSION['modcssurls'][$url])) {
header('HTTP/1.1 403 Forbidden');
exit("Unauthorized request");
}
// don't allow any other connections than http(s)
if (!preg_match('~^https?://~i', $realurl, $matches)) {
header('HTTP/1.1 403 Forbidden');
exit("Invalid URL");
}
$source = false;
$ctype = null;
try {
$client = rcube::get_instance()->get_http_client();
$response = $client->get($realurl);
if (!empty($response)) {
$ctype = $response->getHeader('Content-Type');
$ctype = !empty($ctype) ? $ctype[0] : '';
$source = $response->getBody();
}
}
catch (Exception $e) {
rcube::raise_error($e, true, false);
}
$ctype_regexp = '~^text/(css|plain)~i';
$container_id = isset($_GET['_c']) ? preg_replace('/[^a-z0-9]/i', '', $_GET['_c']) : '';
$css_prefix = isset($_GET['_p']) ? preg_replace('/[^a-z0-9]/i', '', $_GET['_p']) : '';
if ($source !== false && $ctype && preg_match($ctype_regexp, $ctype)) {
header('Content-Type: text/css');
echo rcube_utils::mod_css_styles($source, $container_id, false, $css_prefix);
exit;
}
header('HTTP/1.0 404 Not Found');
exit("Invalid response returned by server");
}
}
@@ -0,0 +1,90 @@
<?php
/**
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
| |
| Copyright (C) The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Save preferences setting in database |
+-----------------------------------------------------------------------+
| Author: Aleksander Machniak <alec@alec.pl> |
+-----------------------------------------------------------------------+
*/
class rcmail_action_utils_save_pref extends rcmail_action
{
// only process ajax requests
protected static $mode = self::MODE_AJAX;
/**
* Request handler.
*
* @param array $args Arguments from the previous step(s)
*/
public function run($args = [])
{
$rcmail = rcmail::get_instance();
$name = rcube_utils::get_input_string('_name', rcube_utils::INPUT_POST);
$value = rcube_utils::get_input_value('_value', rcube_utils::INPUT_POST);
$sessname = rcube_utils::get_input_string('_session', rcube_utils::INPUT_POST);
// Whitelisted preferences and session variables, others
// can be added by plugins
$whitelist = [
'list_cols',
'collapsed_folders',
'collapsed_abooks',
];
$whitelist_sess = [
'list_attrib/columns',
];
$whitelist = array_merge($whitelist, $rcmail->plugins->allowed_prefs);
$whitelist_sess = array_merge($whitelist_sess, $rcmail->plugins->allowed_session_prefs);
if (!in_array($name, $whitelist) || ($sessname && !in_array($sessname, $whitelist_sess))) {
rcube::raise_error([
'code' => 500,
'file' => __FILE__,
'line' => __LINE__,
'message' => sprintf("Hack attempt detected (user: %s)", $rcmail->get_user_name())
],
true,
false
);
$rcmail->output->reset();
$rcmail->output->send();
}
// save preference value
$rcmail->user->save_prefs([$name => $value]);
// update also session if requested
if ($sessname) {
// Support multidimensional arrays...
$vars = explode('/', $sessname);
// ... up to 3 levels
if (count($vars) == 1) {
$_SESSION[$vars[0]] = $value;
}
else if (count($vars) == 2) {
$_SESSION[$vars[0]][$vars[1]] = $value;
}
else if (count($vars) == 3) {
$_SESSION[$vars[0]][$vars[1]][$vars[2]] = $value;
}
}
$rcmail->output->reset();
$rcmail->output->send();
}
}
@@ -0,0 +1,81 @@
<?php
/**
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
| |
| Copyright (C) The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Invoke the configured or default spell checking engine. |
+-----------------------------------------------------------------------+
| Author: Kris Steinhoff <steinhof@umich.edu> |
+-----------------------------------------------------------------------+
*/
class rcmail_action_utils_spell extends rcmail_action
{
// only process ajax requests
protected static $mode = self::MODE_AJAX;
/**
* Request handler.
*
* @param array $args Arguments from the previous step(s)
*/
public function run($args = [])
{
// read input
$lang = rcube_utils::get_input_string('lang', rcube_utils::INPUT_GET);
$data = file_get_contents('php://input');
$learn_word = strpos($data, '<learnword>');
// Get data string
$left = strpos($data, '<text>');
$right = strrpos($data, '</text>');
$data = substr($data, $left+6, $right-($left+6));
$data = html_entity_decode($data, ENT_QUOTES, RCUBE_CHARSET);
$spellchecker = new rcube_spellchecker($lang);
if ($learn_word) {
$spellchecker->add_word($data);
$result = '<?xml version="1.0" encoding="'.RCUBE_CHARSET.'"?><learnwordresult></learnwordresult>';
}
else if (empty($data)) {
$result = '<?xml version="1.0" encoding="'.RCUBE_CHARSET.'"?><spellresult charschecked="0"></spellresult>';
}
else {
$spellchecker->check($data);
$result = $spellchecker->get_xml();
}
if ($error = $spellchecker->error()) {
rcube::raise_error([
'code' => 500,
'file' => __FILE__,
'line' => __LINE__,
'message' => "Spellcheck error: " . $error
],
true,
false
);
header("HTTP/1.0 500 Internal Server Error");
exit;
}
// set response length
header("Content-Length: " . strlen($result));
// Don't use server's default Content-Type charset (#1486406)
header("Content-Type: text/xml; charset=" . RCUBE_CHARSET);
print $result;
exit;
}
}
@@ -0,0 +1,76 @@
<?php
/**
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
| |
| Copyright (C) The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Spellchecker for TinyMCE |
+-----------------------------------------------------------------------+
| Author: Aleksander Machniak <alec@alec.pl> |
+-----------------------------------------------------------------------+
*/
class rcmail_action_utils_spell_html extends rcmail_action
{
// only process ajax requests
protected static $mode = self::MODE_AJAX;
/**
* Request handler.
*
* @param array $args Arguments from the previous step(s)
*/
public function run($args = [])
{
$rcmail = rcmail::get_instance();
$method = rcube_utils::get_input_string('method', rcube_utils::INPUT_POST);
$lang = rcube_utils::get_input_string('lang', rcube_utils::INPUT_POST);
$result = [];
$spellchecker = new rcube_spellchecker($lang);
if ($method == 'addToDictionary') {
$data = rcube_utils::get_input_string('word', rcube_utils::INPUT_POST);
$spellchecker->add_word($data);
$result['result'] = true;
}
else {
$data = rcube_utils::get_input_string('text', rcube_utils::INPUT_POST, true);
$data = html_entity_decode($data, ENT_QUOTES, RCUBE_CHARSET);
if ($data && !$spellchecker->check($data)) {
$result['words'] = $spellchecker->get();
$result['dictionary'] = (bool) $rcmail->config->get('spellcheck_dictionary');
}
}
header("Content-Type: application/json; charset=" . RCUBE_CHARSET);
if ($error = $spellchecker->error()) {
rcube::raise_error([
'code' => 500,
'file' => __FILE__,
'line' => __LINE__,
'message' => "Spellcheck error: " . $error
],
true,
false
);
echo json_encode(['error' => $rcmail->gettext('internalerror')]);
exit;
}
// send output
echo json_encode($result);
exit;
}
}
@@ -0,0 +1,41 @@
<?php
/**
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
| |
| Copyright (C) The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Convert plain text to HTML |
+-----------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> |
+-----------------------------------------------------------------------+
*/
class rcmail_action_utils_text2html extends rcmail_action
{
public static $source = 'php://input';
/**
* Request handler.
*
* @param array $args Arguments from the previous step(s)
*/
public function run($args = [])
{
$text = file_get_contents(self::$source);
$converter = new rcube_text2html($text, false, ['wrap' => true]);
$rcmail = rcmail::get_instance();
$html = $converter->get_html();
$rcmail->output->sendExit($html, ['Content-Type: text/html; charset=' . RCUBE_CHARSET]);
}
}