From 432b9b52b8ef9b9acd8a1d471c9e90e0867a46fa Mon Sep 17 00:00:00 2001 From: owen-oj Date: Tue, 22 Feb 2022 12:36:40 +0000 Subject: [PATCH] added laravel 9 support --- composer.json | 2 +- src/FpdfPasswordProtectFacade.php | 21 --- src/PDFPasswordProtect.php | 10 +- src/PDFPasswordProtectServiceProvider.php | 26 +-- src/Scripts/FpdfProtection.php | 214 ---------------------- 5 files changed, 7 insertions(+), 266 deletions(-) delete mode 100644 src/FpdfPasswordProtectFacade.php delete mode 100644 src/Scripts/FpdfProtection.php diff --git a/composer.json b/composer.json index 13edf85..9fccd2a 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ ], "require": { "php": "^7.4|^8.0", - "illuminate/support": "^6.0|^7.0|^8.0", + "illuminate/support": "^7.0|^8.0|^9.0", "mpdf/mpdf": "^8.0" }, "require-dev": { diff --git a/src/FpdfPasswordProtectFacade.php b/src/FpdfPasswordProtectFacade.php deleted file mode 100644 index 21dceb2..0000000 --- a/src/FpdfPasswordProtectFacade.php +++ /dev/null @@ -1,21 +0,0 @@ -setSourceFile($inputFile); $tplId = $mpdf->ImportPage($pagecount); $mpdf->UseTemplate($tplId); - + //set owner password to user password if null $ownerPassword = is_null($ownerPassword) ? $password : $ownerPassword; - + $mpdf->SetProtection(array('copy', 'print'), $password, $ownerPassword); - - $mpdf->Output($outputFile,\Mpdf\Output\Destination::FILE,); + + $mpdf->Output($outputFile, \Mpdf\Output\Destination::FILE,); } } diff --git a/src/PDFPasswordProtectServiceProvider.php b/src/PDFPasswordProtectServiceProvider.php index c6aef0c..0babe43 100644 --- a/src/PDFPasswordProtectServiceProvider.php +++ b/src/PDFPasswordProtectServiceProvider.php @@ -11,36 +11,12 @@ class PdfPasswordProtectServiceProvider extends ServiceProvider */ public function boot() { - /* - * Optional methods to load your package assets - */ - // $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'pdf-password-protect'); - // $this->loadViewsFrom(__DIR__.'/../resources/views', 'pdf-password-protect'); - // $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); - // $this->loadRoutesFrom(__DIR__.'/routes.php'); + if ($this->app->runningInConsole()) { $this->publishes([ __DIR__.'/../config/config.php' => config_path('pdf-password-protect.php'), ], 'config'); - - // Publishing the views. - /*$this->publishes([ - __DIR__.'/../resources/views' => resource_path('views/vendor/pdf-password-protect'), - ], 'views');*/ - - // Publishing assets. - /*$this->publishes([ - __DIR__.'/../resources/assets' => public_path('vendor/pdf-password-protect'), - ], 'assets');*/ - - // Publishing the translation files. - /*$this->publishes([ - __DIR__.'/../resources/lang' => resource_path('lang/vendor/pdf-password-protect'), - ], 'lang');*/ - - // Registering package commands. - // $this->commands([]); } } diff --git a/src/Scripts/FpdfProtection.php b/src/Scripts/FpdfProtection.php deleted file mode 100644 index 7d06ba8..0000000 --- a/src/Scripts/FpdfProtection.php +++ /dev/null @@ -1,214 +0,0 @@ - 4, 'modify' => 8, 'copy' => 16, 'annot-forms' => 32 ); - $protection = 192; - foreach($permissions as $permission) - { - if (!isset($options[$permission])) - $this->Error('Incorrect permission: '.$permission); - $protection += $options[$permission]; - } - if ($owner_pass === null) - $owner_pass = uniqid(rand()); - $this->encrypted = true; - $this->padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08". - "\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A"; - $this->_generateencryptionkey($user_pass, $owner_pass, $protection); - } - -/**************************************************************************** -* * -* Private methods * -* * -****************************************************************************/ - - function _putstream($s) - { - if ($this->encrypted) - $s = RC4($this->_objectkey($this->n), $s); - parent::_putstream($s); - } - - function _textstring($s) - { - if (!$this->_isascii($s)) - $s = $this->_UTF8toUTF16($s); - if ($this->encrypted) - $s = RC4($this->_objectkey($this->n), $s); - return '('.$this->_escape($s).')'; - } - - /** - * Compute key depending on object number where the encrypted data is stored - */ - function _objectkey($n) - { - return substr($this->_md5_16($this->encryption_key.pack('VXxx',$n)),0,10); - } - - function _putresources() - { - parent::_putresources(); - if ($this->encrypted) { - $this->_newobj(); - $this->enc_obj_id = $this->n; - $this->_put('<<'); - $this->_putencryption(); - $this->_put('>>'); - $this->_put('endobj'); - } - } - - function _putencryption() - { - $this->_put('/Filter /Standard'); - $this->_put('/V 1'); - $this->_put('/R 2'); - $this->_put('/O ('.$this->_escape($this->Ovalue).')'); - $this->_put('/U ('.$this->_escape($this->Uvalue).')'); - $this->_put('/P '.$this->Pvalue); - } - - function _puttrailer() - { - parent::_puttrailer(); - if ($this->encrypted) { - $this->_put('/Encrypt '.$this->enc_obj_id.' 0 R'); - $this->_put('/ID [()()]'); - } - } - - /** - * Get MD5 as binary string - */ - function _md5_16($string) - { - return md5($string, true); - } - - /** - * Compute O value - */ - function _Ovalue($user_pass, $owner_pass) - { - $tmp = $this->_md5_16($owner_pass); - $owner_RC4_key = substr($tmp,0,5); - return RC4($owner_RC4_key, $user_pass); - } - - /** - * Compute U value - */ - function _Uvalue() - { - return RC4($this->encryption_key, $this->padding); - } - - /** - * Compute encryption key - */ - function _generateencryptionkey($user_pass, $owner_pass, $protection) - { - // Pad passwords - $user_pass = substr($user_pass.$this->padding,0,32); - $owner_pass = substr($owner_pass.$this->padding,0,32); - // Compute O value - $this->Ovalue = $this->_Ovalue($user_pass,$owner_pass); - // Compute encyption key - $tmp = $this->_md5_16($user_pass.$this->Ovalue.chr($protection)."\xFF\xFF\xFF"); - $this->encryption_key = substr($tmp,0,5); - // Compute U value - $this->Uvalue = $this->_Uvalue(); - // Compute P value - $this->Pvalue = -(($protection^255)+1); - } -} - -