This repository has been archived by the owner on Aug 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-show.php
74 lines (58 loc) · 1.8 KB
/
api-show.php
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
<?php
require_once "includes/config.php";
require_once "includes/linkpwd.class.php";
// output as JSON
header('Content-type: application/json');
// API enabled
if( API_ENABLED == false ){
header($_SERVER["SERVER_PROTOCOL"].' 423 Locked');
$returnValues = array(
"status" => 423,
"errormsg" => "API is disabled"
);
exit( json_encode($returnValues) );
}
// API key
if( $_POST['apiuser'] == "username" || $_POST['apipass'] == "password" ||
API_KEYS[$_POST['apiuser']] != $_POST['apipass'] ){
header($_SERVER["SERVER_PROTOCOL"].' 401 Unauthorized');
$returnValues = array(
"status" => 401,
"errormsg" => "invalid API username or password"
);
exit( json_encode($returnValues) );
}
// validate the link
$isValidLink = validateLink($_GET['id'], $_GET['key'], $_GET['iv']);
if( $isValidLink[0] == false ){
header($_SERVER["SERVER_PROTOCOL"].' 404 Not Found');
$returnValues = array(
"status" => 404,
"errormsg" => $isValidLink[1]
);
exit( json_encode($returnValues) );
}
// get data from database
$dbD = getLinkData($_GET['id']);
// check password if a password is set; captcha not available for API
if( !empty($dbD['passwordHash']) ){
// validate password
$passwordSubmittedHash = hash("sha256", hex2bin($_GET['key']).hex2bin($_GET['iv']).$_GET['password']);
if( $passwordSubmittedHash != $dbD['passwordHash'] ){
header($_SERVER["SERVER_PROTOCOL"].' 403 Forbidden');
$returnValues = array(
"status" => 403,
"errormsg" => "wrong password"
);
exit( json_encode($returnValues) );
}
}
// decryption
$dataLinks = decryptLinks($dbD['ciphertext'], $_GET['key'], $_GET['iv']);
header($_SERVER["SERVER_PROTOCOL"].' 200 OK');
$returnValues = array(
"status" => 200,
"errormsg" => "ok",
"links" => $dataLinks
);
exit( json_encode($returnValues) );