Roundcube Community Forum

 

File upload failed.

Started by adb101, January 24, 2017, 12:58:47 PM

Previous topic - Next topic

adb101

I'm hoping someone can help. Ever since I installed version 1.1.3 I've had issues attaching files to emails. Attaching a file results in "File upload failed.". I can see the apache user writing a file out to the "temp" directory, but it is always zero size. I have loosened the permissions to 777 and, clearly, the web server can write to the area but, for some reason, doesn't write any content. I have upgraded to version 1.2.3 and I'm still getting the issue.

From the php.ini side of things I've got the following settings:

; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
upload_tmp_dir = /tmp

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 50M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20


Files in roundcube temp look like:

[root@xore temp]# ls -l
total 0
-rw------- 1 apache apache 0 Jan 24 11:37 rcmAttmntUOgZnX
-rw------- 1 apache apache 0 Jan 24 17:47 rcmAttmntfYm0s2
-rw------- 1 apache apache 0 Jan 24 11:35 rcmAttmntmKjVRN
-rw------- 1 apache apache 0 Jan 24 11:41 rcmAttmntxtvs1S


SELinux is disabled.

As an aside, I have Horde installed on the same server and that does not have any issues with attachments.

I have put the Roundcube logging to max but nothing is being written to the logs directory about the file upload failing.

If anyone could suggest how I can get any additional debug or what to try next I'd me most grateful as it's driving me nuts!

SKaero


adb101

post_max_size is not set in php.ini.

Other apps, such as Horde, are posting attachments fine with the same php.ini settings...

SKaero

That could be the problem, post_max_size needs to larger then upload_max_filesize size since files are in the post data. Horde most likely has it's own php.ini, .htaccess or is overwriting the setting at run time.

adb101

Yes, good point. I have checked those and made them the same, but still getting the issue (any file attachment, any size).

I have narrowed the issue down to this code in ./program/steps/mail/attachments.inc:

      else {  // upload failed
            if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) {
                $size = $RCMAIL->show_bytes(rcube_utils::max_upload_size());
                $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) {
                $OUTPUT->command('display_message', $msg, 'error');    <---THIS LINE IS GENERATING THE ERROR MSG ON SCREEN
                $OUTPUT->command('remove_from_attachment_list', $uploadid);
            }


I have put some debug in and $err is coming back as "0". Unfortunately I've got extremely limited PHP experience so if anyone can suggest some additional debug to add to this section to actually work out what the issue is I'd be grateful.

Thanks!

SKaero

This sounds like a permissions problem, what is the exact error message in the error log?

adb101

Unfortunately the error log is not writing anything when the error occurs. I have the following debug settings for roundcube set in config_inc.php:

// ----------------------------------
// LOGGING/DEBUGGING
// ----------------------------------
// system error reporting, sum of: 1 = log; 4 = show
$config['debug_level'] = 1;

  // Log SQL queries to <log_dir>/sql or to syslog
  $config['sql_debug'] = true;

  // Log IMAP conversation to <log_dir>/imap or to syslog
  $config['imap_debug'] = true;

  // Log LDAP conversation to <log_dir>/ldap or to syslog
  $config['ldap_debug'] = true;

  // Log SMTP conversation to <log_dir>/smtp or to syslog
  $config['smtp_debug'] = true;


