From 7c0c5ffbfed6e0753bc406a401419ccd419b5f14 Mon Sep 17 00:00:00 2001 From: Tanguy Le Faucheur Date: Thu, 23 Nov 2023 11:19:38 +0100 Subject: [PATCH] Add method to check if GPG is installed and a way to handle it's absence --- app.php | 6 +++++- lib/cryptography.class.php | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app.php b/app.php index d7a7bfc..45cd806 100644 --- a/app.php +++ b/app.php @@ -83,7 +83,11 @@ $f3->route('GET /signature', } if (!$f3->exists('PDF_STORAGE_ENCRYPTION')) { - $f3->set('PDF_STORAGE_ENCRYPTION', ''); + if (CryptographyClass::isGpgInstalled() == true) { + $f3->set('PDF_STORAGE_ENCRYPTION', 'true'); + } else { + $f3->set('PDF_STORAGE_ENCRYPTION', ''); + } } $f3->set('activeTab', 'sign'); diff --git a/lib/cryptography.class.php b/lib/cryptography.class.php index 7081f80..ce19de8 100644 --- a/lib/cryptography.class.php +++ b/lib/cryptography.class.php @@ -74,5 +74,17 @@ class CryptographyClass return implode('', $pieces); } + + public static function isGpgInstalled() { + $output = null; + $returnCode = null; + + exec('gpg --version', $output, $returnCode); + + if ($returnCode == 0) { + return true; + } + return false; + } } ?>