Browse Source

[Uim] fix: sing-box subscribe (#2448)

fix: sing-box subscribe
77-QiQi 1 year ago
parent
commit
4a2989a2ff
2 changed files with 72 additions and 30 deletions
  1. 67 30
      config/appprofile.example.php
  2. 5 0
      src/Services/Subscribe/SingBox.php

+ 67 - 30
config/appprofile.example.php

@@ -45,77 +45,110 @@ $_ENV['V2RayJson_Config'] = [
 
 $_ENV['SingBox_Config'] = [
     'log' => [
+        'disabled' => false,
         'level' => 'error',
+        'timestamp' => true,
     ],
     'dns' => [
         'servers' => [
+            [
+                'tag' => 'proxy',
+                'address' => 'tls://1.1.1.1/',
+                'detour' => 'select',
+            ],
             [
                 'tag' => 'local',
-                'address' => 'local',
+                'address' => 'h3://223.5.5.5/dns-query',
+                'detour' => 'direct',
+            ],
+            [
+                'tag' => 'block',
+                'address' => 'rcode://refused',
             ],
         ],
         'rules' => [
             [
                 'outbound' => 'any',
                 'server' => 'local',
+                'disable_cache' => true,
+            ],
+            [
+                'clash_mode' => 'Global',
+                'server' => 'proxy',
+            ],
+            [
+                'clash_mode' => 'Direct',
+                'server' => 'local',
+            ],
+            [
+                'rule_set' => 'geosite-cn',
+                'server' => 'local',
             ],
         ],
-        'final' => 'local',
-        'strategy' => 'prefer_ipv6',
+        'final' => 'proxy',
+        'independent_cache' => true,
     ],
     'inbounds' => [
         [
             'type' => 'tun',
-            'inet4_address' => '172.19.0.1/30',
+            'address' => [
+                '172.18.0.1/30',
+                'fdfe:dcba:9876::1/126',
+            ],
             'auto_route' => true,
             'strict_route' => true,
-            'endpoint_independent_nat' => true,
-            'udp_timeout' => 60,
-            'platform' => [
-                'http_proxy' => [
-                    'enabled' => true,
-                    'server' => '127.0.0.1',
-                    'server_port' => 7891,
-                ],
-            ],
             'sniff' => true,
-        ],
-        [
-            'type' => 'mixed',
-            'listen' => '127.0.0.1',
-            'listen_port' => 7891,
-            'sniff' => true,
-            'domain_strategy' => 'prefer_ipv6',
+            'sniff_override_destination' => true,
+            'domain_strategy' => 'prefer_ipv4',
+            'udp_timeout' => 60,
         ],
     ],
     'outbounds' => [
         [
+            'tag' => 'select',
             'type' => 'selector',
-            'tag' => 'default',
+            'default' => 'auto',
+            'outbounds' => [
+                'auto',
+            ],
+            'interrupt_exist_connections' => true,
+        ],
+        [
+            'tag' => 'auto',
+            'type' => 'urltest',
             'outbounds' => [],
+            'url' => 'https://cp.cloudflare.com/generate_204',
+            'interval' => '3m',
+            'tolerance' => 50,
+            'idle_timeout' => '30m',
+            'interrupt_exist_connections' => true,
         ],
         [
-            'type' => 'direct',
             'tag' => 'direct',
+            'type' => 'direct',
         ],
         [
-            'type' => 'block',
             'tag' => 'block',
+            'type' => 'block',
+        ],
+        [
+            'tag' => 'dns-out',
+            'type' => 'dns',
         ],
     ],
     'route' => [
         'rules' => [
             [
-                'clash_mode' => 'Direct',
-                'outbound' => 'direct',
+                'protocol' => 'dns',
+                'outbound' => 'dns-out',
             ],
             [
-                'clash_mode' => 'Rule',
-                'outbound' => 'default',
+                'clash_mode' => 'Direct',
+                'outbound' => 'direct',
             ],
             [
                 'clash_mode' => 'Global',
-                'outbound' => 'default',
+                'outbound' => 'select',
             ],
             [
                 'protocol' => 'stun',
@@ -140,22 +173,26 @@ $_ENV['SingBox_Config'] = [
                 'type' => 'remote',
                 'format' => 'binary',
                 'url' => 'https://' . $_ENV['jsdelivr_url'] . '/gh/SagerNet/sing-geoip@rule-set/geoip-cn.srs',
-                'download_detour' => 'direct',
+                'download_detour' => 'select',
+                'update_interval' => '1d',
             ],
             [
                 'tag' => 'geosite-cn',
                 'type' => 'remote',
                 'format' => 'binary',
                 'url' => 'https://' . $_ENV['jsdelivr_url'] . '/gh/SagerNet/sing-geosite@rule-set/geosite-cn.srs',
-                'download_detour' => 'direct',
+                'download_detour' => 'select',
+                'update_interval' => '1d',
             ],
         ],
         'auto_detect_interface' => true,
+        'final' => 'select',
     ],
     'experimental' => [
         'cache_file' => [
             'enabled' => true,
             'cache_id' => '',
+            'path' => 'cache.db',
         ],
         'clash_api' => [
             'external_controller' => '127.0.0.1:9090',

+ 5 - 0
src/Services/Subscribe/SingBox.php

@@ -102,13 +102,17 @@ final class SingBox extends Base
                         'security' => 'auto',
                         'alter_id' => 0,
                         'tls' => [
+                            'enabled' => true,
                             'server_name' => $host,
                         ],
+                        'packet_encoding' => 'packetaddr',
                         'transport' => [
                             'type' => $transport,
                             'path' => $path,
                             'headers' => $headers,
                             'service_name' => $service_name,
+                            'max_early_data' => 2048,
+                            'early_data_header_name' => 'Sec-WebSocket-Protocol',
                         ],
                     ];
 
@@ -160,6 +164,7 @@ final class SingBox extends Base
 
             $nodes[] = $node;
             $singbox_config['outbounds'][0]['outbounds'][] = $node_raw->name;
+            $singbox_config['outbounds'][1]['outbounds'][] = $node_raw->name;
         }
 
         $singbox_config['outbounds'] = array_merge($singbox_config['outbounds'], $nodes);