@@ -19,6 +19,8 @@ class Surge extends AbstractProtocol
1919 Server::TYPE_TROJAN ,
2020 Server::TYPE_HYSTERIA ,
2121 Server::TYPE_ANYTLS ,
22+ Server::TYPE_SOCKS ,
23+ Server::TYPE_HTTP ,
2224 ];
2325 protected $ protocolRequirements = [
2426 'surge.hysteria.protocol_settings.version ' => [2 => '2398 ' ],
@@ -41,7 +43,9 @@ public function handle()
4143 'aes-128-gcm ' ,
4244 'aes-192-gcm ' ,
4345 'aes-256-gcm ' ,
44- 'chacha20-ietf-poly1305 '
46+ 'chacha20-ietf-poly1305 ' ,
47+ '2022-blake3-aes-128-gcm ' ,
48+ '2022-blake3-aes-256-gcm '
4549 ])
4650 ) {
4751 $ proxies .= self ::buildShadowsocks ($ item ['password ' ], $ item );
@@ -63,6 +67,14 @@ public function handle()
6367 $ proxies .= self ::buildAnyTLS ($ item ['password ' ], $ item );
6468 $ proxyGroup .= $ item ['name ' ] . ', ' ;
6569 }
70+ if ($ item ['type ' ] === Server::TYPE_SOCKS ) {
71+ $ proxies .= self ::buildSocks ($ item ['password ' ], $ item );
72+ $ proxyGroup .= $ item ['name ' ] . ', ' ;
73+ }
74+ if ($ item ['type ' ] === Server::TYPE_HTTP ) {
75+ $ proxies .= self ::buildHttp ($ item ['password ' ], $ item );
76+ $ proxyGroup .= $ item ['name ' ] . ', ' ;
77+ }
6678 }
6779
6880
@@ -249,4 +261,61 @@ public static function buildHysteria($password, $server)
249261 $ uri .= "\r\n" ;
250262 return $ uri ;
251263 }
264+
265+ //参考文档: https://manual.nssurge.com/policy/proxy.html
266+ public static function buildSocks ($ password , $ server )
267+ {
268+ $ protocol_settings = data_get ($ server , 'protocol_settings ' , []);
269+ $ type = data_get ($ protocol_settings , 'tls ' ) ? 'socks5-tls ' : 'socks5 ' ;
270+ $ config = [
271+ "{$ server ['name ' ]}= {$ type }" ,
272+ "{$ server ['host ' ]}" ,
273+ "{$ server ['port ' ]}" ,
274+ "{$ password }" ,
275+ "{$ password }" ,
276+ ];
277+
278+ if (data_get ($ protocol_settings , 'tls ' )) {
279+ if ($ serverName = data_get ($ protocol_settings , 'tls_settings.server_name ' )) {
280+ $ config [] = "sni= {$ serverName }" ;
281+ }
282+ if (data_get ($ protocol_settings , 'tls_settings.allow_insecure ' )) {
283+ $ config [] = 'skip-cert-verify=true ' ;
284+ }
285+ }
286+ $ config [] = 'udp-relay=true ' ;
287+
288+ $ config = array_filter ($ config );
289+ $ uri = implode (', ' , $ config );
290+ $ uri .= "\r\n" ;
291+ return $ uri ;
292+ }
293+
294+ //参考文档: https://manual.nssurge.com/policy/proxy.html
295+ public static function buildHttp ($ password , $ server )
296+ {
297+ $ protocol_settings = data_get ($ server , 'protocol_settings ' , []);
298+ $ type = data_get ($ protocol_settings , 'tls ' ) ? 'https ' : 'http ' ;
299+ $ config = [
300+ "{$ server ['name ' ]}= {$ type }" ,
301+ "{$ server ['host ' ]}" ,
302+ "{$ server ['port ' ]}" ,
303+ "{$ password }" ,
304+ "{$ password }" ,
305+ ];
306+
307+ if (data_get ($ protocol_settings , 'tls ' )) {
308+ if ($ serverName = data_get ($ protocol_settings , 'tls_settings.server_name ' )) {
309+ $ config [] = "sni= {$ serverName }" ;
310+ }
311+ if (data_get ($ protocol_settings , 'tls_settings.allow_insecure ' )) {
312+ $ config [] = 'skip-cert-verify=true ' ;
313+ }
314+ }
315+
316+ $ config = array_filter ($ config );
317+ $ uri = implode (', ' , $ config );
318+ $ uri .= "\r\n" ;
319+ return $ uri ;
320+ }
252321}
0 commit comments