Autopsy  4.4.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 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.Exceptions;
27 import org.openide.util.NbPreferences;
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 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 
72  // Prevent instantiation.
73  private UserPreferences() {
74  }
75 
76  public enum SelectedMode {
77 
80  REVIEW
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  if (!IS_WINDOWS_OS) {
242  return false;
243  }
244  return preferences.getBoolean(IS_MULTI_USER_MODE_ENABLED, false);
245  }
246 
247  public static String getIndexingServerHost() {
248  return preferences.get(INDEXING_SERVER_HOST, "");
249  }
250 
251  public static void setIndexingServerHost(String hostName) {
252  preferences.put(INDEXING_SERVER_HOST, hostName);
253  }
254 
255  public static String getIndexingServerPort() {
256  return preferences.get(INDEXING_SERVER_PORT, "8983");
257  }
258 
259  public static void setIndexingServerPort(int port) {
260  preferences.putInt(INDEXING_SERVER_PORT, port);
261  }
262 
271  preferences.put(MESSAGE_SERVICE_HOST, info.getHost());
272  preferences.put(MESSAGE_SERVICE_PORT, Integer.toString(info.getPort()));
273  preferences.put(MESSAGE_SERVICE_USER, info.getUserName());
274  try {
275  preferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword()));
276  } catch (TextConverterException ex) {
277  throw new UserPreferencesException("Failed to convert password text to hex text.", ex);
278  }
279  }
280 
289  int port;
290  try {
291  port = Integer.parseInt(preferences.get(MESSAGE_SERVICE_PORT, DEFAULT_PORT_STRING));
292  } catch (NumberFormatException ex) {
293  // if there is an error parsing the port number, use the default port number
294  port = DEFAULT_PORT_INT;
295  }
296 
297  try {
298  return new MessageServiceConnectionInfo(
299  preferences.get(MESSAGE_SERVICE_HOST, ""),
300  port,
301  preferences.get(MESSAGE_SERVICE_USER, ""),
302  TextConverter.convertHexTextToText(preferences.get(MESSAGE_SERVICE_PASSWORD, "")));
303  } catch (TextConverterException ex) {
304  throw new UserPreferencesException("Failed to convert password hex text to text.", ex);
305  }
306  }
307 
313  public static int getProcessTimeOutHrs() {
314  int timeOut = preferences.getInt(PROCESS_TIME_OUT_HOURS, DEFAULT_PROCESS_TIMEOUT_HR);
315  if (timeOut < 0) {
316  timeOut = 0;
317  }
318  return timeOut;
319  }
320 
326  public static void setProcessTimeOutHrs(int value) {
327  if (value < 0) {
328  value = 0;
329  }
330  preferences.putInt(PROCESS_TIME_OUT_HOURS, value);
331  }
332 
340  public static boolean getIsTimeOutEnabled() {
341  boolean enabled = preferences.getBoolean(PROCESS_TIME_OUT_ENABLED, false);
342  return enabled;
343  }
344 
352  public static void setIsTimeOutEnabled(boolean enabled) {
353  preferences.putBoolean(PROCESS_TIME_OUT_ENABLED, enabled);
354  }
355 
361  public static String getAppName() {
362  return preferences.get(APP_NAME, String.format("%s %s", Version.getName(), Version.getVersion()));
363  }
364 
370  public static void setAppName(String name) {
371  preferences.put(APP_NAME, name);
372  }
373 
374 }
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: Fri Sep 29 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.