Browse Source

fix: uc bool type error

Co-Authored-By: 世界 <[email protected]>
M1Screw 2 years ago
parent
commit
70c1c7d832
3 changed files with 39 additions and 29 deletions
  1. 10 0
      config/appprofile.example.php
  2. 12 16
      src/Services/Subscribe/Clash.php
  3. 17 13
      src/Services/Subscribe/SingBox.php

+ 10 - 0
config/appprofile.example.php

@@ -100,6 +100,14 @@ $_ENV['SingBox_Config'] = [
         ],
     ],
     'route' => [
+        'geoip' => [
+            'download_url' => 'https://cdn.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geoip-lite.db',
+            'download_detour' => 'direct',
+        ],
+        'geosite' => [
+            'download_url' => 'https://cdn.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geosite-lite.db',
+            'download_detour' => 'direct',
+        ],
         'rules' => [
             [
                 'protocol' => 'dns',
@@ -147,7 +155,9 @@ $_ENV['SingBox_Config'] = [
     ],
     'experimental' => [
         'clash_api' => [
+            'external_controller' => '0.0.0.0:9090',
             'store_mode' => true,
+            'store_selected' => true,
             'cache_id' => '',
         ],
     ],

+ 12 - 16
src/Services/Subscribe/Clash.php

@@ -46,7 +46,7 @@ final class Clash extends Base
                         'port' => (int) $user->port,
                         'password' => $user->passwd,
                         'cipher' => $user->method,
-                        'udp' => $udp,
+                        'udp' => (bool) $udp,
                         'client-fingerprint' => $client_fingerprint,
                         'plugin' => $plugin,
                         'plugin-opts' => $plugin_option,
@@ -64,12 +64,8 @@ final class Clash extends Base
                     };
 
                     $user_pk = Tools::getSs2022UserPk($user, $pk_len);
-                    $plugin = $node_custom_config['plugin'] ?? '';
-                    $plugin_option = $node_custom_config['plugin_option'] ?? null;
                     // Clash 特定配置
                     $udp = $node_custom_config['udp'] ?? true;
-                    // Clash.Meta
-                    $client_fingerprint = $node_custom_config['client_fingerprint'] ?? '';
 
                     $node = [
                         'name' => $node_raw->name,
@@ -78,17 +74,15 @@ final class Clash extends Base
                         'port' => (int) $ss_2022_port,
                         'password' => $user_pk,
                         'cipher' => $method,
-                        'udp' => $udp,
-                        'client-fingerprint' => $client_fingerprint,
-                        'plugin' => $plugin,
-                        'plugin-opts' => $plugin_option,
+                        'udp' => (bool) $udp,
                     ];
 
                     break;
                 case 2:
                     $tuic_port = $node_custom_config['tuic_port'] ?? ($node_custom_config['offset_port_user']
                         ?? ($node_custom_config['offset_port_node'] ?? 443));
-                    $sni = $node_custom_config['sni'] ?? '';
+                    $host = $node_custom_config['host'] ?? '';
+                    $congestion_control = $node_custom_config['congestion_control'] ?? 'bbr';
 
                     // Tuic V5 Only
                     $node = [
@@ -98,7 +92,9 @@ final class Clash extends Base
                         'port' => (int) $tuic_port,
                         'password' => $user->passwd,
                         'uuid' => $user->uuid,
-                        'sni' => $sni,
+                        'sni' => $host,
+                        'congestion-controller' => $congestion_control,
+                        'reduce-rtt' => true,
                     ];
 
                     break;
@@ -134,12 +130,12 @@ final class Clash extends Base
                         'uuid' => $user->uuid,
                         'alterId' => (int) $alter_id,
                         'cipher' => $encryption,
-                        'udp' => $udp,
+                        'udp' => (bool) $udp,
                         'tls' => $tls,
                         'client-fingerprint' => $client_fingerprint,
                         'fingerprint' => $fingerprint,
                         'flow' => $flow,
-                        'skip-cert-verify' => $allow_insecure,
+                        'skip-cert-verify' => (bool) $allow_insecure,
                         'servername' => $host,
                         'network' => $network,
                         'ws-opts' => $ws_opts,
@@ -176,12 +172,12 @@ final class Clash extends Base
                         'port' => (int) $trojan_port,
                         'password' => $user->uuid,
                         'network' => $network,
-                        'udp' => $udp,
+                        'udp' => (bool) $udp,
                         'client-fingerprint' => $client_fingerprint,
                         'fingerprint' => $fingerprint,
                         'flow' => $flow,
-                        'flow-show' => $flow_show,
-                        'skip-cert-verify' => $allow_insecure,
+                        'flow-show' => (bool) $flow_show,
+                        'skip-cert-verify' => (bool) $allow_insecure,
                         'ws-opts' => $ws_opts,
                         'grpc-opts' => $grpc_opts,
                     ];

+ 17 - 13
src/Services/Subscribe/SingBox.php

@@ -30,9 +30,6 @@ final class SingBox extends Base
 
             switch ((int) $node_raw->sort) {
                 case 0:
-                    $plugin = $node_custom_config['plugin'] ?? '';
-                    $plugin_option = $node_custom_config['plugin_option'] ?? '';
-
                     $node = [
                         'type' => 'shadowsocks',
                         'tag' => $node_raw->name,
@@ -40,8 +37,6 @@ final class SingBox extends Base
                         'server_port' => (int) $user->port,
                         'method' => $user->method,
                         'password' => $user->passwd,
-                        'plugin' => $plugin,
-                        'plugin_opts' => $plugin_option,
                     ];
 
                     break;
@@ -56,8 +51,7 @@ final class SingBox extends Base
                     };
 
                     $user_pk = Tools::getSs2022UserPk($user, $pk_len);
-                    $plugin = $node_custom_config['plugin'] ?? '';
-                    $plugin_option = $node_custom_config['plugin_option'] ?? '';
+                    $server_key = $node_custom_config['server_key'] ?? '';
 
                     $node = [
                         'type' => 'shadowsocks',
@@ -65,15 +59,16 @@ final class SingBox extends Base
                         'server' => $server,
                         'server_port' => (int) $ss_2022_port,
                         'method' => $method,
-                        'password' => $user_pk,
-                        'plugin' => $plugin,
-                        'plugin_opts' => $plugin_option,
+                        'password' => $server_key === '' ? $user_pk : $server_key . ':' .$user_pk,
                     ];
 
                     break;
                 case 2:
                     $tuic_port = $node_custom_config['tuic_port'] ?? ($node_custom_config['offset_port_user']
                         ?? ($node_custom_config['offset_port_node'] ?? 443));
+                    $host = $node_custom_config['host'] ?? '';
+                    $allow_insecure = $node_custom_config['allow_insecure'] ?? false;
+                    $congestion_control = $node_custom_config['congestion_control'] ?? 'bbr';
 
                     $node = [
                         'type' => 'tuic',
@@ -82,8 +77,17 @@ final class SingBox extends Base
                         'server_port' => (int) $tuic_port,
                         'uuid' => $user->uuid,
                         'password' => $user->passwd,
+                        'congestion_control' => $congestion_control,
+                        'zero_rtt_handshake' => true,
+                        'tls' => [
+                            'enabled' => true,
+                            'server_name' => $host,
+                            'insecure' => (bool) $allow_insecure,
+                        ],
                     ];
 
+                    $node['tls'] = array_filter($node['tls']);
+
                     break;
                 case 11:
                     $v2_port = $node_custom_config['v2_port'] ?? ($node_custom_config['offset_port_user']
@@ -122,7 +126,7 @@ final class SingBox extends Base
                     $trojan_port = $node_custom_config['trojan_port'] ?? ($node_custom_config['offset_port_user']
                         ?? ($node_custom_config['offset_port_node'] ?? 443));
                     $host = $node_custom_config['host'] ?? '';
-                    $insecure = $node_custom_config['allow_insecure'] ?? false;
+                    $allow_insecure = $node_custom_config['allow_insecure'] ?? false;
                     $transport = $node_custom_config['network']
                         ?? (array_key_exists('grpc', $node_custom_config)
                         && $node_custom_config['grpc'] === '1' ? 'grpc' : '');
@@ -139,7 +143,7 @@ final class SingBox extends Base
                         'tls' => [
                             'enabled' => true,
                             'server_name' => $host,
-                            'insecure' => $insecure,
+                            'insecure' => (bool) $allow_insecure,
                         ],
                         'transport' => [
                             'type' => $transport,
@@ -167,7 +171,7 @@ final class SingBox extends Base
         }
 
         $singbox_config['outbounds'] = array_merge($singbox_config['outbounds'], $nodes);
-        $singbox_config['experimental']['clash_api']['cache_id'] = (string) $user->id;
+        $singbox_config['experimental']['clash_api']['cache_id'] = $_ENV['appName'];
 
         return json_encode($singbox_config);
     }