19 package org.sleuthkit.autopsy.ingest;
 
   22 import java.io.FileInputStream;
 
   23 import java.io.FileOutputStream;
 
   24 import java.io.IOException;
 
   25 import java.nio.file.Files;
 
   26 import java.nio.file.Path;
 
   27 import java.nio.file.Paths;
 
   28 import java.util.ArrayList;
 
   29 import java.util.Collections;
 
   30 import java.util.HashSet;
 
   31 import java.util.List;
 
   33 import java.util.Objects;
 
   34 import java.util.logging.Level;
 
   35 import org.openide.util.NbBundle;
 
   36 import org.openide.util.io.NbObjectInputStream;
 
   37 import org.openide.util.io.NbObjectOutputStream;
 
   38 import org.python.util.PythonObjectInputStream;
 
   76         if (fileIngestFilter == null) {
 
   88     void setFileIngestFilter(
FilesSet fileIngestFilter) {
 
  122         this.moduleTemplates = 
new ArrayList<>();
 
  123         this.warnings = 
new ArrayList<>();
 
  141             this.executionContext = context;
 
  143             this.executionContext = context + 
"." + this.ingestType.name();
 
  146         this.moduleTemplates = 
new ArrayList<>();
 
  148         this.warnings = 
new ArrayList<>();
 
  167     void saveAs(String executionContext) {
 
  181     String getExecutionContext() {
 
  192         List<String> warningMessages = 
new ArrayList<>(this.
warnings);
 
  193         this.warnings.clear();
 
  194         return warningMessages;
 
  202     List<IngestModuleTemplate> getIngestModuleTemplates() {
 
  203         return Collections.unmodifiableList(this.moduleTemplates);
 
  212     List<IngestModuleTemplate> getEnabledIngestModuleTemplates() {
 
  213         List<IngestModuleTemplate> enabledModuleTemplates = 
new ArrayList<>();
 
  214         for (IngestModuleTemplate moduleTemplate : this.moduleTemplates) {
 
  215             if (moduleTemplate.isEnabled()) {
 
  216                 enabledModuleTemplates.add(moduleTemplate);
 
  219         return enabledModuleTemplates;
 
  227     void setIngestModuleTemplates(List<IngestModuleTemplate> moduleTemplates) {
 
  228         this.moduleTemplates.clear();
 
  229         this.moduleTemplates.addAll(moduleTemplates);
 
  239     boolean getProcessUnallocatedSpace() {
 
  246         boolean processUnallocated = 
true;
 
  247         if (!Objects.isNull(
this.fileIngestFilter)) {
 
  250         return processUnallocated;
 
  281             Files.createDirectories(folder);
 
  282             this.moduleSettingsFolderPath = folder.toAbsolutePath().toString();
 
  283         } 
catch (IOException | SecurityException ex) {
 
  284             LOGGER.log(Level.SEVERE, 
"Failed to create ingest module settings directory " + 
this.moduleSettingsFolderPath, ex); 
 
  285             this.warnings.add(NbBundle.getMessage(
IngestJobSettings.class, 
"IngestJobSettings.createModuleSettingsFolder.warning")); 
 
  297         List<IngestModuleFactory> moduleFactories = 
new ArrayList<>();
 
  298         List<IngestModuleFactory> allModuleFactories = IngestModuleFactoryLoader.getIngestModuleFactories();
 
  299         HashSet<String> loadedModuleNames = 
new HashSet<>();
 
  304                 moduleFactories.add(moduleFactory);
 
  306                 moduleFactories.add(moduleFactory);
 
  307             } 
else if (this.ingestType.equals(
IngestType.
FILES_ONLY) && moduleFactory.isFileIngestModuleFactory()) {
 
  308                 moduleFactories.add(moduleFactory);
 
  313             loadedModuleNames.add(moduleFactory.getModuleDisplayName());
 
  326         List<String> missingModuleNames = 
new ArrayList<>();
 
  327         for (String moduleName : enabledModuleNames) {
 
  328             if (!loadedModuleNames.contains(moduleName)) {
 
  329                 missingModuleNames.add(moduleName);
 
  332         for (String moduleName : disabledModuleNames) {
 
  333             if (!loadedModuleNames.contains(moduleName)) {
 
  334                 missingModuleNames.add(moduleName);
 
  337         for (String moduleName : missingModuleNames) {
 
  338             enabledModuleNames.remove(moduleName);
 
  339             disabledModuleNames.remove(moduleName);
 
  340             String warning = NbBundle.getMessage(
IngestJobSettings.class, 
"IngestJobSettings.missingModule.warning", moduleName); 
 
  341             LOGGER.log(Level.WARNING, warning);
 
  342             this.warnings.add(warning);
 
  350             IngestModuleTemplate moduleTemplate = 
new IngestModuleTemplate(moduleFactory, 
loadModuleSettings(moduleFactory));
 
  351             String moduleName = moduleTemplate.getModuleName();
 
  352             if (enabledModuleNames.contains(moduleName)) {
 
  353                 moduleTemplate.setEnabled(
true);
 
  354             } 
else if (disabledModuleNames.contains(moduleName)) {
 
  355                 moduleTemplate.setEnabled(
false);
 
  360                 moduleTemplate.setEnabled(
true);
 
  361                 enabledModuleNames.add(moduleName);
 
  363             this.moduleTemplates.add(moduleTemplate);
 
  383                 fileIngestFilters.put(fSet.getName(), fSet);
 
  389             LOGGER.log(Level.SEVERE, 
"Failed to get file ingest filter from .properties file, default filter being used", ex); 
 
  408         HashSet<String> moduleNames = 
new HashSet<>();
 
  410         if (!modulesSetting.isEmpty()) {
 
  411             String[] settingNames = modulesSetting.split(
", ");
 
  412             for (String name : settingNames) {
 
  415                     case "Thunderbird Parser": 
 
  417                         moduleNames.add(
"Email Parser"); 
 
  419                     case "File Extension Mismatch Detection": 
 
  420                         moduleNames.add(
"Extension Mismatch Detector"); 
 
  424                         moduleNames.add(
"E01 Verifier"); 
 
  426                     case "Archive Extractor": 
 
  427                         moduleNames.add(
"Embedded File Extractor"); 
 
  430                         moduleNames.add(name);
 
  445     static List<String> getEnabledModules(String context) {
 
  460         return moduleSettingsFilePath.contains(pythonModuleSettingsPrefixCS);
 
  474         File settingsFile = 
new File(moduleSettingsFilePath);
 
  475         if (settingsFile.exists()) {
 
  477                 try (NbObjectInputStream in = 
new NbObjectInputStream(
new FileInputStream(settingsFile.getAbsolutePath()))) {
 
  479                 } 
catch (IOException | ClassNotFoundException ex) {
 
  481                     LOGGER.log(Level.WARNING, warning, ex);
 
  482                     this.warnings.add(warning);
 
  485                 try (PythonObjectInputStream in = 
new PythonObjectInputStream(
new FileInputStream(settingsFile.getAbsolutePath()))) {
 
  487                 } 
catch (IOException | ClassNotFoundException exception) {
 
  489                     LOGGER.log(Level.WARNING, warning, exception);
 
  490                     this.warnings.add(warning);
 
  494         if (settings == null) {
 
  510         Path path = Paths.get(this.moduleSettingsFolderPath, fileName);
 
  511         return path.toAbsolutePath().toString();
 
  521         HashSet<String> enabledModuleNames = 
new HashSet<>();
 
  522         HashSet<String> disabledModuleNames = 
new HashSet<>();
 
  523         for (IngestModuleTemplate moduleTemplate : moduleTemplates) {
 
  524             saveModuleSettings(moduleTemplate.getModuleFactory(), moduleTemplate.getModuleSettings());
 
  525             String moduleName = moduleTemplate.getModuleName();
 
  526             if (moduleTemplate.isEnabled()) {
 
  527                 enabledModuleNames.add(moduleName);
 
  529                 disabledModuleNames.add(moduleName);
 
  549         String moduleSettingsFilePath = Paths.get(this.moduleSettingsFolderPath, FactoryClassNameNormalizer.normalize(factory.getClass().getCanonicalName()) + MODULE_SETTINGS_FILE_EXT).toString();
 
  550         try (NbObjectOutputStream out = 
new NbObjectOutputStream(
new FileOutputStream(moduleSettingsFilePath))) {
 
  551             out.writeObject(settings);
 
  552         } 
catch (IOException ex) {
 
  554             LOGGER.log(Level.SEVERE, warning, ex);
 
  555             this.warnings.add(warning);
 
  568         if (input == null || input.isEmpty()) {
 
  572         ArrayList<String> list = 
new ArrayList<>();
 
  574         StringBuilder csvList = 
new StringBuilder();
 
  575         for (
int i = 0; i < list.size() - 1; ++i) {
 
  576             csvList.append(list.get(i)).append(
", ");
 
  578         csvList.append(list.get(list.size() - 1));
 
  579         return csvList.toString();
 
static final String DISABLED_MODULES_KEY
static List< FilesSet > getStandardFileIngestFilters()
void saveModuleSettings(IngestModuleFactory factory, IngestModuleIngestJobSettings settings)
final IngestType ingestType
static final Logger LOGGER
String moduleSettingsFolderPath
static synchronized FilesSetsManager getInstance()
static String makeCommaSeparatedValuesList(HashSet< String > input)
IngestModuleIngestJobSettings getDefaultIngestJobSettings()
static final String MODULE_SETTINGS_FILE_EXT
Map< String, FilesSet > getCustomFileIngestFilters()
static final String MODULE_SETTINGS_FOLDER
FilesSet fileIngestFilter
static final String MODULE_SETTINGS_FOLDER_PATH
final List< IngestModuleTemplate > moduleTemplates
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
IngestModuleIngestJobSettings loadModuleSettings(IngestModuleFactory factory)
Path getSavedModuleSettingsFolder()
void createSavedModuleSettingsFolder()
static FilesSet getDefaultFilter()
final List< String > warnings
IngestJobSettings(String executionContext)
static HashSet< String > getModulesNamesFromSetting(String context, String key, String defaultSetting)
String getModuleSettingsFilePath(IngestModuleFactory factory)
static String getConfigSetting(String moduleName, String settingName)
List< String > getWarnings()
static final String ENABLED_MODULES_KEY
synchronized static Logger getLogger(String name)
String getModuleDisplayName()
static final String LAST_FILE_INGEST_FILTER_KEY
static final CharSequence pythonModuleSettingsPrefixCS
boolean isPythonModuleSettingsFile(String moduleSettingsFilePath)
boolean ingoresUnallocatedSpace()
static boolean settingExists(String moduleName, String settingName)
IngestJobSettings(String context, IngestType ingestType)