Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
KeywordSearchSettings.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2012-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.keywordsearch;
20 
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.logging.Level;
26 import org.openide.util.NbBundle;
32 
33 //This file contains constants and settings for KeywordSearch
34 class KeywordSearchSettings {
35 
36  public static final String MODULE_NAME = NbBundle.getMessage(KeywordSearchSettings.class, "KeywordSearchSettings.moduleName.text");
37  static final String PROPERTIES_OPTIONS = NbBundle.getMessage(KeywordSearchSettings.class, "KeywordSearchSettings.properties_options.text", MODULE_NAME);
38  static final String PROPERTIES_NSRL = NbBundle.getMessage(KeywordSearchSettings.class, "KeywordSearchSettings.propertiesNSRL.text", MODULE_NAME);
39  static final String PROPERTIES_SCRIPTS = NbBundle.getMessage(KeywordSearchSettings.class, "KeywordSearchSettings.propertiesScripts.text", MODULE_NAME);
40  static final String SHOW_SNIPPETS = "showSnippets"; //NON-NLS
41  static final boolean DEFAULT_SHOW_SNIPPETS = true;
42  static final String OCR_ENABLED = "ocrEnabled"; //NON-NLS
43  static final String LIMITED_OCR_ENABLED = "limitedOcrEnabled"; //NON-NLS
44  static final boolean OCR_ENABLED_DEFAULT = false; // NON-NLS
45  static final boolean LIMITED_OCR_ENABLED_DEFAULT = false;
46  private static boolean skipKnown = true;
47  private static final Logger logger = Logger.getLogger(KeywordSearchSettings.class.getName());
48  private static List<StringExtract.StringExtractUnicodeTable.SCRIPT> stringExtractScripts = new ArrayList<>();
49  private static Map<String, String> stringExtractOptions = new HashMap<>();
50 
57  static void setSkipKnown(boolean skip) {
58  ModuleSettings.setConfigSetting(PROPERTIES_NSRL, "SkipKnown", Boolean.toString(skip)); //NON-NLS
59  skipKnown = skip;
60  }
61 
68  static boolean getSkipKnown() {
69  if (ModuleSettings.getConfigSetting(PROPERTIES_NSRL, "SkipKnown") != null) { //NON-NLS
70  return Boolean.parseBoolean(ModuleSettings.getConfigSetting(PROPERTIES_NSRL, "SkipKnown")); //NON-NLS
71  }
72  //if it fails, return the default/last known value
73  logger.log(Level.WARNING, "Could not read property for SkipKnown, returning backup value."); //NON-NLS
74  return skipKnown;
75  }
76 
82  static void setStringExtractScripts(List<StringExtract.StringExtractUnicodeTable.SCRIPT> scripts) {
83  stringExtractScripts.clear();
84  stringExtractScripts.addAll(scripts);
85 
86  //Disabling scripts that weren't selected
87  for (String s : ModuleSettings.getConfigSettings(PROPERTIES_SCRIPTS).keySet()) {
88  if (!scripts.contains(StringExtract.StringExtractUnicodeTable.SCRIPT.valueOf(s))) {
89  ModuleSettings.setConfigSetting(PROPERTIES_SCRIPTS, s, "false"); //NON-NLS
90  }
91  }
92  //Writing and enabling selected scripts
93  for (StringExtract.StringExtractUnicodeTable.SCRIPT s : stringExtractScripts) {
94  ModuleSettings.setConfigSetting(PROPERTIES_SCRIPTS, s.name(), "true"); //NON-NLS
95  }
96 
97  }
98 
105  static void setStringExtractOption(String key, String val) {
106  stringExtractOptions.put(key, val);
107  ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, key, val);
108  }
109 
117  @Deprecated
118  static boolean getOcrOption() {
119  if (ModuleSettings.settingExists(PROPERTIES_OPTIONS, OCR_ENABLED)) {
120  return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, OCR_ENABLED).equals("true"); //NON-NLS
121  } else {
122  return OCR_ENABLED_DEFAULT;
123  }
124  }
125 
135  @Deprecated
136  static boolean getLimitedOcrOption() {
137  if (ModuleSettings.settingExists(PROPERTIES_OPTIONS, LIMITED_OCR_ENABLED)) {
138  return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, LIMITED_OCR_ENABLED).equals("true"); //NON-NLS
139  } else {
140  return LIMITED_OCR_ENABLED_DEFAULT;
141  }
142  }
143 
144  static void setShowSnippets(boolean showSnippets) {
145  ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, SHOW_SNIPPETS, (showSnippets ? "true" : "false")); //NON-NLS
146  }
147 
148  static boolean getShowSnippets() {
149  if (ModuleSettings.settingExists(PROPERTIES_OPTIONS, SHOW_SNIPPETS)) {
150  return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, SHOW_SNIPPETS).equals("true"); //NON-NLS
151  } else {
152  return DEFAULT_SHOW_SNIPPETS;
153  }
154  }
155 
161  static List<SCRIPT> getStringExtractScripts() {
162  if (ModuleSettings.getConfigSettings(PROPERTIES_SCRIPTS) != null && !ModuleSettings.getConfigSettings(PROPERTIES_SCRIPTS).isEmpty()) {
163  List<SCRIPT> scripts = new ArrayList<>();
164  for (Map.Entry<String, String> kvp : ModuleSettings.getConfigSettings(PROPERTIES_SCRIPTS).entrySet()) {
165  if (kvp.getValue().equals("true")) { //NON-NLS
166  scripts.add(SCRIPT.valueOf(kvp.getKey()));
167  }
168  }
169  return scripts;
170  }
171  //if it failed, try to return the built-in list maintained by the singleton.
172  logger.log(Level.WARNING, "Could not read properties for extracting scripts, returning backup values."); //NON-NLS
173  return new ArrayList<>(stringExtractScripts);
174  }
175 
183  static String getStringExtractOption(String key) {
184  if (ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, key) != null) {
185  return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, key);
186  } else {
187  logger.log(Level.WARNING, "Could not read property for key {0}, returning backup value.", key); //NON-NLS
188  return stringExtractOptions.get(key);
189  }
190  }
191 
197  static Map<String, String> getStringExtractOptions() {
198  Map<String, String> settings = ModuleSettings.getConfigSettings(PROPERTIES_OPTIONS);
199  if (settings == null) {
200  Map<String, String> settingsv2 = new HashMap<>();
201  logger.log(Level.WARNING, "Could not read properties for {0}.properties, returning backup values", PROPERTIES_OPTIONS); //NON-NLS
202  settingsv2.putAll(stringExtractOptions);
203  return settingsv2;
204  } else {
205  return settings;
206  }
207  }
208 
213  static void setDefaults() {
214  logger.log(Level.INFO, "Detecting default settings."); //NON-NLS
215  //setting default NSRL
216  if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_NSRL, "SkipKnown")) { //NON-NLS
217  logger.log(Level.INFO, "No configuration for NSRL found, generating default..."); //NON-NLS
218  KeywordSearchSettings.setSkipKnown(true);
219  }
220  //setting default Extract UTF8
221  if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS, StringsExtractOptions.EXTRACT_UTF8.toString())) {
222  logger.log(Level.INFO, "No configuration for UTF8 found, generating default..."); //NON-NLS
223  KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF8.toString(), Boolean.TRUE.toString());
224  }
225  //setting default Extract UTF16
226  if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS, StringsExtractOptions.EXTRACT_UTF16.toString())) {
227  logger.log(Level.INFO, "No configuration for UTF16 found, generating defaults..."); //NON-NLS
228  KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF16.toString(), Boolean.TRUE.toString());
229  }
230  //setting default Latin-1 Script
231  if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_SCRIPTS, SCRIPT.LATIN_1.name())) {
232  logger.log(Level.INFO, "No configuration for Scripts found, generating defaults..."); //NON-NLS
233  ModuleSettings.setConfigSetting(KeywordSearchSettings.PROPERTIES_SCRIPTS, SCRIPT.LATIN_1.name(), Boolean.toString(true));
234  }
235  }
236 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.