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 boolean OCR_ENABLED_DEFAULT =
false;
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<>();
56 static UpdateFrequency getUpdateFrequency() {
57 if (ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS,
"UpdateFrequency") != null) {
58 return UpdateFrequency.valueOf(ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS,
"UpdateFrequency"));
61 logger.log(Level.WARNING,
"Could not read property for UpdateFrequency, returning backup value.");
62 return UpdateFrequency.DEFAULT;
70 static void setUpdateFrequency(UpdateFrequency freq) {
71 ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS,
"UpdateFrequency", freq.name());
81 static void setSkipKnown(
boolean skip) {
82 ModuleSettings.setConfigSetting(PROPERTIES_NSRL,
"SkipKnown", Boolean.toString(skip));
92 static boolean getSkipKnown() {
93 if (ModuleSettings.getConfigSetting(PROPERTIES_NSRL,
"SkipKnown") != null) {
94 return Boolean.parseBoolean(ModuleSettings.getConfigSetting(PROPERTIES_NSRL,
"SkipKnown"));
97 logger.log(Level.WARNING,
"Could not read property for SkipKnown, returning backup value.");
106 static void setStringExtractScripts(List<StringExtract.StringExtractUnicodeTable.SCRIPT> scripts) {
107 stringExtractScripts.clear();
108 stringExtractScripts.addAll(scripts);
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");
117 for (StringExtract.StringExtractUnicodeTable.SCRIPT s : stringExtractScripts) {
118 ModuleSettings.setConfigSetting(PROPERTIES_SCRIPTS, s.name(),
"true");
129 static void setStringExtractOption(String key, String val) {
130 stringExtractOptions.put(key, val);
131 ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, key, val);
139 static void setOcrOption(
boolean enabled) {
140 ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, OCR_ENABLED, (enabled ?
"true" :
"false"));
148 static boolean getOcrOption() {
149 if (ModuleSettings.settingExists(PROPERTIES_OPTIONS, OCR_ENABLED)) {
150 return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, OCR_ENABLED).equals(
"true");
152 return OCR_ENABLED_DEFAULT;
156 static void setShowSnippets(
boolean showSnippets) {
157 ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, SHOW_SNIPPETS, (showSnippets ?
"true" :
"false"));
160 static boolean getShowSnippets() {
161 if (ModuleSettings.settingExists(PROPERTIES_OPTIONS, SHOW_SNIPPETS)) {
162 return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, SHOW_SNIPPETS).equals(
"true");
164 return DEFAULT_SHOW_SNIPPETS;
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")) {
178 scripts.add(SCRIPT.valueOf(kvp.getKey()));
184 logger.log(Level.WARNING,
"Could not read properties for extracting scripts, returning backup values.");
185 return new ArrayList<>(stringExtractScripts);
195 static String getStringExtractOption(String key) {
196 if (ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, key) != null) {
197 return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, key);
199 logger.log(Level.WARNING,
"Could not read property for key {0}, returning backup value.", key);
200 return stringExtractOptions.get(key);
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);
214 settingsv2.putAll(stringExtractOptions);
225 static void setDefaults() {
226 logger.log(Level.INFO,
"Detecting default settings.");
228 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_NSRL,
"SkipKnown")) {
229 logger.log(Level.INFO,
"No configuration for NSRL found, generating default...");
230 KeywordSearchSettings.setSkipKnown(
true);
233 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS,
"UpdateFrequency")) {
234 logger.log(Level.INFO,
"No configuration for Update Frequency found, generating default...");
235 KeywordSearchSettings.setUpdateFrequency(UpdateFrequency.DEFAULT);
238 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS, StringsExtractOptions.EXTRACT_UTF8.toString())) {
239 logger.log(Level.INFO,
"No configuration for UTF8 found, generating default...");
240 KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF8.toString(), Boolean.TRUE.toString());
243 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS, StringsExtractOptions.EXTRACT_UTF16.toString())) {
244 logger.log(Level.INFO,
"No configuration for UTF16 found, generating defaults...");
245 KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF16.toString(), Boolean.TRUE.toString());
248 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS, OCR_ENABLED)) {
249 logger.log(Level.INFO,
"No configuration for OCR found, generating defaults...");
250 KeywordSearchSettings.setOcrOption(OCR_ENABLED_DEFAULT);
253 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_SCRIPTS, SCRIPT.LATIN_1.name())) {
254 logger.log(Level.INFO,
"No configuration for Scripts found, generating defaults...");
255 ModuleSettings.setConfigSetting(KeywordSearchSettings.PROPERTIES_SCRIPTS, SCRIPT.LATIN_1.name(), Boolean.toString(
true));