CCSettings.m 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  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 "TableAccount+CoreDataClass.h"
  27. #define alertViewEsci 1
  28. #define alertViewAzzeraCache 2
  29. @implementation CCSettings
  30. - (id)initWithCoder:(NSCoder *)aDecoder
  31. {
  32. self = [super initWithCoder:aDecoder];
  33. if (self) {
  34. [self initializeForm];
  35. app.activeSettings = self;
  36. }
  37. return self;
  38. }
  39. - (void)initializeForm
  40. {
  41. XLFormDescriptor *form;
  42. XLFormSectionDescriptor *section;
  43. XLFormRowDescriptor *row;
  44. form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_settings_", nil)];
  45. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  46. // Section : PASSWORD --------------------------------------------------------------
  47. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_passcode_", nil)];
  48. [form addFormSection:section];
  49. // Passcode
  50. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"bloccopasscode" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_lock_not_active_", nil)];
  51. [row.cellConfig setObject:[UIImage imageNamed:image_settingsPasscodeNO] forKey:@"imageView.image"];
  52. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  53. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  54. [row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  55. row.action.formSelector = @selector(bloccoPassword);
  56. [section addFormRow:row];
  57. // Passcode simply
  58. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"simplypasscode" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_simply_", nil)];
  59. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  60. [section addFormRow:row];
  61. // Passcode only directory
  62. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"onlylockdir" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_folder_", nil)];
  63. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  64. [section addFormRow:row];
  65. // Section : CLOUD ACCOUNT --------------------------------------------------------------
  66. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_cloud_account_", nil)];
  67. [form addFormSection:section];
  68. // version
  69. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"versionserver" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_version_server_", nil)];
  70. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  71. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  72. [section addFormRow:row];
  73. // Url
  74. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"urlcloud" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_url_", nil)];
  75. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  76. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  77. [section addFormRow:row];
  78. // username
  79. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"usernamecloud" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_username_", nil)];
  80. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  81. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  82. [section addFormRow:row];
  83. // information
  84. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"userinformation" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_information_", nil)];
  85. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  86. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  87. [section addFormRow:row];
  88. // quota
  89. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"quota" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_quota_", nil)];
  90. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  91. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  92. [section addFormRow:row];
  93. // Change Account
  94. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"changecredentials" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_change_credentials_", nil)];
  95. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  96. [row.cellConfig setObject:[UIImage imageNamed:image_settingsCredentials] forKey:@"imageView.image"];
  97. row.action.formSegueIdentifier = @"CCManageAccountSegue";
  98. [section addFormRow:row];
  99. // Section --------------------------------------------------------------
  100. section = [XLFormSectionDescriptor formSection];
  101. [form addFormSection:section];
  102. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"cameraupload" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_uploading_from_camera_", nil)];
  103. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  104. [row.cellConfig setObject:[UIImage imageNamed:image_settingsCameraUpload] forKey:@"imageView.image"];
  105. row.action.formSegueIdentifier = @"CCManageCameraUploadSegue";
  106. [section addFormRow:row];
  107. // Section --------------------------------------------------------------
  108. section = [XLFormSectionDescriptor formSection];
  109. [form addFormSection:section];
  110. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"optimizations" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_optimizations_", nil)];
  111. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  112. [row.cellConfig setObject:[UIImage imageNamed:image_settingsOptimizations] forKey:@"imageView.image"];
  113. row.action.formSegueIdentifier = @"CCManageOptimizationsSegue";
  114. [section addFormRow:row];
  115. // Section --------------------------------------------------------------
  116. section = [XLFormSectionDescriptor formSection];
  117. [form addFormSection:section];
  118. // Crypto Cloud
  119. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"cryptocloud" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_crypto_cloud_system_", nil)];
  120. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  121. [row.cellConfig setObject:[UIImage imageNamed:image_settingsCryptoCloud] forKey:@"imageView.image"];
  122. row.action.formSegueIdentifier = @"CCManageCryptoCloudSegue";
  123. [section addFormRow:row];
  124. // Section : INFORMATION --------------------------------------------------------------
  125. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_information_", nil)];
  126. [form addFormSection:section];
  127. section.footerTitle = @"Nextcloud © 2017 T.W.S. Inc.";
  128. // Acknowledgements
  129. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"buttonLeftAligned" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_acknowledgements_", nil)];
  130. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  131. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  132. [row.cellConfig setObject:[UIImage imageNamed:image_settingsAcknowledgements] forKey:@"imageView.image"];
  133. [row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  134. row.action.formBlock = ^(XLFormRowDescriptor * sender){
  135. [self performSegueWithIdentifier:@"AcknowledgementsSegue" sender:sender];
  136. [self deselectFormRow:sender];
  137. };
  138. [section addFormRow:row];
  139. // Help
  140. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"help" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_help_", nil)];
  141. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  142. [row.cellConfig setObject:[UIImage imageNamed:image_settingsHelp] forKey:@"imageView.image"];
  143. row.action.formSegueIdentifier = @"CCManageHelpSegue";
  144. [section addFormRow:row];
  145. // Contact us mail
  146. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sendmail" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_contact_by_email_", nil)];
  147. [row.cellConfig setObject:COLOR_BRAND forKey:@"textLabel.textColor"];
  148. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  149. [row.cellConfig setObject:[UIImage imageNamed:image_settingsMail] forKey:@"imageView.image"];
  150. row.action.formSelector = @selector(sendMail:);
  151. [section addFormRow:row];
  152. // Version
  153. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"versioneapplicazione" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_app_version_", nil)];
  154. row.value = [NSString stringWithFormat:@"%@ (%@)", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  155. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  156. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  157. [section addFormRow:row];
  158. // Section --------------------------------------------------------------
  159. section = [XLFormSectionDescriptor formSection];
  160. [form addFormSection:section];
  161. // Clear cache
  162. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"azzeracache" rowType:XLFormRowDescriptorTypeButton title:@""];
  163. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  164. [row.cellConfig setObject:[UIImage imageNamed:image_settingsClearCache] forKey:@"imageView.image"];
  165. row.action.formSelector = @selector(azzeraCache:);
  166. [section addFormRow:row];
  167. // Section --------------------------------------------------------------
  168. section = [XLFormSectionDescriptor formSection];
  169. [form addFormSection:section];
  170. // Exit
  171. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"esci" rowType:XLFormRowDescriptorTypeButton title:[CCUtility localizableBrand:@"_exit_" table:nil]];
  172. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  173. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  174. [row.cellConfig setObject:[UIImage imageNamed:image_settingsExit] forKey:@"imageView.image"];
  175. row.action.formSelector = @selector(esci:);
  176. [section addFormRow:row];
  177. #ifdef DEBUG
  178. /*
  179. // Section : debug
  180. section = [XLFormSectionDescriptor formSectionWithTitle:@"Debug"];
  181. [form addFormSection:section];
  182. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"adminRemoveVersion" rowType:XLFormRowDescriptorTypeButton title:@"Remove Version"];
  183. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  184. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  185. [row.cellConfig setObject:[UIImage imageNamed:image_settingsAdmin] forKey:@"imageView.image"];
  186. row.action.formSelector = @selector(adminRemoveVersion:);
  187. [section addFormRow:row];
  188. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"quickActionPhotos" rowType:XLFormRowDescriptorTypeButton title:@"Quick Action Photos"];
  189. [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
  190. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  191. [row.cellConfig setObject:[UIImage imageNamed:image_settingsAdmin] forKey:@"imageView.image"];
  192. row.action.formSelector = @selector(quickActionPhotos:);
  193. [section addFormRow:row];
  194. */
  195. #endif
  196. self.form = form;
  197. }
  198. - (void)viewDidLoad
  199. {
  200. [super viewDidLoad];
  201. self.hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
  202. self.title = NSLocalizedString(@"_settings_", nil);
  203. // Color
  204. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar hidden:NO];
  205. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  206. }
  207. // Apparirà
  208. - (void)viewWillAppear:(BOOL)animated
  209. {
  210. [super viewWillAppear:animated];
  211. // Color
  212. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar hidden:NO];
  213. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  214. [self reloadForm];
  215. [self recalculateSize];
  216. }
  217. // E' apparsa
  218. - (void)viewDidAppear:(BOOL)animated
  219. {
  220. [super viewDidAppear:animated];
  221. }
  222. #pragma --------------------------------------------------------------------------------------------
  223. #pragma mark === Admin ===
  224. #pragma --------------------------------------------------------------------------------------------
  225. /*
  226. - (void)adminRemoveVersion:(XLFormRowDescriptor *)sender
  227. {
  228. [self deselectFormRow:sender];
  229. [CCUtility adminRemoveVersion];
  230. exit(0);
  231. }
  232. - (void)quickActionPhotos:(XLFormRowDescriptor *)sender
  233. {
  234. NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;
  235. UIApplicationShortcutItem *shortcutPhotos = [[UIApplicationShortcutItem alloc] initWithType:[NSString stringWithFormat:@"%@.photos", bundleId] localizedTitle:@"" localizedSubtitle:nil icon:nil userInfo:nil];
  236. [app handleShortCutItem:shortcutPhotos];
  237. }
  238. */
  239. #pragma --------------------------------------------------------------------------------------------
  240. #pragma mark === Chiamate dal Form ===
  241. #pragma --------------------------------------------------------------------------------------------
  242. - (void)reloadForm
  243. {
  244. self.form.delegate = nil;
  245. // ----------------------
  246. XLFormRowDescriptor *rowBloccoPasscode = [self.form formRowWithTag:@"bloccopasscode"];
  247. XLFormRowDescriptor *rowSimplyPasscode = [self.form formRowWithTag:@"simplypasscode"];
  248. XLFormRowDescriptor *rowOnlyLockDir = [self.form formRowWithTag:@"onlylockdir"];
  249. XLFormRowDescriptor *rowVersionServer = [self.form formRowWithTag:@"versionserver"];
  250. XLFormRowDescriptor *rowUrlCloud = [self.form formRowWithTag:@"urlcloud"];
  251. XLFormRowDescriptor *rowUserNameCloud = [self.form formRowWithTag:@"usernamecloud"];
  252. XLFormRowDescriptor *rowUserInformation = [self.form formRowWithTag:@"userinformation"];
  253. XLFormRowDescriptor *rowQuota = [self.form formRowWithTag:@"quota"];
  254. // ------------------------------------------------------------------
  255. if ([[CCUtility getBlockCode] length]) {
  256. rowBloccoPasscode.title = NSLocalizedString(@"_lock_active_", nil);
  257. [rowBloccoPasscode.cellConfig setObject:[UIImage imageNamed:image_settingsPasscodeYES] forKey:@"imageView.image"];
  258. } else {
  259. rowBloccoPasscode.title = NSLocalizedString(@"_lock_not_active_", nil);
  260. [rowBloccoPasscode.cellConfig setObject:[UIImage imageNamed:image_settingsPasscodeNO] forKey:@"imageView.image"];
  261. }
  262. if ([CCUtility getSimplyBlockCode]) [rowSimplyPasscode setValue:@1]; else [rowSimplyPasscode setValue:@0];
  263. if ([CCUtility getOnlyLockDir]) [rowOnlyLockDir setValue:@1]; else [rowOnlyLockDir setValue:@0];
  264. TableAccount *tableAccount = [CCCoreData getActiveAccount];
  265. rowVersionServer.value = [CCNetworking sharedNetworking].sharedOCCommunication.getCurrentServerVersion;
  266. rowUrlCloud.value = app.activeUrl;
  267. rowUserNameCloud.value = [NSString stringWithFormat:@"%@ - %@",app.activeUser, tableAccount.displayName];
  268. rowUserInformation.value = [NSString stringWithFormat:@"%@ %@",tableAccount.address, tableAccount.phone];
  269. NSString *quota = [CCUtility transformedSize:[tableAccount.quotaTotal doubleValue]];
  270. NSString *quotaAvailable = [CCUtility transformedSize:[tableAccount.quotaFree doubleValue]];
  271. rowQuota.value = [NSString stringWithFormat:@"%@ / %@ %@", quota, quotaAvailable, NSLocalizedString(@"_available_", nil)];
  272. // -----------------------------------------------------------------
  273. [self.tableView reloadData];
  274. self.form.delegate = self;
  275. }
  276. - (void)recalculateSize
  277. {
  278. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  279. self.form.delegate = nil;
  280. XLFormRowDescriptor *rowAzzeraCache = [self.form formRowWithTag:@"azzeracache"];
  281. //NSString *size = [CCUtility transformedSize:[[self getUserDirectorySize] longValue]];
  282. //rowAzzeraCache.title = [NSString stringWithFormat:NSLocalizedString(@"_clear_cache_", nil), size];
  283. rowAzzeraCache.title = NSLocalizedString(@"_clear_cache_no_size_", nil);
  284. [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  285. self.form.delegate = self;
  286. });
  287. }
  288. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  289. {
  290. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  291. if ([rowDescriptor.tag isEqualToString:@"onlylockdir"]) {
  292. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  293. [CCUtility setOnlyLockDir:true];
  294. } else {
  295. [CCUtility setOnlyLockDir:false];
  296. }
  297. }
  298. if ([rowDescriptor.tag isEqualToString:@"simplypasscode"]) {
  299. if ([[CCUtility getBlockCode] length] == 0)
  300. [CCUtility setSimplyBlockCode:[[rowDescriptor.value valueData] boolValue]];
  301. else
  302. [self changeSimplyPassword];
  303. }
  304. }
  305. - (void)checkEncryptPass:(XLFormRowDescriptor *)sender
  306. {
  307. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  308. viewController.delegate = self;
  309. viewController.fromType = CCBKPasscodeFromCheckCryptoKey;
  310. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  311. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  312. viewController.passcodeInputView.maximumLength = 64;
  313. viewController.title = NSLocalizedString(@"_check_key_aes_256_", nil);
  314. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  315. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  316. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  317. [self presentViewController:navigationController animated:YES completion:nil];
  318. }
  319. - (void)changeSimplyPassword
  320. {
  321. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  322. viewController.delegate = self;
  323. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  324. viewController.fromType = CCBKPasscodeFromSimply;
  325. viewController.title = NSLocalizedString(@"_change_simply_passcode_", nil);
  326. viewController.inputViewTitlePassword = YES;
  327. if ([CCUtility getSimplyBlockCode]) {
  328. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  329. viewController.passcodeInputView.maximumLength = 6;
  330. } else {
  331. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  332. viewController.passcodeInputView.maximumLength = 64;
  333. }
  334. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  335. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  336. viewController.touchIDManager = touchIDManager;
  337. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  338. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  339. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  340. [self presentViewController:navigationController animated:YES completion:nil];
  341. }
  342. - (void)bloccoPassword
  343. {
  344. // ATTIVAZIONE LOCK PASSWORD
  345. if ([[CCUtility getBlockCode] length] == 0) {
  346. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  347. viewController.delegate = self;
  348. viewController.type = BKPasscodeViewControllerNewPasscodeType;
  349. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  350. viewController.inputViewTitlePassword = YES;
  351. if ([CCUtility getSimplyBlockCode]) {
  352. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  353. viewController.passcodeInputView.maximumLength = 6;
  354. } else {
  355. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  356. viewController.passcodeInputView.maximumLength = 64;
  357. }
  358. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  359. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  360. viewController.touchIDManager = touchIDManager;
  361. viewController.title = NSLocalizedString(@"_passcode_activate_", nil);
  362. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  363. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  364. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  365. [self presentViewController:navigationController animated:YES completion:nil];
  366. } else {
  367. // OFF LOCK PASSWORD
  368. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  369. viewController.delegate = self;
  370. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  371. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  372. viewController.inputViewTitlePassword = YES;
  373. if ([CCUtility getSimplyBlockCode]) {
  374. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  375. viewController.passcodeInputView.maximumLength = 6;
  376. } else {
  377. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  378. viewController.passcodeInputView.maximumLength = 64;
  379. }
  380. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:BKPasscodeKeychainServiceName];
  381. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  382. viewController.touchIDManager = touchIDManager;
  383. viewController.title = NSLocalizedString(@"_disabling_passcode_", nil);
  384. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  385. viewController.navigationItem.leftBarButtonItem.tintColor = COLOR_ENCRYPTED;
  386. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  387. [self presentViewController:navigationController animated:YES completion:nil];
  388. }
  389. }
  390. - (void)esci:(XLFormRowDescriptor *)sender
  391. {
  392. [self deselectFormRow:sender];
  393. UIAlertView * alertView =[[UIAlertView alloc ] initWithTitle:[CCUtility localizableBrand:@"_exit_" table:nil]
  394. message:[CCUtility localizableBrand:@"_want_exit_" table:nil]
  395. delegate:self
  396. cancelButtonTitle:NSLocalizedString(@"_cancel_", nil)
  397. otherButtonTitles: nil];
  398. alertView.tag = alertViewEsci;
  399. [alertView addButtonWithTitle:NSLocalizedString(@"_proceed_", nil)];
  400. [alertView show];
  401. }
  402. - (void)azzeraCache:(XLFormRowDescriptor *)sender
  403. {
  404. [self deselectFormRow:sender];
  405. UIAlertView * alertView =[[UIAlertView alloc ] initWithTitle:NSLocalizedString(@"_delete_cache_",nil)
  406. message:NSLocalizedString(@"_want_delete_cache_", nil)
  407. delegate:self
  408. cancelButtonTitle:NSLocalizedString(@"_cancel_", nil)
  409. otherButtonTitles: nil];
  410. alertView.tag = alertViewAzzeraCache;
  411. [alertView addButtonWithTitle:NSLocalizedString(@"_proceed_", nil)];
  412. [alertView show];
  413. }
  414. #pragma --------------------------------------------------------------------------------------------
  415. #pragma mark === Mail ===
  416. #pragma --------------------------------------------------------------------------------------------
  417. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  418. {
  419. switch (result)
  420. {
  421. case MFMailComposeResultCancelled:
  422. [app messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  423. break;
  424. case MFMailComposeResultSaved:
  425. [app messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  426. break;
  427. case MFMailComposeResultSent:
  428. [app messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess];
  429. break;
  430. case MFMailComposeResultFailed: {
  431. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  432. [app messageNotification:@"_error_" description:msg visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  433. }
  434. break;
  435. default:
  436. break;
  437. }
  438. // Close the Mail Interface
  439. [self dismissViewControllerAnimated:YES completion:NULL];
  440. }
  441. - (void)sendMail:(XLFormRowDescriptor *)sender
  442. {
  443. // Email Subject
  444. NSString *emailTitle = NSLocalizedString(@"_information_req_", nil);
  445. // Email Content
  446. NSString *messageBody;
  447. // Email Recipents
  448. NSArray *toRecipents;
  449. messageBody = [NSString stringWithFormat:@"\n\n\nNextcloud Version %@ (%@)", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  450. toRecipents = [NSArray arrayWithObject:_mail_me_];
  451. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  452. mc.mailComposeDelegate = self;
  453. [mc setSubject:emailTitle];
  454. [mc setMessageBody:messageBody isHTML:NO];
  455. [mc setToRecipients:toRecipents];
  456. // Present mail view controller on screen
  457. [self presentViewController:mc animated:YES completion:NULL];
  458. }
  459. - (void)sendMailEncryptPass
  460. {
  461. [CCUtility sendMailEncryptPass:[CCUtility getEmail] validateEmail:NO form:self];
  462. }
  463. #pragma --------------------------------------------------------------------------------------------
  464. #pragma mark === AlertView ===
  465. #pragma --------------------------------------------------------------------------------------------
  466. - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
  467. {
  468. // Remove ALL
  469. if (buttonIndex == 1 && alertView.tag == alertViewEsci)
  470. {
  471. [self.hud visibleIndeterminateHud];
  472. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  473. [app cancelAllOperations];
  474. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  475. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  476. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  477. [[CCNetworking sharedNetworking] invalidateAndCancelAllSession];
  478. [CCCoreData flushAllDatabase];
  479. [CCUtility deleteAllChainStore];
  480. [self emptyDocumentsDirectory];
  481. [self emptyLibraryDirectory];
  482. [self emptyGroupApplicationSupport];
  483. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  484. for (NSString *file in tmpDirectory)
  485. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  486. [self.hud hideHud];
  487. exit(0);
  488. });
  489. }
  490. // Clear Cache
  491. if (buttonIndex == 1 && alertView.tag == alertViewAzzeraCache)
  492. {
  493. [self.hud visibleHudTitle:NSLocalizedString(@"_remove_cache_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
  494. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  495. [app cancelAllOperations];
  496. [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
  497. [[NSURLCache sharedURLCache] setMemoryCapacity:0];
  498. [[NSURLCache sharedURLCache] setDiskCapacity:0];
  499. [CCCoreData flushTableAutomaticUploadAccount:app.activeAccount selector:nil];
  500. [CCCoreData flushTableDirectoryAccount:app.activeAccount];
  501. [CCCoreData flushTableLocalFileAccount:app.activeAccount];
  502. [CCCoreData flushTableMetadataAccount:app.activeAccount];
  503. [self emptyUserDirectoryUser:app.activeUser url:app.activeUrl];
  504. [self emptyLocalDirectory];
  505. NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
  506. for (NSString *file in tmpDirectory)
  507. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
  508. [self recalculateSize];
  509. // Inizialized home
  510. [[NSNotificationCenter defaultCenter] postNotificationName:@"initializeMain" object:nil];
  511. [self.hud hideHud];
  512. });
  513. }
  514. }
  515. #pragma --------------------------------------------------------------------------------------------
  516. #pragma mark === BKPasscodeViewController ===
  517. #pragma --------------------------------------------------------------------------------------------
  518. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  519. {
  520. [aViewController dismissViewControllerAnimated:YES completion:nil];
  521. switch (aViewController.type) {
  522. case BKPasscodeViewControllerNewPasscodeType: {
  523. // enable passcode
  524. [CCUtility setBlockCode:aPasscode];
  525. }
  526. break;
  527. case BKPasscodeViewControllerCheckPasscodeType: {
  528. // disable passcode
  529. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode) {
  530. [CCUtility setBlockCode:@""];
  531. [CCCoreData setAllDirectoryUnLockForAccount:app.activeAccount];
  532. [app.activeMain.tableView reloadData];
  533. }
  534. // email Key EAS-256
  535. if (aViewController.fromType == CCBKPasscodeFromCheckCryptoKey)
  536. [self sendMailEncryptPass];
  537. // change simply
  538. if (aViewController.fromType == CCBKPasscodeFromSimply) {
  539. // disable passcode
  540. [CCUtility setBlockCode:@""];
  541. [CCCoreData setAllDirectoryUnLockForAccount:app.activeAccount];
  542. [app.activeMain.tableView reloadData];
  543. [CCUtility setSimplyBlockCode:![CCUtility getSimplyBlockCode]];
  544. // Call new passcode
  545. [self bloccoPassword];
  546. }
  547. }
  548. break;
  549. default:
  550. break;
  551. }
  552. [self reloadForm];
  553. }
  554. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  555. {
  556. if (aViewController.fromType == CCBKPasscodeFromCheckCryptoKey) {
  557. NSString *key = [CCUtility getKeyChainPasscodeForUUID:[CCUtility getUUID]];
  558. if ([aPasscode isEqualToString:key]) {
  559. self.lockUntilDate = nil;
  560. self.failedAttempts = 0;
  561. aResultHandler(YES);
  562. } else aResultHandler(NO);
  563. }
  564. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode || aViewController.fromType == CCBKPasscodeFromSimply) {
  565. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  566. self.lockUntilDate = nil;
  567. self.failedAttempts = 0;
  568. aResultHandler(YES);
  569. } else aResultHandler(NO);
  570. }
  571. }
  572. - (void)passcodeViewControllerDidFailAttempt:(CCBKPasscode *)aViewController
  573. {
  574. self.failedAttempts++;
  575. if (self.failedAttempts > 5) {
  576. NSTimeInterval timeInterval = 60;
  577. if (self.failedAttempts > 6) {
  578. NSUInteger multiplier = self.failedAttempts - 6;
  579. timeInterval = (5 * 60) * multiplier;
  580. if (timeInterval > 3600 * 24) {
  581. timeInterval = 3600 * 24;
  582. }
  583. }
  584. self.lockUntilDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
  585. }
  586. }
  587. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  588. {
  589. return self.failedAttempts;
  590. }
  591. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  592. {
  593. return self.lockUntilDate;
  594. }
  595. - (void)passcodeViewCloseButtonPressed:(id)sender
  596. {
  597. [self dismissViewControllerAnimated:YES completion:nil];
  598. }
  599. #pragma --------------------------------------------------------------------------------------------
  600. #pragma mark == Utility ==
  601. #pragma --------------------------------------------------------------------------------------------
  602. - (void)emptyGroupApplicationSupport
  603. {
  604. NSString *file;
  605. NSURL *dirGroup = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:k_capabilitiesGroups];
  606. NSString *dirIniziale = [[dirGroup URLByAppendingPathComponent:appApplicationSupport] path];
  607. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  608. while (file = [enumerator nextObject])
  609. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  610. }
  611. - (void)emptyLibraryDirectory
  612. {
  613. NSString *file;
  614. NSString *dirIniziale;
  615. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
  616. dirIniziale = [paths objectAtIndex:0];
  617. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  618. while (file = [enumerator nextObject])
  619. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  620. }
  621. - (void)emptyDocumentsDirectory
  622. {
  623. NSString *file;
  624. NSString *dirIniziale;
  625. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  626. dirIniziale = [paths objectAtIndex:0];
  627. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  628. while (file = [enumerator nextObject])
  629. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  630. }
  631. - (void)emptyUserDirectoryUser:(NSString *)user url:(NSString *)url
  632. {
  633. NSString *file;
  634. NSString *dirIniziale;
  635. dirIniziale = [CCUtility getDirectoryActiveUser:user activeUrl:url];
  636. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  637. while (file = [enumerator nextObject]) {
  638. NSString *ext = [[file pathExtension] lowercaseString];
  639. // Do not remove ICO
  640. if ([ext isEqualToString:@"ico"])
  641. continue;
  642. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  643. }
  644. }
  645. - (void)emptyLocalDirectory
  646. {
  647. NSString *file;
  648. NSString *dirIniziale;
  649. dirIniziale = [CCUtility getDirectoryLocal];
  650. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirIniziale];
  651. while (file = [enumerator nextObject])
  652. [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", dirIniziale, file] error:nil];
  653. }
  654. - (NSNumber *)getUserDirectorySize
  655. {
  656. NSString *directoryUser = [CCUtility getDirectoryActiveUser:app.activeUser activeUrl:app.activeUrl];
  657. NSURL *directoryURL = [NSURL fileURLWithPath:directoryUser];
  658. unsigned long long count = 0;
  659. NSNumber *value = nil;
  660. if (! directoryURL) return 0;
  661. // Get dimension Document
  662. for (NSURL *url in [[NSFileManager defaultManager] enumeratorAtURL:directoryURL includingPropertiesForKeys:@[NSURLFileSizeKey] options:0 errorHandler:NULL]) {
  663. if ([url getResourceValue:&value forKey:NSURLFileSizeKey error:nil]) {
  664. count += [value longLongValue];
  665. } else {
  666. return nil;
  667. }
  668. }
  669. return @(count);
  670. }
  671. @end