Autopsy  4.12.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 
82  // Prevent instantiation.
83  private UserPreferences() {
84  }
85 
86  public enum SelectedMode {
87 
89  AUTOINGEST
90  };
91 
97  public static SelectedMode getMode() {
98  if (ModuleSettings.settingExists(SETTINGS_PROPERTIES, MODE)) {
99  int ordinal = Integer.parseInt(ModuleSettings.getConfigSetting(SETTINGS_PROPERTIES, MODE));
100  return UserPreferences.SelectedMode.values()[ordinal];
101  }
103  }
104 
110  public static void setMode(SelectedMode mode) {
111  ModuleSettings.setConfigSetting(SETTINGS_PROPERTIES, MODE, Integer.toString(mode.ordinal()));
112  }
113 
120  public static void reloadFromStorage() throws BackingStoreException {
121  preferences.sync();
122  }
123 
131  public static void saveToStorage() throws BackingStoreException {
132  preferences.flush();
133  }
134 
135  public static void addChangeListener(PreferenceChangeListener listener) {
136  preferences.addPreferenceChangeListener(listener);
137  }
138 
139  public static void removeChangeListener(PreferenceChangeListener listener) {
140  preferences.removePreferenceChangeListener(listener);
141  }
142 
143  public static boolean keepPreferredContentViewer() {
144  return preferences.getBoolean(KEEP_PREFERRED_VIEWER, false);
145  }
146 
147  public static void setKeepPreferredContentViewer(boolean value) {
148  preferences.putBoolean(KEEP_PREFERRED_VIEWER, value);
149  }
150 
151  public static boolean hideKnownFilesInDataSourcesTree() {
152  return preferences.getBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, false);
153  }
154 
155  public static void setHideKnownFilesInDataSourcesTree(boolean value) {
156  preferences.putBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, value);
157  }
158 
159  public static boolean hideKnownFilesInViewsTree() {
160  return preferences.getBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, true);
161  }
162 
163  public static void setHideKnownFilesInViewsTree(boolean value) {
164  preferences.putBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, value);
165  }
166 
167  public static boolean hideSlackFilesInDataSourcesTree() {
168  return preferences.getBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, true);
169  }
170 
171  public static void setHideSlackFilesInDataSourcesTree(boolean value) {
172  preferences.putBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, value);
173  }
174 
175  public static boolean hideSlackFilesInViewsTree() {
176  return preferences.getBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, true);
177  }
178 
179  public static void setHideSlackFilesInViewsTree(boolean value) {
180  preferences.putBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, value);
181  }
182 
183  public static boolean displayTimesInLocalTime() {
184  return preferences.getBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, true);
185  }
186 
187  public static void setDisplayTimesInLocalTime(boolean value) {
188  preferences.putBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, value);
189  }
190 
191  public static String getTimeZoneForDisplays() {
192  return preferences.get(TIME_ZONE_FOR_DISPLAYS, TimeZone.GMT_ZONE.getID());
193  }
194 
195  public static void setTimeZoneForDisplays(String timeZone) {
196  preferences.put(TIME_ZONE_FOR_DISPLAYS, timeZone);
197  }
198 
199  public static int numberOfFileIngestThreads() {
200  return preferences.getInt(NUMBER_OF_FILE_INGEST_THREADS, 2);
201  }
202 
203  public static void setNumberOfFileIngestThreads(int value) {
204  preferences.putInt(NUMBER_OF_FILE_INGEST_THREADS, value);
205  }
206 
207  @Deprecated
208  public static boolean groupItemsInTreeByDatasource() {
209  return preferences.getBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, false);
210  }
211 
212  @Deprecated
213  public static void setGroupItemsInTreeByDatasource(boolean value) {
214  preferences.putBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, value);
215  }
216 
223  public static boolean showOnlyCurrentUserTags() {
224  return preferences.getBoolean(SHOW_ONLY_CURRENT_USER_TAGS, false);
225  }
226 
233  public static void setShowOnlyCurrentUserTags(boolean value) {
234  preferences.putBoolean(SHOW_ONLY_CURRENT_USER_TAGS, value);
235  }
236 
244  public static boolean getHideSCOColumns() {
245  return preferences.getBoolean(HIDE_SCO_COLUMNS, false);
246  }
247 
255  public static void setHideSCOColumns(boolean value) {
256  preferences.putBoolean(HIDE_SCO_COLUMNS, value);
257  }
258 
259  public static void setDisplayTranslatedFileNames(boolean value) {
260  preferences.putBoolean(DISPLAY_TRANSLATED_NAMES, value);
261  }
262 
263  public static boolean displayTranslatedFileNames() {
264  return preferences.getBoolean(DISPLAY_TRANSLATED_NAMES, false);
265  }
266 
274  public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws UserPreferencesException {
275  DbType dbType;
276  try {
277  dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE, "POSTGRESQL")); //NON-NLS
278  } catch (Exception ex) {
279  dbType = DbType.SQLITE;
280  }
281  try {
282  return new CaseDbConnectionInfo(
283  preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP, ""),
284  preferences.get(EXTERNAL_DATABASE_PORTNUMBER, "5432"),
285  preferences.get(EXTERNAL_DATABASE_USER, ""),
286  TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")),
287  dbType);
288  } catch (TextConverterException ex) {
289  throw new UserPreferencesException("Failure converting password hex text to text.", ex); // NON-NLS
290  }
291  }
292 
301  public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) throws UserPreferencesException {
302  preferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost());
303  preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort());
304  preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName());
305  try {
306  preferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convertTextToHexText(connectionInfo.getPassword()));
307  } catch (TextConverterException ex) {
308  throw new UserPreferencesException("Failure converting text to password hext text", ex); // NON-NLS
309  }
310  preferences.put(EXTERNAL_DATABASE_TYPE, connectionInfo.getDbType().toString());
311  }
312 
313  public static void setIsMultiUserModeEnabled(boolean enabled) {
314  preferences.putBoolean(IS_MULTI_USER_MODE_ENABLED, enabled);
315  }
316 
317  public static boolean getIsMultiUserModeEnabled() {
318  return preferences.getBoolean(IS_MULTI_USER_MODE_ENABLED, false);
319  }
320 
321  public static String getIndexingServerHost() {
322  return preferences.get(INDEXING_SERVER_HOST, "");
323  }
324 
325  public static void setIndexingServerHost(String hostName) {
326  preferences.put(INDEXING_SERVER_HOST, hostName);
327  }
328 
329  public static String getIndexingServerPort() {
330  return preferences.get(INDEXING_SERVER_PORT, "8983");
331  }
332 
333  public static void setIndexingServerPort(int port) {
334  preferences.putInt(INDEXING_SERVER_PORT, port);
335  }
336 
337  public static void setTextTranslatorName(String textTranslatorName) {
338  preferences.put(TEXT_TRANSLATOR_NAME, textTranslatorName);
339  }
340 
341  public static String getTextTranslatorName() {
342  return preferences.get(TEXT_TRANSLATOR_NAME, null);
343  }
344 
353  preferences.put(MESSAGE_SERVICE_HOST, info.getHost());
354  preferences.put(MESSAGE_SERVICE_PORT, Integer.toString(info.getPort()));
355  preferences.put(MESSAGE_SERVICE_USER, info.getUserName());
356  try {
357  preferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword()));
358  } catch (TextConverterException ex) {
359  throw new UserPreferencesException("Failed to convert password text to hex text.", ex);
360  }
361  }
362 
371  int port;
372  try {
373  port = Integer.parseInt(preferences.get(MESSAGE_SERVICE_PORT, DEFAULT_PORT_STRING));
374  } catch (NumberFormatException ex) {
375  // if there is an error parsing the port number, use the default port number
376  port = DEFAULT_PORT_INT;
377  }
378 
379  try {
380  return new MessageServiceConnectionInfo(
381  preferences.get(MESSAGE_SERVICE_HOST, ""),
382  port,
383  preferences.get(MESSAGE_SERVICE_USER, ""),
384  TextConverter.convertHexTextToText(preferences.get(MESSAGE_SERVICE_PASSWORD, "")));
385  } catch (TextConverterException ex) {
386  throw new UserPreferencesException("Failed to convert password hex text to text.", ex);
387  }
388  }
389 
395  public static int getProcessTimeOutHrs() {
396  int timeOut = preferences.getInt(PROCESS_TIME_OUT_HOURS, DEFAULT_PROCESS_TIMEOUT_HR);
397  if (timeOut < 0) {
398  timeOut = 0;
399  }
400  return timeOut;
401  }
402 
408  public static void setProcessTimeOutHrs(int value) {
409  if (value < 0) {
410  value = 0;
411  }
412  preferences.putInt(PROCESS_TIME_OUT_HOURS, value);
413  }
414 
422  public static boolean getIsTimeOutEnabled() {
423  boolean enabled = preferences.getBoolean(PROCESS_TIME_OUT_ENABLED, false);
424  return enabled;
425  }
426 
434  public static void setIsTimeOutEnabled(boolean enabled) {
435  preferences.putBoolean(PROCESS_TIME_OUT_ENABLED, enabled);
436  }
437 
443  public static String getAppName() {
444  return preferences.get(APP_NAME, Version.getName());
445  }
446 
452  public static void setAppName(String name) {
453  preferences.put(APP_NAME, name);
454  }
455 
461  public static int getLogFileCount() {
462  return preferences.getInt(MAX_NUM_OF_LOG_FILE, LOG_FILE_NUM_INT);
463  }
464 
470  public static int getDefaultLogFileCount() {
471  return LOG_FILE_NUM_INT;
472  }
473 
479  public static void setLogFileCount(int count) {
480  preferences.putInt(MAX_NUM_OF_LOG_FILE, count);
481  }
482 
488  public static int getMaxSolrVMSize() {
489  return preferences.getInt(SOLR_MAX_JVM_SIZE, 512);
490  }
491 
497  public static void setMaxSolrVMSize(int maxSize) {
498  preferences.putInt(SOLR_MAX_JVM_SIZE, maxSize);
499  }
500 
506  public static int getResultsTablePageSize() {
507  return preferences.getInt(RESULTS_TABLE_PAGE_SIZE, 10_000);
508  }
509 
515  public static void setResultsTablePageSize(int pageSize) {
516  preferences.putInt(RESULTS_TABLE_PAGE_SIZE, pageSize);
517  }
518 
524  public static void setExternalHexEditorPath(String executablePath) {
525  preferences.put(EXTERNAL_HEX_EDITOR_PATH, executablePath);
526  }
527 
534  public static String getExternalHexEditorPath() {
535  return preferences.get(EXTERNAL_HEX_EDITOR_PATH, Paths.get("C:", "Program Files", "HxD", "HxD.exe").toString());
536  }
537 }
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 String getConfigSetting(String moduleName, String settingName)
static void setExternalHexEditorPath(String executablePath)
static void addChangeListener(PreferenceChangeListener listener)
static void setShowOnlyCurrentUserTags(boolean value)
static String convertTextToHexText(String property)
static boolean settingExists(String moduleName, String settingName)
static MessageServiceConnectionInfo getMessageServiceConnectionInfo()
static String convertHexTextToText(String property)

Copyright © 2012-2018 Basis Technology. Generated on: Wed Sep 18 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.