-
Notifications
You must be signed in to change notification settings - Fork 66
/
apipanel.php
246 lines (228 loc) · 8.92 KB
/
apipanel.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<?php
require_once 'functions.php';
#-----------------------------#
function token_panel($url_panel,$username_panel,$password_panel){
$panel = select("marzban_panel","*","url_panel",$url_panel,"select");
if($panel['datelogin'] != null){
$date = json_decode($panel['datelogin'],true);
if(isset($date['time'])){
$timecurrent = time();
$start_date = time() - strtotime($date['time']);
if($start_date <= 600){
return $date;
}
}
}
$url_get_token = $url_panel.'/api/admin/token';
$data_token = array(
'username' => $username_panel,
'password' => $password_panel
);
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_TIMEOUT_MS => 6000,
CURLOPT_POSTFIELDS => http_build_query($data_token),
CURLOPT_HTTPHEADER => array(
'Content-Type: application/x-www-form-urlencoded',
'accept: application/json'
)
);
$curl_token = curl_init($url_get_token);
curl_setopt_array($curl_token, $options);
$token = curl_exec($curl_token);
if (curl_error($curl_token)) {
$token = [];
$token['errror'] = curl_error($curl_token);
return $token;
}
curl_close($curl_token);
$body = json_decode( $token, true);
if(isset($body['access_token'])){
$time = date('Y/m/d H:i:s');
$data = json_encode(array(
'time' => $time,
'access_token' => $body['access_token']
));
update("marzban_panel","datelogin",$data,'name_panel',$panel['name_panel']);
}
return $body;
}
#-----------------------------#
function getuser($usernameac,$location)
{
$marzban_list_get = select("marzban_panel", "*", "name_panel", $location,"select");
$Check_token = token_panel($marzban_list_get['url_panel'], $marzban_list_get['username_panel'], $marzban_list_get['password_panel']);
$url = $marzban_list_get['url_panel'].'/api/user/' . $usernameac;
$header_value = 'Bearer ';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Authorization: ' . $header_value . $Check_token['access_token']
));
$output = curl_exec($ch);
curl_close($ch);
$data_useer = json_decode($output, true);
return $data_useer;
}
#-----------------------------#
function ResetUserDataUsage($usernameac,$location)
{
$marzban_list_get = select("marzban_panel", "*", "name_panel", $location,"select");
$Check_token = token_panel($marzban_list_get['url_panel'], $marzban_list_get['username_panel'], $marzban_list_get['password_panel']);
$url = $marzban_list_get['url_panel'].'/api/user/' . $usernameac.'/reset';
$header_value = 'Bearer ';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST , true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Authorization: ' . $header_value . $Check_token['access_token']
));
$output = curl_exec($ch);
curl_close($ch);
$data_useer = json_decode($output, true);
return $data_useer;
}
#-----------------------------#
function adduser($username,$expire,$data_limit,$location)
{
$marzban_list_get = select("marzban_panel", "*", "name_panel", $location,"select");
$Check_token = token_panel($marzban_list_get['url_panel'], $marzban_list_get['username_panel'], $marzban_list_get['password_panel']);
$url = $marzban_list_get['url_panel']."/api/user";
$nameprotocol = array();
if(isset($marzban_list_get['vless']) && $marzban_list_get['vless'] == "onvless"){
$nameprotocol['vless'] = array();
}
if(isset($marzban_list_get['vmess']) && $marzban_list_get['vmess'] == "onvmess"){
$nameprotocol['vmess'] = array();
}
if(isset($marzban_list_get['trojan']) && $marzban_list_get['trojan'] == "ontrojan"){
$nameprotocol['trojan'] = array();
}
if(isset($marzban_list_get['shadowsocks']) && $marzban_list_get['shadowsocks'] == "onshadowsocks"){
$nameprotocol['shadowsocks'] = array();
}
if(isset($nameprotocol['vless']) && $marzban_list_get['flow'] == "flowon"){
$nameprotocol['vless']['flow'] = 'xtls-rprx-vision';
}
$header_value = 'Bearer ';
$data = array(
"proxies" => $nameprotocol,
"data_limit" => $data_limit,
"username" => $username
);
if($expire == "0"){
$data['expire'] = 0;
}else {
if($marzban_list_get['onholdstatus'] == "ononhold"){
$data["expire"] = 0;
$data["status"] = "on_hold";
$data["on_hold_expire_duration"] = $expire - time();
}else{
$data['expire'] = $expire;
}
}
$payload = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Authorization: ' . $header_value . $Check_token['access_token'],
'Content-Type: application/json'
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
//----------------------------------
function Get_System_Stats($location){
$marzban_list_get = select("marzban_panel", "*", "name_panel", $location,"select");
$Check_token = token_panel($marzban_list_get['url_panel'], $marzban_list_get['username_panel'], $marzban_list_get['password_panel']);
$url = $marzban_list_get['url_panel'].'/api/system';
$header_value = 'Bearer ';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Authorization: ' . $header_value . $Check_token['access_token'],
));
$output = curl_exec($ch);
curl_close($ch);
$Get_System_Stats = json_decode($output, true);
return $Get_System_Stats;
}
//----------------------------------
function removeuser($location,$username)
{
$marzban_list_get = select("marzban_panel", "*", "name_panel", $location,"select");
$Check_token = token_panel($marzban_list_get['url_panel'], $marzban_list_get['username_panel'], $marzban_list_get['password_panel']);
$url = $marzban_list_get['url_panel'].'/api/user/'.$username;
$header_value = 'Bearer ';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Authorization: ' . $header_value . $Check_token['access_token']
));
$output = curl_exec($ch);
curl_close($ch);
$data_useer = json_decode($output, true);
return $data_useer;
}
//----------------------------------
function Modifyuser($location,$username,array $data)
{
$marzban_list_get = select("marzban_panel", "*", "name_panel", $location,"select");
$Check_token = token_panel($marzban_list_get['url_panel'], $marzban_list_get['username_panel'], $marzban_list_get['password_panel']);
$url = $marzban_list_get['url_panel'].'/api/user/'.$username;
$payload = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$headers = array();
$headers[] = 'Accept: application/json';
$headers[] = 'Authorization: Bearer '.$Check_token['access_token'];
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
curl_close($ch);
$data_useer = json_decode($result, true);
return $data_useer;
}
#-----------------------------------------------#
function revoke_sub($username,$location)
{
global $connect;
$marzban_list_get = select("marzban_panel", "*", "name_panel", $location,"select");
$Check_token = token_panel($marzban_list_get['url_panel'], $marzban_list_get['username_panel'], $marzban_list_get['password_panel']);
$usernameac = $username;
$url = $marzban_list_get['url_panel'].'/api/user/' . $usernameac.'/revoke_sub';
$header_value = 'Bearer ';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST , true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Authorization: ' . $header_value . $Check_token['access_token']
));
$output = curl_exec($ch);
curl_close($ch);
$data_useer = json_decode($output, true);
return $data_useer;
}