|
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 API |
|
11
|
|
|
* |
|
12
|
|
|
* @file bootstrap.php |
|
13
|
|
|
* --- |
|
14
|
|
|
* |
|
15
|
|
|
* @author Nils Laumaillé ([email protected]) |
|
16
|
|
|
* |
|
17
|
|
|
* @copyright 2009-2022 Teampass.net |
|
18
|
|
|
* |
|
19
|
|
|
* @license https://spdx.org/licenses/GPL-3.0-only.html#licenseText GPL-3.0 |
|
20
|
|
|
* --- |
|
21
|
|
|
* |
|
22
|
|
|
* @see https://www.teampass.net |
|
23
|
|
|
*/ |
|
24
|
|
|
define("PROJECT_ROOT_PATH", __DIR__ . "/.."); |
|
25
|
|
|
// include main configuration file |
|
26
|
|
|
require __DIR__ . '/../../includes/config/settings.php'; |
|
27
|
|
|
require __DIR__ . '/../../includes/config/tp.config.php'; |
|
28
|
|
|
require __DIR__ . '/../../sources/main.functions.php'; |
|
29
|
|
|
|
|
30
|
|
|
// include the base controller file |
|
31
|
|
|
require PROJECT_ROOT_PATH . "/Controller/Api/BaseController.php"; |
|
32
|
|
|
|
|
33
|
|
|
// include the use model file |
|
34
|
|
|
require PROJECT_ROOT_PATH . "/Model/UserModel.php"; |
|
35
|
|
|
require PROJECT_ROOT_PATH . "/Model/ItemModel.php"; |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
function itemAction($actions) |
|
39
|
|
|
{ |
|
40
|
|
|
require PROJECT_ROOT_PATH . "/Controller/Api/ItemController.php"; |
|
41
|
|
|
|
|
42
|
|
|
$objFeedController = new ItemController(); |
|
43
|
|
|
$strMethodName = $actions[0] . 'Action'; |
|
44
|
|
|
$objFeedController->{$strMethodName}(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/* |
|
48
|
|
|
function sanitizeUrl(array $array, string $path) : array |
|
49
|
|
|
{ |
|
50
|
|
|
$filters = []; |
|
51
|
|
|
for ($i=0; $i < count($array); $i++) { |
|
52
|
|
|
array_push($filters, 'trim|escape'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return dataSanitizer( |
|
56
|
|
|
$array, |
|
57
|
|
|
$filters, |
|
58
|
|
|
$path |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
*/ |
|
62
|
|
|
|
|
63
|
|
|
function apiIsEnabled() |
|
64
|
|
|
{ |
|
65
|
|
|
require '../includes/config/tp.config.php'; |
|
66
|
|
|
|
|
67
|
|
|
if ((int) $SETTINGS['api'] === 1) { |
|
|
|
|
|
|
68
|
|
|
return true; |
|
69
|
|
|
} else { |
|
70
|
|
|
header("HTTP/1.1 404 Not Found"); |
|
71
|
|
|
echo json_encode(array('error' => 'API usage is not allowed')); |
|
72
|
|
|
exit(); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
function verifyAuth() |
|
77
|
|
|
{ |
|
78
|
|
|
include_once PROJECT_ROOT_PATH . '/inc/jwt_utils.php'; |
|
79
|
|
|
$bearer_token = get_bearer_token(); |
|
80
|
|
|
|
|
81
|
|
|
if (empty($bearer_token) === false && is_jwt_valid($bearer_token) === true) { |
|
82
|
|
|
return true; |
|
83
|
|
|
} else { |
|
84
|
|
|
header("HTTP/1.1 404 Not Found"); |
|
85
|
|
|
echo json_encode(array('error' => 'Access denied')); |
|
86
|
|
|
exit(); |
|
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
} |