Marino Faggiana 7 жил өмнө
parent
commit
87994ee521

+ 5 - 0
iOSClient/CCGlobal.h

@@ -27,6 +27,8 @@ extern NSString *const appApplicationSupport;
 extern NSString *const appDatabaseNextcloud;
 extern NSString *const appCertificates;
 
+extern NSString *const serverStatus;
+
 extern NSString *const webDAV;
 extern NSString *const dav;
 
@@ -265,6 +267,9 @@ extern NSString *const flowEndpoint;
 // E2EE
 #define k_max_filesize_E2E                              524288000   // 500 MB
 
+// Flow Version
+#define k_flow_version_available                        12
+
 // -----------------------------------------------------------------------------------------------------------
 // -----------------------------------------------------------------------------------------------------------
 

+ 3 - 0
iOSClient/CCGlobal.m

@@ -28,6 +28,9 @@ NSString *const appApplicationSupport = @"Library/Application Support";
 NSString *const appDatabaseNextcloud = @"Library/Application Support/Nextcloud";
 NSString *const appCertificates = @"Library/Application Support/Certificates";
 
+// Server Status
+NSString *const serverStatus = @"/status.php";
+
 // webDAV & DAV
 NSString *const webDAV = @"/remote.php/webdav";
 NSString *const dav = @"/remote.php/dav";

+ 80 - 62
iOSClient/Login/CCLogin.m

@@ -31,6 +31,14 @@
 {
     AppDelegate *appDelegate;
     UIView *rootView;
+    
+    NSString *serverProductName;
+    NSString *serverVersion;
+    NSString *serverVersionString;
+    
+    NSInteger versionMajor;
+    NSInteger versionMicro;
+    NSInteger versionMinor;
 }
 @end
 
@@ -228,8 +236,8 @@
     if ([self.baseUrl.text hasSuffix:@"/"])
         self.baseUrl.text = [self.baseUrl.text substringToIndex:[self.baseUrl.text length] - 1];
     
-    // add webDAV for valid test url
-    NSString *urlTest = [self.baseUrl.text stringByAppendingString:webDAV];
+    // add status.php for valid test url
+    NSString *urlTest = [self.baseUrl.text stringByAppendingString:serverStatus];
     
     // Remove stored cookies
     NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
@@ -238,39 +246,49 @@
         [storage deleteCookie:cookie];
     }
     
-    // Test Login Flow
-    if ([self.baseUrl.text length] > 0 && _user.hidden && _password.hidden) {
-        
-        NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlTest] cachePolicy:0 timeoutInterval:20.0];
-        [request addValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];
-        [request addValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
+    NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlTest] cachePolicy:0 timeoutInterval:20.0];
+    [request addValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];
+    [request addValue:@"true" forHTTPHeaderField:@"OCS-APIRequest"];
 
-        NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
-        NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
+    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
+    NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
         
