Passed
Push — master ( e0ed8e...0d3aa7 )
by Nils
11:00
created

itemAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
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) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $SETTINGS seems to be never defined.
Loading history...
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();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
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();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
87
    }
88
}