增加 HTTP代理 跟随全局设置
This commit is contained in:
@ -65,7 +65,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
"AutoConfigureNetworkServices": NSNumber(value: true as Bool),
|
||||
"LocalHTTP.ListenAddress": "127.0.0.1",
|
||||
"LocalHTTP.ListenPort": NSNumber(value: 1087 as UInt16),
|
||||
"LocalHTTPOn": true
|
||||
"LocalHTTPOn": true,
|
||||
"LocalHTTP.FollowGlobel": true
|
||||
])
|
||||
|
||||
statusItem = NSStatusBar.system().statusItem(withLength: 20)
|
||||
@ -107,6 +108,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
, using: {
|
||||
(note) in
|
||||
SyncPrivoxy()
|
||||
self.applyConfig()
|
||||
}
|
||||
)
|
||||
notifyCenter.addObserver(forName: NSNotification.Name(rawValue: "NOTIFY_FOUND_SS_URL"), object: nil, queue: nil) {
|
||||
|
@ -10,12 +10,32 @@
|
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||
<window title="HTTP Proxy Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" frameAutosaveName="" animationBehavior="default" id="vS3-DL-Nq3">
|
||||
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
|
||||
<rect key="contentRect" x="109" y="131" width="209" height="163"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="1280" height="777"/>
|
||||
<rect key="contentRect" x="109" y="131" width="209" height="197"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
|
||||
<view key="contentView" id="Qef-Mj-9z1">
|
||||
<rect key="frame" x="0.0" y="0.0" width="209" height="163"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="209" height="197"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<button translatesAutoresizingMaskIntoConstraints="NO" id="hgn-81-fsH">
|
||||
<rect key="frame" x="18" y="161" width="138" height="18"/>
|
||||
<buttonCell key="cell" type="check" title="HTTP Proxy Enable" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="dqU-MG-Sum">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<binding destination="Adn-6l-wm4" name="value" keyPath="values.LocalHTTPOn" id="Oey-LL-A84"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button translatesAutoresizingMaskIntoConstraints="NO" id="P4f-0N-7JI">
|
||||
<rect key="frame" x="18" y="133" width="141" height="18"/>
|
||||
<buttonCell key="cell" type="check" title="Follow Globel Mode" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="ofk-Pc-c8f">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<binding destination="Adn-6l-wm4" name="value" keyPath="values.LocalHTTP.FollowGlobel" id="mwB-AA-WgF"/>
|
||||
</connections>
|
||||
</button>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="CKF-K9-m8X">
|
||||
<rect key="frame" x="18" y="103" width="173" height="17"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="HTTP Proxy Listen Address:" id="qd0-kc-ttB">
|
||||
@ -55,36 +75,28 @@
|
||||
<outlet property="formatter" destination="ji3-e7-HNW" id="xWV-vJ-7eq"/>
|
||||
</connections>
|
||||
</textField>
|
||||
<button translatesAutoresizingMaskIntoConstraints="NO" id="hgn-81-fsH">
|
||||
<rect key="frame" x="18" y="133" width="138" height="18"/>
|
||||
<buttonCell key="cell" type="check" title="HTTP Proxy Enable" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="dqU-MG-Sum">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
<connections>
|
||||
<binding destination="Adn-6l-wm4" name="value" keyPath="values.LocalHTTPOn" id="1Pd-0E-d1Z"/>
|
||||
</connections>
|
||||
</buttonCell>
|
||||
</button>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="lD1-xm-Qy3" firstAttribute="top" secondItem="Ecd-cS-zUI" secondAttribute="bottom" constant="8" symbolic="YES" id="5Yk-wJ-yNC"/>
|
||||
<constraint firstItem="vsw-6L-eh3" firstAttribute="leading" secondItem="Ecd-cS-zUI" secondAttribute="leading" id="5mp-aQ-Qhg"/>
|
||||
<constraint firstItem="vsw-6L-eh3" firstAttribute="top" secondItem="CKF-K9-m8X" secondAttribute="bottom" constant="8" symbolic="YES" id="7uP-qc-xvy"/>
|
||||
<constraint firstItem="CKF-K9-m8X" firstAttribute="trailing" secondItem="vsw-6L-eh3" secondAttribute="trailing" id="Ezc-Tf-zrc"/>
|
||||
<constraint firstItem="hgn-81-fsH" firstAttribute="leading" secondItem="Qef-Mj-9z1" secondAttribute="leading" constant="20" symbolic="YES" id="Fpc-TK-Ies"/>
|
||||
<constraint firstItem="Ecd-cS-zUI" firstAttribute="top" secondItem="vsw-6L-eh3" secondAttribute="bottom" constant="6" id="KgW-Uu-Md4"/>
|
||||
<constraint firstItem="Ecd-cS-zUI" firstAttribute="leading" secondItem="lD1-xm-Qy3" secondAttribute="leading" id="Mbc-uA-iWI"/>
|
||||
<constraint firstItem="hgn-81-fsH" firstAttribute="leading" secondItem="CKF-K9-m8X" secondAttribute="leading" id="ScT-n3-3a6"/>
|
||||
<constraint firstItem="CKF-K9-m8X" firstAttribute="top" secondItem="hgn-81-fsH" secondAttribute="bottom" constant="15" id="Vg9-Uw-dYv"/>
|
||||
<constraint firstItem="vsw-6L-eh3" firstAttribute="trailing" secondItem="lD1-xm-Qy3" secondAttribute="trailing" id="iO8-bs-YWa"/>
|
||||
<constraint firstAttribute="bottom" secondItem="lD1-xm-Qy3" secondAttribute="bottom" constant="20" symbolic="YES" id="tqJ-4V-bgH"/>
|
||||
<constraint firstItem="CKF-K9-m8X" firstAttribute="leading" secondItem="vsw-6L-eh3" secondAttribute="leading" id="yJ3-vA-lWm"/>
|
||||
<constraint firstItem="hgn-81-fsH" firstAttribute="leading" secondItem="P4f-0N-7JI" secondAttribute="leading" id="1R6-Zi-ctk"/>
|
||||
<constraint firstItem="P4f-0N-7JI" firstAttribute="top" secondItem="hgn-81-fsH" secondAttribute="bottom" constant="14" id="45x-uF-HIp"/>
|
||||
<constraint firstItem="vsw-6L-eh3" firstAttribute="leading" secondItem="Ecd-cS-zUI" secondAttribute="leading" id="5Fh-yR-UAH"/>
|
||||
<constraint firstItem="CKF-K9-m8X" firstAttribute="trailing" secondItem="vsw-6L-eh3" secondAttribute="trailing" id="7Y3-mK-KBC"/>
|
||||
<constraint firstItem="hgn-81-fsH" firstAttribute="top" secondItem="Qef-Mj-9z1" secondAttribute="top" constant="20" symbolic="YES" id="Frc-hf-qrH"/>
|
||||
<constraint firstItem="vsw-6L-eh3" firstAttribute="trailing" secondItem="lD1-xm-Qy3" secondAttribute="trailing" id="How-c9-yLj"/>
|
||||
<constraint firstItem="vsw-6L-eh3" firstAttribute="top" secondItem="CKF-K9-m8X" secondAttribute="bottom" constant="8" symbolic="YES" id="JrQ-Uu-Dpf"/>
|
||||
<constraint firstItem="Ecd-cS-zUI" firstAttribute="top" secondItem="vsw-6L-eh3" secondAttribute="bottom" constant="6" id="Pcx-Pb-Am7"/>
|
||||
<constraint firstItem="Ecd-cS-zUI" firstAttribute="leading" secondItem="lD1-xm-Qy3" secondAttribute="leading" id="VkT-8o-eV5"/>
|
||||
<constraint firstItem="hgn-81-fsH" firstAttribute="leading" secondItem="Qef-Mj-9z1" secondAttribute="leading" constant="20" symbolic="YES" id="Ybz-LX-Dja"/>
|
||||
<constraint firstItem="P4f-0N-7JI" firstAttribute="leading" secondItem="CKF-K9-m8X" secondAttribute="leading" id="Zgf-bS-WDG"/>
|
||||
<constraint firstItem="lD1-xm-Qy3" firstAttribute="top" secondItem="Ecd-cS-zUI" secondAttribute="bottom" constant="8" symbolic="YES" id="g09-v2-V3P"/>
|
||||
<constraint firstAttribute="bottom" secondItem="lD1-xm-Qy3" secondAttribute="bottom" constant="20" symbolic="YES" id="hSP-RV-6f4"/>
|
||||
<constraint firstItem="CKF-K9-m8X" firstAttribute="leading" secondItem="vsw-6L-eh3" secondAttribute="leading" id="imf-dG-QVW"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="delegate" destination="-2" id="mD3-X9-VEN"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="-19.5" y="92.5"/>
|
||||
<point key="canvasLocation" x="-19.5" y="109.5"/>
|
||||
</window>
|
||||
<userDefaultsController representsSharedInstance="YES" id="Adn-6l-wm4"/>
|
||||
<numberFormatter formatterBehavior="default10_4" usesGroupingSeparator="NO" groupingSize="0" minimumIntegerDigits="0" maximumIntegerDigits="42" id="ji3-e7-HNW" userLabel="Port Number Formatter">
|
||||
|
@ -134,6 +134,13 @@ GCDWebServer *webServer =nil;
|
||||
NSMutableArray* args = [@[@"--mode", @"global", @"--port"
|
||||
, [NSString stringWithFormat:@"%lu", (unsigned long)port]]mutableCopy];
|
||||
|
||||
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"LocalHTTPOn"] && [[NSUserDefaults standardUserDefaults] boolForKey:@"LocalHTTP.FollowGlobel"]) {
|
||||
NSUInteger privoxyPort = [[NSUserDefaults standardUserDefaults]integerForKey:@"LocalHTTP.ListenPort"];
|
||||
|
||||
[args addObject:@"--privoxy-port"];
|
||||
[args addObject:[NSString stringWithFormat:@"%lu", (unsigned long)privoxyPort]];
|
||||
}
|
||||
|
||||
[self addArguments4ManualSpecifyNetworkServices:args];
|
||||
[self callHelper:args];
|
||||
[self stopPACServer];
|
||||
|
@ -9,6 +9,6 @@
|
||||
#ifndef proxy_conf_helper_version_h
|
||||
#define proxy_conf_helper_version_h
|
||||
|
||||
#define kProxyConfHelperVersion @"1.3.1"
|
||||
#define kProxyConfHelperVersion @"1.3.2"
|
||||
|
||||
#endif /* proxy_conf_helper_version_h */
|
||||
|
@ -18,10 +18,22 @@
|
||||
"cwr-n0-zwn.title" = "本地 Socks5 监听地址:";
|
||||
|
||||
/* Class = "NSTextFieldCell"; title = "GFW List URL:"; ObjectID = "dg0-gS-z5V"; */
|
||||
"dg0-gS-z5V.title" = "GFW List URL:";
|
||||
"dg0-gS-z5V.title" = "GFW LIST URL:";
|
||||
|
||||
/* Class = "NSTextFieldCell"; title = "Timeout:"; ObjectID = "i4l-2S-gOQ"; */
|
||||
"i4l-2S-gOQ.title" = "超时:";
|
||||
|
||||
/* Class = "NSTextFieldCell"; title = "本地 Socks5 监听端口:"; ObjectID = "qRs-ow-vVB"; */
|
||||
"qRs-ow-vVB.title" = "本地 Socks5 监听端口:";
|
||||
|
||||
/* Class = "NSTextFieldCell"; title = "Local PAC Listen Address:"; ObjectID = "dvL-Ic-Wae"; */
|
||||
"dvL-Ic-Wae.title" = "本地 PAC 监听地址:";
|
||||
|
||||
/* Class = "NSTextFieldCell"; title = "Local PAC Listen Port:"; ObjectID = "PSg-XK-qhl"; */
|
||||
"PSg-XK-qhl.title" = "本地 PAC 监听端口:";
|
||||
|
||||
/* Class = "NSTextFieldCell"; title = "White List URL:"; ObjectID = "aif-uV-Lxk"; */
|
||||
"aif-uV-Lxk.title" = "白名单列表 URL:";
|
||||
|
||||
/* Class = "NSTextFieldCell"; title = "White IP List URL:"; ObjectID = "qhu-d1-qgq"; */
|
||||
"qhu-d1-qgq.title" = "白名单IP列表 URL:";
|
||||
|
@ -10,3 +10,6 @@
|
||||
|
||||
/* Class = "NSWindow"; title = "HTTP Proxy Preferences"; ObjectID = "vS3-DL-Nq3"; */
|
||||
"vS3-DL-Nq3.title" = "HTTP 代理 设置";
|
||||
|
||||
/* Class = "NSButtonCell"; title = "Follow Globel Mode"; ObjectID = "ofk-Pc-c8f"; */
|
||||
"ofk-Pc-c8f.title" = "跟随全局模式";
|
||||
|
@ -22,9 +22,10 @@ int main(int argc, const char * argv[])
|
||||
NSString* mode;
|
||||
NSString* pacURL;
|
||||
NSString* portString;
|
||||
NSString* privoxyPortString;
|
||||
|
||||
BRLOptionParser *options = [BRLOptionParser new];
|
||||
[options setBanner:@"Usage: %s [-v] [-m auto|global|off] [-u <url>] [-p <port>]", argv[0]];
|
||||
[options setBanner:@"Usage: %s [-v] [-m auto|global|off] [-u <url>] [-p <port>] [-r <port>]", argv[0]];
|
||||
|
||||
// Version
|
||||
[options addOption:"version" flag:'v' description:@"Print the version number." block:^{
|
||||
@ -40,11 +41,13 @@ int main(int argc, const char * argv[])
|
||||
}];
|
||||
|
||||
// Mode
|
||||
[options addOption:"mode" flag:'m' description:@"Proxy mode, may be: auto,blobal,off" argument:&mode];
|
||||
[options addOption:"mode" flag:'m' description:@"Proxy mode, may be: auto,global,off" argument:&mode];
|
||||
|
||||
[options addOption:"pac-url" flag:'u' description:@"PAC file url for auto mode." argument:&pacURL];
|
||||
[options addOption:"port" flag:'p' description:@"Listen port for global mode." argument:&portString];
|
||||
|
||||
[options addOption:"privoxy-port" flag:'r' description:@"Privoxy Port for global mode." argument:&privoxyPortString];
|
||||
|
||||
NSMutableSet* networkServiceKeys = [NSMutableSet set];
|
||||
[options addOption:"network-service" flag:'n' description:@"Manual specify the network profile need to set proxy." blockWithArgument:^(NSString* value){
|
||||
[networkServiceKeys addObject:value];
|
||||
@ -57,7 +60,6 @@ int main(int argc, const char * argv[])
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
NSInteger port = 0;
|
||||
if (mode) {
|
||||
if ([@"auto" isEqualToString:mode]) {
|
||||
if (!pacURL) {
|
||||
@ -75,6 +77,7 @@ int main(int argc, const char * argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
NSInteger port = 0;
|
||||
if (portString) {
|
||||
port = [portString integerValue];
|
||||
if (0 == port) {
|
||||
@ -82,6 +85,14 @@ int main(int argc, const char * argv[])
|
||||
}
|
||||
}
|
||||
|
||||
NSInteger privoxyPort = 0;
|
||||
if (privoxyPortString) {
|
||||
privoxyPort = [privoxyPortString integerValue];
|
||||
if (0 == privoxyPort) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static AuthorizationRef authRef;
|
||||
static AuthorizationFlags authFlags;
|
||||
authFlags = kAuthorizationFlagDefaults
|
||||
@ -149,6 +160,22 @@ int main(int argc, const char * argv[])
|
||||
kCFNetworkProxiesSOCKSEnable];
|
||||
[proxies setObject:@[@"127.0.0.1", @"localhost"] forKey:(NSString *)kCFNetworkProxiesExceptionsList];
|
||||
|
||||
if (privoxyPort != 0) {
|
||||
[proxies setObject:@"127.0.0.1" forKey:(NSString *)
|
||||
kCFNetworkProxiesHTTPProxy];
|
||||
[proxies setObject:[NSNumber numberWithInteger:privoxyPort] forKey:(NSString*)
|
||||
kCFNetworkProxiesHTTPPort];
|
||||
[proxies setObject:[NSNumber numberWithInt:1] forKey:(NSString*)
|
||||
kCFNetworkProxiesHTTPEnable];
|
||||
|
||||
[proxies setObject:@"127.0.0.1" forKey:(NSString *)
|
||||
kCFNetworkProxiesHTTPSProxy];
|
||||
[proxies setObject:[NSNumber numberWithInteger:privoxyPort] forKey:(NSString*)
|
||||
kCFNetworkProxiesHTTPSPort];
|
||||
[proxies setObject:[NSNumber numberWithInt:1] forKey:(NSString*)
|
||||
kCFNetworkProxiesHTTPSEnable];
|
||||
}
|
||||
|
||||
SCPreferencesPathSetValue(prefRef, (__bridge CFStringRef)prefPath
|
||||
, (__bridge CFDictionaryRef)proxies);
|
||||
} else if ([mode isEqualToString:@"off"]) {
|
||||
|
Reference in New Issue
Block a user