Feature: rewrite proxyconfig using objc

This commit is contained in:
yicheng 2019-04-08 15:10:30 +08:00 committed by Yicheng
parent b66ce2500f
commit 6c84cf30ba
7 changed files with 335 additions and 230 deletions

View File

@ -41,6 +41,7 @@
4989F98E20D0AE990001E564 /* sampleConfig.yml in Resources */ = {isa = PBXBuildFile; fileRef = 4989F98D20D0AE990001E564 /* sampleConfig.yml */; }; 4989F98E20D0AE990001E564 /* sampleConfig.yml in Resources */ = {isa = PBXBuildFile; fileRef = 4989F98D20D0AE990001E564 /* sampleConfig.yml */; };
4997732520D251A60009B136 /* SWBApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = 4997732320D251A60009B136 /* SWBApplication.m */; }; 4997732520D251A60009B136 /* SWBApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = 4997732320D251A60009B136 /* SWBApplication.m */; };
499976C821359F0400E7BF83 /* ClashWebViewContoller.swift in Sources */ = {isa = PBXBuildFile; fileRef = 499976C721359F0400E7BF83 /* ClashWebViewContoller.swift */; }; 499976C821359F0400E7BF83 /* ClashWebViewContoller.swift in Sources */ = {isa = PBXBuildFile; fileRef = 499976C721359F0400E7BF83 /* ClashWebViewContoller.swift */; };
49AF9104225B2B03004CC077 /* ProxyConfig in CopyFiles */ = {isa = PBXBuildFile; fileRef = 49AF9103225B2A96004CC077 /* ProxyConfig */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
49B1086A216A356D0064FFCE /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49B10869216A356D0064FFCE /* String+Extension.swift */; }; 49B1086A216A356D0064FFCE /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49B10869216A356D0064FFCE /* String+Extension.swift */; };
49BC061C212931F4005A0FE7 /* AboutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49BC061B212931F4005A0FE7 /* AboutViewController.swift */; }; 49BC061C212931F4005A0FE7 /* AboutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49BC061B212931F4005A0FE7 /* AboutViewController.swift */; };
49C9EF64223E78F5005D8B6A /* ClashProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49C9EF63223E78F5005D8B6A /* ClashProxy.swift */; }; 49C9EF64223E78F5005D8B6A /* ClashProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49C9EF63223E78F5005D8B6A /* ClashProxy.swift */; };
@ -52,17 +53,9 @@
49CF3B6320CED9CF001EBF94 /* check_proxy_helper.sh in Resources */ = {isa = PBXBuildFile; fileRef = 49CF3B6220CED934001EBF94 /* check_proxy_helper.sh */; }; 49CF3B6320CED9CF001EBF94 /* check_proxy_helper.sh in Resources */ = {isa = PBXBuildFile; fileRef = 49CF3B6220CED934001EBF94 /* check_proxy_helper.sh */; };
49CF3B6520CEE06C001EBF94 /* ConfigManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49CF3B6420CEE06C001EBF94 /* ConfigManager.swift */; }; 49CF3B6520CEE06C001EBF94 /* ConfigManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49CF3B6420CEE06C001EBF94 /* ConfigManager.swift */; };
49E07A8C20D501A000A088A3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 49E07A8920D501A000A088A3 /* Main.storyboard */; }; 49E07A8C20D501A000A088A3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 49E07A8920D501A000A088A3 /* Main.storyboard */; };
663E4678213FCDCD006F11BB /* ProxyConfig in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4949D15B213260BD00EF85E6 /* ProxyConfig */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
4949D15A213260BD00EF85E6 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 49CF3B4B20CE5232001EBF94 /* ProxyConfig.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 36B6A3231E263590002B5B1D;
remoteInfo = ProxyConfig;
};
495A44CE20D2671F00888A0A /* PBXContainerItemProxy */ = { 495A44CE20D2671F00888A0A /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy; isa = PBXContainerItemProxy;
containerPortal = 49CF3B1520CD7463001EBF94 /* Project object */; containerPortal = 49CF3B1520CD7463001EBF94 /* Project object */;
@ -70,11 +63,11 @@
remoteGlobalIDString = 495A44BB20D2660A00888A0A; remoteGlobalIDString = 495A44BB20D2660A00888A0A;
remoteInfo = ClashXLaunchHelper; remoteInfo = ClashXLaunchHelper;
}; };
663E4674213FCD50006F11BB /* PBXContainerItemProxy */ = { 49AF9102225B2A96004CC077 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy; isa = PBXContainerItemProxy;
containerPortal = 49CF3B4B20CE5232001EBF94 /* ProxyConfig.xcodeproj */; containerPortal = 49AF90FE225B2A95004CC077 /* ProxyConfig.xcodeproj */;
proxyType = 1; proxyType = 2;
remoteGlobalIDString = 36B6A3221E263590002B5B1D; remoteGlobalIDString = 49AF90F3225B17D2004CC077;
remoteInfo = ProxyConfig; remoteInfo = ProxyConfig;
}; };
/* End PBXContainerItemProxy section */ /* End PBXContainerItemProxy section */
@ -96,7 +89,7 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 7; dstSubfolderSpec = 7;
files = ( files = (
663E4678213FCDCD006F11BB /* ProxyConfig in CopyFiles */, 49AF9104225B2B03004CC077 /* ProxyConfig in CopyFiles */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -146,6 +139,7 @@
4997732320D251A60009B136 /* SWBApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWBApplication.m; sourceTree = "<group>"; }; 4997732320D251A60009B136 /* SWBApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWBApplication.m; sourceTree = "<group>"; };
4997732420D251A60009B136 /* SWBApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWBApplication.h; sourceTree = "<group>"; }; 4997732420D251A60009B136 /* SWBApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWBApplication.h; sourceTree = "<group>"; };
499976C721359F0400E7BF83 /* ClashWebViewContoller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClashWebViewContoller.swift; sourceTree = "<group>"; }; 499976C721359F0400E7BF83 /* ClashWebViewContoller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClashWebViewContoller.swift; sourceTree = "<group>"; };
49AF90FE225B2A95004CC077 /* ProxyConfig.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ProxyConfig.xcodeproj; path = ProxyConfig/ProxyConfig.xcodeproj; sourceTree = "<group>"; };
49B10869216A356D0064FFCE /* String+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extension.swift"; sourceTree = "<group>"; }; 49B10869216A356D0064FFCE /* String+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extension.swift"; sourceTree = "<group>"; };
49BC061B212931F4005A0FE7 /* AboutViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutViewController.swift; sourceTree = "<group>"; }; 49BC061B212931F4005A0FE7 /* AboutViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutViewController.swift; sourceTree = "<group>"; };
49C9EF63223E78F5005D8B6A /* ClashProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClashProxy.swift; sourceTree = "<group>"; }; 49C9EF63223E78F5005D8B6A /* ClashProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClashProxy.swift; sourceTree = "<group>"; };
@ -156,7 +150,6 @@
49CF3B2920CD7465001EBF94 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 49CF3B2920CD7465001EBF94 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
49CF3B2A20CD7465001EBF94 /* ClashX.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = ClashX.entitlements; sourceTree = "<group>"; }; 49CF3B2A20CD7465001EBF94 /* ClashX.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = ClashX.entitlements; sourceTree = "<group>"; };
49CF3B3520CD75DF001EBF94 /* ClashX-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ClashX-Bridging-Header.h"; sourceTree = "<group>"; }; 49CF3B3520CD75DF001EBF94 /* ClashX-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ClashX-Bridging-Header.h"; sourceTree = "<group>"; };
49CF3B4B20CE5232001EBF94 /* ProxyConfig.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ProxyConfig.xcodeproj; path = ProxyConfig/ProxyConfig.xcodeproj; sourceTree = "<group>"; };
49CF3B5B20CE8068001EBF94 /* ProxyConfigHelperManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProxyConfigHelperManager.swift; sourceTree = "<group>"; }; 49CF3B5B20CE8068001EBF94 /* ProxyConfigHelperManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProxyConfigHelperManager.swift; sourceTree = "<group>"; };
49CF3B5E20CE80D2001EBF94 /* install_proxy_helper.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = install_proxy_helper.sh; sourceTree = "<group>"; }; 49CF3B5E20CE80D2001EBF94 /* install_proxy_helper.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = install_proxy_helper.sh; sourceTree = "<group>"; };
49CF3B6220CED934001EBF94 /* check_proxy_helper.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = check_proxy_helper.sh; sourceTree = "<group>"; }; 49CF3B6220CED934001EBF94 /* check_proxy_helper.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = check_proxy_helper.sh; sourceTree = "<group>"; };
@ -254,14 +247,6 @@
path = Views; path = Views;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
4949D157213260BD00EF85E6 /* Products */ = {
isa = PBXGroup;
children = (
4949D15B213260BD00EF85E6 /* ProxyConfig */,
);
name = Products;
sourceTree = "<group>";
};
495A44BD20D2660A00888A0A /* ClashXLaunchHelper */ = { 495A44BD20D2660A00888A0A /* ClashXLaunchHelper */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -326,6 +311,14 @@
path = Basic; path = Basic;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
49AF90FF225B2A95004CC077 /* Products */ = {
isa = PBXGroup;
children = (
49AF9103225B2A96004CC077 /* ProxyConfig */,
);
name = Products;
sourceTree = "<group>";
};
49CF3B1420CD7463001EBF94 = { 49CF3B1420CD7463001EBF94 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -359,8 +352,8 @@
4931969C21631F2E00A8E6E7 /* Views */, 4931969C21631F2E00A8E6E7 /* Views */,
4989F98520D0AA300001E564 /* ViewControllers */, 4989F98520D0AA300001E564 /* ViewControllers */,
49761DA521C9490400AE13EF /* Resources */, 49761DA521C9490400AE13EF /* Resources */,
49CF3B4B20CE5232001EBF94 /* ProxyConfig.xcodeproj */,
49CF3B3A20CD783A001EBF94 /* Support Files */, 49CF3B3A20CD783A001EBF94 /* Support Files */,
49AF90FE225B2A95004CC077 /* ProxyConfig.xcodeproj */,
49CF3B2020CD7463001EBF94 /* AppDelegate.swift */, 49CF3B2020CD7463001EBF94 /* AppDelegate.swift */,
49CF3B2420CD7465001EBF94 /* Assets.xcassets */, 49CF3B2420CD7465001EBF94 /* Assets.xcassets */,
497F0DF220DE2FE50077AD41 /* Icon.icns */, 497F0DF220DE2FE50077AD41 /* Icon.icns */,
@ -446,7 +439,6 @@
buildRules = ( buildRules = (
); );
dependencies = ( dependencies = (
663E4675213FCD50006F11BB /* PBXTargetDependency */,
495A44CF20D2671F00888A0A /* PBXTargetDependency */, 495A44CF20D2671F00888A0A /* PBXTargetDependency */,
); );
name = ClashX; name = ClashX;
@ -502,8 +494,8 @@
projectDirPath = ""; projectDirPath = "";
projectReferences = ( projectReferences = (
{ {
ProductGroup = 4949D157213260BD00EF85E6 /* Products */; ProductGroup = 49AF90FF225B2A95004CC077 /* Products */;
ProjectRef = 49CF3B4B20CE5232001EBF94 /* ProxyConfig.xcodeproj */; ProjectRef = 49AF90FE225B2A95004CC077 /* ProxyConfig.xcodeproj */;
}, },
); );
projectRoot = ""; projectRoot = "";
@ -515,11 +507,11 @@
/* End PBXProject section */ /* End PBXProject section */
/* Begin PBXReferenceProxy section */ /* Begin PBXReferenceProxy section */
4949D15B213260BD00EF85E6 /* ProxyConfig */ = { 49AF9103225B2A96004CC077 /* ProxyConfig */ = {
isa = PBXReferenceProxy; isa = PBXReferenceProxy;
fileType = "compiled.mach-o.executable"; fileType = "compiled.mach-o.executable";
path = ProxyConfig; path = ProxyConfig;
remoteRef = 4949D15A213260BD00EF85E6 /* PBXContainerItemProxy */; remoteRef = 49AF9102225B2A96004CC077 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR; sourceTree = BUILT_PRODUCTS_DIR;
}; };
/* End PBXReferenceProxy section */ /* End PBXReferenceProxy section */
@ -679,11 +671,6 @@
target = 495A44BB20D2660A00888A0A /* ClashXLaunchHelper */; target = 495A44BB20D2660A00888A0A /* ClashXLaunchHelper */;
targetProxy = 495A44CE20D2671F00888A0A /* PBXContainerItemProxy */; targetProxy = 495A44CE20D2671F00888A0A /* PBXContainerItemProxy */;
}; };
663E4675213FCD50006F11BB /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
name = ProxyConfig;
targetProxy = 663E4674213FCD50006F11BB /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */ /* End PBXTargetDependency section */
/* Begin PBXVariantGroup section */ /* Begin PBXVariantGroup section */

129
ClashX/ProxyConfig/ProxyConfig.xcodeproj/project.pbxproj Executable file → Normal file
View File

@ -3,15 +3,15 @@
archiveVersion = 1; archiveVersion = 1;
classes = { classes = {
}; };
objectVersion = 46; objectVersion = 50;
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
36B6A3271E263590002B5B1D /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36B6A3261E263590002B5B1D /* main.swift */; }; 49AF90F7225B17D2004CC077 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 49AF90F6225B17D2004CC077 /* main.m */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */ /* Begin PBXCopyFilesBuildPhase section */
36B6A3211E263590002B5B1D /* CopyFiles */ = { 49AF90F1225B17D2004CC077 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase; isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
dstPath = /usr/share/man/man1/; dstPath = /usr/share/man/man1/;
@ -23,12 +23,12 @@
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
36B6A3231E263590002B5B1D /* ProxyConfig */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ProxyConfig; sourceTree = BUILT_PRODUCTS_DIR; }; 49AF90F3225B17D2004CC077 /* ProxyConfig */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ProxyConfig; sourceTree = BUILT_PRODUCTS_DIR; };
36B6A3261E263590002B5B1D /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; }; 49AF90F6225B17D2004CC077 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
36B6A3201E263590002B5B1D /* Frameworks */ = { 49AF90F0225B17D2004CC077 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
@ -38,26 +38,26 @@
/* End PBXFrameworksBuildPhase section */ /* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */ /* Begin PBXGroup section */
36B6A31A1E263590002B5B1D = { 49AF90EA225B17D2004CC077 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
36B6A3251E263590002B5B1D /* ProxyConfig */, 49AF90F5225B17D2004CC077 /* ProxyConfig */,
36B6A3241E263590002B5B1D /* Products */, 49AF90F4225B17D2004CC077 /* Products */,
); );
sourceTree = "<group>"; sourceTree = "<group>";
}; };
36B6A3241E263590002B5B1D /* Products */ = { 49AF90F4225B17D2004CC077 /* Products */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
36B6A3231E263590002B5B1D /* ProxyConfig */, 49AF90F3225B17D2004CC077 /* ProxyConfig */,
); );
name = Products; name = Products;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
36B6A3251E263590002B5B1D /* ProxyConfig */ = { 49AF90F5225B17D2004CC077 /* ProxyConfig */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
36B6A3261E263590002B5B1D /* main.swift */, 49AF90F6225B17D2004CC077 /* main.m */,
); );
path = ProxyConfig; path = ProxyConfig;
sourceTree = "<group>"; sourceTree = "<group>";
@ -65,13 +65,13 @@
/* End PBXGroup section */ /* End PBXGroup section */
/* Begin PBXNativeTarget section */ /* Begin PBXNativeTarget section */
36B6A3221E263590002B5B1D /* ProxyConfig */ = { 49AF90F2225B17D2004CC077 /* ProxyConfig */ = {
isa = PBXNativeTarget; isa = PBXNativeTarget;
buildConfigurationList = 36B6A32A1E263590002B5B1D /* Build configuration list for PBXNativeTarget "ProxyConfig" */; buildConfigurationList = 49AF90FA225B17D2004CC077 /* Build configuration list for PBXNativeTarget "ProxyConfig" */;
buildPhases = ( buildPhases = (
36B6A31F1E263590002B5B1D /* Sources */, 49AF90EF225B17D2004CC077 /* Sources */,
36B6A3201E263590002B5B1D /* Frameworks */, 49AF90F0225B17D2004CC077 /* Frameworks */,
36B6A3211E263590002B5B1D /* CopyFiles */, 49AF90F1225B17D2004CC077 /* CopyFiles */,
); );
buildRules = ( buildRules = (
); );
@ -79,65 +79,63 @@
); );
name = ProxyConfig; name = ProxyConfig;
productName = ProxyConfig; productName = ProxyConfig;
productReference = 36B6A3231E263590002B5B1D /* ProxyConfig */; productReference = 49AF90F3225B17D2004CC077 /* ProxyConfig */;
productType = "com.apple.product-type.tool"; productType = "com.apple.product-type.tool";
}; };
/* End PBXNativeTarget section */ /* End PBXNativeTarget section */
/* Begin PBXProject section */ /* Begin PBXProject section */
36B6A31B1E263590002B5B1D /* Project object */ = { 49AF90EB225B17D2004CC077 /* Project object */ = {
isa = PBXProject; isa = PBXProject;
attributes = { attributes = {
LastSwiftUpdateCheck = 0820; LastUpgradeCheck = 1020;
LastUpgradeCheck = 0940; ORGANIZATIONNAME = west2online;
ORGANIZATIONNAME = "Zhuhao Wang";
TargetAttributes = { TargetAttributes = {
36B6A3221E263590002B5B1D = { 49AF90F2225B17D2004CC077 = {
CreatedOnToolsVersion = 8.2.1; CreatedOnToolsVersion = 10.2;
LastSwiftMigration = 1020;
ProvisioningStyle = Manual;
}; };
}; };
}; };
buildConfigurationList = 36B6A31E1E263590002B5B1D /* Build configuration list for PBXProject "ProxyConfig" */; buildConfigurationList = 49AF90EE225B17D2004CC077 /* Build configuration list for PBXProject "ProxyConfig" */;
compatibilityVersion = "Xcode 3.2"; compatibilityVersion = "Xcode 9.3";
developmentRegion = English; developmentRegion = en;
hasScannedForEncodings = 0; hasScannedForEncodings = 0;
knownRegions = ( knownRegions = (
English,
en, en,
); );
mainGroup = 36B6A31A1E263590002B5B1D; mainGroup = 49AF90EA225B17D2004CC077;
productRefGroup = 36B6A3241E263590002B5B1D /* Products */; productRefGroup = 49AF90F4225B17D2004CC077 /* Products */;
projectDirPath = ""; projectDirPath = "";
projectRoot = ""; projectRoot = "";
targets = ( targets = (
36B6A3221E263590002B5B1D /* ProxyConfig */, 49AF90F2225B17D2004CC077 /* ProxyConfig */,
); );
}; };
/* End PBXProject section */ /* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */
36B6A31F1E263590002B5B1D /* Sources */ = { 49AF90EF225B17D2004CC077 /* Sources */ = {
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
36B6A3271E263590002B5B1D /* main.swift in Sources */, 49AF90F7225B17D2004CC077 /* main.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
/* End PBXSourcesBuildPhase section */ /* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */ /* Begin XCBuildConfiguration section */
36B6A3281E263590002B5B1D /* Debug */ = { 49AF90F8225B17D2004CC077 /* Debug */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++"; CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES; CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES; CLANG_WARN_COMMA = YES;
@ -156,14 +154,15 @@
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-"; CODE_SIGN_IDENTITY = "Mac Developer";
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf; DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES; ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO; GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES; GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0; GCC_OPTIMIZATION_LEVEL = 0;
@ -177,23 +176,25 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.12; MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = YES; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx; SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
}; };
name = Debug; name = Debug;
}; };
36B6A3291E263590002B5B1D /* Release */ = { 49AF90F9225B17D2004CC077 /* Release */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++"; CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES; CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES; CLANG_WARN_COMMA = YES;
@ -212,14 +213,15 @@
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-"; CODE_SIGN_IDENTITY = "Mac Developer";
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO; ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES; GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
@ -227,60 +229,59 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.12; MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = macosx; SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
}; };
name = Release; name = Release;
}; };
36B6A32B1E263590002B5B1D /* Debug */ = { 49AF90FB225B17D2004CC077 /* Debug */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual; CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = ""; DEVELOPMENT_TEAM = "";
MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
}; };
name = Debug; name = Debug;
}; };
36B6A32C1E263590002B5B1D /* Release */ = { 49AF90FC225B17D2004CC077 /* Release */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
CODE_SIGN_IDENTITY = "Developer ID Application"; CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual; CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = MEWHFZ92DY; DEVELOPMENT_TEAM = "";
MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
}; };
name = Release; name = Release;
}; };
/* End XCBuildConfiguration section */ /* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */ /* Begin XCConfigurationList section */
36B6A31E1E263590002B5B1D /* Build configuration list for PBXProject "ProxyConfig" */ = { 49AF90EE225B17D2004CC077 /* Build configuration list for PBXProject "ProxyConfig" */ = {
isa = XCConfigurationList; isa = XCConfigurationList;
buildConfigurations = ( buildConfigurations = (
36B6A3281E263590002B5B1D /* Debug */, 49AF90F8225B17D2004CC077 /* Debug */,
36B6A3291E263590002B5B1D /* Release */, 49AF90F9225B17D2004CC077 /* Release */,
); );
defaultConfigurationIsVisible = 0; defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release; defaultConfigurationName = Release;
}; };
36B6A32A1E263590002B5B1D /* Build configuration list for PBXNativeTarget "ProxyConfig" */ = { 49AF90FA225B17D2004CC077 /* Build configuration list for PBXNativeTarget "ProxyConfig" */ = {
isa = XCConfigurationList; isa = XCConfigurationList;
buildConfigurations = ( buildConfigurations = (
36B6A32B1E263590002B5B1D /* Debug */, 49AF90FB225B17D2004CC077 /* Debug */,
36B6A32C1E263590002B5B1D /* Release */, 49AF90FC225B17D2004CC077 /* Release */,
); );
defaultConfigurationIsVisible = 0; defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release; defaultConfigurationName = Release;
}; };
/* End XCConfigurationList section */ /* End XCConfigurationList section */
}; };
rootObject = 36B6A31B1E263590002B5B1D /* Project object */; rootObject = 49AF90EB225B17D2004CC077 /* Project object */;
} }

