Autopsy  4.14.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;
32 import org.sleuthkit.datamodel.CaseDbConnectionInfo;
33 import org.sleuthkit.datamodel.TskData.DbType;
34 
39 public final class UserPreferences {
40 
41  private static final Preferences preferences = NbPreferences.forModule(UserPreferences.class);
42  public static final String KEEP_PREFERRED_VIEWER = "KeepPreferredViewer"; // NON-NLS
43  public static final String HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE = "HideKnownFilesInDataSourcesTree"; //NON-NLS
44  public static final String HIDE_KNOWN_FILES_IN_VIEWS_TREE = "HideKnownFilesInViewsTree"; //NON-NLS
45  public static final String HIDE_SLACK_FILES_IN_DATA_SRCS_TREE = "HideSlackFilesInDataSourcesTree"; //NON-NLS
46  public static final String HIDE_SLACK_FILES_IN_VIEWS_TREE = "HideSlackFilesInViewsTree"; //NON-NLS
47  public static final String DISPLAY_TIMES_IN_LOCAL_TIME = "DisplayTimesInLocalTime"; //NON-NLS
48  public static final String TIME_ZONE_FOR_DISPLAYS = "TimeZoneForDisplays"; //NON-NLS
49  public static final String NUMBER_OF_FILE_INGEST_THREADS = "NumberOfFileIngestThreads"; //NON-NLS
50  public static final String IS_MULTI_USER_MODE_ENABLED = "IsMultiUserModeEnabled"; //NON-NLS
51  public static final String EXTERNAL_DATABASE_HOSTNAME_OR_IP = "ExternalDatabaseHostnameOrIp"; //NON-NLS
52  public static final String EXTERNAL_DATABASE_PORTNUMBER = "ExternalDatabasePortNumber"; //NON-NLS
53  public static final String EXTERNAL_DATABASE_NAME = "ExternalDatabaseName"; //NON-NLS
54  public static final String EXTERNAL_DATABASE_USER = "ExternalDatabaseUsername"; //NON-NLS
55  public static final String EXTERNAL_DATABASE_PASSWORD = "ExternalDatabasePassword"; //NON-NLS
56  public static final String EXTERNAL_DATABASE_TYPE = "ExternalDatabaseType"; //NON-NLS
57  public static final String INDEXING_SERVER_HOST = "IndexingServerHost"; //NON-NLS
58  public static final String INDEXING_SERVER_PORT = "IndexingServerPort"; //NON-NLS
59  private static final String MESSAGE_SERVICE_PASSWORD = "MessageServicePassword"; //NON-NLS
60  private static final String MESSAGE_SERVICE_USER = "MessageServiceUser"; //NON-NLS
61  private static final String MESSAGE_SERVICE_HOST = "MessageServiceHost"; //NON-NLS
62  private static final String MESSAGE_SERVICE_PORT = "MessageServicePort"; //NON-NLS
63  public static final String TEXT_TRANSLATOR_NAME = "TextTranslatorName";
64  public static final String PROCESS_TIME_OUT_ENABLED = "ProcessTimeOutEnabled"; //NON-NLS
65  public static final String PROCESS_TIME_OUT_HOURS = "ProcessTimeOutHours"; //NON-NLS
66  private static final int DEFAULT_PROCESS_TIMEOUT_HR = 60;
67  private static final String DEFAULT_PORT_STRING = "61616";
68  private static final int DEFAULT_PORT_INT = 61616;
69  private static final String APP_NAME = "AppName";
70  public static final String SETTINGS_PROPERTIES = "AutoIngest";
71  private static final String MODE = "AutopsyMode"; // NON-NLS
72  private static final String MAX_NUM_OF_LOG_FILE = "MaximumNumberOfLogFiles";
73  private static final int LOG_FILE_NUM_INT = 10;
74  public static final String GROUP_ITEMS_IN_TREE_BY_DATASOURCE = "GroupItemsInTreeByDataSource"; //NON-NLS
75  public static final String SHOW_ONLY_CURRENT_USER_TAGS = "ShowOnlyCurrentUserTags";
76  public static final String HIDE_SCO_COLUMNS = "HideCentralRepoCommentsAndOccurrences"; //The key for this setting pre-dates the settings current functionality //NON-NLS
77  public static final String DISPLAY_TRANSLATED_NAMES = "DisplayTranslatedNames";
78  private static final boolean DISPLAY_TRANSLATED_NAMES_DEFAULT = true;
79  public static final String EXTERNAL_HEX_EDITOR_PATH = "ExternalHexEditorPath";
80  public static final String SOLR_MAX_JVM_SIZE = "SolrMaxJVMSize";
81  public static final String RESULTS_TABLE_PAGE_SIZE = "ResultsTablePageSize";
82  private static final String GEO_TILE_OPTION = "GeolocationTileOption";
83  private static final String GEO_OSM_TILE_ZIP_PATH = "GeolocationOsmZipPath";
84  private static final String GEO_OSM_SERVER_ADDRESS = "GeolocationOsmServerAddress";
85  private static final String GEO_MBTILES_FILE_PATH = "GeolcoationMBTilesFilePath";
86 
87  // Prevent instantiation.
88  private UserPreferences() {
89  }
90 
91  public enum SelectedMode {
92 
94  AUTOINGEST
95  };
96 
102  public static SelectedMode getMode() {
103  if (ModuleSettings.settingExists(SETTINGS_PROPERTIES, MODE)) {
104  int ordinal = Integer.parseInt(ModuleSettings.getConfigSetting(SETTINGS_PROPERTIES, MODE));
105  return UserPreferences.SelectedMode.values()[ordinal];
106  }
108  }
109 
115  public static void setMode(SelectedMode mode) {
116  ModuleSettings.setConfigSetting(SETTINGS_PROPERTIES, MODE, Integer.toString(mode.ordinal()));
117  }
118 
125  public static void reloadFromStorage() throws BackingStoreException {
126  preferences.sync();
127  }
128 
136  public static void saveToStorage() throws BackingStoreException {
137  preferences.flush();
138  }
139 
140  public static void addChangeListener(PreferenceChangeListener listener) {
141  preferences.addPreferenceChangeListener(listener);
142  }
143 
144  public static void removeChangeListener(PreferenceChangeListener listener) {
145  preferences.removePreferenceChangeListener(listener);
146  }
147 
148  public static boolean keepPreferredContentViewer() {
149  return preferences.getBoolean(KEEP_PREFERRED_VIEWER, false);
150  }
151 
152  public static void setKeepPreferredContentViewer(boolean value) {
153  preferences.putBoolean(KEEP_PREFERRED_VIEWER, value);
154  }
155 
156  public static boolean hideKnownFilesInDataSourcesTree() {
157  return preferences.getBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, false);
158  }
159 
160  public static void setHideKnownFilesInDataSourcesTree(boolean value) {
161  preferences.putBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, value);
162  }
163 
164  public static boolean hideKnownFilesInViewsTree() {
165  return preferences.getBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, true);
166  }
167 
168  public static void setHideKnownFilesInViewsTree(boolean value) {
169  preferences.putBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, value);
170  }
171 
172  public static boolean hideSlackFilesInDataSourcesTree() {
173  return preferences.getBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, true);
174  }
175 
176  public static void setHideSlackFilesInDataSourcesTree(boolean value) {
177  preferences.putBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, value);
178  }
179 
180  public static boolean hideSlackFilesInViewsTree() {
181  return preferences.getBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, true);
182  }
183 
184  public static void setHideSlackFilesInViewsTree(boolean value) {
185  preferences.putBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, value);
186  }
187 
188  public static boolean displayTimesInLocalTime() {
189  return preferences.getBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, true);
190  }
191 
192  public static void setDisplayTimesInLocalTime(boolean value) {
193  preferences.putBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, value);
194  }
195 
196  public static String getTimeZoneForDisplays() {
197  return preferences.get(TIME_ZONE_FOR_DISPLAYS, TimeZone.GMT_ZONE.getID());
198  }
199 
200  public static void setTimeZoneForDisplays(String timeZone) {
201  preferences.put(TIME_ZONE_FOR_DISPLAYS, timeZone);
202  }
203 
204  public static int numberOfFileIngestThreads() {
205  return preferences.getInt(NUMBER_OF_FILE_INGEST_THREADS, 2);
206  }
207 
208  public static void setNumberOfFileIngestThreads(int value) {
209  preferences.putInt(NUMBER_OF_FILE_INGEST_THREADS, value);
210  }
211 
212  @Deprecated
213  public static boolean groupItemsInTreeByDatasource() {
214  return preferences.getBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, false);
215  }
216 
217  @Deprecated
218  public static void setGroupItemsInTreeByDatasource(boolean value) {
219  preferences.putBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, value);
220  }
221 
228  public static boolean showOnlyCurrentUserTags() {
229  return preferences.getBoolean(SHOW_ONLY_CURRENT_USER_TAGS, false);
230  }
231 
238  public static void setShowOnlyCurrentUserTags(boolean value) {
239  preferences.putBoolean(SHOW_ONLY_CURRENT_USER_TAGS, value);
240  }
241 
249  public static boolean getHideSCOColumns() {
250  return preferences.getBoolean(HIDE_SCO_COLUMNS, false);
251  }
252 
260  public static void setHideSCOColumns(boolean value) {
261  preferences.putBoolean(HIDE_SCO_COLUMNS, value);
262  }
263 
264  public static void setDisplayTranslatedFileNames(boolean value) {
265  preferences.putBoolean(DISPLAY_TRANSLATED_NAMES, value);
266  }
267 
268  public static boolean displayTranslatedFileNames() {
269  return preferences.getBoolean(DISPLAY_TRANSLATED_NAMES, DISPLAY_TRANSLATED_NAMES_DEFAULT);
270  }
271 
279  public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws UserPreferencesException {
280  DbType dbType;
281  try {
282  dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE, "POSTGRESQL")); //NON-NLS
283  } catch (Exception ex) {
284  dbType = DbType.SQLITE;
285  }
286  try {
287  return new CaseDbConnectionInfo(
288  preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP, ""),
289  preferences.get(EXTERNAL_DATABASE_PORTNUMBER, "5432"),
290  preferences.get(EXTERNAL_DATABASE_USER, ""),
291  TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")),
292  dbType);
293  } catch (TextConverterException ex) {
294  throw new UserPreferencesException("Failure converting password hex text to text.", ex); // NON-NLS
295  }
296  }
297 
306  public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) throws UserPreferencesException {
307  preferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost());
308  preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort());
309  preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName());
310  try {
311  preferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convertTextToHexText(connectionInfo.getPassword()));
312  } catch (TextConverterException ex) {
313  throw new UserPreferencesException("Failure converting text to password hext text", ex); // NON-NLS
314  }
315  preferences.put(EXTERNAL_DATABASE_TYPE, connectionInfo.getDbType().toString());
316  }
317 
318  public static void setIsMultiUserModeEnabled(boolean enabled) {
319  preferences.putBoolean(IS_MULTI_USER_MODE_ENABLED, enabled);
320  }
321 
322  public static boolean getIsMultiUserModeEnabled() {
323  return preferences.getBoolean(IS_MULTI_USER_MODE_ENABLED, false);
324  }
325 
326  public static String getIndexingServerHost() {
327  return preferences.get(INDEXING_SERVER_HOST, "");
328  }
329 
330  public static void setIndexingServerHost(String hostName) {
331  preferences.put(INDEXING_SERVER_HOST, hostName);
332  }
333 
334  public static String getIndexingServerPort() {
335  return preferences.get(INDEXING_SERVER_PORT, "8983");
336  }
337 
338  public static void setIndexingServerPort(int port) {
339  preferences.putInt(INDEXING_SERVER_PORT, port);
340  }
341 
342  public static void setTextTranslatorName(String textTranslatorName) {
343  preferences.put(TEXT_TRANSLATOR_NAME, textTranslatorName);
344  }
345 
346  public static String getTextTranslatorName() {
347  return preferences.get(TEXT_TRANSLATOR_NAME, null);
348  }
349 
358  preferences.put(MESSAGE_SERVICE_HOST, info.getHost());
359  preferences.put(MESSAGE_SERVICE_PORT, Integer.toString(info.getPort()));
360  preferences.put(MESSAGE_SERVICE_USER, info.getUserName());
361  try {
362  preferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword()));
363  } catch (TextConverterException ex) {
364  throw new UserPreferencesException("Failed to convert password text to hex text.", ex);
365  }
366  }
367 
376  int port;
377  try {
378  port = Integer.parseInt(preferences.get(MESSAGE_SERVICE_PORT, DEFAULT_PORT_STRING));
379  } catch (NumberFormatException ex) {
380  // if there is an error parsing the port number, use the default port number
381  port = DEFAULT_PORT_INT;
382  }
383 
384  try {
385  return new MessageServiceConnectionInfo(
386  preferences.get(MESSAGE_SERVICE_HOST, ""),
387  port,
388  preferences.get(MESSAGE_SERVICE_USER, ""),
389  TextConverter.convertHexTextToText(preferences.get(MESSAGE_SERVICE_PASSWORD, "")));
390  } catch (TextConverterException ex) {
391  throw new UserPreferencesException("Failed to convert password hex text to text.", ex);
392  }
393  }
394 
400  public static int getProcessTimeOutHrs() {
401  int timeOut = preferences.getInt(PROCESS_TIME_OUT_HOURS, DEFAULT_PROCESS_TIMEOUT_HR);
402  if (timeOut < 0) {
403  timeOut = 0;
404  }
405  return timeOut;
406  }
407 
413  public static void setProcessTimeOutHrs(int value) {
414  if (value < 0) {
415  value = 0;
416  }
417  preferences.putInt(PROCESS_TIME_OUT_HOURS, value);
418  }
419 
427  public static boolean getIsTimeOutEnabled() {
428  boolean enabled = preferences.getBoolean(PROCESS_TIME_OUT_ENABLED, false);
429  return enabled;
430  }
431 
439  public static void setIsTimeOutEnabled(boolean enabled) {
440  preferences.putBoolean(PROCESS_TIME_OUT_ENABLED, enabled);
441  }
442 
448  public static String getAppName() {
449  return preferences.get(APP_NAME, Version.getName());
450  }
451 
457  public static void setAppName(String name) {
458  preferences.put(APP_NAME, name);
459  }
460 
466  public static int getLogFileCount() {
467  return preferences.getInt(MAX_NUM_OF_LOG_FILE, LOG_FILE_NUM_INT);
468  }
469 
475  public static int getDefaultLogFileCount() {
476  return LOG_FILE_NUM_INT;
477  }
478 
484  public static void setLogFileCount(int count) {
485  preferences.putInt(MAX_NUM_OF_LOG_FILE, count);
486  }
487 
493  public static int getMaxSolrVMSize() {
494  return preferences.getInt(SOLR_MAX_JVM_SIZE, 512);
495  }
496 
502  public static void setMaxSolrVMSize(int maxSize) {
503  preferences.putInt(SOLR_MAX_JVM_SIZE, maxSize);
504  }
505 
511  public static int getResultsTablePageSize() {
512  return preferences.getInt(RESULTS_TABLE_PAGE_SIZE, 10_000);
513  }
514 
520  public static void setResultsTablePageSize(int pageSize) {
521  preferences.putInt(RESULTS_TABLE_PAGE_SIZE, pageSize);
522  }
523 
529  public static void setExternalHexEditorPath(String executablePath) {
530  preferences.put(EXTERNAL_HEX_EDITOR_PATH, executablePath);
531  }
532 
539  public static String getExternalHexEditorPath() {
540  return preferences.get(EXTERNAL_HEX_EDITOR_PATH, Paths.get("C:", "Program Files", "HxD", "HxD.exe").toString());
541  }
542 
548  public static void setGeolocationTileOption(int option) {
549  preferences.putInt(GEO_TILE_OPTION, option);
550  }
551 
557  public static int getGeolocationtTileOption() {
558  return preferences.getInt(GEO_TILE_OPTION, 0);
559  }
560 
566  public static void setGeolocationOsmZipPath(String absolutePath) {
567  preferences.put(GEO_OSM_TILE_ZIP_PATH, absolutePath);
568  }
569 
576  public static String getGeolocationOsmZipPath() {
577  return preferences.get(GEO_OSM_TILE_ZIP_PATH, "");
578  }
579 
585  public static void setGeolocationOsmServerAddress(String address) {
586  preferences.put(GEO_OSM_SERVER_ADDRESS, address);
587  }
588 
594  public static String getGeolocationOsmServerAddress() {
595  return preferences.get(GEO_OSM_SERVER_ADDRESS, "");
596  }
597 
603  public static void setGeolocationMBTilesFilePath(String absolutePath) {
604  preferences.put(GEO_MBTILES_FILE_PATH, absolutePath);
605  }
606 
612  public static String getGeolocationMBTilesFilePath() {
613  return preferences.get(GEO_MBTILES_FILE_PATH, "");
614  }
615 }
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: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.