/** * rcube_shared.inc: parse_bytes() */ function test_parse_bytes() { $data = array('1' => 1, '1024' => 1024, '2k' => 2 * 1024, '2 k' => 2 * 1024, '2kb' => 2 * 1024, '2kB' => 2 * 1024, '2m' => 2 * 1048576, '2 m' => 2 * 1048576, '2mb' => 2 * 1048576, '2mB' => 2 * 1048576, '2g' => 2 * 1024 * 1048576, '2 g' => 2 * 1024 * 1048576, '2gb' => 2 * 1024 * 1048576, '2gB' => 2 * 1024 * 1048576); foreach ($data as $value => $expected) { $result = parse_bytes($value); $this->assertEquals($expected, $result, "Invalid parse_bytes() result for {$value}"); } }
function check_size($args) { $limit = parse_bytes(rcmail::get_instance()->config->get('max_message_size', '10MB')); $total = $args['size']; if ($_SESSION['compose'] && $_SESSION['compose']['attachments']) { foreach ($_SESSION['compose']['attachments'] as $attachment) { $total += $attachment['size']; } } if ($total > $limit) { $this->add_texts('localization/'); $args['error'] = sprintf($this->gettext('overallsizeerror'), show_bytes(parse_bytes($limit))); $args['abort'] = true; } return $args; }
/** * */ 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'); }
/** * Key import (page) handler */ private function key_import() { // Import process if ($data = rcube_utils::get_input_value('_keys', rcube_utils::INPUT_POST)) { // Import from generation form (ajax request) $this->enigma->load_engine(); $result = $this->enigma->engine->import_key($data); if (is_array($result)) { $this->rc->output->command('enigma_key_create_success'); $this->rc->output->show_message('enigma.keygeneratesuccess', 'confirmation'); } else { $this->rc->output->show_message('enigma.keysimportfailed', 'error'); } $this->rc->output->send(); } else { if ($_FILES['_file']['tmp_name'] && is_uploaded_file($_FILES['_file']['tmp_name'])) { $this->enigma->load_engine(); $result = $this->enigma->engine->import_key($_FILES['_file']['tmp_name'], true); if (is_array($result)) { // reload list if any keys has been added if ($result['imported']) { $this->rc->output->command('parent.enigma_list', 1); } else { $this->rc->output->command('parent.enigma_loadframe'); } $this->rc->output->show_message('enigma.keysimportsuccess', 'confirmation', array('new' => $result['imported'], 'old' => $result['unchanged'])); $this->rc->output->send('iframe'); } else { $this->rc->output->show_message('enigma.keysimportfailed', 'error'); } } else { if ($err = $_FILES['_file']['error']) { if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) { $this->rc->output->show_message('filesizeerror', 'error', array('size' => $this->rc->show_bytes(parse_bytes(ini_get('upload_max_filesize'))))); } else { $this->rc->output->show_message('fileuploaderror', 'error'); } } } } $this->rc->output->add_handlers(array('importform' => array($this, 'tpl_key_import_form'))); $this->rc->output->set_pagetitle($this->enigma->gettext('keyimport')); $this->rc->output->send('enigma.keyimport'); }
/** * Initializes file uploading interface. */ public function upload_init() { // Enable upload progress bar if (($seconds = $this->config->get('upload_progress')) && ini_get('apc.rfc1867')) { if ($field_name = ini_get('apc.rfc1867_name')) { $this->output->set_env('upload_progress_name', $field_name); $this->output->set_env('upload_progress_time', (int) $seconds); } } // find max filesize value $max_filesize = parse_bytes(ini_get('upload_max_filesize')); $max_postsize = parse_bytes(ini_get('post_max_size')); if ($max_postsize && $max_postsize < $max_filesize) { $max_filesize = $max_postsize; } $this->output->set_env('max_filesize', $max_filesize); $max_filesize = self::show_bytes($max_filesize); $this->output->set_env('filesizeerror', $this->gettext(array('name' => 'filesizeerror', 'vars' => array('size' => $max_filesize)))); return $max_filesize; }
<th width="120" align="center">操作</th> </tr> <?php foreach ($fileRows as $row) { ?> <tr height="30"> <td><a href="show.php?id=<?php echo $row["id"]; ?> " target="_blank" title="点击查看缩略图"><?php echo $row["file_name"]; ?> </a></td> <td width="100" align="center"><?php echo parse_bytes($row["file_size"], 1024); ?> </td> <td width="180" align="center"><?php echo date("Y-m-d H:i:s", $row["created_at"]); ?> </td> <td width="160" align="center"> <a href="show.php?id=<?php echo $row["id"]; ?> " target="_blank" title="点击查看缩略图">查看</a> <a href="wm_show.php?id=<?php echo $row["id"]; ?> " title="点击进行水印设置">水印</a>
function managesieve_save() { // Init plugin and handle managesieve connection $error = $this->managesieve_start(); // filters set add action if (!empty($_POST['_newset'])) { $name = get_input_value('_name', RCUBE_INPUT_POST); $copy = get_input_value('_copy', RCUBE_INPUT_POST); $from = get_input_value('_from', RCUBE_INPUT_POST); if (!$name) { $error = 'managesieve.emptyname'; } else { if (mb_strlen($name) > 128) { $error = 'managesieve.nametoolong'; } else { if ($from == 'file') { // from file if (is_uploaded_file($_FILES['_file']['tmp_name'])) { $file = file_get_contents($_FILES['_file']['tmp_name']); $file = preg_replace('/\\r/', '', $file); // for security don't save script directly // check syntax before, like this... $this->sieve->load_script($file); if (!$this->sieve->save($name)) { $error = 'managesieve.setcreateerror'; } } else { // upload failed $err = $_FILES['_file']['error']; $error = true; if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) { $msg = rcube_label(array('name' => 'filesizeerror', 'vars' => array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize')))))); } else { $error = 'fileuploaderror'; } } } else { if (!$this->sieve->copy($name, $from == 'set' ? $copy : '')) { $error = 'managesieve.setcreateerror'; } } } } if (!$error) { $this->rc->output->show_message('managesieve.setcreated', 'confirmation'); $this->rc->output->command('parent.managesieve_reload', $name); } else { if ($msg) { $this->rc->output->command('display_message', $msg, 'error'); } else { $this->rc->output->show_message($error, 'error'); } } } else { if (isset($_POST['_name'])) { $name = trim(get_input_value('_name', RCUBE_INPUT_POST, true)); $fid = trim(get_input_value('_fid', RCUBE_INPUT_POST)); $join = trim(get_input_value('_join', RCUBE_INPUT_POST)); // and arrays $headers = $_POST['_header']; $cust_headers = $_POST['_custom_header']; $ops = $_POST['_rule_op']; $sizeops = $_POST['_rule_size_op']; $sizeitems = $_POST['_rule_size_item']; $sizetargets = $_POST['_rule_size_target']; $targets = $_POST['_rule_target']; $act_types = $_POST['_action_type']; $mailboxes = $_POST['_action_mailbox']; $act_targets = $_POST['_action_target']; $area_targets = $_POST['_action_target_area']; $reasons = $_POST['_action_reason']; $addresses = $_POST['_action_addresses']; $days = $_POST['_action_days']; // we need a "hack" for radiobuttons foreach ($sizeitems as $item) { $items[] = $item; } $this->form['disabled'] = $_POST['_disabled'] ? true : false; $this->form['join'] = $join == 'allof' ? true : false; $this->form['name'] = $name; $this->form['tests'] = array(); $this->form['actions'] = array(); if ($name == '') { $this->errors['name'] = $this->gettext('cannotbeempty'); } else { foreach ($this->script as $idx => $rule) { if ($rule['name'] == $name && $idx != $fid) { $this->errors['name'] = $this->gettext('ruleexist'); break; } } } $i = 0; // rules if ($join == 'any') { $this->form['tests'][0]['test'] = 'true'; } else { foreach ($headers as $idx => $header) { $header = $this->strip_value($header); $target = $this->strip_value($targets[$idx], true); $op = $this->strip_value($ops[$idx]); // normal header if (in_array($header, $this->headers)) { if (preg_match('/^not/', $op)) { $this->form['tests'][$i]['not'] = true; } $type = preg_replace('/^not/', '', $op); if ($type == 'exists') { $this->form['tests'][$i]['test'] = 'exists'; $this->form['tests'][$i]['arg'] = $header; } else { $this->form['tests'][$i]['type'] = $type; $this->form['tests'][$i]['test'] = 'header'; $this->form['tests'][$i]['arg1'] = $header; $this->form['tests'][$i]['arg2'] = $target; if ($target == '') { $this->errors['tests'][$i]['target'] = $this->gettext('cannotbeempty'); } else { if (preg_match('/^(value|count)-/', $type) && !preg_match('/[0-9]+/', $target)) { $this->errors['tests'][$i]['target'] = $this->gettext('forbiddenchars'); } } } } else { switch ($header) { case 'size': $sizeop = $this->strip_value($sizeops[$idx]); $sizeitem = $this->strip_value($items[$idx]); $sizetarget = $this->strip_value($sizetargets[$idx]); $this->form['tests'][$i]['test'] = 'size'; $this->form['tests'][$i]['type'] = $sizeop; $this->form['tests'][$i]['arg'] = $sizetarget . $sizeitem; if ($sizetarget == '') { $this->errors['tests'][$i]['sizetarget'] = $this->gettext('cannotbeempty'); } else { if (!preg_match('/^[0-9]+(K|M|G)*$/i', $sizetarget)) { $this->errors['tests'][$i]['sizetarget'] = $this->gettext('forbiddenchars'); } } break; case '...': $cust_header = $headers = $this->strip_value($cust_headers[$idx]); if (preg_match('/^not/', $op)) { $this->form['tests'][$i]['not'] = true; } $type = preg_replace('/^not/', '', $op); if ($cust_header == '') { $this->errors['tests'][$i]['header'] = $this->gettext('cannotbeempty'); } else { $headers = preg_split('/[\\s,]+/', $cust_header, -1, PREG_SPLIT_NO_EMPTY); if (!count($headers)) { $this->errors['tests'][$i]['header'] = $this->gettext('cannotbeempty'); } else { foreach ($headers as $hr) { if (!preg_match('/^[a-z0-9-]+$/i', $hr)) { $this->errors['tests'][$i]['header'] = $this->gettext('forbiddenchars'); } } } } if (empty($this->errors['tests'][$i]['header'])) { $cust_header = is_array($headers) && count($headers) == 1 ? $headers[0] : $headers; } if ($type == 'exists') { $this->form['tests'][$i]['test'] = 'exists'; $this->form['tests'][$i]['arg'] = $cust_header; } else { $this->form['tests'][$i]['test'] = 'header'; $this->form['tests'][$i]['type'] = $type; $this->form['tests'][$i]['arg1'] = $cust_header; $this->form['tests'][$i]['arg2'] = $target; if ($target == '') { $this->errors['tests'][$i]['target'] = $this->gettext('cannotbeempty'); } else { if (preg_match('/^(value|count)-/', $type) && !preg_match('/[0-9]+/', $target)) { $this->errors['tests'][$i]['target'] = $this->gettext('forbiddenchars'); } } } break; } } $i++; } } $i = 0; // actions foreach ($act_types as $idx => $type) { $type = $this->strip_value($type); $target = $this->strip_value($act_targets[$idx]); switch ($type) { case 'fileinto': case 'fileinto_copy': $mailbox = $this->strip_value($mailboxes[$idx]); $this->form['actions'][$i]['target'] = $mailbox; if ($type == 'fileinto_copy') { $type = 'fileinto'; $this->form['actions'][$i]['copy'] = true; } break; case 'reject': case 'ereject': $target = $this->strip_value($area_targets[$idx]); $this->form['actions'][$i]['target'] = str_replace("\r\n", "\n", $target); // if ($target == '') // $this->errors['actions'][$i]['targetarea'] = $this->gettext('cannotbeempty'); break; case 'redirect': case 'redirect_copy': $this->form['actions'][$i]['target'] = $target; if ($this->form['actions'][$i]['target'] == '') { $this->errors['actions'][$i]['target'] = $this->gettext('cannotbeempty'); } else { if (!check_email($this->form['actions'][$i]['target'])) { $this->errors['actions'][$i]['target'] = $this->gettext('noemailwarning'); } } if ($type == 'redirect_copy') { $type = 'redirect'; $this->form['actions'][$i]['copy'] = true; } break; case 'vacation': $reason = $this->strip_value($reasons[$idx]); $this->form['actions'][$i]['reason'] = str_replace("\r\n", "\n", $reason); $this->form['actions'][$i]['days'] = $days[$idx]; $this->form['actions'][$i]['addresses'] = explode(',', $addresses[$idx]); // @TODO: vacation :subject, :mime, :from, :handle if ($this->form['actions'][$i]['addresses']) { foreach ($this->form['actions'][$i]['addresses'] as $aidx => $address) { $address = trim($address); if (!$address) { unset($this->form['actions'][$i]['addresses'][$aidx]); } else { if (!check_email($address)) { $this->errors['actions'][$i]['addresses'] = $this->gettext('noemailwarning'); break; } else { $this->form['actions'][$i]['addresses'][$aidx] = $address; } } } } if ($this->form['actions'][$i]['reason'] == '') { $this->errors['actions'][$i]['reason'] = $this->gettext('cannotbeempty'); } if ($this->form['actions'][$i]['days'] && !preg_match('/^[0-9]+$/', $this->form['actions'][$i]['days'])) { $this->errors['actions'][$i]['days'] = $this->gettext('forbiddenchars'); } break; } $this->form['actions'][$i]['type'] = $type; $i++; } if (!$this->errors) { // zapis skryptu if (!isset($this->script[$fid])) { $fid = $this->sieve->script->add_rule($this->form); $new = true; } else { $fid = $this->sieve->script->update_rule($fid, $this->form); } if ($fid !== false) { $save = $this->sieve->save(); } if ($save && $fid !== false) { $this->rc->output->show_message('managesieve.filtersaved', 'confirmation'); $this->rc->output->add_script(sprintf("rcmail.managesieve_updatelist('%s', '%s', %d, %d);", isset($new) ? 'add' : 'update', Q($this->form['name']), $fid, $this->form['disabled']), 'foot'); } else { $this->rc->output->show_message('managesieve.filtersaveerror', 'error'); // $this->rc->output->send(); } } } } $this->managesieve_send(); }
/** * Check if we can process not exceeding memory_limit * * @param integer Required amount of memory * * @return boolean True if memory won't be exceeded, False otherwise */ public static function mem_check($need) { $mem_limit = parse_bytes(ini_get('memory_limit')); $memory = function_exists('memory_get_usage') ? memory_get_usage() : 16 * 1024 * 1024; // safe value: 16MB return $mem_limit > 0 && $memory + $need > $mem_limit ? false : true; }
<h4> <a href="index.php">返回列表</a> <a href="upload.php">上传照片</a> <a href="logout.php">注销退出</a> </h4> <?php if ($base_url) { ?> <p>文件名:<?php echo $fileRow["file_name"]; ?> </p> <p>文件大小:<?php echo parse_bytes($fileRow["file_size"]); ?> </p> <p>上传时间:<?php echo date("Y-m-d H:i:s", $fileRow["created_at"]); ?> </p> <p> <a href="download.php?id=<?php echo $fileRow["id"]; ?> " title="点击下载原始尺图片">下载</a> <a href="delete.php?id=<?php echo $fileRow["id"]; ?> " title="点击将该图片删除">删除</a>
function managesieve_save() { // load localization $this->add_texts('localization/', array('filters', 'managefilters')); // include main js script if ($this->api->output->type == 'html') { $this->include_script('managesieve.js'); } // Init plugin and handle managesieve connection $error = $this->managesieve_start(); // filters set add action if (!empty($_POST['_newset'])) { $name = get_input_value('_name', RCUBE_INPUT_POST, true); $copy = get_input_value('_copy', RCUBE_INPUT_POST, true); $from = get_input_value('_from', RCUBE_INPUT_POST); $exceptions = $this->rc->config->get('managesieve_filename_exceptions'); $kolab = $this->rc->config->get('managesieve_kolab_master'); $name_uc = mb_strtolower($name); $list = $this->list_scripts(); if (!$name) { $this->errors['name'] = $this->gettext('cannotbeempty'); } else { if (mb_strlen($name) > 128) { $this->errors['name'] = $this->gettext('nametoolong'); } else { if (!empty($exceptions) && in_array($name, (array) $exceptions)) { $this->errors['name'] = $this->gettext('namereserved'); } else { if (!empty($kolab) && in_array($name_uc, array('MASTER', 'USER', 'MANAGEMENT'))) { $this->errors['name'] = $this->gettext('namereserved'); } else { if (in_array($name, $list)) { $this->errors['name'] = $this->gettext('setexist'); } else { if ($from == 'file') { // from file if (is_uploaded_file($_FILES['_file']['tmp_name'])) { $file = file_get_contents($_FILES['_file']['tmp_name']); $file = preg_replace('/\\r/', '', $file); // for security don't save script directly // check syntax before, like this... $this->sieve->load_script($file); if (!$this->save_script($name)) { $this->errors['file'] = $this->gettext('setcreateerror'); } } else { // upload failed $err = $_FILES['_file']['error']; if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) { $msg = rcube_label(array('name' => 'filesizeerror', 'vars' => array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize')))))); } else { $this->errors['file'] = $this->gettext('fileuploaderror'); } } } else { if (!$this->sieve->copy($name, $from == 'set' ? $copy : '')) { $error = 'managesieve.setcreateerror'; } } } } } } } if (!$error && empty($this->errors)) { // Find position of the new script on the list $list[] = $name; asort($list, SORT_LOCALE_STRING); $list = array_values($list); $index = array_search($name, $list); $this->rc->output->show_message('managesieve.setcreated', 'confirmation'); $this->rc->output->command('parent.managesieve_updatelist', 'setadd', array('name' => $name, 'index' => $index)); } else { if ($msg) { $this->rc->output->command('display_message', $msg, 'error'); } else { if ($error) { $this->rc->output->show_message($error, 'error'); } } } } else { if (isset($_POST['_name'])) { $name = trim(get_input_value('_name', RCUBE_INPUT_POST, true)); $fid = trim(get_input_value('_fid', RCUBE_INPUT_POST)); $join = trim(get_input_value('_join', RCUBE_INPUT_POST)); // and arrays $headers = get_input_value('_header', RCUBE_INPUT_POST); $cust_headers = get_input_value('_custom_header', RCUBE_INPUT_POST); $ops = get_input_value('_rule_op', RCUBE_INPUT_POST); $sizeops = get_input_value('_rule_size_op', RCUBE_INPUT_POST); $sizeitems = get_input_value('_rule_size_item', RCUBE_INPUT_POST); $sizetargets = get_input_value('_rule_size_target', RCUBE_INPUT_POST); $targets = get_input_value('_rule_target', RCUBE_INPUT_POST, true); $mods = get_input_value('_rule_mod', RCUBE_INPUT_POST); $mod_types = get_input_value('_rule_mod_type', RCUBE_INPUT_POST); $body_trans = get_input_value('_rule_trans', RCUBE_INPUT_POST); $body_types = get_input_value('_rule_trans_type', RCUBE_INPUT_POST, true); $comparators = get_input_value('_rule_comp', RCUBE_INPUT_POST); $act_types = get_input_value('_action_type', RCUBE_INPUT_POST, true); $mailboxes = get_input_value('_action_mailbox', RCUBE_INPUT_POST, true); $act_targets = get_input_value('_action_target', RCUBE_INPUT_POST, true); $area_targets = get_input_value('_action_target_area', RCUBE_INPUT_POST, true); $reasons = get_input_value('_action_reason', RCUBE_INPUT_POST, true); $addresses = get_input_value('_action_addresses', RCUBE_INPUT_POST, true); $days = get_input_value('_action_days', RCUBE_INPUT_POST); $subject = get_input_value('_action_subject', RCUBE_INPUT_POST, true); $flags = get_input_value('_action_flags', RCUBE_INPUT_POST); // we need a "hack" for radiobuttons foreach ($sizeitems as $item) { $items[] = $item; } $this->form['disabled'] = $_POST['_disabled'] ? true : false; $this->form['join'] = $join == 'allof' ? true : false; $this->form['name'] = $name; $this->form['tests'] = array(); $this->form['actions'] = array(); if ($name == '') { $this->errors['name'] = $this->gettext('cannotbeempty'); } else { foreach ($this->script as $idx => $rule) { if ($rule['name'] == $name && $idx != $fid) { $this->errors['name'] = $this->gettext('ruleexist'); break; } } } $i = 0; // rules if ($join == 'any') { $this->form['tests'][0]['test'] = 'true'; } else { foreach ($headers as $idx => $header) { $header = $this->strip_value($header); $target = $this->strip_value($targets[$idx], true); $operator = $this->strip_value($ops[$idx]); $comparator = $this->strip_value($comparators[$idx]); if ($header == 'size') { $sizeop = $this->strip_value($sizeops[$idx]); $sizeitem = $this->strip_value($items[$idx]); $sizetarget = $this->strip_value($sizetargets[$idx]); $this->form['tests'][$i]['test'] = 'size'; $this->form['tests'][$i]['type'] = $sizeop; $this->form['tests'][$i]['arg'] = $sizetarget; if ($sizetarget == '') { $this->errors['tests'][$i]['sizetarget'] = $this->gettext('cannotbeempty'); } else { if (!preg_match('/^[0-9]+(K|M|G)?$/i', $sizetarget . $sizeitem, $m)) { $this->errors['tests'][$i]['sizetarget'] = $this->gettext('forbiddenchars'); $this->form['tests'][$i]['item'] = $sizeitem; } else { $this->form['tests'][$i]['arg'] .= $m[1]; } } } else { if ($header == 'body') { $trans = $this->strip_value($body_trans[$idx]); $trans_type = $this->strip_value($body_types[$idx], true); if (preg_match('/^not/', $operator)) { $this->form['tests'][$i]['not'] = true; } $type = preg_replace('/^not/', '', $operator); if ($type == 'exists') { $this->errors['tests'][$i]['op'] = true; } $this->form['tests'][$i]['test'] = 'body'; $this->form['tests'][$i]['type'] = $type; $this->form['tests'][$i]['arg'] = $target; if ($target == '' && $type != 'exists') { $this->errors['tests'][$i]['target'] = $this->gettext('cannotbeempty'); } else { if (preg_match('/^(value|count)-/', $type) && !preg_match('/[0-9]+/', $target)) { $this->errors['tests'][$i]['target'] = $this->gettext('forbiddenchars'); } } $this->form['tests'][$i]['part'] = $trans; if ($trans == 'content') { $this->form['tests'][$i]['content'] = $trans_type; } } else { $cust_header = $headers = $this->strip_value($cust_headers[$idx]); $mod = $this->strip_value($mods[$idx]); $mod_type = $this->strip_value($mod_types[$idx]); if (preg_match('/^not/', $operator)) { $this->form['tests'][$i]['not'] = true; } $type = preg_replace('/^not/', '', $operator); if ($header == '...') { $headers = preg_split('/[\\s,]+/', $cust_header, -1, PREG_SPLIT_NO_EMPTY); if (!count($headers)) { $this->errors['tests'][$i]['header'] = $this->gettext('cannotbeempty'); } else { foreach ($headers as $hr) { if (!preg_match('/^[a-z0-9-]+$/i', $hr)) { $this->errors['tests'][$i]['header'] = $this->gettext('forbiddenchars'); } } } if (empty($this->errors['tests'][$i]['header'])) { $cust_header = is_array($headers) && count($headers) == 1 ? $headers[0] : $headers; } } if ($type == 'exists') { $this->form['tests'][$i]['test'] = 'exists'; $this->form['tests'][$i]['arg'] = $header == '...' ? $cust_header : $header; } else { $test = 'header'; $header = $header == '...' ? $cust_header : $header; if ($mod == 'address' || $mod == 'envelope') { $found = false; if (empty($this->errors['tests'][$i]['header'])) { foreach ((array) $header as $hdr) { if (!in_array(strtolower(trim($hdr)), $this->addr_headers)) { $found = true; } } } if (!$found) { $test = $mod; } } $this->form['tests'][$i]['type'] = $type; $this->form['tests'][$i]['test'] = $test; $this->form['tests'][$i]['arg1'] = $header; $this->form['tests'][$i]['arg2'] = $target; if ($target == '') { $this->errors['tests'][$i]['target'] = $this->gettext('cannotbeempty'); } else { if (preg_match('/^(value|count)-/', $type) && !preg_match('/[0-9]+/', $target)) { $this->errors['tests'][$i]['target'] = $this->gettext('forbiddenchars'); } } if ($mod) { $this->form['tests'][$i]['part'] = $mod_type; } } } } if ($header != 'size' && $comparator) { if (preg_match('/^(value|count)/', $this->form['tests'][$i]['type'])) { $comparator = 'i;ascii-numeric'; } $this->form['tests'][$i]['comparator'] = $comparator; } $i++; } } $i = 0; // actions foreach ($act_types as $idx => $type) { $type = $this->strip_value($type); $target = $this->strip_value($act_targets[$idx]); switch ($type) { case 'fileinto': case 'fileinto_copy': $mailbox = $this->strip_value($mailboxes[$idx]); $this->form['actions'][$i]['target'] = $this->mod_mailbox($mailbox, 'in'); if ($type == 'fileinto_copy') { $type = 'fileinto'; $this->form['actions'][$i]['copy'] = true; } break; case 'reject': case 'ereject': $target = $this->strip_value($area_targets[$idx]); $this->form['actions'][$i]['target'] = str_replace("\r\n", "\n", $target); // if ($target == '') // $this->errors['actions'][$i]['targetarea'] = $this->gettext('cannotbeempty'); break; case 'redirect': case 'redirect_copy': $this->form['actions'][$i]['target'] = $target; if ($this->form['actions'][$i]['target'] == '') { $this->errors['actions'][$i]['target'] = $this->gettext('cannotbeempty'); } else { if (!check_email($this->form['actions'][$i]['target'])) { $this->errors['actions'][$i]['target'] = $this->gettext('noemailwarning'); } } if ($type == 'redirect_copy') { $type = 'redirect'; $this->form['actions'][$i]['copy'] = true; } break; case 'addflag': case 'setflag': case 'removeflag': $_target = array(); if (empty($flags[$idx])) { $this->errors['actions'][$i]['target'] = $this->gettext('noflagset'); } else { foreach ($flags[$idx] as $flag) { $_target[] = $this->strip_value($flag); } } $this->form['actions'][$i]['target'] = $_target; break; case 'vacation': $reason = $this->strip_value($reasons[$idx]); $this->form['actions'][$i]['reason'] = str_replace("\r\n", "\n", $reason); $this->form['actions'][$i]['days'] = $days[$idx]; $this->form['actions'][$i]['subject'] = $subject[$idx]; $this->form['actions'][$i]['addresses'] = explode(',', $addresses[$idx]); // @TODO: vacation :mime, :from, :handle if ($this->form['actions'][$i]['addresses']) { foreach ($this->form['actions'][$i]['addresses'] as $aidx => $address) { $address = trim($address); if (!$address) { unset($this->form['actions'][$i]['addresses'][$aidx]); } else { if (!check_email($address)) { $this->errors['actions'][$i]['addresses'] = $this->gettext('noemailwarning'); break; } else { $this->form['actions'][$i]['addresses'][$aidx] = $address; } } } } if ($this->form['actions'][$i]['reason'] == '') { $this->errors['actions'][$i]['reason'] = $this->gettext('cannotbeempty'); } if ($this->form['actions'][$i]['days'] && !preg_match('/^[0-9]+$/', $this->form['actions'][$i]['days'])) { $this->errors['actions'][$i]['days'] = $this->gettext('forbiddenchars'); } break; } $this->form['actions'][$i]['type'] = $type; $i++; } if (!$this->errors && !$error) { // zapis skryptu if (!isset($this->script[$fid])) { $fid = $this->sieve->script->add_rule($this->form); $new = true; } else { $fid = $this->sieve->script->update_rule($fid, $this->form); } if ($fid !== false) { $save = $this->save_script(); } if ($save && $fid !== false) { $this->rc->output->show_message('managesieve.filtersaved', 'confirmation'); if ($this->rc->task != 'mail') { $this->rc->output->command('parent.managesieve_updatelist', isset($new) ? 'add' : 'update', array('name' => Q($this->form['name']), 'id' => $fid, 'disabled' => $this->form['disabled'])); } else { $this->rc->output->command('managesieve_dialog_close'); $this->rc->output->send('iframe'); } } else { $this->rc->output->show_message('managesieve.filtersaveerror', 'error'); // $this->rc->output->send(); } } } } $this->managesieve_send(); }
/** * */ function import_events($silent = false) { // Upload progress update if (!empty($_GET['_progress'])) { rcube_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 = get_input_value('calendar', RCUBE_INPUT_GPC); $driver = $this->get_driver_by_cal($calendar); $rangestart = $_REQUEST['_range'] ? date_create("now -" . intval($_REQUEST['_range']) . " months") : 0; $user_email = $this->rc->user->get_username(); $ical = $this->get_ical(); $errors = !$ical->fopen($_FILES['_data']['tmp_name']); $count = $i = 0; foreach ($ical as $event) { if (isset($event['recurrence']['EXCEPTIONS'])) { foreach ($event['recurrence']['EXCEPTIONS'] as $idx => $exception) { $event['recurrence']['EXCEPTIONS'][$idx]['uid'] = $event['uid']; } } // End mod by Rosali // keep the browser connection alive on long import jobs if (++$i > 100 && $i % 100 == 0) { echo "<!-- -->"; ob_flush(); } // TODO: correctly handle recurring events which start before $rangestart if ($event['end'] && $event['end'] < $rangestart && (!$event['recurrence'] || $event['recurrence']['until'] && $event['recurrence']['until'] < $rangestart)) { continue; } $event['_owner'] = $user_email; $event['calendar'] = $calendar; if ($driver->new_event($event)) { $count++; } else { $errors++; } } // Begin mod by Rosali if ($silent) { return; } // End mod by Rosali 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 = rcube_label(array('name' => 'filesizeerror', 'vars' => array('size' => show_bytes(parse_bytes(ini_get('upload_max_filesize')))))); } else { $msg = rcube_label('fileuploaderror'); } $this->rc->output->command('plugin.import_error', array('message' => $msg)); $this->rc->output->command('plugin.unlock_saving', false); } $this->rc->output->send('iframe'); }
/** * Get maximum upload size * * @return int Maximum size in bytes */ public static function max_upload_size() { // find max filesize value $max_filesize = parse_bytes(ini_get('upload_max_filesize')); $max_postsize = parse_bytes(ini_get('post_max_size')); if ($max_postsize && $max_postsize < $max_filesize) { $max_filesize = $max_postsize; } return $max_filesize; }
/** * Export events to iCalendar format * * @param array Events as array * @param string VCalendar method to advertise * @param boolean Directly send data to stdout instead of returning * @param callable Callback function to fetch attachment contents, false if no attachment export * @return string Events in iCalendar format (http://tools.ietf.org/html/rfc5545) */ public function export($objects, $method = null, $write = false, $get_attachment = false, $recurrence_id = null) { $memory_limit = parse_bytes(ini_get('memory_limit')); $this->method = $method; // encapsulate in VCALENDAR container $vcal = VObject\Component::create('VCALENDAR'); $vcal->version = '2.0'; $vcal->prodid = $this->prodid; $vcal->calscale = 'GREGORIAN'; if (!empty($method)) { $vcal->METHOD = $method; } // TODO: include timezone information // write vcalendar header if ($write) { echo preg_replace('/END:VCALENDAR[\\r\\n]*$/m', '', $vcal->serialize()); } foreach ($objects as $object) { $this->_to_ical($object, !$write ? $vcal : false, $get_attachment); } if ($write) { echo "END:VCALENDAR\r\n"; return true; } else { return $vcal->serialize(); } }
| | +-----------------------------------------------------------------------+ | Author: Thomas Bruederli <*****@*****.**> | +-----------------------------------------------------------------------+ */ // suppress php notices @ini_set('error_reporting', E_ALL & ~E_NOTICE); // include the converter class file require_once 'vcard_convert.php'; require_once 'utils.php'; if (!empty($_FILES['_vcards'])) { // instantiate a parser object $conv = new vcard_convert(array('mailonly' => !empty($_POST['_mailonly']), 'phoneonly' => !empty($_POST['_phoneonly']), 'accesscode' => preg_replace('/[^1-9]/', '', $_POST['_accesscode']))); // check for errors if ($err = $_FILES['_vcards']['error']) { $GLOBALS['error_msg'] = $err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE ? "The uploaded file was too big! Maximum file size allowed: " . show_bytes(parse_bytes(ini_get('upload_max_filesize'))) : "Upload failed, please try again"; } else { if ($conv->fromFile($_FILES['_vcards']['tmp_name'])) { $ext = $_POST['_format'] == 'gmail' ? 'csv' : ($_POST['_format'] == 'img' ? 'zip' : $_POST['_format']); $fname = asciiwords(preg_replace('/\\.[a-z]+$/i', '', $_FILES['_vcards']['name'])); header(sprintf('Content-Type: text/%s', $ext)); header(sprintf('Content-Disposition: attachment; filename="%s.%s"', $fname, $ext)); if ($_POST['_format'] == 'ldif') { print $conv->toLdif(); exit; } else { if ($_POST['_format'] == 'ldap') { // Clean the input dn modifier from dangerous chars $dnID = substr(preg_replace('/[^\\da-z=,_ -]/i', '', $_POST['_dn']), 0, 255); print $conv->toLdif($dnID ? $dnID : "", null, $_POST['_encoding']); exit;
function save() { // Init plugin and handle managesieve connection $error = $this->start(); // get request size limits (#1488648) $max_post = max(array(ini_get('max_input_vars'), ini_get('suhosin.request.max_vars'), ini_get('suhosin.post.max_vars'))); $max_depth = max(array(ini_get('suhosin.request.max_array_depth'), ini_get('suhosin.post.max_array_depth'))); // check request size limit if ($max_post && count($_POST, COUNT_RECURSIVE) >= $max_post) { rcube::raise_error(array('code' => 500, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Request size limit exceeded (one of max_input_vars/suhosin.request.max_vars/suhosin.post.max_vars)"), true, false); $this->rc->output->show_message('managesieve.filtersaveerror', 'error'); } else { if ($max_depth && count($_POST['_header']) > $max_depth) { rcube::raise_error(array('code' => 500, 'type' => 'php', 'file' => __FILE__, 'line' => __LINE__, 'message' => "Request size limit exceeded (one of suhosin.request.max_array_depth/suhosin.post.max_array_depth)"), true, false); $this->rc->output->show_message('managesieve.filtersaveerror', 'error'); } else { if (!empty($_POST['_newset'])) { $name = rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST, true); $copy = rcube_utils::get_input_value('_copy', rcube_utils::INPUT_POST, true); $from = rcube_utils::get_input_value('_from', rcube_utils::INPUT_POST); $exceptions = $this->rc->config->get('managesieve_filename_exceptions'); $kolab = $this->rc->config->get('managesieve_kolab_master'); $name_uc = mb_strtolower($name); $list = $this->list_scripts(); if (!$name) { $this->errors['name'] = $this->plugin->gettext('cannotbeempty'); } else { if (mb_strlen($name) > 128) { $this->errors['name'] = $this->plugin->gettext('nametoolong'); } else { if (!empty($exceptions) && in_array($name, (array) $exceptions)) { $this->errors['name'] = $this->plugin->gettext('namereserved'); } else { if (!empty($kolab) && in_array($name_uc, array('MASTER', 'USER', 'MANAGEMENT'))) { $this->errors['name'] = $this->plugin->gettext('namereserved'); } else { if (in_array($name, $list)) { $this->errors['name'] = $this->plugin->gettext('setexist'); } else { if ($from == 'file') { // from file if (is_uploaded_file($_FILES['_file']['tmp_name'])) { $file = file_get_contents($_FILES['_file']['tmp_name']); $file = preg_replace('/\\r/', '', $file); // for security don't save script directly // check syntax before, like this... $this->sieve->load_script($file); if (!$this->save_script($name)) { $this->errors['file'] = $this->plugin->gettext('setcreateerror'); } } else { // upload failed $err = $_FILES['_file']['error']; if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) { $msg = $this->rc->gettext(array('name' => 'filesizeerror', 'vars' => array('size' => $this->rc->show_bytes(parse_bytes(ini_get('upload_max_filesize')))))); } else { $this->errors['file'] = $this->plugin->gettext('fileuploaderror'); } } } else { if (!$this->sieve->copy($name, $from == 'set' ? $copy : '')) { $error = 'managesieve.setcreateerror'; } } } } } } } if (!$error && empty($this->errors)) { // Find position of the new script on the list $list[] = $name; asort($list, SORT_LOCALE_STRING); $list = array_values($list); $index = array_search($name, $list); $this->rc->output->show_message('managesieve.setcreated', 'confirmation'); $this->rc->output->command('parent.managesieve_updatelist', 'setadd', array('name' => $name, 'index' => $index)); } else { if ($msg) { $this->rc->output->command('display_message', $msg, 'error'); } else { if ($error) { $this->rc->output->show_message($error, 'error'); } } } } else { if (isset($_POST['_name'])) { $name = trim(rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST, true)); $fid = trim(rcube_utils::get_input_value('_fid', rcube_utils::INPUT_POST)); $join = trim(rcube_utils::get_input_value('_join', rcube_utils::INPUT_POST)); // and arrays $headers = rcube_utils::get_input_value('_header', rcube_utils::INPUT_POST); $cust_headers = rcube_utils::get_input_value('_custom_header', rcube_utils::INPUT_POST); $ops = rcube_utils::get_input_value('_rule_op', rcube_utils::INPUT_POST); $sizeops = rcube_utils::get_input_value('_rule_size_op', rcube_utils::INPUT_POST); $sizeitems = rcube_utils::get_input_value('_rule_size_item', rcube_utils::INPUT_POST); $sizetargets = rcube_utils::get_input_value('_rule_size_target', rcube_utils::INPUT_POST); $targets = rcube_utils::get_input_value('_rule_target', rcube_utils::INPUT_POST, true); $mods = rcube_utils::get_input_value('_rule_mod', rcube_utils::INPUT_POST); $mod_types = rcube_utils::get_input_value('_rule_mod_type', rcube_utils::INPUT_POST); $body_trans = rcube_utils::get_input_value('_rule_trans', rcube_utils::INPUT_POST); $body_types = rcube_utils::get_input_value('_rule_trans_type', rcube_utils::INPUT_POST, true); $comparators = rcube_utils::get_input_value('_rule_comp', rcube_utils::INPUT_POST); $indexes = rcube_utils::get_input_value('_rule_index', rcube_utils::INPUT_POST); $lastindexes = rcube_utils::get_input_value('_rule_index_last', rcube_utils::INPUT_POST); $dateheaders = rcube_utils::get_input_value('_rule_date_header', rcube_utils::INPUT_POST); $dateparts = rcube_utils::get_input_value('_rule_date_part', rcube_utils::INPUT_POST); $act_types = rcube_utils::get_input_value('_action_type', rcube_utils::INPUT_POST, true); $mailboxes = rcube_utils::get_input_value('_action_mailbox', rcube_utils::INPUT_POST, true); $act_targets = rcube_utils::get_input_value('_action_target', rcube_utils::INPUT_POST, true); $domain_targets = rcube_utils::get_input_value('_action_target_domain', rcube_utils::INPUT_POST); $area_targets = rcube_utils::get_input_value('_action_target_area', rcube_utils::INPUT_POST, true); $reasons = rcube_utils::get_input_value('_action_reason', rcube_utils::INPUT_POST, true); $addresses = rcube_utils::get_input_value('_action_addresses', rcube_utils::INPUT_POST, true); $intervals = rcube_utils::get_input_value('_action_interval', rcube_utils::INPUT_POST); $interval_types = rcube_utils::get_input_value('_action_interval_type', rcube_utils::INPUT_POST); $subject = rcube_utils::get_input_value('_action_subject', rcube_utils::INPUT_POST, true); $flags = rcube_utils::get_input_value('_action_flags', rcube_utils::INPUT_POST); $varnames = rcube_utils::get_input_value('_action_varname', rcube_utils::INPUT_POST); $varvalues = rcube_utils::get_input_value('_action_varvalue', rcube_utils::INPUT_POST); $varmods = rcube_utils::get_input_value('_action_varmods', rcube_utils::INPUT_POST); $notifymethods = rcube_utils::get_input_value('_action_notifymethod', rcube_utils::INPUT_POST); $notifytargets = rcube_utils::get_input_value('_action_notifytarget', rcube_utils::INPUT_POST, true); $notifyoptions = rcube_utils::get_input_value('_action_notifyoption', rcube_utils::INPUT_POST, true); $notifymessages = rcube_utils::get_input_value('_action_notifymessage', rcube_utils::INPUT_POST, true); $notifyfrom = rcube_utils::get_input_value('_action_notifyfrom', rcube_utils::INPUT_POST); $notifyimp = rcube_utils::get_input_value('_action_notifyimportance', rcube_utils::INPUT_POST); // we need a "hack" for radiobuttons foreach ($sizeitems as $item) { $items[] = $item; } $this->form['disabled'] = $_POST['_disabled'] ? true : false; $this->form['join'] = $join == 'allof' ? true : false; $this->form['name'] = $name; $this->form['tests'] = array(); $this->form['actions'] = array(); if ($name == '') { $this->errors['name'] = $this->plugin->gettext('cannotbeempty'); } else { foreach ($this->script as $idx => $rule) { if ($rule['name'] == $name && $idx != $fid) { $this->errors['name'] = $this->plugin->gettext('ruleexist'); break; } } } $i = 0; // rules if ($join == 'any') { $this->form['tests'][0]['test'] = 'true'; } else { foreach ($headers as $idx => $header) { // targets are indexed differently (assume form order) $target = $this->strip_value(array_shift($targets), true); $header = $this->strip_value($header); $operator = $this->strip_value($ops[$idx]); $comparator = $this->strip_value($comparators[$idx]); if ($header == 'size') { $sizeop = $this->strip_value($sizeops[$idx]); $sizeitem = $this->strip_value($items[$idx]); $sizetarget = $this->strip_value($sizetargets[$idx]); $this->form['tests'][$i]['test'] = 'size'; $this->form['tests'][$i]['type'] = $sizeop; $this->form['tests'][$i]['arg'] = $sizetarget; if ($sizetarget == '') { $this->errors['tests'][$i]['sizetarget'] = $this->plugin->gettext('cannotbeempty'); } else { if (!preg_match('/^[0-9]+(K|M|G)?$/i', $sizetarget . $sizeitem, $m)) { $this->errors['tests'][$i]['sizetarget'] = $this->plugin->gettext('forbiddenchars'); $this->form['tests'][$i]['item'] = $sizeitem; } else { $this->form['tests'][$i]['arg'] .= $m[1]; } } } else { if ($header == 'currentdate') { $datepart = $this->strip_value($dateparts[$idx]); if (preg_match('/^not/', $operator)) { $this->form['tests'][$i]['not'] = true; } $type = preg_replace('/^not/', '', $operator); if ($type == 'exists') { $this->errors['tests'][$i]['op'] = true; } $this->form['tests'][$i]['test'] = 'currentdate'; $this->form['tests'][$i]['type'] = $type; $this->form['tests'][$i]['part'] = $datepart; $this->form['tests'][$i]['arg'] = $target; if ($type != 'exists') { if (!count($target)) { $this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty'); } else { if (strpos($type, 'count-') === 0) { foreach ($target as $arg) { if (preg_match('/[^0-9]/', $arg)) { $this->errors['tests'][$i]['target'] = $this->plugin->gettext('forbiddenchars'); } } } else { if (strpos($type, 'value-') === 0) { // Some date/time formats do not support i;ascii-numeric comparator if ($comparator == 'i;ascii-numeric' && in_array($datepart, array('date', 'time', 'iso8601', 'std11'))) { $comparator = ''; } } } } if (!preg_match('/^(regex|matches|count-)/', $type) && count($target)) { foreach ($target as $arg) { if (!$this->validate_date_part($datepart, $arg)) { $this->errors['tests'][$i]['target'] = $this->plugin->gettext('invaliddateformat'); break; } } } } } else { if ($header == 'date') { $datepart = $this->strip_value($dateparts[$idx]); $dateheader = $this->strip_value($dateheaders[$idx]); $index = $this->strip_value($indexes[$idx]); $indexlast = $this->strip_value($lastindexes[$idx]); if (preg_match('/^not/', $operator)) { $this->form['tests'][$i]['not'] = true; } $type = preg_replace('/^not/', '', $operator); if ($type == 'exists') { $this->errors['tests'][$i]['op'] = true; } if (!empty($index) && $mod != 'envelope') { $this->form['tests'][$i]['index'] = intval($index); $this->form['tests'][$i]['last'] = !empty($indexlast); } if (empty($dateheader)) { $dateheader = 'Date'; } else { if (!preg_match('/^[\\x21-\\x39\\x41-\\x7E]+$/i', $dateheader)) { $this->errors['tests'][$i]['dateheader'] = $this->plugin->gettext('forbiddenchars'); } } $this->form['tests'][$i]['test'] = 'date'; $this->form['tests'][$i]['type'] = $type; $this->form['tests'][$i]['part'] = $datepart; $this->form['tests'][$i]['arg'] = $target; $this->form['tests'][$i]['header'] = $dateheader; if ($type != 'exists') { if (!count($target)) { $this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty'); } else { if (strpos($type, 'count-') === 0) { foreach ($target as $arg) { if (preg_match('/[^0-9]/', $arg)) { $this->errors['tests'][$i]['target'] = $this->plugin->gettext('forbiddenchars'); } } } else { if (strpos($type, 'value-') === 0) { // Some date/time formats do not support i;ascii-numeric comparator if ($comparator == 'i;ascii-numeric' && in_array($datepart, array('date', 'time', 'iso8601', 'std11'))) { $comparator = ''; } } } } if (count($target) && !preg_match('/^(regex|matches|count-)/', $type)) { foreach ($target as $arg) { if (!$this->validate_date_part($datepart, $arg)) { $this->errors['tests'][$i]['target'] = $this->plugin->gettext('invaliddateformat'); break; } } } } } else { if ($header == 'body') { $trans = $this->strip_value($body_trans[$idx]); $trans_type = $this->strip_value($body_types[$idx], true); if (preg_match('/^not/', $operator)) { $this->form['tests'][$i]['not'] = true; } $type = preg_replace('/^not/', '', $operator); if ($type == 'exists') { $this->errors['tests'][$i]['op'] = true; } $this->form['tests'][$i]['test'] = 'body'; $this->form['tests'][$i]['type'] = $type; $this->form['tests'][$i]['arg'] = $target; if (empty($target) && $type != 'exists') { $this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty'); } else { if (preg_match('/^(value|count)-/', $type)) { foreach ($target as $target_value) { if (preg_match('/[^0-9]/', $target_value)) { $this->errors['tests'][$i]['target'] = $this->plugin->gettext('forbiddenchars'); } } } } $this->form['tests'][$i]['part'] = $trans; if ($trans == 'content') { $this->form['tests'][$i]['content'] = $trans_type; } } else { $cust_header = $headers = $this->strip_value(array_shift($cust_headers)); $mod = $this->strip_value($mods[$idx]); $mod_type = $this->strip_value($mod_types[$idx]); $index = $this->strip_value($indexes[$idx]); $indexlast = $this->strip_value($lastindexes[$idx]); if (preg_match('/^not/', $operator)) { $this->form['tests'][$i]['not'] = true; } $type = preg_replace('/^not/', '', $operator); if (!empty($index) && $mod != 'envelope') { $this->form['tests'][$i]['index'] = intval($index); $this->form['tests'][$i]['last'] = !empty($indexlast); } if ($header == '...') { if (!count($headers)) { $this->errors['tests'][$i]['header'] = $this->plugin->gettext('cannotbeempty'); } else { foreach ($headers as $hr) { // RFC2822: printable ASCII except colon if (!preg_match('/^[\\x21-\\x39\\x41-\\x7E]+$/i', $hr)) { $this->errors['tests'][$i]['header'] = $this->plugin->gettext('forbiddenchars'); } } } if (empty($this->errors['tests'][$i]['header'])) { $cust_header = is_array($headers) && count($headers) == 1 ? $headers[0] : $headers; } } $header = $header == '...' ? $cust_header : $header; if (is_array($header)) { foreach ($header as $h_index => $val) { if (isset($this->headers[$val])) { $header[$h_index] = $this->headers[$val]; } } } if ($type == 'exists') { $this->form['tests'][$i]['test'] = 'exists'; $this->form['tests'][$i]['arg'] = $header; } else { $test = 'header'; if ($mod == 'address' || $mod == 'envelope') { $found = false; if (empty($this->errors['tests'][$i]['header'])) { foreach ((array) $header as $hdr) { if (!in_array(strtolower(trim($hdr)), $this->addr_headers)) { $found = true; } } } if (!$found) { $test = $mod; } } $this->form['tests'][$i]['type'] = $type; $this->form['tests'][$i]['test'] = $test; $this->form['tests'][$i]['arg1'] = $header; $this->form['tests'][$i]['arg2'] = $target; if (empty($target)) { $this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty'); } else { if (preg_match('/^(value|count)-/', $type)) { foreach ($target as $target_value) { if (preg_match('/[^0-9]/', $target_value)) { $this->errors['tests'][$i]['target'] = $this->plugin->gettext('forbiddenchars'); } } } } if ($mod) { $this->form['tests'][$i]['part'] = $mod_type; } } } } } } if ($header != 'size' && $comparator) { $this->form['tests'][$i]['comparator'] = $comparator; } $i++; } } $i = 0; // actions foreach ($act_types as $idx => $type) { $type = $this->strip_value($type); switch ($type) { case 'fileinto': case 'fileinto_copy': $mailbox = $this->strip_value($mailboxes[$idx], false, false); $this->form['actions'][$i]['target'] = $this->mod_mailbox($mailbox, 'in'); if ($type == 'fileinto_copy') { $type = 'fileinto'; $this->form['actions'][$i]['copy'] = true; } break; case 'reject': case 'ereject': $target = $this->strip_value($area_targets[$idx]); $this->form['actions'][$i]['target'] = str_replace("\r\n", "\n", $target); // if ($target == '') // $this->errors['actions'][$i]['targetarea'] = $this->plugin->gettext('cannotbeempty'); break; case 'redirect': case 'redirect_copy': $target = $this->strip_value($act_targets[$idx]); $domain = $this->strip_value($domain_targets[$idx]); // force one of the configured domains $domains = (array) $this->rc->config->get('managesieve_domains'); if (!empty($domains) && !empty($target)) { if (!$domain || !in_array($domain, $domains)) { $domain = $domains[0]; } $target .= '@' . $domain; } $this->form['actions'][$i]['target'] = $target; if ($target == '') { $this->errors['actions'][$i]['target'] = $this->plugin->gettext('cannotbeempty'); } else { if (!rcube_utils::check_email($target)) { $this->errors['actions'][$i]['target'] = $this->plugin->gettext(!empty($domains) ? 'forbiddenchars' : 'noemailwarning'); } } if ($type == 'redirect_copy') { $type = 'redirect'; $this->form['actions'][$i]['copy'] = true; } break; case 'addflag': case 'setflag': case 'removeflag': $_target = array(); if (empty($flags[$idx])) { $this->errors['actions'][$i]['target'] = $this->plugin->gettext('noflagset'); } else { foreach ($flags[$idx] as $flag) { $_target[] = $this->strip_value($flag); } } $this->form['actions'][$i]['target'] = $_target; break; case 'vacation': $reason = $this->strip_value($reasons[$idx]); $interval_type = $interval_types[$idx] == 'seconds' ? 'seconds' : 'days'; $this->form['actions'][$i]['reason'] = str_replace("\r\n", "\n", $reason); $this->form['actions'][$i]['subject'] = $subject[$idx]; $this->form['actions'][$i]['addresses'] = array_shift($addresses); $this->form['actions'][$i][$interval_type] = $intervals[$idx]; // @TODO: vacation :mime, :from, :handle foreach ((array) $this->form['actions'][$i]['addresses'] as $aidx => $address) { $this->form['actions'][$i]['addresses'][$aidx] = $address = trim($address); if (empty($address)) { unset($this->form['actions'][$i]['addresses'][$aidx]); } else { if (!rcube_utils::check_email($address)) { $this->errors['actions'][$i]['addresses'] = $this->plugin->gettext('noemailwarning'); break; } } } if ($this->form['actions'][$i]['reason'] == '') { $this->errors['actions'][$i]['reason'] = $this->plugin->gettext('cannotbeempty'); } if ($this->form['actions'][$i][$interval_type] && !preg_match('/^[0-9]+$/', $this->form['actions'][$i][$interval_type])) { $this->errors['actions'][$i]['interval'] = $this->plugin->gettext('forbiddenchars'); } break; case 'set': $this->form['actions'][$i]['name'] = $varnames[$idx]; $this->form['actions'][$i]['value'] = $varvalues[$idx]; foreach ((array) $varmods[$idx] as $v_m) { $this->form['actions'][$i][$v_m] = true; } if (empty($varnames[$idx])) { $this->errors['actions'][$i]['name'] = $this->plugin->gettext('cannotbeempty'); } else { if (!preg_match('/^[0-9a-z_]+$/i', $varnames[$idx])) { $this->errors['actions'][$i]['name'] = $this->plugin->gettext('forbiddenchars'); } } if (!isset($varvalues[$idx]) || $varvalues[$idx] === '') { $this->errors['actions'][$i]['value'] = $this->plugin->gettext('cannotbeempty'); } break; case 'notify': if (empty($notifymethods[$idx])) { $this->errors['actions'][$i]['method'] = $this->plugin->gettext('cannotbeempty'); } if (empty($notifytargets[$idx])) { $this->errors['actions'][$i]['target'] = $this->plugin->gettext('cannotbeempty'); } if (!empty($notifyfrom[$idx]) && !rcube_utils::check_email($notifyfrom[$idx])) { $this->errors['actions'][$i]['from'] = $this->plugin->gettext('noemailwarning'); } // skip empty options foreach ((array) $notifyoptions[$idx] as $opt_idx => $opt) { if (!strlen(trim($opt))) { unset($notifyoptions[$idx][$opt_idx]); } } $this->form['actions'][$i]['method'] = $notifymethods[$idx] . ':' . $notifytargets[$idx]; $this->form['actions'][$i]['options'] = $notifyoptions[$idx]; $this->form['actions'][$i]['message'] = $notifymessages[$idx]; $this->form['actions'][$i]['from'] = $notifyfrom[$idx]; $this->form['actions'][$i]['importance'] = $notifyimp[$idx]; break; } $this->form['actions'][$i]['type'] = $type; $i++; } if (!$this->errors && !$error) { // save the script if (!isset($this->script[$fid])) { $fid = $this->sieve->script->add_rule($this->form); $new = true; } else { $fid = $this->sieve->script->update_rule($fid, $this->form); } if ($fid !== false) { $save = $this->save_script(); } if ($save && $fid !== false) { $this->rc->output->show_message('managesieve.filtersaved', 'confirmation'); if ($this->rc->task != 'mail') { $this->rc->output->command('parent.managesieve_updatelist', isset($new) ? 'add' : 'update', array('name' => $this->form['name'], 'id' => $fid, 'disabled' => $this->form['disabled'])); } else { $this->rc->output->command('managesieve_dialog_close'); $this->rc->output->send('iframe'); } } else { $this->rc->output->show_message('managesieve.filtersaveerror', 'error'); // $this->rc->output->send(); } } } } } } $this->send(); }
/** * Handler for attachment uploads */ public function attachment_upload($session_key, $id_prefix = '') { // Upload progress update if (!empty($_GET['_progress'])) { $this->rc->upload_progress(); } $recid = $id_prefix . rcube_utils::get_input_value('_id', rcube_utils::INPUT_GPC); $uploadid = rcube_utils::get_input_value('_uploadid', rcube_utils::INPUT_GPC); if (!is_array($_SESSION[$session_key]) || $_SESSION[$session_key]['id'] != $recid) { $_SESSION[$session_key] = array(); $_SESSION[$session_key]['id'] = $recid; $_SESSION[$session_key]['attachments'] = array(); } // clear all stored output properties (like scripts and env vars) $this->rc->output->reset(); if (is_array($_FILES['_attachments']['tmp_name'])) { foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath) { // Process uploaded attachment if there is no error $err = $_FILES['_attachments']['error'][$i]; if (!$err) { $attachment = array('path' => $filepath, 'size' => $_FILES['_attachments']['size'][$i], 'name' => $_FILES['_attachments']['name'][$i], 'mimetype' => rcube_mime::file_content_type($filepath, $_FILES['_attachments']['name'][$i], $_FILES['_attachments']['type'][$i]), 'group' => $recid); $attachment = $this->rc->plugins->exec_hook('attachment_upload', $attachment); } if (!$err && $attachment['status'] && !$attachment['abort']) { $id = $attachment['id']; // store new attachment in session unset($attachment['status'], $attachment['abort']); $_SESSION[$session_key]['attachments'][$id] = $attachment; if (($icon = $_SESSION[$session_key . '_deleteicon']) && is_file($icon)) { $button = html::img(array('src' => $icon, 'alt' => $this->rc->gettext('delete'))); } else { $button = rcube::Q($this->rc->gettext('delete')); } $content = html::a(array('href' => "#delete", 'class' => 'delete', 'onclick' => sprintf("return %s.remove_from_attachment_list('rcmfile%s')", rcmail_output::JS_OBJECT_NAME, $id), 'title' => $this->rc->gettext('delete'), 'aria-label' => $this->rc->gettext('delete') . ' ' . $attachment['name']), $button); $content .= rcube::Q($attachment['name']); $this->rc->output->command('add2attachment_list', "rcmfile{$id}", array('html' => $content, 'name' => $attachment['name'], 'mimetype' => $attachment['mimetype'], 'classname' => rcube_utils::file2class($attachment['mimetype'], $attachment['name']), 'complete' => true), $uploadid); } else { // upload failed if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) { $msg = $this->rc->gettext(array('name' => 'filesizeerror', 'vars' => array('size' => $this->rc->show_bytes(parse_bytes(ini_get('upload_max_filesize')))))); } else { if ($attachment['error']) { $msg = $attachment['error']; } else { $msg = $this->rc->gettext('fileuploaderror'); } } $this->rc->output->command('display_message', $msg, 'error'); $this->rc->output->command('remove_from_attachment_list', $uploadid); } } } else { if ($_SERVER['REQUEST_METHOD'] == 'POST') { // if filesize exceeds post_max_size then $_FILES array is empty, // show filesizeerror instead of fileuploaderror if ($maxsize = ini_get('post_max_size')) { $msg = $this->rc->gettext(array('name' => 'filesizeerror', 'vars' => array('size' => $this->rc->show_bytes(parse_bytes($maxsize))))); } else { $msg = $this->rc->gettext('fileuploaderror'); } $this->rc->output->command('display_message', $msg, 'error'); $this->rc->output->command('remove_from_attachment_list', $uploadid); } } $this->rc->output->send('iframe'); }
/** * Build a valid iCal format block from the given event * * @param array Hash array with event/task properties from libkolab * @param object VCalendar object to append event to or false for directly sending data to stdout * @param callable Callback function to fetch attachment contents, false if no attachment export * @param object RECURRENCE-ID property when serializing a recurrence exception */ private function _to_ical($event, $vcal, $get_attachment, $recurrence_id = null) { $type = $event['_type'] ?: 'event'; $vcal_creator = new VObject\Component\VCalendar(); $ve = $vcal_creator->createComponent($this->type_component_map[$type]); $ve->add('UID', $event['uid']); // set DTSTAMP according to RFC 5545, 3.8.7.2. $dtstamp = !empty($event['changed']) && !empty($this->method) ? $event['changed'] : new DateTime(); $ve->add('DTSTAMP', $dtstamp); if ($event['allday']) { $ve->DTSTAMP['VALUE'] = 'DATE'; } if (!empty($event['created'])) { $ve->add('CREATED', $event['created']); } if (!empty($event['changed'])) { $ve->add('LAST-MODIFIED', $event['changed']); } if (!empty($event['start'])) { $ve->add('DTSTART', $event['start']); } if ($event['allday']) { $ve->DTSTART['VALUE'] = 'DATE'; } if (!empty($event['end'])) { $ve->add('DTEND', $event['end']); } if ($event['allday']) { $ve->DTEND['VALUE'] = 'DATE'; } if (!empty($event['due'])) { $ve->add('DUE', $event['due']); } // we're exporting a recurrence instance only if (!$recurrence_id && $event['recurrence_date'] && $event['recurrence_date'] instanceof DateTime) { $recurrence_id = $vcal_creator->createProperty('RECURRENCE-ID'); $recurrence_id->setDateTime($event['recurrence_date']); if ($event['allday']) { $recurrence_id['VALUE'] = 'DATE'; } if ($event['thisandfuture']) { $recurrence_id->add('RANGE', 'THISANDFUTURE'); } } if ($recurrence_id) { $ve->add($recurrence_id); } $ve->add('SUMMARY', $event['title']); if ($event['location']) { $ve->add('LOCATION', $event['location']); } if ($event['description']) { $ve->add('DESCRIPTION', strtr($event['description'], array("\r\n" => "\n", "\r" => "\n"))); } // normalize line endings if (isset($event['sequence'])) { $ve->add('SEQUENCE', $event['sequence']); } if ($event['recurrence'] && !$recurrence_id) { $exdates = $rdates = null; if (isset($event['recurrence']['EXDATE'])) { $exdates = $event['recurrence']['EXDATE']; unset($event['recurrence']['EXDATE']); // don't serialize EXDATEs into RRULE value } if (isset($event['recurrence']['RDATE'])) { $rdates = $event['recurrence']['RDATE']; unset($event['recurrence']['RDATE']); // don't serialize RDATEs into RRULE value } if ($event['recurrence']['FREQ']) { $ve->add('RRULE', libcalendaring::to_rrule($event['recurrence'], (bool) $event['allday'])); } // add EXDATEs each one per line (for Thunderbird Lightning) if (is_array($exdates)) { foreach ($exdates as $ex) { $ve->add('EXDATE', $ex); } } // add RDATEs if (is_array($rdates) && !empty($rdates)) { $ve->RDATE = $rdates; } } if ($event['categories']) { $ve->add('CATEGORIES', (array) $event['categories']); } if (!empty($event['free_busy'])) { $ve->add('TRANSP', $event['free_busy'] == 'free' ? 'TRANSPARENT' : 'OPAQUE'); // for Outlook clients we provide the X-MICROSOFT-CDO-BUSYSTATUS property if (stripos($this->agent, 'outlook') !== false) { $ve->add('X-MICROSOFT-CDO-BUSYSTATUS', $event['free_busy'] == 'outofoffice' ? 'OOF' : strtoupper($event['free_busy'])); } } if ($event['priority']) { $ve->add('PRIORITY', $event['priority']); } if ($event['cancelled']) { $ve->add('STATUS', 'CANCELLED'); } else { if ($event['free_busy'] == 'tentative') { $ve->add('STATUS', 'TENTATIVE'); } else { if ($event['complete'] == 100) { $ve->add('STATUS', 'COMPLETED'); } else { if (!empty($event['status'])) { $ve->add('STATUS', $event['status']); } } } } if (!empty($event['sensitivity'])) { $ve->add('CLASS', strtoupper($event['sensitivity'])); } if (!empty($event['complete'])) { $ve->add('PERCENT-COMPLETE', intval($event['complete'])); } // Apple iCal and BusyCal required the COMPLETED date to be set in order to consider a task complete if ($event['status'] == 'COMPLETED' || $event['complete'] == 100) { $ve->add('COMPLETED', $event['changed'] ?: new DateTime('now - 1 hour'), true); } if ($event['valarms']) { foreach ($event['valarms'] as $alarm) { $va = $vcal_creator->createComponent('VALARM'); $va->ACTION = $alarm['action']; if ($alarm['trigger'] instanceof DateTime) { $va->add('TRIGGER', $alarm['trigger']); } else { $va->add('TRIGGER', $alarm['trigger']); if (strtoupper($alarm['related']) == 'END') { $va->TRIGGER['RELATED'] = 'END'; } } if ($alarm['action'] == 'EMAIL') { foreach ((array) $alarm['attendees'] as $attendee) { $va->add('ATTENDEE', 'mailto:' . $attendee); } } if ($alarm['description']) { $va->add('DESCRIPTION', $alarm['description'] ?: $event['title']); } if ($alarm['summary']) { $va->add('SUMMARY', $alarm['summary']); } if ($alarm['duration']) { $va->add('DURATION', $alarm['duration']); $va->add('REPEAT', intval($alarm['repeat'])); } if ($alarm['uri']) { $va->add('ATTACH', $alarm['uri'], array('VALUE' => 'URI')); } $ve->add($va); } } else { if ($event['alarms']) { $va = $vcal_creator->createComponent('VALARM'); list($trigger, $va->action) = explode(':', $event['alarms']); $val = libcalendaring::parse_alarm_value($trigger); if ($val[3]) { $va->add('TRIGGER', $val[3]); } else { if ($val[0] instanceof DateTime) { $va->add('TRIGGER', $val[0]); } } $ve->add($va); } } foreach ((array) $event['attendees'] as $attendee) { if ($attendee['role'] == 'ORGANIZER') { if (empty($event['organizer'])) { $event['organizer'] = $attendee; } } else { if (!empty($attendee['email'])) { if (isset($attendee['rsvp'])) { $attendee['rsvp'] = $attendee['rsvp'] ? 'TRUE' : null; } $ve->add('ATTENDEE', 'mailto:' . $attendee['email'], array_filter(self::map_keys($attendee, $this->attendee_keymap))); } } } if ($event['organizer']) { $ve->add('ORGANIZER', 'mailto:' . $event['organizer']['email'], self::map_keys($event['organizer'], array('name' => 'CN'))); } foreach ((array) $event['url'] as $url) { if (!empty($url)) { $ve->add('URL', $url); } } if (!empty($event['parent_id'])) { $ve->add('RELATED-TO', $event['parent_id'], array('RELTYPE' => 'PARENT')); } if ($event['comment']) { $ve->add('COMMENT', $event['comment']); } $memory_limit = parse_bytes(ini_get('memory_limit')); // export attachments if (!empty($event['attachments'])) { foreach ((array) $event['attachments'] as $attach) { // check available memory and skip attachment export if we can't buffer it // @todo: use rcube_utils::mem_check() if (is_callable($get_attachment) && $memory_limit > 0 && ($memory_used = function_exists('memory_get_usage') ? memory_get_usage() : 16 * 1024 * 1024) && $attach['size'] && $memory_used + $attach['size'] * 3 > $memory_limit) { continue; } // embed attachments using the given callback function if (is_callable($get_attachment) && ($data = call_user_func($get_attachment, $attach['id'], $event))) { // embed attachments for iCal $ve->add('ATTACH', base64_encode($data), array_filter(array('VALUE' => 'BINARY', 'ENCODING' => 'BASE64', 'FMTTYPE' => $attach['mimetype'], 'X-LABEL' => $attach['name']))); unset($data); // attempt to free memory } else { if (!empty($this->attach_uri)) { $ve->add('ATTACH', strtr($this->attach_uri, array('{{id}}' => urlencode($attach['id']), '{{name}}' => urlencode($attach['name']), '{{mimetype}}' => urlencode($attach['mimetype']))), array('FMTTYPE' => $attach['mimetype'], 'VALUE' => 'URI')); } } } } foreach ((array) $event['links'] as $uri) { $ve->add('ATTACH', $uri); } // add custom properties foreach ((array) $event['x-custom'] as $prop) { $ve->add($prop[0], $prop[1]); } // append to vcalendar container if ($vcal) { $vcal->add($ve); } else { // serialize and send to stdout echo $ve->serialize(); } // append recurrence exceptions if (is_array($event['recurrence']) && $event['recurrence']['EXCEPTIONS']) { foreach ($event['recurrence']['EXCEPTIONS'] as $ex) { $exdate = $ex['recurrence_date'] ?: $ex['start']; $recurrence_id = $vcal_crator->createProperty('RECURRENCE-ID'); $recurrence_id->setDateTime($exdate); if ($event['allday']) { $recurrence_id['VALUE'] = 'DATE'; } if ($ex['thisandfuture']) { $recurrence_id->add('RANGE', 'THISANDFUTURE'); } $this->_to_ical($ex, $vcal, $get_attachment, $recurrence_id); } } }
/** * Initializes file uploading interface. * * @param $int Optional maximum file size in bytes */ public function upload_init($max_size = null) { // Enable upload progress bar if ($seconds = $this->config->get('upload_progress')) { if (function_exists('uploadprogress_get_info')) { $field_name = 'UPLOAD_IDENTIFIER'; } if (!$field_name && filter_var(ini_get('apc.rfc1867'), FILTER_VALIDATE_BOOLEAN)) { $field_name = ini_get('apc.rfc1867_name'); } if (!$field_name && filter_var(ini_get('session.upload_progress.enabled'), FILTER_VALIDATE_BOOLEAN)) { $field_name = ini_get('session.upload_progress.name'); } if ($field_name) { $this->output->set_env('upload_progress_name', $field_name); $this->output->set_env('upload_progress_time', (int) $seconds); } } // find max filesize value $max_filesize = parse_bytes(ini_get('upload_max_filesize')); $max_postsize = parse_bytes(ini_get('post_max_size')); if ($max_postsize && $max_postsize < $max_filesize) { $max_filesize = $max_postsize; } if ($max_size && $max_size < $max_filesize) { $max_filesize = $max_size; } $this->output->set_env('max_filesize', $max_filesize); $max_filesize = $this->show_bytes($max_filesize); $this->output->set_env('filesizeerror', $this->gettext(array('name' => 'filesizeerror', 'vars' => array('size' => $max_filesize)))); return $max_filesize; }
/** * Determine the maximum size for cache data to be written */ private function max_packet_size() { if ($this->max_packet < 0) { $this->max_packet = 2097152; // default/max is 2 MB if ($this->type == 'db') { if ($value = $this->db->get_variable('max_allowed_packet', $this->max_packet)) { $this->max_packet = $value; } $this->max_packet -= 2000; } else { $max_packet = rcube::get_instance()->config->get($this->type . '_max_allowed_packet'); $this->max_packet = parse_bytes($max_packet) ?: $this->max_packet; } } return $this->max_packet; }
function save_data() { $COMPOSE_ID = rcube_utils::get_input_value('_id', rcube_utils::INPUT_GPC); $COMPOSE = null; if ($COMPOSE_ID && $_SESSION['compose_data_' . $COMPOSE_ID]) { $SESSION_KEY = 'compose_data_' . $COMPOSE_ID; $COMPOSE =& $_SESSION[$SESSION_KEY]; } if (!$COMPOSE) { die("Invalid session var!"); } $uploadid = rcube_utils::get_input_value('_uploadid', rcube_utils::INPUT_POST); $files = rcube_utils::get_input_value('files', rcube_utils::INPUT_POST); $RCMAIL = rcmail::get_instance(); $RCMAIL->output->reset(); //rcube::write_log('dropbox_attachments', $files); if (is_array($files)) { $multiple = count($files) > 1; foreach ($files as $i => $file) { /*File checks*/ $err = false; if ($file['is_dir'] == 'true') { $err = "UPLOAD_ERR_DIRECTORY"; } // Fetch file $filepath = $this->download_fopen($file['link']); //rcube::write_log('dropbox_attachments', link); //rcube::write_log('dropbox_attachments', $filepath); rcube::write_log('dropbox_attachments', $file['link']); if (!$filepath) { $err = "UPLOAD_ERR_FETCH"; } if (!$err) { $attachment = $this->move_file(array('path' => $filepath, 'size' => $file['bytes'], 'name' => $file['name'], 'mimetype' => rcube_mime::file_content_type($filepath, $file['name']), 'group' => $COMPOSE_ID)); } //rcube::write_log('dropbox_attachments', $attachment); if (!$err && $attachment['status'] && !$attachment['abort']) { $id = $attachment['id']; // store new attachment in session unset($attachment['status'], $attachment['abort']); $RCMAIL->session->append($SESSION_KEY . '.attachments', $id, $attachment); if (($icon = $COMPOSE['deleteicon']) && is_file($icon)) { $button = html::img(array('src' => $icon, 'alt' => $RCMAIL->gettext('delete'))); } else { if ($COMPOSE['textbuttons']) { $button = rcube::Q($RCMAIL->gettext('delete')); } else { $button = ''; } } $content = html::a(array('href' => "#delete", 'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%s', this)", rcmail_output::JS_OBJECT_NAME, $id), 'title' => $RCMAIL->gettext('delete'), 'class' => 'delete'), $button); $content .= rcube::Q($attachment['name']); $RCMAIL->output->command('add2attachment_list', "rcmfile{$id}", array('html' => $content, 'name' => $attachment['name'], 'mimetype' => $attachment['mimetype'], 'classname' => rcube_utils::file2class($attachment['mimetype'], $attachment['name']), 'complete' => true), $uploadid); } else { // upload failed if ($err == "UPLOAD_ERR_DIRECTORY") { $msg = "Directory upload not allowed."; } else { if ($err == "UPLOAD_ERR_FETCH") { $msg = "Failed to download file from Dropbox"; } else { if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) { $size = $RCMAIL->show_bytes(parse_bytes(ini_get('upload_max_filesize'))); $msg = $RCMAIL->gettext(array('name' => 'filesizeerror', 'vars' => array('size' => $size))); } else { if ($attachment['error']) { $msg = $attachment['error']; } else { $msg = $RCMAIL->gettext('fileuploaderror'); } } } } if ($attachment['error'] || $err != UPLOAD_ERR_NO_FILE) { $RCMAIL->output->command('display_message', $msg, 'error'); $RCMAIL->output->command('remove_from_attachment_list', $uploadid); } } } } $RCMAIL->output->command('auto_save_start', 'false'); $RCMAIL->output->send(); }
require_once '../bootstrap.php'; /* if (empty($_COOKIE["uid"]) || (int)$_COOKIE["uid"] < 1) { header("Location: login.php"); exit; }*/ //$uid = $_COOKIE["uid"]; // $callbackName=$_GET['callback']; $uid = 1; // $userinfo = $db->getOne("SELECT username FROM users WHERE id='$uid' LIMIT 1"); // $username = $userinfo["username"]; $fileRows = $db->getAll("SELECT id, file_key, file_name, file_size, created_at FROM uploads WHERE user_id='{$uid}' ORDER BY created_at DESC"); //$jobj=new stdclass(); //$array=array(array()); foreach ($fileRows as &$row) { //var_dump($row);exit; $key = $row["file_key"]; list($ret, $err) = Qiniu_RS_Stat($client, $bucket, $key); if ($err == null) { $base_url = Qiniu_RS_MakeBaseUrl($domain, $key); } $row['file_size'] = parse_bytes($row["file_size"], 1024); $row['created_at'] = date("Y-m-d H:i:s", $row["created_at"]); $row['img_url'] = $base_url . '-mm'; } if (isset($_GET['callback'])) { $jsonp = $_GET['callback'] . "(" . json_encode($fileRows) . ")"; } else { $jsonp = json_encode($fileRows); } echo $jsonp;