Nothing being written to the error log  :(

SKaero

It definitely sounds like a permissions problem, if Roundcube isn't writing anything to the log then it most likely doesn't have access. If Roundcube doesn't have access to write to the temp folder then it wont be able to add attachments.

adb101

But it is writing to the other logs in that directory?

[root@xore logs]# ls -l
total 163636
-rw-rw-rw- 1 root root      4707 Jan 23 10:30 errors    <-- Contains just user login error messages
-rw-rw-rw- 1 root root 161504231 Jan 25 11:48 imap
-rw-rw-rw- 1 root root     30812 Jan 24 09:11 sendmail
-rw-rw-rw- 1 root root   5993827 Jan 25 11:48 sql


It is able to write to the "temp" directory as the files appear, but are zero length:

[root@xore temp]# ls -lt | head
total 0
-rw------- 1 apache apache 0 Jan 25 11:05 rcmAttmntpDOyC5
-rw------- 1 apache apache 0 Jan 25 11:04 rcmAttmntPVOp07
-rw------- 1 apache apache 0 Jan 25 11:03 rcmAttmntfRwYtt
-rw------- 1 apache apache 0 Jan 25 11:02 rcmAttmntC8DNeO
-rw------- 1 apache apache 0 Jan 25 08:49 rcmAttmntw6ini7
-rw------- 1 apache apache 0 Jan 25 08:45 rcmAttmntrCVke1
-rw------- 1 apache apache 0 Jan 25 08:37 rcmAttmntVRsid7
-rw------- 1 apache apache 0 Jan 25 08:34 rcmAttmntS6wxNt
-rw------- 1 apache apache 0 Jan 25 08:33 rcmAttmntelSjdR


The filesystem the roundcube installation directory resides in has no special restrictions:

[root@xore temp]# mount
/dev/mapper/VolGroup00-LvRoot on / type ext4 (rw,user_xattr,acl)


Unless roundcube is trying to open some sort of special pipe or other construct to write files in "temp" which the OS is blocking..? Without any useful error message I'm a bit stuck...

Thanks.

rm13

Possibly the htaccess file. These php values may be set there.

php_value   upload_max_filesize   
php_value   post_max_size         
php_value   memory_limit         

Do your apache logs have any php errors that may shed some light?

adb101

Unfortunately there seems to be a complete lack of logging for this error, hence by difficultly in tracking down the issue!

I've set the following values in the .htaccess file in the RC directory:

php_flag    display_errors  On
php_flag    log_errors      On
php_value    error_log    logs/errors

php_value   upload_max_filesize   50M
php_value   post_max_size         50M
php_value   memory_limit          128M


As I mentioned before, the attachment file gets "touched" in the directory but there is no data inside it. This indicates that the process has write access.

Horde, which I have installed on the same server, can upload file attachments but I prefer the RC interface ;) The htaccess settings are the same for RC and Horde (in respect to the above values).

Thanks

JohnDoh

are you running any roundcube plugins? if so make sure you try with them all disabled.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more...

m_rc_b

Just in case anyone else has the "File upload failed" problem, my own experiences might help a percentage of cases.

It is not just the PHP file (.../attachments.inc) that uses the (English language) message "File upload failed", it is also used in app.min.js, which then lead me down the path I followed. Using Firefox debugger, I could see when and where the message was occurring and then found that it was that a JavaScript failure to access an iframe document (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Property_access_denied?utm_source=mozilla&utm_medium=firefox-console-errors&utm_campaign=default). After further investigation, I see that in my web server's configuration file for SSL, it was FORCING an HTTP header (X-FRAME-OPTIONS) always to DENY - even adding in "sameorigin" in to the RoundCube config options only caused the header to become invalid: DENY, sameorigin.  So, I ended up amending the web server's config file, restart the web server, reload the RoundCube page and problem solved.

Hope this helps.

ljbomir

#13
@adb101, Did you manage resolving your problem ?

I've been struggling to find out any clue on the same.

X-FRAME-OPTIONS is correctly set to "sameorigin" in the header. I have tried also disabling it without any results.

The biggest pain is that I can not get a single error message in /var/log/roundcube/, neither in /var/log/apache2/domain-name/, neither in /var/log/apache2/ !

I can only upload some small ascii files which are being uploaded in /var/lib/roundcube/temp folder.
For all the rest it fails.

Any help on enabling logging for this specific upload action will be much appreciated.

Thanks
Lyubo

SKaero

If you create a file with the following:

<?php
phpinfo
();


What is returned?