NCSettings.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. //
  2. // NCSettings.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 24/11/14.
  6. // Copyright (c) 2014 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "NCSettings.h"
  24. #import "CCAdvanced.h"
  25. #import "CCManageAccount.h"
  26. #import "CCManageAutoUpload.h"
  27. #import "NCManageEndToEndEncryption.h"
  28. #import "NCBridgeSwift.h"
  29. #import "NSNotificationCenter+MainThread.h"
  30. #import <LocalAuthentication/LocalAuthentication.h>
  31. #import <TOPasscodeViewController/TOPasscodeViewController.h>
  32. #define alertViewEsci 1
  33. #define alertViewAzzeraCache 2
  34. @interface NCSettings () <TOPasscodeSettingsViewControllerDelegate, TOPasscodeViewControllerDelegate>
  35. {
  36. AppDelegate *appDelegate;
  37. TOPasscodeViewController *passcodeViewController;
  38. TOPasscodeSettingsViewController *passcodeSettingsViewController;
  39. }
  40. @end
  41. @implementation NCSettings
  42. - (void)initializeForm
  43. {
  44. XLFormDescriptor *form = [XLFormDescriptor formDescriptor];
  45. XLFormSectionDescriptor *section;
  46. XLFormRowDescriptor *row;
  47. //NSInteger serverVersionMajor = [[NCManageDatabase shared] getCapabilitiesServerIntWithAccount:appDelegate.account elements:NCElementsJSON.shared.capabilitiesVersionMajor];
  48. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  49. // Section AUTO UPLOAD OF CAMERA IMAGES ----------------------------
  50. section = [XLFormSectionDescriptor formSection];
  51. [form addFormSection:section];
  52. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUpload" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_settings_autoupload_", nil)];
  53. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  54. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  55. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  56. [row.cellConfig setObject:[[UIImage imageNamed:@"autoUpload"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  57. row.action.viewControllerClass = [CCManageAutoUpload class];
  58. [section addFormRow:row];
  59. // Section : LOCK --------------------------------------------------------------
  60. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_lock_", nil)];
  61. [form addFormSection:section];
  62. // Lock active YES/NO
  63. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"bloccopasscode" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_lock_not_active_", nil)];
  64. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  65. [row.cellConfig setObject:[[UIImage imageNamed:@"lock.open"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  66. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  67. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  68. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  69. //[row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  70. row.action.formSelector = @selector(passcode:);
  71. [section addFormRow:row];
  72. // Enable Touch ID
  73. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"enableTouchDaceID" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_enable_touch_face_id_", nil)];
  74. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  75. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  76. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  77. [section addFormRow:row];
  78. // Lock no screen
  79. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"notPasscodeAtStart" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_no_screen_", nil)];
  80. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  81. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  82. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  83. [section addFormRow:row];
  84. // Section : E2EEncryption --------------------------------------------------------------
  85. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_e2e_settings_title_", nil)];
  86. [form addFormSection:section];
  87. // EndToEnd Encryption
  88. NSString *title = [NSString stringWithFormat:@"%@ (%@)",NSLocalizedString(@"_e2e_settings_", nil), NSLocalizedString(@"_experimental_", nil)];
  89. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"e2eEncryption" rowType:XLFormRowDescriptorTypeButton title:title];
  90. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  91. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  92. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  93. [row.cellConfig setObject:[[UIImage imageNamed:@"lock"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  94. row.action.viewControllerClass = [NCManageEndToEndEncryption class];
  95. [section addFormRow:row];
  96. // Section Advanced -------------------------------------------------
  97. section = [XLFormSectionDescriptor formSection];
  98. [form addFormSection:section];
  99. // Advanced
  100. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"advanced" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_advanced_", nil)];
  101. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  102. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  103. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  104. [row.cellConfig setObject:[[UIImage imageNamed:@"gear"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  105. row.action.viewControllerClass = [CCAdvanced class];
  106. [section addFormRow:row];
  107. // Section : INFORMATION ------------------------------------------------
  108. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_information_", nil)];
  109. [form addFormSection:section];
  110. // Acknowledgements
  111. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"buttonLeftAligned" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_acknowledgements_", nil)];
  112. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  113. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  114. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  115. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  116. [row.cellConfig setObject:[[UIImage imageNamed:@"acknowledgements"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  117. row.action.formBlock = ^(XLFormRowDescriptor * sender){
  118. [self performSegueWithIdentifier:@"AcknowledgementsSegue" sender:sender];
  119. [self deselectFormRow:sender];
  120. };
  121. [section addFormRow:row];
  122. if (!NCBrandOptions.shared.disable_crash_service) {
  123. // Privacy
  124. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"privacy" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_privacy_", nil)];
  125. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  126. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  127. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  128. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  129. [row.cellConfig setObject:[[UIImage imageNamed:@"shield.checkerboard"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  130. row.action.formSelector = @selector(privacy:);
  131. [section addFormRow:row];
  132. // Source code
  133. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sourcecode" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_source_code_", nil)];
  134. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
  135. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  136. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  137. [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
  138. [row.cellConfig setObject:[[UIImage imageNamed:@"gitHub"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  139. row.action.formSelector = @selector(sourceCode:);
  140. [section addFormRow:row];
  141. }
  142. self.tableView.showsVerticalScrollIndicator = NO;
  143. self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 35, 0);
  144. self.form = form;
  145. }
  146. // MARK: - View Life Cycle
  147. - (void)viewDidLoad
  148. {
  149. [super viewDidLoad];
  150. self.title = NSLocalizedString(@"_settings_", nil);
  151. self.view.backgroundColor = NCBrandColor.shared.systemGroupedBackground;
  152. self.tableView.backgroundColor = NCBrandColor.shared.systemGroupedBackground;
  153. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  154. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground) name:NCGlobal.shared.notificationCenterApplicationDidEnterBackground object:nil];
  155. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initialize) name:NCGlobal.shared.notificationCenterInitialize object:nil];
  156. [self initializeForm];
  157. [self reloadForm];
  158. }
  159. - (void)viewWillAppear:(BOOL)animated
  160. {
  161. [super viewWillAppear:animated];
  162. appDelegate.activeViewController = self;
  163. }
  164. #pragma mark - NotificationCenter
  165. - (void)initialize
  166. {
  167. [self initializeForm];
  168. [self reloadForm];
  169. }
  170. - (void)applicationDidEnterBackground
  171. {
  172. if (passcodeViewController.view.window != nil) {
  173. [passcodeViewController dismissViewControllerAnimated:true completion:nil];
  174. }
  175. if (passcodeSettingsViewController.view.window != nil) {
  176. [passcodeSettingsViewController dismissViewControllerAnimated:true completion:nil];
  177. }
  178. }
  179. #pragma mark -
  180. - (void)reloadForm
  181. {
  182. self.form.delegate = nil;
  183. // ------------------------------------------------------------------
  184. XLFormRowDescriptor *rowBloccoPasscode = [self.form formRowWithTag:@"bloccopasscode"];
  185. XLFormRowDescriptor *rowNotPasscodeAtStart = [self.form formRowWithTag:@"notPasscodeAtStart"];
  186. XLFormRowDescriptor *rowEnableTouchDaceID = [self.form formRowWithTag:@"enableTouchDaceID"];
  187. // ------------------------------------------------------------------
  188. if ([[CCUtility getPasscode] length]) {
  189. rowBloccoPasscode.title = NSLocalizedString(@"_lock_active_", nil);
  190. [rowBloccoPasscode.cellConfig setObject:[[UIImage imageNamed:@"lock"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  191. } else {
  192. rowBloccoPasscode.title = NSLocalizedString(@"_lock_not_active_", nil);
  193. [rowBloccoPasscode.cellConfig setObject:[[UIImage imageNamed:@"lock.open"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
  194. }
  195. if ([CCUtility getEnableTouchFaceID]) [rowEnableTouchDaceID setValue:@1]; else [rowEnableTouchDaceID setValue:@0];
  196. if ([CCUtility getNotPasscodeAtStart]) [rowNotPasscodeAtStart setValue:@1]; else [rowNotPasscodeAtStart setValue:@0];
  197. // -----------------------------------------------------------------
  198. [self.tableView reloadData];
  199. self.form.delegate = self;
  200. }
  201. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  202. {
  203. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  204. if ([rowDescriptor.tag isEqualToString:@"notPasscodeAtStart"]) {
  205. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  206. [CCUtility setNotPasscodeAtStart:true];
  207. } else {
  208. [CCUtility setNotPasscodeAtStart:false];
  209. }
  210. }
  211. if ([rowDescriptor.tag isEqualToString:@"enableTouchDaceID"]) {
  212. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  213. [CCUtility setEnableTouchFaceID:true];
  214. } else {
  215. [CCUtility setEnableTouchFaceID:false];
  216. }
  217. }
  218. }
  219. #pragma mark -
  220. - (void)privacy:(XLFormRowDescriptor *)sender
  221. {
  222. [self deselectFormRow:sender];
  223. NCBrowserWeb* browserWebVC = [[UIStoryboard storyboardWithName:@"NCBrowserWeb" bundle:nil] instantiateInitialViewController];
  224. browserWebVC.urlBase = NCBrandOptions.shared.privacy;
  225. browserWebVC.isHiddenButtonExit = false;
  226. browserWebVC.titleBrowser = NSLocalizedString(@"_privacy_", nil);
  227. [self presentViewController:browserWebVC animated:YES completion:nil];
  228. }
  229. - (void)sourceCode:(XLFormRowDescriptor *)sender
  230. {
  231. [self deselectFormRow:sender];
  232. NCBrowserWeb* browserWebVC = [[UIStoryboard storyboardWithName:@"NCBrowserWeb" bundle:nil] instantiateInitialViewController];
  233. browserWebVC.urlBase = NCBrandOptions.shared.sourceCode;
  234. browserWebVC.isHiddenButtonExit = false;
  235. browserWebVC.titleBrowser = NSLocalizedString(@"_source_code_", nil);
  236. [self presentViewController:browserWebVC animated:YES completion:nil];
  237. }
  238. #pragma mark - Passcode
  239. - (void)didPerformBiometricValidationRequestInPasscodeViewController:(TOPasscodeViewController *)passcodeViewController
  240. {
  241. [[LAContext new] evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:[[NCBrandOptions shared] brand] reply:^(BOOL success, NSError * _Nullable error) {
  242. if (success) {
  243. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  244. [CCUtility setPasscode:@""];
  245. [passcodeViewController dismissViewControllerAnimated:YES completion:nil];
  246. [self reloadForm];
  247. });
  248. }
  249. }];
  250. }
  251. - (void)passcodeSettingsViewController:(TOPasscodeSettingsViewController *)passcodeSettingsViewController didChangeToNewPasscode:(NSString *)passcode ofType:(TOPasscodeType)type
  252. {
  253. [CCUtility setPasscode:passcode];
  254. [passcodeSettingsViewController dismissViewControllerAnimated:YES completion:nil];
  255. [self reloadForm];
  256. }
  257. - (void)didTapCancelInPasscodeViewController:(TOPasscodeViewController *)passcodeViewController
  258. {
  259. [passcodeViewController dismissViewControllerAnimated:YES completion:nil];
  260. }
  261. - (BOOL)passcodeViewController:(TOPasscodeViewController *)passcodeViewController isCorrectCode:(NSString *)code
  262. {
  263. if ([code isEqualToString:[CCUtility getPasscode]]) {
  264. [CCUtility setPasscode:@""];
  265. [self reloadForm];
  266. return YES;
  267. }
  268. return NO;
  269. }
  270. - (void)passcode:(XLFormRowDescriptor *)sender
  271. {
  272. LAContext *laContext = [LAContext new];
  273. NSError *error;
  274. [self deselectFormRow:sender];
  275. if ([[CCUtility getPasscode] length] == 0) {
  276. passcodeSettingsViewController = [[TOPasscodeSettingsViewController alloc] init];
  277. passcodeSettingsViewController.hideOptionsButton = YES;
  278. passcodeSettingsViewController.requireCurrentPasscode = NO;
  279. passcodeSettingsViewController.passcodeType = TOPasscodeTypeSixDigits;
  280. passcodeSettingsViewController.delegate = self;
  281. [self presentViewController:passcodeSettingsViewController animated:YES completion:nil];
  282. } else {
  283. passcodeViewController = [[TOPasscodeViewController alloc] initPasscodeType:TOPasscodeTypeSixDigits allowCancel:true];
  284. passcodeViewController.delegate = self;
  285. passcodeViewController.keypadButtonShowLettering = false;
  286. if (CCUtility.getEnableTouchFaceID && [laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
  287. if (error == NULL) {
  288. if (laContext.biometryType == LABiometryTypeFaceID) {
  289. passcodeViewController.biometryType = TOPasscodeBiometryTypeFaceID;
  290. passcodeViewController.allowBiometricValidation = true;
  291. passcodeViewController.automaticallyPromptForBiometricValidation = true;
  292. } else if (laContext.biometryType == LABiometryTypeTouchID) {
  293. passcodeViewController.biometryType = TOPasscodeBiometryTypeTouchID;
  294. passcodeViewController.allowBiometricValidation = true;
  295. passcodeViewController.automaticallyPromptForBiometricValidation = true;
  296. } else {
  297. NSLog(@"No Biometric support");
  298. }
  299. }
  300. }
  301. [self presentViewController:passcodeViewController animated:YES completion:nil];
  302. }
  303. }
  304. #pragma mark -
  305. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  306. return NCGlobal.shared.heightCellSettings;
  307. }
  308. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
  309. {
  310. NSString *sectionName;
  311. switch (section)
  312. {
  313. case 1: {
  314. sectionName = NSLocalizedString(@"_lock_protection_no_screen_footer_", nil);
  315. }
  316. break;
  317. case 4: {
  318. NSString *versionServer = [[NCManageDatabase shared] getCapabilitiesServerStringWithAccount:appDelegate.account elements:NCElementsJSON.shared.capabilitiesVersionString];
  319. NSString *themingName = [[NCManageDatabase shared] getCapabilitiesServerStringWithAccount:appDelegate.account elements:NCElementsJSON.shared.capabilitiesThemingName];
  320. NSString *themingSlogan = [[NCManageDatabase shared] getCapabilitiesServerStringWithAccount:appDelegate.account elements:NCElementsJSON.shared.capabilitiesThemingSlogan];
  321. NSString *versionNextcloud = [NSString stringWithFormat:[NCBrandOptions shared].textCopyrightNextcloudServer, versionServer];
  322. NSString *versionNextcloudiOS = [NSString stringWithFormat:[NCBrandOptions shared].textCopyrightNextcloudiOS, NCUtility.shared.getVersionApp];
  323. NSString *nameSlogan = [NSString stringWithFormat:@"%@ - %@", themingName, themingSlogan];
  324. sectionName = [NSString stringWithFormat:@"\n%@\n\n%@\n%@", versionNextcloudiOS, versionNextcloud, nameSlogan];
  325. }
  326. break;
  327. }
  328. return sectionName;
  329. }
  330. @end