Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attachments on the filesystem plugin doesn't seems to work with 1.15.3.1 #215

Open
schoubi opened this issue Oct 21, 2021 · 13 comments
Open

Comments

@schoubi
Copy link

schoubi commented Oct 21, 2021

plugin worked, but with 1.15.3.1 it doesn't work anymore : any attachment uploaded is put in the database, and admin receive an alert :
IOException: Unable to read resource content (root)/files//H/Hr3Ow[...]KrrjXgqxPI5mw:Unable to open for reading

Directory /var/www/html/osticket/files is readable and writable by apache user...

Can't figure out what is happening, no other error messages....

@JediKev
Copy link
Contributor

JediKev commented Oct 21, 2021

@schoubi

Unable to open for reading means either the file doesn't have appropriate permissions/ownership or the file is missing for whatever reason. It'd be worth checking your attachment directory and see if you can find the file.

I am not able to replicate this using Apache, v1.15.4, PHP 7.4, and MySQL 8.0 (ie. plugin works just fine).

Cheers.

@schoubi
Copy link
Author

schoubi commented Oct 28, 2021

I double check before filling the bug, and permissions on the file system are correct :

/var/www/html/osticket/files# ls -lard
drwxr-xr-x 66 www-data www-data

With plugin "attachment on filesystem" activated, when we send an email with an attachment, it seems that OSTicket can't create the file for whatever reason, and end up using database storage as a backup.

So we deactivate the plugin, and now we have errors everytime a mail with a file attached is retrieved...So maybe it's not the plugin itself, but there's clearly a problem with backend storage subsystem...(maybe only related to our instance, but i cant figure it out)

PHP Fatal error:  Uncaught Exception: No such backend registered in /var/www/html/osticket/include/class.file.php:748
Stack trace:
#0 /var/www/html/osticket/include/class.file.php(113): FileStorageBackend::getInstance()
#1 /var/www/html/osticket/include/class.file.php(117): AttachmentFile->open()
#2 /var/www/html/osticket/include/class.file.php(135): AttachmentFile->sendData()
#3 /var/www/html/osticket/include/class.mailer.php(519): AttachmentFile->getData()
#4 [internal function]: Mailer->{closure}()
#5 /var/www/html/osticke/include/class.mailer.php(525): preg_replace_callback()
#6 /var/www/html/osticket/include/class.email.php(190): Mailer->send()
#7 /var/www/html/osticket/include/class.email.php(200): Email->send()
#8 /var/www/html/osticket/include/class.ticket.php(1738): Email->sendAlert()
#9 /var/www/html/osticket/include/class.ticket.php(4552): Ticket->onNewTicket()
#10 /var/www/html/osticket/include/class.mailfetch.php(905): Ticket: in /var/www/html/osticket/include/class.file.php on line 748

@JediKev
Copy link
Contributor

JediKev commented Oct 28, 2021

@schoubi

Uncaught Exception: No such backend registered is because, as you've mentioned, you disabled the plugin. If the plugin is disabled the FilesystemStorage backend is not registered which makes any attachment that was stored on the Filesystem throw this error when trying to retrieve the file data.

Cheers.

@schoubi
Copy link
Author

schoubi commented Oct 28, 2021

Could it be this ?

On line 72 of storage-fs

mkdir($base, 751);

second argument is permissions, which should be as an octal number (0751) (https://www.php.net/manual/en/function.mkdir.php)

Therefore it create a directory with permissions : d-wxr-xr-t 2 www-data www-data 4096 Oct 28 17:44 test/ so apache can create the directory but not read it.

I cant modify the plugin to test, as php make.php hydrate is making a lot of error on a modern OS (Ubuntu 20.04)

@JediKev
Copy link
Contributor

JediKev commented Oct 28, 2021

@schoubi

No, 0751 means User has full permissions, group has read/execute, and others only have execute. With this in mind the Apache user will have full access to the folder and the Apache group has read/execute access to the folder.

Cheers.

@schoubi
Copy link
Author

schoubi commented Oct 28, 2021

I know, but on line 72 perms are non octal (0 is missing) so the behavior is not the one expected.
I cannot test the plugin, but i can test php :

As it should be :

/tmp# cat test.0751.php
<?php

mkdir("/tmp/test", 0751);

?>
/tmp# sudo -u www-data php -f /tmp/test.0751.php
/tmp# ls -lart test
drwxr-x--x  2 www-data www-data 4096 Oct 28 19:07 .

As this is now on storage.php :

/tmp# cat test.751.php
<?php

mkdir("/tmp/test", 751);

?>
/tmp# sudo -u www-data php -f /tmp/test.751.php
/tmp# ls -lart test
d-wxr-xr-t  2 www-data www-data 4096 Oct 28 19:08 .

see ? On the second example, perms are messed up : user has no read access, and others had sticky bit ...

@JediKev
Copy link
Contributor

JediKev commented Oct 28, 2021

@schoubi

Yes, we were discussing this further and thought the octal might be an issue. I’m in the process of making a custom build of the plugin and let you test to see.

Cheers.

@JediKev
Copy link
Contributor

JediKev commented Oct 28, 2021

@schoubi

Below is a build of the plugin with 0751 as the permissions for mkdir(). Please test and let us know.
storage-fs.phar.zip

Cheers.

@schoubi
Copy link
Author

schoubi commented Nov 2, 2021

Hi @JediKev ,

Thanks for this test version, the permissions are no longer changing to something messed up but OsTicket still can't create files :
(root)/files/Y/Y4KSJS0[...]leqW9pI:Unable to open for reading

/var/www/html/osticket# ls -la
drwxrwxr-x 28 www-data www-data  4096 Oct 28 17:37 files/
/var/www/html/osticket/files# ls -la
[...]
drwxr-x--x  2 www-data www-data 4096 Oct 28 17:23 Y

Still digging...

@JediKev
Copy link
Contributor

JediKev commented Nov 2, 2021

@schoubi

Are you running SELINUX by chance (you can check by running getenforce)? If so, you may need to add the httpd context of rw. You can do so by running sudo chcon -R -t httpd_sys_rw_content_t /path/to/attachments_folder/. There may be a better context so please research at your own leisure.

With a lot of the Red Hat distros (and others) they have SELINUX installed and enabled by default. This typically has pretty tight security so you have to add a context in order for Apache to read/rewrite certain directories and files.

Cheers.

@schoubi
Copy link
Author

schoubi commented Nov 16, 2021

Hi,

Unfortunately no, we use Ubuntu Server 20.04 and completely deactivated selinux on non critical servers...

# getenforce
Disabled

Btw we have this plugin activated on Osticket on CentOS 7.9 which run fine, it seems that the problem stick with Ubuntu 20...Maybe the php or apache version had influence ?

@stiman
Copy link

stiman commented Jan 24, 2023

was this solved?

@schoubi
Copy link
Author

schoubi commented Jan 24, 2023

No, but i'm stuck with 1.15.8, can't test with newer versions of OsTicket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants