Autopsy  4.13.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-2019 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  private 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  public static final String EXTERNAL_HEX_EDITOR_PATH = "ExternalHexEditorPath";
79  public static final String SOLR_MAX_JVM_SIZE = "SolrMaxJVMSize";
80  public static final String RESULTS_TABLE_PAGE_SIZE = "ResultsTablePageSize";
81  private static final String GEO_TILE_OPTION = "GeolocationTileOption";
82  private static final String GEO_OSM_TILE_ZIP_PATH = "GeolocationOsmZipPath";
83  private static final String GEO_OSM_SERVER_ADDRESS = "GeolocationOsmServerAddress";
84  private static final String GEO_MBTILES_FILE_PATH = "GeolcoationMBTilesFilePath";
85 
86  // Prevent instantiation.
87  private UserPreferences() {
88  }
89 
90  public enum SelectedMode {
91 
93  AUTOINGEST
94  };
95 
101  public static SelectedMode getMode() {
102  if (ModuleSettings.settingExists(SETTINGS_PROPERTIES, MODE)) {
103  int ordinal = Integer.parseInt(ModuleSettings.getConfigSetting(SETTINGS_PROPERTIES, MODE));
104  return UserPreferences.SelectedMode.values()[ordinal];
105  }
107  }
108 
114  public static void setMode(SelectedMode mode) {
115  ModuleSettings.setConfigSetting(SETTINGS_PROPERTIES, MODE, Integer.toString(mode.ordinal()));
116  }
117 
124  public static void reloadFromStorage() throws BackingStoreException {
125  preferences.sync();
126  }
127 
135  public static void saveToStorage() throws BackingStoreException {
136  preferences.flush();
137  }
138 
139  public static void addChangeListener(PreferenceChangeListener listener) {
140  preferences.addPreferenceChangeListener(listener);
141  }
142 
143  public static void removeChangeListener(PreferenceChangeListener listener) {
144  preferences.removePreferenceChangeListener(listener);
145  }
146 
147  public static boolean keepPreferredContentViewer() {
148  return preferences.getBoolean(KEEP_PREFERRED_VIEWER, false);
149  }
150 
151  public static void setKeepPreferredContentViewer(boolean value) {
152  preferences.putBoolean(KEEP_PREFERRED_VIEWER, value);
153  }
154 
155  public static boolean hideKnownFilesInDataSourcesTree() {
156  return preferences.getBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, false);
157  }
158 
159  public static void setHideKnownFilesInDataSourcesTree(boolean value) {
160  preferences.putBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, value);
161  }
162 
163  public static boolean hideKnownFilesInViewsTree() {
164  return preferences.getBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, true);
165  }
166 
167  public static void setHideKnownFilesInViewsTree(boolean value) {
168  preferences.putBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, value);
169  }
170 
171  public static boolean hideSlackFilesInDataSourcesTree() {
172  return preferences.getBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, true);
173  }
174 
175  public static void setHideSlackFilesInDataSourcesTree(boolean value) {
176  preferences.putBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, value);
177  }
178 
179  public static boolean hideSlackFilesInViewsTree() {
180  return preferences.getBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, true);
181  }
182 
183  public static void setHideSlackFilesInViewsTree(boolean value) {
184  preferences.putBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, value);
185  }
186 
187  public static boolean displayTimesInLocalTime() {
188  return preferences.getBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, true);
189  }
190 
191  public static void setDisplayTimesInLocalTime(boolean value) {
192  preferences.putBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, value);
193  }
194 
195  public static String getTimeZoneForDisplays() {
196  return preferences.get(TIME_ZONE_FOR_DISPLAYS, TimeZone.GMT_ZONE.getID());
197  }
198 
199  public static void setTimeZoneForDisplays(String timeZone) {
200  preferences.put(TIME_ZONE_FOR_DISPLAYS, timeZone);
201  }
202 
203  public static int numberOfFileIngestThreads() {
204  return preferences.getInt(NUMBER_OF_FILE_INGEST_THREADS, 2);
205  }
206 
207  public static void setNumberOfFileIngestThreads(int value) {
208  preferences.putInt(NUMBER_OF_FILE_INGEST_THREADS, value);
209  }
210 
211  @Deprecated
212  public static boolean groupItemsInTreeByDatasource() {
213  return preferences.getBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, false);
214  }
215 
216  @Deprecated
217  public static void setGroupItemsInTreeByDatasource(boolean value) {
218  preferences.putBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, value);
219  }
220 
227  public static boolean showOnlyCurrentUserTags() {
228  return preferences.getBoolean(SHOW_ONLY_CURRENT_USER_TAGS, false);
229  }
230 
237  public static void setShowOnlyCurrentUserTags(boolean value) {
238  preferences.putBoolean(SHOW_ONLY_CURRENT_USER_TAGS, value);
239  }
240 
248  public static boolean getHideSCOColumns() {
249  return preferences.getBoolean(HIDE_SCO_COLUMNS, false);
250  }
251 
259  public static void setHideSCOColumns(boolean value) {
260  preferences.putBoolean(HIDE_SCO_COLUMNS, value);
261  }
262 
263  public static void setDisplayTranslatedFileNames(boolean value) {
264  preferences.putBoolean(DISPLAY_TRANSLATED_NAMES, value);
265  }
266 
267  public static boolean displayTranslatedFileNames() {
268  return preferences.getBoolean(DISPLAY_TRANSLATED_NAMES, false);
269  }
270 
278  public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws UserPreferencesException {
279  DbType dbType;
280  try {
281  dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE, "POSTGRESQL")); //NON-NLS
282  } catch (Exception ex) {
283  dbType = DbType.SQLITE;
284  }
285  try {
286  return new CaseDbConnectionInfo(
287  preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP, ""),
288  preferences.get(EXTERNAL_DATABASE_PORTNUMBER, "5432"),
289  preferences.get(EXTERNAL_DATABASE_USER, ""),
290  TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")),
291  dbType);
292  } catch (TextConverterException ex) {
293  throw new UserPreferencesException("Failure converting password hex text to text.", ex); // NON-NLS
294  }
295  }
296 
305  public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) throws UserPreferencesException {
306  preferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost());
307  preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort());
308  preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName());
309  try {
310  preferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convertTextToHexText(connectionInfo.getPassword()));
311  } catch (TextConverterException ex) {
312  throw new UserPreferencesException("Failure converting text to password hext text", ex); // NON-NLS
313  }
314  preferences.put(EXTERNAL_DATABASE_TYPE, connectionInfo.getDbType().toString());
315  }
316 
317  public static void setIsMultiUserModeEnabled(boolean enabled) {
318  preferences.putBoolean(IS_MULTI_USER_MODE_ENABLED, enabled);
319  }
320 
321  public static boolean getIsMultiUserModeEnabled() {
322  return preferences.getBoolean(IS_MULTI_USER_MODE_ENABLED, false);
323  }
324 
325  public static String getIndexingServerHost() {
326  return preferences.get(INDEXING_SERVER_HOST, "");
327  }
328 
329  public static void setIndexingServerHost(String hostName) {
330  preferences.put(INDEXING_SERVER_HOST, hostName);
331  }
332 
333  public static String getIndexingServerPort() {
334  return preferences.get(INDEXING_SERVER_PORT, "8983");
335  }
336 
337  public static void setIndexingServerPort(int port) {
338  preferences.putInt(INDEXING_SERVER_PORT, port);
339  }
340 
341  public static void setTextTranslatorName(String textTranslatorName) {
342  preferences.put(TEXT_TRANSLATOR_NAME, textTranslatorName);
343  }
344 
345  public static String getTextTranslatorName() {
346  return preferences.get(TEXT_TRANSLATOR_NAME, null);
347  }
348 
357  preferences.put(MESSAGE_SERVICE_HOST, info.getHost());
358  preferences.put(MESSAGE_SERVICE_PORT, Integer.toString(info.getPort()));
359  preferences.put(MESSAGE_SERVICE_USER, info.getUserName());
360  try {
361  preferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword()));
362  } catch (TextConverterException ex) {
363  throw new UserPreferencesException("Failed to convert password text to hex text.", ex);
364  }
365  }
366 
375  int port;
376  try {
377  port = Integer.parseInt(preferences.get(MESSAGE_SERVICE_PORT, DEFAULT_PORT_STRING));
378  } catch (NumberFormatException ex) {
379  // if there is an error parsing the port number, use the default port number
380  port = DEFAULT_PORT_INT;
381  }
382 
383  try {
384  return new MessageServiceConnectionInfo(
385  preferences.get(MESSAGE_SERVICE_HOST, ""),
386  port,
387  preferences.get(MESSAGE_SERVICE_USER, ""),
388  TextConverter.convertHexTextToText(preferences.get(MESSAGE_SERVICE_PASSWORD, "")));
389  } catch (TextConverterException ex) {
390  throw new UserPreferencesException("Failed to convert password hex text to text.", ex);
391  }
392  }
393 
399  public static int getProcessTimeOutHrs() {
400  int timeOut = preferences.getInt(PROCESS_TIME_OUT_HOURS, DEFAULT_PROCESS_TIMEOUT_HR);
401  if (timeOut < 0) {
402  timeOut = 0;
403  }
404  return timeOut;
405  }
406 
412  public static void setProcessTimeOutHrs(int value) {
413  if (value < 0) {
414  value = 0;
415  }
416  preferences.putInt(PROCESS_TIME_OUT_HOURS, value);
417  }
418 
426  public static boolean getIsTimeOutEnabled() {
427  boolean enabled = preferences.getBoolean(PROCESS_TIME_OUT_ENABLED, false);
428  return enabled;
429  }
430 
438  public static void setIsTimeOutEnabled(boolean enabled) {
439  preferences.putBoolean(PROCESS_TIME_OUT_ENABLED, enabled);
440  }
441 
447  public static String getAppName() {
448  return preferences.get(APP_NAME, Version.getName());
449  }
450 
456  public static void setAppName(String name) {
457  preferences.put(APP_NAME, name);
458  }
459 
465  public static int getLogFileCount() {
466  return preferences.getInt(MAX_NUM_OF_LOG_FILE, LOG_FILE_NUM_INT);
467  }
468 
474  public static int getDefaultLogFileCount() {
475  return LOG_FILE_NUM_INT;
476  }
477 
483  public static void setLogFileCount(int count) {
484  preferences.putInt(MAX_NUM_OF_LOG_FILE, count);
485  }
486 
492  public static int getMaxSolrVMSize() {
493  return preferences.getInt(SOLR_MAX_JVM_SIZE, 512);
494  }
495 
501  public static void setMaxSolrVMSize(int maxSize) {
502  preferences.putInt(SOLR_MAX_JVM_SIZE, maxSize);
503  }
504 
510  public static int getResultsTablePageSize() {
511  return preferences.getInt(RESULTS_TABLE_PAGE_SIZE, 10_000);
512  }
513 
519  public static void setResultsTablePageSize(int pageSize) {
520  preferences.putInt(RESULTS_TABLE_PAGE_SIZE, pageSize);
521  }
522 
528  public static void setExternalHexEditorPath(String executablePath) {
529  preferences.put(EXTERNAL_HEX_EDITOR_PATH, executablePath);
530  }
531 
538  public static String getExternalHexEditorPath() {
539  return preferences.get(EXTERNAL_HEX_EDITOR_PATH, Paths.get("C:", "Program Files", "HxD", "HxD.exe").toString());
540  }
541 
547  public static void setGeolocationTileOption(int option) {
548  preferences.putInt(GEO_TILE_OPTION, option);
549  }
550 
556  public static int getGeolocationtTileOption() {
557  return preferences.getInt(GEO_TILE_OPTION, 0);
558  }
559 
565  public static void setGeolocationOsmZipPath(String absolutePath) {
566  preferences.put(GEO_OSM_TILE_ZIP_PATH, absolutePath);
567  }
568 
575  public static String getGeolocationOsmZipPath() {
576  return preferences.get(GEO_OSM_TILE_ZIP_PATH, "");
577  }
578 
584  public static void setGeolocationOsmServerAddress(String address) {
585  preferences.put(GEO_OSM_SERVER_ADDRESS, address);
586  }
587 
593  public static String getGeolocationOsmServerAddress() {
594  return preferences.get(GEO_OSM_SERVER_ADDRESS, "");
595  }
596 
602  public static void setGeolocationMBTilesFilePath(String absolutePath) {
603  preferences.put(GEO_MBTILES_FILE_PATH, absolutePath);
604  }
605 
611  public static String getGeolocationMBTilesFilePath() {
612  return preferences.get(GEO_MBTILES_FILE_PATH, "");
613  }
614 }
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 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 String getConfigSetting(String moduleName, String settingName)
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 boolean settingExists(String moduleName, String settingName)
static MessageServiceConnectionInfo getMessageServiceConnectionInfo()
static String convertHexTextToText(String property)

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