diff --git a/CoreUtils/src/org/sleuthkit/autopsy/coreutils/ModuleSettings.java b/CoreUtils/src/org/sleuthkit/autopsy/coreutils/ModuleSettings.java index d7ab6a7c40..74beec655c 100644 --- a/CoreUtils/src/org/sleuthkit/autopsy/coreutils/ModuleSettings.java +++ b/CoreUtils/src/org/sleuthkit/autopsy/coreutils/ModuleSettings.java @@ -101,26 +101,21 @@ public class ModuleSettings { * @return - the value associated with the setting. * @throws IOException */ - public static String getConfigSetting(String moduleName, String settingName){ - if(configExists(moduleName)){ - try{ - InputStream inputStream = new FileInputStream(getPropertyPath(moduleName)); - Properties props = new Properties(); - props.load(inputStream); - inputStream.close(); - return props.getProperty(settingName); - } - - catch(IOException e){ - Logger.getLogger(ModuleSettings.class.getName()).log(Level.WARNING, "Could not read config file [" + moduleName + "]", e); - return null; - } - - } - else{ + public static String getConfigSetting(String moduleName, String settingName) { + if (!configExists(moduleName)) { makeConfigFile(moduleName); - return getConfigSetting(moduleName, settingName); + Logger.getLogger(ModuleSettings.class.getName()).log(Level.INFO, "File did not exist. Created file [" + moduleName + ".properties]"); } + + try { + Properties props = fetchProperties(moduleName); + + return props.getProperty(settingName); + } catch (IOException e) { + Logger.getLogger(ModuleSettings.class.getName()).log(Level.WARNING, "Could not read config file [" + moduleName + "]", e); + return null; + } + } @@ -132,63 +127,52 @@ public class ModuleSettings { */ public static Map< String, String> getConfigSettings(String moduleName) { - if (configExists(moduleName)) { - try{ - InputStream inputStream = new FileInputStream(getPropertyPath(moduleName)); - Properties props = new Properties(); - props.load(inputStream); - inputStream.close(); - + if (!configExists(moduleName)) { + makeConfigFile(moduleName); + Logger.getLogger(ModuleSettings.class.getName()).log(Level.INFO, "File did not exist. Created file [" + moduleName + ".properties]"); + } + try { + Properties props = fetchProperties(moduleName); Set keys = props.stringPropertyNames(); Map map = new HashMap(); - + for (String s : keys) { map.put(s, props.getProperty(s)); } - + return map; - } - catch(IOException e){ - Logger.getLogger(ModuleSettings.class.getName()).log(Level.WARNING, "Could not read config file [" + moduleName + "]", e); - return null; - } - } - else { - makeConfigFile(moduleName); - return getConfigSettings(moduleName); + } catch (IOException e) { + Logger.getLogger(ModuleSettings.class.getName()).log(Level.WARNING, "Could not read config file [" + moduleName + "]", e); + return null; } } + + /** * Sets the given properties file to the given setting map. * @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){ - if(configExists(moduleName)){ - try{ - InputStream inputStream = new FileInputStream(getPropertyPath(moduleName)); - Properties props = new Properties(); - props.load(inputStream); - inputStream.close(); + public static 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]"); + } + try { + Properties props = fetchProperties(moduleName); - for(Map.Entry kvp : settings.entrySet()){ + for (Map.Entry kvp : settings.entrySet()) { props.setProperty(kvp.getKey(), kvp.getValue()); } - + File path = new File(getPropertyPath(moduleName)); FileOutputStream fos = new FileOutputStream(path); - props.store(fos, "Changed config settings"); + props.store(fos, "Changed config settings(batch)"); fos.close(); - } - catch(IOException e ){ - Logger.getLogger(ModuleSettings.class.getName()).log(Level.WARNING, "Property file exists for [" + moduleName + "] at [" + getPropertyPath(moduleName) + "] but could not be loaded.", e); - } - } - else{ - makeConfigFile(moduleName); - setConfigSettings(moduleName, settings); + } catch (IOException e) { + Logger.getLogger(ModuleSettings.class.getName()).log(Level.WARNING, "Property file exists for [" + moduleName + "] at [" + getPropertyPath(moduleName) + "] but could not be loaded.", e); } } @@ -199,30 +183,22 @@ public class ModuleSettings { * @param settingVal - the value to set the setting to. */ public static void setConfigSetting(String moduleName, String settingName, String settingVal) { - if(configExists(moduleName)){ - try{ - InputStream inputStream = new FileInputStream(getPropertyPath(moduleName)); - Properties props = new Properties(); - props.load(inputStream); - inputStream.close(); - - props.setProperty(settingName, settingVal); - - File path = new File(getPropertyPath(moduleName)); - FileOutputStream fos = new FileOutputStream(path); - props.store(fos, "Changed config settings"); - fos.close(); - } - catch(IOException e ){ - Logger.getLogger(ModuleSettings.class.getName()).log(Level.WARNING, "Property file exists for [" + moduleName + "] at [" + getPropertyPath(moduleName) + "] but could not be loaded.", e); - } - } - - else{ - //throw new FileNotFoundException("No property file found for [" + moduleName + "]"); + if (!configExists(moduleName)) { makeConfigFile(moduleName); Logger.getLogger(ModuleSettings.class.getName()).log(Level.INFO, "File did not exist. Created file [" + moduleName + ".properties]"); - setConfigSetting(moduleName, settingName, settingVal); + } + + try { + Properties props = fetchProperties(moduleName); + + props.setProperty(settingName, settingVal); + + File path = new File(getPropertyPath(moduleName)); + FileOutputStream fos = new FileOutputStream(path); + props.store(fos, "Changed config settings(single)"); + fos.close(); + } catch (IOException e) { + Logger.getLogger(ModuleSettings.class.getName()).log(Level.WARNING, "Property file exists for [" + moduleName + "] at [" + getPropertyPath(moduleName) + "] but could not be loaded.", e); } } @@ -236,11 +212,8 @@ public class ModuleSettings { public static void removeProperty(String moduleName, String key){ try{ if(getConfigSetting(moduleName, key) != null){ - // setConfigSetting(moduleName, key, ""); - InputStream inputStream = new FileInputStream(getPropertyPath(moduleName)); - Properties props = new Properties(); - props.load(inputStream); - inputStream.close(); + Properties props = fetchProperties(moduleName); + props.remove(key); File path = new File(getPropertyPath(moduleName)); FileOutputStream fos = new FileOutputStream(path); @@ -253,6 +226,20 @@ public class ModuleSettings { } } + /** + * Returns the properties file as specified by moduleName. + * @param moduleName + * @return Properties file as specified by moduleName. + * @throws IOException + */ + private static Properties fetchProperties(String moduleName)throws IOException{ + InputStream inputStream = new FileInputStream(getPropertyPath(moduleName)); + Properties props = new Properties(); + props.load(inputStream); + inputStream.close(); + return props; + } + /** * Gets the property file as specified. * @param moduleName diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java index 18a7a49ed8..2ab9e8b297 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchIngestModule.java @@ -92,10 +92,8 @@ public final class KeywordSearchIngestModule implements IngestModuleAbstractFile private static final Logger logger = Logger.getLogger(KeywordSearchIngestModule.class.getName()); public static final String MODULE_NAME = "Keyword Search"; - public static final String MODULE_DESCRIPTION = "Performs file indexing and periodic search using keywords and regular expressions in lists."; final public static String MODULE_VERSION = "1.0"; - public static final String PROP_SCRIPTS = MODULE_NAME + "_Scripts"; - public static final String PROP_OPTIONS = MODULE_NAME + "_Options"; - public static final String PROP_NSRL = MODULE_NAME + "_NSRL"; + public static final String MODULE_DESCRIPTION = "Performs file indexing and periodic search using keywords and regular expressions in lists."; + final public static String MODULE_VERSION = "1.0"; private String args; private static KeywordSearchIngestModule instance = null; private IngestServices services; @@ -138,15 +136,15 @@ public final class KeywordSearchIngestModule implements IngestModuleAbstractFile private KeywordSearchIngestModule() { //set default script - if(ModuleSettings.getConfigSetting(PROP_OPTIONS, AbstractFileExtract.ExtractOptions.EXTRACT_UTF8.toString()) == null){ + 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(PROP_SCRIPTS, SCRIPT.LATIN_1.name()) == null){ - ModuleSettings.setConfigSetting(PROP_SCRIPTS, SCRIPT.LATIN_1.name(), Boolean.toString(true)); + 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(PROP_OPTIONS, AbstractFileExtract.ExtractOptions.EXTRACT_UTF16.toString()) == null){ + if(ModuleSettings.getConfigSetting(KeywordSearchSettings.PROPERTIES_OPTIONS, AbstractFileExtract.ExtractOptions.EXTRACT_UTF16.toString()) == null){ KeywordSearchSettings.stringExtractOptions.put(AbstractFileExtract.ExtractOptions.EXTRACT_UTF16.toString(), Boolean.TRUE.toString()); } @@ -374,9 +372,9 @@ public final class KeywordSearchIngestModule implements IngestModuleAbstractFile //use the settings files to set values //Grabbing skipKnown - if(! ModuleSettings.getConfigSettings(PROP_NSRL).isEmpty()){ + if(! ModuleSettings.getConfigSettings(KeywordSearchSettings.PROPERTIES_NSRL).isEmpty()){ try{ - KeywordSearchSettings.setSkipKnown(Boolean.parseBoolean(ModuleSettings.getConfigSetting(PROP_NSRL, "SkipKnown"))); + 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); @@ -385,14 +383,14 @@ public final class KeywordSearchIngestModule implements IngestModuleAbstractFile //populating stringExtractOptions - if(! ModuleSettings.getConfigSettings(PROP_OPTIONS).isEmpty()){ - KeywordSearchSettings.stringExtractOptions = ModuleSettings.getConfigSettings(PROP_OPTIONS); + if(! ModuleSettings.getConfigSettings(KeywordSearchSettings.PROPERTIES_OPTIONS).isEmpty()){ + KeywordSearchSettings.stringExtractOptions = ModuleSettings.getConfigSettings(KeywordSearchSettings.PROPERTIES_OPTIONS); } //populating stringExtractScripts - if(! ModuleSettings.getConfigSettings(PROP_SCRIPTS).isEmpty()){ + if(! ModuleSettings.getConfigSettings(KeywordSearchSettings.PROPERTIES_SCRIPTS).isEmpty()){ try{ - for(Map.Entry kvp: ModuleSettings.getConfigSettings(PROP_SCRIPTS).entrySet()){ + 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())); } diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSettings.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSettings.java index f3b86c21da..ae6fd87948 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSettings.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchSettings.java @@ -44,20 +44,36 @@ public class KeywordSearchSettings { + /** + * + * @return IngestModule singleton + */ static KeywordSearchIngestModule getDefault(){ return KeywordSearchIngestModule.getDefault(); } + /** + * + * @return IngestModule's update frequency + */ static UpdateFrequency getUpdateFrequency(){ return KeywordSearchIngestModule.getDefault().getUpdateFrequency(); } + /** + * Sets the ingest module's update frequency. + * @param c Update frequency to set. + */ static void setUpdateFrequency(UpdateFrequency c){ KeywordSearchIngestModule.getDefault().setUpdateFrequency(c); } + /** + * Sets whether or not to skip adding known good files to the search during index. + * @param skip + */ static void setSkipKnown(boolean skip) { ModuleSettings.setConfigSetting(PROPERTIES_NSRL, "SkipKnown", Boolean.toString(skip)); skipKnown = skip; @@ -65,6 +81,10 @@ public class KeywordSearchSettings { + /** + * Sets what scripts to extract during ingest + * @param scripts List of scripts to extract + */ static void setStringExtractScripts(List scripts) { stringExtractScripts.clear(); stringExtractScripts.addAll(scripts); @@ -125,6 +145,10 @@ public class KeywordSearchSettings { } } + /** + * Gets the setting for whether or not this ingest is skipping adding known good files to the index. + * @return skip setting + */ static boolean getSkipKnown() { try{ if(ModuleSettings.getConfigSetting(PROPERTIES_NSRL, "SkipKnown") != null){