mirror of
https://github.com/zhigang1992/shadowsocks-iOS.git
synced 2026-06-19 10:19:10 +08:00
add ShadowsocksRunner
This commit is contained in:
@@ -14,10 +14,5 @@
|
||||
UITextField *passwordField;
|
||||
}
|
||||
|
||||
+ (void)openSSURL:(NSURL *)url;
|
||||
+ (BOOL)settingsAreNotComplete;
|
||||
+ (BOOL)runProxy;
|
||||
+ (void)reloadConfig;
|
||||
+ (void)saveConfigForKey:(NSString *)key value:(NSString *)value;
|
||||
@property (nonatomic, weak) UIPopoverController *myPopoverController;
|
||||
@end
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
#import "NSData+Base64.h"
|
||||
#import "ProxySettingsTableViewController.h"
|
||||
#import "SimpleTableViewSource.h"
|
||||
#import "local.h"
|
||||
#import "SWBAppDelegate.h"
|
||||
#import "ShadowsocksRunner.h"
|
||||
|
||||
// rows
|
||||
|
||||
@@ -20,13 +20,6 @@
|
||||
|
||||
// config keys
|
||||
|
||||
#define kIPKey @"proxy ip"
|
||||
#define kPortKey @"proxy port"
|
||||
#define kPasswordKey @"proxy password"
|
||||
#define kEncryptionKey @"proxy encryption"
|
||||
#define kProxyModeKey @"proxy mode"
|
||||
#define kUsePublicServer @"public server"
|
||||
|
||||
|
||||
@interface ProxySettingsTableViewController () {
|
||||
SimpleTableViewSource *encryptionSource;
|
||||
@@ -38,112 +31,12 @@
|
||||
|
||||
@implementation ProxySettingsTableViewController
|
||||
|
||||
+ (BOOL)settingsAreNotComplete {
|
||||
if ((![ProxySettingsTableViewController isUsingPublicServer]) && ([[NSUserDefaults standardUserDefaults] stringForKey:kIPKey] == nil ||
|
||||
[[NSUserDefaults standardUserDefaults] stringForKey:kPortKey] == nil ||
|
||||
[[NSUserDefaults standardUserDefaults] stringForKey:kPasswordKey] == nil)) {
|
||||
return YES;
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
+ (BOOL)runProxy {
|
||||
if (![ProxySettingsTableViewController settingsAreNotComplete]) {
|
||||
local_main();
|
||||
return YES;
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
NSLog(@"warning: settings are not complete");
|
||||
#endif
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)reloadConfig {
|
||||
if (![ProxySettingsTableViewController settingsAreNotComplete]) {
|
||||
if ([ProxySettingsTableViewController isUsingPublicServer]) {
|
||||
set_config("106.186.124.182", "8910", "Shadowsocks", "aes-128-cfb");
|
||||
memcpy(shadowsocks_key, "\x45\xd1\xd9\x9e\xbd\xf5\x8c\x85\x34\x55\xdd\x65\x46\xcd\x06\xd3", 16);
|
||||
} else {
|
||||
NSString *v = [[NSUserDefaults standardUserDefaults] objectForKey:kEncryptionKey];
|
||||
if (!v) {
|
||||
v = @"aes-256-cfb";
|
||||
}
|
||||
set_config([[[NSUserDefaults standardUserDefaults] stringForKey:kIPKey] cStringUsingEncoding:NSUTF8StringEncoding], [[[NSUserDefaults standardUserDefaults] stringForKey:kPortKey] cStringUsingEncoding:NSUTF8StringEncoding], [[[NSUserDefaults standardUserDefaults] stringForKey:kPasswordKey] cStringUsingEncoding:NSUTF8StringEncoding], [v cStringUsingEncoding:NSUTF8StringEncoding]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)openSSURL:(NSURL *)url {
|
||||
if (!url.host) {
|
||||
return;
|
||||
}
|
||||
NSString *urlString = [url absoluteString];
|
||||
int i = 0;
|
||||
NSString *errorReason = nil;
|
||||
while(i < 2) {
|
||||
if (i == 1) {
|
||||
NSData *data = [[NSData alloc] initWithBase64Encoding:url.host];
|
||||
NSString *decodedString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
urlString = decodedString;
|
||||
}
|
||||
i++;
|
||||
urlString = [urlString stringByReplacingOccurrencesOfString:@"ss://" withString:@"" options:NSAnchoredSearch range:NSMakeRange(0, urlString.length)];
|
||||
NSRange firstColonRange = [urlString rangeOfString:@":"];
|
||||
NSRange lastColonRange = [urlString rangeOfString:@":" options:NSBackwardsSearch];
|
||||
NSRange lastAtRange = [urlString rangeOfString:@"@" options:NSBackwardsSearch];
|
||||
if (firstColonRange.length == 0) {
|
||||
errorReason = @"colon not found";
|
||||
continue;
|
||||
}
|
||||
if (firstColonRange.location == lastColonRange.location) {
|
||||
errorReason = @"only one colon";
|
||||
continue;
|
||||
}
|
||||
if (lastAtRange.length == 0) {
|
||||
errorReason = @"at not found";
|
||||
continue;
|
||||
}
|
||||
if (!((firstColonRange.location < lastAtRange.location) && (lastAtRange.location < lastColonRange.location))) {
|
||||
errorReason = @"wrong position";
|
||||
continue;
|
||||
}
|
||||
NSString *method = [urlString substringWithRange:NSMakeRange(0, firstColonRange.location)];
|
||||
NSString *password = [urlString substringWithRange:NSMakeRange(firstColonRange.location + 1, lastAtRange.location - firstColonRange.location - 1)];
|
||||
NSString *IP = [urlString substringWithRange:NSMakeRange(lastAtRange.location + 1, lastColonRange.location - lastAtRange.location - 1)];
|
||||
NSString *port = [urlString substringWithRange:NSMakeRange(lastColonRange.location + 1, urlString.length - lastColonRange.location - 1)];
|
||||
[ProxySettingsTableViewController saveConfigForKey:kIPKey value:IP];
|
||||
[ProxySettingsTableViewController saveConfigForKey:kPortKey value:port];
|
||||
[ProxySettingsTableViewController saveConfigForKey:kPasswordKey value:password];
|
||||
[ProxySettingsTableViewController saveConfigForKey:kEncryptionKey value:method];
|
||||
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:kUsePublicServer];
|
||||
[ProxySettingsTableViewController reloadConfig];
|
||||
return;
|
||||
}
|
||||
|
||||
NSLog(@"%@", errorReason);
|
||||
}
|
||||
|
||||
+ (void)saveConfigForKey:(NSString *)key value:(NSString *)value {
|
||||
[[NSUserDefaults standardUserDefaults] setObject:value forKey:key];
|
||||
}
|
||||
|
||||
+ (BOOL)isUsingPublicServer {
|
||||
NSNumber *usePublicServer = [[NSUserDefaults standardUserDefaults] objectForKey:kUsePublicServer];
|
||||
if (usePublicServer != nil) {
|
||||
return [usePublicServer boolValue];
|
||||
} else {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)changePublicServer:(UISegmentedControl *)segmentedControl {
|
||||
BOOL result = NO;
|
||||
if (segmentedControl.selectedSegmentIndex == 0) {
|
||||
result = YES;
|
||||
}
|
||||
[[NSUserDefaults standardUserDefaults] setBool:result forKey:kUsePublicServer];
|
||||
[ShadowsocksRunner setUsingPublicServer:result];
|
||||
if ((self.tableView.numberOfSections == 1) && !result) {
|
||||
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationFade];
|
||||
} else if ((self.tableView.numberOfSections == 2) && result) {
|
||||
@@ -196,11 +89,11 @@
|
||||
if (passwordField.text == nil) {
|
||||
passwordField.text = @"";
|
||||
}
|
||||
[ProxySettingsTableViewController saveConfigForKey:kIPKey value:ipField.text];
|
||||
[ProxySettingsTableViewController saveConfigForKey:kPortKey value:portField.text];
|
||||
[ProxySettingsTableViewController saveConfigForKey:kPasswordKey value:passwordField.text];
|
||||
[ShadowsocksRunner saveConfigForKey:kShadowsocksIPKey value:ipField.text];
|
||||
[ShadowsocksRunner saveConfigForKey:kShadowsocksPortKey value:portField.text];
|
||||
[ShadowsocksRunner saveConfigForKey:kShadowsocksPasswordKey value:passwordField.text];
|
||||
|
||||
[ProxySettingsTableViewController reloadConfig];
|
||||
[ShadowsocksRunner reloadConfig];
|
||||
|
||||
[self dismissModalViewControllerAnimated:YES];
|
||||
if (self->_myPopoverController) {
|
||||
@@ -217,7 +110,7 @@
|
||||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
||||
// Return the number of sections.
|
||||
if ([ProxySettingsTableViewController isUsingPublicServer]) {
|
||||
if ([ShadowsocksRunner isUsingPublicServer]) {
|
||||
return 1;
|
||||
}
|
||||
return 2;
|
||||
@@ -245,7 +138,7 @@
|
||||
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:@[_L(Public), _L(Custom)]];
|
||||
[cell.contentView addSubview:segmentedControl];
|
||||
segmentedControl.center = CGPointMake(320 * 0.5f, cell.bounds.size.height * 0.5f);
|
||||
if ([ProxySettingsTableViewController isUsingPublicServer]) {
|
||||
if ([ShadowsocksRunner isUsingPublicServer]) {
|
||||
segmentedControl.selectedSegmentIndex = 0;
|
||||
} else {
|
||||
segmentedControl.selectedSegmentIndex = 1;
|
||||
@@ -285,21 +178,21 @@
|
||||
cell.textLabel.text = _L(IP);
|
||||
textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
|
||||
textField.secureTextEntry = NO;
|
||||
textField.text = [[NSUserDefaults standardUserDefaults] stringForKey:kIPKey];
|
||||
textField.text = [[NSUserDefaults standardUserDefaults] stringForKey:kShadowsocksIPKey];
|
||||
ipField = textField;
|
||||
break;
|
||||
case kPortRow:
|
||||
cell.textLabel.text = _L(Port);
|
||||
textField.keyboardType = UIKeyboardTypeNumberPad;
|
||||
textField.secureTextEntry = NO;
|
||||
textField.text = [[NSUserDefaults standardUserDefaults] stringForKey:kPortKey];
|
||||
textField.text = [[NSUserDefaults standardUserDefaults] stringForKey:kShadowsocksPortKey];
|
||||
portField = textField;
|
||||
break;
|
||||
case kPasswordRow:
|
||||
cell.textLabel.text = _L(Password);
|
||||
textField.keyboardType = UIKeyboardTypeDefault;
|
||||
textField.secureTextEntry = YES;
|
||||
textField.text = [[NSUserDefaults standardUserDefaults] stringForKey:kPasswordKey];
|
||||
textField.text = [[NSUserDefaults standardUserDefaults] stringForKey:kShadowsocksPasswordKey];
|
||||
passwordField = textField;
|
||||
break;
|
||||
default:
|
||||
@@ -324,7 +217,7 @@
|
||||
[self.navigationController pushViewController:detailViewController animated:YES];
|
||||
*/
|
||||
if (indexPath.row == 3) {
|
||||
NSString *v = [[NSUserDefaults standardUserDefaults] objectForKey:kEncryptionKey];
|
||||
NSString *v = [[NSUserDefaults standardUserDefaults] objectForKey:kShadowsocksEncryptionKey];
|
||||
if (!v) {
|
||||
v = @"aes-256-cfb";
|
||||
}
|
||||
@@ -359,7 +252,7 @@
|
||||
@"seed-cfb",
|
||||
nil]
|
||||
initialValue:v selectionBlock:^(NSObject *value) {
|
||||
[[NSUserDefaults standardUserDefaults] setObject:value forKey:kEncryptionKey];
|
||||
[[NSUserDefaults standardUserDefaults] setObject:value forKey:kShadowsocksEncryptionKey];
|
||||
}];
|
||||
UIViewController *controller = [[UIViewController alloc] init];
|
||||
controller.contentSizeForViewInPopover = self.contentSizeForViewInPopover;
|
||||
@@ -370,14 +263,14 @@
|
||||
controller.view = tableView1;
|
||||
[self.navigationController pushViewController:controller animated:YES];
|
||||
} else if (indexPath.row == 4) {
|
||||
NSString *v = [[NSUserDefaults standardUserDefaults] objectForKey:kProxyModeKey];
|
||||
NSString *v = [[NSUserDefaults standardUserDefaults] objectForKey:kShadowsocksProxyModeKey];
|
||||
if (!v) {
|
||||
v = @"pac";
|
||||
}
|
||||
modeSource = [[SimpleTableViewSource alloc] initWithLabels:[NSArray arrayWithObjects:_L(PAC), _L(Global), _L(Off), nil]
|
||||
values:[NSArray arrayWithObjects:@"pac", @"global", @"off", nil]
|
||||
initialValue:v selectionBlock:^(NSObject *value) {
|
||||
[[NSUserDefaults standardUserDefaults] setObject:value forKey:kProxyModeKey];
|
||||
[[NSUserDefaults standardUserDefaults] setObject:value forKey:kShadowsocksProxyModeKey];
|
||||
SWBAppDelegate *appDelegate = (SWBAppDelegate *) [UIApplication sharedApplication].delegate;
|
||||
[appDelegate updateProxyMode];
|
||||
}];
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
#import "GCDWebServer.h"
|
||||
#import "SWBViewController.h"
|
||||
#import "ProxySettingsTableViewController.h"
|
||||
#import "ShadowsocksRunner.h"
|
||||
|
||||
#define kProxyModeKey @"proxy mode"
|
||||
|
||||
@@ -105,7 +105,7 @@ void polipo_exit();
|
||||
|
||||
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
|
||||
if (buttonIndex == 1) {
|
||||
[ProxySettingsTableViewController openSSURL:ssURL];
|
||||
[ShadowsocksRunner openSSURL:ssURL];
|
||||
} else {
|
||||
// Do nothing
|
||||
}
|
||||
@@ -139,9 +139,9 @@ void polipo_exit();
|
||||
#pragma mark - Run proxy
|
||||
|
||||
- (void)runProxy {
|
||||
[ProxySettingsTableViewController reloadConfig];
|
||||
[ShadowsocksRunner reloadConfig];
|
||||
for (; ;) {
|
||||
if ([ProxySettingsTableViewController runProxy]) {
|
||||
if ([ShadowsocksRunner runProxy]) {
|
||||
sleep(1);
|
||||
} else {
|
||||
sleep(2);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import "QRCodeViewController.h"
|
||||
#import "SWBViewController.h"
|
||||
#import "ShadowsocksRunner.h"
|
||||
#import "ProxySettingsTableViewController.h"
|
||||
#import "SWBAboutController.h"
|
||||
|
||||
@@ -151,7 +152,7 @@
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated {
|
||||
if ([ProxySettingsTableViewController settingsAreNotComplete]) {
|
||||
if ([ShadowsocksRunner settingsAreNotComplete]) {
|
||||
[self showSettings];
|
||||
}
|
||||
}
|
||||
|
||||
28
ShadowWeb/ShadowsocksRunner.h
Normal file
28
ShadowWeb/ShadowsocksRunner.h
Normal file
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by clowwindy on 14-2-27.
|
||||
// Copyright (c) 2014 clowwindy. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
|
||||
#define kShadowsocksIPKey @"proxy ip"
|
||||
#define kShadowsocksPortKey @"proxy port"
|
||||
#define kShadowsocksPasswordKey @"proxy password"
|
||||
#define kShadowsocksEncryptionKey @"proxy encryption"
|
||||
#define kShadowsocksProxyModeKey @"proxy mode"
|
||||
#define kShadowsocksUsePublicServer @"public server"
|
||||
|
||||
|
||||
@interface ShadowsocksRunner : NSObject
|
||||
|
||||
+ (BOOL)settingsAreNotComplete;
|
||||
+ (BOOL)runProxy;
|
||||
+ (void)reloadConfig;
|
||||
+ (void)openSSURL:(NSURL *)url;
|
||||
+ (void)saveConfigForKey:(NSString *)key value:(NSString *)value;
|
||||
+ (void)setUsingPublicServer:(BOOL)use;
|
||||
+ (BOOL)isUsingPublicServer;
|
||||
|
||||
|
||||
@end
|
||||
120
ShadowWeb/ShadowsocksRunner.m
Normal file
120
ShadowWeb/ShadowsocksRunner.m
Normal file
@@ -0,0 +1,120 @@
|
||||
//
|
||||
// Created by clowwindy on 14-2-27.
|
||||
// Copyright (c) 2014 clowwindy. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ShadowsocksRunner.h"
|
||||
#import "local.h"
|
||||
|
||||
|
||||
@implementation ShadowsocksRunner {
|
||||
|
||||
}
|
||||
|
||||
+ (BOOL)settingsAreNotComplete {
|
||||
if ((![ShadowsocksRunner isUsingPublicServer]) && ([[NSUserDefaults standardUserDefaults] stringForKey:kShadowsocksIPKey] == nil ||
|
||||
[[NSUserDefaults standardUserDefaults] stringForKey:kShadowsocksPortKey] == nil ||
|
||||
[[NSUserDefaults standardUserDefaults] stringForKey:kShadowsocksPasswordKey] == nil)) {
|
||||
return YES;
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
+ (BOOL)runProxy {
|
||||
if (![ShadowsocksRunner settingsAreNotComplete]) {
|
||||
local_main();
|
||||
return YES;
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
NSLog(@"warning: settings are not complete");
|
||||
#endif
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)reloadConfig {
|
||||
if (![ShadowsocksRunner settingsAreNotComplete]) {
|
||||
if ([ShadowsocksRunner isUsingPublicServer]) {
|
||||
set_config("106.186.124.182", "8910", "Shadowsocks", "aes-128-cfb");
|
||||
memcpy(shadowsocks_key, "\x45\xd1\xd9\x9e\xbd\xf5\x8c\x85\x34\x55\xdd\x65\x46\xcd\x06\xd3", 16);
|
||||
} else {
|
||||
NSString *v = [[NSUserDefaults standardUserDefaults] objectForKey:kShadowsocksEncryptionKey];
|
||||
if (!v) {
|
||||
v = @"aes-256-cfb";
|
||||
}
|
||||
set_config([[[NSUserDefaults standardUserDefaults] stringForKey:kShadowsocksIPKey] cStringUsingEncoding:NSUTF8StringEncoding], [[[NSUserDefaults standardUserDefaults] stringForKey:kShadowsocksPortKey] cStringUsingEncoding:NSUTF8StringEncoding], [[[NSUserDefaults standardUserDefaults] stringForKey:kShadowsocksPasswordKey] cStringUsingEncoding:NSUTF8StringEncoding], [v cStringUsingEncoding:NSUTF8StringEncoding]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)openSSURL:(NSURL *)url {
|
||||
if (!url.host) {
|
||||
return;
|
||||
}
|
||||
NSString *urlString = [url absoluteString];
|
||||
int i = 0;
|
||||
NSString *errorReason = nil;
|
||||
while(i < 2) {
|
||||
if (i == 1) {
|
||||
NSData *data = [[NSData alloc] initWithBase64Encoding:url.host];
|
||||
NSString *decodedString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
urlString = decodedString;
|
||||
}
|
||||
i++;
|
||||
urlString = [urlString stringByReplacingOccurrencesOfString:@"ss://" withString:@"" options:NSAnchoredSearch range:NSMakeRange(0, urlString.length)];
|
||||
NSRange firstColonRange = [urlString rangeOfString:@":"];
|
||||
NSRange lastColonRange = [urlString rangeOfString:@":" options:NSBackwardsSearch];
|
||||
NSRange lastAtRange = [urlString rangeOfString:@"@" options:NSBackwardsSearch];
|
||||
if (firstColonRange.length == 0) {
|
||||
errorReason = @"colon not found";
|
||||
continue;
|
||||
}
|
||||
if (firstColonRange.location == lastColonRange.location) {
|
||||
errorReason = @"only one colon";
|
||||
continue;
|
||||
}
|
||||
if (lastAtRange.length == 0) {
|
||||
errorReason = @"at not found";
|
||||
continue;
|
||||
}
|
||||
if (!((firstColonRange.location < lastAtRange.location) && (lastAtRange.location < lastColonRange.location))) {
|
||||
errorReason = @"wrong position";
|
||||
continue;
|
||||
}
|
||||
NSString *method = [urlString substringWithRange:NSMakeRange(0, firstColonRange.location)];
|
||||
NSString *password = [urlString substringWithRange:NSMakeRange(firstColonRange.location + 1, lastAtRange.location - firstColonRange.location - 1)];
|
||||
NSString *IP = [urlString substringWithRange:NSMakeRange(lastAtRange.location + 1, lastColonRange.location - lastAtRange.location - 1)];
|
||||
NSString *port = [urlString substringWithRange:NSMakeRange(lastColonRange.location + 1, urlString.length - lastColonRange.location - 1)];
|
||||
[ShadowsocksRunner saveConfigForKey:kShadowsocksIPKey value:IP];
|
||||
[ShadowsocksRunner saveConfigForKey:kShadowsocksPortKey value:port];
|
||||
[ShadowsocksRunner saveConfigForKey:kShadowsocksPasswordKey value:password];
|
||||
[ShadowsocksRunner saveConfigForKey:kShadowsocksEncryptionKey value:method];
|
||||
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:kShadowsocksUsePublicServer];
|
||||
[ShadowsocksRunner reloadConfig];
|
||||
return;
|
||||
}
|
||||
|
||||
NSLog(@"%@", errorReason);
|
||||
}
|
||||
|
||||
+ (void)saveConfigForKey:(NSString *)key value:(NSString *)value {
|
||||
[[NSUserDefaults standardUserDefaults] setObject:value forKey:key];
|
||||
}
|
||||
|
||||
|
||||
+ (void)setUsingPublicServer:(BOOL)use {
|
||||
[[NSUserDefaults standardUserDefaults] setBool:use forKey:kShadowsocksUsePublicServer];
|
||||
|
||||
}
|
||||
|
||||
+ (BOOL)isUsingPublicServer {
|
||||
NSNumber *usePublicServer = [[NSUserDefaults standardUserDefaults] objectForKey:kShadowsocksUsePublicServer];
|
||||
if (usePublicServer != nil) {
|
||||
return [usePublicServer boolValue];
|
||||
} else {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -11,6 +11,7 @@
|
||||
#import "encrypt.h"
|
||||
#import "SWBAppDelegate.h"
|
||||
#import "GCDWebServer.h"
|
||||
#import "ShadowsocksRunner.h"
|
||||
|
||||
@implementation SWBAppDelegate
|
||||
|
||||
@@ -19,16 +20,13 @@
|
||||
// Insert code here to initialize your application
|
||||
dispatch_queue_t proxy = dispatch_queue_create("proxy", NULL);
|
||||
dispatch_async(proxy, ^{
|
||||
set_config("106.186.124.182", "8910", "Shadowsocks", "aes-128-cfb");
|
||||
memcpy(shadowsocks_key, "\x45\xd1\xd9\x9e\xbd\xf5\x8c\x85\x34\x55\xdd\x65\x46\xcd\x06\xd3", 16);
|
||||
local_main();
|
||||
[self runProxy];
|
||||
});
|
||||
|
||||
NSData *pacData = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"proxy" withExtension:@"pac"]];
|
||||
GCDWebServer *webServer = [[GCDWebServer alloc] init];
|
||||
[webServer addHandlerForMethod:@"GET" path:@"/proxy.pac" requestClass:[GCDWebServerRequest class] processBlock:^GCDWebServerResponse *(GCDWebServerRequest *request) {
|
||||
return [GCDWebServerDataResponse responseWithData:pacData contentType:@"application/x-ns-proxy-autoconfig"];
|
||||
|
||||
}
|
||||
];
|
||||
|
||||
@@ -50,6 +48,17 @@
|
||||
[SWBAppDelegate toggleSystemProxy:NO];
|
||||
}
|
||||
|
||||
- (void)runProxy {
|
||||
[ShadowsocksRunner reloadConfig];
|
||||
for (; ;) {
|
||||
if ([ShadowsocksRunner runProxy]) {
|
||||
sleep(1);
|
||||
} else {
|
||||
sleep(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)exit {
|
||||
[[NSApplication sharedApplication] terminate:nil];
|
||||
}
|
||||
|
||||
@@ -109,9 +109,11 @@
|
||||
62DE796018B2140D00277174 /* cancel.png in Resources */ = {isa = PBXBuildFile; fileRef = 62DE795F18B2140D00277174 /* cancel.png */; };
|
||||
62F47B8D18BDED61007B223A /* ConfigWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 62F47B8C18BDED61007B223A /* ConfigWindow.xib */; };
|
||||
96D80C05176CE1D7006C8078 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96D80C04176CE1D7006C8078 /* AVFoundation.framework */; };
|
||||
EB18906527B59E4F6A70A14A /* ShadowsocksRunner.m in Sources */ = {isa = PBXBuildFile; fileRef = EB1897A89055A4C2CFD81AF8 /* ShadowsocksRunner.m */; };
|
||||
EB189096BC8B91FA0F60A34C /* 3gnet_disable.mobileconfig in Resources */ = {isa = PBXBuildFile; fileRef = EB1897AD03717EB5E44BA24B /* 3gnet_disable.mobileconfig */; };
|
||||
EB1890D6331E61914013309F /* polipo_disable.config in Resources */ = {isa = PBXBuildFile; fileRef = EB189F29205BA2AB998B867D /* polipo_disable.config */; };
|
||||
EB1891FD5CE9480608918422 /* SimpleTableViewSource.m in Sources */ = {isa = PBXBuildFile; fileRef = EB1897832237B71EF50B3DF4 /* SimpleTableViewSource.m */; };
|
||||
EB1896F6F5F2468484F67FAD /* ShadowsocksRunner.m in Sources */ = {isa = PBXBuildFile; fileRef = EB1897A89055A4C2CFD81AF8 /* ShadowsocksRunner.m */; };
|
||||
EB1897A04CF0382A754FE700 /* SWBConfigWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = EB1895348E32ABA4F4F86742 /* SWBConfigWindowController.m */; };
|
||||
EB189A01F66776EC1714F32D /* 3gnet_enable.mobileconfig in Resources */ = {isa = PBXBuildFile; fileRef = EB1897A8F80969EC7477F89D /* 3gnet_enable.mobileconfig */; };
|
||||
EB189DBA13C945ADF838DF2C /* QRCodeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = EB1892CE8806A5E5632B5714 /* QRCodeViewController.m */; };
|
||||
@@ -368,8 +370,10 @@
|
||||
EB1895847BCC9ED701A0C8CB /* SWBAboutController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWBAboutController.h; sourceTree = "<group>"; };
|
||||
EB1896EFEA137F75386005D4 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = SOURCE_ROOT; };
|
||||
EB1897832237B71EF50B3DF4 /* SimpleTableViewSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SimpleTableViewSource.m; sourceTree = "<group>"; };
|
||||
EB1897A89055A4C2CFD81AF8 /* ShadowsocksRunner.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShadowsocksRunner.m; sourceTree = "<group>"; };
|
||||
EB1897A8F80969EC7477F89D /* 3gnet_enable.mobileconfig */ = {isa = PBXFileReference; lastKnownFileType = file.mobileconfig; path = 3gnet_enable.mobileconfig; sourceTree = "<group>"; };
|
||||
EB1897AD03717EB5E44BA24B /* 3gnet_disable.mobileconfig */ = {isa = PBXFileReference; lastKnownFileType = file.mobileconfig; path = 3gnet_disable.mobileconfig; sourceTree = "<group>"; };
|
||||
EB189E412781A71BA967EECE /* ShadowsocksRunner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShadowsocksRunner.h; sourceTree = "<group>"; };
|
||||
EB189EE1CF6E8C6C431B87BA /* SWBAboutController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SWBAboutController.m; sourceTree = "<group>"; };
|
||||
EB189F12BEB086705288D293 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = file.md; path = README.md; sourceTree = SOURCE_ROOT; };
|
||||
EB189F29205BA2AB998B867D /* polipo_disable.config */ = {isa = PBXFileReference; lastKnownFileType = file.config; path = polipo_disable.config; sourceTree = "<group>"; };
|
||||
@@ -716,6 +720,8 @@
|
||||
EB18942F05960F64CC059413 /* SimpleTableViewSource.h */,
|
||||
EB1892CE8806A5E5632B5714 /* QRCodeViewController.m */,
|
||||
EB189069EF341E65B5414D00 /* QRCodeViewController.h */,
|
||||
EB1897A89055A4C2CFD81AF8 /* ShadowsocksRunner.m */,
|
||||
EB189E412781A71BA967EECE /* ShadowsocksRunner.h */,
|
||||
);
|
||||
name = Shadowsocks;
|
||||
sourceTree = "<group>";
|
||||
@@ -1042,6 +1048,7 @@
|
||||
62D85AB1176DA6FC00FE5575 /* util.c in Sources */,
|
||||
EB189E4CAA0DEF020070DC84 /* SWBAboutController.m in Sources */,
|
||||
EB189DBA13C945ADF838DF2C /* QRCodeViewController.m in Sources */,
|
||||
EB1896F6F5F2468484F67FAD /* ShadowsocksRunner.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -1071,6 +1078,7 @@
|
||||
627A6E0518B47E9300493BBC /* main.m in Sources */,
|
||||
627A6E0C18B47E9300493BBC /* SWBAppDelegate.m in Sources */,
|
||||
EB1897A04CF0382A754FE700 /* SWBConfigWindowController.m in Sources */,
|
||||
EB18906527B59E4F6A70A14A /* ShadowsocksRunner.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user