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 index.php |
14
|
|
|
* --- |
15
|
|
|
* |
16
|
|
|
* @author Nils Laumaillé ([email protected]) |
17
|
|
|
* |
18
|
|
|
* @copyright 2009-2025 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
|
|
|
// Determine the protocol used |
27
|
|
|
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https://' : 'http://'; |
28
|
|
|
|
29
|
|
|
// Validate and filter the host |
30
|
|
|
$host = filter_var($_SERVER['HTTP_HOST'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME); |
31
|
|
|
|
32
|
|
|
// Allocate the correct CORS header |
33
|
|
|
if ($host !== false) { |
34
|
|
|
header("Access-Control-Allow-Origin: $protocol$host"); |
35
|
|
|
} else { |
36
|
|
|
header("Access-Control-Allow-Origin: 'null'"); |
37
|
|
|
} |
38
|
|
|
header("Content-Type: application/json; charset=UTF-8"); |
39
|
|
|
header("Access-Control-Allow-Methods: POST, GET"); |
40
|
|
|
header("Access-Control-Max-Age: 3600"); |
41
|
|
|
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"); |
42
|
|
|
require __DIR__ . "/inc/bootstrap.php"; |
43
|
|
|
|
44
|
|
|
// sanitize url segments |
45
|
|
|
$base = new BaseController(); |
|
|
|
|
46
|
|
|
$uri = $base->getUriSegments(); |
47
|
|
|
if (!is_array($uri)) { |
48
|
|
|
$uri = [$uri]; // ensure $uril is table |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
// Prepare DB password |
52
|
|
|
if (defined('DB_PASSWD_CLEAR') === false) { |
53
|
|
|
define('DB_PASSWD_CLEAR', cryption(DB_PASSWD, '', 'decrypt', $SETTINGS)['string']); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// Do initial checks |
57
|
|
|
$apiStatus = json_decode(apiIsEnabled(), true); |
58
|
|
|
$jwtStatus = json_decode(verifyAuth(), true); |
59
|
|
|
|
60
|
|
|
// Authorization handler |
61
|
|
|
if ($uri[0] === 'authorize') { |
62
|
|
|
// Is API enabled in Teampass settings |
63
|
|
|
if ($apiStatus['error'] === false) { |
64
|
|
|
require API_ROOT_PATH . "/Controller/Api/AuthController.php"; |
65
|
|
|
$objFeedController = new AuthController(); |
66
|
|
|
$strMethodName = $uri[0] . 'Action'; |
67
|
|
|
$objFeedController->{$strMethodName}(); |
68
|
|
|
} else { |
69
|
|
|
// Error management |
70
|
|
|
errorHdl( |
71
|
|
|
$apiStatus['error_header'], |
72
|
|
|
json_encode(['error' => $apiStatus['error_message']]) |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
} elseif ($jwtStatus['error'] === false) { |
76
|
|
|
// get infos from JWT parameters |
77
|
|
|
$userData = json_decode(getDataFromToken(), true); |
78
|
|
|
|
79
|
|
|
// define the position of controller in $uri |
80
|
|
|
$controller = $uri[0]; |
81
|
|
|
$action = $uri[1]; |
82
|
|
|
//error_log("API - controller: ".$controller." | action: ".$action." || ");//.print_r($userData, true) |
83
|
|
|
if ($userData['error'] === true) { |
84
|
|
|
// Error management |
85
|
|
|
errorHdl( |
86
|
|
|
$userData['error_header'], |
87
|
|
|
json_encode(['error' => $userData['error_message']]) |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
// action related to USER |
91
|
|
|
} elseif ($controller === 'user') { |
92
|
|
|
require API_ROOT_PATH . "/Controller/Api/UserController.php"; |
93
|
|
|
$objFeedController = new UserController(); |
94
|
|
|
$strMethodName = (string) $action . 'Action'; |
95
|
|
|
$objFeedController->{$strMethodName}(); |
96
|
|
|
|
97
|
|
|
// action related to ITEM |
98
|
|
|
} elseif ($controller === 'item') { |
99
|
|
|
// Manage requested action |
100
|
|
|
itemAction( |
101
|
|
|
array_slice($uri, 1), |
102
|
|
|
$userData['data'] |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
// action related to FOLDER |
106
|
|
|
} elseif ($controller === 'folder') { |
107
|
|
|
// Manage requested action |
108
|
|
|
folderAction( |
109
|
|
|
array_slice($uri, 1), |
110
|
|
|
$userData['data'] |
111
|
|
|
); |
112
|
|
|
} else { |
113
|
|
|
errorHdl( |
114
|
|
|
"HTTP/1.1 404 Not Found", |
115
|
|
|
json_encode(['error' => 'No action provided']) |
116
|
|
|
); |
117
|
|
|
} |
118
|
|
|
// manage error case |
119
|
|
|
} else { |
120
|
|
|
if ($jwtStatus['error'] === true) { |
121
|
|
|
errorHdl( |
122
|
|
|
$jwtStatus['error_header'], |
123
|
|
|
json_encode(['error' => $jwtStatus['error_message']]) |
124
|
|
|
); |
125
|
|
|
} else { |
126
|
|
|
errorHdl( |
127
|
|
|
"HTTP/1.1 404 Not Found", |
128
|
|
|
json_encode(['error' => 'Access denied']) |
129
|
|
|
); |
130
|
|
|
} |
131
|
|
|
} |
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