|
@@ -2,7 +2,6 @@
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
-use App\Components\NetworkDetection;
|
|
|
use App\Helpers\DataChart;
|
|
|
use App\Http\Controllers\Controller;
|
|
|
use App\Http\Requests\Admin\NodeRequest;
|
|
@@ -13,8 +12,10 @@ use App\Models\Level;
|
|
|
use App\Models\Node;
|
|
|
use App\Models\NodeCertificate;
|
|
|
use App\Models\RuleGroup;
|
|
|
+use App\Utils\NetworkDetection;
|
|
|
use Exception;
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
+use Illuminate\Http\RedirectResponse;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Log;
|
|
|
use Response;
|
|
@@ -37,11 +38,11 @@ class NodeController extends Controller
|
|
|
foreach ($nodeList as $node) {
|
|
|
$online_log = $node->onlineLogs->where('log_time', '>=', strtotime('-5 minutes'))->sortBy('log_time')->first(); // 在线人数
|
|
|
$node->online_users = $online_log->online_user ?? 0;
|
|
|
- $node->transfer = flowAutoShow($node->dailyDataFlows->sum('total')); // 已产生流量
|
|
|
+ $node->transfer = formatBytes($node->dailyDataFlows->sum('total')); // 已产生流量
|
|
|
$node_info = $node->heartbeats->where('log_time', '>=', strtotime(config('tasks.recently_heartbeat')))->sortBy('log_time')->first(); // 近期负载
|
|
|
- $node->isOnline = ! empty($node_info) && ! empty($node_info->load);
|
|
|
+ $node->isOnline = $node_info !== null && ! empty($node_info->load);
|
|
|
$node->load = $node_info->load ?? false;
|
|
|
- $node->uptime = empty($node_info) ? 0 : seconds2time($node_info->uptime);
|
|
|
+ $node->uptime = $node_info === null ? 0 : formatTime($node_info->uptime);
|
|
|
}
|
|
|
|
|
|
return view('admin.node.index', ['nodeList' => $nodeList]);
|
|
@@ -79,7 +80,69 @@ class NodeController extends Controller
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
- public function clone(Node $node)
|
|
|
+ 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'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function clone(Node $node): RedirectResponse
|
|
|
{ // 克隆节点
|
|
|
$new = $node->replicate()->fill([
|
|
|
'name' => $node->name.'_克隆',
|
|
@@ -139,9 +202,8 @@ class NodeController extends Controller
|
|
|
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
|
|
|
- $data[$ip] = [$icmp ? config('common.network_status')[$icmp] : ' ', $tcp ? config('common.network_status')[$tcp] : ' '];
|
|
|
+ $status = (new NetworkDetection)->networkStatus($ip, $node->port ?? 22);
|
|
|
+ $data[$ip] = [config('common.network_status')[$status['icmp']], config('common.network_status')[$status['tcp']]];
|
|
|
}
|
|
|
|
|
|
return Response::json(['status' => 'success', 'title' => '['.$node->name.']阻断信息', 'message' => $data ?? []]);
|
|
@@ -173,10 +235,10 @@ class NodeController extends Controller
|
|
|
$ret = false;
|
|
|
if ($id) {
|
|
|
$node = Node::findOrFail($id);
|
|
|
- $ret = reloadNode::dispatchNow($node);
|
|
|
+ $ret = reloadNode::dispatchSync($node);
|
|
|
} else {
|
|
|
foreach (Node::whereStatus(1)->whereType(4)->get() as $node) {
|
|
|
- $result = reloadNode::dispatchNow($node);
|
|
|
+ $result = reloadNode::dispatchSync($node);
|
|
|
if ($result && ! $ret) {
|
|
|
$ret = true;
|
|
|
}
|
|
@@ -216,66 +278,4 @@ 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'],
|
|
|
- ];
|
|
|
- }
|
|
|
}
|