bithost-gmbh / pdfviewhelpers

TYPO3 CMS extension that provides various Fluid ViewHelpers to generate PDF documents.
GNU General Public License v3.0
44 stars 20 forks source link

generated font files in pdfviewhelpers/Resources/Private/PHP/tcpdf/fonts missing #127

Closed medarob closed 5 years ago

medarob commented 5 years ago

Hi,

maybe someone can help because right now we get the following error message TCPDF ERROR: Could not include font definition file: "roboto"

I noticed that various files are missing in this folder: /var/www/test/web/typo3conf/ext/pdfviewhelpers/Resources/Private/PHP/tcpdf/fonts

for example: grafik

If those files are available, the error is gone and the pdf works.

Now, normally those files should be auto-generated, correct? What is wrong if this doesn't not work?

The error appeard after we switched from a TYPO3 8.7.27 TER version to 8.7.27 Composer. Before that, all worked fine. We haven't touched the typoscript or template code.

We might have screwed up the composer installation because we used a root user for the composer commands to install the extensions. Can that be fixed? Everything seems to work but the pdf files... :/ I can't remember putting those files into the directory mentioned above manually when I integrated the extension.

Maybe someone has a hint what could be wrong here?

Thank you

macjohnny commented 5 years ago

the fonts should be there when installing pdfviewhelpers, see https://github.com/bithost-gmbh/pdfviewhelpers/tree/master/Resources/Private/PHP/tcpdf/fonts

it seems strange. can you uninstall and re-install the extension again?

medarob commented 5 years ago

That is correct. Those fonts are inside the folder.

But we use custom fonts like Roboto and some others and the files for those fonts are missing. So, I wonder if those files were auto-generated by tcpdf?

medarob commented 5 years ago

I just tested it on our DEV environment and there the files are auto-generated inside the tcpdf/fonts folder. But it's not working on the production environment so it seems like a permission problem? I had hoped that someone knows which permissions are needed in order to make it work.

The error message in the backend is this:


