Autopsy  4.11.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_CENTRAL_REPO_COMMENTS_AND_OCCURRENCES = "HideCentralRepoCommentsAndOccurrences";
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 
227 
234  public static void setShowOnlyCurrentUserTags(boolean value) {
235  preferences.putBoolean(SHOW_ONLY_CURRENT_USER_TAGS, value);
236  }
237 
246  public static boolean hideCentralRepoCommentsAndOccurrences() {
247  return preferences.getBoolean(HIDE_CENTRAL_REPO_COMMENTS_AND_OCCURRENCES, false);
248  }
249 
250 
258  public static void setHideCentralRepoCommentsAndOccurrences(boolean value) {
259  preferences.putBoolean(HIDE_CENTRAL_REPO_COMMENTS_AND_OCCURRENCES, value);
260  }
261 
262  public static void setDisplayTranslatedFileNames(boolean value) {
263  preferences.putBoolean(DISPLAY_TRANSLATED_NAMES, value);
264  }
265 
266  public static boolean displayTranslatedFileNames() {
267  return preferences.getBoolean(DISPLAY_TRANSLATED_NAMES, false);
268  }
269 
277  public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws UserPreferencesException {
278  DbType dbType;
279  try {
280  dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE, "POSTGRESQL")); //NON-NLS
281  } catch (Exception ex) {
282  dbType = DbType.SQLITE;
283  }
284  try {
285  return new CaseDbConnectionInfo(
286  preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP, ""),
287  preferences.get(EXTERNAL_DATABASE_PORTNUMBER, "5432"),
288  preferences.get(EXTERNAL_DATABASE_USER, ""),
289  TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")),
290  dbType);
291  } catch (TextConverterException ex) {
292  throw new UserPreferencesException("Failure converting password hex text to text.", ex); // NON-NLS
293  }
294  }
295 
304  public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) throws UserPreferencesException {
305  preferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost());
306  preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort());
307  preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName());
308  try {
309  preferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convertTextToHexText(connectionInfo.getPassword()));
310  } catch (TextConverterException ex) {
311  throw new UserPreferencesException("Failure converting text to password hext text", ex); // NON-NLS
312  }
313  preferences.put(EXTERNAL_DATABASE_TYPE, connectionInfo.getDbType().toString());
314  }
315 
316  public static void setIsMultiUserModeEnabled(boolean enabled) {
317  preferences.putBoolean(IS_MULTI_USER_MODE_ENABLED, enabled);
318  }
319 
320  public static boolean getIsMultiUserModeEnabled() {
321  return preferences.getBoolean(IS_MULTI_USER_MODE_ENABLED, false);
322  }
323 
324  public static String getIndexingServerHost() {
325  return preferences.get(INDEXING_SERVER_HOST, "");
326  }
327 
328  public static void setIndexingServerHost(String hostName) {
329  preferences.put(INDEXING_SERVER_HOST, hostName);
330  }
331 
332  public static String getIndexingServerPort() {
333  return preferences.get(INDEXING_SERVER_PORT, "8983");
334  }
335 
336  public static void setIndexingServerPort(int port) {
337  preferences.putInt(INDEXING_SERVER_PORT, port);
338  }
339 
340  public static void setTextTranslatorName(String textTranslatorName){
341  preferences.put(TEXT_TRANSLATOR_NAME, textTranslatorName);
342  }
343 
344  public static String getTextTranslatorName(){
345  return preferences.get(TEXT_TRANSLATOR_NAME, null);
346  }
347 
356  preferences.put(MESSAGE_SERVICE_HOST, info.getHost());
357  preferences.put(MESSAGE_SERVICE_PORT, Integer.toString(info.getPort()));
358  preferences.put(MESSAGE_SERVICE_USER, info.getUserName());
359  try {
360  preferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword()));
361  } catch (TextConverterException ex) {
362  throw new UserPreferencesException("Failed to convert password text to hex text.", ex);
363  }
364  }
365 
374  int port;
375  try {
376  port = Integer.parseInt(preferences.get(MESSAGE_SERVICE_PORT, DEFAULT_PORT_STRING));
377  } catch (NumberFormatException ex) {
378  // if there is an error parsing the port number, use the default port number
379  port = DEFAULT_PORT_INT;
380  }
381 
382  try {
383  return new MessageServiceConnectionInfo(
384  preferences.get(MESSAGE_SERVICE_HOST, ""),
385  port,
386  preferences.get(MESSAGE_SERVICE_USER, ""),
387  TextConverter.convertHexTextToText(preferences.get(MESSAGE_SERVICE_PASSWORD, "")));
388  } catch (TextConverterException ex) {
389  throw new UserPreferencesException("Failed to convert password hex text to text.", ex);
390  }
391  }
392 
398  public static int getProcessTimeOutHrs() {
399  int timeOut = preferences.getInt(PROCESS_TIME_OUT_HOURS, DEFAULT_PROCESS_TIMEOUT_HR);
400  if (timeOut < 0) {
401  timeOut = 0;
402  }
403  return timeOut;
404  }
405 
411  public static void setProcessTimeOutHrs(int value) {
412  if (value < 0) {
413  value = 0;
414  }
415  preferences.putInt(PROCESS_TIME_OUT_HOURS, value);
416  }
417 
425  public static boolean getIsTimeOutEnabled() {
426  boolean enabled = preferences.getBoolean(PROCESS_TIME_OUT_ENABLED, false);
427  return enabled;
428  }
429 
437  public static void setIsTimeOutEnabled(boolean enabled) {
438  preferences.putBoolean(PROCESS_TIME_OUT_ENABLED, enabled);
439  }
440 
446  public static String getAppName() {
447  return preferences.get(APP_NAME, Version.getName());
448  }
449 
455  public static void setAppName(String name) {
456  preferences.put(APP_NAME, name);
457  }
458 
464  public static int getLogFileCount() {
465  return preferences.getInt(MAX_NUM_OF_LOG_FILE, LOG_FILE_NUM_INT);
466  }
467 
473  public static int getDefaultLogFileCount() {
474  return LOG_FILE_NUM_INT;
475  }
476 
482  public static void setLogFileCount(int count) {
483  preferences.putInt(MAX_NUM_OF_LOG_FILE, count);
484  }
485 
491  public static int getMaxSolrVMSize() {
492  return preferences.getInt(SOLR_MAX_JVM_SIZE, 512);
493  }
494 
500  public static void setMaxSolrVMSize(int maxSize) {
501  preferences.putInt(SOLR_MAX_JVM_SIZE, maxSize);
502  }
503 
509  public static int getResultsTablePageSize() {
510  return preferences.getInt(RESULTS_TABLE_PAGE_SIZE, 10_000);
511  }
512 
518  public static void setResultsTablePageSize(int pageSize) {
519  preferences.putInt(RESULTS_TABLE_PAGE_SIZE, pageSize);
520  }
521 
527  public static void setExternalHexEditorPath(String executablePath) {
528  preferences.put(EXTERNAL_HEX_EDITOR_PATH, executablePath);
529  }
530 
537  public static String getExternalHexEditorPath() {
538  return preferences.get(EXTERNAL_HEX_EDITOR_PATH, Paths.get("C:", "Program Files", "HxD", "HxD.exe").toString());
539  }
540 }
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 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 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 Jun 21 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.