enable/disable apn

This commit is contained in:
clowwindy
2013-06-16 19:47:11 +08:00
parent e869100fd5
commit 414929eb6a
8 changed files with 265 additions and 29 deletions

View File

@@ -74,8 +74,10 @@
62D85AB4176DAA7200FE5575 /* polipo.config in Resources */ = {isa = PBXBuildFile; fileRef = 62D85AB2176DAA7200FE5575 /* polipo.config */; };
62D85AB5176DAA7200FE5575 /* silence.wav in Resources */ = {isa = PBXBuildFile; fileRef = 62D85AB3176DAA7200FE5575 /* silence.wav */; };
96D80C05176CE1D7006C8078 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96D80C04176CE1D7006C8078 /* AVFoundation.framework */; };
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 */; };
EB189A01F66776EC1714F32D /* shadowsocks.mobileconfig in Resources */ = {isa = PBXBuildFile; fileRef = EB1897A8F80969EC7477F89D /* shadowsocks.mobileconfig */; };
EB189A01F66776EC1714F32D /* 3gnet_enable.mobileconfig in Resources */ = {isa = PBXBuildFile; fileRef = EB1897A8F80969EC7477F89D /* 3gnet_enable.mobileconfig */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -215,7 +217,9 @@
96D80C04176CE1D7006C8078 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
EB18942F05960F64CC059413 /* SimpleTableViewSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleTableViewSource.h; sourceTree = "<group>"; };
EB1897832237B71EF50B3DF4 /* SimpleTableViewSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SimpleTableViewSource.m; sourceTree = "<group>"; };
EB1897A8F80969EC7477F89D /* shadowsocks.mobileconfig */ = {isa = PBXFileReference; lastKnownFileType = file.mobileconfig; path = shadowsocks.mobileconfig; 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>"; };
EB189F29205BA2AB998B867D /* polipo_disable.config */ = {isa = PBXFileReference; lastKnownFileType = file.config; path = polipo_disable.config; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -305,7 +309,9 @@
621571BC16CF6BCB003D96B4 /* Default@2x.png */,
621571BE16CF6BCB003D96B4 /* Default-568h@2x.png */,
621FCBF617603E5100411E5F /* proxy.pac */,
EB1897A8F80969EC7477F89D /* shadowsocks.mobileconfig */,
EB1897A8F80969EC7477F89D /* 3gnet_enable.mobileconfig */,
EB1897AD03717EB5E44BA24B /* 3gnet_disable.mobileconfig */,
EB189F29205BA2AB998B867D /* polipo_disable.config */,
);
name = "Supporting Files";
sourceTree = "<group>";
@@ -558,9 +564,11 @@
621571BD16CF6BCB003D96B4 /* Default@2x.png in Resources */,
621571BF16CF6BCB003D96B4 /* Default-568h@2x.png in Resources */,
621FCBF717603E5100411E5F /* proxy.pac in Resources */,
EB189A01F66776EC1714F32D /* shadowsocks.mobileconfig in Resources */,
EB189A01F66776EC1714F32D /* 3gnet_enable.mobileconfig in Resources */,
62D85AB4176DAA7200FE5575 /* polipo.config in Resources */,
62D85AB5176DAA7200FE5575 /* silence.wav in Resources */,
EB189096BC8B91FA0F60A34C /* 3gnet_disable.mobileconfig in Resources */,
EB1890D6331E61914013309F /* polipo_disable.config in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -0,0 +1,60 @@
<?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>PayloadContent</key>
<array>
<dict>
<key>PayloadContent</key>
<array>
<dict>
<key>DefaultsData</key>
<dict>
<key>apns</key>
<array>
<dict>
<key>apn</key>
<string>3GNET</string>
<key>proxyPort</key>
<integer>0</integer>
</dict>
</array>
</dict>
<key>DefaultsDomainName</key>
<string>com.apple.managedCarrier</string>
</dict>
</array>
<key>PayloadDescription</key>
<string>提供对营运商“接入点名称”的自定义。</string>
<key>PayloadDisplayName</key>
<string>APN</string>
<key>PayloadIdentifier</key>
<string>shadowsocks.</string>
<key>PayloadOrganization</key>
<string></string>
<key>PayloadType</key>
<string>com.apple.apn.managed</string>
<key>PayloadUUID</key>
<string>A76FF343-6067-4F1F-9D25-05B11960560B</string>
<key>PayloadVersion</key>
<integer>1</integer>
</dict>
</array>
<key>PayloadDescription</key>
<string>描述文件描述。</string>
<key>PayloadDisplayName</key>
<string>Shadowsocks(Disabled)</string>
<key>PayloadIdentifier</key>
<string>shadowsocks</string>
<key>PayloadOrganization</key>
<string></string>
<key>PayloadRemovalDisallowed</key>
<false/>
<key>PayloadType</key>
<string>Configuration</string>
<key>PayloadUUID</key>
<string>7392093F-365D-4F19-A1D3-8A583C832492</string>
<key>PayloadVersion</key>
<integer>1</integer>
</dict>
</plist>

View File

@@ -6,9 +6,11 @@
// Copyright (c) 2012 clowwindy. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ProxySettingsTableViewController.h"
#import "SimpleTableViewSource.h"
#import "local.h"
#import "SWBAppDelegate.h"
// rows
@@ -25,7 +27,8 @@
@interface ProxySettingsTableViewController () {
SimpleTableViewSource *source;
SimpleTableViewSource *encryptionSource;
SimpleTableViewSource *apnSource;
}
@end
@@ -135,7 +138,7 @@
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 4;
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
@@ -146,6 +149,12 @@
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
if (indexPath.row == 4) {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"bb"];
cell.textLabel.text = @"Enable/Disable APN";
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"aaaaa"];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
textField.adjustsFontSizeToFitWidth = YES;
@@ -199,15 +208,31 @@
if (!v) {
v = @"aes-256-cfb";
}
source = [[SimpleTableViewSource alloc] initWithLabels:[NSArray arrayWithObjects:@"Table", @"AES-256-CFB", @"AES-192-CFB", @"AES-128-CFB", @"BF-CFB", nil]
encryptionSource = [[SimpleTableViewSource alloc] initWithLabels:[NSArray arrayWithObjects:@"Table", @"AES-256-CFB", @"AES-192-CFB", @"AES-128-CFB", @"BF-CFB", nil]
values:[NSArray arrayWithObjects:@"table", @"aes-256-cfb", @"aes-192-cfb", @"aes-128-cfb", @"bf-cfb", nil]
initialValue:v selectionBlock:^(NSObject * value) {
[[NSUserDefaults standardUserDefaults] setObject:value forKey:kEncryptionKey];
}];
UIViewController *controller = [[UIViewController alloc] init];
UITableView *tableView1 = [[UITableView alloc] initWithFrame:controller.view.frame style:UITableViewStyleGrouped];
tableView1.dataSource = source;
tableView1.delegate = source;
tableView1.dataSource = encryptionSource;
tableView1.delegate = encryptionSource;
controller.view = tableView1;
[self.navigationController pushViewController:controller animated:YES];
} else if (indexPath.row == 4) {
apnSource = [[SimpleTableViewSource alloc] initWithLabels:[NSArray arrayWithObjects:@"Enable Unicom", @"Disable Unicom", nil]
values:[NSArray arrayWithObjects:@"3gnet_enable", @"3gnet_disable", nil]
initialValue:nil selectionBlock:^(NSObject *value) {
SWBAppDelegate *appDelegate = (SWBAppDelegate *)[UIApplication sharedApplication].delegate;
NSString *v = (NSString *)value;
[appDelegate setPolipo:[v rangeOfString:@"enable"].length > 0];
[[UIApplication sharedApplication] openURL:
[NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8080/apn?id=%@", (NSString *)value]]];
}];
UIViewController *controller = [[UIViewController alloc] init];
UITableView *tableView1 = [[UITableView alloc] initWithFrame:controller.view.frame style:UITableViewStyleGrouped];
tableView1.dataSource = apnSource;
tableView1.delegate = apnSource;
controller.view = tableView1;
[self.navigationController pushViewController:controller animated:YES];
}

View File

@@ -22,4 +22,6 @@
@property (nonatomic, strong) SWBNetworkActivityIndicatorManager *networkActivityIndicatorManager;
- (void)setPolipo:(BOOL)enabled;
@end

View File

@@ -16,19 +16,24 @@
int polipo_main(int argc, char **argv);
void polipo_exit();
@implementation SWBAppDelegate
@implementation SWBAppDelegate {
BOOL polipoRunning;
BOOL polipoEnabled;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
}];
polipoEnabled = YES;
dispatch_queue_t proxy = dispatch_queue_create("proxy", NULL);
dispatch_async(proxy, ^{
[self runProxy];
});
[self proxyHttpStart];
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updatePolipo) userInfo:nil repeats:YES];
NSData *pacData = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"proxy" withExtension:@"pac"]];
GCDWebServer *webServer = [[GCDWebServer alloc] init];
@@ -38,10 +43,10 @@ void polipo_exit();
}
];
NSData *mobileconfig = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"shadowsocks" withExtension:@"mobileconfig"]];
[webServer addHandlerForMethod:@"GET" path:@"/apn" requestClass:[GCDWebServerRequest class] processBlock:^GCDWebServerResponse *(GCDWebServerRequest *request) {
return [GCDWebServerDataResponse responseWithData:mobileconfig contentType:@"application/x-apple-aspen-config"];
NSString *apnID = request.query[@"id"];
NSData *mobileconfig = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:apnID withExtension:@"mobileconfig"]];
return [GCDWebServerDataResponse responseWithData:mobileconfig contentType:@"application/x-apple-aspen-config"];
}
];
@@ -117,30 +122,42 @@ void polipo_exit();
}
}
#pragma mark polipo
-(void) updatePolipo {
if (!polipoRunning) {
[self proxyHttpStart];
}
}
- (void) proxyHttpStart
{
[NSThread detachNewThreadSelector:@selector(proxyHttpRun) toTarget:self withObject:nil];
if (polipoRunning) {
NSLog(@"already running");
return;
}
polipoRunning = YES;
if (polipoEnabled) {
[NSThread detachNewThreadSelector:@selector(proxyHttpRun) toTarget:self withObject:nil];
} else{
[NSThread detachNewThreadSelector:@selector(proxyHttpRunDisabled) toTarget:self withObject:nil];
}
}
- (void) proxyHttpStop
{
if (!polipoRunning) {
NSLog(@"not running");
return;
}
polipo_exit();
}
- (void) proxyHttpRun
{
// self.proxyHttpRunning = YES;
@autoreleasepool {
- (void) proxyHttpRunDisabled {
@autoreleasepool {
polipoRunning = YES;
NSLog(@"http proxy start");
NSString *configuration = [[NSBundle mainBundle] pathForResource:@"polipo" ofType:@"config"];
NSString *configuration = [[NSBundle mainBundle] pathForResource:@"polipo_disable" ofType:@"config"];
char *args[5] = {
"test",
"-c",
@@ -148,13 +165,34 @@ void polipo_exit();
"proxyAddress=0.0.0.0",
(char*)[[NSString stringWithFormat:@"proxyPort=%d", 8081] UTF8String],
};
polipo_main(5, args);
NSLog(@"http proxy stop");
polipoRunning = NO;
}}
- (void) proxyHttpRun
{
@autoreleasepool {
polipoRunning = YES;
NSLog(@"http proxy start");
NSString *configuration = [[NSBundle mainBundle] pathForResource:@"polipo" ofType:@"config"];
char *args[5] = {
"test",
"-c",
(char*)[configuration UTF8String],
"proxyAddress=0.0.0.0",
(char*)[[NSString stringWithFormat:@"proxyPort=%d", 8081] UTF8String],
};
polipo_main(5, args);
NSLog(@"http proxy stop");
polipoRunning = NO;
}
// self.proxyHttpRunning = NO;
}
- (void)setPolipo:(BOOL)enabled {
polipoEnabled = enabled;
[self proxyHttpStop];
}
@end

View File

@@ -0,0 +1,103 @@
# daemonise = true
# scrubLogs = true
# socksProxyType = socks5
# logLevel = 0x07
chunkHighMark = 10000000
objectHighMark = 1024
diskCacheRoot = ""
localDocumentRoot = ""
idleTime = 1
disableLocalInterface = true
disableConfiguration = true
disableIndexing = true
dnsUseGethostbyname = yes
# socksParentProxy = 127.0.0.1:1080
# socksProxyType = socks5
# allowUnalignedRangeRequests boolean false Allow unaligned range requests (unreliable).
# allowedClients list (not set) Networks from which clients are allowed to connect.
# allowedPorts intlist 80-100, 1024-65535 Ports to which connections are allowed.
# alwaysAddNoTransform boolean false If true, add a no-transform directive to all requests.
# authCredentials atom (hidden) username:password.
# authRealm atom (none) Authentication realm.
# bigBufferSize integer 32768 Size of big buffers (max size of headers).
# cacheIsShared boolean true If false, ignore s-maxage and private.
# censorReferer tristate false Censor referer headers.
# censoredHeaders list (empty list) Headers to censor.
# chunkCriticalMark integer 24772608 Critical mark for chunk memory (0 = auto).
# chunkHighMark integer 25165824 High mark for chunk memory.
# chunkLowMark integer 18874368 Low mark for chunk memory (0 = auto).
# clientTimeout time 2m Client-side timeout.
# disableConfiguration boolean false Disable reconfiguring Polipo at runtime.
# disableIndexing boolean true Disable indexing of the local cache.
# disableLocalInterface boolean false Disable the local configuration pages.
# disableProxy boolean false Whether to be a web server only.
# disableServersList boolean true Disable the list of known servers.
# disableVia boolean true Don't use Via headers.
# diskCacheDirectoryPermissions integer 0700 Access rights for new directories.
# diskCacheFilePermissions integer 0600 Access rights for new cache files.
# diskCacheTruncateSize integer 1048576 Size to which on-disk objects are truncated.
# diskCacheTruncateTime time 4d12h Time after which on-disk objects are truncated.
# diskCacheUnlinkTime time 32d Time after which on-disk objects are removed.
# diskCacheWriteoutOnClose integer 32768 Number of bytes to write out eagerly.
# dnsGethostbynameTtl time 20m TTL for gethostbyname addresses.
# dnsMaxTimeout time 1m Max timeout for DNS queries.
# dnsNameServer atom 127.0.0.1 The name server to use.
# dnsNegativeTtl time 2m TTL for negative DNS replies with no TTL.
# dnsUseGethostbyname 4-state reluctantly Use the system resolver.
# dontCacheCookies boolean false Work around cachable cookies.
# dontCacheRedirects boolean false If true, don't cache redirects.
# dontTrustVaryETag tristate maybe Whether to trust the ETag when there's Vary.
# expectContinue tristate maybe Send Expect-Continue to servers.
# forbiddenFile atom (none) File specifying forbidden URLs.
# forbiddenRedirectCode integer 302 Redirect code, 301 or 302.
# forbiddenUrl atom (none) URL to which forbidden requests should be redirected.
# idleTime time 20s Time to remain idle before writing out.
# laxHttpParser boolean true Ignore unknown HTTP headers.
# logFacility atom user Syslog facility to use.
# logFile atom (none) Log file (stderr if empty and logSyslog is unset, /var/log/polipo if empty and daemonise is true).
# logFilePermissions integer 0640 Access rights of the logFile.
# logSyslog boolean false Log to syslog.
# maxAge time 14d1h Max age for objects without Expires header.
# maxAgeFraction float 0.100000 Fresh fraction of modification time.
# maxConnectionAge time 21m Maximum age of a server-side connection.
# maxConnectionRequests integer 400 Maximum number of requests on a server-side connection.
# maxDiskCacheEntrySize integer -1 Maximum size of objects cached on disk.
# maxDiskEntries integer 32 File descriptors used by the on-disk cache.
# maxExpiresAge time 30d1h Max age for objects with Expires header.
# maxNoModifiedAge time 23m Max age for objects without Last-modified.
# maxObjectsWhenIdle integer 32 Number of objects to write at a time when idle.
# maxPipelineTrain integer 10 Maximum number of requests pipelined at a time.
# maxSideBuffering integer 1500 Maximum buffering for PUT and POST requests.
# maxWriteoutWhenIdle integer 65536 Amount of data to write at a time when idle.
# mindlesslyCacheVary boolean false If true, mindlessly cache negotiated objects.
# objectHashTableSize integer 32768 Size of the object hash table (0 = auto).
# objectHighMark integer 2048 High object count mark.
# parentAuthCredentials atom (hidden) username:password.
# parentProxy atom (none) Parent proxy (host:port).
# pidFile atom (none) File with pid of running daemon.
# pipelineAdditionalRequests tristate maybe Pipeline requests on an active connection.
# pmmFirstSize integer 0 The size of the first PMM chunk.
# pmmSize integer 0 The size of a PMM chunk.
# preciseExpiry boolean false Whether to consider all files for purging.
# proxyAddress atom 127.0.0.1 The IP address on which the proxy listens.
# proxyName atom shodan.local The name by which the proxy is known.
# proxyOffline boolean false Avoid contacting remote servers.
# proxyPort integer 8123 The TCP port on which the proxy listens.
# publicObjectLowMark integer 1024 Low object count mark (0 = auto).
# redirector atom (none) Squid-style redirector.
# redirectorRedirectCode integer 302 Redirect code to use with redirector.
# relaxTransparency tristate false Avoid contacting remote servers.
# replyUnpipelineSize integer 1048576 Size for a pipeline break.
# replyUnpipelineTime time 20s Estimated time for a pipeline break.
# serverExpireTime time 1d Time during which server data is valid.
# serverIdleTimeout time 45s Server-side idle timeout.
# serverMaxSlots integer 8 Maximum number of connections per broken server.
# serverSlots integer 2 Maximum number of connections per server.
# serverSlots1 integer 4 Maximum number of connections per HTTP/1.0 server.
# serverTimeout time 1m30s Server-side timeout.
# smallRequestTime time 10s Estimated time for a small request.
# socksParentProxy atom (none) SOCKS parent proxy (host:port)
# socksUserName atom (empty) SOCKS4a user name
# tunnelAllowedPorts intlist 22, 80, 109-110, 143, 443, 873, 993, 995, 2401, 5222-5223, 9418 Ports to which tunnelled connections are allowed.
# uncachableFile atom (none) File specifying uncachable URLs.

2
iProxy

Submodule iProxy updated: f35b239459...ec75e2820d