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;
34 class KeywordSearchSettings {
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";
41 static final boolean DEFAULT_SHOW_SNIPPETS =
true;
42 static final String OCR_ENABLED =
"ocrEnabled";
43 static final String LIMITED_OCR_ENABLED =
"limitedOcrEnabled";
44 static final boolean OCR_ENABLED_DEFAULT =
false;
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<>();
57 static void setSkipKnown(
boolean skip) {
58 ModuleSettings.setConfigSetting(PROPERTIES_NSRL,
"SkipKnown", Boolean.toString(skip));
68 static boolean getSkipKnown() {
69 if (ModuleSettings.getConfigSetting(PROPERTIES_NSRL,
"SkipKnown") != null) {
70 return Boolean.parseBoolean(ModuleSettings.getConfigSetting(PROPERTIES_NSRL,
"SkipKnown"));
73 logger.log(Level.WARNING,
"Could not read property for SkipKnown, returning backup value.");
82 static void setStringExtractScripts(List<StringExtract.StringExtractUnicodeTable.SCRIPT> scripts) {
83 stringExtractScripts.clear();
84 stringExtractScripts.addAll(scripts);
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");
93 for (StringExtract.StringExtractUnicodeTable.SCRIPT s : stringExtractScripts) {
94 ModuleSettings.setConfigSetting(PROPERTIES_SCRIPTS, s.name(),
"true");
105 static void setStringExtractOption(String key, String val) {
106 stringExtractOptions.put(key, val);
107 ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, key, val);
118 static boolean getOcrOption() {
119 if (ModuleSettings.settingExists(PROPERTIES_OPTIONS, OCR_ENABLED)) {
120 return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, OCR_ENABLED).equals(
"true");
122 return OCR_ENABLED_DEFAULT;
136 static boolean getLimitedOcrOption() {
137 if (ModuleSettings.settingExists(PROPERTIES_OPTIONS, LIMITED_OCR_ENABLED)) {
138 return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, LIMITED_OCR_ENABLED).equals(
"true");
140 return LIMITED_OCR_ENABLED_DEFAULT;
144 static void setShowSnippets(
boolean showSnippets) {
145 ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, SHOW_SNIPPETS, (showSnippets ?
"true" :
"false"));
148 static boolean getShowSnippets() {
149 if (ModuleSettings.settingExists(PROPERTIES_OPTIONS, SHOW_SNIPPETS)) {
150 return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, SHOW_SNIPPETS).equals(
"true");
152 return DEFAULT_SHOW_SNIPPETS;
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")) {
166 scripts.add(SCRIPT.valueOf(kvp.getKey()));
172 logger.log(Level.WARNING,
"Could not read properties for extracting scripts, returning backup values.");
173 return new ArrayList<>(stringExtractScripts);
183 static String getStringExtractOption(String key) {
184 if (ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, key) != null) {
185 return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, key);
187 logger.log(Level.WARNING,
"Could not read property for key {0}, returning backup value.", key);
188 return stringExtractOptions.get(key);
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);
202 settingsv2.putAll(stringExtractOptions);
213 static void setDefaults() {
214 logger.log(Level.INFO,
"Detecting default settings.");
216 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_NSRL,
"SkipKnown")) {
217 logger.log(Level.INFO,
"No configuration for NSRL found, generating default...");
218 KeywordSearchSettings.setSkipKnown(
true);
221 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS, StringsExtractOptions.EXTRACT_UTF8.toString())) {
222 logger.log(Level.INFO,
"No configuration for UTF8 found, generating default...");
223 KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF8.toString(), Boolean.TRUE.toString());
226 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS, StringsExtractOptions.EXTRACT_UTF16.toString())) {
227 logger.log(Level.INFO,
"No configuration for UTF16 found, generating defaults...");
228 KeywordSearchSettings.setStringExtractOption(StringsExtractOptions.EXTRACT_UTF16.toString(), Boolean.TRUE.toString());
231 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_SCRIPTS, SCRIPT.LATIN_1.name())) {
232 logger.log(Level.INFO,
"No configuration for Scripts found, generating defaults...");
233 ModuleSettings.setConfigSetting(KeywordSearchSettings.PROPERTIES_SCRIPTS, SCRIPT.LATIN_1.name(), Boolean.toString(
true));