From 8302c1ca8be9e55280f010f66f5b5160509ba229 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Fri, 17 Oct 2014 15:14:59 +0000 Subject: [PATCH] Default max file size Determine and set a reasonable max file size on install Remove file extension restrictions - transition to mime types --- include/class.config.php | 9 --------- include/class.format.php | 10 ++++++++++ include/class.forms.php | 4 +++- include/class.i18n.php | 12 +++++++++++- include/i18n/en_US/config.yaml | 4 ---- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/include/class.config.php b/include/class.config.php index 8a7d5eebd..08881a4d3 100644 --- a/include/class.config.php +++ b/include/class.config.php @@ -523,15 +523,6 @@ class OsticketConfig extends Config { return $this->get('max_file_size'); } - function getStaffMaxFileUploads() { - return $this->get('max_staff_file_uploads'); - } - - function getClientMaxFileUploads() { - //TODO: change max_user_file_uploads to max_client_file_uploads - return $this->get('max_user_file_uploads'); - } - function getLogLevel() { return $this->get('log_level'); } diff --git a/include/class.format.php b/include/class.format.php index 55635f5aa..2357e45e5 100644 --- a/include/class.format.php +++ b/include/class.format.php @@ -30,6 +30,16 @@ class Format { return round(($bytes/1048576),1).' mb'; } + function filesize2bytes($size) { + switch (substr($size, -1)) { + case 'M': case 'm': return (int)$size <<= 20; + case 'K': case 'k': return (int)$size <<= 10; + case 'G': case 'g': return (int)$size <<= 30; + } + + return $size; + } + /* encode text into desired encoding - taking into accout charset when available. */ function encode($text, $charset=null, $encoding='utf-8') { diff --git a/include/class.forms.php b/include/class.forms.php index 54ef6e900..5f0301503 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -1128,7 +1128,9 @@ class ThreadEntryField extends FormField { $attachments = new FileUploadField(); $fileupload_config = $attachments->getConfigurationOptions(); - $fileupload_config['extensions']->set('default', $cfg->getAllowedFileTypes()); + if ($cfg->getAllowedFileTypes()) + $fileupload_config['extensions']->set('default', $cfg->getAllowedFileTypes()); + return array( 'attachments' => new BooleanField(array( 'label'=>__('Enable Attachments'), diff --git a/include/class.i18n.php b/include/class.i18n.php index 4a9540520..4a0d138f2 100644 --- a/include/class.i18n.php +++ b/include/class.i18n.php @@ -104,8 +104,18 @@ class Internationalization { } } - // Pages and content + // Load core config $_config = new OsticketConfig(); + + // Determine reasonable default max_file_size + $max_size = Format::filesize2bytes(strtoupper(ini_get('upload_max_filesize'))); + $val = ((int) $max_size/2); + $po2 = 1; + while( $po2 < $val ) $po2 <<= 1; + + $_config->set('max_file_size', $po2); + + // Pages and content foreach (array('landing','thank-you','offline', 'registration-staff', 'pwreset-staff', 'banner-staff', 'registration-client', 'pwreset-client', 'banner-client', diff --git a/include/i18n/en_US/config.yaml b/include/i18n/en_US/config.yaml index a63764ba9..b29df10ac 100644 --- a/include/i18n/en_US/config.yaml +++ b/include/i18n/en_US/config.yaml @@ -15,7 +15,6 @@ core: reply_separator: '-- reply above this line --' # Do not translate below here - allowed_filetypes: '.doc, .pdf, .jpg, .jpeg, .gif, .png, .xls, .docx, .xlsx, .txt' isonline: 1 staff_ip_binding: 0 staff_max_logins: 4 @@ -27,9 +26,6 @@ core: client_session_timeout: 30 max_page_size: 25 max_open_tickets: 0 - max_file_size: 1048576 - max_user_file_uploads: 1 - max_staff_file_uploads: 1 autolock_minutes: 3 default_priority_id: 2 default_smtp_id: 0 -- GitLab