-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
93 lines (81 loc) · 3.66 KB
/
Copy pathindex.php
File metadata and controls
93 lines (81 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
declare(strict_types=1);
require __DIR__ . "/inc/bootstrap.php";
//variable declarations
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$uri = explode( '/', $uri );
$settings_json = json_decode(file_get_contents(__DIR__ . '/settings.json'));
$valid_path = explode(",", $settings_json->path);
if ((isset($uri[1]) && !(in_array($uri[1], $valid_path)))) {
header("HTTP/1.1 404 Not Found");
exit();
}
elseif (($uri[1] == $valid_path[0])
&& ($_SERVER['REQUEST_METHOD'] === "POST"))
{
if ($_SERVER["CONTENT_TYPE"] == "application/json") {
require PROJECT_ROOT_PATH . "/Controller/Api/UserController.php";
$objUserController = new UserController();
$objUserController->authenticate($settings_json);
}
else
{
header('Content-Type: application/json; charset=utf-8');
echo json_encode($settings_json->errors->request_content_type);
}
}
elseif ($uri[1] == $valid_path[1])
{
if ($_SERVER['REQUEST_METHOD'] === "GET")
{
if (($_SERVER["CONTENT_TYPE"] == "application/json") && !(isset($uri[2]))) {
require PROJECT_ROOT_PATH . "/Controller/Api/FileController.php";
require PROJECT_ROOT_PATH . "/Controller/Api/UserController.php";
$objUserController = new UserController();
$objFileController = new FileController();
if($objUserController->verify_credentials($settings_json)) {
$objFileController->getFiles($settings_json);
}
}
elseif (($_SERVER["CONTENT_TYPE"] == "application/json") && (isset($uri[2]))) {
require PROJECT_ROOT_PATH . "/Controller/Api/FileController.php";
require PROJECT_ROOT_PATH . "/Controller/Api/UserController.php";
$objUserController = new UserController();
$objFileController = new FileController();
if($objUserController->verify_credentials($settings_json)) {
$objFileController->getFile($settings_json, $uri[2]);
}
}
}
elseif ($_SERVER['REQUEST_METHOD'] === "POST") {
require PROJECT_ROOT_PATH . "/Controller/Api/FileController.php";
require PROJECT_ROOT_PATH . "/Controller/Api/UserController.php";
$objUserController = new UserController();
$objFileController = new FileController();
if($objUserController->verify_credentials($settings_json)) {
$objFileController->uploadFile($settings_json, $_FILES);
}
}
elseif ($_SERVER['REQUEST_METHOD'] === "DELETE") {
if (($_SERVER["CONTENT_TYPE"] == "application/json") && (isset($uri[2]))) {
require PROJECT_ROOT_PATH . "/Controller/Api/FileController.php";
require PROJECT_ROOT_PATH . "/Controller/Api/UserController.php";
$objUserController = new UserController();
$objFileController = new FileController();
if($objUserController->verify_credentials($settings_json)) {
$objFileController->deleteFile($settings_json, $uri[2]);
}
}
}
else
{
header('Content-Type: application/json; charset=utf-8');
echo json_encode($settings_json->errors->request_content_type);
}
}
else
{
header("HTTP/1.1 404 Not Found");
exit();
}
?>