1 | <?php |
||
2 | namespace DigitalOrigin\Pmt\Controller\Payment; |
||
3 | |||
4 | use Magento\Framework\App\Action\Action; |
||
5 | |||
6 | class Log extends Action |
||
7 | { |
||
8 | /** |
||
9 | * @var mixed |
||
10 | */ |
||
11 | protected $config; |
||
12 | |||
13 | public function __construct( |
||
14 | \Magento\Framework\App\Action\Context $context, |
||
15 | \DigitalOrigin\Pmt\Helper\Config $pmtConfig |
||
16 | ) { |
||
17 | $this->config = $pmtConfig->getConfig(); |
||
18 | return parent::__construct($context); |
||
19 | } |
||
20 | |||
21 | public function execute() |
||
22 | { |
||
23 | try { |
||
24 | $secretKey = $this->getRequest()->getParam('secret'); |
||
25 | $privateKey = $this->config['secret_key']; |
||
26 | $file = 'var/log/pmt.log'; |
||
27 | if (file_exists($file) && $privateKey == $secretKey) { |
||
28 | header('Content-Description: File Transfer'); |
||
29 | header('Content-Type: application/octet-stream'); |
||
30 | header('Content-Disposition: attachment; filename="'.basename($file).'"'); |
||
31 | header('Expires: 0'); |
||
32 | header('Cache-Control: must-revalidate'); |
||
33 | header('Pragma: public'); |
||
34 | header('Content-Length: ' . filesize($file)); |
||
35 | readfile($file); |
||
36 | exit; |
||
0 ignored issues
–
show
|
|||
37 | } else { |
||
38 | die('ERROR'); |
||
0 ignored issues
–
show
|
|||
39 | } |
||
40 | } catch (\Exception $e) { |
||
41 | die($e->getMessage()); |
||
42 | } |
||
43 | } |
||
44 | } |
||
45 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.