mirror of
https://github.com/24eme/signaturepdf
synced 2024-05-19 14:16:37 +02:00
PDF storage expiration time for multi-signature mode
This commit is contained in:
parent
b2ca7e81f3
commit
eca93fb359
29
app.php
29
app.php
|
@ -140,8 +140,8 @@ $f3->route('POST /sign',
|
||||||
$f3->route('POST /share',
|
$f3->route('POST /share',
|
||||||
function($f3) {
|
function($f3) {
|
||||||
$hash = substr(hash('sha512', uniqid().rand()), 0, 20);
|
$hash = substr(hash('sha512', uniqid().rand()), 0, 20);
|
||||||
$sharingFolder = $f3->get('PDF_STORAGE_PATH').$hash."/";
|
$sharingFolder = $f3->get('PDF_STORAGE_PATH').$hash;
|
||||||
$f3->set('UPLOADS', $sharingFolder);
|
$f3->set('UPLOADS', $sharingFolder."/");
|
||||||
if (!is_dir($f3->get('PDF_STORAGE_PATH'))) {
|
if (!is_dir($f3->get('PDF_STORAGE_PATH'))) {
|
||||||
$f3->error(500, 'Sharing folder doesn\'t exist');
|
$f3->error(500, 'Sharing folder doesn\'t exist');
|
||||||
}
|
}
|
||||||
|
@ -149,6 +149,9 @@ $f3->route('POST /share',
|
||||||
$f3->error(500, 'Sharing folder is not writable');
|
$f3->error(500, 'Sharing folder is not writable');
|
||||||
}
|
}
|
||||||
mkdir($sharingFolder);
|
mkdir($sharingFolder);
|
||||||
|
$expireFile = $sharingFolder.".expire";
|
||||||
|
file_put_contents($expireFile, $f3->get('POST.duration'));
|
||||||
|
touch($expireFile, date_format(date_modify(date_create(), file_get_contents($expireFile)), 'U'));
|
||||||
$filename = "original.pdf";
|
$filename = "original.pdf";
|
||||||
$tmpfile = tempnam($sharingFolder, date('YmdHis'));
|
$tmpfile = tempnam($sharingFolder, date('YmdHis'));
|
||||||
$svgFiles = "";
|
$svgFiles = "";
|
||||||
|
@ -164,7 +167,7 @@ $f3->route('POST /share',
|
||||||
return true;
|
return true;
|
||||||
}, false, function($fileBaseName, $formFieldName) use ($tmpfile, $filename, $sharingFolder, &$svgFiles) {
|
}, false, function($fileBaseName, $formFieldName) use ($tmpfile, $filename, $sharingFolder, &$svgFiles) {
|
||||||
if($formFieldName == "pdf") {
|
if($formFieldName == "pdf") {
|
||||||
file_put_contents($sharingFolder."filename.txt", $fileBaseName);
|
file_put_contents($sharingFolder."/filename.txt", $fileBaseName);
|
||||||
return $filename;
|
return $filename;
|
||||||
}
|
}
|
||||||
if($formFieldName == "svg") {
|
if($formFieldName == "svg") {
|
||||||
|
@ -229,12 +232,15 @@ $f3->route('GET /signature/@hash/pdf',
|
||||||
$f3->route('POST /signature/@hash/save',
|
$f3->route('POST /signature/@hash/save',
|
||||||
function($f3) {
|
function($f3) {
|
||||||
$hash = Web::instance()->slug($f3->get('PARAMS.hash'));
|
$hash = Web::instance()->slug($f3->get('PARAMS.hash'));
|
||||||
$sharingFolder = $f3->get('PDF_STORAGE_PATH').$hash.'/';
|
$sharingFolder = $f3->get('PDF_STORAGE_PATH').$hash;
|
||||||
$f3->set('UPLOADS', $sharingFolder);
|
$f3->set('UPLOADS', $sharingFolder.'/');
|
||||||
$tmpfile = tempnam($sharingFolder, date('YmdHis'));
|
$tmpfile = tempnam($sharingFolder, date('YmdHis'));
|
||||||
unlink($tmpfile);
|
unlink($tmpfile);
|
||||||
$svgFiles = "";
|
$svgFiles = "";
|
||||||
|
|
||||||
|
$expireFile = $sharingFolder.".expire";
|
||||||
|
touch($expireFile, date_format(date_modify(date_create(), file_get_contents($expireFile)), 'U'));
|
||||||
|
|
||||||
$files = Web::instance()->receive(function($file,$formFieldName){
|
$files = Web::instance()->receive(function($file,$formFieldName){
|
||||||
if($formFieldName == "svg" && strpos(Web::instance()->mime($file['tmp_name'], true), 'image/svg+xml') !== 0) {
|
if($formFieldName == "svg" && strpos(Web::instance()->mime($file['tmp_name'], true), 'image/svg+xml') !== 0) {
|
||||||
$f3->error(403);
|
$f3->error(403);
|
||||||
|
@ -275,6 +281,19 @@ $f3->route('GET /signature/@hash/nblayers',
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$f3->route('GET /cron', function($f3) {
|
||||||
|
$sharingFolder = $f3->get('PDF_STORAGE_PATH');
|
||||||
|
foreach(glob($sharingFolder.'*.expire') as $expireFile) {
|
||||||
|
if(filemtime($expireFile) > time()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$expiredFolder = str_replace('.expire', '', $expireFile);
|
||||||
|
array_map('unlink', glob($expiredFolder."/*"));
|
||||||
|
rmdir($expiredFolder);
|
||||||
|
unlink($expireFile);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$f3->route('GET /organization',
|
$f3->route('GET /organization',
|
||||||
function($f3) {
|
function($f3) {
|
||||||
$f3->set('maxSize', min(array(convertPHPSizeToBytes(ini_get('post_max_size')), convertPHPSizeToBytes(ini_get('upload_max_filesize')))));
|
$f3->set('maxSize', min(array(convertPHPSizeToBytes(ini_get('post_max_size')), convertPHPSizeToBytes(ini_get('upload_max_filesize')))));
|
||||||
|
|
|
@ -984,6 +984,12 @@ var modalSharing = function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var runCron = function() {
|
||||||
|
const xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('GET', '/cron');
|
||||||
|
xhr.send();
|
||||||
|
}
|
||||||
|
|
||||||
var pageUpload = async function() {
|
var pageUpload = async function() {
|
||||||
document.querySelector('body').classList.remove('bg-light');
|
document.querySelector('body').classList.remove('bg-light');
|
||||||
document.getElementById('input_pdf_upload').value = '';
|
document.getElementById('input_pdf_upload').value = '';
|
||||||
|
@ -1080,6 +1086,9 @@ var pageSignature = async function(url) {
|
||||||
};
|
};
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
|
if(sharingMode) {
|
||||||
|
setTimeout(function() { runCron() }, 2000);
|
||||||
|
}
|
||||||
if(hash) {
|
if(hash) {
|
||||||
pageSignature('/signature/'+hash+'/pdf');
|
pageSignature('/signature/'+hash+'/pdf');
|
||||||
window.addEventListener('hashchange', function() {
|
window.addEventListener('hashchange', function() {
|
||||||
|
|
|
@ -175,6 +175,7 @@
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<p>En activant le partage de ce PDF vous allez pouvoir proposer un lien aux personnes de votre choix pour qu'elles puissent signer ce PDF.</p>
|
<p>En activant le partage de ce PDF vous allez pouvoir proposer un lien aux personnes de votre choix pour qu'elles puissent signer ce PDF.</p>
|
||||||
<p><i class="bi bi-hdd-network"></i> Ce partage nécessite que le PDF soit transféré et stocké sur le serveur afin d'être accessible aux futurs signataires.</p>
|
<p><i class="bi bi-hdd-network"></i> Ce partage nécessite que le PDF soit transféré et stocké sur le serveur afin d'être accessible aux futurs signataires.</p>
|
||||||
|
<p class="mb-0"><i class="bi bi-hourglass-split"></i> Le PDF sera conservé <select name="duration" form="form_sharing"><option value="+1 year">un an</option><option value="+6 month">six mois</option><option value="+1 month" selected="selected">un mois</option><option value="+1 week">une semaine</option><option value="+1 day">un jour</option><option value="+1 hour">une heure</option></select> après la dernière signature.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer text-center d-block">
|
<div class="modal-footer text-center d-block">
|
||||||
<form id="form_sharing" clas action="/share" method="post" enctype="multipart/form-data">
|
<form id="form_sharing" clas action="/share" method="post" enctype="multipart/form-data">
|
||||||
|
@ -204,7 +205,7 @@
|
||||||
<button onclick="navigator.clipboard.writeText(document.getElementById('input-share-link').value); this.innerText = 'Copié !';" autofocus="autofocus" class="btn btn-primary" type="button" id="btn-copy-share-link"><i class="bi bi-clipboard"></i> Copier</button>
|
<button onclick="navigator.clipboard.writeText(document.getElementById('input-share-link').value); this.innerText = 'Copié !';" autofocus="autofocus" class="btn btn-primary" type="button" id="btn-copy-share-link"><i class="bi bi-clipboard"></i> Copier</button>
|
||||||
<script>document.querySelector('#input-share-link').value = document.location.href.replace(/#.*/, '');</script>
|
<script>document.querySelector('#input-share-link').value = document.location.href.replace(/#.*/, '');</script>
|
||||||
</div>
|
</div>
|
||||||
<p>Chacun des signataires pourra à tout moment télécharger la dernière version du PDF signé.</p>
|
<p class="mb-0">Chacun des signataires pourra à tout moment télécharger la dernière version du PDF signé.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer text-start">
|
<div class="modal-footer text-start">
|
||||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Fermer</button>
|
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Fermer</button>
|
||||||
|
@ -242,11 +243,12 @@
|
||||||
<script>
|
<script>
|
||||||
var maxSize = <?php echo $maxSize ?>;
|
var maxSize = <?php echo $maxSize ?>;
|
||||||
var maxPage = <?php echo $maxPage ?>;
|
var maxPage = <?php echo $maxPage ?>;
|
||||||
|
var sharingMode = <?php echo intval(!isset($noSharingMode)) ?>;
|
||||||
var hash = null;
|
var hash = null;
|
||||||
<?php if(isset($hash)): ?>
|
<?php if(isset($hash)): ?>
|
||||||
hash = "<?php echo $hash ?>";
|
hash = "<?php echo $hash ?>";
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</script>
|
</script>
|
||||||
<script src="/js/signature.js?202204150047"></script>
|
<script src="/js/signature.js?202204270035"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue