mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-19 15:40:51 +08:00
77 lines
2.1 KiB
PHP
77 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\V2\Server;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Services\ServerService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class ServerController extends Controller
|
|
{
|
|
/**
|
|
* server handshake api
|
|
*/
|
|
public function handshake(Request $request): JsonResponse
|
|
{
|
|
$websocket = ['enabled' => false];
|
|
|
|
if ((bool) admin_setting('server_ws_enable', 1)) {
|
|
$customUrl = trim((string) admin_setting('server_ws_url', ''));
|
|
|
|
if ($customUrl !== '') {
|
|
$wsUrl = rtrim($customUrl, '/');
|
|
} else {
|
|
$wsScheme = $request->isSecure() ? 'wss' : 'ws';
|
|
$wsUrl = "{$wsScheme}://{$request->getHost()}:8076";
|
|
}
|
|
|
|
$websocket = [
|
|
'enabled' => true,
|
|
'ws_url' => $wsUrl,
|
|
];
|
|
}
|
|
|
|
return response()->json([
|
|
'websocket' => $websocket
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* node report api - merge traffic + alive + status + metrics
|
|
*/
|
|
public function report(Request $request): JsonResponse
|
|
{
|
|
$node = $request->attributes->get('node_info');
|
|
|
|
ServerService::touchNode($node);
|
|
|
|
$traffic = $request->input('traffic');
|
|
if (is_array($traffic) && !empty($traffic)) {
|
|
ServerService::processTraffic($node, $traffic);
|
|
}
|
|
|
|
$alive = $request->input('alive');
|
|
if (is_array($alive) && !empty($alive)) {
|
|
ServerService::processAlive($node->id, $alive);
|
|
}
|
|
|
|
$online = $request->input('online');
|
|
if (is_array($online) && !empty($online)) {
|
|
ServerService::processOnline($node, $online);
|
|
}
|
|
|
|
$status = $request->input('status');
|
|
if (is_array($status) && !empty($status)) {
|
|
ServerService::processStatus($node, $status);
|
|
}
|
|
|
|
$metrics = $request->input('metrics');
|
|
if (is_array($metrics) && !empty($metrics)) {
|
|
ServerService::updateMetrics($node, $metrics);
|
|
}
|
|
|
|
return response()->json(['data' => true]);
|
|
}
|
|
}
|