Skip to content

Commit

Permalink
Hardunlink for directory + typo
Browse files Browse the repository at this point in the history
  • Loading branch information
tale-fau committed Jul 30, 2024
1 parent aa16fe6 commit 356d8a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 5 additions & 2 deletions app.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,11 @@ function($f3) {
if($f3->get('DEBUG')) {
return;
}

array_map('unlink', glob($finalFile."*"));
if ($f3->get('PDF_STORAGE_PATH') != $sharingFolder && $cryptor->isEncrypted()) {
CryptographyClass::hardUnlink($sharingFolder);
} else {
array_map('unlink', glob($finalFile."*"));
}
}
);

Expand Down
13 changes: 10 additions & 3 deletions lib/cryptography.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function encrypt() {
$command = "gpg --batch --passphrase $this->symmetricKey --symmetric --cipher-algo AES256 -o $outputFile $file";
$result = shell_exec($command);
if ($result) {
echo "Cypher failure";
echo "Cipher failure";
return $result;
}
$this->hardUnlink($file);
Expand All @@ -46,15 +46,15 @@ public function decrypt() {
if (!$this->symmetricKey) {
return false;
}
$decryptFolder = sys_get_temp_dir()."/".uniqid('pdfsignature.'.getmypid(), true);
$decryptFolder = sys_get_temp_dir()."/".uniqid('pdfsignature.decrypted.'.getmypid(), true);
echo $decryptFolder."\n";
mkdir($decryptFolder);
foreach ($this->getFiles(true) as $file) {
$outputFile = $decryptFolder."/".str_replace(".gpg", "", basename($file));
$command = "gpg --batch --passphrase $this->symmetricKey --decrypt -o $outputFile $file";
$result = shell_exec($command);
if ($result) {
throw new Exception("Decypher failure");
throw new Exception("Decipher failure");
}
}
return $decryptFolder;
Expand All @@ -68,6 +68,13 @@ public static function hardUnlink($element) {
if (!$element) {
return;
}
if (is_dir($element)) {
foreach (glob($element.'/*') as $file) {
self::hardUnlink($file);
}
rmdir($element);
return;
}
$eraser = str_repeat(0, strlen(file_get_contents($element)));
file_put_contents($element, $eraser);
unlink($element);
Expand Down

0 comments on commit 356d8a4

Please sign in to comment.