1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the official Paylater module for PrestaShop. |
4
|
|
|
* |
5
|
|
|
* @author Paga+Tarde <[email protected]> |
6
|
|
|
* @copyright 2019 Paga+Tarde |
7
|
|
|
* @license proprietary |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class PaylaterLogModuleFrontController |
12
|
|
|
*/ |
13
|
|
|
class PaylaterConfigModuleFrontController 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 false|string |
38
|
|
|
* @throws PrestaShopDatabaseException |
39
|
|
|
*/ |
40
|
|
|
public function getExtraConfigs() |
41
|
|
|
{ |
42
|
|
|
$sql_content = 'select * from ' . _DB_PREFIX_. 'pmt_config'; |
|
|
|
|
43
|
|
|
$dbConfigs = Db::getInstance()->executeS($sql_content); |
|
|
|
|
44
|
|
|
|
45
|
|
|
// Convert a multimple dimension array for SQL insert statements into a simple key/value |
46
|
|
|
$simpleDbConfigs = array(); |
47
|
|
|
foreach ($dbConfigs as $config) { |
48
|
|
|
$simpleDbConfigs[$config['config']] = $config['value']; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $simpleDbConfigs; |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Update POST params in DB |
56
|
|
|
*/ |
57
|
|
|
public function postMethod() |
58
|
|
|
{ |
59
|
|
|
$errors = array(); |
60
|
|
|
$post = (_PS_VERSION_ < 1.6) ? $_POST + $_GET : Tools::getAllValues(); |
|
|
|
|
61
|
|
|
unset($post['fc']); |
62
|
|
|
unset($post['module']); |
63
|
|
|
unset($post['controller']); |
64
|
|
|
unset($post['secret']); |
65
|
|
|
if (count($post)) { |
66
|
|
|
foreach ($post as $config => $value) { |
67
|
|
|
$defaultConfigs = $this->getExtraConfigs(); |
68
|
|
|
if (isset($defaultConfigs[$config])) { |
69
|
|
|
Db::getInstance()->update( |
70
|
|
|
'pmt_config', |
71
|
|
|
array('value' => pSQL($value)), |
|
|
|
|
72
|
|
|
'config = \''. pSQL($config) .'\'' |
73
|
|
|
); |
74
|
|
|
} else { |
75
|
|
|
$errors[$config] = $value; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} else { |
79
|
|
|
$errors['NO_POST_DATA'] = 'No post data provided'; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$dbConfigs = $this->getMethod(); |
83
|
|
|
if (count($errors) > 0) { |
84
|
|
|
$dbConfigs['__ERRORS__'] = $errors; |
85
|
|
|
} |
86
|
|
|
return $dbConfigs; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Read PTM configs |
91
|
|
|
* |
92
|
|
|
* @throws PrestaShopDatabaseException |
93
|
|
|
*/ |
94
|
|
|
public function getMethod() |
95
|
|
|
{ |
96
|
|
|
$sql_content = 'select * from ' . _DB_PREFIX_. 'pmt_config'; |
|
|
|
|
97
|
|
|
$dbConfigs = Db::getInstance()->executeS($sql_content); |
98
|
|
|
|
99
|
|
|
$simpleDbConfigs = array(); |
100
|
|
|
foreach ($dbConfigs as $config) { |
101
|
|
|
$simpleDbConfigs[$config['config']] = $config['value']; |
102
|
|
|
} |
103
|
|
|
return $simpleDbConfigs; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return bool|null |
108
|
|
|
*/ |
109
|
|
|
public function authorize() |
110
|
|
|
{ |
111
|
|
|
$privateKey = Configuration::get('pmt_private_key'); |
|
|
|
|
112
|
|
|
|
113
|
|
|
if (Tools::getValue('secret', false) == $privateKey) { |
114
|
|
|
return true; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
header('HTTP/1.1 403 Forbidden', true, 403); |
118
|
|
|
header('Content-Type: application/json', true); |
119
|
|
|
|
120
|
|
|
exit(); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
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