v2board/app/Http/Controllers/Admin/Server/VmessController.php

93 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2020-06-11 20:47:02 +08:00
<?php
namespace App\Http\Controllers\Admin\Server;
2023-02-15 14:53:13 +08:00
use App\Http\Requests\Admin\ServerVmessSave;
use App\Http\Requests\Admin\ServerVmessUpdate;
2020-06-11 20:47:02 +08:00
use App\Services\ServerService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
2023-02-15 14:53:13 +08:00
use App\Models\ServerVmess;
2020-06-11 20:47:02 +08:00
2023-02-15 14:53:13 +08:00
class VmessController extends Controller
2020-06-11 20:47:02 +08:00
{
2023-02-15 14:53:13 +08:00
public function save(ServerVmessSave $request)
2020-06-11 20:47:02 +08:00
{
2020-07-15 15:57:12 +08:00
$params = $request->validated();
2020-06-11 20:47:02 +08:00
if ($request->input('id')) {
2023-02-15 14:53:13 +08:00
$server = ServerVmess::find($request->input('id'));
2020-06-11 20:47:02 +08:00
if (!$server) {
abort(500, '服务器不存在');
}
try {
$server->update($params);
} catch (\Exception $e) {
abort(500, '保存失败');
}
return response([
'data' => true
]);
}
2023-02-15 14:53:13 +08:00
if (!ServerVmess::create($params)) {
2020-06-11 20:47:02 +08:00
abort(500, '创建失败');
}
return response([
'data' => true
]);
}
public function drop(Request $request)
{
if ($request->input('id')) {
2023-02-15 14:53:13 +08:00
$server = ServerVmess::find($request->input('id'));
2020-06-11 20:47:02 +08:00
if (!$server) {
abort(500, '节点ID不存在');
}
}
return response([
'data' => $server->delete()
]);
}
2023-02-15 14:53:13 +08:00
public function update(ServerVmessUpdate $request)
2020-06-11 20:47:02 +08:00
{
$params = $request->only([
'show',
]);
2023-02-15 14:53:13 +08:00
$server = ServerVmess::find($request->input('id'));
2020-06-11 20:47:02 +08:00
if (!$server) {
abort(500, '该服务器不存在');
}
try {
$server->update($params);
} catch (\Exception $e) {
abort(500, '保存失败');
}
return response([
'data' => true
]);
}
public function copy(Request $request)
{
2023-02-15 14:53:13 +08:00
$server = ServerVmess::find($request->input('id'));
2020-06-18 17:39:29 +08:00
$server->show = 0;
2020-06-11 20:47:02 +08:00
if (!$server) {
abort(500, '服务器不存在');
}
2023-02-15 14:53:13 +08:00
if (!ServerVmess::create($server->toArray())) {
2020-06-11 20:47:02 +08:00
abort(500, '复制失败');
}
return response([
'data' => true
]);
}
}