diff --git a/CoreUtils/src/org/sleuthkit/autopsy/coreutils/ModuleSettings.java b/CoreUtils/src/org/sleuthkit/autopsy/coreutils/ModuleSettings.java index 74beec655c..117c5eb4ab 100644 --- a/CoreUtils/src/org/sleuthkit/autopsy/coreutils/ModuleSettings.java +++ b/CoreUtils/src/org/sleuthkit/autopsy/coreutils/ModuleSettings.java @@ -81,6 +81,20 @@ public class ModuleSettings { return f.exists(); } + public static boolean settingExists(String moduleName, String settingName){ + if(! configExists(moduleName)){ + return false; + } + try{ + Properties props = fetchProperties(moduleName); + return (props.getProperty(settingName) != null); + } + catch(IOException e){ + return false; + } + + } + /** * Returns the path of the given properties file. * @param moduleName - The name of the config file to evaluate @@ -155,7 +169,7 @@ public class ModuleSettings { * @param moduleName - The name of the module to be written to. * @param settings - The mapping of all key:value pairs of settings to add to the config. */ - public static void setConfigSettings(String moduleName, Map settings) { + public static synchronized void setConfigSettings(String moduleName, Map settings) { if (!configExists(moduleName)) { makeConfigFile(moduleName); Logger.getLogger(ModuleSettings.class.getName()).log(Level.INFO, "File did not exist. Created file [" + moduleName + ".properties]"); @@ -182,7 +196,7 @@ public class ModuleSettings { * @param settingName - The name of the setting to be modified. * @param settingVal - the value to set the setting to. */ - public static void setConfigSetting(String moduleName, String settingName, String settingVal) { + public static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal) { if (!configExists(moduleName)) { makeConfigFile(moduleName); Logger.getLogger(ModuleSettings.class.getName()).log(Level.INFO, "File did not exist. Created file [" + moduleName + ".properties]"); @@ -209,7 +223,7 @@ public class ModuleSettings { * @param key - the name of the key to remove. */ - public static void removeProperty(String moduleName, String key){ + public static synchronized void removeProperty(String moduleName, String key){ try{ if(getConfigSetting(moduleName, key) != null){ Properties props = fetchProperties(moduleName); @@ -243,10 +257,16 @@ public class ModuleSettings { /** * Gets the property file as specified. * @param moduleName - * @return A new file handle + * @return A new file handle, returns null if the file does not exist. */ public static File getPropertyFile(String moduleName) { + String path = getPropertyPath(moduleName); + if (path == null){ + return null; + } + else{ return new File(getPropertyPath(moduleName)); + } } } diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchConfigurationPanel2.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchConfigurationPanel2.java index e2ee055ab1..db1833e5f4 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchConfigurationPanel2.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchConfigurationPanel2.java @@ -45,7 +45,7 @@ public class KeywordSearchConfigurationPanel2 extends javax.swing.JPanel impleme private void activateWidgets() { skipNSRLCheckBox.setSelected(KeywordSearchSettings.getSkipKnown()); boolean enable = !IngestManager.getDefault().isIngestRunning() - && !IngestManager.getDefault().isModuleRunning(KeywordSearchSettings.getDefault()); + && !IngestManager.getDefault().isModuleRunning(KeywordSearchIngestModule.getDefault()); skipNSRLCheckBox.setEnabled(enable); setTimeSettingEnabled(enable); diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchConfigurationPanel3.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchConfigurationPanel3.java index bd7a7b7102..263e5d860e 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchConfigurationPanel3.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchConfigurationPanel3.java @@ -150,7 +150,7 @@ public class KeywordSearchConfigurationPanel3 extends javax.swing.JPanel impleme final boolean extractEnabled = utf16 || utf8; boolean ingestNotRunning = !IngestManager.getDefault().isIngestRunning() - && ! IngestManager.getDefault().isModuleRunning(KeywordSearchSettings.getDefault());; + && ! IngestManager.getDefault().isModuleRunning(KeywordSearchIngestModule.getDefault()); //enable / disable checboxes activateScriptsCheckboxes(extractEnabled && ingestNotRunning); enableUTF16Checkbox.setEnabled(ingestNotRunning); diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java index ce2b5c01b4..9e92936738 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java @@ -88,7 +88,6 @@ public final class KeywordSearchIngestModule implements IngestModuleAbstractFile return time; } }; - private volatile UpdateFrequency updateFrequency = UpdateFrequency.AVG; private static final Logger logger = Logger.getLogger(KeywordSearchIngestModule.class.getName()); public static final String MODULE_NAME = "Keyword Search"; @@ -135,21 +134,7 @@ public final class KeywordSearchIngestModule implements IngestModuleAbstractFile //private constructor to ensure singleton instance private KeywordSearchIngestModule() { //set default script - - - if(ModuleSettings.getConfigSetting(KeywordSearchSettings.PROPERTIES_OPTIONS, AbstractFileExtract.ExtractOptions.EXTRACT_UTF8.toString()) == null){ - KeywordSearchSettings.stringExtractOptions.put(AbstractFileExtract.ExtractOptions.EXTRACT_UTF8.toString(), Boolean.TRUE.toString()); - - } - if(ModuleSettings.getConfigSetting(KeywordSearchSettings.PROPERTIES_SCRIPTS, SCRIPT.LATIN_1.name()) == null){ - ModuleSettings.setConfigSetting(KeywordSearchSettings.PROPERTIES_SCRIPTS, SCRIPT.LATIN_1.name(), Boolean.toString(true)); - KeywordSearchSettings.stringExtractScripts.add(SCRIPT.LATIN_1); - } - if(ModuleSettings.getConfigSetting(KeywordSearchSettings.PROPERTIES_OPTIONS, AbstractFileExtract.ExtractOptions.EXTRACT_UTF16.toString()) == null){ - KeywordSearchSettings.stringExtractOptions.put(AbstractFileExtract.ExtractOptions.EXTRACT_UTF16.toString(), Boolean.TRUE.toString()); - } - - + KeywordSearchSettings.setDefaults(); } /** @@ -167,18 +152,10 @@ public final class KeywordSearchIngestModule implements IngestModuleAbstractFile /** * returns the current minimal update frequency setting in minutes */ - UpdateFrequency getUpdateFrequency() { - return updateFrequency; + private UpdateFrequency getUpdateFrequency() { + return KeywordSearchSettings.getUpdateFrequency(); } - /** - * set new minimal update frequency module should use - * - * @param frequency to use in minutes - */ - void setUpdateFrequency(UpdateFrequency frequency) { - this.updateFrequency = frequency; - } /** * Starts processing of every file provided by IngestManager. Checks if it @@ -373,17 +350,13 @@ public final class KeywordSearchIngestModule implements IngestModuleAbstractFile //use the settings files to set values - //Grabbing skipKnown - if(! ModuleSettings.getConfigSettings(KeywordSearchSettings.PROPERTIES_NSRL).isEmpty()){ - try{ - KeywordSearchSettings.setSkipKnown(Boolean.parseBoolean(ModuleSettings.getConfigSetting(KeywordSearchSettings.PROPERTIES_NSRL, "SkipKnown"))); - } - catch(Exception e){ - Logger.getLogger(KeywordSearchIngestModule.class.getName()).log(Level.WARNING, "Could not parse boolean value from properties file.", e); - } + + + //setting default skip known + if(ModuleSettings.getConfigSetting(KeywordSearchSettings.PROPERTIES_NSRL, "SkipKnown") == null){ + KeywordSearchSettings.setSkipKnown(true); } - //populating stringExtractOptions if(! ModuleSettings.getConfigSettings(KeywordSearchSettings.PROPERTIES_OPTIONS).isEmpty()){ KeywordSearchSettings.stringExtractOptions = ModuleSettings.getConfigSettings(KeywordSearchSettings.PROPERTIES_OPTIONS); @@ -391,16 +364,11 @@ public final class KeywordSearchIngestModule implements IngestModuleAbstractFile //populating stringExtractScripts if(! ModuleSettings.getConfigSettings(KeywordSearchSettings.PROPERTIES_SCRIPTS).isEmpty()){ - try{ for(Map.Entry kvp: ModuleSettings.getConfigSettings(KeywordSearchSettings.PROPERTIES_SCRIPTS).entrySet()){ if(kvp.getKey() != null && Boolean.parseBoolean(kvp.getValue())){ KeywordSearchSettings.stringExtractScripts.add(SCRIPT.valueOf(kvp.getKey())); } } - } - catch(Exception e ){ - Logger.getLogger(KeywordSearchIngestModule.class.getName()).log(Level.WARNING, "Could not parse boolean value from properties file.", e); - } } @@ -443,7 +411,7 @@ public final class KeywordSearchIngestModule implements IngestModuleAbstractFile indexer = new Indexer(); - final int updateIntervalMs = updateFrequency.getTime() * 60 * 1000; + final int updateIntervalMs = KeywordSearchSettings.getUpdateFrequency().getTime() * 60 * 1000; logger.log(Level.INFO, "Using commit interval (ms): " + updateIntervalMs); logger.log(Level.INFO, "Using searcher interval (ms): " + updateIntervalMs); diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSettings.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSettings.java index ae6fd87948..9b6c3440d1 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSettings.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSettings.java @@ -39,37 +39,36 @@ public class KeywordSearchSettings { static final String PROPERTIES_NSRL = MODULE_NAME+"_NSRL"; static final String PROPERTIES_SCRIPTS = MODULE_NAME+"_Scripts"; private static boolean skipKnown = true; + private static final Logger logger = Logger.getLogger(KeywordSearchSettings.class.getName()); + private static UpdateFrequency UpdateFreq = UpdateFrequency.AVG; static List stringExtractScripts = new ArrayList(); static Map stringExtractOptions = new HashMap(); - + /** - * - * @return IngestModule singleton - */ - static KeywordSearchIngestModule getDefault(){ - return KeywordSearchIngestModule.getDefault(); - } - - /** - * - * @return IngestModule's update frequency + * Gets the update Frequency from KeywordSearch_Options.properties + * @return KeywordSearchIngestModule's update frequency */ static UpdateFrequency getUpdateFrequency(){ - return KeywordSearchIngestModule.getDefault().getUpdateFrequency(); + if(ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, "UpdateFrequency") != null){ + return UpdateFrequency.valueOf(ModuleSettings.getConfigSetting(PROPERTIES_OPTIONS, "UpdateFrequency")); + } + //if it failed, return the default/last known value + logger.log(Level.WARNING, "Could not read property for UpdateFrequency, returning backup value."); + return UpdateFreq; } + /** - * Sets the ingest module's update frequency. - * @param c Update frequency to set. + * Sets the update frequency and writes to KeywordSearch_Options.properties + * @param freq Sets KeywordSearchIngestModule to this value. */ - static void setUpdateFrequency(UpdateFrequency c){ - KeywordSearchIngestModule.getDefault().setUpdateFrequency(c); + static void setUpdateFrequency(UpdateFrequency freq){ + ModuleSettings.setConfigSetting(PROPERTIES_OPTIONS, "UpdateFrequency", freq.name()); + UpdateFreq = freq; } - - /** * Sets whether or not to skip adding known good files to the search during index. * @param skip @@ -78,6 +77,19 @@ public class KeywordSearchSettings { ModuleSettings.setConfigSetting(PROPERTIES_NSRL, "SkipKnown", Boolean.toString(skip)); skipKnown = skip; } + + /** + * Gets the setting for whether or not this ingest is skipping adding known good files to the index. + * @return skip setting + */ + static boolean getSkipKnown() { + if(ModuleSettings.getConfigSetting(PROPERTIES_NSRL, "SkipKnown") != null){ + return Boolean.parseBoolean(ModuleSettings.getConfigSetting(PROPERTIES_NSRL, "SkipKnown")); + } + //if it fails, return the default/last known value + logger.log(Level.WARNING, "Could not read property for SkipKnown, returning backup value."); + return skipKnown; + } @@ -126,6 +138,7 @@ public class KeywordSearchSettings { return scripts; } //if it failed, try to return the built-in list maintained by the singleton. + logger.log(Level.WARNING, "Could not read properties for extracting scripts, returning backup values."); return new ArrayList