forked from mahdiMGF2/mirzabot
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhiddify.php
More file actions
90 lines (89 loc) · 3.16 KB
/
hiddify.php
File metadata and controls
90 lines (89 loc) · 3.16 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
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
<?php
require_once 'config.php';
require_once 'request.php';
#-----------------------------#
function getdatauser($username,$location)
{
$marzban_list_get = select("marzban_panel", "*", "name_panel", $location,"select");
$usernameac = $username;
$url = $marzban_list_get['url_panel'].'/api/v2/admin/user/';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch,CURLOPT_TIMEOUT_MS, 4000);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Basic ' . base64_encode("{$marzban_list_get['secret_code']}:")
));
$output = curl_exec($ch);
curl_close($ch);
$data_useer = json_decode($output, true);
if(isset($data_useer['message']))return $data_useer;
if(!isset($data_useer) || count($data_useer) == 0)return [];
foreach($data_useer as $data){
if(!isset($data['name']))continue;
if($data['name'] == $username){
return $data;
}
}
}
function serverstatus($location)
{
$marzban_list_get = select("marzban_panel", "*", "name_panel", $location,"select");
$url = $marzban_list_get['url_panel'].'/api/v2/admin/server_status/';
$headers = array(
'Authorization: Basic ' . base64_encode("{$marzban_list_get['secret_code']}:")
);
$req = new CurlRequest($url);
$req->setHeaders($headers);
$response = $req->get();
return $response;
}
// #-----------------------------#
function adduserhi($location,array $data)
{
$marzban_list_get = select("marzban_panel", "*", "name_panel", $location,"select");
$url = $marzban_list_get['url_panel'].'/api/v2/admin/user/';
$payload = json_encode($data,true);
$headers = array(
'Accept: application/json',
'Content-Type: application/json',
'Hiddify-API-Key: '.$marzban_list_get['secret_code']
);
$req = new CurlRequest($url);
$req->setHeaders($headers);
$response = $req->post($payload);
return $response;
}
// #-----------------------------#
function updateuserhi($username,$location,array $data)
{
$marzban_list_get = select("marzban_panel", "*", "name_panel", $location,"select");
$paneldata = getdatauser($username,$location);
$url = $marzban_list_get['url_panel'].'/api/v2/admin/user/'.$paneldata['uuid']."/";
$payload = json_encode($data,true);
$headers = array(
'Accept: application/json',
'Content-Type: application/json',
'Hiddify-API-Key: '.$marzban_list_get['secret_code']
);
$req = new CurlRequest($url);
$req->setHeaders($headers);
$response = $req->PATCH($payload);
return $response;
}
//----------------------------------
function removeuserhi($location,$uuid)
{
$marzban_list_get = select("marzban_panel", "*", "name_panel", $location,"select");
$url = $marzban_list_get['url_panel']."/api/v2/admin/user/$uuid/";
$headers = array(
'Accept: application/json',
'Content-Type: application/json',
'Hiddify-API-Key: '.$marzban_list_get['secret_code']
);
$req = new CurlRequest($url);
$req->setHeaders($headers);
$response = $req->delete();
return $response;
}