2197 removed copy past code from IngestProfiles

This commit is contained in:
William Schaefer 2017-02-14 12:28:09 -05:00
parent 515b84f5bc
commit 4cefd75345
5 changed files with 58 additions and 102 deletions

View File

@ -57,15 +57,6 @@ public class IngestJobSettings {
private static final String MODULE_SETTINGS_FOLDER_PATH = Paths.get(PlatformUtil.getUserConfigDirectory(), IngestJobSettings.MODULE_SETTINGS_FOLDER).toAbsolutePath().toString(); private static final String MODULE_SETTINGS_FOLDER_PATH = Paths.get(PlatformUtil.getUserConfigDirectory(), IngestJobSettings.MODULE_SETTINGS_FOLDER).toAbsolutePath().toString();
private static final String MODULE_SETTINGS_FILE_EXT = ".settings"; //NON-NLS private static final String MODULE_SETTINGS_FILE_EXT = ".settings"; //NON-NLS
private static final Logger LOGGER = Logger.getLogger(IngestJobSettings.class.getName()); private static final Logger LOGGER = Logger.getLogger(IngestJobSettings.class.getName());
/**
* @return the ENABLED_MODULES_KEY
*/
static String getEnabledModulesKey() {
return ENABLED_MODULES_KEY;
}
private FilesSet fileIngestFilter; private FilesSet fileIngestFilter;
private String executionContext; private String executionContext;
private final IngestType ingestType; private final IngestType ingestType;
@ -75,15 +66,15 @@ public class IngestJobSettings {
private final List<String> warnings; private final List<String> warnings;
/** /**
* Gets the last selected FileIngestFilter saved in settings which is represented * Gets the last selected FileIngestFilter saved in settings which is
* by a FilesSet, if the last selected filter is null * represented by a FilesSet, if the last selected filter is null the
* the default filter will be returned. * default filter will be returned.
* *
* @return FilesSet which represents the FileIngestFilter * @return FilesSet which represents the FileIngestFilter
*/ */
FilesSet getFileIngestFilter() { FilesSet getFileIngestFilter() {
if (fileIngestFilter==null){ if (fileIngestFilter == null) {
fileIngestFilter=FilesSetsManager.getDefaultFilter(); fileIngestFilter = FilesSetsManager.getDefaultFilter();
} }
return fileIngestFilter; return fileIngestFilter;
} }
@ -120,7 +111,7 @@ public class IngestJobSettings {
/** /**
* Constructs an ingest job settings object for a given execution context. * Constructs an ingest job settings object for a given execution context.
* Examples of execution contexts include the add data source wizard and the * Examples of execution contexts include the add data source wizard and the
* run ingest modules dialog. Different execution conterxts may have * run ingest modules dialog. Different execution contexts may have
* different ingest job settings. * different ingest job settings.
* *
* @param executionContext The ingest execution context identifier. * @param executionContext The ingest execution context identifier.
@ -137,7 +128,7 @@ public class IngestJobSettings {
/** /**
* Constructs an ingest job settings object for a given context. Examples of * Constructs an ingest job settings object for a given context. Examples of
* execution contexts include the add data source wizard and the run ingest * execution contexts include the add data source wizard and the run ingest
* modules dialog. Different execution conterxts may have different ingest * modules dialog. Different execution contexts may have different ingest
* job settings. * job settings.
* *
* @param context The context identifier string. * @param context The context identifier string.
@ -167,20 +158,22 @@ public class IngestJobSettings {
} }
/** /**
* Saves the settings with a new context name removing the old profile folder * Saves the settings with a new context name removing the old profile
* * folder
* @param executionContext will be used to name the new folder for storing the settings *
* @param executionContext will be used to name the new folder for storing
* the settings
*/ */
void saveAs(String executionContext) { void saveAs(String executionContext) {
this.executionContext = executionContext; this.executionContext = executionContext;
this.createSavedModuleSettingsFolder(); this.createSavedModuleSettingsFolder();
this.store(); this.store();
} }
/** /**
* Gets the ingest execution context identifier. Examples of execution * Gets the ingest execution context identifier. Examples of execution
* contexts include the add data source wizard and the run ingest modules * contexts include the add data source wizard and the run ingest modules
* dialog. Different execution conterxts may have different ingest job * dialog. Different execution contexts may have different ingest job
* settings. * settings.
* *
* @return The execution context identifier. * @return The execution context identifier.
@ -266,16 +259,18 @@ public class IngestJobSettings {
return Paths.get(IngestJobSettings.MODULE_SETTINGS_FOLDER_PATH, executionContext); return Paths.get(IngestJobSettings.MODULE_SETTINGS_FOLDER_PATH, executionContext);
} }
/** /**
* Returns the path to the ingest module settings folder from a static manner. * Returns the path to the ingest module settings folder from a static
* manner.
* *
* @param context specify the context of the folder you wish to get * @param context specify the context of the folder you wish to get
*
* @return path to the module settings folder * @return path to the module settings folder
*/ */
static Path getSavedModuleSettingsFolder(String context) { static Path getSavedModuleSettingsFolder(String context) {
return Paths.get(IngestJobSettings.MODULE_SETTINGS_FOLDER_PATH, context); return Paths.get(IngestJobSettings.MODULE_SETTINGS_FOLDER_PATH, context);
} }
/** /**
* Creates the folder for saving the individual ingest module settings part * Creates the folder for saving the individual ingest module settings part
* of these ingest job settings. * of these ingest job settings.
@ -322,8 +317,8 @@ public class IngestJobSettings {
* Get the enabled/disabled ingest modules settings for this context. By * Get the enabled/disabled ingest modules settings for this context. By
* default, all loaded modules are enabled. * default, all loaded modules are enabled.
*/ */
HashSet<String> enabledModuleNames = getModulesNamesFromSetting(IngestJobSettings.ENABLED_MODULES_KEY, makeCommaSeparatedValuesList(loadedModuleNames)); HashSet<String> enabledModuleNames = getModulesNamesFromSetting(executionContext, IngestJobSettings.ENABLED_MODULES_KEY, makeCommaSeparatedValuesList(loadedModuleNames));
HashSet<String> disabledModuleNames = getModulesNamesFromSetting(IngestJobSettings.DISABLED_MODULES_KEY, ""); //NON-NLS HashSet<String> disabledModuleNames = getModulesNamesFromSetting(executionContext, IngestJobSettings.DISABLED_MODULES_KEY, ""); //NON-NLS
/** /**
* Check for missing modules and create warnings if any are found. * Check for missing modules and create warnings if any are found.
@ -382,9 +377,9 @@ public class IngestJobSettings {
ModuleSettings.setConfigSetting(this.executionContext, IngestJobSettings.LAST_FILE_INGEST_FILTER_KEY, FilesSetsManager.getDefaultFilter().getName()); ModuleSettings.setConfigSetting(this.executionContext, IngestJobSettings.LAST_FILE_INGEST_FILTER_KEY, FilesSetsManager.getDefaultFilter().getName());
} }
try { try {
Map<String,FilesSet> fileIngestFilters = FilesSetsManager.getInstance() Map<String, FilesSet> fileIngestFilters = FilesSetsManager.getInstance()
.getCustomFileIngestFilters(); .getCustomFileIngestFilters();
for (FilesSet fSet : FilesSetsManager.getStandardFileIngestFilters()){ for (FilesSet fSet : FilesSetsManager.getStandardFileIngestFilters()) {
fileIngestFilters.put(fSet.getName(), fSet); fileIngestFilters.put(fSet.getName(), fSet);
} }
this.fileIngestFilter = fileIngestFilters.get(ModuleSettings.getConfigSetting( this.fileIngestFilter = fileIngestFilters.get(ModuleSettings.getConfigSetting(
@ -403,12 +398,12 @@ public class IngestJobSettings {
* *
* @return The list of module names associated with the key. * @return The list of module names associated with the key.
*/ */
HashSet<String> getModulesNamesFromSetting(String key, String defaultSetting) { static HashSet<String> getModulesNamesFromSetting(String context, String key, String defaultSetting) {
if (ModuleSettings.settingExists(this.executionContext, key) == false) { if (ModuleSettings.settingExists(context, key) == false) {
ModuleSettings.setConfigSetting(this.executionContext, key, defaultSetting); ModuleSettings.setConfigSetting(context, key, defaultSetting);
} }
HashSet<String> moduleNames = new HashSet<>(); HashSet<String> moduleNames = new HashSet<>();
String modulesSetting = ModuleSettings.getConfigSetting(this.executionContext, key); String modulesSetting = ModuleSettings.getConfigSetting(context, key);
if (!modulesSetting.isEmpty()) { if (!modulesSetting.isEmpty()) {
String[] settingNames = modulesSetting.split(", "); String[] settingNames = modulesSetting.split(", ");
for (String name : settingNames) { for (String name : settingNames) {
@ -436,6 +431,13 @@ public class IngestJobSettings {
return moduleNames; return moduleNames;
} }
/**
* @return the ENABLED_MODULES_KEY
*/
static HashSet<String> getEnabledModules(String context, String defaultSetting) {
return getModulesNamesFromSetting(context, ENABLED_MODULES_KEY, defaultSetting);
}
/** /**
* Determines if the moduleSettingsFilePath is that of a serialized jython * Determines if the moduleSettingsFilePath is that of a serialized jython
* instance. Serialized Jython instances (settings saved on the disk) * instance. Serialized Jython instances (settings saved on the disk)

View File

@ -22,20 +22,23 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.HashSet; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.openide.util.Exceptions; import org.openide.util.Exceptions;
import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.ModuleSettings;
import org.sleuthkit.autopsy.coreutils.PlatformUtil; import org.sleuthkit.autopsy.coreutils.PlatformUtil;
public class IngestProfileMap { /**
* Class for managing the access to the
*/
public final class IngestProfiles {
private static final String PROFILE_FOLDER = "IngestProfiles"; private static final String PROFILE_FOLDER = "IngestProfiles";
private static final String PROFILE_NAME_KEY = "Profile_Name"; private static final String PROFILE_NAME_KEY = "Profile_Name";
private static final String PROFILE_DESC_KEY = "Profile_Description"; private static final String PROFILE_DESC_KEY = "Profile_Description";
private static final String PROFILE_FILTER_KEY = "Profile_Filter"; private static final String PROFILE_FILTER_KEY = "Profile_Filter";
private TreeMap<String, IngestProfile> profileMap = null; private Map<String, IngestProfile> profileMap = null;
private static final Object PROFILE_LOCK = new Object(); private static final Object PROFILE_LOCK = new Object();
/** /**
@ -43,7 +46,7 @@ public class IngestProfileMap {
* *
* @return profileList * @return profileList
*/ */
public TreeMap<String, IngestProfile> getIngestProfileMap() { public Map<String, IngestProfile> getIngestProfileMap() {
if (profileMap == null) { if (profileMap == null) {
loadProfileList(); loadProfileList();
} }
@ -93,26 +96,17 @@ public class IngestProfileMap {
* FileIngestFilter. The name can be used to find the ModuleSettings for * FileIngestFilter. The name can be used to find the ModuleSettings for
* this profile. * this profile.
*/ */
public static class IngestProfile { public static final class IngestProfile {
private final String name; private final String name;
private final String description; private final String description;
private final String fileIngestFilter; private final String fileIngestFilter;
/**
* The key for Enabled ingest modules
*
* @return the ENABLED_MODULES_KEY
*/
static String getEnabledModulesKey() {
return IngestJobSettings.getEnabledModulesKey();
}
/** /**
* Creates a new IngestProfile * Creates a new IngestProfile
* *
* @param name - unique name of the profile * @param name - unique name of the profile
* @param desc - optional description of profile * @param desc - optional description of profile
* @param selectedFilter - the File Ingest Filter used for this profile * @param selectedFilter - the File Ingest Filter used for this profile
*/ */
IngestProfile(String name, String desc, String selectedFilter) { IngestProfile(String name, String desc, String selectedFilter) {
@ -197,46 +191,6 @@ public class IngestProfileMap {
} }
} }
/**
* Gets the module names for a given key.
*
* @param key The key string.
*/
HashSet<String> getModuleNames(String key) {
synchronized (PROFILE_LOCK) {
if (ModuleSettings.settingExists(this.getName(), key) == false) {
ModuleSettings.setConfigSetting(this.getName(), key, "");
}
HashSet<String> moduleNames = new HashSet<>();
String modulesSetting = ModuleSettings.getConfigSetting(this.getName(), 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;
case "Archive Extractor": //NON-NLS
moduleNames.add("Embedded File Extractor"); //NON-NLS
break;
default:
moduleNames.add(name);
}
}
}
return moduleNames;
}
}
/** /**
* Save a Ingest profile file in the profile folder. * Save a Ingest profile file in the profile folder.
* *

View File

@ -26,7 +26,7 @@ import java.util.List;
import org.openide.DialogDisplayer; import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor; import org.openide.NotifyDescriptor;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.ingest.IngestProfileMap.IngestProfile; import org.sleuthkit.autopsy.ingest.IngestProfiles.IngestProfile;
/** /**
* Panel to display options for profile creation and editing. * Panel to display options for profile creation and editing.
@ -70,10 +70,10 @@ class ProfilePanel extends IngestModuleGlobalSettingsPanel {
/** /**
* Get the name of the profile. * Get the name of the profile.
* *
* The name will not contain any trailing or leading spaces. * The name will not contain any trailing or leading spaces.
* *
* @return * @return
*/ */
String getProfileName() { String getProfileName() {
return profileNameField.getText().trim(); return profileNameField.getText().trim();
@ -211,8 +211,8 @@ class ProfilePanel extends IngestModuleGlobalSettingsPanel {
DialogDisplayer.getDefault().notify(notifyDesc); DialogDisplayer.getDefault().notify(notifyDesc);
return false; return false;
} }
if (!containsOnlyLegalChars(getProfileName(), ILLEGAL_NAME_CHARS)){ if (!containsOnlyLegalChars(getProfileName(), ILLEGAL_NAME_CHARS)) {
NotifyDescriptor notifyDesc = new NotifyDescriptor.Message( NotifyDescriptor notifyDesc = new NotifyDescriptor.Message(
NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.messages.profileNameContainsIllegalCharacter"), NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.messages.profileNameContainsIllegalCharacter"),
NotifyDescriptor.WARNING_MESSAGE); NotifyDescriptor.WARNING_MESSAGE);
DialogDisplayer.getDefault().notify(notifyDesc); DialogDisplayer.getDefault().notify(notifyDesc);

View File

@ -28,7 +28,7 @@ import org.netbeans.spi.options.OptionsPanelController;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.corecomponents.OptionsPanel; import org.sleuthkit.autopsy.corecomponents.OptionsPanel;
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
import org.sleuthkit.autopsy.ingest.IngestProfileMap.IngestProfile; import org.sleuthkit.autopsy.ingest.IngestProfiles.IngestProfile;
import org.sleuthkit.autopsy.modules.interestingitems.FilesSet; import org.sleuthkit.autopsy.modules.interestingitems.FilesSet;
import org.sleuthkit.autopsy.modules.interestingitems.FilesSetsManager; import org.sleuthkit.autopsy.modules.interestingitems.FilesSetsManager;
@ -49,7 +49,7 @@ class ProfileSettingsPanel extends IngestModuleGlobalSettingsPanel implements Op
}) })
private final DefaultListModel<IngestProfile> profilesListModel; private final DefaultListModel<IngestProfile> profilesListModel;
private TreeMap<String, IngestProfile> profiles; private Map<String, IngestProfile> profiles;
private ProfilePanel panel; private ProfilePanel panel;
private boolean filtersShouldBeRefreshed; private boolean filtersShouldBeRefreshed;
@ -386,7 +386,7 @@ class ProfileSettingsPanel extends IngestModuleGlobalSettingsPanel implements Op
public void load() { public void load() {
int currentIndex = this.profileList.getSelectedIndex(); int currentIndex = this.profileList.getSelectedIndex();
this.profilesListModel.clear(); this.profilesListModel.clear();
this.profiles = new IngestProfileMap().getIngestProfileMap(); this.profiles = (TreeMap<String, IngestProfile>) new IngestProfiles().getIngestProfileMap();
for (IngestProfile profile : this.profiles.values()) { for (IngestProfile profile : this.profiles.values()) {
profilesListModel.addElement(profile); profilesListModel.addElement(profile);
} }
@ -422,7 +422,7 @@ class ProfileSettingsPanel extends IngestModuleGlobalSettingsPanel implements Op
filterDescArea.setText(NbBundle.getMessage(ProfileSettingsPanel.class, "ProfileSettingsPanel.messages.filterLoadFailed")); filterDescArea.setText(NbBundle.getMessage(ProfileSettingsPanel.class, "ProfileSettingsPanel.messages.filterLoadFailed"));
} }
selectedModulesArea.setText(""); selectedModulesArea.setText("");
for (String moduleName : selectedProfile.getModuleNames(IngestProfile.getEnabledModulesKey())) { for (String moduleName : IngestJobSettings.getEnabledModules(selectedProfile.getName(), "")) {
selectedModulesArea.append(moduleName + "\n"); selectedModulesArea.append(moduleName + "\n");
} }

View File

@ -38,8 +38,8 @@ import org.sleuthkit.autopsy.corecomponents.OptionsPanel;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
import org.sleuthkit.autopsy.ingest.IngestModuleGlobalSettingsPanel; import org.sleuthkit.autopsy.ingest.IngestModuleGlobalSettingsPanel;
import org.sleuthkit.autopsy.ingest.IngestProfileMap; import org.sleuthkit.autopsy.ingest.IngestProfiles;
import org.sleuthkit.autopsy.ingest.IngestProfileMap.IngestProfile; import org.sleuthkit.autopsy.ingest.IngestProfiles.IngestProfile;
import org.sleuthkit.autopsy.modules.filetypeid.FileTypeDetector; import org.sleuthkit.autopsy.modules.filetypeid.FileTypeDetector;
/** /**
@ -1003,7 +1003,7 @@ public final class FilesSetDefsPanel extends IngestModuleGlobalSettingsPanel imp
private void deleteSetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteSetButtonActionPerformed private void deleteSetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteSetButtonActionPerformed
FilesSet selectedSet = this.setsList.getSelectedValue(); FilesSet selectedSet = this.setsList.getSelectedValue();
if (panelType == PANEL_TYPE.FILE_INGEST_FILTERS) { if (panelType == PANEL_TYPE.FILE_INGEST_FILTERS) {
for (IngestProfile profile : new IngestProfileMap().getIngestProfileMap().values()) { for (IngestProfile profile : new IngestProfiles().getIngestProfileMap().values()) {
if (profile.getFileIngestFilter().equals(selectedSet.getName())) { if (profile.getFileIngestFilter().equals(selectedSet.getName())) {
MessageNotifyUtil.Message.error(NbBundle.getMessage(this.getClass(), MessageNotifyUtil.Message.error(NbBundle.getMessage(this.getClass(),
"FilesSetDefsPanel.ingest.fileFilterInUseError", "FilesSetDefsPanel.ingest.fileFilterInUseError",