Skip to content

Commit

Permalink
Merge branch 'issues/2524' of github.com:ooni/probe-ios into issues/2524
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed Oct 19, 2023
2 parents 762ae61 + 219a4b8 commit aec578c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
4 changes: 3 additions & 1 deletion ooniprobe/Utility/ProxySettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
typedef NS_ENUM(NSInteger, ProxyProtocol) {
NONE,
PSIPHON,
SOCKS5
SOCKS5,
HTTP,
HTTPS
};

@interface ProxySettings : NSObject
Expand Down
32 changes: 30 additions & 2 deletions ooniprobe/Utility/ProxySettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ - (id) init {
self.protocol = PSIPHON;
} else if ([protocol isEqualToString:[ProxySettings getProtocol:SOCKS5]]) {
self.protocol = SOCKS5;
} else if ([protocol isEqualToString:[ProxySettings getProtocol:HTTP]]) {
self.protocol = HTTP;
} else if ([protocol isEqualToString:[ProxySettings getProtocol:HTTPS]]) {
self.protocol = HTTPS;
} else {
// This is where we will extend the code to add support for
// more proxies, e.g., HTTP proxies.
Expand All @@ -30,7 +34,7 @@ - (void)saveProxy{
}

- (BOOL)isCustom{
if (self.protocol == SOCKS5)
if (self.protocol == SOCKS5 || self.protocol == HTTP || self.protocol == HTTPS)
return true;
return false;
}
Expand All @@ -49,6 +53,24 @@ - (NSString*)getProxyString{
//URI url = new URI(urlStr);
return urlStr;
}
if (self.protocol == HTTP) {
// Alright, we now need to construct a new SOCKS5 URL.
NSString *urlStr = [NSString stringWithFormat:@"http://%@:%@/", self.hostname, self.port];
if ([ProxySettings isIPv6:self.hostname]) {
urlStr = [NSString stringWithFormat:@"http://[%@]:%@/", self.hostname, self.port]; // IPv6 must be quoted in URLs
}
//URI url = new URI(urlStr);
return urlStr;
}
if (self.protocol == HTTPS) {
// Alright, we now need to construct a new SOCKS5 URL.
NSString *urlStr = [NSString stringWithFormat:@"https://%@:%@/", self.hostname, self.port];
if ([ProxySettings isIPv6:self.hostname]) {
urlStr = [NSString stringWithFormat:@"https://[%@]:%@/", self.hostname, self.port]; // IPv6 must be quoted in URLs
}
//URI url = new URI(urlStr);
return urlStr;
}
return @"";

}
Expand All @@ -69,7 +91,13 @@ + (NSString*)getProtocol:(ProxyProtocol) protocol {
result = @"proxy_psiphon";
break;
case SOCKS5:
result = @"SOCKS5";
result = @"socks5";
break;
case HTTP:
result = @"http";
break;
case HTTPS:
result = @"https";
break;
default:
result = @"unknown";
Expand Down
20 changes: 16 additions & 4 deletions ooniprobe/View/Settings/ProxyViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ - (void)reloadRows{
@[[ProxySettings getProtocol:NONE],
[ProxySettings getProtocol:PSIPHON],
@"proxy_custom"],
@[[ProxySettings getProtocol:SOCKS5]],
@[
[ProxySettings getProtocol:SOCKS5],
[ProxySettings getProtocol:HTTP],
[ProxySettings getProtocol:HTTPS]
],
@[@"proxy_hostname", @"proxy_port"]];
else
items = @[@[[ProxySettings getProtocol:NONE],
Expand Down Expand Up @@ -124,15 +128,23 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
else if (indexPath.row == 1)
currentProxy.protocol = PSIPHON;
if (indexPath.row == 2)
[self setCustom];
[self setCustom:SOCKS5];
[self reloadRows];
} else if (indexPath.section == 1){
if (indexPath.row == 0)
[self setCustom:SOCKS5];
else if (indexPath.row == 1)
[self setCustom:HTTP];
else if (indexPath.row == 2)
[self setCustom:HTTPS];
[self reloadRows];
}
//[self.view endEditing:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}

-(void)setCustom {
currentProxy.protocol = SOCKS5;
- (void)setCustom:(enum ProxyProtocol)protocol {
currentProxy.protocol = protocol;
}

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
Expand Down

0 comments on commit aec578c

Please sign in to comment.