-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathserver.php
executable file
·97 lines (87 loc) · 3.03 KB
/
server.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
<?php
// require(dirname(dirname(dirname(dirname(__FILE__)))).'/init.php');
require('lib/DB.php');
require('lib/WHMCS.php');
require('config.php');
// use WHMCS\Database\Capsule;
function getUsers(){
global $Db;
$users = $Db->get('user');
$data = [];
foreach ($users as $user){
$user['id'] = $user['pid'];
$user['v2ray_user'] = [
"uuid" => $user['v2ray_uuid'],
"email" => sprintf("%s@v2ray.user", $user['v2ray_uuid']),
"alter_id" => $user['v2ray_alter_id'],
"level" => $user['v2ray_level'],
];
array_push($data, $user);
}
$res = [
'msg' => 'ok',
'data' => $data,
];
echo json_encode($res);
}
function addTraffic(){
global $Db;
$rate = $_GET['rate'];
$input = file_get_contents("php://input");
//file_put_contents('111.txt', json_encode($input));
$datas = json_decode($input, true);
foreach ($datas as $data) {
$user = $Db->where('pid', $data['user_id'])->getOne('user');
$fetchData = [
't' => time(),
'u' => $user['u'] + ($data['u'] * $rate),
'd' => $user['d'] + ($data['d'] * $rate)
];
if($user['u'] + $user['d'] > $user['transfer_enable']) {
$fetchData['enable'] = 0;
}
$result = $Db->where('pid', $data['user_id'])->update('user', $fetchData);
}
$res = [
"ret" => 1,
"msg" => "ok",
];
echo json_encode($res);
}
function getConfig(){
$jsonData = file_get_contents('./server.json');
$jsonData = json_decode($jsonData);
$jsonData->inbound->port = (int)$_GET['port'];
$jsonData->inboundDetour[0]->port = (int)$_GET['localport'];
if ($_GET['tls']) {
$jsonData->inbound->streamSettings->security = "tls";
$tls = (object) array("certificateFile" => "/home/v2ray.crt", "keyFile" => "/home/v2ray.key");
$jsonData->inbound->streamSettings->tlsSettings->certificates[0] = $tls;
}
echo json_encode($jsonData, JSON_UNESCAPED_UNICODE);
}
$databaseName = !empty($_GET['databaseName'])?$_GET['databaseName']:null;
$token = !empty($_GET['token'])?$_GET['token']:null;
$method = !empty($_GET['method'])?$_GET['method']:null;
if(isset($databaseName) && isset($token)){
$WHMCSdb = new MysqliDb($config['db_hostname'], $config['db_username'], $config['db_password'], $config['db_database'], $config['db_port']);
$WHMCS = new WHMCS($config['cc_encryption_hash']);
$server = $WHMCSdb->where('name', $databaseName)->getOne('tblservers');
if($token !== $server['accesshash']) {
die('TOKEN ERROR!!');
}
$dbhost = $server['ipaddress'] ? $server['ipaddress'] : 'localhost';
$dbuser = $server['username'];
$dbpass = $WHMCS->decrypt($server['password']);
$Db = new MysqliDb($dbhost, $dbuser, $dbpass, $databaseName, 3306);
switch($_GET['method']) {
case 'getUsers': return getUsers();
break;
case 'addTraffic': return addTraffic();
break;
case 'getConfig': return getConfig();
break;
}
}else{
die('Invaild');
}