Autopsy  4.17.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-2020 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;
33 import org.sleuthkit.datamodel.CaseDbConnectionInfo;
34 import org.sleuthkit.datamodel.TskData.DbType;
35 
40 public final class UserPreferences {
41 
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  private static final String SOLR8_SERVER_HOST = "Solr8ServerHost"; //NON-NLS
59  private static final String SOLR8_SERVER_PORT = "Solr8ServerPort"; //NON-NLS
60  private static final String SOLR4_SERVER_HOST = "IndexingServerHost"; //NON-NLS
61  private static final String SOLR4_SERVER_PORT = "IndexingServerPort"; //NON-NLS
62  private static final String ZK_SERVER_HOST = "ZookeeperServerHost"; //NON-NLS
63  private static final String ZK_SERVER_PORT = "ZookeeperServerPort"; //NON-NLS
64  private static final String MESSAGE_SERVICE_PASSWORD = "MessageServicePassword"; //NON-NLS
65  private static final String MESSAGE_SERVICE_USER = "MessageServiceUser"; //NON-NLS
66  private static final String MESSAGE_SERVICE_HOST = "MessageServiceHost"; //NON-NLS
67  private static final String MESSAGE_SERVICE_PORT = "MessageServicePort"; //NON-NLS
68  public static final String TEXT_TRANSLATOR_NAME = "TextTranslatorName";
69  public static final String OCR_TRANSLATION_ENABLED = "OcrTranslationEnabled";
70  public static final String PROCESS_TIME_OUT_ENABLED = "ProcessTimeOutEnabled"; //NON-NLS
71  public static final String PROCESS_TIME_OUT_HOURS = "ProcessTimeOutHours"; //NON-NLS
72  private static final int DEFAULT_PROCESS_TIMEOUT_HR = 60;
73  private static final String DEFAULT_PORT_STRING = "61616";
74  private static final int DEFAULT_PORT_INT = 61616;
75  private static final String APP_NAME = "AppName";
76  public static final String SETTINGS_PROPERTIES = "AutoIngest";
77  private static final String MODE = "AutopsyMode"; // NON-NLS
78  private static final String MAX_NUM_OF_LOG_FILE = "MaximumNumberOfLogFiles";
79  private static final int LOG_FILE_NUM_INT = 10;
80  public static final String GROUP_ITEMS_IN_TREE_BY_DATASOURCE = "GroupItemsInTreeByDataSource"; //NON-NLS
81  public static final String SHOW_ONLY_CURRENT_USER_TAGS = "ShowOnlyCurrentUserTags";
82  public static final String HIDE_SCO_COLUMNS = "HideCentralRepoCommentsAndOccurrences"; //The key for this setting pre-dates the settings current functionality //NON-NLS
83  public static final String DISPLAY_TRANSLATED_NAMES = "DisplayTranslatedNames";
84  private static final boolean DISPLAY_TRANSLATED_NAMES_DEFAULT = true;
85  public static final String EXTERNAL_HEX_EDITOR_PATH = "ExternalHexEditorPath";
86  public static final String SOLR_MAX_JVM_SIZE = "SolrMaxJVMSize";
87  private static final int DEFAULT_SOLR_HEAP_SIZE_MB = 2048;
88  public static final String RESULTS_TABLE_PAGE_SIZE = "ResultsTablePageSize";
89  private static final String GEO_TILE_OPTION = "GeolocationTileOption";
90  private static final String GEO_OSM_TILE_ZIP_PATH = "GeolocationOsmZipPath";
91  private static final String GEO_OSM_SERVER_ADDRESS = "GeolocationOsmServerAddress";
92  private static final String GEO_MBTILES_FILE_PATH = "GeolcoationMBTilesFilePath";
93  private static final String HEALTH_MONITOR_REPORT_PATH = "HealthMonitorReportPath";
94 
95  // Prevent instantiation.
96  private UserPreferences() {
97  }
98 
99  public enum SelectedMode {
100 
102  AUTOINGEST
103  };
104 
110  public static SelectedMode getMode() {
111  if (ModuleSettings.settingExists(SETTINGS_PROPERTIES, MODE)) {
112  int ordinal = Integer.parseInt(ModuleSettings.getConfigSetting(SETTINGS_PROPERTIES, MODE));
113  return UserPreferences.SelectedMode.values()[ordinal];
114  }
116  }
117 
123  public static void setMode(SelectedMode mode) {
124  ModuleSettings.setConfigSetting(SETTINGS_PROPERTIES, MODE, Integer.toString(mode.ordinal()));
125  }
126 
133  public static void reloadFromStorage() throws BackingStoreException {
134  preferences.sync();
135  }
136 
144  public static void saveToStorage() throws BackingStoreException {
145  preferences.flush();
146  }
147 
148  public static void addChangeListener(PreferenceChangeListener listener) {
149  preferences.addPreferenceChangeListener(listener);
150  }
151 
152  public static void removeChangeListener(PreferenceChangeListener listener) {
153  preferences.removePreferenceChangeListener(listener);
154  }
155 
156  public static boolean keepPreferredContentViewer() {
157  return preferences.getBoolean(KEEP_PREFERRED_VIEWER, false);
158  }
159 
160  public static void setKeepPreferredContentViewer(boolean value) {
161  preferences.putBoolean(KEEP_PREFERRED_VIEWER, value);
162  }
163 
164  public static boolean hideKnownFilesInDataSourcesTree() {
165  return preferences.getBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, false);
166  }
167 
168  public static void setHideKnownFilesInDataSourcesTree(boolean value) {
169  preferences.putBoolean(HIDE_KNOWN_FILES_IN_DATA_SRCS_TREE, value);
170  }
171 
172  public static boolean hideKnownFilesInViewsTree() {
173  return preferences.getBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, true);
174  }
175 
176  public static void setHideKnownFilesInViewsTree(boolean value) {
177  preferences.putBoolean(HIDE_KNOWN_FILES_IN_VIEWS_TREE, value);
178  }
179 
180  public static boolean hideSlackFilesInDataSourcesTree() {
181  return preferences.getBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, true);
182  }
183 
184  public static void setHideSlackFilesInDataSourcesTree(boolean value) {
185  preferences.putBoolean(HIDE_SLACK_FILES_IN_DATA_SRCS_TREE, value);
186  }
187 
188  public static boolean hideSlackFilesInViewsTree() {
189  return preferences.getBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, true);
190  }
191 
192  public static void setHideSlackFilesInViewsTree(boolean value) {
193  preferences.putBoolean(HIDE_SLACK_FILES_IN_VIEWS_TREE, value);
194  }
195 
196  public static boolean displayTimesInLocalTime() {
197  return preferences.getBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, true);
198  }
199 
200  public static void setDisplayTimesInLocalTime(boolean value) {
201  preferences.putBoolean(DISPLAY_TIMES_IN_LOCAL_TIME, value);
202  }
203 
204  public static String getTimeZoneForDisplays() {
205  return preferences.get(TIME_ZONE_FOR_DISPLAYS, TimeZone.GMT_ZONE.getID());
206  }
207 
208  public static void setTimeZoneForDisplays(String timeZone) {
209  preferences.put(TIME_ZONE_FOR_DISPLAYS, timeZone);
210  }
211 
212  public static int numberOfFileIngestThreads() {
213  return preferences.getInt(NUMBER_OF_FILE_INGEST_THREADS, 2);
214  }
215 
216  public static void setNumberOfFileIngestThreads(int value) {
217  preferences.putInt(NUMBER_OF_FILE_INGEST_THREADS, value);
218  }
219 
220  @Deprecated
221  public static boolean groupItemsInTreeByDatasource() {
222  return preferences.getBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, false);
223  }
224 
225  @Deprecated
226  public static void setGroupItemsInTreeByDatasource(boolean value) {
227  preferences.putBoolean(GROUP_ITEMS_IN_TREE_BY_DATASOURCE, value);
228  }
229 
236  public static boolean showOnlyCurrentUserTags() {
237  return preferences.getBoolean(SHOW_ONLY_CURRENT_USER_TAGS, false);
238  }
239 
246  public static void setShowOnlyCurrentUserTags(boolean value) {
247  preferences.putBoolean(SHOW_ONLY_CURRENT_USER_TAGS, value);
248  }
249 
257  public static boolean getHideSCOColumns() {
258  return preferences.getBoolean(HIDE_SCO_COLUMNS, false);
259  }
260 
268  public static void setHideSCOColumns(boolean value) {
269  preferences.putBoolean(HIDE_SCO_COLUMNS, value);
270  }
271 
272  public static void setDisplayTranslatedFileNames(boolean value) {
273  preferences.putBoolean(DISPLAY_TRANSLATED_NAMES, value);
274  }
275 
276  public static boolean displayTranslatedFileNames() {
277  return preferences.getBoolean(DISPLAY_TRANSLATED_NAMES, DISPLAY_TRANSLATED_NAMES_DEFAULT);
278  }
279 
287  public static CaseDbConnectionInfo getDatabaseConnectionInfo() throws UserPreferencesException {
288  DbType dbType;
289  try {
290  dbType = DbType.valueOf(preferences.get(EXTERNAL_DATABASE_TYPE, "POSTGRESQL")); //NON-NLS
291  } catch (Exception ex) {
292  dbType = DbType.SQLITE;
293  }
294  try {
295  return new CaseDbConnectionInfo(
296  preferences.get(EXTERNAL_DATABASE_HOSTNAME_OR_IP, ""),
297  preferences.get(EXTERNAL_DATABASE_PORTNUMBER, "5432"),
298  preferences.get(EXTERNAL_DATABASE_USER, ""),
299  TextConverter.convertHexTextToText(preferences.get(EXTERNAL_DATABASE_PASSWORD, "")),
300  dbType);
301  } catch (TextConverterException ex) {
302  throw new UserPreferencesException("Failure converting password hex text to text.", ex); // NON-NLS
303  }
304  }
305 
314  public static void setDatabaseConnectionInfo(CaseDbConnectionInfo connectionInfo) throws UserPreferencesException {
315  preferences.put(EXTERNAL_DATABASE_HOSTNAME_OR_IP, connectionInfo.getHost());
316  preferences.put(EXTERNAL_DATABASE_PORTNUMBER, connectionInfo.getPort());
317  preferences.put(EXTERNAL_DATABASE_USER, connectionInfo.getUserName());
318  try {
319  preferences.put(EXTERNAL_DATABASE_PASSWORD, TextConverter.convertTextToHexText(connectionInfo.getPassword()));
320  } catch (TextConverterException ex) {
321  throw new UserPreferencesException("Failure converting text to password hext text", ex); // NON-NLS
322  }
323  preferences.put(EXTERNAL_DATABASE_TYPE, connectionInfo.getDbType().toString());
324  }
325 
326  public static void setIsMultiUserModeEnabled(boolean enabled) {
327  preferences.putBoolean(IS_MULTI_USER_MODE_ENABLED, enabled);
328  }
329 
330  public static boolean getIsMultiUserModeEnabled() {
331  return preferences.getBoolean(IS_MULTI_USER_MODE_ENABLED, false);
332  }
333 
334  public static String getIndexingServerHost() {
335  return preferences.get(SOLR8_SERVER_HOST, "");
336  }
337 
338  public static void setIndexingServerHost(String hostName) {
339  preferences.put(SOLR8_SERVER_HOST, hostName);
340  }
341 
342  public static String getIndexingServerPort() {
343  return preferences.get(SOLR8_SERVER_PORT, "8983");
344  }
345 
346  public static void setIndexingServerPort(int port) {
347  preferences.putInt(SOLR8_SERVER_PORT, port);
348  }
349 
350  public static String getSolr4ServerHost() {
351  return preferences.get(SOLR4_SERVER_HOST, "");
352  }
353 
354  public static void setSolr4ServerHost(String hostName) {
355  preferences.put(SOLR4_SERVER_HOST, hostName);
356  }
357 
358  public static String getSolr4ServerPort() {
359  return preferences.get(SOLR4_SERVER_PORT, "");
360  }
361 
362  public static void setSolr4ServerPort(String port) {
363  preferences.put(SOLR4_SERVER_PORT, port);
364  }
365 
366  public static String getZkServerHost() {
367  return preferences.get(ZK_SERVER_HOST, "");
368  }
369 
370  public static void setZkServerHost(String hostName) {
371  preferences.put(ZK_SERVER_HOST, hostName);
372  }
373 
374  public static String getZkServerPort() {
375  return preferences.get(ZK_SERVER_PORT, "9983");
376  }
377 
378  public static void setZkServerPort(String port) {
379  preferences.put(ZK_SERVER_PORT, port);
380  }
381 
382  public static void setTextTranslatorName(String textTranslatorName) {
383  preferences.put(TEXT_TRANSLATOR_NAME, textTranslatorName);
384  }
385 
386  public static String getTextTranslatorName() {
387  return preferences.get(TEXT_TRANSLATOR_NAME, null);
388  }
389 
390  public static void setUseOcrInTranslation(boolean enableOcr) {
391  preferences.putBoolean(OCR_TRANSLATION_ENABLED, enableOcr);
392  }
393 
394  public static boolean getUseOcrInTranslation() {
395  return preferences.getBoolean(OCR_TRANSLATION_ENABLED, true);
396  }
397 
406  preferences.put(MESSAGE_SERVICE_HOST, info.getHost());
407  preferences.put(MESSAGE_SERVICE_PORT, Integer.toString(info.getPort()));
408  preferences.put(MESSAGE_SERVICE_USER, info.getUserName());
409  try {
410  preferences.put(MESSAGE_SERVICE_PASSWORD, TextConverter.convertTextToHexText(info.getPassword()));
411  } catch (TextConverterException ex) {
412  throw new UserPreferencesException("Failed to convert password text to hex text.", ex);
413  }
414  }
415 
424  int port;
425  try {
426  port = Integer.parseInt(preferences.get(MESSAGE_SERVICE_PORT, DEFAULT_PORT_STRING));
427  } catch (NumberFormatException ex) {
428  // if there is an error parsing the port number, use the default port number
429  port = DEFAULT_PORT_INT;
430  }
431 
432  try {
433  return new MessageServiceConnectionInfo(
434  preferences.get(MESSAGE_SERVICE_HOST, ""),
435  port,
436  preferences.get(MESSAGE_SERVICE_USER, ""),
437  TextConverter.convertHexTextToText(preferences.get(MESSAGE_SERVICE_PASSWORD, "")));
438  } catch (TextConverterException ex) {
439  throw new UserPreferencesException("Failed to convert password hex text to text.", ex);
440  }
441  }
442 
448  public static int getProcessTimeOutHrs() {
449  int timeOut = preferences.getInt(PROCESS_TIME_OUT_HOURS, DEFAULT_PROCESS_TIMEOUT_HR);
450  if (timeOut < 0) {
451  timeOut = 0;
452  }
453  return timeOut;
454  }
455 
461  public static void setProcessTimeOutHrs(int value) {
462  if (value < 0) {
463  value = 0;
464  }
465  preferences.putInt(PROCESS_TIME_OUT_HOURS, value);
466  }
467 
475  public static boolean getIsTimeOutEnabled() {
476  boolean enabled = preferences.getBoolean(PROCESS_TIME_OUT_ENABLED, false);
477  return enabled;
478  }
479 
487  public static void setIsTimeOutEnabled(boolean enabled) {
488  preferences.putBoolean(PROCESS_TIME_OUT_ENABLED, enabled);
489  }
490 
496  public static String getAppName() {
497  return preferences.get(APP_NAME, Version.getName());
498  }
499 
505  public static void setAppName(String name) {
506  preferences.put(APP_NAME, name);
507  }
508 
514  public static int getLogFileCount() {
515  return preferences.getInt(MAX_NUM_OF_LOG_FILE, LOG_FILE_NUM_INT);
516  }
517 
523  public static int getDefaultLogFileCount() {
524  return LOG_FILE_NUM_INT;
525  }
526 
532  public static void setLogFileCount(int count) {
533  preferences.putInt(MAX_NUM_OF_LOG_FILE, count);
534  }
535 
541  public static int getMaxSolrVMSize() {
542  return preferences.getInt(SOLR_MAX_JVM_SIZE, DEFAULT_SOLR_HEAP_SIZE_MB);
543  }
544 
550  public static void setMaxSolrVMSize(int maxSize) {
551  preferences.putInt(SOLR_MAX_JVM_SIZE, maxSize);
552  }
553 
559  public static int getResultsTablePageSize() {
560  return preferences.getInt(RESULTS_TABLE_PAGE_SIZE, 10_000);
561  }
562 
568  public static void setResultsTablePageSize(int pageSize) {
569  preferences.putInt(RESULTS_TABLE_PAGE_SIZE, pageSize);
570  }
571 
577  public static void setExternalHexEditorPath(String executablePath) {
578  preferences.put(EXTERNAL_HEX_EDITOR_PATH, executablePath);
579  }
580 
587  public static String getExternalHexEditorPath() {
588  return preferences.get(EXTERNAL_HEX_EDITOR_PATH, Paths.get("C:", "Program Files", "HxD", "HxD.exe").toString());
589  }
590 
596  public static void setGeolocationTileOption(int option) {
597  preferences.putInt(GEO_TILE_OPTION, option);
598  }
599 
605  public static int getGeolocationtTileOption() {
606  return preferences.getInt(GEO_TILE_OPTION, 0);
607  }
608 
614  public static void setGeolocationOsmZipPath(String absolutePath) {
615  preferences.put(GEO_OSM_TILE_ZIP_PATH, absolutePath);
616  }
617 
624  public static String getGeolocationOsmZipPath() {
625  return preferences.get(GEO_OSM_TILE_ZIP_PATH, "");
626  }
627 
633  public static void setGeolocationOsmServerAddress(String address) {
634  preferences.put(GEO_OSM_SERVER_ADDRESS, address);
635  }
636 
642  public static String getGeolocationOsmServerAddress() {
643  return preferences.get(GEO_OSM_SERVER_ADDRESS, "");
644  }
645 
651  public static void setGeolocationMBTilesFilePath(String absolutePath) {
652  preferences.put(GEO_MBTILES_FILE_PATH, absolutePath);
653  }
654 
660  public static String getGeolocationMBTilesFilePath() {
661  return preferences.get(GEO_MBTILES_FILE_PATH, "");
662  }
663 
669  public static String getAppTempDirectory() {
671  .toAbsolutePath().toString();
672  }
673 
679  public static void setHealthMonitorReportPath(String reportPath) {
680  preferences.put(HEALTH_MONITOR_REPORT_PATH, reportPath);
681  }
682 
688  public static String getHealthMonitorReportPath() {
689  return preferences.get(HEALTH_MONITOR_REPORT_PATH, "");
690  }
691 }
static void setZkServerHost(String hostName)
static synchronized String getConfigSetting(String moduleName, String settingName)
static void setGroupItemsInTreeByDatasource(boolean value)
static void setKeepPreferredContentViewer(boolean value)
static void setDisplayTimesInLocalTime(boolean value)
static void setMode(SelectedMode mode)
static void setUseOcrInTranslation(boolean enableOcr)
static void setHideSlackFilesInViewsTree(boolean value)
static void setHealthMonitorReportPath(String reportPath)
static CaseDbConnectionInfo getDatabaseConnectionInfo()
static void setHideSCOColumns(boolean value)
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 synchronized boolean settingExists(String moduleName, String settingName)
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 setHideSlackFilesInDataSourcesTree(boolean value)
static void setHideKnownFilesInDataSourcesTree(boolean value)
static void setGeolocationOsmZipPath(String absolutePath)
static void setExternalHexEditorPath(String executablePath)
static void addChangeListener(PreferenceChangeListener listener)
static void setGeolocationMBTilesFilePath(String absolutePath)
static void setSolr4ServerHost(String hostName)
static void setShowOnlyCurrentUserTags(boolean value)
static String convertTextToHexText(String property)
static void setGeolocationOsmServerAddress(String address)
static MessageServiceConnectionInfo getMessageServiceConnectionInfo()
static String convertHexTextToText(String property)

Copyright © 2012-2021 Basis Technology. Generated on: Tue Jan 19 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.