mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-15 09:17:42 +00:00
Complete first draft of ingest job config refactor
This commit is contained in:
parent
5be063e85a
commit
0adee48f25
@ -64,7 +64,7 @@ IngestManager.StartIngestJobsTask.run.startupErr.dlgErrorList=\nErrors\: \n{0}
|
||||
IngestManager.StartIngestJobsTask.run.startupErr.dlgTitle=Ingest Failure
|
||||
IngestJobConfigurator.createModuleSettingsFolderForContext.exception.msg=Failed to create ingest module settings folder, cannot save settings.
|
||||
IngestJobConfigurator.createModuleSettingsFolderForContext.exception.title=Ingest Job Initialization Failure
|
||||
IngestJobConfigurator.saveJobSettings.usermsg=Failed to save ingest job settings for {0} module.
|
||||
IngestJobConfiguration.saveJobSettings.errmsg=Failed to save ingest job settings for {0} module.
|
||||
IngestJobConfigurator.saveJobSettings.usermsg.title=Ingest Job Settings
|
||||
IngestJobConfigurationPanel.descriptionLabel.text=
|
||||
IngestProgressSnapshotDialog.title.text=Ingest Progress Snapshot
|
||||
|
@ -59,7 +59,7 @@ IngestManager.StartIngestJobsTask.run.startupErr.dlgSolution=\u5931\u6557\u3057\
|
||||
IngestManager.StartIngestJobsTask.run.startupErr.dlgTitle=\u30a4\u30f3\u30b8\u30a7\u30b9\u30c8\u5931\u6557
|
||||
IngestJobConfigurator.createModuleSettingsFolderForContext.exception.msg=\u30a4\u30f3\u30b8\u30a7\u30b9\u30c8\u30e2\u30b8\u30e5\u30fc\u30eb\u8a2d\u5b9a\u30d5\u30a9\u30eb\u30c0\u306e\u4f5c\u6210\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002\u8a2d\u5b9a\u3092\u4fdd\u5b58\u3067\u304d\u307e\u305b\u3093\u3002
|
||||
IngestJobConfigurator.createModuleSettingsFolderForContext.exception.title=\u30a4\u30f3\u30b8\u30a7\u30b9\u30c8\u30b8\u30e7\u30d6\u521d\u671f\u5316\u306e\u5931\u6557
|
||||
IngestJobConfigurator.saveJobSettings.usermsg={0}\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30a4\u30f3\u30b8\u30a7\u30b9\u30c8\u30b8\u30e7\u30d6\u8a2d\u5b9a\u306e\u4fdd\u5b58\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002
|
||||
IngestJobConfiguration.saveJobSettings.errmsg={0}\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30a4\u30f3\u30b8\u30a7\u30b9\u30c8\u30b8\u30e7\u30d6\u8a2d\u5b9a\u306e\u4fdd\u5b58\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002
|
||||
IngestJobConfigurator.saveJobSettings.usermsg.title=\u30a4\u30f3\u30b8\u30a7\u30b9\u30c8\u30b8\u30e7\u30d6\u8a2d\u5b9a
|
||||
IngestJob.progress.dataSourceIngest.initialDisplayName={0}\u3092\u89e3\u6790\u4e2d
|
||||
IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.dataSource=\u30c7\u30fc\u30bf\u30bd\u30fc\u30b9
|
||||
|
@ -0,0 +1,378 @@
|
||||
/*
|
||||
* Autopsy Forensic Browser
|
||||
*
|
||||
* Copyright 2014 Basis Technology Corp.
|
||||
* Contact: carrier <at> sleuthkit <dot> org
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.sleuthkit.autopsy.ingest;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import org.openide.util.NbBundle;
|
||||
import org.openide.util.io.NbObjectInputStream;
|
||||
import org.openide.util.io.NbObjectOutputStream;
|
||||
import org.sleuthkit.autopsy.coreutils.ModuleSettings;
|
||||
import org.sleuthkit.autopsy.coreutils.PlatformUtil;
|
||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||
|
||||
/**
|
||||
* The ingest job configuration for a particular context.
|
||||
*/
|
||||
public class IngestJobConfiguration {
|
||||
|
||||
private static final String ENABLED_INGEST_MODULES_KEY = "Enabled_Ingest_Modules"; //NON-NLS
|
||||
private static final String DISABLED_INGEST_MODULES_KEY = "Disabled_Ingest_Modules"; //NON-NLS
|
||||
private static final String PARSE_UNALLOC_SPACE_KEY = "Process_Unallocated_Space"; //NON-NLS
|
||||
private static final String MODULE_SETTINGS_FOLDER = "IngestModuleSettings"; //NON-NLS
|
||||
private static final String MODULE_SETTINGS_FOLDER_PATH = Paths.get(PlatformUtil.getUserConfigDirectory(), IngestJobConfiguration.MODULE_SETTINGS_FOLDER).toAbsolutePath().toString();
|
||||
private static final String MODULE_SETTINGS_FILE_EXT = ".settings"; //NON-NLS
|
||||
private static final Logger logger = Logger.getLogger(IngestJobConfiguration.class.getName());
|
||||
private final String context;
|
||||
private String moduleSettingsFolderForContext;
|
||||
private final List<IngestModuleTemplate> moduleTemplates;
|
||||
private boolean processUnallocatedSpace;
|
||||
|
||||
/**
|
||||
* A collection of warning and error messages generated by an ingest job
|
||||
* configuration operation.
|
||||
*/
|
||||
public static class Messages { // RJCTODO: Improve name
|
||||
|
||||
private final List<String> errors;
|
||||
private final List<String> warnings;
|
||||
|
||||
Messages() {
|
||||
this.errors = new ArrayList<>();
|
||||
this.warnings = new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<String> getWarningMessages() {
|
||||
return Collections.unmodifiableList(this.warnings);
|
||||
}
|
||||
|
||||
public List<String> getErrorMessages() {
|
||||
return Collections.unmodifiableList(this.errors);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an empty ingest job configuration for a context.
|
||||
*
|
||||
* @param context The context identifier string.
|
||||
*/
|
||||
public IngestJobConfiguration(String context) {
|
||||
this.context = context;
|
||||
this.moduleTemplates = new ArrayList<>();
|
||||
this.processUnallocatedSpace = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the last saved configuration into memory, using a default
|
||||
* configuration if a saved configuration does not exist.
|
||||
*
|
||||
* @return RJCTODO
|
||||
*/
|
||||
public Messages load() {
|
||||
Messages messages = new Messages();
|
||||
this.read(messages);
|
||||
return messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves this ingest job configuration.
|
||||
*
|
||||
* @return RJCTODO
|
||||
*/
|
||||
public Messages save() {
|
||||
Messages messages = new Messages();
|
||||
this.write(messages);
|
||||
return messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* RJCTODO
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<IngestModuleTemplate> getIngestModuleTemplates() {
|
||||
return Collections.unmodifiableList(this.moduleTemplates);
|
||||
}
|
||||
|
||||
/**
|
||||
* RJCTODO
|
||||
* @param moduleTemplates
|
||||
*/
|
||||
void setIngestModuleTemplates(List<IngestModuleTemplate> moduleTemplates) {
|
||||
this.moduleTemplates.clear();
|
||||
this.moduleTemplates.addAll(moduleTemplates);
|
||||
}
|
||||
|
||||
/**
|
||||
* RJCTODO
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean shouldProcessUnallocatedSpace() {
|
||||
return this.processUnallocatedSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* RJCTODO
|
||||
* @param processUnallocatedSpace
|
||||
*/
|
||||
void setProcessUnallocatedSpace(boolean processUnallocatedSpace) {
|
||||
this.processUnallocatedSpace = processUnallocatedSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* RJCTODO
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private void read(Messages messages) {
|
||||
|
||||
// createModuleSettingsFolderForContext
|
||||
try {
|
||||
Path folder = Paths.get(IngestJobConfiguration.MODULE_SETTINGS_FOLDER_PATH, context);
|
||||
Files.createDirectories(folder);
|
||||
this.moduleSettingsFolderForContext = folder.toAbsolutePath().toString();
|
||||
} catch (Exception ex) {
|
||||
// RJCTODO:
|
||||
return;
|
||||
// logger.log(Level.SEVERE, "Failed to create ingest module settings directory", ex); //NON-NLS
|
||||
// JOptionPane.showMessageDialog(null,
|
||||
// NbBundle.getMessage(this.getClass(),
|
||||
// "IngestJobConfigurator.createModuleSettingsFolderForContext.exception.msg"),
|
||||
// NbBundle.getMessage(this.getClass(),
|
||||
// "IngestJobConfigurator.createModuleSettingsFolderForContext.exception.title"),
|
||||
// JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
// Get the ingest module factories discovered by the ingest module
|
||||
// loader.
|
||||
List<IngestModuleFactory> moduleFactories = IngestModuleFactoryLoader.getIngestModuleFactories();
|
||||
HashSet<String> loadedModuleNames = new HashSet<>();
|
||||
for (IngestModuleFactory moduleFactory : moduleFactories) {
|
||||
loadedModuleNames.add(moduleFactory.getModuleDisplayName());
|
||||
}
|
||||
|
||||
// Get the enabled and disabled ingest modules settings for the current
|
||||
// context. Observe that the default settings make all loaded ingest
|
||||
// modules enabled.
|
||||
HashSet<String> enabledModuleNames = getModulesNamesFromSetting(IngestJobConfiguration.ENABLED_INGEST_MODULES_KEY, makeCommaSeparatedList(loadedModuleNames));
|
||||
HashSet<String> disabledModuleNames = getModulesNamesFromSetting(IngestJobConfiguration.DISABLED_INGEST_MODULES_KEY, "");
|
||||
|
||||
// Check for missing modules.
|
||||
List<String> missingModuleNames = new ArrayList<>();
|
||||
for (String moduleName : enabledModuleNames) {
|
||||
if (!loadedModuleNames.contains(moduleName)) {
|
||||
missingModuleNames.add(moduleName);
|
||||
}
|
||||
}
|
||||
for (String moduleName : disabledModuleNames) {
|
||||
if (!loadedModuleNames.contains(moduleName)) {
|
||||
missingModuleNames.add(moduleName);
|
||||
}
|
||||
}
|
||||
for (String moduleName : missingModuleNames) {
|
||||
enabledModuleNames.remove(moduleName);
|
||||
disabledModuleNames.remove(moduleName);
|
||||
messages.warnings.add(String.format("Previously loaded %s module could not be found", moduleName)); //NON-NLS
|
||||
}
|
||||
|
||||
// Create ingest module templates.
|
||||
for (IngestModuleFactory moduleFactory : moduleFactories) {
|
||||
IngestModuleTemplate moduleTemplate = new IngestModuleTemplate(moduleFactory, loadJobSettings(moduleFactory));
|
||||
String moduleName = moduleTemplate.getModuleName();
|
||||
if (enabledModuleNames.contains(moduleName)) {
|
||||
moduleTemplate.setEnabled(true);
|
||||
} else if (disabledModuleNames.contains(moduleName)) {
|
||||
moduleTemplate.setEnabled(false);
|
||||
} else {
|
||||
// The module factory was loaded, but the module name does not
|
||||
// appear in the enabled/disabled module settings. Treat the
|
||||
// module as a new module and enable it by default.
|
||||
moduleTemplate.setEnabled(true);
|
||||
enabledModuleNames.add(moduleName);
|
||||
}
|
||||
this.moduleTemplates.add(moduleTemplate);
|
||||
}
|
||||
|
||||
// Update the enabled/disabled ingest module settings to reflect any
|
||||
// missing modules or newly discovered modules.
|
||||
ModuleSettings.setConfigSetting(this.context, ENABLED_INGEST_MODULES_KEY, makeCommaSeparatedList(enabledModuleNames));
|
||||
ModuleSettings.setConfigSetting(this.context, DISABLED_INGEST_MODULES_KEY, makeCommaSeparatedList(disabledModuleNames));
|
||||
|
||||
// Get the process unallocated space flag setting. If the setting does
|
||||
// not exist yet, default it to true.
|
||||
if (ModuleSettings.settingExists(this.context, PARSE_UNALLOC_SPACE_KEY) == false) {
|
||||
ModuleSettings.setConfigSetting(this.context, PARSE_UNALLOC_SPACE_KEY, "true"); //NON-NLS
|
||||
}
|
||||
this.processUnallocatedSpace = Boolean.parseBoolean(ModuleSettings.getConfigSetting(this.context, PARSE_UNALLOC_SPACE_KEY));
|
||||
}
|
||||
|
||||
/**
|
||||
* RJCTODO
|
||||
*
|
||||
* @param key
|
||||
* @param defaultSetting
|
||||
* @return
|
||||
*/
|
||||
private HashSet<String> getModulesNamesFromSetting(String key, String defaultSetting) {
|
||||
// Get the ingest modules setting from the user's config file.
|
||||
// If there is no such setting yet, create the default setting.
|
||||
if (ModuleSettings.settingExists(this.context, key) == false) {
|
||||
ModuleSettings.setConfigSetting(this.context, key, defaultSetting);
|
||||
}
|
||||
HashSet<String> moduleNames = new HashSet<>();
|
||||
String modulesSetting = ModuleSettings.getConfigSetting(this.context, key);
|
||||
if (!modulesSetting.isEmpty()) {
|
||||
String[] settingNames = modulesSetting.split(", ");
|
||||
for (String name : settingNames) {
|
||||
// Map some old core module names to the current core module names.
|
||||
switch (name) {
|
||||
case "Thunderbird Parser": //NON-NLS
|
||||
case "MBox Parser": //NON-NLS
|
||||
moduleNames.add("Email Parser"); //NON-NLS
|
||||
break;
|
||||
case "File Extension Mismatch Detection": //NON-NLS
|
||||
moduleNames.add("Extension Mismatch Detector"); //NON-NLS
|
||||
break;
|
||||
case "EWF Verify": //NON-NLS
|
||||
case "E01 Verify": //NON-NLS
|
||||
moduleNames.add("E01 Verifier"); //NON-NLS
|
||||
break;
|
||||
default:
|
||||
moduleNames.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
return moduleNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* RJCTODO
|
||||
*
|
||||
* @param factory
|
||||
* @return
|
||||
*/
|
||||
private IngestModuleIngestJobSettings loadJobSettings(IngestModuleFactory factory) {
|
||||
IngestModuleIngestJobSettings settings = null;
|
||||
File settingsFile = new File(getModuleSettingsFilePath(factory));
|
||||
if (settingsFile.exists()) {
|
||||
try (NbObjectInputStream in = new NbObjectInputStream(new FileInputStream(settingsFile.getAbsolutePath()))) {
|
||||
settings = (IngestModuleIngestJobSettings) in.readObject();
|
||||
} catch (IOException | ClassNotFoundException ex) {
|
||||
String logMessage = String.format("Error loading ingest job settings for %s module for %s context, using defaults", factory.getModuleDisplayName(), this.context); //NON-NLS
|
||||
// logger.log(Level.WARNING, logMessage, ex); RJCTODO
|
||||
}
|
||||
}
|
||||
if (settings == null) {
|
||||
settings = factory.getDefaultIngestJobSettings();
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* RJCTODO
|
||||
* @param factory
|
||||
* @return
|
||||
*/
|
||||
private String getModuleSettingsFilePath(IngestModuleFactory factory) {
|
||||
StringBuilder filePath = new StringBuilder(this.moduleSettingsFolderForContext);
|
||||
filePath.append(File.separator);
|
||||
filePath.append(factory.getClass().getCanonicalName());
|
||||
filePath.append(MODULE_SETTINGS_FILE_EXT);
|
||||
return filePath.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* RJCTODO
|
||||
* @param messages
|
||||
*/
|
||||
private void write(Messages messages) {
|
||||
// Save the enabled/disabled ingest module settings for the current context.
|
||||
HashSet<String> enabledModuleNames = new HashSet<>();
|
||||
HashSet<String> disabledModuleNames = new HashSet<>();
|
||||
for (IngestModuleTemplate moduleTemplate : moduleTemplates) {
|
||||
saveModuleSettings(moduleTemplate.getModuleFactory(), moduleTemplate.getModuleSettings(), messages);
|
||||
String moduleName = moduleTemplate.getModuleName();
|
||||
if (moduleTemplate.isEnabled()) {
|
||||
enabledModuleNames.add(moduleName);
|
||||
} else {
|
||||
disabledModuleNames.add(moduleName);
|
||||
}
|
||||
}
|
||||
ModuleSettings.setConfigSetting(this.context, ENABLED_INGEST_MODULES_KEY, makeCommaSeparatedList(enabledModuleNames));
|
||||
ModuleSettings.setConfigSetting(this.context, DISABLED_INGEST_MODULES_KEY, makeCommaSeparatedList(disabledModuleNames));
|
||||
|
||||
// Save the process unallocated space setting for the current context.
|
||||
String processUnalloc = Boolean.toString(this.processUnallocatedSpace);
|
||||
ModuleSettings.setConfigSetting(this.context, PARSE_UNALLOC_SPACE_KEY, processUnalloc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the ingest job settings for an ingest module for this context.
|
||||
*
|
||||
* @param factory The ingest module factory for the ingest module.
|
||||
* @param settings The ingest job settings for the ingest module
|
||||
* @param messages A collection of error and warning messages to receive any
|
||||
* error messages generated.
|
||||
*/
|
||||
private void saveModuleSettings(IngestModuleFactory factory, IngestModuleIngestJobSettings settings, Messages messages) {
|
||||
try {
|
||||
try (NbObjectOutputStream out = new NbObjectOutputStream(new FileOutputStream(getModuleSettingsFilePath(factory)))) {
|
||||
out.writeObject(settings);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
logger.log(Level.SEVERE, String.format("Error saving ingest job settings for %s ingest module for %s context", factory.getModuleDisplayName(), this.context), ex); //NON-NLS
|
||||
messages.errors.add(NbBundle.getMessage(this.getClass(), "IngestJobConfiguration.saveJobSettings.errmsg", factory.getModuleDisplayName()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* RJCTODO: Consider making this a generally available utility; there might
|
||||
* be a cleaner impl in Core Java 2
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
private static String makeCommaSeparatedList(HashSet<String> input) {
|
||||
if (input == null || input.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.addAll(input);
|
||||
StringBuilder csvList = new StringBuilder();
|
||||
for (int i = 0; i < list.size() - 1; ++i) {
|
||||
csvList.append(list.get(i)).append(", ");
|
||||
}
|
||||
csvList.append(list.get(list.size() - 1));
|
||||
return csvList.toString();
|
||||
}
|
||||
|
||||
}
|
@ -40,20 +40,25 @@ import org.sleuthkit.autopsy.corecomponents.AdvancedConfigurationDialog;
|
||||
*/
|
||||
class IngestJobConfigurationPanel extends javax.swing.JPanel {
|
||||
|
||||
private List<IngestModuleModel> modules = new ArrayList<>();
|
||||
private boolean processUnallocatedSpace = false;
|
||||
private IngestModuleModel selectedModule = null;
|
||||
private final IngestJobConfiguration config;
|
||||
private final List<IngestModuleModel> modules;
|
||||
private IngestModuleModel selectedModule;
|
||||
|
||||
IngestJobConfigurationPanel(List<IngestModuleTemplate> moduleTemplates, boolean processUnallocatedSpace) {
|
||||
for (IngestModuleTemplate moduleTemplate : moduleTemplates) {
|
||||
modules.add(new IngestModuleModel(moduleTemplate));
|
||||
IngestJobConfigurationPanel(IngestJobConfiguration config) {
|
||||
this.config = config;
|
||||
this.modules = new ArrayList<>();
|
||||
for (IngestModuleTemplate moduleTemplate : config.getIngestModuleTemplates()) {
|
||||
this.modules.add(new IngestModuleModel(moduleTemplate));
|
||||
}
|
||||
this.processUnallocatedSpace = processUnallocatedSpace;
|
||||
initComponents();
|
||||
customizeComponents();
|
||||
}
|
||||
|
||||
List<IngestModuleTemplate> getIngestModuleTemplates() {
|
||||
/**
|
||||
* RJCTODO
|
||||
* @return
|
||||
*/
|
||||
IngestJobConfiguration getConfig() {
|
||||
List<IngestModuleTemplate> moduleTemplates = new ArrayList<>();
|
||||
for (IngestModuleModel module : modules) {
|
||||
IngestModuleTemplate moduleTemplate = module.getIngestModuleTemplate();
|
||||
@ -63,11 +68,8 @@ class IngestJobConfigurationPanel extends javax.swing.JPanel {
|
||||
}
|
||||
moduleTemplates.add(moduleTemplate);
|
||||
}
|
||||
return moduleTemplates;
|
||||
}
|
||||
|
||||
boolean getProcessUnallocSpace() {
|
||||
return processUnallocCheckbox.isSelected();
|
||||
this.config.setIngestModuleTemplates(moduleTemplates);
|
||||
return this.config;
|
||||
}
|
||||
|
||||
private void customizeComponents() {
|
||||
@ -113,7 +115,7 @@ class IngestJobConfigurationPanel extends javax.swing.JPanel {
|
||||
}
|
||||
});
|
||||
|
||||
processUnallocCheckbox.setSelected(processUnallocatedSpace);
|
||||
processUnallocCheckbox.setSelected(this.config.shouldProcessUnallocatedSpace());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -261,7 +263,7 @@ class IngestJobConfigurationPanel extends javax.swing.JPanel {
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void processUnallocCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_processUnallocCheckboxActionPerformed
|
||||
processUnallocatedSpace = processUnallocCheckbox.isSelected();
|
||||
this.config.setProcessUnallocatedSpace(processUnallocCheckbox.isSelected());
|
||||
}//GEN-LAST:event_processUnallocCheckboxActionPerformed
|
||||
|
||||
private void advancedButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_advancedButtonActionPerformed
|
||||
|
@ -18,216 +18,37 @@
|
||||
*/
|
||||
package org.sleuthkit.autopsy.ingest;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.openide.util.NbBundle;
|
||||
import org.openide.util.io.NbObjectInputStream;
|
||||
import org.openide.util.io.NbObjectOutputStream;
|
||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||
import org.sleuthkit.autopsy.coreutils.ModuleSettings;
|
||||
import org.sleuthkit.autopsy.coreutils.PlatformUtil;
|
||||
import org.sleuthkit.datamodel.Content;
|
||||
|
||||
/**
|
||||
* Provides a mechanism for creating and persisting an ingest job configuration
|
||||
* for a particular context and for launching ingest jobs that process one or
|
||||
* more data sources using the ingest job configuration.
|
||||
*
|
||||
* @deprecated Use the IngestModuleConfiguration and IngestJobConfigurationPanel
|
||||
* and IngestManager.startIngestJob() or IngestManager.startIngestJobNoUI() instead. // RJCTODO
|
||||
*/
|
||||
@Deprecated
|
||||
public final class IngestJobConfigurator {
|
||||
|
||||
private static final String ENABLED_INGEST_MODULES_KEY = "Enabled_Ingest_Modules"; //NON-NLS
|
||||
private static final String DISABLED_INGEST_MODULES_KEY = "Disabled_Ingest_Modules"; //NON-NLS
|
||||
private static final String PARSE_UNALLOC_SPACE_KEY = "Process_Unallocated_Space"; //NON-NLS
|
||||
private static final String MODULE_SETTINGS_FOLDER_PATH = new StringBuilder(PlatformUtil.getUserConfigDirectory()).append(File.separator).append("IngestModuleSettings").toString(); //NON-NLS
|
||||
private static final String MODULE_SETTINGS_FILE_EXT = ".settings"; //NON-NLS
|
||||
private static final Logger logger = Logger.getLogger(IngestJobConfigurator.class.getName());
|
||||
private final String launcherContext;
|
||||
private String moduleSettingsFolderForContext = null;
|
||||
private final List<String> warnings = new ArrayList<>();
|
||||
private IngestJobConfigurationPanel ingestConfigPanel = null;
|
||||
private final IngestJobConfiguration config;
|
||||
private final IngestJobConfigurationPanel ingestConfigPanel;
|
||||
private IngestJobConfiguration.Messages messages;
|
||||
|
||||
/**
|
||||
* Constructs an ingest job launcher that creates and persists an ingest job
|
||||
* configuration for a particular context and launches ingest jobs that
|
||||
* process one or more data sources using the ingest job configuration.
|
||||
*
|
||||
* @param launcherContext The context identifier.
|
||||
* @param context The context identifier.
|
||||
*/
|
||||
public IngestJobConfigurator(String launcherContext) {
|
||||
this.launcherContext = launcherContext;
|
||||
|
||||
createModuleSettingsFolderForContext();
|
||||
|
||||
// Get the ingest module factories discovered by the ingest module
|
||||
// loader.
|
||||
List<IngestModuleFactory> moduleFactories = IngestModuleFactoryLoader.getIngestModuleFactories();
|
||||
HashSet<String> loadedModuleNames = new HashSet<>();
|
||||
for (IngestModuleFactory moduleFactory : moduleFactories) {
|
||||
loadedModuleNames.add(moduleFactory.getModuleDisplayName());
|
||||
}
|
||||
|
||||
// Get the enabled and disabled ingest modules settings for the current
|
||||
// context. Observe that the default settings make all loaded ingest
|
||||
// modules enabled.
|
||||
HashSet<String> enabledModuleNames = getModulesNamesFromSetting(ENABLED_INGEST_MODULES_KEY, makeCommaSeparatedList(loadedModuleNames));
|
||||
HashSet<String> disabledModuleNames = getModulesNamesFromSetting(DISABLED_INGEST_MODULES_KEY, "");
|
||||
|
||||
// Check for missing modules.
|
||||
List<String> missingModuleNames = new ArrayList<>();
|
||||
for (String moduleName : enabledModuleNames) {
|
||||
if (!loadedModuleNames.contains(moduleName)) {
|
||||
missingModuleNames.add(moduleName);
|
||||
}
|
||||
}
|
||||
for (String moduleName : disabledModuleNames) {
|
||||
if (!loadedModuleNames.contains(moduleName)) {
|
||||
missingModuleNames.add(moduleName);
|
||||
}
|
||||
}
|
||||
for (String moduleName : missingModuleNames) {
|
||||
enabledModuleNames.remove(moduleName);
|
||||
disabledModuleNames.remove(moduleName);
|
||||
warnings.add(String.format("Previously loaded %s module could not be found", moduleName)); //NON-NLS
|
||||
}
|
||||
|
||||
// Create ingest module templates.
|
||||
List<IngestModuleTemplate> moduleTemplates = new ArrayList<>();
|
||||
for (IngestModuleFactory moduleFactory : moduleFactories) {
|
||||
IngestModuleTemplate moduleTemplate = new IngestModuleTemplate(moduleFactory, loadJobSettings(moduleFactory));
|
||||
String moduleName = moduleTemplate.getModuleName();
|
||||
if (enabledModuleNames.contains(moduleName)) {
|
||||
moduleTemplate.setEnabled(true);
|
||||
} else if (disabledModuleNames.contains(moduleName)) {
|
||||
moduleTemplate.setEnabled(false);
|
||||
} else {
|
||||
// The module factory was loaded, but the module name does not
|
||||
// appear in the enabled/disabled module settings. Treat the
|
||||
// module as a new module and enable it by default.
|
||||
moduleTemplate.setEnabled(true);
|
||||
enabledModuleNames.add(moduleName);
|
||||
}
|
||||
moduleTemplates.add(moduleTemplate);
|
||||
}
|
||||
|
||||
// Update the enabled/disabled ingest module settings to reflect any
|
||||
// missing modules or newly discovered modules.
|
||||
ModuleSettings.setConfigSetting(launcherContext, ENABLED_INGEST_MODULES_KEY, makeCommaSeparatedList(enabledModuleNames));
|
||||
ModuleSettings.setConfigSetting(launcherContext, DISABLED_INGEST_MODULES_KEY, makeCommaSeparatedList(disabledModuleNames));
|
||||
|
||||
// Get the process unallocated space flag setting. If the setting does
|
||||
// not exist yet, default it to true.
|
||||
if (ModuleSettings.settingExists(launcherContext, PARSE_UNALLOC_SPACE_KEY) == false) {
|
||||
ModuleSettings.setConfigSetting(launcherContext, PARSE_UNALLOC_SPACE_KEY, "true"); //NON-NLS
|
||||
}
|
||||
boolean processUnallocatedSpace = Boolean.parseBoolean(ModuleSettings.getConfigSetting(launcherContext, PARSE_UNALLOC_SPACE_KEY));
|
||||
|
||||
// Make the configuration panel for the context.
|
||||
ingestConfigPanel = new IngestJobConfigurationPanel(moduleTemplates, processUnallocatedSpace);
|
||||
}
|
||||
|
||||
private void createModuleSettingsFolderForContext() {
|
||||
try {
|
||||
StringBuilder folderPath = new StringBuilder(MODULE_SETTINGS_FOLDER_PATH);
|
||||
folderPath.append(File.separator);
|
||||
folderPath.append(launcherContext);
|
||||
folderPath.append(File.separator);
|
||||
File folder = new File(folderPath.toString());
|
||||
if (!folder.exists()) {
|
||||
Files.createDirectories(folder.toPath());
|
||||
}
|
||||
moduleSettingsFolderForContext = folder.getAbsolutePath();
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, "Failed to create ingest module settings directory", ex); //NON-NLS
|
||||
JOptionPane.showMessageDialog(null,
|
||||
NbBundle.getMessage(this.getClass(),
|
||||
"IngestJobConfigurator.createModuleSettingsFolderForContext.exception.msg"),
|
||||
NbBundle.getMessage(this.getClass(),
|
||||
"IngestJobConfigurator.createModuleSettingsFolderForContext.exception.title"),
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
private HashSet<String> getModulesNamesFromSetting(String key, String defaultSetting) {
|
||||
// Get the ingest modules setting from the user's config file.
|
||||
// If there is no such setting yet, create the default setting.
|
||||
if (ModuleSettings.settingExists(launcherContext, key) == false) {
|
||||
ModuleSettings.setConfigSetting(launcherContext, key, defaultSetting);
|
||||
}
|
||||
HashSet<String> moduleNames = new HashSet<>();
|
||||
String modulesSetting = ModuleSettings.getConfigSetting(launcherContext, key);
|
||||
if (!modulesSetting.isEmpty()) {
|
||||
String[] settingNames = modulesSetting.split(", ");
|
||||
for (String name : settingNames) {
|
||||
// Map some old core module names to the current core module names.
|
||||
switch (name) {
|
||||
case "Thunderbird Parser": //NON-NLS
|
||||
case "MBox Parser": //NON-NLS
|
||||
moduleNames.add("Email Parser"); //NON-NLS
|
||||
break;
|
||||
case "File Extension Mismatch Detection": //NON-NLS
|
||||
moduleNames.add("Extension Mismatch Detector"); //NON-NLS
|
||||
break;
|
||||
case "EWF Verify": //NON-NLS
|
||||
case "E01 Verify": //NON-NLS
|
||||
moduleNames.add("E01 Verifier"); //NON-NLS
|
||||
break;
|
||||
default:
|
||||
moduleNames.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
return moduleNames;
|
||||
}
|
||||
|
||||
private IngestModuleIngestJobSettings loadJobSettings(IngestModuleFactory factory) {
|
||||
IngestModuleIngestJobSettings settings = null;
|
||||
File settingsFile = new File(getModuleSettingsFilePath(factory));
|
||||
if (settingsFile.exists()) {
|
||||
try (NbObjectInputStream in = new NbObjectInputStream(new FileInputStream(settingsFile.getAbsolutePath()))) {
|
||||
settings = (IngestModuleIngestJobSettings) in.readObject();
|
||||
} catch (IOException | ClassNotFoundException ex) {
|
||||
String logMessage = String.format("Error loading ingest job settings for %s module for %s context, using defaults", factory.getModuleDisplayName(), launcherContext); //NON-NLS
|
||||
logger.log(Level.WARNING, logMessage, ex);
|
||||
}
|
||||
}
|
||||
if (settings == null) {
|
||||
settings = factory.getDefaultIngestJobSettings();
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
private void saveJobSettings(IngestModuleFactory factory, IngestModuleIngestJobSettings settings) {
|
||||
try {
|
||||
try (NbObjectOutputStream out = new NbObjectOutputStream(new FileOutputStream(getModuleSettingsFilePath(factory)))) {
|
||||
out.writeObject(settings);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
String logMessage = String.format("Error saving ingest job settings for %s module for %s context", factory.getModuleDisplayName(), launcherContext); //NON-NLS
|
||||
logger.log(Level.SEVERE, logMessage, ex);
|
||||
String userMessage = NbBundle.getMessage(this.getClass(), "IngestJobConfigurator.saveJobSettings.usermsg", factory.getModuleDisplayName());
|
||||
JOptionPane.showMessageDialog(null, userMessage,
|
||||
NbBundle.getMessage(this.getClass(),
|
||||
"IngestJobConfigurator.saveJobSettings.usermsg.title"),
|
||||
JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
private String getModuleSettingsFilePath(IngestModuleFactory factory) {
|
||||
StringBuilder filePath = new StringBuilder(this.moduleSettingsFolderForContext);
|
||||
filePath.append(File.separator);
|
||||
filePath.append(factory.getClass().getCanonicalName());
|
||||
filePath.append(MODULE_SETTINGS_FILE_EXT);
|
||||
return filePath.toString();
|
||||
@Deprecated
|
||||
public IngestJobConfigurator(String context) {
|
||||
this.config = new IngestJobConfiguration(context);
|
||||
this.ingestConfigPanel = new IngestJobConfigurationPanel(config);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -236,7 +57,11 @@ public final class IngestJobConfigurator {
|
||||
*
|
||||
* @return A collection of warning messages.
|
||||
*/
|
||||
@Deprecated
|
||||
public List<String> getIngestJobConfigWarnings() {
|
||||
List<String> warnings = new ArrayList<>();
|
||||
warnings.addAll(this.messages.getWarningMessages());
|
||||
warnings.addAll(this.messages.getErrorMessages());
|
||||
return warnings;
|
||||
}
|
||||
|
||||
@ -247,6 +72,7 @@ public final class IngestJobConfigurator {
|
||||
* @return A JPanel with components that can be used to create an ingest job
|
||||
* configuration.
|
||||
*/
|
||||
@Deprecated
|
||||
public JPanel getIngestJobConfigPanel() {
|
||||
return ingestConfigPanel;
|
||||
}
|
||||
@ -254,42 +80,9 @@ public final class IngestJobConfigurator {
|
||||
/**
|
||||
* Persists the ingest job configuration for the specified context.
|
||||
*/
|
||||
@Deprecated
|
||||
public void saveIngestJobConfig() {
|
||||
List<IngestModuleTemplate> moduleTemplates = ingestConfigPanel.getIngestModuleTemplates();
|
||||
|
||||
// Save the enabled/disabled ingest module settings for the current context.
|
||||
HashSet<String> enabledModuleNames = new HashSet<>();
|
||||
HashSet<String> disabledModuleNames = new HashSet<>();
|
||||
for (IngestModuleTemplate moduleTemplate : moduleTemplates) {
|
||||
saveJobSettings(moduleTemplate.getModuleFactory(), moduleTemplate.getModuleSettings());
|
||||
String moduleName = moduleTemplate.getModuleName();
|
||||
if (moduleTemplate.isEnabled()) {
|
||||
enabledModuleNames.add(moduleName);
|
||||
} else {
|
||||
disabledModuleNames.add(moduleName);
|
||||
}
|
||||
}
|
||||
ModuleSettings.setConfigSetting(launcherContext, ENABLED_INGEST_MODULES_KEY, makeCommaSeparatedList(enabledModuleNames));
|
||||
ModuleSettings.setConfigSetting(launcherContext, DISABLED_INGEST_MODULES_KEY, makeCommaSeparatedList(disabledModuleNames));
|
||||
|
||||
// Save the process unallocated space setting for the current context.
|
||||
String processUnalloc = Boolean.toString(ingestConfigPanel.getProcessUnallocSpace());
|
||||
ModuleSettings.setConfigSetting(launcherContext, PARSE_UNALLOC_SPACE_KEY, processUnalloc);
|
||||
}
|
||||
|
||||
private static String makeCommaSeparatedList(HashSet<String> input) {
|
||||
if (input == null || input.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.addAll(input);
|
||||
StringBuilder csvList = new StringBuilder();
|
||||
for (int i = 0; i < list.size() - 1; ++i) {
|
||||
csvList.append(list.get(i)).append(", ");
|
||||
}
|
||||
csvList.append(list.get(list.size() - 1));
|
||||
return csvList.toString();
|
||||
this.messages = this.config.save();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -298,10 +91,11 @@ public final class IngestJobConfigurator {
|
||||
*
|
||||
* @param dataSources The data sources to ingest.
|
||||
*/
|
||||
@Deprecated
|
||||
public void startIngestJobs(List<Content> dataSources) {
|
||||
// Filter out the disabled ingest module templates.
|
||||
List<IngestModuleTemplate> enabledModuleTemplates = new ArrayList<>();
|
||||
List<IngestModuleTemplate> moduleTemplates = ingestConfigPanel.getIngestModuleTemplates();
|
||||
List<IngestModuleTemplate> moduleTemplates = this.config.getIngestModuleTemplates();
|
||||
for (IngestModuleTemplate moduleTemplate : moduleTemplates) {
|
||||
if (moduleTemplate.isEnabled()) {
|
||||
enabledModuleTemplates.add(moduleTemplate);
|
||||
@ -309,7 +103,7 @@ public final class IngestJobConfigurator {
|
||||
}
|
||||
|
||||
if ((!enabledModuleTemplates.isEmpty()) && (dataSources != null) && (!dataSources.isEmpty())) {
|
||||
IngestManager.getInstance().startIngestJobs(dataSources, enabledModuleTemplates, ingestConfigPanel.getProcessUnallocSpace());
|
||||
IngestManager.getInstance().startIngestJobs(dataSources, enabledModuleTemplates, this.config.shouldProcessUnallocatedSpace());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user