mirror of
https://github.com/qinyuhang/ShadowsocksX-NG-R.git
synced 2026-10-20 14:34:30 +00:00
fix add server from QR code
fix add server from QR code
This commit is contained in:
@@ -825,6 +825,7 @@
|
||||
"$(inherited)",
|
||||
"$(SDKROOT)/usr/lib/system",
|
||||
"$(PROJECT_DIR)/ShadowsocksX-NG",
|
||||
"$(PROJECT_DIR)",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.10;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.qiuyuzhou.ShadowsocksX-NG";
|
||||
@@ -851,6 +852,7 @@
|
||||
"$(inherited)",
|
||||
"$(SDKROOT)/usr/lib/system",
|
||||
"$(PROJECT_DIR)/ShadowsocksX-NG",
|
||||
"$(PROJECT_DIR)",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.10;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.qiuyuzhou.ShadowsocksX-NG";
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.2</string>
|
||||
<string>1.2.R</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleURLTypes</key>
|
||||
@@ -34,6 +34,18 @@
|
||||
<string>ss</string>
|
||||
</array>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Viewer</string>
|
||||
<key>CFBundleURLIconFile</key>
|
||||
<string>menu_icon@2x</string>
|
||||
<key>CFBundleURLName</key>
|
||||
<string>shadowsocks</string>
|
||||
<key>CFBundleURLSchemes</key>
|
||||
<array>
|
||||
<string>ssr</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
|
||||
@@ -10,4 +10,5 @@ import Foundation
|
||||
|
||||
let NOTIFY_SERVER_PROFILES_CHANGED = "NOTIFY_SERVER_PROFILES_CHANGED"
|
||||
let NOTIFY_ADV_PROXY_CONF_CHANGED = "NOTIFY_ADV_PROXY_CONF_CHANGED"
|
||||
let NOTIFY_ADV_CONF_CHANGED = "NOTIFY_ADV_CONF_CHANGED"
|
||||
let NOTIFY_ADV_CONF_CHANGED = "NOTIFY_ADV_CONF_CHANGED"
|
||||
let NOTIFY_INVALIDE_QR = "NOTIFY_INVALIDE_QR"
|
||||
@@ -39,24 +39,20 @@ class ServerProfile: NSObject {
|
||||
profile.serverPort = (data["ServerPort"] as! NSNumber).unsignedShortValue
|
||||
profile.method = data["Method"] as! String
|
||||
profile.password = data["Password"] as! String
|
||||
profile.ssrObfs = data["ssrObfs"] as! String
|
||||
profile.ssrObfsParam = data["ssrObfsParam"] as! String
|
||||
profile.ssrProtocol = data["ssrProtocol"] as! String
|
||||
profile.ssrProtocolParam = data["ssrProtocolParam"] as! String
|
||||
|
||||
if let remark = data["Remark"] {
|
||||
profile.remark = remark as! String
|
||||
}
|
||||
if let ota = data["OTA"] {
|
||||
profile.ota = ota as! Bool
|
||||
}
|
||||
if let ssrProtocol = data["ssrProtocol"]{
|
||||
profile.ssrProtocol = ssrProtocol as! String
|
||||
}
|
||||
if let ssrProtocolParam = data["ssrProtocolParam"]{
|
||||
profile.ssrProtocolParam = ssrProtocolParam as! String
|
||||
}
|
||||
if let ssrObfs = data["ssrObfs"]{
|
||||
profile.ssrObfs = ssrObfs as! String
|
||||
}
|
||||
if let ssrObfsParam = data["ssrObfsParam"]{
|
||||
profile.ssrObfsParam = ssrObfsParam as! String
|
||||
}
|
||||
}
|
||||
|
||||
if let id = data["Id"] as? String {
|
||||
@@ -151,7 +147,7 @@ class ServerProfile: NSObject {
|
||||
}
|
||||
|
||||
func URL() -> NSURL? {
|
||||
if(ssrObfs==""){
|
||||
if(ssrObfs=="plain"){
|
||||
let parts = "\(method):\(password)@\(serverHost):\(serverPort)"
|
||||
let base64String = parts.dataUsingEncoding(NSUTF8StringEncoding)?
|
||||
.base64EncodedStringWithOptions(NSDataBase64EncodingOptions())
|
||||
|
||||
+87
-6
@@ -53,7 +53,7 @@ void ScanQRCodeOnScreen() {
|
||||
CGImageRef image = CGDisplayCreateImage(displays[displaysIndex]);
|
||||
NSArray *features = [detector featuresInImage:[CIImage imageWithCGImage:image]];
|
||||
for (CIQRCodeFeature *feature in features) {
|
||||
NSLog(@"%@", feature.messageString);
|
||||
// NSLog(@"%@", feature.messageString);
|
||||
if ( [feature.messageString hasPrefix:@"ss://"] )
|
||||
{
|
||||
[foundSSUrls addObject:[NSURL URLWithString:feature.messageString]];
|
||||
@@ -77,7 +77,6 @@ void ScanQRCodeOnScreen() {
|
||||
// 解析SS URL,如果成功则返回一个与ServerProfile类兼容的dict
|
||||
// 或SSR URL,ServerProfile类已经默认添加SSR参数,默认放空,如果URL为SSR://则改变解析方法
|
||||
// ss:// + base64(method:password@domain:port)
|
||||
// ssr:// + base64(abc.xyz:12345:auth_sha1_v2:rc4-md5:tls1.2_ticket_auth:{base64(password)}/?obfsparam={base64(混淆参数(网址))}&remarks={base64(节点名称)})
|
||||
NSDictionary<NSString *, id>* ParseSSURL(NSURL* url) {
|
||||
if (!url.host) {
|
||||
return nil;
|
||||
@@ -86,7 +85,7 @@ NSDictionary<NSString *, id>* ParseSSURL(NSURL* url) {
|
||||
NSString *urlString = [url absoluteString];
|
||||
int i = 0;
|
||||
NSString *errorReason = nil;
|
||||
if([[NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:NULL ] hasPrefix:@"ss://"]){
|
||||
if([urlString hasPrefix:@"ss://"]){
|
||||
while(i < 2) {
|
||||
if (i == 1) {
|
||||
NSString* host = url.host;
|
||||
@@ -136,8 +135,90 @@ NSDictionary<NSString *, id>* ParseSSURL(NSURL* url) {
|
||||
};
|
||||
}
|
||||
|
||||
}else if ([[NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:NULL ] hasPrefix:@"ssr://"]){
|
||||
NSLog(@"Have One ssr QR coming");
|
||||
}else if ([urlString hasPrefix:@"ssr://"]){
|
||||
// ssr:// + base64(abc.xyz:12345:auth_sha1_v2:rc4-md5:tls1.2_ticket_auth:{base64(password)}/?obfsparam={base64(混淆参数(网址))}&remarks={base64(节点名称)})
|
||||
urlString = [urlString stringByReplacingOccurrencesOfString:@"ssr://" withString:@"" options:NSAnchoredSearch range:NSMakeRange(0, urlString.length)];
|
||||
NSData *data = [[NSData alloc] initWithBase64EncodedString:urlString options:0];
|
||||
NSString *decodedString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
urlString = decodedString;
|
||||
|
||||
if (data == NULL) {
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName:@"NOTIFY_INVALIDE_QR"
|
||||
object:nil
|
||||
userInfo: @{ @"urls": @"配置二维码无效!",
|
||||
@"source": @"qrcode"
|
||||
}
|
||||
];
|
||||
}else{
|
||||
NSRange paramSplit = [decodedString rangeOfString:@"?"];
|
||||
NSString *firstParam = [decodedString substringToIndex:paramSplit.location-1];
|
||||
NSString *lastParam = [decodedString substringFromIndex:paramSplit.location];
|
||||
lastParam = [lastParam substringFromIndex:1];
|
||||
|
||||
NSArray *lastParamArray = [lastParam componentsSeparatedByString:@"&"];
|
||||
NSMutableDictionary *parserLastParamDict = [[NSMutableDictionary alloc]init];
|
||||
for (int i=0; i<lastParamArray.count; i++) {
|
||||
NSString *toSplitString = lastParamArray[i];
|
||||
NSRange lastParamSplit = [toSplitString rangeOfString:@"="];
|
||||
if (lastParamSplit.location != NSNotFound) {
|
||||
NSString *key = [toSplitString substringToIndex:lastParamSplit.location];
|
||||
NSString *value = [[NSString alloc] initWithData:[[NSData alloc] initWithBase64EncodedString:[toSplitString substringFromIndex:lastParamSplit.location+1] options:0]encoding:NSUTF8StringEncoding];
|
||||
// NSString *value = [toSplitString substringFromIndex:lastParamSplit.location+1];
|
||||
[parserLastParamDict setValue: value forKey: key];
|
||||
}
|
||||
}
|
||||
NSLog(@"parserLastParamDict is %@",parserLastParamDict);
|
||||
|
||||
//后面已经parser完成,接下来需要解析到profile里面
|
||||
//abc.xyz:12345:auth_sha1_v2:rc4-md5:tls1.2_ticket_auth:{base64(password)}
|
||||
NSRange range = [firstParam rangeOfString:@":"];
|
||||
NSString *ip = [firstParam substringToIndex:range.location];//第一个参数是域名
|
||||
|
||||
firstParam = [firstParam substringFromIndex:range.location + range.length];
|
||||
range = [firstParam rangeOfString:@":"];
|
||||
NSString *port = [firstParam substringToIndex:range.location];//第二个参数是端口
|
||||
|
||||
firstParam = [firstParam substringFromIndex:range.location + range.length];
|
||||
range = [firstParam rangeOfString:@":"];
|
||||
NSString *ssrProtocol = [firstParam substringToIndex:range.location];//第三个参数是协议
|
||||
|
||||
firstParam = [firstParam substringFromIndex:range.location + range.length];
|
||||
range = [firstParam rangeOfString:@":"];
|
||||
NSString *encryption = [firstParam substringToIndex:range.location];//第四个参数是加密
|
||||
|
||||
firstParam = [firstParam substringFromIndex:range.location + range.length];
|
||||
range = [firstParam rangeOfString:@":"];
|
||||
NSString *ssrObfs = [firstParam substringToIndex:range.location];//第五个参数是混淆协议
|
||||
|
||||
firstParam = [firstParam substringFromIndex:range.location + range.length];
|
||||
// range = [firstParam rangeOfString:@":"];
|
||||
NSString *password = [[NSString alloc] initWithData:[[NSData alloc] initWithBase64EncodedString:firstParam options:0]encoding:NSUTF8StringEncoding];//第五个参数是base64密码
|
||||
|
||||
NSString *ssrObfsParam = @"";
|
||||
NSString *remarks = @"";
|
||||
NSString *ssrProtocolParam = @"";
|
||||
for (NSString *key in parserLastParamDict) {
|
||||
NSLog(@"key: %@ value: %@", key, parserLastParamDict[key]);
|
||||
if ([key isEqual: @"obfsparam"]) {
|
||||
ssrObfsParam = parserLastParamDict[key];
|
||||
} else if ([key isEqual: @"remarks"]) {
|
||||
remarks = parserLastParamDict[key];
|
||||
} else if([key isEqual:@"protocolparam"]){
|
||||
ssrProtocolParam = parserLastParamDict[key];
|
||||
}
|
||||
}
|
||||
|
||||
return @{@"ServerHost":ip,
|
||||
@"ServerPort": @([port integerValue]),
|
||||
@"Method": encryption,
|
||||
@"Password": password,
|
||||
@"ssrObfs":ssrObfs,
|
||||
@"ssrObfsParam":ssrObfsParam,
|
||||
@"ssrProtocol":ssrProtocol,
|
||||
@"ssrProtocolParam":ssrProtocolParam,
|
||||
};
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
return nil;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user