2020-06-11 20:47:02 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin\Server;
|
|
|
|
|
|
|
|
use App\Http\Requests\Admin\ServerTrojanSave;
|
|
|
|
use App\Http\Requests\Admin\ServerTrojanUpdate;
|
2020-07-02 21:41:14 +08:00
|
|
|
use App\Services\ServerService;
|
2020-06-11 20:47:02 +08:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Models\ServerTrojan;
|
|
|
|
|
|
|
|
class TrojanController extends Controller
|
|
|
|
{
|
|
|
|
public function save(ServerTrojanSave $request)
|
|
|
|
{
|
2020-07-15 15:57:12 +08:00
|
|
|
$params = $request->validated();
|
2020-06-11 20:47:02 +08:00
|
|
|
if ($request->input('id')) {
|
|
|
|
$server = ServerTrojan::find($request->input('id'));
|
|
|
|
if (!$server) {
|
|
|
|
abort(500, '服务器不存在');
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$server->update($params);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
abort(500, '保存失败');
|
|
|
|
}
|
|
|
|
return response([
|
|
|
|
'data' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ServerTrojan::create($params)) {
|
|
|
|
abort(500, '创建失败');
|
|
|
|
}
|
|
|
|
|
|
|
|
return response([
|
|
|
|
'data' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function drop(Request $request)
|
|
|
|
{
|
|
|
|
if ($request->input('id')) {
|
|
|
|
$server = ServerTrojan::find($request->input('id'));
|
|
|
|
if (!$server) {
|
|
|
|
abort(500, '节点ID不存在');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return response([
|
|
|
|
'data' => $server->delete()
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update(ServerTrojanUpdate $request)
|
|
|
|
{
|
|
|
|
$params = $request->only([
|
|
|
|
'show',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$server = ServerTrojan::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 = ServerTrojan::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, '服务器不存在');
|
|
|
|
}
|
|
|
|
if (!ServerTrojan::create($server->toArray())) {
|
|
|
|
abort(500, '复制失败');
|
|
|
|
}
|
|
|
|
|
|
|
|
return response([
|
|
|
|
'data' => true
|
|
|
|
]);
|
|
|
|
}
|
2020-07-02 21:41:14 +08:00
|
|
|
public function viewConfig(Request $request)
|
|
|
|
{
|
|
|
|
$serverService = new ServerService();
|
|
|
|
$config = $serverService->getTrojanConfig($request->input('node_id'), 23333);
|
|
|
|
return response([
|
|
|
|
'data' => $config
|
|
|
|
]);
|
|
|
|
}
|
2020-06-11 20:47:02 +08:00
|
|
|
}
|