-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-v2.php
140 lines (140 loc) · 4.09 KB
/
api-v2.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
// API v2 is not yet finished, you have to use the old API version.
header_remove('Server');
header("Content-type: application/json");
require('assets/init.php');
require('api/v2/init.php');
$wo['loggedin'] = false;
$response_data = array();
$error_code = 0;
$error_message = '';
$type = (!empty($_GET['type'])) ? Wo_Secure($_GET['type'], 0) : false;
$server_key = (!empty($_POST['server_key'])) ? Wo_Secure($_POST['server_key'], 0) : false;
if (empty($type)) {
$response_data = array(
'api_status' => '404',
'errors' => array(
'error_id' => '1',
'error_text' => 'Error: 404 API Type not specified'
)
);
echo json_encode($response_data, JSON_PRETTY_PRINT);
exit();
}
if (empty($server_key)) {
$response_data = array(
'api_status' => '404',
'errors' => array(
'error_id' => '1',
'error_text' => 'Error: 404 POST (server_key) not specified, Admin Panel > API Settings > Manage API Server Key'
)
);
echo json_encode($response_data, JSON_PRETTY_PRINT);
exit();
}
if ($server_key != $wo['config']['widnows_app_api_key']) {
$response_data = array(
'api_status' => '404',
'errors' => array(
'error_id' => '1',
'error_text' => 'Error: invalid server key'
)
);
echo json_encode($response_data, JSON_PRETTY_PRINT);
exit();
}
$api = "api/v2/endpoints/$type.php";
$pages_without_access_token = array(
'get-site-settings',
'active_account_sms',
'auth',
'regsiter',
'send-reset-password-email',
'create-account',
'social-login',
'is-active',
'two-factor',
'reset_password',
'validation_user'
);
$pages_without_loggedin = array(
'get-site-settings',
'active_account_sms',
'auth',
'regsiter',
'send-reset-password-email',
'create-account',
'social-login',
'is-active',
'two-factor',
'reset_password',
'validation_user'
);
if (!file_exists($api)) {
$response_data = array(
'api_status' => '404',
'errors' => array(
'error_id' => '1',
'error_text' => 'Error: 404 API Type Not Found'
)
);
echo json_encode($response_data, JSON_PRETTY_PRINT);
exit();
}
if (!in_array($type, $pages_without_access_token)) {
if (empty($_GET['access_token'])) {
$error_code = 1;
$error_message = 'Error: access_token is missing';
}
}
if (!empty($_GET['access_token'])) {
$get_user_id_from_access_token = Wo_ValidateAccessToken($_GET['access_token']);
if (is_numeric($get_user_id_from_access_token) && $get_user_id_from_access_token > 0) {
$wo['user'] = Wo_UserData($get_user_id_from_access_token);
if (!empty($wo['user'])) {
$wo['loggedin'] = true;
if ($wo['user']['user_id'] < 0 || empty($wo['user']['user_id']) || !is_numeric($wo['user']['user_id']) || Wo_UserActive($wo['user']['username']) === false) {
$wo['loggedin'] = false;
}
}
}
}
if (!in_array($type, $pages_without_loggedin)) {
if ($wo['loggedin'] == false && !empty($_GET['access_token'])) {
$error_code = 2;
$error_message = 'Invalid or expired access_token';
} else if ($wo['loggedin'] == false) {
$error_code = 2;
$error_message = 'Not authorized';
}
}
if (!empty($error_code)) {
$response_data = array(
'api_status' => '404',
'errors' => array(
'error_id' => $error_code,
'error_text' => $error_message
)
);
echo json_encode($response_data, JSON_PRETTY_PRINT);
exit();
}
if ($wo['loggedin'] == true) {
$wo['lang'] = Wo_LangsFromDB($wo['user']['language']);
}
require_once "api/v2/functions.php";
require_once "$api";
if (!empty($error_code)) {
$response_data = array(
'api_status' => '400',
'errors' => array(
'error_id' => $error_code,
'error_text' => $error_message
)
);
}
echo json_encode($response_data, JSON_PRETTY_PRINT);
exit();
mysqli_close($sqlConnect);
unset($wo);
?>