Laravel snappy on Laradock error /usr/local/bin/wkhtmltopdf not found - laravel

Context
I have deployed a Laravel app using Laradock. This app has the feature to generate certificates in PDF and attach them to an email notification.
Everything works fine in Laravel Homestead (development environment), however, that feature is not working in Laradock production mode.
Goal
I have implemented a functionality to send a PDF certificate through an email notification as an attachment like so (using Laravel Filament):
<?php
use Illuminate\Support\Facades\Notification;
use App\Notifications\Certificates\CertificateIssued;
Notification::route('mail',[
$certificate->participant->email=>$certificate->participant->name,
])->notify(new CertificateIssued($record));
Now in the notification class CertificateIssued I instantiate a Laravel Snappy PDF generator class
public function toMail($notifiable)
{
$generateCertificate = new GenerateCertificate();
//...
return
(new MailMessage)->markdown('emails.certificates.issued',[
//Some vars to be passed
])
->attachData($GenerateCertificate->attachPDF($this->certificate),$pdf_filename, [
'mime' => 'application/pdf',
]);
}
The Laravel Snappy PDF certificate class is like so:
use App\Models\Certificate;
use App\Services\Certificates\Qr\GenerateQr;
use Barryvdh\Snappy\Facades\SnappyPdf as PDF;
class GenerateCertificate
{
public function attachPdf(Certificate $certificate)
{
$pdf = $this->generate_pdf_certificate($certificate);
return $pdf->output();
}
public function generate_pdf_certificate(Certificate $certificate)
{
//QR code
$qr=$this->generate_png_qr($certificate);
//load blade view
$pdf = PDF::loadView('certificates.default',compact('certificate','qr'));
//Set PDF options. todo: abstract options away
$pdf = $this->setPdfOptions($pdf);
return $pdf;
}
public function genera_qr_png(Certificate $certificate)
{
$generateQR = new GenerateQr($this->generate_url_qr_verification($certificate),'png',130);
return $generateQR->image();
}
}
So I want the PDF attachment to be sent on an email notification. That piece of code is also used in a scheduler for newly generated certificates to be sent via email.
Error
But the email sending notification cannot be achieved due to an error in the wkhtmltopdf
[2022-05-19 16:40:53] production.ERROR: The exit status code '127' says something went wrong:
stderr: "sh: /usr/local/bin/wkhtmltopdf: not found
.env
I have actually installed the WKHTMLTOPDF in both the workspace and php-fpm containers.
###########################################################
################ Containers Customization #################
###########################################################
### WORKSPACE #############################################
WORKSPACE_INSTALL_WKHTMLTOPDF=true
### PHP_FPM ###############################################
PHP_FPM_INSTALL_WKHTMLTOPDF=true
Inside the container,
> docker exec -it --user=laradock project_workspace_1 zsh
➜ www git:(master) ✗ /usr/local/bin/wkhtmltopdf -V
wkhtmltopdf 0.12.6 (with patched qt)
➜ www git:(master) ✗ ls -lah /usr/local/bin
total 92M
drwxr-xr-x 1 root root 4.0K May 18 10:18 .
drwxr-xr-x 1 root root 4.0K Apr 16 2021 ..
-rwxr-xr-x 1 laradock www-data 2.6M Apr 22 19:48 composer
-rwxr-xr-x 1 root root 221 May 18 10:15 pip
-rwxr-xr-x 1 root root 221 May 18 10:15 pip3
-rwxr-xr-x 1 root root 221 May 18 10:15 pip3.10
-rwxr-xr-x 1 root root 221 May 18 10:15 pip3.8
-rwxr-xr-x 1 root root 238 May 18 10:15 virtualenv
-rwxr-xr-x 1 root root 208 May 18 10:15 wheel
-rwxr-xr-x 1 laradock www-data 45M Jun 10 2020 wkhtmltoimage
-rwxr-xr-x 1 laradock www-data 45M Jun 10 2020 wkhtmltopdf
I can see it is indeed installed in /usr/local/bin/ and I can actually execute it. Even if the owner is root:root, but I changed it to laradock:www-data but it made no difference.
What works and main question
I have another functionality to generate a certificate preview that works as a PDF download which does work. So why does this PDF preview download works and not the PDF attachment?
Here is a PDF generator preview that generates a PDF and prompts for download in the browser (using Laravel Filament):
public function certificate_preview(){
$event = Event::with('relationships...')->findOrFail($this->record->id);
$pdf = SnappyPdf::loadView('certificates.default',['event'=>$this->record])
->setPaper('Letter')
->setOrientation('Portrait')
->setOption('disable-external-links', false)
->setOption('enable-local-file-access', true)
->setOption('enable-internal-links' , true)
->output()
;
$disk = Storage::disk('pdf');
$disk->put('preview.pdf', $pdf);
return Storage::disk('pdf')->download('preview.pdf');//https://dev.to/fractalbit/tips-for-working-with-private-files-in-laravel-1g08
//dd(Storage::disk('pdf')->path('preview.pdf'));
//dd($this->record);
}
The previous code streams the PDF in the browser as a download option or it simply shows it right in the browser:
blob:https://myapp.com/long_uuid_string
where I can see perfectly the PDF! But why isn't the attachment working and outputs the
ERROR: The exit status code '127' says something went wrong: stderr: "sh: /usr/local/bin/wkhtmltopdf: not found" at /var/www/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php:469
error?
Version info
The version of wkhtmltopdf is:
➜ www git:(master) ✗ /usr/local/bin/wkhtmltopdf -V
wkhtmltopdf 0.12.6 (with patched qt)
➜ www git:(master) ✗ php -v
PHP 8.1.5 (cli) (built: Apr 21 2022 10:14:45) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.5, Copyright (c) Zend Technologies
with Zend OPcache v8.1.5, Copyright (c), by Zend Technologies
Problem identified
I have tested to send an email notification without the queue in jobs and it worked!
Looks like the php-worker container should have the WKHTMLTOPDF installed, which is missing in the .env file.
I mean, there's no
### PHP_WORKER ############################################
PHP_WORKER_INSTALL_WKHTMLTOPDF=true
in the PHP-WORKERsection.
So now the question is, how to install that extension in the php-worker container?

