-
Notifications
You must be signed in to change notification settings - Fork 66
/
marzneshin.php
242 lines (226 loc) · 8.98 KB
/
marzneshin.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
<?php
#-----------------------------#
function token_panelm($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/admins/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 getuserm($username,$location)
{
$marzban_list_get = select("marzban_panel", "*", "name_panel", $location,"select");
$Check_token = token_panelm($marzban_list_get['url_panel'], $marzban_list_get['username_panel'], $marzban_list_get['password_panel']);
$usernameac = $username;
$url = $marzban_list_get['url_panel'].'/api/users/' . $usernameac;
if(!isset($Check_token['access_token']))return;
$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 ResetUserDataUsagem($username,$location)
{
$marzban_list_get = select("marzban_panel", "*", "name_panel", $location,"select");
$Check_token = token_panelm($marzban_list_get['url_panel'], $marzban_list_get['username_panel'], $marzban_list_get['password_panel']);
$usernameac = $username;
$url = $marzban_list_get['url_panel'].'/api/users/' . $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 revoke_subm($username,$location)
{
$marzban_list_get = select("marzban_panel", "*", "name_panel", $location,"select");
$Check_token = token_panelm($marzban_list_get['url_panel'], $marzban_list_get['username_panel'], $marzban_list_get['password_panel']);
$usernameac = $username;
$url = $marzban_list_get['url_panel'].'/api/users/' . $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;
}
#-----------------------------#
function adduserm($location,$data_limit,$username_ac,$timestamp)
{
global $pdo;
$marzban_list_get = select("marzban_panel", "*", "name_panel", $location,"select");
$Check_token = token_panelm($marzban_list_get['url_panel'], $marzban_list_get['username_panel'], $marzban_list_get['password_panel']);
$url = $marzban_list_get['url_panel']."/api/users";
$header_value = 'Bearer ';
$data = array(
'service_ids' => json_decode($marzban_list_get['proxies'],true),
"data_limit" => $data_limit,
"username" => $username_ac,
);
if($marzban_list_get['onholdstatus'] == "offonhold"){
if ($timestamp == 0) {
$data["expire_date"] = null;
$data["expire_strategy"] = "never";
} else {
$date = date('c',$timestamp);
$data["expire_date"] = $date;
$data["expire_strategy"] = "fixed_date";
}
}else{
if($timestamp == 0 ){
$data["expire_date"] = null;
$data["expire_strategy"] = "never";
}else{
$data["expire_date"] = null;
$data["expire_strategy"] = "start_on_first_use";
$date = new DateTime();
$date->setTimestamp($timestamp - time());
$formattedDate = $date->format('Y-m-d\TH:i:s');
$data["activation_deadline"] = $formattedDate;
$data["usage_duration"] = $timestamp - time();
}
}
$payload = json_encode($data);
file_put_contents('ss',$payload);
$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_Statsm($location){
$marzban_list_get = select("marzban_panel", "*", "name_panel", $location,"select");
$Check_token = token_panelm($marzban_list_get['url_panel'], $marzban_list_get['username_panel'], $marzban_list_get['password_panel']);
$url = $marzban_list_get['url_panel'].'/api/system/stats/users';
$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 removeuserm($location,$username)
{
$marzban_list_get = select("marzban_panel", "*", "name_panel", $location,"select");
$Check_token = token_panelm($marzban_list_get['url_panel'], $marzban_list_get['username_panel'], $marzban_list_get['password_panel']);
$url = $marzban_list_get['url_panel'].'/api/users/'.$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 Modifyuserm($location,$username,array $data)
{
$marzban_list_get = select("marzban_panel", "*", "name_panel", $location,"select");
$Check_token = token_panelm($marzban_list_get['url_panel'], $marzban_list_get['username_panel'], $marzban_list_get['password_panel']);
$url = $marzban_list_get['url_panel'].'/api/users/'.$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;
}