Skip to content

Commit

Permalink
feat(iOS): support rule match
Browse files Browse the repository at this point in the history
  • Loading branch information
linaaaqi committed Apr 21, 2023
1 parent 5e3505a commit e91c6e1
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 25 deletions.
File renamed without changes.
18 changes: 11 additions & 7 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
3EA6B289293FA83E00B2BABC /* libleaf.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3EA6B288293FA83000B2BABC /* libleaf.a */; };
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
7A31DD8228420C0B00E82EE1 /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2FD21EF825A363AA00F556E0 /* NetworkExtension.framework */; };
7AF7727F29F27CEF003033FB /* site.dat in Resources */ = {isa = PBXBuildFile; fileRef = 7AF7727E29F27CEF003033FB /* site.dat */; };
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
Expand Down Expand Up @@ -94,6 +95,7 @@
4A9C0075B77637136AF52D8B /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7AF7727E29F27CEF003033FB /* site.dat */ = {isa = PBXFileReference; lastKnownFileType = file; path = site.dat; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
7F9A79C99E6BB92BFA8F918D /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
8B949A6E3580C410A6129430 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -134,6 +136,7 @@
2FD21F0F25A363E300F556E0 /* PacketTunnel */ = {
isa = PBXGroup;
children = (
2FD21F1025A363E300F556E0 /* PacketTunnelProvider.swift */,
2FD21F1225A363E300F556E0 /* Info.plist */,
2FD21F1325A363E300F556E0 /* PacketTunnel.entitlements */,
);
Expand All @@ -160,8 +163,8 @@
3EA6B27D293F699400B2BABC /* Shared */ = {
isa = PBXGroup;
children = (
7AF7727E29F27CEF003033FB /* site.dat */,
3E06F988293FAFC600E04D92 /* LeafAdapter.swift */,
2FD21F1025A363E300F556E0 /* PacketTunnelProvider.swift */,
3EA6B272293F183000B2BABC /* Helpers */,
2F50954A25A36FD0001A32D5 /* VPNManager.swift */,
3EA6B279293F1FAD00B2BABC /* Logger.swift */,
Expand Down Expand Up @@ -328,6 +331,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7AF7727F29F27CEF003033FB /* site.dat in Resources */,
3EA6B276293F1AC500B2BABC /* template.conf in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -542,7 +546,7 @@
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = 95WRM2QC52;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -586,7 +590,7 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = PacketTunnel/PacketTunnel.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = 95WRM2QC52;
ENABLE_BITCODE = NO;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "i386 arm64";
Expand Down Expand Up @@ -632,7 +636,7 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = PacketTunnel/PacketTunnel.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = 95WRM2QC52;
ENABLE_BITCODE = NO;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "i386 arm64";
Expand Down Expand Up @@ -675,7 +679,7 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = PacketTunnel/PacketTunnel.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = 95WRM2QC52;
ENABLE_BITCODE = NO;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "i386 arm64";
Expand Down Expand Up @@ -829,7 +833,7 @@
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = 95WRM2QC52;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -872,7 +876,7 @@
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = 95WRM2QC52;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down
6 changes: 5 additions & 1 deletion ios/Shared/Helpers/FileManager+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

extension FileManager {
static var appGroupId = "group.com.sail-tunnel.sail"

private var sharedFolderURL: URL? {
let appGroupId = FileManager.appGroupId
guard let sharedFolderURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupId) else {
Expand All @@ -34,4 +34,8 @@ extension FileManager {
var leafConfTemplateFile: URL? {
Bundle.main.url(forResource: "template", withExtension: "conf")
}

var leafSiteDataFile: URL? {
Bundle.main.url(forResource: "site", withExtension: "dat", subdirectory: "Shared")
}
}
2 changes: 1 addition & 1 deletion ios/Shared/LeafAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public class LeafAdapater {

setenv("LOG_NO_COLOR", "true", 1)

leaf_run(LeafAdapater.leafId, file?.path)
leaf_run_with_options(LeafAdapater.leafId, file?.path, true, true, true, 8, 1024 * 32)

self.state = .started
self.networkMonitor = networkMonitor
Expand Down
File renamed without changes.
48 changes: 32 additions & 16 deletions lib/models/app_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@ class AppModel extends BaseModel {
tunFd: '{{tunFd}}',
routingDomainResolve: true);

List<Proxy> proxies = [];

proxies.add(Proxy(tag: 'Direct', protocol: 'direct'));
proxies.add(Proxy(tag: 'Reject', protocol: 'reject'));

List<Rule> rules = [];
// rules.add(Rule(typeField: 'EXTERNAL', target: 'Direct', filter: 'site:cn'));

rules.add(Rule(typeField: 'EXTERNAL', target: 'Direct', filter: 'site:geolocation-!cn'));
rules.add(Rule(typeField: 'EXTERNAL', target: 'Direct', filter: 'site:cn'));
rules.add(Rule(typeField: 'FINAL', target: 'Direct'));

config.general = general;
config.proxies = proxies;
config.rules = rules;
}

Expand Down Expand Up @@ -123,7 +131,7 @@ class AppModel extends BaseModel {
}

void setConfigProxies(UserModel userModel, ServerModel serverModel) async {
List<Proxy> proxies = [];
List<Proxy> proxies = config.proxies!;
List<ProxyGroup> proxyGroups = [];
List<String> actors = [];

Expand All @@ -145,8 +153,14 @@ class AppModel extends BaseModel {
protocol: 'url-test',
actors: actors,
checkInterval: 600));
}

config.rules?.last.target = "UrlTest";
if (serverModel.selectServerEntity != null) {
config.rules?.first.target = serverModel.selectServerEntity!.name;
} else if (proxyGroups.isNotEmpty) {
config.rules?.first.target = 'UrlTest';
} else {
config.rules?.first.target = 'Direct';
}

config.proxies = proxies;
Expand All @@ -160,18 +174,20 @@ class AppModel extends BaseModel {
}

void setConfigRule(String tag) async {
// var proxy = config.proxies?.where((proxies) => proxies.tag == tag);
//
// if (proxy == null || proxy.isEmpty) {
// return;
// }
//
// config.rules?.last.target = tag;
//
// print("-----------------config-----------------");
// print(config);
// print("-----------------config-----------------");
//
// vpnManager.setTunnelConfiguration(config.toString());
var proxy = config.proxies?.where((proxies) => proxies.tag == tag);
print("proxy: $proxy");

if (proxy == null || proxy.isEmpty) {
// TODO: 弹窗提示
return;
}

config.rules?.first.target = tag;

print("-----------------config-----------------");
print(config);
print("-----------------config-----------------");

vpnManager.setTunnelConfiguration(config.toString());
}
}

0 comments on commit e91c6e1

Please sign in to comment.