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 PagantisConfigModuleFrontController extends ModuleFrontController |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Initial method |
17
|
|
|
*/ |
18
|
|
|
public function initContent() |
19
|
|
|
{ |
20
|
|
|
$this->authorize(); |
21
|
|
|
$method = Tools::strtolower($_SERVER['REQUEST_METHOD']) . "Method"; |
|
|
|
|
22
|
|
|
if (method_exists($this, $method)) { |
23
|
|
|
header('HTTP/1.1 200 Ok', true, 200); |
24
|
|
|
header('Content-Type: application/json', true); |
25
|
|
|
$result = json_encode($this->{$method}()); |
26
|
|
|
header('Content-Length: ' . Tools::strlen($result)); |
27
|
|
|
echo $result; |
28
|
|
|
exit(); |
|
|
|
|
29
|
|
|
} |
30
|
|
|
header('HTTP/1.1 405 Method not allowed', true, 405); |
31
|
|
|
header('Content-Type: application/json', true); |
32
|
|
|
|
33
|
|
|
exit(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return array |
38
|
|
|
*/ |
39
|
|
|
public function getExtraConfigs() |
40
|
|
|
{ |
41
|
|
|
$sql_content = 'select * from ' . _DB_PREFIX_. 'pagantis_config'; |
|
|
|
|
42
|
|
|
$dbConfigs = Db::getInstance()->executeS($sql_content); |
|
|
|
|
43
|
|
|
|
44
|
|
|
$simpleDbConfigs = array(); |
45
|
|
|
foreach ($dbConfigs as $config) { |
46
|
|
|
$simpleDbConfigs[$config['config']] = $config['value']; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $simpleDbConfigs; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Update POST params in DB |
54
|
|
|
*/ |
55
|
|
|
public function postMethod() |
56
|
|
|
{ |
57
|
|
|
$errors = array(); |
58
|
|
|
$post = (_PS_VERSION_ < 1.6) ? $_POST + $_GET : Tools::getAllValues(); |
|
|
|
|
59
|
|
|
unset($post['fc']); |
60
|
|
|
unset($post['module']); |
61
|
|
|
unset($post['controller']); |
62
|
|
|
unset($post['secret']); |
63
|
|
|
if (count($post)) { |
64
|
|
|
foreach ($post as $config => $value) { |
65
|
|
|
$defaultConfigs = $this->getExtraConfigs(); |
66
|
|
|
if (isset($defaultConfigs[$config])) { |
67
|
|
|
Db::getInstance()->update( |
68
|
|
|
'pagantis_config', |
69
|
|
|
array('value' => pSQL($value)), |
|
|
|
|
70
|
|
|
'config = \''. pSQL($config) .'\'' |
71
|
|
|
); |
72
|
|
|
} else { |
73
|
|
|
$errors[$config] = $value; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} else { |
77
|
|
|
$errors['NO_POST_DATA'] = 'No post data provided'; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$dbConfigs = $this->getMethod(); |
81
|
|
|
if (count($errors) > 0) { |
82
|
|
|
$dbConfigs['__ERRORS__'] = $errors; |
83
|
|
|
} |
84
|
|
|
return $dbConfigs; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Read PTM configs |
89
|
|
|
* |
90
|
|
|
* @throws PrestaShopDatabaseException |
91
|
|
|
*/ |
92
|
|
|
public function getMethod() |
93
|
|
|
{ |
94
|
|
|
$sql_content = 'select * from ' . _DB_PREFIX_. 'pagantis_config'; |
|
|
|
|
95
|
|
|
$dbConfigs = Db::getInstance()->executeS($sql_content); |
96
|
|
|
|
97
|
|
|
$simpleDbConfigs = array(); |
98
|
|
|
foreach ($dbConfigs as $config) { |
99
|
|
|
$simpleDbConfigs[$config['config']] = $config['value']; |
100
|
|
|
} |
101
|
|
|
return $simpleDbConfigs; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return bool|null |
106
|
|
|
*/ |
107
|
|
|
public function authorize() |
108
|
|
|
{ |
109
|
|
|
$privateKey = Configuration::get('pagantis_private_key'); |
|
|
|
|
110
|
|
|
|
111
|
|
|
if (Tools::getValue('secret', false) == $privateKey) { |
112
|
|
|
return true; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
header('HTTP/1.1 403 Forbidden', true, 403); |
116
|
|
|
header('Content-Type: application/json', true); |
117
|
|
|
|
118
|
|
|
exit(); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
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