Core: Error handler (FE): PHP Warning: fopen(file:///var/www/typo3/web/typo3conf/ext/pdfviewhelpers/Resources/Private/PHP/tcpdf/fonts/roboto.php): failed to open stream: Permission denied in /var/www/typo3/web/typo3conf/ext/pdfviewhelpers/Resources/Private/PHP/tcpdf/include/tcpdf_static.php line 1821   

Core: Error handler (FE): PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/typo3/web/typo3conf/ext/pdfviewhelpers/Resources/Private/PHP/tcpdf/include/tcpdf_fonts.php line 890   

Core: Error handler (FE): PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/typo3/web/typo3conf/ext/pdfviewhelpers/Resources/Private/PHP/tcpdf/include/tcpdf_fonts.php line 889   

Core: Error handler (FE): PHP Warning: fopen(file:///var/www/typo3/web/typo3conf/ext/pdfviewhelpers/Resources/Private/PHP/tcpdf/fonts/roboto.ctg.z): failed to open stream: Permission denied in /var/www/typo3/web/typo3conf/ext/pdfviewhelpers/Resources/Private/PHP/tcpdf/include/tcpdf_static.php line 1821     

Core: Error handler (FE): PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/typo3/web/typo3conf/ext/pdfviewhelpers/Resources/Private/PHP/tcpdf/include/tcpdf_fonts.php line 371   

Core: Error handler (FE): PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/typo3/web/typo3conf/ext/pdfviewhelpers/Resources/Private/PHP/tcpdf/include/tcpdf_fonts.php line 370   

Core: Error handler (FE): PHP Warning: fopen(file:///var/www/typo3/web/typo3conf/ext/pdfviewhelpers/Resources/Private/PHP/tcpdf/fonts/roboto.z): failed to open stream: Permission denied in /var/www/typo3/web/typo3conf/ext/pdfviewhelpers/Resources/Private/PHP/tcpdf/include/tcpdf_static.php line 1821
maechler commented 5 years ago

@medarob Could you check the permissions on the fonts folder on DEV and PROD?

ls -l /var/www/typo3/web/typo3conf/ext/pdfviewhelpers/Resources/Private/PHP/tcpdf/fonts/

Although I am a bit confused. At first you said the files were missing, but the error message clearly reads Permission denied, which suggests that the files have been auto generated. Maybe you checked the fonts folder before the very first time that pdfviewhelpers ran on PROD?

Maybe the files were somehow created in the context of the root user during a composer command, although I can not come up with a reason why that could happen. You could try to remove the installed extension folder pdfviewhelpers and run composer install again without root permissions. If you already installed composer with root permissions, you might have to reinstall composer as well without root permissions. If that does not help, it would maybe be helpful if you could show us your composer.json file.

medarob commented 5 years ago

I checked the permission for the fonts folder:

on DEV/STAGING: drwxr-sr-x 7 apache apache 8192 Aug 23 11:41 fonts on PROD: drwxr-sr-x. 7 apache apache 8192 Aug 23 14:22 fonts

It seems like the only difference is the . behind the x. On another website I found this as explanation: The dot after file permissions in 'ls' long output denotes that the file in question has a SELinux security context, no matter if SELinux is enabled or not. But I have no idea if that can be a problem?

Composer is only installed on our DEV/Staging systems but not on PROD. We copy/rsync the files from Staging to our PROD system. So, I can only re-install the extension via composer on our DEV/Staging system - but there it works, though.

So, auto generating of the font files works on our DEV/Staging system and if we copy the complete folder on our PROD system the pdf works because the font files are already included.

I know that we had the same error on DEV. We had to change the owner and group of the fonts folder and files to apache and then auto-generating worked on DEV. We did the same change on PROD but the problem still exists. Normally the font files should be auto-generated on PROD as well. This worked also on our TER installation with the same owner/group.

If I delete only the font files inside the pdfviewhelpers/Resources/Private/PHP/tcpdf/fonts/ folder on PROD they are not autogenerated and I'll get the error message.

our composer.json:

{
    "repositories": [
        {
            "type": "composer",
            "url": "https://composer.typo3.org/"
        }
    ],
    "extra": {
        "typo3/cms": {
            "cms-package-dir": "{$vendor-dir}/typo3/cms",
            "web-dir": "web"
        }
    },
    "autoload": {
        "psr-4": {
            "Vendor\\VendorProject\\": "web/typo3conf/ext/vendor_project/Classes/"
        }
    },
    "require": {
        "typo3/cms": "^8.7",
        "georgringer/backend-debug": "^1.1",
        "t3g/blog": "^8.7",
        "aoepeople/crawler": "^6.4",
        "clickstorm/cs_seo": "^3.1",
        "friendsoftypo3/extension-builder": "^8.10",
        "in2code/femanager": "^5.1",
        "teaminmedias-pluswerk/ke_search": "^2.8",
        "mindshape/mindshape_cookie_hint": "^1.0",
        "sjbr/static-info-tables": "^6.7",
        "georgringer/news": "^7.2",
        "bithost-gmbh/pdfviewhelpers": "^2.1",
        "in2code/powermail": "^7.3",
        "dmitryd/typo3-realurl": "^2.5",
        "stefanfroemken/repair_translation": "^1.4",
        "derhansen/sf_event_mgt": "^4.1",
        "derhansen/sf_event_mgt_indexer": "^2.0",
        "lochmueller/sourceopt": "^1.0",
        "fluidtypo3/vhs": "^5.2",
        "mask/mask": "^3.3",
        "typo3-ter/lfeditor": "^5.1",
        "typo3-ter/l10nmgr": "^8.4",
        "typo3-ter/rx-shariff": "^12.1",
        "bitmotion/secure-downloads": "^3.0"
    }
}
maechler commented 5 years ago

Composer should not have an impact on the permissions if you do not run it on PROD. But SELinux could definitely have something to do with it, as it extends the default user, group and other permissions with more fine grained permissions.

Is it possible that SELinux permissions changed at the same time you switched from TER to composer? Can you test whether the TER version still works on your PROD server? You could also use ls -dZ to see the SELinux directory context and then go on from there to check the permissions:

ls -dZ /var/www/typo3/web/typo3conf/ext/pdfviewhelpers/Resources/Private/PHP/tcpdf/fonts
medarob commented 5 years ago

Auto-generating the files still works on the TER version.

The SELinux directory context seems different. I also noticed that a write persmission was missing in comparision to a test instance on our prod server but this permission is also missing on our dev server where it works. I added the permission and it works now BUT if I remove the permission it still works... so, it seems now it works and not sure what has changed since friday. It's strange! Maybe our IT department has changed something on the server... I will monitor the behaviour.

Thank you for the ideas what to check.

maechler commented 5 years ago

Sometimes things can not be explained 😅 I will close this issue as it does not seem to have something to do with pdfviewhelpers in particular.

Although I just created a follow up issue, that would help to keep typo3conf/ext clean and probably would also have prevented your issues: https://github.com/bithost-gmbh/pdfviewhelpers/issues/128