diff --git a/app.php b/app.php index 4e98468..ccc5630 100644 --- a/app.php +++ b/app.php @@ -292,12 +292,37 @@ $f3->route('POST /share', } \Flash::instance()->setKey('openModal', 'shareinformations'); + \Flash::instance()->setKey("adminKey", $pdfSignature->createAdminKey()); $f3->reroute($f3->get('REVERSE_PROXY_URL').'/signature/'.$hash.(($symmetricKey) ? '#'.$symmetricKey : null)); } ); +$f3->route('GET @signature_deletion: /signature/@hash/delete/@key', function ($f3) { + $sharingFolder = $f3->get('PDF_STORAGE_PATH'); + $baseHash = $sharingFolder.$f3->get('PARAMS.hash'); + + if (is_dir($baseHash) === false) { + $f3->error(403); + } + + if (is_file($baseHash.'.admin') === false || is_readable($baseHash.'.admin') === false) { + $f3->error(403); + } + + if (file_get_contents($baseHash.'.admin') !== $f3->get('PARAMS.key')) { + $f3->error(403); + } + + GPGCryptography::hardUnlink($baseHash.'/.lock'); + GPGCryptography::hardUnlink($baseHash); + unlink($baseHash.'.admin'); + unlink($baseHash.'.expire'); + + $f3->reroute($f3->get('REVERSE_PROXY_URL').'/signature'); +}); + $f3->route('GET /signature/@hash/pdf', function($f3) { $f3->set('activeTab', 'sign'); diff --git a/lib/GPGCryptography.class.php b/lib/GPGCryptography.class.php index 5df6c54..b542478 100644 --- a/lib/GPGCryptography.class.php +++ b/lib/GPGCryptography.class.php @@ -90,8 +90,7 @@ class GPGCryptography return preg_replace('/[^0-9a-zA-Z]*/', '', $key); } - public static function createSymmetricKey() { - $length = 15; + public static function createSymmetricKey($length = 15) { $keySpace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $pieces = []; $max = mb_strlen($keySpace, '8bit') - 1; diff --git a/lib/PDFSignature.class.php b/lib/PDFSignature.class.php index f9ee2c8..15e28d1 100644 --- a/lib/PDFSignature.class.php +++ b/lib/PDFSignature.class.php @@ -30,6 +30,14 @@ class PDFSignature } } + public function createAdminKey() + { + $link = $this->gpg->createSymmetricKey(20); + file_put_contents($this->pathHash.'.admin', $link); + + return $link; + } + public function verifyEncryption() { if(!$this->isEncrypted()) { diff --git a/templates/signature.html.php b/templates/signature.html.php index d7495ea..acd3192 100644 --- a/templates/signature.html.php +++ b/templates/signature.html.php @@ -317,6 +317,34 @@ pdfHash = ""; + hasKey('adminKey')): ?> + localStorage.setItem(pdfHash+'.adminKey', 'getKey('adminKey') ?>') + + + const adminKey = localStorage.getItem(pdfHash+'.adminKey') + if (adminKey) { + const icon = document.createElement('i') + icon.classList.add('float-end', 'bi', 'bi-trash3') + icon.style.cursor = 'pointer' + document.getElementById('text_document_name').appendChild(icon) + + icon.addEventListener('click', async function () { + if (confirm("Êtes vous sûr de vouloir supprimer ce PDF ainsi que les signatures associées ?")) { + try { + const response = await fetch('/signature/'+pdfHash+'/delete/'+adminKey); + if (!response.ok) { + throw new Error(`Response status: ${response.status}`); + } + + localStorage.removeItem(pdfHash+'.adminKey') + window.location.replace('/signature') + } catch (error) { + console.error(error.message); + } + } + }) + } + var trad = _('Text to modify') ]); ?>;