CCSettings.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. //
  2. // CCSettings.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 24/11/14.
  6. // Copyright (c) 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  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 "CCSettings.h"
  24. #import "AppDelegate.h"
  25. #import "CCMain.h"
  26. #import "OCCapabilities.h"
  27. #import "CCSynchronize.h"
  28. #import "CCAdvanced.h"
  29. #import "CCManageCryptoCloud.h"
  30. #import "CCManageAccount.h"
  31. #import "NCManageEndToEndEncryption.h"
  32. #import "NCBridgeSwift.h"
  33. #define alertViewEsci 1
  34. #define alertViewAzzeraCache 2
  35. @implementation CCSettings
  36. - (id)initWithCoder:(NSCoder *)aDecoder
  37. {
  38. self = [super initWithCoder:aDecoder];
  39. if (self) {
  40. [self initializeForm];
  41. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  42. app.activeSettings = self;
  43. }
  44. return self;
  45. }
  46. - (void)initializeForm
  47. {
  48. XLFormDescriptor *form;
  49. XLFormSectionDescriptor *section;
  50. XLFormRowDescriptor *row;
  51. form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_settings_", nil)];
  52. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  53. // Section AUTO UPLOAD OF CAMERA IMAGES ----------------------------
  54. section = [XLFormSectionDescriptor formSection];
  55. [form addFormSection:section];
  56. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUpload" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_settings_autoupload_", nil)];
  57. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  58. [row.cellConfig setObject:[UIImage imageNamed:@"settingsCameraUpload"] forKey:@"imageView.image"];
  59. row.action.formSegueIdentifier = @"CCManageAutoUploadSegue";
  60. [section addFormRow:row];
  61. // Section FOLDERS FAVORITES OFFLINE ------------------------------------
  62. section = [XLFormSectionDescriptor formSection];
  63. [form addFormSection:section];
  64. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"favoriteoffline" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_favorite_offline_", nil)];
  65. [row.cellConfig setObject:[UIImage imageNamed:@"settingsFavoriteOffline"] forKey:@"imageView.image"];
  66. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  67. [section addFormRow:row];
  68. // Section : LOCK --------------------------------------------------------------
  69. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_lock_", nil)];
  70. [form addFormSection:section];
  71. // Lock active YES/NO
  72. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"bloccopasscode" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_lock_not_active_", nil)];
  73. [row.cellConfig setObject:[UIImage imageNamed:@"settingsPasscodeNO"] forKey:@"imageView.image"];
  74. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  75. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  76. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  77. //[row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  78. row.action.formSelector = @selector(bloccoPassword);
  79. [section addFormRow:row];
  80. // Passcode simply
  81. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"simplypasscode" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_simply_", nil)];
  82. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  83. [section addFormRow:row];
  84. // Lock no screen
  85. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"onlylockdir" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_no_screen_", nil)];
  86. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  87. [section addFormRow:row];
  88. // Section : E2EEncryption --------------------------------------------------------------
  89. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_e2e_settings_title_", nil)];
  90. [form addFormSection:section];
  91. // EndToEnd Encryption
  92. NSString *title = [NSString stringWithFormat:@"%@ (%@)",NSLocalizedString(@"_e2e_settings_", nil), NSLocalizedString(@"_experimental_", nil)];
  93. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"e2eEncryption" rowType:XLFormRowDescriptorTypeButton title:title];
  94. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  95. [row.cellConfig setObject:[UIImage imageNamed:@"settingsE2EEncryption"] forKey:@"imageView.image"];
  96. row.action.viewControllerClass = [NCManageEndToEndEncryption class];
  97. [section addFormRow:row];
  98. // Section Advanced -------------------------------------------------
  99. section = [XLFormSectionDescriptor formSection];
  100. [form addFormSection:section];
  101. // Advanced
  102. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"advanced" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_advanced_", nil)];
  103. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  104. [row.cellConfig setObject:[UIImage imageNamed:@"settingsAdvanced"] 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.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  113. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  114. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  115. [row.cellConfig setObject:[UIImage imageNamed:@"settingsAcknowledgements"] forKey:@"imageView.image"];
  116. row.action.formBlock = ^(XLFormRowDescriptor * sender){
  117. [self performSegueWithIdentifier:@"AcknowledgementsSegue" sender:sender];
  118. [self deselectFormRow:sender];
  119. };
  120. [section addFormRow:row];
  121. // Contact us mail
  122. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sendmail" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_contact_by_email_", nil)];
  123. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  124. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  125. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  126. [row.cellConfig setObject:[UIImage imageNamed:@"settingsMail"] forKey:@"imageView.image"];
  127. row.action.formSelector = @selector(sendMail:);
  128. [section addFormRow:row];
  129. self.form = form;
  130. }
  131. // Apparirà
  132. - (void)viewWillAppear:(BOOL)animated
  133. {
  134. [super viewWillAppear:animated];
  135. self.tableView.backgroundColor = [NCBrandColor sharedInstance].tableBackground;
  136. self.tableView.showsVerticalScrollIndicator = NO;
  137. // Color
  138. [app aspectNavigationControllerBar:self.navigationController.navigationBar online:[app.reachability isReachable] hidden:NO];
  139. [app aspectTabBar:self.tabBarController.tabBar hidden:NO];
  140. [self reloadForm];
  141. }
  142. - (void)changeTheming
  143. {
  144. if (self.isViewLoaded && self.view.window)
  145. [app changeTheming:self];
  146. }
  147. #pragma --------------------------------------------------------------------------------------------
  148. #pragma mark === Chiamate dal Form ===
  149. #pragma --------------------------------------------------------------------------------------------
  150. - (void)reloadForm
  151. {
  152. self.form.delegate = nil;
  153. // ----------------------
  154. XLFormRowDescriptor *rowBloccoPasscode = [self.form formRowWithTag:@"bloccopasscode"];
  155. XLFormRowDescriptor *rowSimplyPasscode = [self.form formRowWithTag:@"simplypasscode"];
  156. XLFormRowDescriptor *rowOnlyLockDir = [self.form formRowWithTag:@"onlylockdir"];
  157. XLFormRowDescriptor *rowFavoriteOffline = [self.form formRowWithTag:@"favoriteoffline"];
  158. // ------------------------------------------------------------------
  159. if ([[CCUtility getBlockCode] length]) {
  160. rowBloccoPasscode.title = NSLocalizedString(@"_lock_active_", nil);
  161. [rowBloccoPasscode.cellConfig setObject:[UIImage imageNamed:@"settingsPasscodeYES"] forKey:@"imageView.image"];
  162. } else {
  163. rowBloccoPasscode.title = NSLocalizedString(@"_lock_not_active_", nil);
  164. [rowBloccoPasscode.cellConfig setObject:[UIImage imageNamed:@"settingsPasscodeNO"] forKey:@"imageView.image"];
  165. }
  166. if ([CCUtility getSimplyBlockCode]) [rowSimplyPasscode setValue:@1]; else [rowSimplyPasscode setValue:@0];
  167. if ([CCUtility getOnlyLockDir]) [rowOnlyLockDir setValue:@1]; else [rowOnlyLockDir setValue:@0];
  168. if ([CCUtility getFavoriteOffline]) [rowFavoriteOffline setValue:@1]; else [rowFavoriteOffline setValue:@0];
  169. // -----------------------------------------------------------------
  170. [self.tableView reloadData];
  171. self.form.delegate = self;
  172. }
  173. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  174. {
  175. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  176. if ([rowDescriptor.tag isEqualToString:@"onlylockdir"]) {
  177. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  178. [CCUtility setOnlyLockDir:true];
  179. } else {
  180. [CCUtility setOnlyLockDir:false];
  181. }
  182. }
  183. if ([rowDescriptor.tag isEqualToString:@"simplypasscode"]) {
  184. if ([[CCUtility getBlockCode] length] == 0)
  185. [CCUtility setSimplyBlockCode:[[rowDescriptor.value valueData] boolValue]];
  186. else
  187. [self changeSimplyPassword];
  188. }
  189. if ([rowDescriptor.tag isEqualToString:@"favoriteoffline"]) {
  190. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  191. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_continue_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  192. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  193. [CCUtility setFavoriteOffline:true];
  194. [self synchronizeFavorites];
  195. }]];
  196. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  197. [self reloadForm];
  198. }]];
  199. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  200. // iPhone
  201. [self presentViewController:alertController animated:YES completion:nil];
  202. }else {
  203. // iPad
  204. // Change Rect to position Popover
  205. UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:alertController];
  206. [popup presentPopoverFromRect:[self.tableView rectForRowAtIndexPath:[self.form indexPathOfFormRow:rowDescriptor]] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  207. }
  208. } else {
  209. [CCUtility setFavoriteOffline:false];
  210. }
  211. }
  212. }
  213. - (void)checkEncryptPass:(XLFormRowDescriptor *)sender
  214. {
  215. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  216. viewController.delegate = self;
  217. viewController.fromType = CCBKPasscodeFromCheckCryptoKey;
  218. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  219. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  220. viewController.passcodeInputView.maximumLength = 64;
  221. viewController.title = NSLocalizedString(@"_check_key_aes_256_", nil);
  222. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  223. viewController.navigationItem.leftBarButtonItem.tintColor = [NCBrandColor sharedInstance].cryptocloud;
  224. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  225. [self presentViewController:navigationController animated:YES completion:nil];
  226. }
  227. - (void)changeSimplyPassword
  228. {
  229. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  230. viewController.delegate = self;
  231. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  232. viewController.fromType = CCBKPasscodeFromSimply;
  233. viewController.title = NSLocalizedString(@"_change_simply_passcode_", nil);
  234. viewController.inputViewTitlePassword = YES;
  235. if ([CCUtility getSimplyBlockCode]) {
  236. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  237. viewController.passcodeInputView.maximumLength = 6;
  238. } else {
  239. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  240. viewController.passcodeInputView.maximumLength = 64;
  241. }
  242. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  243. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  244. viewController.touchIDManager = touchIDManager;
  245. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  246. viewController.navigationItem.leftBarButtonItem.tintColor = [NCBrandColor sharedInstance].cryptocloud;
  247. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  248. [self presentViewController:navigationController animated:YES completion:nil];
  249. }
  250. - (void)bloccoPassword
  251. {
  252. // ATTIVAZIONE LOCK PASSWORD
  253. if ([[CCUtility getBlockCode] length] == 0) {
  254. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  255. viewController.delegate = self;
  256. viewController.type = BKPasscodeViewControllerNewPasscodeType;
  257. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  258. viewController.inputViewTitlePassword = YES;
  259. if ([CCUtility getSimplyBlockCode]) {
  260. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  261. viewController.passcodeInputView.maximumLength = 6;
  262. } else {
  263. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  264. viewController.passcodeInputView.maximumLength = 64;
  265. }
  266. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  267. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  268. viewController.touchIDManager = touchIDManager;
  269. viewController.title = NSLocalizedString(@"_passcode_activate_", nil);
  270. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  271. viewController.navigationItem.leftBarButtonItem.tintColor = [NCBrandColor sharedInstance].cryptocloud;
  272. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  273. [self presentViewController:navigationController animated:YES completion:nil];
  274. } else {
  275. // OFF LOCK PASSWORD
  276. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  277. viewController.delegate = self;
  278. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  279. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  280. viewController.inputViewTitlePassword = YES;
  281. if ([CCUtility getSimplyBlockCode]) {
  282. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  283. viewController.passcodeInputView.maximumLength = 6;
  284. } else {
  285. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  286. viewController.passcodeInputView.maximumLength = 64;
  287. }
  288. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  289. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  290. viewController.touchIDManager = touchIDManager;
  291. viewController.title = NSLocalizedString(@"_disabling_passcode_", nil);
  292. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  293. viewController.navigationItem.leftBarButtonItem.tintColor = [NCBrandColor sharedInstance].cryptocloud;
  294. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  295. [self presentViewController:navigationController animated:YES completion:nil];
  296. }
  297. }
  298. - (void)synchronizeFavorites
  299. {
  300. NSArray *metadatas = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND favorite = true", app.activeAccount] sorted:nil ascending:NO];
  301. for (tableMetadata *metadata in metadatas) {
  302. if (metadata.directory) {
  303. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  304. if (!serverUrl) continue;
  305. serverUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:metadata.fileName];
  306. NSString *serverUrlBeginWith = serverUrl;
  307. if (![serverUrl hasSuffix:@"/"])
  308. serverUrlBeginWith = [serverUrl stringByAppendingString:@"/"];
  309. NSArray *directories = [[NCManageDatabase sharedInstance] getTablesDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND (serverUrl = %@ OR serverUrl BEGINSWITH %@)", app.activeAccount, serverUrl, serverUrlBeginWith] sorted:@"serverUrl" ascending:true];
  310. for (tableDirectory *directory in directories)
  311. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:nil directoryID:directory.directoryID];
  312. }
  313. }
  314. [app.activeFavorites readListingFavorites];
  315. }
  316. #pragma --------------------------------------------------------------------------------------------
  317. #pragma mark === Table View ===
  318. #pragma --------------------------------------------------------------------------------------------
  319. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
  320. {
  321. NSString *sectionName;
  322. switch (section)
  323. {
  324. case 1: {
  325. sectionName = NSLocalizedString(@"_favorite_offline_footer_", nil);
  326. }
  327. break;
  328. case 2: {
  329. sectionName = NSLocalizedString(@"_lock_protection_no_screen_footer_", nil);
  330. }
  331. break;
  332. case 4: {
  333. tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilites];
  334. NSString *versionServer = capabilities.versionString;
  335. NSString *versionApp = [NSString stringWithFormat:@"%@.%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  336. NSString *versionNextcloud = [NSString stringWithFormat:[NCBrandOptions sharedInstance].textCopyrightNextcloudServer, versionServer];
  337. NSString *versionNextcloudiOS = [NSString stringWithFormat:[NCBrandOptions sharedInstance].textCopyrightNextcloudiOS, versionApp];
  338. sectionName = [NSString stringWithFormat:@"%@\n%@", versionNextcloudiOS, versionNextcloud];
  339. }
  340. break;
  341. }
  342. return sectionName;
  343. }
  344. #pragma --------------------------------------------------------------------------------------------
  345. #pragma mark === Mail ===
  346. #pragma --------------------------------------------------------------------------------------------
  347. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  348. {
  349. switch (result)
  350. {
  351. case MFMailComposeResultCancelled:
  352. [app messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
  353. break;
  354. case MFMailComposeResultSaved:
  355. [app messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
  356. break;
  357. case MFMailComposeResultSent:
  358. [app messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
  359. break;
  360. case MFMailComposeResultFailed: {
  361. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  362. [app messageNotification:@"_error_" description:msg visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  363. }
  364. break;
  365. default:
  366. break;
  367. }
  368. // Close the Mail Interface
  369. [self dismissViewControllerAnimated:YES completion:NULL];
  370. }
  371. - (void)sendMail:(XLFormRowDescriptor *)sender
  372. {
  373. if ([MFMailComposeViewController canSendMail]) {
  374. // Email Subject
  375. NSString *emailTitle = NSLocalizedString(@"_information_req_", nil);
  376. // Email Content
  377. NSString *messageBody;
  378. // Email Recipents
  379. NSArray *toRecipents;
  380. messageBody = [NSString stringWithFormat:@"%@\n\n\n\n%@ Version %@ (%@) - iOS %@", NSLocalizedString(@"_write_in_english_", nil), [NCBrandOptions sharedInstance].brand, [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"], [[UIDevice currentDevice] systemVersion]];
  381. toRecipents = [NSArray arrayWithObject:[NCBrandOptions sharedInstance].mailMe];
  382. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  383. mc.mailComposeDelegate = self;
  384. [mc setSubject:emailTitle];
  385. [mc setMessageBody:messageBody isHTML:NO];
  386. [mc setToRecipients:toRecipents];
  387. // Present mail view controller on screen
  388. [self presentViewController:mc animated:YES completion:NULL];
  389. }
  390. }
  391. - (void)sendMailEncryptPass
  392. {
  393. if ([MFMailComposeViewController canSendMail])
  394. [CCUtility sendMailEncryptPass:[CCUtility getEmail] validateEmail:NO form:self nameImage:@"backgroundDetail"];
  395. }
  396. #pragma --------------------------------------------------------------------------------------------
  397. #pragma mark === BKPasscodeViewController ===
  398. #pragma --------------------------------------------------------------------------------------------
  399. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  400. {
  401. [aViewController dismissViewControllerAnimated:YES completion:nil];
  402. switch (aViewController.type) {
  403. case BKPasscodeViewControllerNewPasscodeType: {
  404. // enable passcode
  405. [CCUtility setBlockCode:aPasscode];
  406. }
  407. break;
  408. case BKPasscodeViewControllerCheckPasscodeType: {
  409. // disable passcode
  410. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode) {
  411. [CCUtility setBlockCode:@""];
  412. [[NCManageDatabase sharedInstance] setAllDirectoryUnLock];
  413. [app.activeMain.tableView reloadData];
  414. }
  415. // email Key EAS-256
  416. if (aViewController.fromType == CCBKPasscodeFromCheckCryptoKey)
  417. [self sendMailEncryptPass];
  418. // change simply
  419. if (aViewController.fromType == CCBKPasscodeFromSimply) {
  420. // disable passcode
  421. [CCUtility setBlockCode:@""];
  422. [[NCManageDatabase sharedInstance] setAllDirectoryUnLock];
  423. [app.activeMain.tableView reloadData];
  424. [CCUtility setSimplyBlockCode:![CCUtility getSimplyBlockCode]];
  425. // Call new passcode
  426. [self bloccoPassword];
  427. }
  428. }
  429. break;
  430. default:
  431. break;
  432. }
  433. [self reloadForm];
  434. }
  435. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  436. {
  437. if (aViewController.fromType == CCBKPasscodeFromCheckCryptoKey) {
  438. NSString *key = [CCUtility getKeyChainPasscodeForUUID:[CCUtility getUUID]];
  439. if ([aPasscode isEqualToString:key]) {
  440. self.lockUntilDate = nil;
  441. self.failedAttempts = 0;
  442. aResultHandler(YES);
  443. } else aResultHandler(NO);
  444. }
  445. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode || aViewController.fromType == CCBKPasscodeFromSimply) {
  446. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  447. self.lockUntilDate = nil;
  448. self.failedAttempts = 0;
  449. aResultHandler(YES);
  450. } else aResultHandler(NO);
  451. }
  452. }
  453. - (void)passcodeViewControllerDidFailAttempt:(CCBKPasscode *)aViewController
  454. {
  455. self.failedAttempts++;
  456. if (self.failedAttempts > 5) {
  457. NSTimeInterval timeInterval = 60;
  458. if (self.failedAttempts > 6) {
  459. NSUInteger multiplier = self.failedAttempts - 6;
  460. timeInterval = (5 * 60) * multiplier;
  461. if (timeInterval > 3600 * 24) {
  462. timeInterval = 3600 * 24;
  463. }
  464. }
  465. self.lockUntilDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
  466. }
  467. }
  468. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  469. {
  470. return self.failedAttempts;
  471. }
  472. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  473. {
  474. return self.lockUntilDate;
  475. }
  476. - (void)passcodeViewCloseButtonPressed:(id)sender
  477. {
  478. [self dismissViewControllerAnimated:YES completion:nil];
  479. }
  480. @end