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) {
|
2023-12-06 15:01:32 -05:00
|
|
|
return $this->fail([400202,'服务器不存在']);
|
2023-11-17 01:44:01 -05:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
$server->update($params);
|
|
|
|
} catch (\Exception $e) {
|
2023-12-06 15:01:32 -05:00
|
|
|
\Log::error($e);
|
|
|
|
return $this->fail([500, '保存失败']);
|
2023-11-17 01:44:01 -05:00
|
|
|
}
|
2023-12-06 15:01:32 -05:00
|
|
|
return $this->success(true);
|
2023-11-17 01:44:01 -05:00
|
|
|
}
|
|
|
|
|
2023-12-06 15:01:32 -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) {
|
2023-12-06 15:01:32 -05:00
|
|
|
return $this->fail([400202,'节点ID不存在']);
|
2023-11-17 01:44:01 -05:00
|
|
|
}
|
|
|
|
}
|
2023-12-06 15:01:32 -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) {
|
2023-12-06 15:01:32 -05:00
|
|
|
return $this->fail([400202,'该服务器不存在']);
|
2023-11-17 01:44:01 -05:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
$server->update($params);
|
|
|
|
} catch (\Exception $e) {
|
2023-12-06 15:01:32 -05:00
|
|
|
\Log::error($e);
|
|
|
|
return $this->fail([500,'保存失败']);
|
2023-11-17 01:44:01 -05:00
|
|
|
}
|
|
|
|
|
2023-12-06 15:01:32 -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) {
|
2023-12-06 15:01:32 -05:00
|
|
|
return $this->fail([400202,'服务器不存在']);
|
2023-11-17 01:44:01 -05:00
|
|
|
}
|
2023-12-06 15:01:32 -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);
|
2023-12-06 15:01:32 -05:00
|
|
|
return $this->success($config);
|
2023-11-17 01:44:01 -05:00
|
|
|
}
|
|
|
|
}
|