-        NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) {
+    NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) {
             
-            dispatch_async(dispatch_get_main_queue(), ^{
-                
-                self.login.enabled = YES;
-                self.loadingBaseUrl.hidden = YES;
+        dispatch_async(dispatch_get_main_queue(), ^{
                 
-                if (error) {
+            self.loadingBaseUrl.hidden = YES;
+            self.login.enabled = YES;
+            
+            if (error) {
                     
-                    if ([error code] == NSURLErrorServerCertificateUntrusted) {
+                if ([error code] == NSURLErrorServerCertificateUntrusted) {
                         
-                        [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:[error localizedDescription] viewController:self delegate:self];
+                    [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:[error localizedDescription] viewController:self delegate:self];
                         
-                    } else {
+                } else {
                         
-                        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_connection_error_", nil) message:[error localizedDescription] preferredStyle:UIAlertControllerStyleAlert];
-                        UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
+                    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_connection_error_", nil) message:[error localizedDescription] preferredStyle:UIAlertControllerStyleAlert];
+                    UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
                         
-                        [alertController addAction:okAction];
-                        [self presentViewController:alertController animated:YES completion:nil];
-                    }
+                    [alertController addAction:okAction];
+                    [self presentViewController:alertController animated:YES completion:nil];
+                }
 
-                } else {
+            } else {
+                    
+                if (![self serverStatus:data]) {
+                        
+                    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_serverstatus_error_", nil) message:[error localizedDescription] preferredStyle:UIAlertControllerStyleAlert];
+                    UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
+                        
+                    [alertController addAction:okAction];
+                    [self presentViewController:alertController animated:YES completion:nil];
+                    return;
+                }
+                
+                // Login Flow
+                if (_user.hidden && _password.hidden && versionMajor >= k_flow_version_available) {
                     
                     appDelegate.activeLoginWeb = [CCLoginWeb new];
                     appDelegate.activeLoginWeb.loginType = _loginType;
@@ -279,47 +297,24 @@
                     
                     [appDelegate.activeLoginWeb presentModalWithDefaultTheme:self];
                 }
-            });
-        }];
-        
-        [task resume];
-        
-    } else {
-    
-        NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlTest] cachePolicy:0 timeoutInterval:20.0];
-        [request addValue:[CCUtility getUserAgent] forHTTPHeaderField:@"User-Agent"];
-    
-        NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
-        NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
-    
-        NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) {
-        
-            dispatch_async(dispatch_get_main_queue(), ^{
-            
-                self.login.enabled = YES;
-                self.loadingBaseUrl.hidden = YES;
-        
-                if (error != nil) {
-        
-                    // self signed certificate
-                    if ([error code] == NSURLErrorServerCertificateUntrusted) {
-                        
-                        [[CCCertificate sharedManager] presentViewControllerCertificateWithTitle:[error localizedDescription] viewController:self delegate:self];
                 
-                    } else {
+                // NO Login Flow available
+                if (versionMajor < k_flow_version_available) {
                     
-                        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_connection_error_", nil) message:[error localizedDescription] preferredStyle:UIAlertControllerStyleAlert];
-                        UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
+                    [self.loginTypeView setHidden:YES];
+
+                    _imageUser.hidden = NO;
+                    _user.hidden = NO;
+                    _imagePassword.hidden = NO;
+                    _password.hidden = NO;
                     
-                        [alertController addAction:okAction];
-                        [self presentViewController:alertController animated:YES completion:nil];
-                    }
+                    [_user becomeFirstResponder];
                 }
-            });
-        }];
-    
-        [task resume];
-    }
+            }
+        });
+    }];
+        
+    [task resume];
 }
 
 - (void)trustedCerticateAccepted
@@ -344,6 +339,29 @@
     }
 }
 
+- (BOOL)serverStatus:(NSData *)data
+{
+    NSError *error;
+    NSDictionary *jsongParsed = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
+    
+    if (error) {
+        return false;
+    }
+    
+    serverProductName = [jsongParsed valueForKey:@"productname"];
+    serverVersion = [jsongParsed valueForKey:@"version"];
+    serverVersionString = [jsongParsed valueForKey:@"versionstring"];
+
+    NSArray *arrayVersion = [serverVersionString componentsSeparatedByString:@"."];
+    if (arrayVersion.count == 3) {
+        versionMajor = [arrayVersion[0] integerValue];
+        versionMicro = [arrayVersion[1] integerValue];
+        versionMinor = [arrayVersion[2] integerValue];
+    }
+    
+    return true;
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark == Login ==
 #pragma --------------------------------------------------------------------------------------------

+ 1 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -216,6 +216,7 @@
 
 "_connect_server_anyway_"       = "Do you want to connect to the server anyway?";
 "_connection_error_"            = "Connection error";
+"_serverstatus_error_"          = "Connection to server failure, verify your server address or network status";
 "_add_your_nextcloud_"          = "Add your Nextcloud account";
 "_login_url_"                   = "Server address https://…";
 "_login_bottom_label_"          = "Don't have a server yet?\nChoose one of the providers.";