NCSettings.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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.cellSettings;
  54. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  55. [row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
  56. [row.cellConfig setObject:[[UIImage imageNamed:@"autoUpload"] imageWithColor:NCBrandColor.shared.icon 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.cellSettings;
  65. [row.cellConfig setObject:[[UIImage imageNamed:@"lock.open"] imageWithColor:NCBrandColor.shared.icon size:25] forKey:@"imageView.image"];
  66. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  67. [row.cellConfig setObject:NCBrandColor.shared.textView 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.cellSettings;
  75. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  76. [row.cellConfig setObject:NCBrandColor.shared.textView 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.cellSettings;
  81. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  82. [row.cellConfig setObject:NCBrandColor.shared.textView 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.cellSettings;
  91. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  92. [row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
  93. [row.cellConfig setObject:[[UIImage imageNamed:@"lock"] imageWithColor:NCBrandColor.shared.icon 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.cellSettings;
  102. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  103. [row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
  104. [row.cellConfig setObject:[[UIImage imageNamed:@"gear"] imageWithColor:NCBrandColor.shared.icon 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.cellSettings;
  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.textView forKey:@"textLabel.textColor"];
  116. [row.cellConfig setObject:[[UIImage imageNamed:@"acknowledgements"] imageWithColor:NCBrandColor.shared.icon 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.cellSettings;
  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.textView forKey:@"textLabel.textColor"];
  129. [row.cellConfig setObject:[[UIImage imageNamed:@"shield.checkerboard"] imageWithColor:NCBrandColor.shared.icon 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.cellSettings;
  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.textView forKey:@"textLabel.textColor"];
  138. [row.cellConfig setObject:[[UIImage imageNamed:@"gitHub"] imageWithColor:NCBrandColor.shared.icon 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. #pragma mark - Life Cycle
  147. - (void)viewDidLoad
  148. {
  149. [super viewDidLoad];
  150. self.title = NSLocalizedString(@"_settings_", nil);
  151. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  152. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:NCGlobal.shared.notificationCenterChangeTheming object:nil];
  153. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground) name:NCGlobal.shared.notificationCenterApplicationDidEnterBackground object:nil];
  154. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initializeMain) name:NCGlobal.shared.notificationCenterInitializeMain object:nil];
  155. [self changeTheming];
  156. }
  157. - (void)viewWillAppear:(BOOL)animated
  158. {
  159. [super viewWillAppear:animated];
  160. appDelegate.activeViewController = self;
  161. [self initializeForm];
  162. [self reloadForm];
  163. }
  164. #pragma mark - NotificationCenter
  165. - (void)changeTheming
  166. {
  167. self.view.backgroundColor = NCBrandColor.shared.backgroundSettings;
  168. self.tableView.backgroundColor = NCBrandColor.shared.backgroundSettings;
  169. [self initializeForm];
  170. [self reloadForm];
  171. }
  172. - (void)initializeMain
  173. {
  174. [self initializeForm];
  175. [self reloadForm];
  176. }
  177. - (void)applicationDidEnterBackground
  178. {
  179. if (passcodeViewController.view.window != nil) {
  180. [passcodeViewController dismissViewControllerAnimated:true completion:nil];
  181. }
  182. if (passcodeSettingsViewController.view.window != nil) {
  183. [passcodeSettingsViewController dismissViewControllerAnimated:true completion:nil];
  184. }
  185. }
  186. #pragma mark -
  187. - (void)reloadForm
  188. {
  189. self.form.delegate = nil;
  190. // ------------------------------------------------------------------
  191. XLFormRowDescriptor *rowBloccoPasscode = [self.form formRowWithTag:@"bloccopasscode"];
  192. XLFormRowDescriptor *rowNotPasscodeAtStart = [self.form formRowWithTag:@"notPasscodeAtStart"];
  193. XLFormRowDescriptor *rowEnableTouchDaceID = [self.form formRowWithTag:@"enableTouchDaceID"];
  194. // ------------------------------------------------------------------
  195. if ([[CCUtility getPasscode] length]) {
  196. rowBloccoPasscode.title = NSLocalizedString(@"_lock_active_", nil);
  197. [rowBloccoPasscode.cellConfig setObject:[[UIImage imageNamed:@"lock"] imageWithColor:NCBrandColor.shared.icon size:25] forKey:@"imageView.image"];
  198. } else {
  199. rowBloccoPasscode.title = NSLocalizedString(@"_lock_not_active_", nil);
  200. [rowBloccoPasscode.cellConfig setObject:[[UIImage imageNamed:@"lock.open"] imageWithColor:NCBrandColor.shared.icon size:25] forKey:@"imageView.image"];
  201. }
  202. if ([CCUtility getEnableTouchFaceID]) [rowEnableTouchDaceID setValue:@1]; else [rowEnableTouchDaceID setValue:@0];
  203. if ([CCUtility getNotPasscodeAtStart]) [rowNotPasscodeAtStart setValue:@1]; else [rowNotPasscodeAtStart setValue:@0];
  204. // -----------------------------------------------------------------
  205. [self.tableView reloadData];
  206. self.form.delegate = self;
  207. }
  208. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  209. {
  210. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  211. if ([rowDescriptor.tag isEqualToString:@"notPasscodeAtStart"]) {
  212. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  213. [CCUtility setNotPasscodeAtStart:true];
  214. } else {
  215. [CCUtility setNotPasscodeAtStart:false];
  216. }
  217. }
  218. if ([rowDescriptor.tag isEqualToString:@"enableTouchDaceID"]) {
  219. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  220. [CCUtility setEnableTouchFaceID:true];
  221. } else {
  222. [CCUtility setEnableTouchFaceID:false];
  223. }
  224. }
  225. }
  226. #pragma mark -
  227. - (void)privacy:(XLFormRowDescriptor *)sender
  228. {
  229. [self deselectFormRow:sender];
  230. NCBrowserWeb* browserWebVC = [[UIStoryboard storyboardWithName:@"NCBrowserWeb" bundle:nil] instantiateInitialViewController];
  231. browserWebVC.urlBase = NCBrandOptions.shared.privacy;
  232. browserWebVC.isHiddenButtonExit = false;
  233. browserWebVC.titleBrowser = NSLocalizedString(@"_privacy_", nil);
  234. [self presentViewController:browserWebVC animated:YES completion:nil];
  235. }
  236. - (void)sourceCode:(XLFormRowDescriptor *)sender
  237. {
  238. [self deselectFormRow:sender];
  239. NCBrowserWeb* browserWebVC = [[UIStoryboard storyboardWithName:@"NCBrowserWeb" bundle:nil] instantiateInitialViewController];
  240. browserWebVC.urlBase = NCBrandOptions.shared.sourceCode;
  241. browserWebVC.isHiddenButtonExit = false;
  242. browserWebVC.titleBrowser = NSLocalizedString(@"_source_code_", nil);
  243. [self presentViewController:browserWebVC animated:YES completion:nil];
  244. }
  245. #pragma mark - Passcode
  246. - (void)didPerformBiometricValidationRequestInPasscodeViewController:(TOPasscodeViewController *)passcodeViewController
  247. {
  248. [[LAContext new] evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:[[NCBrandOptions shared] brand] reply:^(BOOL success, NSError * _Nullable error) {
  249. if (success) {
  250. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  251. [CCUtility setPasscode:@""];
  252. [passcodeViewController dismissViewControllerAnimated:YES completion:nil];
  253. [self reloadForm];
  254. });
  255. }
  256. }];
  257. }
  258. - (void)passcodeSettingsViewController:(TOPasscodeSettingsViewController *)passcodeSettingsViewController didChangeToNewPasscode:(NSString *)passcode ofType:(TOPasscodeType)type
  259. {
  260. [CCUtility setPasscode:passcode];
  261. [passcodeSettingsViewController dismissViewControllerAnimated:YES completion:nil];
  262. [self reloadForm];
  263. }
  264. - (void)didTapCancelInPasscodeViewController:(TOPasscodeViewController *)passcodeViewController
  265. {
  266. [passcodeViewController dismissViewControllerAnimated:YES completion:nil];
  267. }
  268. - (BOOL)passcodeViewController:(TOPasscodeViewController *)passcodeViewController isCorrectCode:(NSString *)code
  269. {
  270. if ([code isEqualToString:[CCUtility getPasscode]]) {
  271. [CCUtility setPasscode:@""];
  272. [self reloadForm];
  273. return YES;
  274. }
  275. return NO;
  276. }
  277. - (void)passcode:(XLFormRowDescriptor *)sender
  278. {
  279. LAContext *laContext = [LAContext new];
  280. NSError *error;
  281. [self deselectFormRow:sender];
  282. if ([[CCUtility getPasscode] length] == 0) {
  283. passcodeSettingsViewController = [[TOPasscodeSettingsViewController alloc] init];
  284. if (@available(iOS 13.0, *)) {
  285. if ([[UITraitCollection currentTraitCollection] userInterfaceStyle] == UIUserInterfaceStyleDark) {
  286. passcodeSettingsViewController.style = TOPasscodeSettingsViewStyleDark;
  287. }
  288. }
  289. passcodeSettingsViewController.hideOptionsButton = YES;
  290. passcodeSettingsViewController.requireCurrentPasscode = NO;
  291. passcodeSettingsViewController.passcodeType = TOPasscodeTypeSixDigits;
  292. passcodeSettingsViewController.delegate = self;
  293. [self presentViewController:passcodeSettingsViewController animated:YES completion:nil];
  294. } else {
  295. passcodeViewController = [[TOPasscodeViewController alloc] initWithStyle:TOPasscodeViewStyleTranslucentLight passcodeType:TOPasscodeTypeSixDigits];
  296. if (@available(iOS 13.0, *)) {
  297. if ([[UITraitCollection currentTraitCollection] userInterfaceStyle] == UIUserInterfaceStyleDark) {
  298. passcodeViewController.style = TOPasscodeViewStyleTranslucentDark;
  299. }
  300. }
  301. passcodeViewController.allowCancel = true;
  302. passcodeViewController.delegate = self;
  303. passcodeViewController.keypadButtonShowLettering = false;
  304. if (CCUtility.getEnableTouchFaceID && [laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
  305. if (error == NULL) {
  306. if (laContext.biometryType == LABiometryTypeFaceID) {
  307. passcodeViewController.biometryType = TOPasscodeBiometryTypeFaceID;
  308. passcodeViewController.allowBiometricValidation = true;
  309. passcodeViewController.automaticallyPromptForBiometricValidation = true;
  310. } else if (laContext.biometryType == LABiometryTypeTouchID) {
  311. passcodeViewController.biometryType = TOPasscodeBiometryTypeTouchID;
  312. passcodeViewController.allowBiometricValidation = true;
  313. passcodeViewController.automaticallyPromptForBiometricValidation = true;
  314. } else {
  315. NSLog(@"No Biometric support");
  316. }
  317. }
  318. }
  319. [self presentViewController:passcodeViewController animated:YES completion:nil];
  320. }
  321. }
  322. #pragma mark -
  323. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
  324. {
  325. NSString *sectionName;
  326. switch (section)
  327. {
  328. case 1: {
  329. sectionName = NSLocalizedString(@"_lock_protection_no_screen_footer_", nil);
  330. }
  331. break;
  332. case 4: {
  333. NSString *versionServer = [[NCManageDatabase shared] getCapabilitiesServerStringWithAccount:appDelegate.account elements:NCElementsJSON.shared.capabilitiesVersionString];
  334. NSString *themingName = [[NCManageDatabase shared] getCapabilitiesServerStringWithAccount:appDelegate.account elements:NCElementsJSON.shared.capabilitiesThemingName];
  335. NSString *themingSlogan = [[NCManageDatabase shared] getCapabilitiesServerStringWithAccount:appDelegate.account elements:NCElementsJSON.shared.capabilitiesThemingSlogan];
  336. NSString *versionNextcloud = [NSString stringWithFormat:[NCBrandOptions shared].textCopyrightNextcloudServer, versionServer];
  337. NSString *versionNextcloudiOS = [NSString stringWithFormat:[NCBrandOptions shared].textCopyrightNextcloudiOS, NCUtility.shared.getVersionApp];
  338. NSString *nameSlogan = [NSString stringWithFormat:@"%@ - %@", themingName, themingSlogan];
  339. sectionName = [NSString stringWithFormat:@"\n%@\n\n%@\n%@", versionNextcloudiOS, versionNextcloud, nameSlogan];
  340. }
  341. break;
  342. }
  343. return sectionName;
  344. }
  345. @end