| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * This file is part of the official Pagantis module for PrestaShop. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @author    Pagantis <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @copyright 2019 Pagantis | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @license   proprietary | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * Class PagantisLogModuleFrontController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class PagantisLogModuleFrontController extends ModuleFrontController | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * @var string $message | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     protected $message; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * @var bool $error | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     protected $error = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * Controller index method: | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 27 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     public function postProcess() | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         if (!$this->authorize()) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |             return; | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |         }; | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |         $limit = 200; | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         $where = ''; | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         if (Tools::getValue('limit', false) && is_numeric(Tools::getValue('limit'))) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |             $limit = Tools::getValue('limit'); | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |         if (Tools::getValue('from', false)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |             $where = 'WHERE createdAt >= \'' . Tools::getValue('from') . '\''; | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |         $sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'pagantis_log ' . $where . ' ORDER BY id desc LIMIT ' . $limit; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |         if ($results = Db::getInstance()->ExecuteS($sql)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |             foreach ($results as $row) { | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |                 $data = (is_null(json_decode($row['log']))) ? $row['log'] : json_decode($row['log']); | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |                 if (is_array($data)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |                     $data['timestamp'] = $row['createdAt']; | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |                 } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |                     $data = array("message" => $data, 'timestamp' => $row['createdAt']); | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |                 $this->message[] = $data; | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |         $this->jsonResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * Send a jsonResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     public function jsonResponse() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $result = json_encode($this->message); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         header('HTTP/1.1 200 Ok', true, 200); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         header('Content-Type: application/json', true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         header('Content-Length: ' . Tools::strlen($result)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         echo $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         exit(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * @return bool|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     public function authorize() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $privateKey = Configuration::get('pagantis_private_key'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         if (Tools::getValue('secret', false) == $privateKey) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         header('HTTP/1.1 403 Forbidden', true, 403); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         header('Content-Type: application/json', true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         exit(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 87 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |  | 
            
                        
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths