CCSettings.m 38 KB

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