mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 09:39:10 +08:00
update: new feature route manage
This commit is contained in:
parent
f9e2afe9d1
commit
16693b94bf
57
app/Http/Controllers/Admin/Server/RouteController.php
Normal file
57
app/Http/Controllers/Admin/Server/RouteController.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Server;
|
||||
|
||||
use App\Http\Requests\Admin\ServerShadowsocksSave;
|
||||
use App\Http\Requests\Admin\ServerShadowsocksUpdate;
|
||||
use App\Models\ServerRoute;
|
||||
use App\Models\ServerShadowsocks;
|
||||
use App\Services\ServerService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class RouteController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$routes = ServerRoute::get();
|
||||
return [
|
||||
'data' => $routes
|
||||
];
|
||||
}
|
||||
|
||||
public function save(Request $request)
|
||||
{
|
||||
$params = $request->validate([
|
||||
'remarks' => 'required',
|
||||
'match' => 'required',
|
||||
'action' => 'required',
|
||||
'action_value' => 'nullable'
|
||||
]);
|
||||
if ($request->input('id')) {
|
||||
try {
|
||||
$route = ServerRoute::find($request->input('id'));
|
||||
$route->update($params);
|
||||
return [
|
||||
'data' => true
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
}
|
||||
if (!ServerRoute::create($params)) abort(500, '创建失败');
|
||||
return [
|
||||
'data' => true
|
||||
];
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
$route = ServerRoute::find($request->input('id'));
|
||||
if (!$route) abort(500, '路由不存在');
|
||||
if (!$route->delete()) abort(500, '删除失败');
|
||||
return [
|
||||
'data' => true
|
||||
];
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ class UniProxyController extends Controller
|
||||
private $nodeType;
|
||||
private $nodeInfo;
|
||||
private $nodeId;
|
||||
private $token;
|
||||
private $serverService;
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
@ -29,25 +29,11 @@ class UniProxyController extends Controller
|
||||
if ($token !== config('v2board.server_token')) {
|
||||
abort(500, 'token is error');
|
||||
}
|
||||
$this->token = $token;
|
||||
$this->nodeType = $request->input('node_type');
|
||||
$this->nodeId = $request->input('node_id');
|
||||
switch ($this->nodeType) {
|
||||
case 'v2ray':
|
||||
$this->nodeInfo = ServerV2ray::find($this->nodeId);
|
||||
break;
|
||||
case 'shadowsocks':
|
||||
$this->nodeInfo = ServerShadowsocks::find($this->nodeId);
|
||||
break;
|
||||
case 'trojan':
|
||||
$this->nodeInfo = ServerTrojan::find($this->nodeId);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (!$this->nodeInfo) {
|
||||
abort(500, 'server not found');
|
||||
}
|
||||
$this->serverService = new ServerService();
|
||||
$this->nodeInfo = $this->serverService->getServer($this->nodeId, $this->nodeType);
|
||||
if (!$this->nodeInfo) abort(500, 'server is not exist');
|
||||
}
|
||||
|
||||
// 后端获取用户
|
||||
@ -55,8 +41,7 @@ class UniProxyController extends Controller
|
||||
{
|
||||
ini_set('memory_limit', -1);
|
||||
Cache::put(CacheKey::get('SERVER_' . strtoupper($this->nodeType) . '_LAST_CHECK_AT', $this->nodeInfo->id), time(), 3600);
|
||||
$serverService = new ServerService();
|
||||
$users = $serverService->getAvailableUsers($this->nodeInfo->group_id);
|
||||
$users = $this->serverService->getAvailableUsers($this->nodeInfo->group_id);
|
||||
$users = $users->toArray();
|
||||
|
||||
$response['users'] = $users;
|
||||
@ -127,6 +112,7 @@ class UniProxyController extends Controller
|
||||
'push_interval' => 120,
|
||||
'pull_interval' => 120
|
||||
];
|
||||
$response['routes'] = $this->serverService->getRoutes($this->nodeInfo['route_id']);
|
||||
$eTag = sha1(json_encode($response));
|
||||
if (strpos($request->header('If-None-Match'), $eTag) !== false ) {
|
||||
abort(304);
|
||||
|
@ -18,6 +18,7 @@ class ServerShadowsocksSave extends FormRequest
|
||||
'name' => 'required',
|
||||
'group_id' => 'required|array',
|
||||
'parent_id' => 'nullable|integer',
|
||||
'route_id' => 'nullable|array',
|
||||
'host' => 'required',
|
||||
'port' => 'required',
|
||||
'server_port' => 'required',
|
||||
@ -35,6 +36,7 @@ class ServerShadowsocksSave extends FormRequest
|
||||
'name.required' => '节点名称不能为空',
|
||||
'group_id.required' => '权限组不能为空',
|
||||
'group_id.array' => '权限组格式不正确',
|
||||
'route_id.array' => '路由组格式不正确',
|
||||
'parent_id.integer' => '父节点格式不正确',
|
||||
'host.required' => '节点地址不能为空',
|
||||
'port.required' => '连接端口不能为空',
|
||||
|
@ -17,6 +17,7 @@ class ServerTrojanSave extends FormRequest
|
||||
'show' => '',
|
||||
'name' => 'required',
|
||||
'group_id' => 'required|array',
|
||||
'route_id' => 'nullable|array',
|
||||
'parent_id' => 'nullable|integer',
|
||||
'host' => 'required',
|
||||
'port' => 'required',
|
||||
@ -34,6 +35,7 @@ class ServerTrojanSave extends FormRequest
|
||||
'name.required' => '节点名称不能为空',
|
||||
'group_id.required' => '权限组不能为空',
|
||||
'group_id.array' => '权限组格式不正确',
|
||||
'route_id.array' => '路由组格式不正确',
|
||||
'parent_id.integer' => '父节点格式不正确',
|
||||
'host.required' => '节点地址不能为空',
|
||||
'port.required' => '连接端口不能为空',
|
||||
|
@ -17,6 +17,7 @@ class ServerV2raySave extends FormRequest
|
||||
'show' => '',
|
||||
'name' => 'required',
|
||||
'group_id' => 'required|array',
|
||||
'route_id' => 'nullable|array',
|
||||
'parent_id' => 'nullable|integer',
|
||||
'host' => 'required',
|
||||
'port' => 'required',
|
||||
@ -38,6 +39,7 @@ class ServerV2raySave extends FormRequest
|
||||
'name.required' => '节点名称不能为空',
|
||||
'group_id.required' => '权限组不能为空',
|
||||
'group_id.array' => '权限组格式不正确',
|
||||
'route_id.array' => '路由组格式不正确',
|
||||
'parent_id.integer' => '父ID格式不正确',
|
||||
'host.required' => '节点地址不能为空',
|
||||
'port.required' => '连接端口不能为空',
|
||||
|
@ -28,6 +28,9 @@ class AdminRoute
|
||||
$router->get ('/server/group/fetch', 'Admin\\Server\\GroupController@fetch');
|
||||
$router->post('/server/group/save', 'Admin\\Server\\GroupController@save');
|
||||
$router->post('/server/group/drop', 'Admin\\Server\\GroupController@drop');
|
||||
$router->get ('/server/route/fetch', 'Admin\\Server\\RouteController@fetch');
|
||||
$router->post('/server/route/save', 'Admin\\Server\\RouteController@save');
|
||||
$router->post('/server/route/drop', 'Admin\\Server\\RouteController@drop');
|
||||
$router->get ('/server/manage/getNodes', 'Admin\\Server\\ManageController@getNodes');
|
||||
$router->post('/server/manage/sort', 'Admin\\Server\\ManageController@sort');
|
||||
$router->group([
|
||||
|
16
app/Models/ServerRoute.php
Executable file
16
app/Models/ServerRoute.php
Executable file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ServerRoute extends Model
|
||||
{
|
||||
protected $table = 'v2_server_route';
|
||||
protected $dateFormat = 'U';
|
||||
protected $guarded = ['id'];
|
||||
protected $casts = [
|
||||
'created_at' => 'timestamp',
|
||||
'updated_at' => 'timestamp',
|
||||
];
|
||||
}
|
@ -13,6 +13,7 @@ class ServerShadowsocks extends Model
|
||||
'created_at' => 'timestamp',
|
||||
'updated_at' => 'timestamp',
|
||||
'group_id' => 'array',
|
||||
'route_id' => 'array',
|
||||
'tags' => 'array',
|
||||
'obfs_settings' => 'array'
|
||||
];
|
||||
|
@ -13,6 +13,7 @@ class ServerTrojan extends Model
|
||||
'created_at' => 'timestamp',
|
||||
'updated_at' => 'timestamp',
|
||||
'group_id' => 'array',
|
||||
'route_id' => 'array',
|
||||
'tags' => 'array'
|
||||
];
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ class ServerV2ray extends Model
|
||||
'created_at' => 'timestamp',
|
||||
'updated_at' => 'timestamp',
|
||||
'group_id' => 'array',
|
||||
'route_id' => 'array',
|
||||
'tlsSettings' => 'array',
|
||||
'networkSettings' => 'array',
|
||||
'dnsSettings' => 'array',
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\ServerLog;
|
||||
use App\Models\ServerRoute;
|
||||
use App\Models\ServerShadowsocks;
|
||||
use App\Models\User;
|
||||
use App\Models\ServerV2ray;
|
||||
@ -107,7 +108,6 @@ class ServerService
|
||||
return $servers;
|
||||
}
|
||||
|
||||
|
||||
public function getAvailableUsers($groupId)
|
||||
{
|
||||
return User::whereIn('group_id', $groupId)
|
||||
@ -183,7 +183,7 @@ class ServerService
|
||||
return $server->toArray();
|
||||
}
|
||||
|
||||
public function mergeData(&$servers)
|
||||
private function mergeData(&$servers)
|
||||
{
|
||||
foreach ($servers as $k => $v) {
|
||||
$serverType = strtoupper($servers[$k]['type']);
|
||||
@ -217,4 +217,23 @@ class ServerService
|
||||
array_multisort($tmp, SORT_ASC, $servers);
|
||||
return $servers;
|
||||
}
|
||||
|
||||
public function getRoutes(array $routeIds)
|
||||
{
|
||||
return ServerRoute::select(['id', 'match', 'action', 'action_value'])->whereIn('id', $routeIds)->get();
|
||||
}
|
||||
|
||||
public function getServer($serverId, $serverType)
|
||||
{
|
||||
switch ($serverType) {
|
||||
case 'v2ray':
|
||||
return ServerV2ray::find($serverId);
|
||||
case 'shadowsocks':
|
||||
return ServerShadowsocks::find($serverId);
|
||||
case 'trojan':
|
||||
return ServerTrojan::find($serverId);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -194,10 +194,24 @@ CREATE TABLE `v2_server_group` (
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `v2_server_route`;
|
||||
CREATE TABLE `v2_server_route` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`remarks` varchar(255) NOT NULL,
|
||||
`match` varchar(255) NOT NULL,
|
||||
`action` varchar(11) NOT NULL,
|
||||
`action_value` varchar(255) DEFAULT NULL,
|
||||
`created_at` int(11) NOT NULL,
|
||||
`updated_at` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `v2_server_shadowsocks`;
|
||||
CREATE TABLE `v2_server_shadowsocks` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`group_id` varchar(255) NOT NULL,
|
||||
`route_id` varchar(255) DEFAULT NULL,
|
||||
`parent_id` int(11) DEFAULT NULL,
|
||||
`tags` varchar(255) DEFAULT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
@ -220,6 +234,7 @@ DROP TABLE IF EXISTS `v2_server_trojan`;
|
||||
CREATE TABLE `v2_server_trojan` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '节点ID',
|
||||
`group_id` varchar(255) NOT NULL COMMENT '节点组',
|
||||
`route_id` varchar(255) DEFAULT NULL,
|
||||
`parent_id` int(11) DEFAULT NULL COMMENT '父节点',
|
||||
`tags` varchar(255) DEFAULT NULL COMMENT '节点标签',
|
||||
`name` varchar(255) NOT NULL COMMENT '节点名称',
|
||||
@ -241,7 +256,8 @@ DROP TABLE IF EXISTS `v2_server_v2ray`;
|
||||
CREATE TABLE `v2_server_v2ray` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`group_id` varchar(255) NOT NULL,
|
||||
`name` varchar(255) CHARACTER SET utf8mb4 NOT NULL,
|
||||
`route_id` varchar(255) DEFAULT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`parent_id` int(11) DEFAULT NULL,
|
||||
`host` varchar(255) NOT NULL,
|
||||
`port` varchar(11) NOT NULL,
|
||||
@ -260,7 +276,7 @@ CREATE TABLE `v2_server_v2ray` (
|
||||
`created_at` int(11) NOT NULL,
|
||||
`updated_at` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `v2_stat_order`;
|
||||
@ -381,4 +397,4 @@ CREATE TABLE `v2_user` (
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
-- 2022-11-21 20:03:16
|
||||
-- 2022-11-27 07:09:04
|
||||
|
@ -587,12 +587,6 @@ ALTER TABLE `v2_mail_log`
|
||||
CHANGE `template_name` `template_name` varchar(255) NOT NULL AFTER `subject`,
|
||||
CHANGE `error` `error` text NULL AFTER `template_name`;
|
||||
|
||||
ALTER TABLE `v2_plan`
|
||||
ADD `inventory_limit` int(11) NULL AFTER `reset_traffic_method`;
|
||||
|
||||
ALTER TABLE `v2_plan`
|
||||
CHANGE `inventory_limit` `capacity_limit` int(11) NULL AFTER `reset_traffic_method`;
|
||||
|
||||
ALTER TABLE `v2_user`
|
||||
ADD `speed_limit` int(11) NULL AFTER `plan_id`;
|
||||
|
||||
@ -608,3 +602,29 @@ ALTER TABLE `v2_server_trojan`
|
||||
UPDATE `v2_stat_server` SET
|
||||
`server_type` = 'v2ray'
|
||||
WHERE `server_type` = 'vmess';
|
||||
|
||||
ALTER TABLE `v2_server_shadowsocks`
|
||||
ADD `route_id` varchar(255) COLLATE 'utf8mb4_general_ci' NULL AFTER `group_id`;
|
||||
|
||||
ALTER TABLE `v2_server_trojan`
|
||||
ADD `route_id` varchar(255) COLLATE 'utf8mb4_general_ci' NULL AFTER `group_id`;
|
||||
|
||||
ALTER TABLE `v2_server_v2ray`
|
||||
COLLATE 'utf8mb4_general_ci';
|
||||
|
||||
ALTER TABLE `v2_server_v2ray`
|
||||
CHANGE `group_id` `group_id` varchar(255) NOT NULL AFTER `id`,
|
||||
CHANGE `route_id` `route_id` varchar(255) NULL AFTER `group_id`,
|
||||
CHANGE `host` `host` varchar(255) NOT NULL AFTER `parent_id`,
|
||||
CHANGE `port` `port` varchar(11) NOT NULL AFTER `host`,
|
||||
CHANGE `tags` `tags` varchar(255) NULL AFTER `tls`,
|
||||
CHANGE `rate` `rate` varchar(11) NOT NULL AFTER `tags`,
|
||||
CHANGE `network` `network` text NOT NULL AFTER `rate`,
|
||||
CHANGE `rules` `rules` text NULL AFTER `network`,
|
||||
CHANGE `networkSettings` `networkSettings` text NULL AFTER `rules`,
|
||||
CHANGE `tlsSettings` `tlsSettings` text NULL AFTER `networkSettings`,
|
||||
CHANGE `ruleSettings` `ruleSettings` text NULL AFTER `tlsSettings`,
|
||||
CHANGE `dnsSettings` `dnsSettings` text NULL AFTER `ruleSettings`;
|
||||
|
||||
ALTER TABLE `v2_server_v2ray`
|
||||
ADD `route_id` varchar(255) COLLATE 'utf8mb4_general_ci' NULL AFTER `group_id`;
|
||||
|
Loading…
Reference in New Issue
Block a user