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;
27 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 private static boolean skipKnown =
true;
44 private static final Logger logger = Logger.getLogger(KeywordSearchSettings.class.getName());
45 private static UpdateFrequency UpdateFreq = UpdateFrequency.DEFAULT;
46 private static List<StringExtract.StringExtractUnicodeTable.SCRIPT> stringExtractScripts =
new ArrayList<>();
47 private static Map<String, String> stringExtractOptions =
new HashMap<>();
54 static UpdateFrequency getUpdateFrequency() {
55 if (ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS,
"UpdateFrequency") != null) {
56 return UpdateFrequency.valueOf(ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS,
"UpdateFrequency"));
59 logger.log(Level.WARNING,
"Could not read property for UpdateFrequency, returning backup value.");
60 return UpdateFrequency.DEFAULT;
68 static void setUpdateFrequency(UpdateFrequency freq) {
69 ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS,
"UpdateFrequency", freq.name());
79 static void setSkipKnown(
boolean skip) {
80 ModuleSettings.setConfigSetting(PROPERTIES_NSRL,
"SkipKnown", Boolean.toString(skip));
90 static boolean getSkipKnown() {
91 if (ModuleSettings.getConfigSetting(PROPERTIES_NSRL,
"SkipKnown") != null) {
92 return Boolean.parseBoolean(ModuleSettings.getConfigSetting(PROPERTIES_NSRL,
"SkipKnown"));
95 logger.log(Level.WARNING,
"Could not read property for SkipKnown, returning backup value.");
104 static void setStringExtractScripts(List<StringExtract.StringExtractUnicodeTable.SCRIPT> scripts) {
105 stringExtractScripts.clear();
106 stringExtractScripts.addAll(scripts);
109 for (String s : ModuleSettings.getConfigSettings(PROPERTIES_SCRIPTS).keySet()) {
110 if (!scripts.contains(StringExtract.StringExtractUnicodeTable.SCRIPT.valueOf(s))) {
111 ModuleSettings.setConfigSetting(PROPERTIES_SCRIPTS, s,
"false");
115 for (StringExtract.StringExtractUnicodeTable.SCRIPT s : stringExtractScripts) {
116 ModuleSettings.setConfigSetting(PROPERTIES_SCRIPTS, s.name(),
"true");
127 static void setStringExtractOption(String key, String val) {
128 stringExtractOptions.put(key, val);
129 ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, key, val);
132 static void setShowSnippets(
boolean showSnippets) {
133 ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, SHOW_SNIPPETS, (showSnippets ?
"true" :
"false"));
136 static boolean getShowSnippets() {
137 if (ModuleSettings.settingExists(PROPERTIES_OPTIONS, SHOW_SNIPPETS)) {
138 return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, SHOW_SNIPPETS).equals(
"true");
140 return DEFAULT_SHOW_SNIPPETS;
149 static List<SCRIPT> getStringExtractScripts() {
150 if (ModuleSettings.getConfigSettings(PROPERTIES_SCRIPTS) != null && !ModuleSettings.getConfigSettings(PROPERTIES_SCRIPTS).isEmpty()) {
151 List<SCRIPT> scripts =
new ArrayList<>();
152 for (Map.Entry<String, String> kvp : ModuleSettings.getConfigSettings(PROPERTIES_SCRIPTS).entrySet()) {
153 if (kvp.getValue().equals(
"true")) {
154 scripts.add(SCRIPT.valueOf(kvp.getKey()));
160 logger.log(Level.WARNING,
"Could not read properties for extracting scripts, returning backup values.");
161 return new ArrayList<>(stringExtractScripts);
170 static String getStringExtractOption(String key) {
171 if (ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, key) != null) {
172 return ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, key);
174 logger.log(Level.WARNING,
"Could not read property for key {0}, returning backup value.", key);
175 return stringExtractOptions.get(key);
184 static Map<String, String> getStringExtractOptions() {
185 Map<String, String> settings = ModuleSettings.getConfigSettings(PROPERTIES_OPTIONS);
186 if (settings == null) {
187 Map<String, String> settingsv2 =
new HashMap<>();
188 logger.log(Level.WARNING,
"Could not read properties for {0}.properties, returning backup values", PROPERTIES_OPTIONS);
189 settingsv2.putAll(stringExtractOptions);
200 static void setDefaults() {
201 logger.log(Level.INFO,
"Detecting default settings.");
203 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_NSRL,
"SkipKnown")) {
204 logger.log(Level.INFO,
"No configuration for NSRL found, generating default...");
205 KeywordSearchSettings.setSkipKnown(
true);
208 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS,
"UpdateFrequency")) {
209 logger.log(Level.INFO,
"No configuration for Update Frequency found, generating default...");
210 KeywordSearchSettings.setUpdateFrequency(UpdateFrequency.DEFAULT);
213 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS, TextExtractor.ExtractOptions.EXTRACT_UTF8.toString())) {
214 logger.log(Level.INFO,
"No configuration for UTF8 found, generating default...");
215 KeywordSearchSettings.setStringExtractOption(TextExtractor.ExtractOptions.EXTRACT_UTF8.toString(), Boolean.TRUE.toString());
218 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_OPTIONS, TextExtractor.ExtractOptions.EXTRACT_UTF16.toString())) {
219 logger.log(Level.INFO,
"No configuration for UTF16 found, generating defaults...");
220 KeywordSearchSettings.setStringExtractOption(TextExtractor.ExtractOptions.EXTRACT_UTF16.toString(), Boolean.TRUE.toString());
223 if (!ModuleSettings.settingExists(KeywordSearchSettings.PROPERTIES_SCRIPTS, SCRIPT.LATIN_1.name())) {
224 logger.log(Level.INFO,
"No configuration for Scripts found, generating defaults...");
225 ModuleSettings.setConfigSetting(KeywordSearchSettings.PROPERTIES_SCRIPTS, SCRIPT.LATIN_1.name(), Boolean.toString(
true));