|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Teampass - a collaborative passwords manager. |
|
4
|
|
|
* --- |
|
5
|
|
|
* This library is distributed in the hope that it will be useful, |
|
6
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
7
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
8
|
|
|
* --- |
|
9
|
|
|
* |
|
10
|
|
|
* @project Teampass |
|
11
|
|
|
* @version API |
|
12
|
|
|
* |
|
13
|
|
|
* @file BaseController.php |
|
14
|
|
|
* --- |
|
15
|
|
|
* |
|
16
|
|
|
* @author Nils Laumaillé ([email protected]) |
|
17
|
|
|
* |
|
18
|
|
|
* @copyright 2009-2023 Teampass.net |
|
19
|
|
|
* |
|
20
|
|
|
* @license https://spdx.org/licenses/GPL-3.0-only.html#licenseText GPL-3.0 |
|
21
|
|
|
* --- |
|
22
|
|
|
* |
|
23
|
|
|
* @see https://www.teampass.net |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
use TeampassClasses\SuperGlobal\SuperGlobal; |
|
28
|
|
|
|
|
29
|
|
|
class BaseController |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* __call magic method. |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __call($name, $arguments) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->sendOutput('', array('HTTP/1.1 404 Not Found')); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Get URI elements. |
|
41
|
|
|
* |
|
42
|
|
|
* @return array|string |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getUriSegments() |
|
45
|
|
|
{ |
|
46
|
|
|
$superGlobal = new SuperGlobal(); |
|
47
|
|
|
$uri = parse_url($superGlobal->get('REQUEST_URI', 'SERVER'), PHP_URL_PATH); |
|
48
|
|
|
$uri = explode( '/', $uri ); |
|
49
|
|
|
return $this->sanitizeUrl(array_slice($uri, ((int) array_search('index.php', $uri) + 1))); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Get querystring params. |
|
54
|
|
|
* |
|
55
|
|
|
* @return array|string |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getQueryStringParams() |
|
58
|
|
|
{ |
|
59
|
|
|
$superGlobal = new SuperGlobal(); |
|
60
|
|
|
parse_str(html_entity_decode($superGlobal->get('QUERY_STRING', 'SERVER')), $query); |
|
61
|
|
|
return $this->sanitizeUrl($query); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Undocumented function |
|
66
|
|
|
* |
|
67
|
|
|
* @param array $array |
|
68
|
|
|
* @return array|string |
|
69
|
|
|
*/ |
|
70
|
|
|
public function sanitizeUrl(array $array) |
|
71
|
|
|
{ |
|
72
|
|
|
$filters = []; |
|
73
|
|
|
$array_size = count($array); |
|
74
|
|
|
for ($i=0; $i < $array_size; $i++) { |
|
75
|
|
|
array_push($filters, 'trim|escape'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return dataSanitizer( |
|
79
|
|
|
$array, |
|
80
|
|
|
$filters, |
|
81
|
|
|
__DIR__.'/../../..' |
|
|
|
|
|
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Send API output. |
|
88
|
|
|
* |
|
89
|
|
|
* @param mixed $data |
|
90
|
|
|
* @param string $httpHeader |
|
91
|
|
|
*/ |
|
92
|
|
|
protected function sendOutput($data, $httpHeaders=array()): void |
|
93
|
|
|
{ |
|
94
|
|
|
header_remove('Set-Cookie'); |
|
95
|
|
|
|
|
96
|
|
|
if (is_array($httpHeaders) && count($httpHeaders)) { |
|
97
|
|
|
foreach ($httpHeaders as $httpHeader) { |
|
98
|
|
|
header($httpHeader); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
echo $data; |
|
103
|
|
|
} |
|
104
|
|
|
} |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.