Related

Changing group from user to root

I am using mac and I am trying to change my open file limit by modifying the following directory:
/Library/LaunchDaemons
when I created two files I got the following permissions:
-rw-r--r--# 1 root wheel 535 Jul 2 16:36 limit.maxfiles.plist
-rw-r--r--# 1 samu wheel 586 Jul 2 16:53 limit.maxproc.plist
however when I run limit.maxproc.plist file I get the following error:
/Library/LaunchDaemons/limit.maxproc.plist: Path had bad ownership/permissions
which is due to the permissions of my group.
I want to change the group from samu to root but not sure how?
I found the solution. To change a specific file owner to root you can use the following command :
sudo chown root limit.maxproc.plist

My metasploit module(s) not found/loading

Any custom metasploit module I create isn't getting loaded.
I tried both of these demos:
https://www.offensive-security.com/metasploit-unleashed/building-module/ https://github.com/rapid7/metasploit-framework/wiki/Loading-External-Modules
and got the same result that the modules were NOT found.
Before posting here, I checked these out:
https://forums.kali.org/showthread.php?28940-Metasploit-modules-not-loading!
https://www.offensive-security.com/metasploit-unleashed/modules-and-locations
and from SO:
I can't get new modules to load in metasploit
How to add module in Metasploit?
no help
Just working with the github example, on the Kali host, I do indeed have the file in the right location (according to the demo):
root#kali:~/.msf4/modules/exploits/test# ls -al
total 12
drwxr-xr-x 2 root root 4096 Mar 19 13:59 .
drwxr-xr-x 3 root root 4096 Mar 19 13:58 ..
-rw-r--r-- 1 root root 9 Mar 19 13:59 test_module.rb
I then ran reload_all and when using this command:
use exploit/test/test_module it returns with Failed to load module.
I also tried to manually load that path and it failed too:
msf > loadpath ~/.msf4/modules/
Loaded 0 modules:
Posting the answer for anyone who may come across this. I'm kinda new to this; didn't know where metasploit info gets logged.
It's in: ~/.msf4/logs/framework.log
The log told me I had a syntax error... must have happened from copying and pasting the text from the browser. Cleaned that up and everything works.

Maven error: Could not find or load main class .usr.share.maven.boot.plexus-classworlds-2.x.jar

I have recently upgraded my Ubuntu from 14.04 to 16.04 and started getting the following error when running any mvn commands (version 3.3.9): Error: Could not find or load main class .usr.share.maven.boot.plexus-classworlds-2.x.jar. My environment variables are declared as follows:
$JAVA_HOME: /usr/lib/jvm/java-8-oracle
$PATH: /usr/local/texlive/2015/bin/x86_64-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$M2_HOME: /usr/share/maven
$M2: /usr/share/maven/bin
When trying to find a solution, I've tried removing the M2 and M2_HOME variables as suggested on various threads, which resulted in getting a different error: Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher. I have also tried running apt-get remove --purge maven and installing it again as well as downloading the .tar.gz archive, but in both cases, nothing has changed.
When looking into the /usr/share/maven/boot folder, there is a chain of symlinks pointing from plexus-classworlds-2.x.jar -> /usr/share/java/plexus-classworlds2-2.5.2.jar. Am I missing some dependencies? Or are there any old configuration files that did not get removed by --purge?
EDIT: When I execute mvn as root, I get the Launcher error instead of plexus-classworlds-2.x. Also, I have completely removed and reinstalled all plexus libraries, yet with no change.
Check if /usr/share/maven/boot has multiple jars with pattern /usr/share/maven/boot/plexus-classworlds-*.jar.
Mine was something like:
drwxr-xr-x 2 root root 4096 Dec 23 14:21 ./
drwxr-xr-x 6 root root 4096 Nov 14 2015 ../
-rw-r--r-- 1 root root 52684 Dec 12 2015 plexus-classworlds-2.5.2.jar
lrwxrwxrwx 1 root root 34 Dec 10 2015 plexus-classworlds-2.x.jar -> ../../java/plexus-classworlds2.jar
This messes up /usr/share/maven/bin/mvn bash script and executes a wrong java command.
I had to remove the jar and leave only the symbolic link.

