add: server name check

This commit is contained in:
tokumeikoi 2021-03-10 19:52:51 +09:00
parent 11b6c8448a
commit 58a63ae819
5 changed files with 22 additions and 17 deletions

View File

@ -2,13 +2,9 @@
namespace App\Http\Controllers\Admin\Server;
use App\Http\Requests\Admin\ServerTrojanSort;
use App\Models\Plan;
use App\Models\Server;
use App\Models\ServerGroup;
use App\Models\ServerShadowsocks;
use App\Models\ServerTrojan;
use App\Models\User;
use App\Services\ServerService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

View File

@ -3,21 +3,19 @@
namespace App\Http\Controllers\Admin\Server;
use App\Http\Requests\Admin\ServerShadowsocksSave;
use App\Http\Requests\Admin\ServerShadowsocksSort;
use App\Http\Requests\Admin\ServerShadowsocksUpdate;
use App\Models\ServerShadowsocks;
use App\Utils\CacheKey;
use App\Services\ServerService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Server;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
class ShadowsocksController extends Controller
{
public function save(ServerShadowsocksSave $request)
{
$params = $request->validated();
$serverService = new ServerService();
if ($serverService->serverIsExist($params['name'])) abort(500, '节点名称已存在,请更换名称再试');
$params['group_id'] = json_encode($params['group_id']);
if (isset($params['tags'])) {
$params['tags'] = json_encode($params['tags']);

View File

@ -3,21 +3,19 @@
namespace App\Http\Controllers\Admin\Server;
use App\Http\Requests\Admin\ServerTrojanSave;
use App\Http\Requests\Admin\ServerTrojanSort;
use App\Http\Requests\Admin\ServerTrojanUpdate;
use App\Services\ServerService;
use App\Utils\CacheKey;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\ServerTrojan;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
class TrojanController extends Controller
{
public function save(ServerTrojanSave $request)
{
$params = $request->validated();
$serverService = new ServerService();
if ($serverService->serverIsExist($params['name'])) abort(500, '节点名称已存在,请更换名称再试');
$params['group_id'] = json_encode($params['group_id']);
if (isset($params['tags'])) {
$params['tags'] = json_encode($params['tags']);

View File

@ -3,21 +3,20 @@
namespace App\Http\Controllers\Admin\Server;
use App\Http\Requests\Admin\ServerV2raySave;
use App\Http\Requests\Admin\ServerV2raySort;
use App\Http\Requests\Admin\ServerV2rayUpdate;
use App\Services\ServerService;
use App\Utils\CacheKey;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Server;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
class V2rayController extends Controller
{
public function save(ServerV2raySave $request)
{
$params = $request->validated();
$serverService = new ServerService();
if ($serverService->serverIsExist($params['name'])) abort(500, '节点名称已存在,请更换名称再试');
$params['group_id'] = json_encode($params['group_id']);
if (isset($params['tags'])) {
$params['tags'] = json_encode($params['tags']);

View File

@ -357,4 +357,18 @@ class ServerService
}
return $server->toArray();
}
public function serverIsExist($name):bool
{
if (ServerShadowsocks::where('name', $name)->first()) {
return true;
}
if (ServerTrojan::where('name', $name)->first()) {
return true;
}
if (Server::where('name', $name)->first()) {
return true;
}
return false;
}
}