2019-10-29 15:33:36 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Server;
|
|
|
|
|
2020-02-28 15:16:23 +08:00
|
|
|
use App\Services\ServerService;
|
2020-04-25 19:44:47 +08:00
|
|
|
use App\Services\UserService;
|
2020-06-05 13:25:32 +08:00
|
|
|
use App\Utils\CacheKey;
|
2019-10-29 15:33:36 +08:00
|
|
|
use Illuminate\Http\Request;
|
2020-01-31 00:03:18 +08:00
|
|
|
use App\Http\Controllers\Controller;
|
2019-10-29 15:33:36 +08:00
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\Server;
|
|
|
|
use App\Models\ServerLog;
|
2020-04-25 19:44:47 +08:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2019-10-29 15:33:36 +08:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2020-01-12 01:27:36 +08:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2019-10-29 15:33:36 +08:00
|
|
|
|
2020-06-18 02:25:05 +08:00
|
|
|
/*
|
|
|
|
* V2ray Aurora
|
|
|
|
* Github: https://github.com/tokumeikoi/aurora
|
|
|
|
*/
|
2019-10-29 15:33:36 +08:00
|
|
|
class DeepbworkController extends Controller
|
|
|
|
{
|
2020-01-31 00:03:18 +08:00
|
|
|
public function __construct(Request $request)
|
|
|
|
{
|
|
|
|
$token = $request->input('token');
|
|
|
|
if (empty($token)) {
|
|
|
|
abort(500, 'token is null');
|
|
|
|
}
|
|
|
|
if ($token !== config('v2board.server_token')) {
|
|
|
|
abort(500, 'token is error');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-29 15:33:36 +08:00
|
|
|
// 后端获取用户
|
2020-01-11 13:36:52 +08:00
|
|
|
public function user(Request $request)
|
|
|
|
{
|
2019-10-29 15:33:36 +08:00
|
|
|
$nodeId = $request->input('node_id');
|
|
|
|
$server = Server::find($nodeId);
|
2019-11-25 00:22:52 +08:00
|
|
|
if (!$server) {
|
|
|
|
abort(500, 'fail');
|
2019-11-25 00:20:26 +08:00
|
|
|
}
|
2020-06-05 13:25:32 +08:00
|
|
|
Cache::put(CacheKey::get('SERVER_LAST_CHECK_AT', $server->id), time(), 3600);
|
2020-02-28 15:16:23 +08:00
|
|
|
$serverService = new ServerService();
|
|
|
|
$users = $serverService->getAvailableUsers(json_decode($server->group_id));
|
2019-10-29 15:33:36 +08:00
|
|
|
$result = [];
|
|
|
|
foreach ($users as $user) {
|
|
|
|
$user->v2ray_user = [
|
2020-06-08 01:08:07 +08:00
|
|
|
"uuid" => $user->uuid,
|
|
|
|
"email" => sprintf("%s@v2board.user", $user->uuid),
|
2019-10-29 15:33:36 +08:00
|
|
|
"alter_id" => $user->v2ray_alter_id,
|
|
|
|
"level" => $user->v2ray_level,
|
|
|
|
];
|
2020-06-08 01:08:07 +08:00
|
|
|
unset($user['uuid']);
|
2019-10-29 15:33:36 +08:00
|
|
|
unset($user['v2ray_alter_id']);
|
|
|
|
unset($user['v2ray_level']);
|
|
|
|
array_push($result, $user);
|
|
|
|
}
|
|
|
|
return response([
|
|
|
|
'msg' => 'ok',
|
|
|
|
'data' => $result,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 后端提交数据
|
2020-01-11 13:36:52 +08:00
|
|
|
public function submit(Request $request)
|
|
|
|
{
|
2020-03-07 11:37:39 +08:00
|
|
|
// Log::info('serverSubmitData:' . $request->input('node_id') . ':' . file_get_contents('php://input'));
|
2019-10-29 15:33:36 +08:00
|
|
|
$server = Server::find($request->input('node_id'));
|
|
|
|
if (!$server) {
|
2020-01-11 13:36:52 +08:00
|
|
|
return response([
|
2020-04-25 19:44:47 +08:00
|
|
|
'ret' => 0,
|
|
|
|
'msg' => 'server is not found'
|
2020-01-11 13:36:52 +08:00
|
|
|
]);
|
2019-10-29 15:33:36 +08:00
|
|
|
}
|
|
|
|
$data = file_get_contents('php://input');
|
|
|
|
$data = json_decode($data, true);
|
2020-06-05 13:25:32 +08:00
|
|
|
Cache::put(CacheKey::get('SERVER_ONLINE_USER', $server->id), count($data), 3600);
|
2020-04-25 19:44:47 +08:00
|
|
|
$serverService = new ServerService();
|
|
|
|
$userService = new UserService();
|
2019-10-29 15:33:36 +08:00
|
|
|
foreach ($data as $item) {
|
2020-01-11 13:36:52 +08:00
|
|
|
$u = $item['u'] * $server->rate;
|
|
|
|
$d = $item['d'] * $server->rate;
|
2020-04-25 19:44:47 +08:00
|
|
|
if (!$userService->trafficFetch($u, $d, $item['user_id'])) {
|
|
|
|
return response([
|
|
|
|
'ret' => 0,
|
|
|
|
'msg' => 'user fetch fail'
|
|
|
|
]);
|
|
|
|
}
|
2020-01-11 13:36:52 +08:00
|
|
|
|
2020-04-25 19:44:47 +08:00
|
|
|
$serverService->log(
|
|
|
|
$item['user_id'],
|
|
|
|
$request->input('node_id'),
|
2020-04-26 19:19:31 +08:00
|
|
|
$item['u'],
|
|
|
|
$item['d'],
|
2020-06-11 20:47:02 +08:00
|
|
|
$server->rate,
|
|
|
|
'vmess'
|
2020-04-25 19:44:47 +08:00
|
|
|
);
|
2019-10-29 15:33:36 +08:00
|
|
|
}
|
2020-01-11 13:36:52 +08:00
|
|
|
|
|
|
|
return response([
|
|
|
|
'ret' => 1,
|
|
|
|
'msg' => 'ok'
|
|
|
|
]);
|
2019-10-29 15:33:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 后端获取配置
|
2020-01-11 13:36:52 +08:00
|
|
|
public function config(Request $request)
|
|
|
|
{
|
2019-10-29 15:33:36 +08:00
|
|
|
$nodeId = $request->input('node_id');
|
|
|
|
$localPort = $request->input('local_port');
|
2019-12-11 21:43:20 +08:00
|
|
|
if (empty($nodeId) || empty($localPort)) {
|
2020-02-05 18:46:10 +08:00
|
|
|
abort(500, '参数错误');
|
2019-12-11 21:43:20 +08:00
|
|
|
}
|
2020-03-10 13:11:31 +08:00
|
|
|
$serverService = new ServerService();
|
|
|
|
try {
|
2020-06-12 00:18:35 +08:00
|
|
|
$json = $serverService->getVmessConfig($nodeId, $localPort);
|
2020-03-10 13:11:31 +08:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
abort(500, $e->getMessage());
|
2019-10-29 15:33:36 +08:00
|
|
|
}
|
2020-01-11 13:36:52 +08:00
|
|
|
|
2019-12-10 09:53:34 +08:00
|
|
|
die(json_encode($json, JSON_UNESCAPED_UNICODE));
|
2019-10-29 15:33:36 +08:00
|
|
|
}
|
|
|
|
}
|