-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
56 lines (45 loc) · 1.47 KB
/
index.php
File metadata and controls
56 lines (45 loc) · 1.47 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
<?php
// TODO: Check error behavior for different issues (e.g. not found response from s3)
require_once('setup.php');
function getAuthToken() {
$headers = apache_request_headers();
$header = isset($headers['Authorization']) ? $headers['Authorization'] : null;
return preg_match('/Bearer (.+)/', $header, $m) ? $m[1] : null;
}
$accesstoken = conf('accesstoken');
if ($accesstoken === null) throw new Exception("Missing access token configuration", 500);
if ($accesstoken !== false && getAuthToken() !== $accesstoken) throw new Exception("Invalid access token", 401);
$get = isset($_GET['get']) ? $_GET['get'] : 'status';
if ($get === 'status') {
test();
$info = ['status' => 'OK'];
sendJSON($info);
exit;
}
if ($get === 'computers') {
serveComputers();
exit;
}
if ($get === 'buckets') {
$computerID = validUUID($_GET['computer']);
serveBuckets($computerID);
exit;
}
if ($get === 'keys') {
$computerID = validUUID($_GET['computer']);
serveKeys($computerID);
exit;
}
if ($get === 'blob' || $get === 'tree' || $get === 'master') {
$computerID = validUUID($_GET['computer']);
$bucketID = validUUID($_GET['bucket']);
$hashes = isset($_GET['hashes']) ? $_GET['hashes'] : "";
if ($get === 'master') {
$hashes = masterHash($computerID, $bucketID);
}
$hashes = array_map('validHash', explode(',', $hashes));
$isTree = $get !== 'blob';
$found = serveObjects($computerID, $bucketID, $hashes, $isTree);
exit;
}
throw new Exception("Bad request", 400);