From 1646405e76bb09469bcfc11fb5bca852c28b066e Mon Sep 17 00:00:00 2001 From: wanghongen Date: Mon, 17 Jul 2023 16:45:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=BB=98=E8=AE=A4=E7=AB=AF?= =?UTF-8?q?=E5=8F=A3=E5=8F=B7=EF=BC=8Cpc=E6=A0=B9=E8=AF=81=E4=B9=A6?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E7=AE=80=E5=8C=96=EF=BC=8C=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=AD=A5=E9=AA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- lib/network/bin/server.dart | 2 +- lib/network/handler.dart | 11 ++-- lib/ui/desktop/toolbar/ssl/ssl.dart | 60 ++++++++++------- lib/utils/ip.dart | 3 +- linux/flutter/generated_plugin_registrant.cc | 4 -- linux/flutter/generated_plugins.cmake | 1 - macos/Flutter/GeneratedPluginRegistrant.swift | 2 - pubspec.lock | 64 ------------------- pubspec.yaml | 1 - .../flutter/generated_plugin_registrant.cc | 3 - windows/flutter/generated_plugins.cmake | 1 - 12 files changed, 46 insertions(+), 108 deletions(-) diff --git a/README.md b/README.md index 7d755b3..2673dda 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ **Mac首次打开会提示已损坏,需要到系统偏好设置-安全性与隐私-允许任何来源。** -国内下载地址:https://gitee.com/wanghongenpin/network-proxy-flutter/releases/tag/0.0.1 +国内下载地址:https://gitee.com/wanghongenpin/network-proxy-flutter/releases > ios个人开发者账号用到VPN没法上架AppStore, 后面可能会上架美版AppStore。 diff --git a/lib/network/bin/server.dart b/lib/network/bin/server.dart index fde9db2..9c43c46 100644 --- a/lib/network/bin/server.dart +++ b/lib/network/bin/server.dart @@ -20,7 +20,7 @@ Future main() async { /// 代理服务器 class ProxyServer { bool init = false; - int port = 6666; + int port = 9099; bool _enableSsl = false; bool enableDesktop = true; diff --git a/lib/network/handler.dart b/lib/network/handler.dart index 114ea98..0c24a2e 100644 --- a/lib/network/handler.dart +++ b/lib/network/handler.dart @@ -39,17 +39,18 @@ class HttpChannelHandler extends ChannelHandler { @override void channelRead(Channel channel, HttpRequest msg) async { channel.putAttribute(AttributeKeys.request, msg); - //请求本服务 - if ((await localIp()) == msg.hostAndPort?.host) { - localRequest(msg, channel); - return; - } if (msg.uri == 'http://proxy.pin/ssl' || msg.requestUrl == 'http://127.0.0.1:${channel.socket.port}/ssl') { _crtDownload(channel, msg); return; } + //请求本服务 + if ((await localIp()) == msg.hostAndPort?.host) { + localRequest(msg, channel); + return; + } + //转发请求 forward(channel, msg).catchError((error, trace) { channel.close(); diff --git a/lib/ui/desktop/toolbar/ssl/ssl.dart b/lib/ui/desktop/toolbar/ssl/ssl.dart index 1d0934c..cc1d019 100644 --- a/lib/ui/desktop/toolbar/ssl/ssl.dart +++ b/lib/ui/desktop/toolbar/ssl/ssl.dart @@ -1,10 +1,11 @@ import 'dart:io'; -import 'package:file_selector/file_selector.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:network_proxy/network/bin/server.dart'; import 'package:network_proxy/utils/ip.dart'; +import 'package:path_provider/path_provider.dart'; +import 'package:url_launcher/url_launcher.dart'; class SslWidget extends StatefulWidget { final ProxyServer proxyServer; @@ -82,20 +83,27 @@ class _SslState extends State { title: const Text("电脑HTTPS抓包配置", style: TextStyle(fontSize: 16)), alignment: Alignment.center, children: [ - const Text("1. 下载根证书安装到本系统(已完成忽略)"), - FilledButton(onPressed: () => _downloadCert(), child: const Text("下载证书")), + Text( + " 安装证书到本系统,${Platform.isMacOS ? "“安装完选择“始终信任此证书”" : "选择“受信任的根证书颁发机构”"}"), const SizedBox(height: 10), - Text("2. 双击安装证书,${Platform.isMacOS ? "“Mac安装完选择“始终信任此证书”" : "Windows选择“受信任的根证书颁发机构”"}"), + FilledButton( + onPressed: _installCert, child: const Text("安装证书")), const SizedBox(height: 10), Platform.isMacOS - ? Image.network("https://foruda.gitee.com/images/1689323260158189316/c2d881a4_1073801.png", - width: 800, height: 500) + ? Image.network( + "https://foruda.gitee.com/images/1689323260158189316/c2d881a4_1073801.png", + width: 800, + height: 500) : Row(children: [ - Image.network("https://foruda.gitee.com/images/1689335589122168223/c904a543_1073801.png", - width: 400, height: 400), + Image.network( + "https://foruda.gitee.com/images/1689335589122168223/c904a543_1073801.png", + width: 400, + height: 400), const SizedBox(width: 10), - Image.network("https://foruda.gitee.com/images/1689335334688878324/f6aa3a3a_1073801.png", - width: 400, height: 400) + Image.network( + "https://foruda.gitee.com/images/1689335334688878324/f6aa3a3a_1073801.png", + width: 400, + height: 400) ]) ]); }); @@ -112,34 +120,36 @@ class _SslState extends State { children: [ const Text("1. 根证书安装到本系统(已完成忽略)"), const SizedBox(height: 10), - SelectableText.rich(TextSpan(text: "2. 配置手机Wifi代理 Host:$host Port:${widget.proxyServer.port}")), + SelectableText.rich(TextSpan( + text: + "2. 配置手机Wifi代理 Host:$host Port:${widget.proxyServer.port}")), const SizedBox(height: 10), const Row( children: [ Text("3. 打开手机系统自带浏览器访问:\t"), - SelectableText.rich( - TextSpan(text: "http://proxy.pin/ssl", style: TextStyle(decoration: TextDecoration.underline))) + SelectableText.rich(TextSpan( + text: "http://proxy.pin/ssl", + style: TextStyle(decoration: TextDecoration.underline))) ], ), const SizedBox(height: 10), const Text("4. 打开手机设置下载安装证书信任证书\n\t 设置 > 通用 > 关于本机 > 证书信任设置"), const SizedBox(height: 20), - const Text(" 抓微信小程序ios需要开启本地网络权限", style: TextStyle(fontWeight: FontWeight.bold)), + const Text(" 抓微信小程序ios需要开启本地网络权限", + style: TextStyle(fontWeight: FontWeight.bold)), ]); }); } - void _downloadCert() async { - final FileSaveLocation? location = await getSaveLocation(suggestedName: "ProxyPinCA.crt"); - if (location != null) { - const String fileMimeType = 'application/x-x509-ca-cert'; + void _installCert() async { + final String appPath = + await getApplicationSupportDirectory().then((value) => value.path); + var caFile = File("$appPath${Platform.pathSeparator}ProxyPinCA.crt"); + if (!(await caFile.exists())) { var body = await rootBundle.load('assets/certs/ca.crt'); - final XFile xFile = XFile.fromData( - body.buffer.asUint8List(), - mimeType: fileMimeType, - ); - await xFile.saveTo(location.path); + await caFile.writeAsBytes(body.buffer.asUint8List()); } + launchUrl(Uri.file(caFile.path)); } } @@ -147,7 +157,9 @@ class _Switch extends StatefulWidget { final ProxyServer proxyServer; final Function(bool val) onEnableChange; - const _Switch({Key? key, required this.proxyServer, required this.onEnableChange}) : super(key: key); + const _Switch( + {Key? key, required this.proxyServer, required this.onEnableChange}) + : super(key: key); @override State<_Switch> createState() => _SwitchState(); diff --git a/lib/utils/ip.dart b/lib/utils/ip.dart index e3154c9..21f25f9 100644 --- a/lib/utils/ip.dart +++ b/lib/utils/ip.dart @@ -15,7 +15,8 @@ String? ip; Future localIp() async { ip ??= await NetworkInterface.list().then((interfaces) { - return interfaces.firstWhere((it) => it.name == "en0", orElse: () => interfaces.first).addresses.first.address; + return interfaces.firstWhere((it) => it.name == "en0" || it.name == 'WLAN', + orElse: () => interfaces.first).addresses.first.address; }); return ip!; } diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 6139551..e332053 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,16 +6,12 @@ #include "generated_plugin_registrant.h" -#include #include #include #include #include void fl_register_plugins(FlPluginRegistry* registry) { - g_autoptr(FlPluginRegistrar) file_selector_linux_registrar = - fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin"); - file_selector_plugin_register_with_registrar(file_selector_linux_registrar); g_autoptr(FlPluginRegistrar) proxy_manager_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "ProxyManagerPlugin"); proxy_manager_plugin_register_with_registrar(proxy_manager_registrar); diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 6fb4385..7b363ea 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,7 +3,6 @@ # list(APPEND FLUTTER_PLUGIN_LIST - file_selector_linux proxy_manager screen_retriever url_launcher_linux diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 735e101..9f7137c 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,7 +5,6 @@ import FlutterMacOS import Foundation -import file_selector_macos import path_provider_foundation import proxy_manager import screen_retriever @@ -15,7 +14,6 @@ import url_launcher_macos import window_manager func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { - FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) ProxyManagerPlugin.register(with: registry.registrar(forPlugin: "ProxyManagerPlugin")) ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin")) diff --git a/pubspec.lock b/pubspec.lock index 96319c4..b2399a6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -153,70 +153,6 @@ packages: url: "https://pub.dev" source: hosted version: "7.0.0" - file_selector: - dependency: "direct main" - description: - name: file_selector - sha256: "59b35aa4af7988be7ec88f9ddaa6c71c5b54bf0f8b35009389d9343b10e9c3af" - url: "https://pub.dev" - source: hosted - version: "1.0.0" - file_selector_android: - dependency: transitive - description: - name: file_selector_android - sha256: "59e694afad4609d689185a608958c85fbccb3e6feab12a6b8c95a2c0f90ad2f7" - url: "https://pub.dev" - source: hosted - version: "0.5.0+1" - file_selector_ios: - dependency: transitive - description: - name: file_selector_ios - sha256: "54542b6b35e3ced6246df5fae13cf0b879d14669d0fdff1a53a098f16e23328b" - url: "https://pub.dev" - source: hosted - version: "0.5.1+4" - file_selector_linux: - dependency: transitive - description: - name: file_selector_linux - sha256: "770eb1ab057b5ae4326d1c24cc57710758b9a46026349d021d6311bd27580046" - url: "https://pub.dev" - source: hosted - version: "0.9.2" - file_selector_macos: - dependency: transitive - description: - name: file_selector_macos - sha256: "4ada532862917bf16e3adb3891fe3a5917a58bae03293e497082203a80909412" - url: "https://pub.dev" - source: hosted - version: "0.9.3+1" - file_selector_platform_interface: - dependency: transitive - description: - name: file_selector_platform_interface - sha256: "412705a646a0ae90f33f37acfae6a0f7cbc02222d6cd34e479421c3e74d3853c" - url: "https://pub.dev" - source: hosted - version: "2.6.0" - file_selector_web: - dependency: transitive - description: - name: file_selector_web - sha256: e292740c469df0aeeaba0895bf622bea351a05e87d22864c826bf21c4780e1d7 - url: "https://pub.dev" - source: hosted - version: "0.9.2" - file_selector_windows: - dependency: transitive - description: - name: file_selector_windows - sha256: "1372760c6b389842b77156203308940558a2817360154084368608413835fc26" - url: "https://pub.dev" - source: hosted - version: "0.9.3" flutter: dependency: "direct main" description: flutter diff --git a/pubspec.yaml b/pubspec.yaml index af7bb3a..26069e4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,7 +14,6 @@ dependencies: basic_utils: logger: ^1.4.0 date_format: ^2.0.7 - file_selector: ^1.0.0 window_manager: ^0.3.5 path_provider: ^2.0.15 url_launcher: ^6.1.11 diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 8f5f695..8223173 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,7 +6,6 @@ #include "generated_plugin_registrant.h" -#include #include #include #include @@ -14,8 +13,6 @@ #include void RegisterPlugins(flutter::PluginRegistry* registry) { - FileSelectorWindowsRegisterWithRegistrar( - registry->GetRegistrarForPlugin("FileSelectorWindows")); ProxyManagerPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("ProxyManagerPlugin")); ScreenRetrieverPluginRegisterWithRegistrar( diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index d769193..6c36c83 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,7 +3,6 @@ # list(APPEND FLUTTER_PLUGIN_LIST - file_selector_windows proxy_manager screen_retriever share_plus