mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 17:49:11 +08:00
93 lines
2.2 KiB
PHP
93 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\Server;
|
|
|
|
use App\Http\Requests\Admin\ServerVmessSave;
|
|
use App\Http\Requests\Admin\ServerVmessUpdate;
|
|
use App\Services\ServerService;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\ServerVmess;
|
|
|
|
class VmessController extends Controller
|
|
{
|
|
public function save(ServerVmessSave $request)
|
|
{
|
|
$params = $request->validated();
|
|
|
|
if ($request->input('id')) {
|
|
$server = ServerVmess::find($request->input('id'));
|
|
if (!$server) {
|
|
abort(500, '服务器不存在');
|
|
}
|
|
try {
|
|
$server->update($params);
|
|
} catch (\Exception $e) {
|
|
abort(500, '保存失败');
|
|
}
|
|
return response([
|
|
'data' => true
|
|
]);
|
|
}
|
|
|
|
if (!ServerVmess::create($params)) {
|
|
abort(500, '创建失败');
|
|
}
|
|
|
|
return response([
|
|
'data' => true
|
|
]);
|
|
}
|
|
|
|
public function drop(Request $request)
|
|
{
|
|
if ($request->input('id')) {
|
|
$server = ServerVmess::find($request->input('id'));
|
|
if (!$server) {
|
|
abort(500, '节点ID不存在');
|
|
}
|
|
}
|
|
return response([
|
|
'data' => $server->delete()
|
|
]);
|
|
}
|
|
|
|
public function update(ServerVmessUpdate $request)
|
|
{
|
|
$params = $request->only([
|
|
'show',
|
|
]);
|
|
|
|
$server = ServerVmess::find($request->input('id'));
|
|
|
|
if (!$server) {
|
|
abort(500, '该服务器不存在');
|
|
}
|
|
try {
|
|
$server->update($params);
|
|
} catch (\Exception $e) {
|
|
abort(500, '保存失败');
|
|
}
|
|
|
|
return response([
|
|
'data' => true
|
|
]);
|
|
}
|
|
|
|
public function copy(Request $request)
|
|
{
|
|
$server = ServerVmess::find($request->input('id'));
|
|
$server->show = 0;
|
|
if (!$server) {
|
|
abort(500, '服务器不存在');
|
|
}
|
|
if (!ServerVmess::create($server->toArray())) {
|
|
abort(500, '复制失败');
|
|
}
|
|
|
|
return response([
|
|
'data' => true
|
|
]);
|
|
}
|
|
}
|