View File

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

View File

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "49AF90F2225B17D2004CC077"
BuildableName = "ProxyConfig"
BlueprintName = "ProxyConfig"
ReferencedContainer = "container:ProxyConfig.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "49AF90F2225B17D2004CC077"
BuildableName = "ProxyConfig"
BlueprintName = "ProxyConfig"
ReferencedContainer = "container:ProxyConfig.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "49AF90F2225B17D2004CC077"
BuildableName = "ProxyConfig"
BlueprintName = "ProxyConfig"
ReferencedContainer = "container:ProxyConfig.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "49AF90F2225B17D2004CC077"
BuildableName = "ProxyConfig"
BlueprintName = "ProxyConfig"
ReferencedContainer = "container:ProxyConfig.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -0,0 +1,151 @@
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
NSString const* version = @"0.1.3";
NSArray<NSString *>* getIgnoreList() {
NSString *configPath = [NSHomeDirectory() stringByAppendingString:@"/.config/clash/proxyIgnoreList.plist"];
if ([NSFileManager.defaultManager fileExistsAtPath:configPath]) {
NSArray *arr = [[NSArray alloc] initWithContentsOfFile:configPath];
if (arr != nil && arr.count > 0 && [arr containsObject:@"127.0.0.1"]) {
return arr;
}
}
NSArray *ignoreList = @[
@"192.168.0.0/16",
@"10.0.0.0/8",
@"172.16.0.0/12",
@"127.0.0.1",
@"localhost",
@"*.local",
@"*.crashlytics.com"
];
return ignoreList;
}
NSDictionary* getProxySetting(BOOL enable,
int port,
int socksPort){
NSMutableDictionary *proxySettings = [NSMutableDictionary dictionary];
NSString *ip = enable ? @"127.0.0.1" : @"";
NSInteger enableInt = enable ? 1 : 0;
proxySettings[(NSString *)kCFNetworkProxiesHTTPProxy] = ip;
proxySettings[(NSString *)kCFNetworkProxiesHTTPEnable] = @(enableInt);
proxySettings[(NSString *)kCFNetworkProxiesHTTPSProxy] = ip;
proxySettings[(NSString *)kCFNetworkProxiesHTTPSEnable] = @(enableInt);
proxySettings[(NSString *)kCFNetworkProxiesSOCKSProxy] = ip;
proxySettings[(NSString *)kCFNetworkProxiesSOCKSEnable] = @(enableInt);
if (enable) {
proxySettings[(NSString *)kCFNetworkProxiesHTTPPort] = @(port);
proxySettings[(NSString *)kCFNetworkProxiesHTTPSPort] = @(port);
proxySettings[(NSString *)kCFNetworkProxiesSOCKSPort] = @(socksPort);
} else {
proxySettings[(NSString *)kCFNetworkProxiesHTTPPort] = nil;
proxySettings[(NSString *)kCFNetworkProxiesHTTPSPort] = nil;
proxySettings[(NSString *)kCFNetworkProxiesSOCKSPort] = nil;
}
proxySettings[(NSString *)kCFNetworkProxiesExceptionsList] = getIgnoreList();
return proxySettings;
}
void updateProxySettings(SCPreferencesRef prefs,
NSString *interfaceKey,
BOOL enable,
int port,
int socksPort) {
NSDictionary *proxySettings = getProxySetting(enable, port, socksPort);
NSString *path = [NSString stringWithFormat:@"/%@/%@/%@",
(NSString *)kSCPrefNetworkServices,
interfaceKey,
(NSString *)kSCEntNetProxies];
SCPreferencesPathSetValue(prefs,
(__bridge CFStringRef)path,
(__bridge CFDictionaryRef)proxySettings);
}
NSArray<NSString *> *parseArgs(int argc, const char * argv[]) {
NSMutableArray *results = [NSMutableArray array];
for (int i = 0; i < argc; i++) {
NSString *str = [[NSString alloc] initWithCString:argv[i] encoding:NSUTF8StringEncoding];
[results addObject:str];
}
return results;
}
int main(int argc, const char * argv[]) {
int port = 0;
int socksPort = 0;
BOOL flag = NO;
NSArray *args = parseArgs(argc,argv);
if (args.count > 3) {
port = [args[1] intValue];
socksPort = [args[2] intValue];
if ([args[3] isEqualToString:@"enable"]) {
flag = YES;
} else if ([args[3] isEqualToString:@"disable"]) {
flag = NO;
} else {
printf("ERROR: flag is invalid.");
exit(EXIT_FAILURE);
}
} else if (args.count == 2 && [args[1] isEqualToString:@"version"]) {
printf("%s",[version UTF8String]);
exit(EXIT_SUCCESS);
} else {
printf("Usage: ProxyConfig <port> <socksPort> <enable/disable>");
exit(EXIT_FAILURE);
}
static AuthorizationRef authRef;
static AuthorizationFlags authFlags;
authFlags = kAuthorizationFlagDefaults
| kAuthorizationFlagExtendRights
| kAuthorizationFlagInteractionAllowed
| kAuthorizationFlagPreAuthorize;
OSStatus authErr = AuthorizationCreate(nil, kAuthorizationEmptyEnvironment, authFlags, &authRef);
if (authErr != noErr || authRef == NULL) {
authRef = nil;
printf("Error when create authorization");
exit(EXIT_FAILURE);
}
SCPreferencesRef prefRef = SCPreferencesCreateWithAuthorization(nil, CFSTR("ClashX"), nil, authRef);
NSDictionary *sets = (__bridge NSDictionary *)SCPreferencesGetValue(prefRef, kSCPrefNetworkServices);
if (!prefRef || ! sets) {
printf("Error: SCPreferencesGetValue fail");
AuthorizationFree(authRef, authFlags);
exit(EXIT_FAILURE);
}
for (NSString *key in [sets allKeys]) {
NSMutableDictionary *dict = [sets objectForKey:key];
NSString *hardware = [dict valueForKeyPath:@"Interface.Hardware"];
if ([hardware isEqualToString:@"AirPort"]
|| [hardware isEqualToString:@"Wi-Fi"]
|| [hardware isEqualToString:@"Ethernet"]) {
updateProxySettings(prefRef, key, flag, port, socksPort);
}
}
SCPreferencesCommitChanges(prefRef);
SCPreferencesApplyChanges(prefRef);
SCPreferencesSynchronize(prefRef);
AuthorizationFree(authRef, authFlags);
return 0;
}

