diff --git a/lib/network/channel.dart b/lib/network/channel.dart index add8932..7984a13 100644 --- a/lib/network/channel.dart +++ b/lib/network/channel.dart @@ -276,15 +276,8 @@ class ChannelPipeline extends ChannelHandler { handler.channelActive(context, channel); } - /// 转发请求 - void relay(Channel clientChannel, Channel remoteChannel) { - var rawCodec = RawCodec(); - clientChannel.pipeline.handle(rawCodec, rawCodec, RelayHandler(remoteChannel)); - remoteChannel.pipeline.handle(rawCodec, rawCodec, RelayHandler(clientChannel)); - } - ///远程转发请求 - remoteForward(ChannelContext channelContext, HostAndPort remote, Uint8List msg) async { + remoteForward(ChannelContext channelContext, HostAndPort remote) async { var clientChannel = channelContext.clientChannel!; Channel? remoteChannel = channelContext.serverChannel ?? await channelContext.connectServerChannel(remote, RelayHandler(clientChannel)); @@ -298,8 +291,18 @@ class ChannelPipeline extends ChannelHandler { await remoteChannel.secureSocket(channelContext, host: channelContext.getAttribute(AttributeKeys.domain)); } - relay(clientChannel, remoteChannel); - handler.channelRead(channelContext, clientChannel, msg); + relay(channelContext, clientChannel, remoteChannel); + } + + /// 转发请求 + void relay(ChannelContext channelContext, Channel clientChannel, Channel remoteChannel) { + var rawCodec = RawCodec(); + clientChannel.pipeline.handle(rawCodec, rawCodec, RelayHandler(remoteChannel)); + remoteChannel.pipeline.handle(rawCodec, rawCodec, RelayHandler(clientChannel)); + + var body = buffer.bytes; + buffer.clear(); + handler.channelRead(channelContext, clientChannel, body); } @override @@ -307,22 +310,19 @@ class ChannelPipeline extends ChannelHandler { try { //手机扫码连接转发远程 HostAndPort? remote = channelContext.getAttribute(AttributeKeys.remote); + buffer.add(msg); + if (remote != null) { - await remoteForward(channelContext, remote, msg); + await remoteForward(channelContext, remote); return; } - buffer.add(msg); - Channel? remoteChannel = channelContext.getAttribute(channel.id); //大body 不解析直接转发 - if (buffer.length > Codec.maxBodyLength && handler is! RelayHandler) { + if (buffer.length > Codec.maxBodyLength && handler is! RelayHandler && remoteChannel != null) { logger.w("[$channel] forward large body"); - relay(channel, remoteChannel!); - var body = buffer.bytes; - buffer.clear(); - handler.channelRead(channelContext, channel, body); + relay(channelContext, channel, remoteChannel); return; } diff --git a/lib/network/components/script_manager.dart b/lib/network/components/script_manager.dart index b0389f5..3852a77 100644 --- a/lib/network/components/script_manager.dart +++ b/lib/network/components/script_manager.dart @@ -353,6 +353,13 @@ async function onResponse(context, request, response) { } request.headers.add(key, value); }); + + //判断是否是二进制 + if (getListElementType(map['body']) == int) { + request.body = convertList(map['body']); + return request; + } + request.body = map['body']?.toString().codeUnits; if (request.body != null && request.charset == 'utf-8') { diff --git a/lib/network/handler.dart b/lib/network/handler.dart index 7e0126f..7aeb9b7 100644 --- a/lib/network/handler.dart +++ b/lib/network/handler.dart @@ -114,7 +114,7 @@ class HttpProxyChannelHandler extends ChannelHandler { //实现抓包代理转发 if (httpRequest.method != HttpMethod.connect) { - log.i("[${channel.id}] ${httpRequest.method.name} ${httpRequest.requestUrl}"); + log.d("[${channel.id}] ${httpRequest.method.name} ${httpRequest.requestUrl}"); if (HostFilter.filter(httpRequest.hostAndPort?.host)) { await remoteChannel.write(httpRequest); return; diff --git a/lib/ui/component/utils.dart b/lib/ui/component/utils.dart index fce2fda..7f16625 100644 --- a/lib/ui/component/utils.dart +++ b/lib/ui/component/utils.dart @@ -1,3 +1,19 @@ +/* + * Copyright 2023 WangHongEn + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import 'dart:io'; import 'package:flutter/material.dart'; diff --git a/lib/ui/desktop/desktop.dart b/lib/ui/desktop/desktop.dart index 54c838e..e1f7f1f 100644 --- a/lib/ui/desktop/desktop.dart +++ b/lib/ui/desktop/desktop.dart @@ -14,7 +14,6 @@ * limitations under the License. */ - import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:network_proxy/network/bin/configuration.dart'; @@ -148,23 +147,22 @@ class _DesktopHomePagePageState extends State implements EventL isCN ? '提示:默认不会开启HTTPS抓包,请安装证书后再开启HTTPS抓包。\n' '点击HTTPS抓包(加锁图标),选择安装根证书,按照提示操作即可。\n\n' - '1. 桌面端增加全部请求列表;\n' - '2. iOS 通知栏显示VPN状态;\n' - '3. iOS修复停止长时间切换后台再开启抓包无网络问题;\n' - '4. 桌面端保存调整左右面板比例;\n' - '5. 手机端请求列表增加滚动条;\n' - '6. 修复请求重发和脚本导致URL错误;\n' - '7. 修复脚本二进制body转换问题;\n' - '8. 修复请求编辑中文路径编码问题;\n' + '1. 支持多种主题颜色选择;\n' + '2. 外部代理支持身份验证;\n' + '3. 双击列表tab滚动到顶部;\n' + '4. 修复部分p12证书导入失败的问题;\n' + '5. 修复Transfer-Encoding有空格解析错误问题;\n' + '6. 脚本增加rawBody原始字节参数, body支持字节数组修改;\n' + '7. 修复脚本消息体编码错误导致错误响应;\n' : 'Tips:By default, HTTPS packet capture will not be enabled. Please install the certificate before enabling HTTPS packet capture。\n' 'Click HTTPS Capture packets(Lock icon),Choose to install the root certificate and follow the prompts to proceed。\n\n' - '1. Desktop: Add all requests list;\n' - '2. iOS notification bar displays VPN status;\n' - '3. iOS fix: Stop switching to the background for a long time and then start packet capture without network problem;\n' - '4. Desktop: save the left and right panel ratio;\n' - '5. Mobile:Add a scrollbar to the request list;\n' - '6. fix request repeat & script change url wrong;\n' - '7. fix script binary body convert;\n' + '1. Support multiple theme colors;\n' + '2. External proxy support authentication;\n' + '3. Double-click the list tab to scroll to the top;\n' + '4. Fix the issue of partial p12 certificate import failure;\n' + '5. Fix header Transfer-Encoding with spaces;\n' + '6. The script add rawBody raw byte parameter, body supports byte array modification;\n' + '7. Fix script message body encoding error causing incorrect response;\n' '', style: const TextStyle(fontSize: 14))); }); diff --git a/lib/ui/desktop/left_menus/history.dart b/lib/ui/desktop/left_menus/history.dart index 0bdc23f..fbf03bf 100644 --- a/lib/ui/desktop/left_menus/history.dart +++ b/lib/ui/desktop/left_menus/history.dart @@ -79,7 +79,7 @@ class HistoryPageWidget extends StatelessWidget { preferredSize: const Size.fromHeight(40), child: AppBar( leadingWidth: 50, - leading: BackButton(style: ButtonStyle(iconSize: MaterialStateProperty.all(15))), + leading: BackButton(style: ButtonStyle(iconSize: WidgetStateProperty.all(15))), centerTitle: false, title: Text( textAlign: TextAlign.start, diff --git a/lib/ui/mobile/mobile.dart b/lib/ui/mobile/mobile.dart index bd3ed4e..f9bb35e 100644 --- a/lib/ui/mobile/mobile.dart +++ b/lib/ui/mobile/mobile.dart @@ -245,25 +245,24 @@ class MobileHomeState extends State implements EventListener, Li String content = isCN ? '提示:默认不会开启HTTPS抓包,请安装证书后再开启HTTPS抓包。\n\n' - '1. 桌面端增加全部请求列表;\n' - '2. iOS 通知栏显示VPN状态;\n' - '3. iOS修复停止长时间切换后台再开启抓包无网络问题;\n' - '4. 桌面端保存调整左右面板比例;\n' - '5. 手机端请求列表增加滚动条;\n' - '6. 修复请求重发和脚本导致URL错误;\n' - '7. 修复脚本二进制body转换问题;\n' - '8. 修复请求编辑中文路径编码问题;\n' + '1. 支持多种主题颜色选择;\n' + '2. 外部代理支持身份验证;\n' + '3. 双击列表tab滚动到顶部;\n' + '4. 修复部分p12证书导入失败的问题;\n' + '5. 修复Transfer-Encoding有空格解析错误问题;\n' + '6. 脚本增加rawBody原始字节参数, body支持字节数组修改;\n' + '7. 修复脚本消息体编码错误导致错误响应;\n' : 'Tips:By default, HTTPS packet capture will not be enabled. Please install the certificate before enabling HTTPS packet capture。\n\n' 'Click HTTPS Capture packets(Lock icon),Choose to install the root certificate and follow the prompts to proceed。\n\n' - '1. Desktop: Add all requests list;\n' - '2. iOS notification bar displays VPN status;\n' - '3. iOS fix: Stop switching to the background for a long time and then start packet capture without network problem;\n' - '4. Desktop: save the left and right panel ratio;\n' - '5. Mobile:Add a scrollbar to the request list;\n' - '6. fix request repeat & script change url wrong;\n' - '7. fix script binary body convert;\n' + '1. Support multiple theme colors;\n' + '2. External proxy support authentication;\n' + '3. Double-click the list tab to scroll to the top;\n' + '4. Fix the issue of partial p12 certificate import failure;\n' + '5. Fix header Transfer-Encoding with spaces;\n' + '6. The script add rawBody raw byte parameter, body supports byte array modification;\n' + '7. Fix script message body encoding error causing incorrect response;\n' ''; - showAlertDialog(isCN ? '更新内容V1.1.2' : "Update content V1.1.2", content, () { + showAlertDialog(isCN ? '更新内容V1.1.3' : "Update content V1.1.3", content, () { widget.appConfiguration.upgradeNoticeV12 = false; widget.appConfiguration.flushConfig(); }); diff --git a/lib/utils/ip.dart b/lib/utils/ip.dart index 18710be..a687275 100644 --- a/lib/utils/ip.dart +++ b/lib/utils/ip.dart @@ -26,7 +26,10 @@ Future localIp({bool readCache = true}) async { Future localAddress() async { return await NetworkInterface.list(type: InternetAddressType.IPv4).then((interfaces) { - return interfaces.firstWhere(primary, orElse: () => interfaces.first).addresses.first; + interfaces.sort((a, b) { + return weight(a) - weight(b); + }); + return interfaces.first.addresses.first; }); } @@ -40,10 +43,7 @@ Future> localIps() async { var list = await NetworkInterface.list(type: InternetAddressType.IPv4); list.sort((a, b) { - if (primary(a)) { - return -1; - } - return 1; + return weight(a) - weight(b); }); ipList = []; @@ -56,11 +56,24 @@ Future> localIps() async { } Future networkName() { - return NetworkInterface.list(type: InternetAddressType.IPv4) - .then((interfaces) => interfaces.firstWhere(primary, orElse: () => interfaces.first).name); + return NetworkInterface.list(type: InternetAddressType.IPv4).then((interfaces) { + interfaces.sort((a, b) { + return weight(a) - weight(b); + }); + return interfaces.first.name; + }); } // en0(macos系统) or WLAN(widows设备名)优先 -bool primary(NetworkInterface it) { - return it.name == 'en0' || it.name.startsWith('WLAN') || it.name.startsWith("wlan") || it.name.startsWith('ccmn'); +int weight(NetworkInterface it) { + if (it.name.toUpperCase().startsWith('WLAN')) { + return -10; + } + if (it.name == 'en0') { + return -1; + } + if (it.name.startsWith('ccmn')) { + return 0; + } + return 1; } diff --git a/linux/build.sh b/linux/build.sh index 451310e..bc4a262 100644 --- a/linux/build.sh +++ b/linux/build.sh @@ -5,7 +5,7 @@ cd ../build/linux/x64/release rm -rf package mkdir -p package/DEBIAN echo "Package: ProxyPin" >> package/DEBIAN/control -echo "Version: 1.1.2" >> package/DEBIAN/control +echo "Version: 1.1.3" >> package/DEBIAN/control echo "Priority: optional" >> package/DEBIAN/control echo "Architecture: amd64" >> package/DEBIAN/control echo "Depends: ca-certificates" >> package/DEBIAN/control