19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
25 import java.util.logging.Level;
26 import org.openide.util.NbBundle;
35 class KeywordSearchSettings {
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";
42 static final boolean DEFAULT_SHOW_SNIPPETS =
true;
43 static final String OCR_ENABLED =
"ocrEnabled";
44 static final String LIMITED_OCR_ENABLED =
"limitedOcrEnabled";
45 static final boolean OCR_ENABLED_DEFAULT =
false;
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<>();
58 static UpdateFrequency getUpdateFrequency() {
59 if (ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS,
"UpdateFrequency") != null) {
60 return UpdateFrequency.valueOf(ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS,
"UpdateFrequency"));
63 logger.log(Level.WARNING,
"Could not read property for UpdateFrequency, returning backup value.");
64 return UpdateFrequency.DEFAULT;
72 static void setUpdateFrequency(UpdateFrequency freq) {
73 ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS,
"UpdateFrequency", freq.name());
83 static void setSkipKnown(
boolean skip) {
84 ModuleSettings.setConfigSetting(PROPERTIES_NSRL,
"SkipKnown", Boolean.toString(skip));
94 static boolean getSkipKnown() {
95 if (ModuleSettings.getConfigSetting(PROPERTIES_NSRL,
"SkipKnown") != null) {
96 return Boolean.parseBoolean(ModuleSettings.getConfigSetting(PROPERTIES_NSRL,
"SkipKnown"));
99 logger.log(Level.WARNING,
"Could not read property for SkipKnown, returning backup value.");
108 static void setStringExtractScripts(List<StringExtract.StringExtractUnicodeTable.SCRIPT> scripts) {
109 stringExtractScripts.clear();
110 stringExtractScripts.addAll(scripts);
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");
119 for (StringExtract.StringExtractUnicodeTable.SCRIPT s : stringExtractScripts) {
120 ModuleSettings.setConfigSetting(PROPERTIES_SCRIPTS, s.name(),
"true");
131 static void setStringExtractOption(String key, String val) {
132 stringExtractOptions.put(key, val);
133 ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, key, val);
144 static boolean getOcrOption() {
145 if (ModuleSettings.settingExists(PROPERTIES_OPTIONS, OCR_ENABLED)) {
146 return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, OCR_ENABLED).equals(
"true");
148 return OCR_ENABLED_DEFAULT;
162 static boolean getLimitedOcrOption() {
163 if (ModuleSettings.settingExists(PROPERTIES_OPTIONS, LIMITED_OCR_ENABLED)) {
164 return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, LIMITED_OCR_ENABLED).equals(
"true");
166 return LIMITED_OCR_ENABLED_DEFAULT;
170 static void setShowSnippets(
boolean showSnippets) {
171 ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, SHOW_SNIPPETS, (showSnippets ?
"true" :
"false"));
174 static boolean getShowSnippets() {
175 if (ModuleSettings.settingExists(PROPERTIES_OPTIONS, SHOW_SNIPPETS)) {
176 return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, SHOW_SNIPPETS).equals(
"true");
178 return DEFAULT_SHOW_SNIPPETS;
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")) {
192 scripts.add(SCRIPT.valueOf(kvp.getKey()));
198 logger.log(Level.WARNING,
"Could not read properties for extracting scripts, returning backup values.");
199 return new ArrayList<>(stringExtractScripts);
209 static String getStringExtractOption(String key) {
210 if (ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, key) != null) {
211 return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, key);
213 logger.log(Level.WARNING,
"Could not read property for key {0}, returning backup value.", key);
214 return stringExtractOptions.get(key);
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);
228 settingsv2.putAll(stringExtractOptions);
239 static void setDefaults() {
240 logger.log(Level.INFO,
"Detecting default settings.");
242 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_NSRL,
"SkipKnown")) {
243 logger.log(Level.INFO,
"No configuration for NSRL found, generating default...");
244 KeywordSearchSettings.setSkipKnown(
true);
247 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS,
"UpdateFrequency")) {
248 logger.log(Level.INFO,
"No configuration for Update Frequency found, generating default...");
249 KeywordSearchSettings.setUpdateFrequency(UpdateFrequency.DEFAULT);
252 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS, StringsExtractOptions.EXTRACT_UTF8.toString())) {
253 logger.log(Level.INFO,
"No configuration for UTF8 found, generating default...");
254 KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF8.toString(), Boolean.TRUE.toString());
257 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS, StringsExtractOptions.EXTRACT_UTF16.toString())) {
258 logger.log(Level.INFO,
"No configuration for UTF16 found, generating defaults...");
259 KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF16.toString(), Boolean.TRUE.toString());
262 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_SCRIPTS, SCRIPT.LATIN_1.name())) {
263 logger.log(Level.INFO,
"No configuration for Scripts found, generating defaults...");
264 ModuleSettings.setConfigSetting(KeywordSearchSettings.PROPERTIES_SCRIPTS, SCRIPT.LATIN_1.name(), Boolean.toString(
true));