Unable to integrate text editor into Moodle 2

I have not been able to integrate CkEditor with Moodle 2.9.1+. (I suspect the issue would apply to any text editor, not just CkEditor.)
Per the README instructions, I cloned moodle-ckeditor from https://github.com/electrolinux/moodle-ckeditor into the lib/editor directory of the moodle installation I administer.
I renamed the downloaded directory from moodle-ckeditor to ckeditor.
I added this line to config.php in the root moodle directory:
$CFG->texteditors='ckeditor,tinymce,htmlarea';
When I navigate to Admin > Plugins > Text editors > Manage editors, I only see the original 3 editors: TinyMCS HTML editor, Plain text area, and Atto HTML editor.
FWIW, when I experimentally removed "tinymce," from the shown line of config.php, it still showed up on the "Manage editors" page. That makes me think that $CFG->texteditors is not being used. I do know it is being read, because I get an error on the "Manage editors" page if I put a syntax error into that line.
I've appended a console session in case to call attention to or rule out mistakes due to typos, permissions, etc.:
[~/public_html]# grep ckeditor config.php
$CFG->texteditors='ckeditor,tinymce,htmlarea';
[~/public_html]# ls -l lib/editor
total 28
drwxr-xr-x 7 millscso millscso 4096 Jul 23 16:09 ./
drwxr-xr-x 48 millscso millscso 4096 Jul 16 02:16 ../
drwxr-xr-x 9 millscso millscso 4096 Jul 16 02:16 atto/
drwxr-xr-x 5 millscso millscso 4096 Jul 23 16:09 ckeditor/
drwxr-xr-x 7 millscso millscso 4096 Jul 23 15:59 ckeditor-/
-rw-r--r-- 1 millscso millscso 0 Jul 16 02:16 index.html
drwxr-xr-x 3 millscso millscso 4096 Jul 16 02:16 textarea/
drwxr-xr-x 9 millscso millscso 4096 Jul 16 02:16 tinymce/
Update
A few days after reverting the change to config.php, "CKEditor HTML editor" began showing up within Admin > Plugins > Text editors > Manage editors. Unfortunately, when I click on Settings [http://mills-cs.org/admin/settings.php?section=editorsettingsckeditor], I get a Section error.
Works for me with Moodle 2.7, here's what I did
git clone https://github.com/electrolinux/moodle-ckeditor.git
copied and pasted the folder /moodle-ckeditor/ into moodlewww/lib/editor/
renamed moodlewww/lib/editor/moodle-ckeditor/ to moodlewww/lib/editor/ckeditor/
Logged into my site and clicked on site admin -> notifications to install ckeditor
I skipped $CFG->texteditors='ckeditor,tinymce,htmlarea';
Instead went to site admin -> plugins -> editors -> manage editors then enabled ckeditor - this might be what's wrong in your case?
Then moved ckeditor up the list so it is first.
UPDATE:
I tried with an install of 2.9 and it failed because the version.php file is missing - I'm guessing this is a requirement in 2.9.
I always have the debugger on development. You might find it useful too, have these settings in config.php
// Developer settings - not for production!
error_reporting(E_ALL & ~E_STRICT);
ini_set('display_errors', 1);
$CFG->debug = E_ALL & ~E_STRICT;
$CFG->debugdisplay = true;
So I created the missing file /lib/editor/ckeditor/version.php with the contents below and it installed correctly in 2.9
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* CKEditor text editor integration version file.
*
* #package editor_ckeditor
* #copyright
* #license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2015073000; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2015051100; // Requires this Moodle version
$plugin->component = 'editor_ckeditor'; // Full name of the plugin (used for diagnostics)

Phusion Passenger, mod_rails rails 2.3 problem

"The application has exited during startup (i.e. during the evaluation of config/environment.rb). The error message may have been written to the web server's log file. Please check the web server's log file (i.e. not the (Rails) application's log file) to find out why the application exited."
I'm getting the above error message when I try to access my test site.
Permission for config/* is
-rw-r--r-- 1 www-data root 2011 Aug 27 20:17 environment.rb
drwxr-xr-x 3 root root 4096 Aug 27 20:17 environments
drwxr-xr-x 3 root root 4096 Aug 27 20:17 initializers
drwxr-xr-x 3 root root 4096 Aug 27 20:17 locales
-rw-r--r-- 1 root root 2431 Aug 27 20:17 routes.rb
I've tried "root root 2011 Aug 27 20:17 environment.rb" as well but no success either.
I'm running Debian GNU/Linux and have other Rails sites running fine on the same server, I have tried to replicate the setup from one of the other sites, but it's not having any effect.
I encountered this same issue, and after killing passenger and apache ended up finding:
http://geminstallthat.wordpress.com/2009/03/01/passenger-with-rails-23-application-missingsourcefile/
Essentially the issue is for some versions of libapache2-mod-passenger the app/controllers/application.rb change to app/controllers/application_controller.rb (in Rails 2.3) explodes things (technical term).

Resources