CCSettings.m 27 KB

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