Autopsy  4.9.1
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-2018 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 
22 import java.util.prefs.BackingStoreException;
24 import java.util.prefs.PreferenceChangeListener;
25 import java.util.prefs.Preferences;
26 import org.openide.util.NbPreferences;
27 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 boolean IS_WINDOWS_OS = PlatformUtil.isWindowsOS();
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 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_CENTRAL_REPO_COMMENTS_AND_OCCURRENCES = "HideCentralRepoCommentsAndOccurrences";
77  public static final String DISPLAY_TRANSLATED_NAMES = "DisplayTranslatedNames";
78 
79  // Prevent instantiation.
80  private UserPreferences() {
81  }
82 
83  public enum SelectedMode {
84 
86  AUTOINGEST
87  };
88 
94  public static SelectedMode getMode() {
95  if (ModuleSettings.settingExists(SETTINGS_PROPERTIES, MODE)) {
96  int ordinal = Integer.parseInt(ModuleSettings.getConfigSetting(SETTINGS_PROPERTIES, MODE));
97  return UserPreferences.SelectedMode.values()[ordinal];
98  }
100  }
101 
107  public static void setMode(SelectedMode mode) {
108  ModuleSettings.setConfigSetting(SETTINGS_PROPERTIES, MODE, Integer.toString(mode.ordinal()));
109  }
110 
117  public static void reloadFromStorage() throws BackingStoreException {
118  preferences.sync();
119  }
120 
128  public static void saveToStorage() throws BackingStoreException {
129  preferences.flush();
130  }
131 
132  public static void addChangeListener(PreferenceChangeListener listener) {
133  preferences.addPreferenceChangeListener(listener);
134  }
135 
136  public static void removeChangeListener(PreferenceChangeListener listener) {
137  preferences.removePreferenceChangeListener(listener);
138  }
139 
140  public static boolean keepPreferredContentViewer() {
141  return preferences.getBoolean(KEEP_PREFERRED_VIEWER, false);
142  }
143 
144  public static void setKeepPreferredContentViewer(boolean value) {
145  preferences.putBoolean(KEEP_PREFERRED_VIEWER, value);
146  }
147 
148  public static boolean hideKnownFilesInDataSourcesTree() {
149  return preferences.getBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, false);
150  }
151 
152  public static void setHideKnownFilesInDataSourcesTree(boolean value) {
153  preferences.putBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, value);
154  }
155 
156  public static boolean hideKnownFilesInViewsTree() {
157  return preferences.getBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, true);
158  }
159 
160  public static void setHideKnownFilesInViewsTree(boolean value) {
161  preferences.putBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, value);
162  }
163 
164  public static boolean hideSlackFilesInDataSourcesTree() {
165  return preferences.getBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, true);
166  }
167 
168  public static void setHideSlackFilesInDataSourcesTree(boolean value) {
169  preferences.putBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, value);
170  }
171 
172  public static boolean hideSlackFilesInViewsTree() {
173  return preferences.getBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, true);
174  }
175 
176  public static void setHideSlackFilesInViewsTree(boolean value) {
177  preferences.putBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, value);
178  }
179 
180  public static boolean displayTimesInLocalTime() {
181  return preferences.getBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, true);
182  }
183 
184  public static void setDisplayTimesInLocalTime(boolean value) {
185  preferences.putBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, value);
186  }
187 
188  public static String getTimeZoneForDisplays() {
189  return preferences.get(TIME_ZONE_FOR_DISPLAYS, TimeZone.GMT_ZONE.getID());
190  }
191 
192  public static void setTimeZoneForDisplays(String timeZone) {
193  preferences.put(TIME_ZONE_FOR_DISPLAYS, timeZone);
194  }
195 
196  public static int numberOfFileIngestThreads() {
197  return preferences.getInt(NUMBER_OF_FILE_INGEST_THREADS, 2);
198  }
199 
200  public static void setNumberOfFileIngestThreads(int value) {
201  preferences.putInt(NUMBER_OF_FILE_INGEST_THREADS, value);
202  }
203 
204  @Deprecated
205  public static boolean groupItemsInTreeByDatasource() {
206  return preferences.getBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, false);
207  }
208 
209  @Deprecated
210  public static void setGroupItemsInTreeByDatasource(boolean value) {
211  preferences.putBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, value);
212  }
213 
220  public static boolean showOnlyCurrentUserTags() {
221  return preferences.getBoolean(SHOW_ONLY_CURRENT_USER_TAGS, false);
222  }
223 
224 
231  public static void setShowOnlyCurrentUserTags(boolean value) {
232  preferences.putBoolean(SHOW_ONLY_CURRENT_USER_TAGS, value);
233  }
234 
243  public static boolean hideCentralRepoCommentsAndOccurrences() {
244  return preferences.getBoolean(HIDE_CENTRAL_REPO_COMMENTS_AND_OCCURRENCES, false);
245  }
246 
247 
255  public static void setHideCentralRepoCommentsAndOccurrences(boolean value) {
256  preferences.putBoolean(HIDE_CENTRAL_REPO_COMMENTS_AND_OCCURRENCES, 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 
345  preferences.put(MESSAGE_SERVICE_HOST, info.getHost());
346  preferences.put(MESSAGE_SERVICE_PORT, Integer.toString(info.getPort()));
347  preferences.put(MESSAGE_SERVICE_USER, info.getUserName());
348  try {
349  preferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword()));
350  } catch (TextConverterException ex) {
351  throw new UserPreferencesException("Failed to convert password text to hex text.", ex);
352  }
353  }
354 
363  int port;
364  try {
365  port = Integer.parseInt(preferences.get(MESSAGE_SERVICE_PORT, DEFAULT_PORT_STRING));
366  } catch (NumberFormatException ex) {
367  // if there is an error parsing the port number, use the default port number
368  port = DEFAULT_PORT_INT;
369  }
370 
371  try {
372  return new MessageServiceConnectionInfo(
373  preferences.get(MESSAGE_SERVICE_HOST, ""),
374  port,
375  preferences.get(MESSAGE_SERVICE_USER, ""),
376  TextConverter.convertHexTextToText(preferences.get(MESSAGE_SERVICE_PASSWORD, "")));
377  } catch (TextConverterException ex) {
378  throw new UserPreferencesException("Failed to convert password hex text to text.", ex);
379  }
380  }
381 
387  public static int getProcessTimeOutHrs() {
388  int timeOut = preferences.getInt(PROCESS_TIME_OUT_HOURS, DEFAULT_PROCESS_TIMEOUT_HR);
389  if (timeOut < 0) {
390  timeOut = 0;
391  }
392  return timeOut;
393  }
394 
400  public static void setProcessTimeOutHrs(int value) {
401  if (value < 0) {
402  value = 0;
403  }
404  preferences.putInt(PROCESS_TIME_OUT_HOURS, value);
405  }
406 
414  public static boolean getIsTimeOutEnabled() {
415  boolean enabled = preferences.getBoolean(PROCESS_TIME_OUT_ENABLED, false);
416  return enabled;
417  }
418 
426  public static void setIsTimeOutEnabled(boolean enabled) {
427  preferences.putBoolean(PROCESS_TIME_OUT_ENABLED, enabled);
428  }
429 
435  public static String getAppName() {
436  return preferences.get(APP_NAME, Version.getName());
437  }
438 
444  public static void setAppName(String name) {
445  preferences.put(APP_NAME, name);
446  }
447 
453  public static int getLogFileCount() {
454  return preferences.getInt(MAX_NUM_OF_LOG_FILE, LOG_FILE_NUM_INT);
455  }
456 
462  public static int getDefaultLogFileCount() {
463  return LOG_FILE_NUM_INT;
464  }
465 
471  public static void setLogFileCount(int count) {
472  preferences.putInt(MAX_NUM_OF_LOG_FILE, count);
473  }
474 }
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 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: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.