|
@@ -47,9 +47,8 @@ class NodeController extends Controller
|
|
|
return view('admin.node.index', ['nodeList' => $nodeList]);
|
|
|
}
|
|
|
|
|
|
- // 添加节点
|
|
|
public function store(NodeRequest $request): JsonResponse
|
|
|
- {
|
|
|
+ { // 添加节点
|
|
|
try {
|
|
|
if ($node = Node::create($this->nodeStore($request->validated()))) {
|
|
|
// 生成节点标签
|
|
@@ -80,74 +79,8 @@ class NodeController extends Controller
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
- // 添加节点信息
|
|
|
- private function nodeStore(array $info): array
|
|
|
- {
|
|
|
- switch ($info['type']) {
|
|
|
- case 0:
|
|
|
- $profile = [
|
|
|
- 'method' => $info['method'],
|
|
|
- ];
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- $profile = [
|
|
|
- 'method' => $info['v2_method'],
|
|
|
- 'v2_alter_id' => $info['v2_alter_id'],
|
|
|
- 'v2_net' => $info['v2_net'],
|
|
|
- 'v2_type' => $info['v2_type'],
|
|
|
- 'v2_host' => $info['v2_host'],
|
|
|
- 'v2_path' => $info['v2_path'],
|
|
|
- 'v2_tls' => $info['v2_tls'] ? 'tls' : '',
|
|
|
- 'v2_sni' => $info['v2_sni'],
|
|
|
- ];
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- $profile = [
|
|
|
- 'allow_insecure' => false,
|
|
|
- ];
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- case 4:
|
|
|
- $profile = [
|
|
|
- 'method' => $info['method'],
|
|
|
- 'protocol' => $info['protocol'],
|
|
|
- 'obfs' => $info['obfs'],
|
|
|
- 'obfs_param' => $info['obfs_param'],
|
|
|
- 'protocol_param' => $info['protocol_param'],
|
|
|
- 'passwd' => $info['passwd'],
|
|
|
- ];
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- return [
|
|
|
- 'type' => $info['type'],
|
|
|
- 'name' => $info['name'],
|
|
|
- 'country_code' => $info['country_code'],
|
|
|
- 'server' => $info['server'],
|
|
|
- 'ip' => $info['ip'],
|
|
|
- 'ipv6' => $info['ipv6'],
|
|
|
- 'level' => $info['level'],
|
|
|
- 'rule_group_id' => $info['rule_group_id'],
|
|
|
- 'speed_limit' => $info['speed_limit'],
|
|
|
- 'client_limit' => $info['client_limit'],
|
|
|
- 'description' => $info['description'],
|
|
|
- 'profile' => $profile ?? [],
|
|
|
- 'traffic_rate' => $info['traffic_rate'],
|
|
|
- 'is_udp' => $info['is_udp'],
|
|
|
- 'is_display' => $info['is_display'],
|
|
|
- 'is_ddns' => $info['is_ddns'],
|
|
|
- 'relay_node_id' => $info['relay_node_id'],
|
|
|
- 'port' => $info['port'],
|
|
|
- 'push_port' => $info['push_port'],
|
|
|
- 'detection_type' => $info['detection_type'],
|
|
|
- 'sort' => $info['sort'],
|
|
|
- 'status' => $info['status'],
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- // 克隆节点
|
|
|
public function clone(Node $node)
|
|
|
- {
|
|
|
+ { // 克隆节点
|
|
|
$new = $node->replicate()->fill([
|
|
|
'name' => $node->name.'_克隆',
|
|
|
'server' => null,
|
|
@@ -157,9 +90,8 @@ class NodeController extends Controller
|
|
|
return redirect()->route('admin.node.edit', $new);
|
|
|
}
|
|
|
|
|
|
- // 编辑节点页面
|
|
|
public function edit(Node $node)
|
|
|
- {
|
|
|
+ { // 编辑节点页面
|
|
|
return view('admin.node.info', [
|
|
|
'node' => $node,
|
|
|
'nodes' => Node::whereNotIn('id', [$node->id])->orderBy('id')->pluck('id', 'name'),
|
|
@@ -171,9 +103,8 @@ class NodeController extends Controller
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
- // 编辑节点
|
|
|
public function update(NodeRequest $request, Node $node): JsonResponse
|
|
|
- {
|
|
|
+ { // 编辑节点
|
|
|
try {
|
|
|
if ($node->update($this->nodeStore($request->validated()))) {
|
|
|
// 更新节点标签
|
|
@@ -190,9 +121,8 @@ class NodeController extends Controller
|
|
|
return Response::json(['status' => 'fail', 'message' => '编辑失败']);
|
|
|
}
|
|
|
|
|
|
- // 删除节点
|
|
|
public function destroy(Node $node): JsonResponse
|
|
|
- {
|
|
|
+ { // 删除节点
|
|
|
try {
|
|
|
if ($node->delete()) {
|
|
|
return Response::json(['status' => 'success', 'message' => '删除成功']);
|
|
@@ -206,9 +136,8 @@ class NodeController extends Controller
|
|
|
return Response::json(['status' => 'fail', 'message' => '删除线路失败']);
|
|
|
}
|
|
|
|
|
|
- // 节点IP阻断检测
|
|
|
public function checkNode(Node $node): JsonResponse
|
|
|
- {
|
|
|
+ { // 节点IP阻断检测
|
|
|
foreach ($node->ips() as $ip) {
|
|
|
$icmp = (new NetworkDetection)->networkCheck($ip, true, $node->port ?? 22); // ICMP
|
|
|
$tcp = (new NetworkDetection)->networkCheck($ip, false, $node->port ?? 22); // TCP
|
|
@@ -218,9 +147,8 @@ class NodeController extends Controller
|
|
|
return Response::json(['status' => 'success', 'title' => '['.$node->name.']阻断信息', 'message' => $data ?? []]);
|
|
|
}
|
|
|
|
|
|
- // 刷新节点地理位置
|
|
|
public function refreshGeo($id): JsonResponse
|
|
|
- {
|
|
|
+ { // 刷新节点地理位置
|
|
|
$ret = false;
|
|
|
if ($id) {
|
|
|
$ret = Node::findOrFail($id)->refresh_geo();
|
|
@@ -240,9 +168,8 @@ class NodeController extends Controller
|
|
|
return Response::json(['status' => 'fail', 'message' => '【存在】获取地理位置更新失败!']);
|
|
|
}
|
|
|
|
|
|
- // 重载节点
|
|
|
public function reload($id): JsonResponse
|
|
|
- {
|
|
|
+ { // 重载节点
|
|
|
$ret = false;
|
|
|
if ($id) {
|
|
|
$node = Node::findOrFail($id);
|
|
@@ -263,15 +190,13 @@ class NodeController extends Controller
|
|
|
return Response::json(['status' => 'fail', 'message' => '【存在】重载失败!']);
|
|
|
}
|
|
|
|
|
|
- // 节点流量监控
|
|
|
public function nodeMonitor(Node $node)
|
|
|
- {
|
|
|
+ { // 节点流量监控
|
|
|
return view('admin.node.monitor', array_merge(['nodeName' => $node->name, 'nodeServer' => $node->server], $this->DataFlowChart($node->id, true)));
|
|
|
}
|
|
|
|
|
|
- // Ping节点延迟
|
|
|
public function pingNode(Node $node): JsonResponse
|
|
|
- {
|
|
|
+ { // Ping节点延迟
|
|
|
if ($node->is_ddns) {
|
|
|
if ($result = (new NetworkDetection)->ping($node->server)) {
|
|
|
return Response::json(['status' => 'success', 'message' => $result]);
|
|
@@ -291,4 +216,66 @@ class NodeController extends Controller
|
|
|
|
|
|
return Response::json(['status' => 'fail', 'message' => 'Ping访问失败']);
|
|
|
}
|
|
|
+
|
|
|
+ private function nodeStore(array $info): array
|
|
|
+ { // 添加节点信息
|
|
|
+ switch ($info['type']) {
|
|
|
+ case 0:
|
|
|
+ $profile = ['method' => $info['method']];
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ $profile = [
|
|
|
+ 'method' => $info['v2_method'],
|
|
|
+ 'v2_alter_id' => $info['v2_alter_id'],
|
|
|
+ 'v2_net' => $info['v2_net'],
|
|
|
+ 'v2_type' => $info['v2_type'],
|
|
|
+ 'v2_host' => $info['v2_host'],
|
|
|
+ 'v2_path' => $info['v2_path'],
|
|
|
+ 'v2_tls' => $info['v2_tls'] ? 'tls' : '',
|
|
|
+ 'v2_sni' => $info['v2_sni'],
|
|
|
+ ];
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ $profile = [
|
|
|
+ 'allow_insecure' => false,
|
|
|
+ ];
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ case 4:
|
|
|
+ $profile = [
|
|
|
+ 'method' => $info['method'],
|
|
|
+ 'protocol' => $info['protocol'],
|
|
|
+ 'obfs' => $info['obfs'],
|
|
|
+ 'obfs_param' => $info['obfs_param'],
|
|
|
+ 'protocol_param' => $info['protocol_param'],
|
|
|
+ 'passwd' => $info['passwd'],
|
|
|
+ ];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'type' => $info['type'],
|
|
|
+ 'name' => $info['name'],
|
|
|
+ 'country_code' => $info['country_code'],
|
|
|
+ 'server' => $info['server'],
|
|
|
+ 'ip' => $info['ip'],
|
|
|
+ 'ipv6' => $info['ipv6'],
|
|
|
+ 'level' => $info['level'],
|
|
|
+ 'rule_group_id' => $info['rule_group_id'],
|
|
|
+ 'speed_limit' => $info['speed_limit'],
|
|
|
+ 'client_limit' => $info['client_limit'],
|
|
|
+ 'description' => $info['description'],
|
|
|
+ 'profile' => $profile ?? [],
|
|
|
+ 'traffic_rate' => $info['traffic_rate'],
|
|
|
+ 'is_udp' => $info['is_udp'],
|
|
|
+ 'is_display' => $info['is_display'],
|
|
|
+ 'is_ddns' => $info['is_ddns'],
|
|
|
+ 'relay_node_id' => $info['relay_node_id'],
|
|
|
+ 'port' => $info['port'] ?? 0,
|
|
|
+ 'push_port' => $info['push_port'],
|
|
|
+ 'detection_type' => $info['detection_type'],
|
|
|
+ 'sort' => $info['sort'],
|
|
|
+ 'status' => $info['status'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
}
|