Autopsy  4.19.1
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;
33 
34 //This file contains constants and settings for KeywordSearch
35 class KeywordSearchSettings {
36 
37  public static final String MODULE_NAME = NbBundle.getMessage(KeywordSearchSettings.class, "KeywordSearchSettings.moduleName.text");
38  static final String PROPERTIES_OPTIONS = NbBundle.getMessage(KeywordSearchSettings.class, "KeywordSearchSettings.properties_options.text", MODULE_NAME);
39  static final String PROPERTIES_NSRL = NbBundle.getMessage(KeywordSearchSettings.class, "KeywordSearchSettings.propertiesNSRL.text", MODULE_NAME);
40  static final String PROPERTIES_SCRIPTS = NbBundle.getMessage(KeywordSearchSettings.class, "KeywordSearchSettings.propertiesScripts.text", MODULE_NAME);
41  static final String SHOW_SNIPPETS = "showSnippets"; //NON-NLS
42  static final boolean DEFAULT_SHOW_SNIPPETS = true;
43  static final String OCR_ENABLED = "ocrEnabled"; //NON-NLS
44  static final String LIMITED_OCR_ENABLED = "limitedOcrEnabled"; //NON-NLS
45  static final boolean OCR_ENABLED_DEFAULT = false; // NON-NLS
46  static final boolean LIMITED_OCR_ENABLED_DEFAULT = false;
47  private static boolean skipKnown = true;
48  private static final Logger logger = Logger.getLogger(KeywordSearchSettings.class.getName());
49  private static UpdateFrequency UpdateFreq = UpdateFrequency.DEFAULT;
50  private static List<StringExtract.StringExtractUnicodeTable.SCRIPT> stringExtractScripts = new ArrayList<>();
51  private static Map<String, String> stringExtractOptions = new HashMap<>();
52 
58  static UpdateFrequency getUpdateFrequency() {
59  if (ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, "UpdateFrequency") != null) { //NON-NLS
60  return UpdateFrequency.valueOf(ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, "UpdateFrequency")); //NON-NLS
61  }
62  //if it failed, return the default/last known value
63  logger.log(Level.WARNING, "Could not read property for UpdateFrequency, returning backup value."); //NON-NLS
64  return UpdateFrequency.DEFAULT;
65  }
66 
72  static void setUpdateFrequency(UpdateFrequency freq) {
73  ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, "UpdateFrequency", freq.name()); //NON-NLS
74  UpdateFreq = freq;
75  }
76 
83  static void setSkipKnown(boolean skip) {
84  ModuleSettings.setConfigSetting(PROPERTIES_NSRL, "SkipKnown", Boolean.toString(skip)); //NON-NLS
85  skipKnown = skip;
86  }
87 
94  static boolean getSkipKnown() {
95  if (ModuleSettings.getConfigSetting(PROPERTIES_NSRL, "SkipKnown") != null) { //NON-NLS
96  return Boolean.parseBoolean(ModuleSettings.getConfigSetting(PROPERTIES_NSRL, "SkipKnown")); //NON-NLS
97  }
98  //if it fails, return the default/last known value
99  logger.log(Level.WARNING, "Could not read property for SkipKnown, returning backup value."); //NON-NLS
100  return skipKnown;
101  }
102 
108  static void setStringExtractScripts(List<StringExtract.StringExtractUnicodeTable.SCRIPT> scripts) {
109  stringExtractScripts.clear();
110  stringExtractScripts.addAll(scripts);
111 
112  //Disabling scripts that weren't selected
113  for (String s : ModuleSettings.getConfigSettings(PROPERTIES_SCRIPTS).keySet()) {
114  if (!scripts.contains(StringExtract.StringExtractUnicodeTable.SCRIPT.valueOf(s))) {
115  ModuleSettings.setConfigSetting(PROPERTIES_SCRIPTS, s, "false"); //NON-NLS
116  }
117  }
118  //Writing and enabling selected scripts
119  for (StringExtract.StringExtractUnicodeTable.SCRIPT s : stringExtractScripts) {
120  ModuleSettings.setConfigSetting(PROPERTIES_SCRIPTS, s.name(), "true"); //NON-NLS
121  }
122 
123  }
124 
131  static void setStringExtractOption(String key, String val) {
132  stringExtractOptions.put(key, val);
133  ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, key, val);
134  }
135 
143  @Deprecated
144  static boolean getOcrOption() {
145  if (ModuleSettings.settingExists(PROPERTIES_OPTIONS, OCR_ENABLED)) {
146  return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, OCR_ENABLED).equals("true"); //NON-NLS
147  } else {
148  return OCR_ENABLED_DEFAULT;
149  }
150  }
151 
161  @Deprecated
162  static boolean getLimitedOcrOption() {
163  if (ModuleSettings.settingExists(PROPERTIES_OPTIONS, LIMITED_OCR_ENABLED)) {
164  return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, LIMITED_OCR_ENABLED).equals("true"); //NON-NLS
165  } else {
166  return LIMITED_OCR_ENABLED_DEFAULT;
167  }
168  }
169 
170  static void setShowSnippets(boolean showSnippets) {
171  ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, SHOW_SNIPPETS, (showSnippets ? "true" : "false")); //NON-NLS
172  }
173 
174  static boolean getShowSnippets() {
175  if (ModuleSettings.settingExists(PROPERTIES_OPTIONS, SHOW_SNIPPETS)) {
176  return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, SHOW_SNIPPETS).equals("true"); //NON-NLS
177  } else {
178  return DEFAULT_SHOW_SNIPPETS;
179  }
180  }
181 
187  static List<SCRIPT> getStringExtractScripts() {
188  if (ModuleSettings.getConfigSettings(PROPERTIES_SCRIPTS) != null && !ModuleSettings.getConfigSettings(PROPERTIES_SCRIPTS).isEmpty()) {
189  List<SCRIPT> scripts = new ArrayList<>();
190  for (Map.Entry<String, String> kvp : ModuleSettings.getConfigSettings(PROPERTIES_SCRIPTS).entrySet()) {
191  if (kvp.getValue().equals("true")) { //NON-NLS
192  scripts.add(SCRIPT.valueOf(kvp.getKey()));
193  }
194  }
195  return scripts;
196  }
197  //if it failed, try to return the built-in list maintained by the singleton.
198  logger.log(Level.WARNING, "Could not read properties for extracting scripts, returning backup values."); //NON-NLS
199  return new ArrayList<>(stringExtractScripts);
200  }
201 
209  static String getStringExtractOption(String key) {
210  if (ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, key) != null) {
211  return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, key);
212  } else {
213  logger.log(Level.WARNING, "Could not read property for key {0}, returning backup value.", key); //NON-NLS
214  return stringExtractOptions.get(key);
215  }
216  }
217 
223  static Map<String, String> getStringExtractOptions() {
224  Map<String, String> settings = ModuleSettings.getConfigSettings(PROPERTIES_OPTIONS);
225  if (settings == null) {
226  Map<String, String> settingsv2 = new HashMap<>();
227  logger.log(Level.WARNING, "Could not read properties for {0}.properties, returning backup values", PROPERTIES_OPTIONS); //NON-NLS
228  settingsv2.putAll(stringExtractOptions);
229  return settingsv2;
230  } else {
231  return settings;
232  }
233  }
234 
239  static void setDefaults() {
240  logger.log(Level.INFO, "Detecting default settings."); //NON-NLS
241  //setting default NSRL
242  if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_NSRL, "SkipKnown")) { //NON-NLS
243  logger.log(Level.INFO, "No configuration for NSRL found, generating default..."); //NON-NLS
244  KeywordSearchSettings.setSkipKnown(true);
245  }
246  //setting default Update Frequency
247  if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS, "UpdateFrequency")) { //NON-NLS
248  logger.log(Level.INFO, "No configuration for Update Frequency found, generating default..."); //NON-NLS
249  KeywordSearchSettings.setUpdateFrequency(UpdateFrequency.DEFAULT);
250  }
251  //setting default Extract UTF8
252  if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS, StringsExtractOptions.EXTRACT_UTF8.toString())) {
253  logger.log(Level.INFO, "No configuration for UTF8 found, generating default..."); //NON-NLS
254  KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF8.toString(), Boolean.TRUE.toString());
255  }
256  //setting default Extract UTF16
257  if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS, StringsExtractOptions.EXTRACT_UTF16.toString())) {
258  logger.log(Level.INFO, "No configuration for UTF16 found, generating defaults..."); //NON-NLS
259  KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF16.toString(), Boolean.TRUE.toString());
260  }
261  //setting default Latin-1 Script
262  if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_SCRIPTS, SCRIPT.LATIN_1.name())) {
263  logger.log(Level.INFO, "No configuration for Scripts found, generating defaults..."); //NON-NLS
264  ModuleSettings.setConfigSetting(KeywordSearchSettings.PROPERTIES_SCRIPTS, SCRIPT.LATIN_1.name(), Boolean.toString(true));
265  }
266  }
267 }

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