mirror of
https://github.com/24eme/signaturepdf
synced 2026-03-14 13:55:44 +01:00
Merge branch 'master' of github.com:24eme/signaturepdf
This commit is contained in:
commit
aad3dddf88
6 changed files with 243 additions and 31 deletions
60
app.php
60
app.php
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
setlocale(LC_ALL, "");
|
||||
require(__DIR__.'/lib/GPGCryptography.class.php');
|
||||
require(__DIR__.'/lib/NSSCryptography.class.php');
|
||||
require(__DIR__.'/lib/PDFSignature.class.php');
|
||||
require(__DIR__.'/lib/Image2SVG.class.php');
|
||||
require(__DIR__.'/lib/Compression.class.php');
|
||||
|
|
@ -68,6 +69,11 @@ if (!$f3->exists('PDF_STORAGE_ENCRYPTION')) {
|
|||
$f3->set('PDF_STORAGE_ENCRYPTION', GPGCryptography::isGpgInstalled());
|
||||
}
|
||||
|
||||
if ($f3->exists('NSS3_DIRECTORY') && $f3->exists('NSS3_PASSWORD') && $f3->exists('NSS3_NICK')) {
|
||||
NSSCryptography::getInstance($f3->get('NSS3_DIRECTORY'), $f3->get('NSS3_PASSWORD'), $f3->get('NSS3_NICK'));
|
||||
}
|
||||
|
||||
|
||||
$domain = basename(glob($f3->get('ROOT')."/locale/application_*.pot")[0], '.pot');
|
||||
|
||||
bindtextdomain($domain, $f3->get('ROOT')."/locale");
|
||||
|
|
@ -167,7 +173,7 @@ $f3->route('POST /sign',
|
|||
$filename = null;
|
||||
$tmpfile = tempnam($f3->get('UPLOADS'), 'pdfsignature_sign');
|
||||
unlink($tmpfile);
|
||||
$svgFiles = "";
|
||||
$svgFiles = [];
|
||||
|
||||
$files = Web::instance()->receive(function($file,$formFieldName){
|
||||
if($formFieldName == "pdf" && strpos(Web::instance()->mime($file['tmp_name'], true), 'application/pdf') !== 0) {
|
||||
|
|
@ -186,7 +192,7 @@ $f3->route('POST /sign',
|
|||
}
|
||||
|
||||
if($formFieldName == "svg") {
|
||||
$svgFiles .= " ".$tmpfile."_".$fileBaseName;
|
||||
$svgFiles[] = $tmpfile."_".$fileBaseName;
|
||||
|
||||
return basename($tmpfile."_".$fileBaseName);
|
||||
}
|
||||
|
|
@ -196,12 +202,13 @@ $f3->route('POST /sign',
|
|||
$f3->error(403);
|
||||
}
|
||||
|
||||
if(!$svgFiles) {
|
||||
if(!count($svgFiles)) {
|
||||
$f3->error(403);
|
||||
}
|
||||
|
||||
shell_exec(sprintf("rsvg-convert -f pdf -o %s %s", $tmpfile.'.svg.pdf', $svgFiles));
|
||||
shell_exec(sprintf("pdftk %s multistamp %s output %s", $tmpfile.".pdf", $tmpfile.'.svg.pdf', $tmpfile.'_signe.pdf'));
|
||||
PDFSignature::createPDFFromSvg($svgFiles, $tmpfile.'.svg.pdf');
|
||||
PDFSignature::addSvgToPDF($tmpfile.'.pdf', $tmpfile.'.svg.pdf', $tmpfile.'_signe.pdf');
|
||||
|
||||
Web::instance()->send($tmpfile.'_signe.pdf', null, 0, TRUE, $filename);
|
||||
|
||||
if($f3->get('DEBUG')) {
|
||||
|
|
@ -215,21 +222,24 @@ $f3->route('POST /share',
|
|||
function($f3) {
|
||||
$hash = Web::instance()->slug($_POST['hash']);
|
||||
$sharingFolder = $f3->get('PDF_STORAGE_PATH').$hash;
|
||||
$f3->set('UPLOADS', $sharingFolder."/");
|
||||
$symmetricKey = (isset($_COOKIE[$hash])) ? GPGCryptography::protectSymmetricKey($_COOKIE[$hash]) : null;
|
||||
|
||||
if (!is_dir($f3->get('PDF_STORAGE_PATH'))) {
|
||||
$f3->error(500, 'Sharing folder doesn\'t exist');
|
||||
}
|
||||
if (!is_writable($f3->get('PDF_STORAGE_PATH'))) {
|
||||
$f3->error(500, 'Sharing folder is not writable');
|
||||
}
|
||||
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'));
|
||||
|
||||
$pdfSignature = new PDFSignature($sharingFolder, $symmetricKey);
|
||||
$pdfSignature->createShare($f3->get('POST.duration'));
|
||||
|
||||
$f3->set('UPLOADS', $sharingFolder."/");
|
||||
|
||||
$filename = "original.pdf";
|
||||
$tmpfile = tempnam($sharingFolder, date('YmdHis'));
|
||||
unlink($tmpfile);
|
||||
$svgFiles = "";
|
||||
$svgFiles = [];
|
||||
$files = Web::instance()->receive(function($file,$formFieldName){
|
||||
if($formFieldName == "pdf" && strpos(Web::instance()->mime($file['tmp_name'], true), 'application/pdf') !== 0) {
|
||||
$f3->error(403);
|
||||
|
|
@ -245,7 +255,7 @@ $f3->route('POST /share',
|
|||
return $filename;
|
||||
}
|
||||
if($formFieldName == "svg") {
|
||||
$svgFiles .= " ".$tmpfile."_".$fileBaseName;
|
||||
$svgFiles[] = $tmpfile."_".$fileBaseName;
|
||||
return basename($tmpfile."_".$fileBaseName);
|
||||
}
|
||||
});
|
||||
|
|
@ -253,26 +263,20 @@ $f3->route('POST /share',
|
|||
if(!count($files)) {
|
||||
$f3->error(403);
|
||||
}
|
||||
if($svgFiles) {
|
||||
shell_exec(sprintf("rsvg-convert -f pdf -o %s %s", $tmpfile.'.svg.pdf', $svgFiles));
|
||||
}
|
||||
if(!$f3->get('DEBUG')) {
|
||||
array_map('GPGCryptography::hardUnlink', glob($tmpfile."*.svg"));
|
||||
|
||||
$pdfSignature->saveShare();
|
||||
|
||||
if(count($svgFiles)) {
|
||||
$pdfSignature->addSignature($svgFiles, $tmpfile.".svg.pdf");
|
||||
}
|
||||
|
||||
$symmetricKey = "";
|
||||
if (isset($_COOKIE[$hash])) {
|
||||
$symmetricKey = "#" . $_COOKIE[$hash];
|
||||
$encryptor = new GPGCryptography($_COOKIE[$hash], $f3->get('PDF_STORAGE_PATH').$hash);
|
||||
if (!$encryptor->encrypt()) {
|
||||
GPGCryptography::hardUnlink($sharingFolder);
|
||||
$f3->error(500);
|
||||
}
|
||||
if(!$f3->get('DEBUG')) {
|
||||
$pdfSignature->clean();
|
||||
}
|
||||
|
||||
\Flash::instance()->setKey('openModal', 'shareinformations');
|
||||
|
||||
$f3->reroute($f3->get('REVERSE_PROXY_URL').'/signature/'.$hash.$symmetricKey);
|
||||
$f3->reroute($f3->get('REVERSE_PROXY_URL').'/signature/'.$hash.(($symmetricKey) ? '#'.$symmetricKey : null));
|
||||
}
|
||||
|
||||
);
|
||||
|
|
@ -320,7 +324,7 @@ $f3->route('POST /signature/@hash/save',
|
|||
}
|
||||
|
||||
$pdfSignature = new PDFSignature($f3->get('PDF_STORAGE_PATH').$hash, $symmetricKey);
|
||||
$pdfSignature->addSignature($svgFiles, $tmpfile."svg.pdf");
|
||||
$pdfSignature->addSignature($svgFiles, $tmpfile.".svg.pdf");
|
||||
|
||||
if(!$f3->get('DEBUG')) {
|
||||
$pdfSignature->clean();
|
||||
|
|
@ -339,7 +343,7 @@ $f3->route('GET /signature/@hash/nblayers',
|
|||
$files = scandir($f3->get('PDF_STORAGE_PATH').$hash);
|
||||
$nbLayers = 0;
|
||||
foreach($files as $file) {
|
||||
if(strpos($file, 'svg.pdf') !== false) {
|
||||
if(strpos($file, '.svg.pdf') !== false) {
|
||||
$nbLayers++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue