Xboard/app/Http/Controllers/V1/Admin/Server/TrojanController.php

85 lines
2.4 KiB
PHP
Raw Normal View History

2023-11-17 01:44:01 -05:00
<?php
namespace App\Http\Controllers\V1\Admin\Server;
2023-12-04 07:40:49 -05:00
use App\Exceptions\ApiException;
2023-11-17 01:44:01 -05:00
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\ServerTrojanSave;
use App\Http\Requests\Admin\ServerTrojanUpdate;
use App\Models\ServerTrojan;
use App\Services\ServerService;
use Illuminate\Http\Request;
class TrojanController extends Controller
{
public function save(ServerTrojanSave $request)
{
$params = $request->validated();
if ($request->input('id')) {
$server = ServerTrojan::find($request->input('id'));
if (!$server) {
return $this->fail([400202,'服务器不存在']);
2023-11-17 01:44:01 -05:00
}
try {
$server->update($params);
} catch (\Exception $e) {
\Log::error($e);
return $this->fail([500, '保存失败']);
2023-11-17 01:44:01 -05:00
}
return $this->success(true);
2023-11-17 01:44:01 -05:00
}
ServerTrojan::create($params);
return $this->success(true);
2023-11-17 01:44:01 -05:00
}
public function drop(Request $request)
{
if ($request->input('id')) {
$server = ServerTrojan::find($request->input('id'));
if (!$server) {
return $this->fail([400202,'节点ID不存在']);
2023-11-17 01:44:01 -05:00
}
}
return $this->success($server->delete());
2023-11-17 01:44:01 -05:00
}
public function update(ServerTrojanUpdate $request)
{
$params = $request->only([
'show',
]);
$server = ServerTrojan::find($request->input('id'));
if (!$server) {
return $this->fail([400202,'该服务器不存在']);
2023-11-17 01:44:01 -05:00
}
try {
$server->update($params);
} catch (\Exception $e) {
\Log::error($e);
return $this->fail([500,'保存失败']);
2023-11-17 01:44:01 -05:00
}
return $this->success(true);
2023-11-17 01:44:01 -05:00
}
public function copy(Request $request)
{
$server = ServerTrojan::find($request->input('id'));
$server->show = 0;
if (!$server) {
return $this->fail([400202,'服务器不存在']);
2023-11-17 01:44:01 -05:00
}
ServerTrojan::create($server->toArray());
return $this->success(true);
2023-11-17 01:44:01 -05:00
}
public function viewConfig(Request $request)
{
$serverService = new ServerService();
$config = $serverService->getTrojanConfig($request->input('node_id'), 23333);
return $this->success($config);
2023-11-17 01:44:01 -05:00
}
}