Autopsy  4.16.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
UserPreferences.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014-2020 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.core;
20 
21 import java.nio.file.Paths;
23 import java.util.prefs.BackingStoreException;
25 import java.util.prefs.PreferenceChangeListener;
26 import java.util.prefs.Preferences;
27 import org.openide.util.NbPreferences;
28 import org.python.icu.util.TimeZone;
33 import org.sleuthkit.datamodel.CaseDbConnectionInfo;
34 import org.sleuthkit.datamodel.TskData.DbType;
35 
40 public final class UserPreferences {
41 
42  private static final Preferences preferences = NbPreferences.forModule(UserPreferences.class);
43  public static final String KEEP_PREFERRED_VIEWER = "KeepPreferredViewer"; // NON-NLS
44  public static final String HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE = "HideKnownFilesInDataSourcesTree"; //NON-NLS
45  public static final String HIDE_KNOWN_FILES_IN_VIEWS_TREE = "HideKnownFilesInViewsTree"; //NON-NLS
46  public static final String HIDE_SLACK_FILES_IN_DATA_SRCS_TREE = "HideSlackFilesInDataSourcesTree"; //NON-NLS
47  public static final String HIDE_SLACK_FILES_IN_VIEWS_TREE = "HideSlackFilesInViewsTree"; //NON-NLS
48  public static final String DISPLAY_TIMES_IN_LOCAL_TIME = "DisplayTimesInLocalTime"; //NON-NLS
49  public static final String TIME_ZONE_FOR_DISPLAYS = "TimeZoneForDisplays"; //NON-NLS
50  public static final String NUMBER_OF_FILE_INGEST_THREADS = "NumberOfFileIngestThreads"; //NON-NLS
51  public static final String IS_MULTI_USER_MODE_ENABLED = "IsMultiUserModeEnabled"; //NON-NLS
52  public static final String EXTERNAL_DATABASE_HOSTNAME_OR_IP = "ExternalDatabaseHostnameOrIp"; //NON-NLS
53  public static final String EXTERNAL_DATABASE_PORTNUMBER = "ExternalDatabasePortNumber"; //NON-NLS
54  public static final String EXTERNAL_DATABASE_NAME = "ExternalDatabaseName"; //NON-NLS
55  public static final String EXTERNAL_DATABASE_USER = "ExternalDatabaseUsername"; //NON-NLS
56  public static final String EXTERNAL_DATABASE_PASSWORD = "ExternalDatabasePassword"; //NON-NLS
57  public static final String EXTERNAL_DATABASE_TYPE = "ExternalDatabaseType"; //NON-NLS
58  public static final String INDEXING_SERVER_HOST = "IndexingServerHost"; //NON-NLS
59  public static final String INDEXING_SERVER_PORT = "IndexingServerPort"; //NON-NLS
60  private static final String MESSAGE_SERVICE_PASSWORD = "MessageServicePassword"; //NON-NLS
61  private static final String MESSAGE_SERVICE_USER = "MessageServiceUser"; //NON-NLS
62  private static final String MESSAGE_SERVICE_HOST = "MessageServiceHost"; //NON-NLS
63  private static final String MESSAGE_SERVICE_PORT = "MessageServicePort"; //NON-NLS
64  public static final String TEXT_TRANSLATOR_NAME = "TextTranslatorName";
65  public static final String PROCESS_TIME_OUT_ENABLED = "ProcessTimeOutEnabled"; //NON-NLS
66  public static final String PROCESS_TIME_OUT_HOURS = "ProcessTimeOutHours"; //NON-NLS
67  private static final int DEFAULT_PROCESS_TIMEOUT_HR = 60;
68  private static final String DEFAULT_PORT_STRING = "61616";
69  private static final int DEFAULT_PORT_INT = 61616;
70  private static final String APP_NAME = "AppName";
71  public static final String SETTINGS_PROPERTIES = "AutoIngest";
72  private static final String MODE = "AutopsyMode"; // NON-NLS
73  private static final String MAX_NUM_OF_LOG_FILE = "MaximumNumberOfLogFiles";
74  private static final int LOG_FILE_NUM_INT = 10;
75  public static final String GROUP_ITEMS_IN_TREE_BY_DATASOURCE = "GroupItemsInTreeByDataSource"; //NON-NLS
76  public static final String SHOW_ONLY_CURRENT_USER_TAGS = "ShowOnlyCurrentUserTags";
77  public static final String HIDE_SCO_COLUMNS = "HideCentralRepoCommentsAndOccurrences"; //The key for this setting pre-dates the settings current functionality //NON-NLS
78  public static final String DISPLAY_TRANSLATED_NAMES = "DisplayTranslatedNames";
79  private static final boolean DISPLAY_TRANSLATED_NAMES_DEFAULT = true;
80  public static final String EXTERNAL_HEX_EDITOR_PATH = "ExternalHexEditorPath";
81  public static final String SOLR_MAX_JVM_SIZE = "SolrMaxJVMSize";
82  public static final String RESULTS_TABLE_PAGE_SIZE = "ResultsTablePageSize";
83  private static final String GEO_TILE_OPTION = "GeolocationTileOption";
84  private static final String GEO_OSM_TILE_ZIP_PATH = "GeolocationOsmZipPath";
85  private static final String GEO_OSM_SERVER_ADDRESS = "GeolocationOsmServerAddress";
86  private static final String GEO_MBTILES_FILE_PATH = "GeolcoationMBTilesFilePath";
87 
88  // Prevent instantiation.
89  private UserPreferences() {
90  }
91 
92  public enum SelectedMode {
93 
95  AUTOINGEST
96  };
97 
103  public static SelectedMode getMode() {
104  if (ModuleSettings.settingExists(SETTINGS_PROPERTIES, MODE)) {
105  int ordinal = Integer.parseInt(ModuleSettings.getConfigSetting(SETTINGS_PROPERTIES, MODE));
106  return UserPreferences.SelectedMode.values()[ordinal];
107  }
109  }
110 
116  public static void setMode(SelectedMode mode) {
117  ModuleSettings.setConfigSetting(SETTINGS_PROPERTIES, MODE, Integer.toString(mode.ordinal()));
118  }
119 
126  public static void reloadFromStorage() throws BackingStoreException {
127  preferences.sync();
128  }
129 
137  public static void saveToStorage() throws BackingStoreException {
138  preferences.flush();
139  }
140 
141  public static void addChangeListener(PreferenceChangeListener listener) {
142  preferences.addPreferenceChangeListener(listener);
143  }
144 
145  public static void removeChangeListener(PreferenceChangeListener listener) {
146  preferences.removePreferenceChangeListener(listener);
147  }
148 
149  public static boolean keepPreferredContentViewer() {
150  return preferences.getBoolean(KEEP_PREFERRED_VIEWER, false);
151  }
152 
153  public static void setKeepPreferredContentViewer(boolean value) {
154  preferences.putBoolean(KEEP_PREFERRED_VIEWER, value);
155  }
156 
157  public static boolean hideKnownFilesInDataSourcesTree() {
158  return preferences.getBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, false);
159  }
160 
161  public static void setHideKnownFilesInDataSourcesTree(boolean value) {
162  preferences.putBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, value);
163  }
164 
165  public static boolean hideKnownFilesInViewsTree() {
166  return preferences.getBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, true);
167  }
168 
169  public static void setHideKnownFilesInViewsTree(boolean value) {
170  preferences.putBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, value);
171  }
172 
173  public static boolean hideSlackFilesInDataSourcesTree() {
174  return preferences.getBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, true);
175  }
176 
177  public static void setHideSlackFilesInDataSourcesTree(boolean value) {
178  preferences.putBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, value);
179  }
180 
181  public static boolean hideSlackFilesInViewsTree() {
182  return preferences.getBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, true);
183  }
184 
185  public static void setHideSlackFilesInViewsTree(boolean value) {
186  preferences.putBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, value);
187  }
188 
189  public static boolean displayTimesInLocalTime() {
190  return preferences.getBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, true);
191  }
192 
193  public static void setDisplayTimesInLocalTime(boolean value) {
194  preferences.putBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, value);
195  }
196 
197  public static String getTimeZoneForDisplays() {
198  return preferences.get(TIME_ZONE_FOR_DISPLAYS, TimeZone.GMT_ZONE.getID());
199  }
200 
201  public static void setTimeZoneForDisplays(String timeZone) {
202  preferences.put(TIME_ZONE_FOR_DISPLAYS, timeZone);
203  }
204 
205  public static int numberOfFileIngestThreads() {
206  return preferences.getInt(NUMBER_OF_FILE_INGEST_THREADS, 2);
207  }
208 
209  public static void setNumberOfFileIngestThreads(int value) {
210  preferences.putInt(NUMBER_OF_FILE_INGEST_THREADS, value);
211  }
212 
213  @Deprecated
214  public static boolean groupItemsInTreeByDatasource() {
215  return preferences.getBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, false);
216  }
217 
218  @Deprecated
219  public static void setGroupItemsInTreeByDatasource(boolean value) {
220  preferences.putBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, value);
221  }
222 
229  public static boolean showOnlyCurrentUserTags() {
230  return preferences.getBoolean(SHOW_ONLY_CURRENT_USER_TAGS, false);
231  }
232 
239  public static void setShowOnlyCurrentUserTags(boolean value) {
240  preferences.putBoolean(SHOW_ONLY_CURRENT_USER_TAGS, value);
241  }
242 
250  public static boolean getHideSCOColumns() {
251  return preferences.getBoolean(HIDE_SCO_COLUMNS, false);
252  }
253 
261  public static void setHideSCOColumns(boolean value) {
262  preferences.putBoolean(HIDE_SCO_COLUMNS, value);
263  }
264 
265  public static void setDisplayTranslatedFileNames(boolean value) {
266  preferences.putBoolean(DISPLAY_TRANSLATED_NAMES, value);
267  }
268 
269  public static boolean displayTranslatedFileNames() {
270  return preferences.getBoolean(DISPLAY_TRANSLATED_NAMES, DISPLAY_TRANSLATED_NAMES_DEFAULT);
271  }
272 
280  public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws UserPreferencesException {
281  DbType dbType;
282  try {
283  dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE, "POSTGRESQL")); //NON-NLS
284  } catch (Exception ex) {
285  dbType = DbType.SQLITE;
286  }
287  try {
288  return new CaseDbConnectionInfo(
289  preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP, ""),
290  preferences.get(EXTERNAL_DATABASE_PORTNUMBER, "5432"),
291  preferences.get(EXTERNAL_DATABASE_USER, ""),
292  TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")),
293  dbType);
294  } catch (TextConverterException ex) {
295  throw new UserPreferencesException("Failure converting password hex text to text.", ex); // NON-NLS
296  }
297  }
298 
307  public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) throws UserPreferencesException {
308  preferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost());
309  preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort());
310  preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName());
311  try {
312  preferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convertTextToHexText(connectionInfo.getPassword()));
313  } catch (TextConverterException ex) {
314  throw new UserPreferencesException("Failure converting text to password hext text", ex); // NON-NLS
315  }
316  preferences.put(EXTERNAL_DATABASE_TYPE, connectionInfo.getDbType().toString());
317  }
318 
319  public static void setIsMultiUserModeEnabled(boolean enabled) {
320  preferences.putBoolean(IS_MULTI_USER_MODE_ENABLED, enabled);
321  }
322 
323  public static boolean getIsMultiUserModeEnabled() {
324  return preferences.getBoolean(IS_MULTI_USER_MODE_ENABLED, false);
325  }
326 
327  public static String getIndexingServerHost() {
328  return preferences.get(INDEXING_SERVER_HOST, "");
329  }
330 
331  public static void setIndexingServerHost(String hostName) {
332  preferences.put(INDEXING_SERVER_HOST, hostName);
333  }
334 
335  public static String getIndexingServerPort() {
336  return preferences.get(INDEXING_SERVER_PORT, "8983");
337  }
338 
339  public static void setIndexingServerPort(int port) {
340  preferences.putInt(INDEXING_SERVER_PORT, port);
341  }
342 
343  public static void setTextTranslatorName(String textTranslatorName) {
344  preferences.put(TEXT_TRANSLATOR_NAME, textTranslatorName);
345  }
346 
347  public static String getTextTranslatorName() {
348  return preferences.get(TEXT_TRANSLATOR_NAME, null);
349  }
350 
359  preferences.put(MESSAGE_SERVICE_HOST, info.getHost());
360  preferences.put(MESSAGE_SERVICE_PORT, Integer.toString(info.getPort()));
361  preferences.put(MESSAGE_SERVICE_USER, info.getUserName());
362  try {
363  preferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword()));
364  } catch (TextConverterException ex) {
365  throw new UserPreferencesException("Failed to convert password text to hex text.", ex);
366  }
367  }
368 
377  int port;
378  try {
379  port = Integer.parseInt(preferences.get(MESSAGE_SERVICE_PORT, DEFAULT_PORT_STRING));
380  } catch (NumberFormatException ex) {
381  // if there is an error parsing the port number, use the default port number
382  port = DEFAULT_PORT_INT;
383  }
384 
385  try {
386  return new MessageServiceConnectionInfo(
387  preferences.get(MESSAGE_SERVICE_HOST, ""),
388  port,
389  preferences.get(MESSAGE_SERVICE_USER, ""),
390  TextConverter.convertHexTextToText(preferences.get(MESSAGE_SERVICE_PASSWORD, "")));
391  } catch (TextConverterException ex) {
392  throw new UserPreferencesException("Failed to convert password hex text to text.", ex);
393  }
394  }
395 
401  public static int getProcessTimeOutHrs() {
402  int timeOut = preferences.getInt(PROCESS_TIME_OUT_HOURS, DEFAULT_PROCESS_TIMEOUT_HR);
403  if (timeOut < 0) {
404  timeOut = 0;
405  }
406  return timeOut;
407  }
408 
414  public static void setProcessTimeOutHrs(int value) {
415  if (value < 0) {
416  value = 0;
417  }
418  preferences.putInt(PROCESS_TIME_OUT_HOURS, value);
419  }
420 
428  public static boolean getIsTimeOutEnabled() {
429  boolean enabled = preferences.getBoolean(PROCESS_TIME_OUT_ENABLED, false);
430  return enabled;
431  }
432 
440  public static void setIsTimeOutEnabled(boolean enabled) {
441  preferences.putBoolean(PROCESS_TIME_OUT_ENABLED, enabled);
442  }
443 
449  public static String getAppName() {
450  return preferences.get(APP_NAME, Version.getName());
451  }
452 
458  public static void setAppName(String name) {
459  preferences.put(APP_NAME, name);
460  }
461 
467  public static int getLogFileCount() {
468  return preferences.getInt(MAX_NUM_OF_LOG_FILE, LOG_FILE_NUM_INT);
469  }
470 
476  public static int getDefaultLogFileCount() {
477  return LOG_FILE_NUM_INT;
478  }
479 
485  public static void setLogFileCount(int count) {
486  preferences.putInt(MAX_NUM_OF_LOG_FILE, count);
487  }
488 
494  public static int getMaxSolrVMSize() {
495  return preferences.getInt(SOLR_MAX_JVM_SIZE, 512);
496  }
497 
503  public static void setMaxSolrVMSize(int maxSize) {
504  preferences.putInt(SOLR_MAX_JVM_SIZE, maxSize);
505  }
506 
512  public static int getResultsTablePageSize() {
513  return preferences.getInt(RESULTS_TABLE_PAGE_SIZE, 10_000);
514  }
515 
521  public static void setResultsTablePageSize(int pageSize) {
522  preferences.putInt(RESULTS_TABLE_PAGE_SIZE, pageSize);
523  }
524 
530  public static void setExternalHexEditorPath(String executablePath) {
531  preferences.put(EXTERNAL_HEX_EDITOR_PATH, executablePath);
532  }
533 
540  public static String getExternalHexEditorPath() {
541  return preferences.get(EXTERNAL_HEX_EDITOR_PATH, Paths.get("C:", "Program Files", "HxD", "HxD.exe").toString());
542  }
543 
549  public static void setGeolocationTileOption(int option) {
550  preferences.putInt(GEO_TILE_OPTION, option);
551  }
552 
558  public static int getGeolocationtTileOption() {
559  return preferences.getInt(GEO_TILE_OPTION, 0);
560  }
561 
567  public static void setGeolocationOsmZipPath(String absolutePath) {
568  preferences.put(GEO_OSM_TILE_ZIP_PATH, absolutePath);
569  }
570 
577  public static String getGeolocationOsmZipPath() {
578  return preferences.get(GEO_OSM_TILE_ZIP_PATH, "");
579  }
580 
586  public static void setGeolocationOsmServerAddress(String address) {
587  preferences.put(GEO_OSM_SERVER_ADDRESS, address);
588  }
589 
595  public static String getGeolocationOsmServerAddress() {
596  return preferences.get(GEO_OSM_SERVER_ADDRESS, "");
597  }
598 
604  public static void setGeolocationMBTilesFilePath(String absolutePath) {
605  preferences.put(GEO_MBTILES_FILE_PATH, absolutePath);
606  }
607 
613  public static String getGeolocationMBTilesFilePath() {
614  return preferences.get(GEO_MBTILES_FILE_PATH, "");
615  }
616 
622  public static String getAppTempDirectory() {
624  .toAbsolutePath().toString();
625  }
626 }
static synchronized String getConfigSetting(String moduleName, String settingName)
static void setGroupItemsInTreeByDatasource(boolean value)
static void setKeepPreferredContentViewer(boolean value)
static void setDisplayTimesInLocalTime(boolean value)
static void setMode(SelectedMode mode)
static void setHideSlackFilesInViewsTree(boolean value)
static CaseDbConnectionInfo getDatabaseConnectionInfo()
static void setHideSCOColumns(boolean value)
static void setIsTimeOutEnabled(boolean enabled)
static void setResultsTablePageSize(int pageSize)
static void setIsMultiUserModeEnabled(boolean enabled)
static void removeChangeListener(PreferenceChangeListener listener)
static void setMessageServiceConnectionInfo(MessageServiceConnectionInfo info)
static synchronized boolean settingExists(String moduleName, String settingName)
static void setHideKnownFilesInViewsTree(boolean value)
static void setTextTranslatorName(String textTranslatorName)
static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo)
static void setTimeZoneForDisplays(String timeZone)
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static void setIndexingServerHost(String hostName)
static void setDisplayTranslatedFileNames(boolean value)
static void setHideSlackFilesInDataSourcesTree(boolean value)
static void setHideKnownFilesInDataSourcesTree(boolean value)
static void setGeolocationOsmZipPath(String absolutePath)
static void setExternalHexEditorPath(String executablePath)
static void addChangeListener(PreferenceChangeListener listener)
static void setGeolocationMBTilesFilePath(String absolutePath)
static void setShowOnlyCurrentUserTags(boolean value)
static String convertTextToHexText(String property)
static void setGeolocationOsmServerAddress(String address)
static MessageServiceConnectionInfo getMessageServiceConnectionInfo()
static String convertHexTextToText(String property)

Copyright © 2012-2020 Basis Technology. Generated on: Tue Sep 22 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.