/** * Validate memory limit * * @param array $result */ function validate_memory_limit(&$results) { $memory_limit = php_config_value_to_bytes(ini_get('memory_limit')); $formatted_memory_limit = $memory_limit === -1 ? 'unlimited' : format_file_size($memory_limit); if ($memory_limit === -1 || $memory_limit >= 67108864) { $results[] = new TestResult('Your memory limit is: ' . $formatted_memory_limit, STATUS_OK); return true; } else { $results[] = new TestResult('Your memory is too low to complete the installation. Minimal value is 64MB, and you have it set to ' . $formatted_memory_limit, STATUS_ERROR); return false; } // if }
/** * This function will return max upload size in bytes * * @param void * @return integer */ function get_max_upload_size() { $max = min(php_config_value_to_bytes(ini_get('upload_max_filesize')), php_config_value_to_bytes(ini_get('post_max_size'))); Hook::fire('max_upload_size', null, $max); return $max; }
function getmails($accounts = null, &$err, &$succ, &$errAccounts, &$mailsReceived, $maxPerAccount = 0) { Env::useHelper('permissions'); Env::useHelper('format'); if (is_null($accounts)) { $accounts = MailAccounts::findAll(); } if (config_option('max_email_fetch') && ($maxPerAccount == 0 || config_option('max_email_fetch') < $maxPerAccount)) { $maxPerAccount = config_option('max_email_fetch'); } $old_memory_limit = ini_get('memory_limit'); if (php_config_value_to_bytes($old_memory_limit) < 192 * 1024 * 1024) { ini_set('memory_limit', '192M'); } $err = 0; $succ = 0; $errAccounts = array(); $mailsReceived = 0; if (isset($accounts)) { foreach ($accounts as $account) { if (!$account->getServer()) { continue; } try { $lastChecked = $account->getLastChecked(); $minutes = 5; if ($lastChecked instanceof DateTimeValue && $lastChecked->getTimestamp() + $minutes * 60 >= DateTimeValueLib::now()->getTimestamp()) { $succ++; continue; } else { try { DB::beginWork(); $account->setLastChecked(DateTimeValueLib::now()); $account->save(); DB::commit(); } catch (Exception $ex) { DB::rollback(); $errAccounts[$err]["accountName"] = $account->getEmail(); $errAccounts[$err]["message"] = $e->getMessage(); $err++; } } $accId = $account->getId(); $emails = array(); if (!$account->getIsImap()) { $mailsReceived += self::getNewPOP3Mails($account, $maxPerAccount); } else { $mailsReceived += self::getNewImapMails($account, $maxPerAccount); } $account->setLastChecked(EMPTY_DATETIME); $account->save(); // self::cleanCheckingAccountError($account); $succ++; } catch (Exception $e) { $account->setLastChecked(EMPTY_DATETIME); $account->save(); $errAccounts[$err]["accountName"] = $account->getEmail(); $errAccounts[$err]["message"] = $e->getMessage(); $err++; // self::setErrorCheckingAccount($account, $e); } } } ini_set('memory_limit', $old_memory_limit); tpl_assign('err', $err); tpl_assign('errAccounts', $errAccounts); tpl_assign('accounts', $accounts); tpl_assign('mailsReceived', $mailsReceived); }
function zip_extract() { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $fileId = array_var($_GET, 'id'); ajx_current("empty"); if (!zip_supported()) { flash_error(lang('zip not supported')); return; } $file = ProjectFiles::findById($fileId); if (!$file->canEdit(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } if (!$file) { flash_error(lang('file dnx')); ajx_current("empty"); } else { $old_memory_limit = ini_get('memory_limit'); if (php_config_value_to_bytes($old_memory_limit) < 96*1024*1024) { ini_set('memory_limit', '96M'); } @set_time_limit(0); session_commit(); $content = $file->getLastRevision()->getFileContent(); $filepath = ROOT.'/tmp/'.rand().'.zip'; $handle = fopen($filepath, 'wb'); fwrite($handle, $content); fclose($handle); $encoder = EncodingConverter::instance(); $file_count = 0; $zip = new ZipArchive(); if ($zip->open($filepath)) { $tmp_dir = ROOT.'/tmp/'.rand().'/'; $zip->extractTo($tmp_dir); $i=0; $members = $file->getMemberIds(); while ($e_name = $zip->getNameIndex($i++)) { $tmp_path = $tmp_dir.$e_name; //removes weird characters $e_name = preg_match_all('/([\x09\x0a\x0d\x20-\x7e]'. // ASCII characters '|[\xc2-\xdf][\x80-\xbf]'. // 2-byte (except overly longs) '|\xe0[\xa0-\xbf][\x80-\xbf]'. // 3 byte (except overly longs) '|[\xe1-\xec\xee\xef][\x80-\xbf]{2}'. // 3 byte (except overly longs) '|\xed[\x80-\x9f][\x80-\xbf])+/', // 3 byte (except UTF-16 surrogates) $e_name, $clean_pieces); $e_name = join('?', $clean_pieces[0]); if (!is_dir($tmp_path)) { $this->upload_file(null, $e_name, $tmp_path, $members); $file_count++; } } $zip->close(); delete_dir($tmp_dir); } unlink($filepath); ajx_current("reload"); flash_success(lang('success extracting files', $file_count)); } } // zip_extract
function zip_extract() { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $fileId = array_var($_GET, 'id'); ajx_current("empty"); if (!zip_supported()) { flash_error(lang('zip not supported')); return; } $file = ProjectFiles::findById($fileId); if (!$file->canEdit(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } if (!$file) { flash_error(lang('file dnx')); ajx_current("empty"); } else { $old_memory_limit = ini_get('memory_limit'); if (php_config_value_to_bytes($old_memory_limit) < 96 * 1024 * 1024) { ini_set('memory_limit', '96M'); } @set_time_limit(0); session_commit(); $content = $file->getLastRevision()->getFileContent(); $filepath = ROOT . '/tmp/' . rand() . '.zip'; $handle = fopen($filepath, 'wb'); fwrite($handle, $content); fclose($handle); $file_count = 0; $zip = new ZipArchive(); if ($zip->open($filepath)) { $tmp_dir = ROOT . '/tmp/' . rand() . '/'; $zip->extractTo($tmp_dir); $i = 0; $workspaces = $file->getWorkspaces(); while ($e_name = $zip->getNameIndex($i++)) { $tmp_path = $tmp_dir . $e_name; if (!is_dir($tmp_path)) { $this->upload_file(null, $e_name, $tmp_path, $workspaces); $file_count++; } } $zip->close(); delete_dir($tmp_dir); } unlink($filepath); ajx_current("reload"); flash_success(lang('success extracting files', $file_count)); } }
/** * View specific email * */ function view() { $this->addHelper('textile'); $email = MailContents::findById(get_id()); if (!$email instanceof MailContent) { flash_error(lang('email dnx')); ajx_current("empty"); return; } if ($email->getIsDeleted()) { flash_error(lang('email dnx deleted')); ajx_current("empty"); return; } if (!$email->canView(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } tpl_assign('email', $email); $attachments = array(); if ($email->getState() >= 200) { $old_memory_limit = ini_get('memory_limit'); if (php_config_value_to_bytes($old_memory_limit) < 256 * 1024 * 1024) { ini_set('memory_limit', '256M'); } $attachments = self::readAttachmentsFromFileSystem($email, $att_ver); if ($attachments && is_array($attachments)) { foreach ($attachments as &$attach) { if ($att_ver < 2) { $attach["FileName"] = $attach['name']; $attach['size'] = format_filesize(strlen($attach["data"])); unset($attach['name']); unset($attach['data']); } else { $attach["FileName"] = $attach['name']; $attach['size'] = format_filesize(filesize($attach["path"])); unset($attach['name']); } } } else { } ini_set('memory_limit', $old_memory_limit); } else { MailUtilities::parseMail($email->getContent(), $decoded, $parsedEmail, $warnings); if (isset($parsedEmail['Attachments'])) { $attachments = $parsedEmail['Attachments']; } foreach ($attachments as &$attach) { $attach['size'] = format_filesize(strlen($attach["Data"])); unset($attach['Data']); } } if ($email->getBodyHtml() != '') { $tmp_folder = "/tmp/" . $email->getAccountId() . "_" . logged_user()->getId() . "_" . $email->getId() . "_temp_mail_content_res"; if (is_dir(ROOT . $tmp_folder)) { remove_dir(ROOT . $tmp_folder); } $parts_array = array_var($decoded, 0, array('Parts' => '')); $email->setBodyHtml(self::rebuild_body_html($email->getBodyHtml(), array_var($parts_array, 'Parts'), $tmp_folder)); } tpl_assign('attachments', $attachments); ajx_extra_data(array("title" => $email->getSubject(), 'icon' => 'ico-email')); ajx_set_no_toolbar(true); if (array_var($_GET, 'replace')) { ajx_replace(true); } $email->setIsRead(logged_user()->getId(), true); ApplicationReadLogs::createLog($email, $email->getWorkspaces(), ApplicationReadLogs::ACTION_READ); }
/** * Return max upload size * * This function will check for max upload size and return value in bytes. By default it will compare values of * upload_max_filesize and post_max_size from php.ini, but it can also take additional values provided as arguments * (for instance, if you store data in MySQL database one of the limiting factors can be max_allowed_packet * configuration value). * * Examples: * <pre> * $max_size = get_max_upload_size(); // check only data from php.ini * $max_size = get_max_upload_size(12000, 18000); // take this values into calculation too * </pre> * * @param mixed * @return integer */ function get_max_upload_size() { static $size = false; if ($size === false) { $size = php_config_value_to_bytes(ini_get('upload_max_filesize')); // Start with upload max size $post_max_size = php_config_value_to_bytes(ini_get('post_max_size')); if ($size > $post_max_size) { $size = $post_max_size; } // if } // if return $size; }
if(!ini_get('session.auto_start') || (strtolower(ini_get('session.auto_start')) == 'off')) { if ( !isset($_GET['avoid_session']) || (isset($_GET['avoid_session']) && !$_GET['avoid_session']) ){ session_start(); // Start the session } } include_once ENVIRONMENT_PATH . '/classes/Env.class.php'; include_once ENVIRONMENT_PATH . '/constants.php'; include_once ENVIRONMENT_PATH . '/functions/utf.php'; include_once ENVIRONMENT_PATH . '/functions/general.php'; include_once ENVIRONMENT_PATH . '/functions/files.php'; // Configure PHP if (php_config_value_to_bytes(ini_get('memory_limit')) < 64*1024*1024) { ini_set('memory_limit', '64M'); } ini_set('short_open_tag', 'on'); ini_set('date.timezone', 'GMT'); if(function_exists('date_default_timezone_set')) { date_default_timezone_set('GMT'); } else { putenv('TZ=GMT'); } // if if(defined('DEBUG') && DEBUG) { //set_time_limit(120); ini_set('display_errors', 1); error_reporting(E_ALL); } else {
/** * View specific email * */ function view() { $this->addHelper('textile'); $email = MailContents::findById(get_id()); if (!$email instanceof MailContent) { flash_error(lang('email dnx')); ajx_current("empty"); return; } if ($email->getIsDeleted()) { flash_error(lang('email dnx deleted')); ajx_current("empty"); return; } if (!$email->canView(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } tpl_assign('email', $email); $additional_body = ""; $attachments = array(); if ($email->getState() >= 200) { $old_memory_limit = ini_get('memory_limit'); if (php_config_value_to_bytes($old_memory_limit) < 256 * 1024 * 1024) { ini_set('memory_limit', '256M'); } $attachments = self::readAttachmentsFromFileSystem($email, $att_ver); if ($attachments && is_array($attachments)) { foreach ($attachments as &$attach) { if ($att_ver < 2) { $attach["FileName"] = $attach['name']; $attach['size'] = format_filesize(strlen($attach["data"])); unset($attach['name']); unset($attach['data']); } else { $attach["FileName"] = $attach['name']; $attach['size'] = format_filesize(filesize($attach["path"])); unset($attach['name']); } } } else { } ini_set('memory_limit', $old_memory_limit); } else { MailUtilities::parseMail($email->getContent(), $decoded, $parsedEmail, $warnings); if (isset($parsedEmail['Attachments'])) { $attachments = $parsedEmail['Attachments']; } else { if ($email->getHasAttachments() && !in_array($parsedEmail['Type'], array('html', 'text', 'delivery-status')) && isset($parsedEmail['FileName'])) { // the email is the attachment $attach = array('Data' => $parsedEmail['Data'], 'Type' => $parsedEmail['Type'], 'FileName' => $parsedEmail['FileName']); $attachments = array($attach); } } $to_remove = array(); foreach ($attachments as $k => &$attach) { // dont show inline images in attachments box if (array_var($attach, 'FileDisposition') == 'inline' && array_var($parsedEmail, 'Type') == 'html') { $attach['hide'] = true; } if (array_var($attach, 'Type') == 'html') { $attach_tmp = $attach['Data']; $attach_tmp = preg_replace('/<html[^>]*[>]/', '', $attach_tmp); $attach_tmp = preg_replace('/<\\/html>/', '', $attach_tmp); $attach_tmp = preg_replace('/<head>*<\\/head>/', '', $attach_tmp); $attach_tmp = preg_replace('/<body[^>]*[>]/', '', $attach_tmp); $attach_tmp = preg_replace('/<\\/body>/', '', $attach_tmp); $additional_body .= $attach_tmp; //break; } $attach['size'] = format_filesize(strlen($attach["Data"])); unset($attach['Data']); } } if ($email->getBodyHtml() != '') { $tmp_folder = "/tmp/" . $email->getAccountId() . "_" . logged_user()->getId() . "_" . $email->getId() . "_temp_mail_content_res"; if (is_dir(ROOT . $tmp_folder)) { remove_dir(ROOT . $tmp_folder); } $parts_array = array_var($decoded, 0, array('Parts' => '')); $email->setBodyHtml(self::rebuild_body_html($email->getBodyHtml(), array_var($parts_array, 'Parts'), $tmp_folder) . $additional_body); } tpl_assign('attachments', $attachments); ajx_extra_data(array("title" => $email->getSubject(), 'icon' => 'ico-email')); ajx_set_no_toolbar(true); if (array_var($_GET, 'replace')) { ajx_replace(true); } if (!$email->getIsRead(logged_user()->getId())) { $object_controler = new ObjectController(); $object_controler->do_mark_as_read_unread_objects(array($email->getId()), true); } ApplicationReadLogs::createLog($email, null, ApplicationReadLogs::ACTION_READ); }
/** * This function will return max upload size in bytes * * @param void * @return integer */ function get_max_upload_size() { return min(php_config_value_to_bytes(ini_get('upload_max_filesize')), php_config_value_to_bytes(ini_get('post_max_size'))); // max }
/** * Return max upload size * * This function will check for max upload size and return value in bytes. By default it will compare values of * upload_max_filesize and post_max_size from php.ini, but it can also take additional values provided as arguments * (for instance, if you store data in MySQL database one of the limiting factors can be max_allowed_packet * configuration value). * * Examples: * <pre> * $max_size = get_max_upload_size(); // check only data from php.ini * $max_size = get_max_upload_size(12000, 18000); // take this values into calculation too * </pre> * * @param mixed * @return integer */ function get_max_upload_size() { $arguments = func_get_args(); if (!is_array($arguments)) { $arguments = array(); } // if $arguments[] = php_config_value_to_bytes(ini_get('upload_max_filesize')); $arguments[] = php_config_value_to_bytes(ini_get('post_max_size')); $min = null; foreach ($arguments as $argument) { if (is_null($min)) { $min = $argument; } else { $min = min($argument, $min); } // if } // if return $min; }