Autopsy  4.10.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  public static final String PROCESS_TIME_OUT_ENABLED = "ProcessTimeOutEnabled"; //NON-NLS
64  public static final String PROCESS_TIME_OUT_HOURS = "ProcessTimeOutHours"; //NON-NLS
65  private static final int DEFAULT_PROCESS_TIMEOUT_HR = 60;
66  private static final String DEFAULT_PORT_STRING = "61616";
67  private static final int DEFAULT_PORT_INT = 61616;
68  private static final String APP_NAME = "AppName";
69  public static final String SETTINGS_PROPERTIES = "AutoIngest";
70  private static final String MODE = "AutopsyMode"; // NON-NLS
71  private static final String MAX_NUM_OF_LOG_FILE = "MaximumNumberOfLogFiles";
72  private static final int LOG_FILE_NUM_INT = 10;
73  public static final String GROUP_ITEMS_IN_TREE_BY_DATASOURCE = "GroupItemsInTreeByDataSource"; //NON-NLS
74  public static final String SHOW_ONLY_CURRENT_USER_TAGS = "ShowOnlyCurrentUserTags";
75  public static final String HIDE_CENTRAL_REPO_COMMENTS_AND_OCCURRENCES = "HideCentralRepoCommentsAndOccurrences";
76  public static final String DISPLAY_TRANSLATED_NAMES = "DisplayTranslatedNames";
77  public static final String EXTERNAL_HEX_EDITOR_PATH = "ExternalHexEditorPath";
78  public static final String SOLR_MAX_JVM_SIZE = "SolrMaxJVMSize";
79 
80  // Prevent instantiation.
81  private UserPreferences() {
82  }
83 
84  public enum SelectedMode {
85 
87  AUTOINGEST
88  };
89 
95  public static SelectedMode getMode() {
96  if (ModuleSettings.settingExists(SETTINGS_PROPERTIES, MODE)) {
97  int ordinal = Integer.parseInt(ModuleSettings.getConfigSetting(SETTINGS_PROPERTIES, MODE));
98  return UserPreferences.SelectedMode.values()[ordinal];
99  }
101  }
102 
108  public static void setMode(SelectedMode mode) {
109  ModuleSettings.setConfigSetting(SETTINGS_PROPERTIES, MODE, Integer.toString(mode.ordinal()));
110  }
111 
118  public static void reloadFromStorage() throws BackingStoreException {
119  preferences.sync();
120  }
121 
129  public static void saveToStorage() throws BackingStoreException {
130  preferences.flush();
131  }
132 
133  public static void addChangeListener(PreferenceChangeListener listener) {
134  preferences.addPreferenceChangeListener(listener);
135  }
136 
137  public static void removeChangeListener(PreferenceChangeListener listener) {
138  preferences.removePreferenceChangeListener(listener);
139  }
140 
141  public static boolean keepPreferredContentViewer() {
142  return preferences.getBoolean(KEEP_PREFERRED_VIEWER, false);
143  }
144 
145  public static void setKeepPreferredContentViewer(boolean value) {
146  preferences.putBoolean(KEEP_PREFERRED_VIEWER, value);
147  }
148 
149  public static boolean hideKnownFilesInDataSourcesTree() {
150  return preferences.getBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, false);
151  }
152 
153  public static void setHideKnownFilesInDataSourcesTree(boolean value) {
154  preferences.putBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, value);
155  }
156 
157  public static boolean hideKnownFilesInViewsTree() {
158  return preferences.getBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, true);
159  }
160 
161  public static void setHideKnownFilesInViewsTree(boolean value) {
162  preferences.putBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, value);
163  }
164 
165  public static boolean hideSlackFilesInDataSourcesTree() {
166  return preferences.getBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, true);
167  }
168 
169  public static void setHideSlackFilesInDataSourcesTree(boolean value) {
170  preferences.putBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, value);
171  }
172 
173  public static boolean hideSlackFilesInViewsTree() {
174  return preferences.getBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, true);
175  }
176 
177  public static void setHideSlackFilesInViewsTree(boolean value) {
178  preferences.putBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, value);
179  }
180 
181  public static boolean displayTimesInLocalTime() {
182  return preferences.getBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, true);
183  }
184 
185  public static void setDisplayTimesInLocalTime(boolean value) {
186  preferences.putBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, value);
187  }
188 
189  public static String getTimeZoneForDisplays() {
190  return preferences.get(TIME_ZONE_FOR_DISPLAYS, TimeZone.GMT_ZONE.getID());
191  }
192 
193  public static void setTimeZoneForDisplays(String timeZone) {
194  preferences.put(TIME_ZONE_FOR_DISPLAYS, timeZone);
195  }
196 
197  public static int numberOfFileIngestThreads() {
198  return preferences.getInt(NUMBER_OF_FILE_INGEST_THREADS, 2);
199  }
200 
201  public static void setNumberOfFileIngestThreads(int value) {
202  preferences.putInt(NUMBER_OF_FILE_INGEST_THREADS, value);
203  }
204 
205  @Deprecated
206  public static boolean groupItemsInTreeByDatasource() {
207  return preferences.getBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, false);
208  }
209 
210  @Deprecated
211  public static void setGroupItemsInTreeByDatasource(boolean value) {
212  preferences.putBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, value);
213  }
214 
221  public static boolean showOnlyCurrentUserTags() {
222  return preferences.getBoolean(SHOW_ONLY_CURRENT_USER_TAGS, false);
223  }
224 
225 
232  public static void setShowOnlyCurrentUserTags(boolean value) {
233  preferences.putBoolean(SHOW_ONLY_CURRENT_USER_TAGS, value);
234  }
235 
244  public static boolean hideCentralRepoCommentsAndOccurrences() {
245  return preferences.getBoolean(HIDE_CENTRAL_REPO_COMMENTS_AND_OCCURRENCES, false);
246  }
247 
248 
256  public static void setHideCentralRepoCommentsAndOccurrences(boolean value) {
257  preferences.putBoolean(HIDE_CENTRAL_REPO_COMMENTS_AND_OCCURRENCES, value);
258  }
259 
260  public static void setDisplayTranslatedFileNames(boolean value) {
261  preferences.putBoolean(DISPLAY_TRANSLATED_NAMES, value);
262  }
263 
264  public static boolean displayTranslatedFileNames() {
265  return preferences.getBoolean(DISPLAY_TRANSLATED_NAMES, false);
266  }
267 
275  public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws UserPreferencesException {
276  DbType dbType;
277  try {
278  dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE, "POSTGRESQL")); //NON-NLS
279  } catch (Exception ex) {
280  dbType = DbType.SQLITE;
281  }
282  try {
283  return new CaseDbConnectionInfo(
284  preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP, ""),
285  preferences.get(EXTERNAL_DATABASE_PORTNUMBER, "5432"),
286  preferences.get(EXTERNAL_DATABASE_USER, ""),
287  TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")),
288  dbType);
289  } catch (TextConverterException ex) {
290  throw new UserPreferencesException("Failure converting password hex text to text.", ex); // NON-NLS
291  }
292  }
293 
302  public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) throws UserPreferencesException {
303  preferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost());
304  preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort());
305  preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName());
306  try {
307  preferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convertTextToHexText(connectionInfo.getPassword()));
308  } catch (TextConverterException ex) {
309  throw new UserPreferencesException("Failure converting text to password hext text", ex); // NON-NLS
310  }
311  preferences.put(EXTERNAL_DATABASE_TYPE, connectionInfo.getDbType().toString());
312  }
313 
314  public static void setIsMultiUserModeEnabled(boolean enabled) {
315  preferences.putBoolean(IS_MULTI_USER_MODE_ENABLED, enabled);
316  }
317 
318  public static boolean getIsMultiUserModeEnabled() {
319  return preferences.getBoolean(IS_MULTI_USER_MODE_ENABLED, false);
320  }
321 
322  public static String getIndexingServerHost() {
323  return preferences.get(INDEXING_SERVER_HOST, "");
324  }
325 
326  public static void setIndexingServerHost(String hostName) {
327  preferences.put(INDEXING_SERVER_HOST, hostName);
328  }
329 
330  public static String getIndexingServerPort() {
331  return preferences.get(INDEXING_SERVER_PORT, "8983");
332  }
333 
334  public static void setIndexingServerPort(int port) {
335  preferences.putInt(INDEXING_SERVER_PORT, port);
336  }
337 
346  preferences.put(MESSAGE_SERVICE_HOST, info.getHost());
347  preferences.put(MESSAGE_SERVICE_PORT, Integer.toString(info.getPort()));
348  preferences.put(MESSAGE_SERVICE_USER, info.getUserName());
349  try {
350  preferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword()));
351  } catch (TextConverterException ex) {
352  throw new UserPreferencesException("Failed to convert password text to hex text.", ex);
353  }
354  }
355 
364  int port;
365  try {
366  port = Integer.parseInt(preferences.get(MESSAGE_SERVICE_PORT, DEFAULT_PORT_STRING));
367  } catch (NumberFormatException ex) {
368  // if there is an error parsing the port number, use the default port number
369  port = DEFAULT_PORT_INT;
370  }
371 
372  try {
373  return new MessageServiceConnectionInfo(
374  preferences.get(MESSAGE_SERVICE_HOST, ""),
375  port,
376  preferences.get(MESSAGE_SERVICE_USER, ""),
377  TextConverter.convertHexTextToText(preferences.get(MESSAGE_SERVICE_PASSWORD, "")));
378  } catch (TextConverterException ex) {
379  throw new UserPreferencesException("Failed to convert password hex text to text.", ex);
380  }
381  }
382 
388  public static int getProcessTimeOutHrs() {
389  int timeOut = preferences.getInt(PROCESS_TIME_OUT_HOURS, DEFAULT_PROCESS_TIMEOUT_HR);
390  if (timeOut < 0) {
391  timeOut = 0;
392  }
393  return timeOut;
394  }
395 
401  public static void setProcessTimeOutHrs(int value) {
402  if (value < 0) {
403  value = 0;
404  }
405  preferences.putInt(PROCESS_TIME_OUT_HOURS, value);
406  }
407 
415  public static boolean getIsTimeOutEnabled() {
416  boolean enabled = preferences.getBoolean(PROCESS_TIME_OUT_ENABLED, false);
417  return enabled;
418  }
419 
427  public static void setIsTimeOutEnabled(boolean enabled) {
428  preferences.putBoolean(PROCESS_TIME_OUT_ENABLED, enabled);
429  }
430 
436  public static String getAppName() {
437  return preferences.get(APP_NAME, Version.getName());
438  }
439 
445  public static void setAppName(String name) {
446  preferences.put(APP_NAME, name);
447  }
448 
454  public static int getLogFileCount() {
455  return preferences.getInt(MAX_NUM_OF_LOG_FILE, LOG_FILE_NUM_INT);
456  }
457 
463  public static int getDefaultLogFileCount() {
464  return LOG_FILE_NUM_INT;
465  }
466 
472  public static void setLogFileCount(int count) {
473  preferences.putInt(MAX_NUM_OF_LOG_FILE, count);
474  }
475 
481  public static int getMaxSolrVMSize() {
482  return preferences.getInt(SOLR_MAX_JVM_SIZE, 512);
483  }
484 
490  public static void setMaxSolrVMSize(int maxSize) {
491  preferences.putInt(SOLR_MAX_JVM_SIZE, maxSize);
492  }
493 
499  public static void setExternalHexEditorPath(String executablePath) {
500  preferences.put(EXTERNAL_HEX_EDITOR_PATH, executablePath);
501  }
502 
509  public static String getExternalHexEditorPath() {
510  return preferences.get(EXTERNAL_HEX_EDITOR_PATH, Paths.get("C:", "Program Files", "HxD", "HxD.exe").toString());
511  }
512 }
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 setIsTimeOutEnabled(boolean enabled)
static void setIsMultiUserModeEnabled(boolean enabled)
static void removeChangeListener(PreferenceChangeListener listener)
static void setMessageServiceConnectionInfo(MessageServiceConnectionInfo info)
static void setHideKnownFilesInViewsTree(boolean value)
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 setHideCentralRepoCommentsAndOccurrences(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 final String HIDE_CENTRAL_REPO_COMMENTS_AND_OCCURRENCES
static MessageServiceConnectionInfo getMessageServiceConnectionInfo()
static String convertHexTextToText(String property)

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