diff --git a/.gitignore b/.gitignore index 195efe9..241cf6a 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ DerivedData Pods *.pem +KeepMeConnected/KeepMeConnected.app/ diff --git a/KeepMeConnected.xcodeproj/project.pbxproj b/KeepMeConnected.xcodeproj/project.pbxproj index cfae7bb..c686360 100644 --- a/KeepMeConnected.xcodeproj/project.pbxproj +++ b/KeepMeConnected.xcodeproj/project.pbxproj @@ -326,6 +326,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.12; + MARKETING_VERSION = 1.0.2; PRODUCT_BUNDLE_IDENTIFIER = net.laverse.KeepMeConnected; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 4.2; @@ -344,6 +345,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.12; + MARKETING_VERSION = 1.0.2; PRODUCT_BUNDLE_IDENTIFIER = net.laverse.KeepMeConnected; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 4.2; diff --git a/KeepMeConnected/Info.plist b/KeepMeConnected/Info.plist index af2e8ee..0b112d5 100644 --- a/KeepMeConnected/Info.plist +++ b/KeepMeConnected/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0.1 + $(MARKETING_VERSION) CFBundleVersion 1 LSApplicationCategoryType diff --git a/KeepMeConnected/WatchGuard.swift b/KeepMeConnected/WatchGuard.swift index 6be2ddb..989487b 100644 --- a/KeepMeConnected/WatchGuard.swift +++ b/KeepMeConnected/WatchGuard.swift @@ -59,37 +59,42 @@ class WatchGuard: NSObject { request.timeoutInterval = 3 request.httpMethod = "POST" - // Body - request.httpBody = "action=fw_logon&fw_domain=\(userDomain)&fw_logon_type=logon&fw_username=\(userName)&fw_password=\(userPassword)&lang=en-US&submit=Login".data(using: String.Encoding.ascii, allowLossyConversion: false) - - // Headers - request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") - request.addValue("*/*", forHTTPHeaderField: "Accept") - request.addValue(WatchGuard.UserAgent, forHTTPHeaderField: "User-Agent") - - // Execute the request - let task = URLSession.shared.dataTask(with: request) { (data, response, error) in - if error != nil { - handler(WatchGuardLoginResponse.Error(error!.localizedDescription.dropSuffix("."))) - } else { - if let httpResponse = response as? HTTPURLResponse { - if httpResponse.url == portalUrl || httpResponse.url?.absoluteString.range(of:"success.shtml") != nil { - handler(WatchGuardLoginResponse.Success) - }else{ - if let errcode = URLComponents(string: httpResponse.url!.absoluteString)?.queryItems?.filter({$0.name == "errcode"}).first?.value { - os_log("Error on logon. Error (%@) '%@'",errcode,WatchGuard.getErrorCodeStr(errcode)) - handler(WatchGuardLoginResponse.Failed(WatchGuard.getErrorCodeStr(errcode))) + if let encodedUserDomain = userDomain.addingPercentEncoding(withAllowedCharacters:.alphanumerics), + let encodedUserName = userName.addingPercentEncoding(withAllowedCharacters:.alphanumerics), + let encodedUserPassword = userPassword.addingPercentEncoding(withAllowedCharacters:.alphanumerics) { + + // Body + request.httpBody = "action=fw_logon&fw_domain=\(encodedUserDomain)&fw_logon_type=logon&fw_username=\(encodedUserName)&fw_password=\(encodedUserPassword)&lang=en-US&submit=Login".data(using: String.Encoding.ascii, allowLossyConversion: false) + + // Headers + request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") + request.addValue("*/*", forHTTPHeaderField: "Accept") + request.addValue(WatchGuard.UserAgent, forHTTPHeaderField: "User-Agent") + + // Execute the request + let task = URLSession.shared.dataTask(with: request) { (data, response, error) in + if error != nil { + handler(WatchGuardLoginResponse.Error(error!.localizedDescription.dropSuffix("."))) + } else { + if let httpResponse = response as? HTTPURLResponse { + if httpResponse.url == portalUrl || httpResponse.url?.absoluteString.range(of:"success.shtml") != nil { + handler(WatchGuardLoginResponse.Success) }else{ - os_log("Error on logon. Wrong base '%@'",httpResponse.url!.absoluteString) - handler(WatchGuardLoginResponse.Error(String(format: "Missing errcode in redirection to '%@'",httpResponse.url!.absoluteString))) + if let errcode = URLComponents(string: httpResponse.url!.absoluteString)?.queryItems?.filter({$0.name == "errcode"}).first?.value { + os_log("Error on logon. Error (%@) '%@'",errcode,WatchGuard.getErrorCodeStr(errcode)) + handler(WatchGuardLoginResponse.Failed(WatchGuard.getErrorCodeStr(errcode))) + }else{ + os_log("Error on logon. Wrong base '%@'",httpResponse.url!.absoluteString) + handler(WatchGuardLoginResponse.Error(String(format: "Missing errcode in redirection to '%@'",httpResponse.url!.absoluteString))) + } } + }else{ + handler(WatchGuardLoginResponse.Error("No HTTPURLResponse was returned")) } - }else{ - handler(WatchGuardLoginResponse.Error("No HTTPURLResponse was returned")) } } + task.resume() } - task.resume() } func logout(portalUrl: URL,handler: @escaping (_: WatchGuardLogoutResponse) -> Void){