View File

@ -1,133 +0,0 @@
import Foundation
import SystemConfiguration
let version = "0.1.3"
func getIgnoreList() -> [String] {
let configPath = "\(NSHomeDirectory())/.config/clash/proxyIgnoreList.plist"
if FileManager.default.fileExists(atPath: configPath) {
if let arr = NSArray(contentsOfFile: configPath) as? [String] {
return arr
}
}
let ignoreList = [
"192.168.0.0/16",
"10.0.0.0/8",
"172.16.0.0/12",
"127.0.0.1",
"localhost",
"*.local",
"*.crashlytics.com"
]
return ignoreList
}
func getProxySetting(enable:Bool,port:Int,socksPort:Int) -> [String:AnyObject] {
let ip = enable ? "127.0.0.1" : ""
let enableInt = enable ? 1 : 0
var proxySettings: [String:AnyObject] = [:]
proxySettings[kCFNetworkProxiesHTTPProxy as String] = ip as AnyObject
proxySettings[kCFNetworkProxiesHTTPEnable as String] = enableInt as AnyObject
proxySettings[kCFNetworkProxiesHTTPSProxy as String] = ip as AnyObject
proxySettings[kCFNetworkProxiesHTTPSEnable as String] = enableInt as AnyObject
proxySettings[kCFNetworkProxiesSOCKSProxy as String] = ip as AnyObject
proxySettings[kCFNetworkProxiesSOCKSEnable as String] = enableInt as AnyObject
if enable {
proxySettings[kCFNetworkProxiesHTTPPort as String] = port as AnyObject
proxySettings[kCFNetworkProxiesHTTPSPort as String] = port as AnyObject
proxySettings[kCFNetworkProxiesSOCKSPort as String] = socksPort as AnyObject
} else {
proxySettings[kCFNetworkProxiesHTTPPort as String] = nil
proxySettings[kCFNetworkProxiesHTTPSPort as String] = nil
proxySettings[kCFNetworkProxiesSOCKSPort as String] = nil
}
let ignoreList = getIgnoreList()
proxySettings[kCFNetworkProxiesExceptionsList as String] = ignoreList as AnyObject
return proxySettings
}
func updateProxySetting(prefs:SCPreferences, interfaceKey:String,enable:Bool,port:Int,socksPort:Int) {
let proxySettings = getProxySetting(enable: enable, port: port, socksPort: socksPort)
let path = "/\(kSCPrefNetworkServices)/\(interfaceKey)/\(kSCEntNetProxies)"
SCPreferencesPathSetValue(prefs, path as CFString, proxySettings as CFDictionary)
}
func main(_ args: [String]) {
var port: Int = 0
var socksPort = 0
var flag: Bool = false
if args.count > 3 {
guard let _port = Int(args[1]),
let _socksPort = Int(args[2]) else {
print("ERROR: port is invalid.")
exit(EXIT_FAILURE)
}
guard args[3] == "enable" || args[3] == "disable" else {
print("ERROR: flag is invalid.")
exit(EXIT_FAILURE)
}
port = _port
socksPort = _socksPort
flag = args[3] == "enable"
} else if args.count == 2 && args[1] == "version"{
print(version)
exit(EXIT_SUCCESS)
} else {
print("Usage: ProxyConfig <port> <socksPort> <enable/disable>")
exit(EXIT_FAILURE)
}
var authRef: AuthorizationRef? = nil
let authFlags: AuthorizationFlags = [.extendRights, .interactionAllowed, .preAuthorize]
let authErr = AuthorizationCreate(nil, nil, authFlags, &authRef)
defer {
AuthorizationFree(authRef!, AuthorizationFlags())
}
guard authErr == noErr else {
print("Error: Failed to create administration authorization due to error \(authErr).")
exit(EXIT_FAILURE)
}
guard authRef != nil else {
print("Error: No authorization has been granted to modify network configuration.")
exit(EXIT_FAILURE)
}
guard let prefRef = SCPreferencesCreateWithAuthorization(nil, "ClashX" as CFString, nil, authRef),
let sets = SCPreferencesGetValue(prefRef, kSCPrefNetworkServices)
else {
print("Error: SCPreferencesGetValue fail")
exit(EXIT_FAILURE)
}
for key in sets.allKeys {
//
let dict = sets.object(forKey: key) as? NSDictionary
let hardware = ((dict?["Interface"]) as? NSDictionary)?["Hardware"] as? String
if hardware == "AirPort" || hardware == "Ethernet" {
updateProxySetting(prefs: prefRef,
interfaceKey: key as! String,
enable: flag,
port: port,
socksPort: socksPort)
}
}
SCPreferencesCommitChanges(prefRef)
SCPreferencesApplyChanges(prefRef)
}
main(CommandLine.arguments)