Autopsy  4.14.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;
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 boolean OCR_ENABLED_DEFAULT = false; // NON-NLS
45  private static boolean skipKnown = true;
46  private static final Logger logger = Logger.getLogger(KeywordSearchSettings.class.getName());
47  private static UpdateFrequency UpdateFreq = UpdateFrequency.DEFAULT;
48  private static List<StringExtract.StringExtractUnicodeTable.SCRIPT> stringExtractScripts = new ArrayList<>();
49  private static Map<String, String> stringExtractOptions = new HashMap<>();
50 
56  static UpdateFrequency getUpdateFrequency() {
57  if (ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, "UpdateFrequency") != null) { //NON-NLS
58  return UpdateFrequency.valueOf(ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, "UpdateFrequency")); //NON-NLS
59  }
60  //if it failed, return the default/last known value
61  logger.log(Level.WARNING, "Could not read property for UpdateFrequency, returning backup value."); //NON-NLS
62  return UpdateFrequency.DEFAULT;
63  }
64 
70  static void setUpdateFrequency(UpdateFrequency freq) {
71  ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, "UpdateFrequency", freq.name()); //NON-NLS
72  UpdateFreq = freq;
73  }
74 
81  static void setSkipKnown(boolean skip) {
82  ModuleSettings.setConfigSetting(PROPERTIES_NSRL, "SkipKnown", Boolean.toString(skip)); //NON-NLS
83  skipKnown = skip;
84  }
85 
92  static boolean getSkipKnown() {
93  if (ModuleSettings.getConfigSetting(PROPERTIES_NSRL, "SkipKnown") != null) { //NON-NLS
94  return Boolean.parseBoolean(ModuleSettings.getConfigSetting(PROPERTIES_NSRL, "SkipKnown")); //NON-NLS
95  }
96  //if it fails, return the default/last known value
97  logger.log(Level.WARNING, "Could not read property for SkipKnown, returning backup value."); //NON-NLS
98  return skipKnown;
99  }
100 
106  static void setStringExtractScripts(List<StringExtract.StringExtractUnicodeTable.SCRIPT> scripts) {
107  stringExtractScripts.clear();
108  stringExtractScripts.addAll(scripts);
109 
110  //Disabling scripts that weren't selected
111  for (String s : ModuleSettings.getConfigSettings(PROPERTIES_SCRIPTS).keySet()) {
112  if (!scripts.contains(StringExtract.StringExtractUnicodeTable.SCRIPT.valueOf(s))) {
113  ModuleSettings.setConfigSetting(PROPERTIES_SCRIPTS, s, "false"); //NON-NLS
114  }
115  }
116  //Writing and enabling selected scripts
117  for (StringExtract.StringExtractUnicodeTable.SCRIPT s : stringExtractScripts) {
118  ModuleSettings.setConfigSetting(PROPERTIES_SCRIPTS, s.name(), "true"); //NON-NLS
119  }
120 
121  }
122 
129  static void setStringExtractOption(String key, String val) {
130  stringExtractOptions.put(key, val);
131  ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, key, val);
132  }
133 
139  static void setOcrOption(boolean enabled) {
140  ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, OCR_ENABLED, (enabled ? "true" : "false")); //NON-NLS
141  }
142 
148  static boolean getOcrOption() {
149  if (ModuleSettings.settingExists(PROPERTIES_OPTIONS, OCR_ENABLED)) {
150  return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, OCR_ENABLED).equals("true"); //NON-NLS
151  } else {
152  return OCR_ENABLED_DEFAULT;
153  }
154  }
155 
156  static void setShowSnippets(boolean showSnippets) {
157  ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, SHOW_SNIPPETS, (showSnippets ? "true" : "false")); //NON-NLS
158  }
159 
160  static boolean getShowSnippets() {
161  if (ModuleSettings.settingExists(PROPERTIES_OPTIONS, SHOW_SNIPPETS)) {
162  return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, SHOW_SNIPPETS).equals("true"); //NON-NLS
163  } else {
164  return DEFAULT_SHOW_SNIPPETS;
165  }
166  }
167 
173  static List<SCRIPT> getStringExtractScripts() {
174  if (ModuleSettings.getConfigSettings(PROPERTIES_SCRIPTS) != null && !ModuleSettings.getConfigSettings(PROPERTIES_SCRIPTS).isEmpty()) {
175  List<SCRIPT> scripts = new ArrayList<>();
176  for (Map.Entry<String, String> kvp : ModuleSettings.getConfigSettings(PROPERTIES_SCRIPTS).entrySet()) {
177  if (kvp.getValue().equals("true")) { //NON-NLS
178  scripts.add(SCRIPT.valueOf(kvp.getKey()));
179  }
180  }
181  return scripts;
182  }
183  //if it failed, try to return the built-in list maintained by the singleton.
184  logger.log(Level.WARNING, "Could not read properties for extracting scripts, returning backup values."); //NON-NLS
185  return new ArrayList<>(stringExtractScripts);
186  }
187 
195  static String getStringExtractOption(String key) {
196  if (ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, key) != null) {
197  return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, key);
198  } else {
199  logger.log(Level.WARNING, "Could not read property for key {0}, returning backup value.", key); //NON-NLS
200  return stringExtractOptions.get(key);
201  }
202  }
203 
209  static Map<String, String> getStringExtractOptions() {
210  Map<String, String> settings = ModuleSettings.getConfigSettings(PROPERTIES_OPTIONS);
211  if (settings == null) {
212  Map<String, String> settingsv2 = new HashMap<>();
213  logger.log(Level.WARNING, "Could not read properties for {0}.properties, returning backup values", PROPERTIES_OPTIONS); //NON-NLS
214  settingsv2.putAll(stringExtractOptions);
215  return settingsv2;
216  } else {
217  return settings;
218  }
219  }
220 
225  static void setDefaults() {
226  logger.log(Level.INFO, "Detecting default settings."); //NON-NLS
227  //setting default NSRL
228  if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_NSRL, "SkipKnown")) { //NON-NLS
229  logger.log(Level.INFO, "No configuration for NSRL found, generating default..."); //NON-NLS
230  KeywordSearchSettings.setSkipKnown(true);
231  }
232  //setting default Update Frequency
233  if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS, "UpdateFrequency")) { //NON-NLS
234  logger.log(Level.INFO, "No configuration for Update Frequency found, generating default..."); //NON-NLS
235  KeywordSearchSettings.setUpdateFrequency(UpdateFrequency.DEFAULT);
236  }
237  //setting default Extract UTF8
238  if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS, StringsExtractOptions.EXTRACT_UTF8.toString())) {
239  logger.log(Level.INFO, "No configuration for UTF8 found, generating default..."); //NON-NLS
240  KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF8.toString(), Boolean.TRUE.toString());
241  }
242  //setting default Extract UTF16
243  if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS, StringsExtractOptions.EXTRACT_UTF16.toString())) {
244  logger.log(Level.INFO, "No configuration for UTF16 found, generating defaults..."); //NON-NLS
245  KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF16.toString(), Boolean.TRUE.toString());
246  }
247  //setting OCR default (disabled by default)
248  if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS, OCR_ENABLED)) {
249  logger.log(Level.INFO, "No configuration for OCR found, generating defaults..."); //NON-NLS
250  KeywordSearchSettings.setOcrOption(OCR_ENABLED_DEFAULT);
251  }
252  //setting default Latin-1 Script
253  if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_SCRIPTS, SCRIPT.LATIN_1.name())) {
254  logger.log(Level.INFO, "No configuration for Scripts found, generating defaults..."); //NON-NLS
255  ModuleSettings.setConfigSetting(KeywordSearchSettings.PROPERTIES_SCRIPTS, SCRIPT.LATIN_1.name(), Boolean.toString(true));
256  }
257  }
258 }

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.