Autopsy  4.6.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-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;
31 import org.sleuthkit.datamodel.CaseDbConnectionInfo;
32 import org.sleuthkit.datamodel.TskData.DbType;
33 
38 public final class UserPreferences {
39 
40  private static final boolean IS_WINDOWS_OS = PlatformUtil.isWindowsOS();
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 NUMBER_OF_FILE_INGEST_THREADS = "NumberOfFileIngestThreads"; //NON-NLS
49  public static final String IS_MULTI_USER_MODE_ENABLED = "IsMultiUserModeEnabled"; //NON-NLS
50  public static final String EXTERNAL_DATABASE_HOSTNAME_OR_IP = "ExternalDatabaseHostnameOrIp"; //NON-NLS
51  public static final String EXTERNAL_DATABASE_PORTNUMBER = "ExternalDatabasePortNumber"; //NON-NLS
52  public static final String EXTERNAL_DATABASE_NAME = "ExternalDatabaseName"; //NON-NLS
53  public static final String EXTERNAL_DATABASE_USER = "ExternalDatabaseUsername"; //NON-NLS
54  public static final String EXTERNAL_DATABASE_PASSWORD = "ExternalDatabasePassword"; //NON-NLS
55  public static final String EXTERNAL_DATABASE_TYPE = "ExternalDatabaseType"; //NON-NLS
56  public static final String INDEXING_SERVER_HOST = "IndexingServerHost"; //NON-NLS
57  public static final String INDEXING_SERVER_PORT = "IndexingServerPort"; //NON-NLS
58  private static final String MESSAGE_SERVICE_PASSWORD = "MessageServicePassword"; //NON-NLS
59  private static final String MESSAGE_SERVICE_USER = "MessageServiceUser"; //NON-NLS
60  private static final String MESSAGE_SERVICE_HOST = "MessageServiceHost"; //NON-NLS
61  private static final String MESSAGE_SERVICE_PORT = "MessageServicePort"; //NON-NLS
62  public static final String PROCESS_TIME_OUT_ENABLED = "ProcessTimeOutEnabled"; //NON-NLS
63  public static final String PROCESS_TIME_OUT_HOURS = "ProcessTimeOutHours"; //NON-NLS
64  private static final int DEFAULT_PROCESS_TIMEOUT_HR = 60;
65  private static final String DEFAULT_PORT_STRING = "61616";
66  private static final int DEFAULT_PORT_INT = 61616;
67  private static final String APP_NAME = "AppName";
68  public static final String SETTINGS_PROPERTIES = "AutoIngest";
69  private static final String MODE = "AutopsyMode"; // NON-NLS
70  private static final String MAX_NUM_OF_LOG_FILE = "MaximumNumberOfLogFiles";
71  private static final int LOG_FILE_NUM_INT = 10;
72 
73  // Prevent instantiation.
74  private UserPreferences() {
75  }
76 
77  public enum SelectedMode {
78 
80  AUTOINGEST
81  };
82 
88  public static SelectedMode getMode() {
89  if (ModuleSettings.settingExists(SETTINGS_PROPERTIES, MODE)) {
90  int ordinal = Integer.parseInt(ModuleSettings.getConfigSetting(SETTINGS_PROPERTIES, MODE));
91  return UserPreferences.SelectedMode.values()[ordinal];
92  }
94  }
95 
101  public static void setMode(SelectedMode mode) {
102  ModuleSettings.setConfigSetting(SETTINGS_PROPERTIES, MODE, Integer.toString(mode.ordinal()));
103  }
104 
111  public static void reloadFromStorage() throws BackingStoreException {
112  preferences.sync();
113  }
114 
122  public static void saveToStorage() throws BackingStoreException {
123  preferences.flush();
124  }
125 
126  public static void addChangeListener(PreferenceChangeListener listener) {
127  preferences.addPreferenceChangeListener(listener);
128  }
129 
130  public static void removeChangeListener(PreferenceChangeListener listener) {
131  preferences.removePreferenceChangeListener(listener);
132  }
133 
134  public static boolean keepPreferredContentViewer() {
135  return preferences.getBoolean(KEEP_PREFERRED_VIEWER, false);
136  }
137 
138  public static void setKeepPreferredContentViewer(boolean value) {
139  preferences.putBoolean(KEEP_PREFERRED_VIEWER, value);
140  }
141 
142  public static boolean hideKnownFilesInDataSourcesTree() {
143  return preferences.getBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, false);
144  }
145 
146  public static void setHideKnownFilesInDataSourcesTree(boolean value) {
147  preferences.putBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, value);
148  }
149 
150  public static boolean hideKnownFilesInViewsTree() {
151  return preferences.getBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, true);
152  }
153 
154  public static void setHideKnownFilesInViewsTree(boolean value) {
155  preferences.putBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, value);
156  }
157 
158  public static boolean hideSlackFilesInDataSourcesTree() {
159  return preferences.getBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, true);
160  }
161 
162  public static void setHideSlackFilesInDataSourcesTree(boolean value) {
163  preferences.putBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, value);
164  }
165 
166  public static boolean hideSlackFilesInViewsTree() {
167  return preferences.getBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, true);
168  }
169 
170  public static void setHideSlackFilesInViewsTree(boolean value) {
171  preferences.putBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, value);
172  }
173 
174  public static boolean displayTimesInLocalTime() {
175  return preferences.getBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, true);
176  }
177 
178  public static void setDisplayTimesInLocalTime(boolean value) {
179  preferences.putBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, value);
180  }
181 
182  public static int numberOfFileIngestThreads() {
183  return preferences.getInt(NUMBER_OF_FILE_INGEST_THREADS, 2);
184  }
185 
186  public static void setNumberOfFileIngestThreads(int value) {
187  preferences.putInt(NUMBER_OF_FILE_INGEST_THREADS, value);
188  }
189 
197  public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws UserPreferencesException {
198  DbType dbType;
199  try {
200  dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE, "POSTGRESQL")); //NON-NLS
201  } catch (Exception ex) {
202  dbType = DbType.SQLITE;
203  }
204  try {
205  return new CaseDbConnectionInfo(
206  preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP, ""),
207  preferences.get(EXTERNAL_DATABASE_PORTNUMBER, "5432"),
208  preferences.get(EXTERNAL_DATABASE_USER, ""),
209  TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")),
210  dbType);
211  } catch (TextConverterException ex) {
212  throw new UserPreferencesException("Failure converting password hex text to text.", ex); // NON-NLS
213  }
214  }
215 
224  public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) throws UserPreferencesException {
225  preferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost());
226  preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort());
227  preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName());
228  try {
229  preferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convertTextToHexText(connectionInfo.getPassword()));
230  } catch (TextConverterException ex) {
231  throw new UserPreferencesException("Failure converting text to password hext text", ex); // NON-NLS
232  }
233  preferences.put(EXTERNAL_DATABASE_TYPE, connectionInfo.getDbType().toString());
234  }
235 
236  public static void setIsMultiUserModeEnabled(boolean enabled) {
237  preferences.putBoolean(IS_MULTI_USER_MODE_ENABLED, enabled);
238  }
239 
240  public static boolean getIsMultiUserModeEnabled() {
241  return preferences.getBoolean(IS_MULTI_USER_MODE_ENABLED, false);
242  }
243 
244  public static String getIndexingServerHost() {
245  return preferences.get(INDEXING_SERVER_HOST, "");
246  }
247 
248  public static void setIndexingServerHost(String hostName) {
249  preferences.put(INDEXING_SERVER_HOST, hostName);
250  }
251 
252  public static String getIndexingServerPort() {
253  return preferences.get(INDEXING_SERVER_PORT, "8983");
254  }
255 
256  public static void setIndexingServerPort(int port) {
257  preferences.putInt(INDEXING_SERVER_PORT, port);
258  }
259 
268  preferences.put(MESSAGE_SERVICE_HOST, info.getHost());
269  preferences.put(MESSAGE_SERVICE_PORT, Integer.toString(info.getPort()));
270  preferences.put(MESSAGE_SERVICE_USER, info.getUserName());
271  try {
272  preferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword()));
273  } catch (TextConverterException ex) {
274  throw new UserPreferencesException("Failed to convert password text to hex text.", ex);
275  }
276  }
277 
286  int port;
287  try {
288  port = Integer.parseInt(preferences.get(MESSAGE_SERVICE_PORT, DEFAULT_PORT_STRING));
289  } catch (NumberFormatException ex) {
290  // if there is an error parsing the port number, use the default port number
291  port = DEFAULT_PORT_INT;
292  }
293 
294  try {
295  return new MessageServiceConnectionInfo(
296  preferences.get(MESSAGE_SERVICE_HOST, ""),
297  port,
298  preferences.get(MESSAGE_SERVICE_USER, ""),
299  TextConverter.convertHexTextToText(preferences.get(MESSAGE_SERVICE_PASSWORD, "")));
300  } catch (TextConverterException ex) {
301  throw new UserPreferencesException("Failed to convert password hex text to text.", ex);
302  }
303  }
304 
310  public static int getProcessTimeOutHrs() {
311  int timeOut = preferences.getInt(PROCESS_TIME_OUT_HOURS, DEFAULT_PROCESS_TIMEOUT_HR);
312  if (timeOut < 0) {
313  timeOut = 0;
314  }
315  return timeOut;
316  }
317 
323  public static void setProcessTimeOutHrs(int value) {
324  if (value < 0) {
325  value = 0;
326  }
327  preferences.putInt(PROCESS_TIME_OUT_HOURS, value);
328  }
329 
337  public static boolean getIsTimeOutEnabled() {
338  boolean enabled = preferences.getBoolean(PROCESS_TIME_OUT_ENABLED, false);
339  return enabled;
340  }
341 
349  public static void setIsTimeOutEnabled(boolean enabled) {
350  preferences.putBoolean(PROCESS_TIME_OUT_ENABLED, enabled);
351  }
352 
358  public static String getAppName() {
359  return preferences.get(APP_NAME, Version.getName());
360  }
361 
367  public static void setAppName(String name) {
368  preferences.put(APP_NAME, name);
369  }
370 
375  public static int getLogFileCount() {
376  return preferences.getInt(MAX_NUM_OF_LOG_FILE, LOG_FILE_NUM_INT);
377  }
378 
383  public static int getDefaultLogFileCount() {
384  return LOG_FILE_NUM_INT;
385  }
390  public static void setLogFileCount(int count) {
391  preferences.putInt(MAX_NUM_OF_LOG_FILE, count);
392  }
393 }
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 synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static void setIndexingServerHost(String hostName)
static void setHideSlackFilesInDataSourcesTree(boolean value)
static void setHideKnownFilesInDataSourcesTree(boolean value)
static String getConfigSetting(String moduleName, String settingName)
static void addChangeListener(PreferenceChangeListener listener)
static String convertTextToHexText(String property)
static boolean settingExists(String moduleName, String settingName)
static MessageServiceConnectionInfo getMessageServiceConnectionInfo()
static String convertHexTextToText(String property)

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.