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.Collection;
30 import java.util.Collections;
31 import java.util.HashSet;
32 import java.util.List;
34 import java.util.Objects;
35 import java.util.logging.Level;
36 import org.openide.util.NbBundle;
37 import org.openide.util.io.NbObjectInputStream;
38 import org.openide.util.io.NbObjectOutputStream;
39 import org.python.util.PythonObjectInputStream;
57 private static final CharSequence
PYTHON_CLASS_PROXY_PREFIX =
"org.python.proxies.".subSequence(0,
"org.python.proxies.".length() - 1);
61 private final List<String>
warnings =
new ArrayList<>();
116 this.executionContext = executionContext +
"." + this.ingestType.name();
140 this.executionContext = executionContext +
"." + this.ingestType.name();
142 this.moduleTemplates.addAll(moduleTemplates);
191 public void saveAs(String executionContext) {
204 List<String> warningMessages =
new ArrayList<>(this.
warnings);
205 this.warnings.clear();
206 return warningMessages;
228 if (fileFilter == null) {
240 this.fileFilter = fileIngestFilter;
249 return Collections.unmodifiableList(this.moduleTemplates);
258 this.moduleTemplates.clear();
259 this.moduleTemplates.addAll(moduleTemplates);
268 List<IngestModuleTemplate> enabledModuleTemplates =
new ArrayList<>();
270 if (moduleTemplate.isEnabled()) {
271 enabledModuleTemplates.add(moduleTemplate);
274 return enabledModuleTemplates;
284 boolean processUnallocated =
true;
285 if (!Objects.isNull(
this.fileFilter)) {
288 return processUnallocated;
298 Files.createDirectories(folder);
299 this.moduleSettingsFolderPath = folder.toAbsolutePath().toString();
300 }
catch (IOException | SecurityException ex) {
301 logger.log(Level.SEVERE,
"Failed to create ingest module settings directory " +
this.moduleSettingsFolderPath, ex);
302 this.warnings.add(NbBundle.getMessage(
IngestJobSettings.class,
"IngestJobSettings.createModuleSettingsFolder.warning"));
315 List<IngestModuleFactory> moduleFactories =
new ArrayList<>();
316 List<IngestModuleFactory> allModuleFactories = IngestModuleFactoryLoader.getIngestModuleFactories();
317 HashSet<String> loadedModuleNames =
new HashSet<>();
322 moduleFactories.add(moduleFactory);
324 moduleFactories.add(moduleFactory);
325 }
else if (this.ingestType.equals(
IngestType.
FILES_ONLY) && moduleFactory.isFileIngestModuleFactory()) {
326 moduleFactories.add(moduleFactory);
331 loadedModuleNames.add(moduleFactory.getModuleDisplayName());
344 List<String> missingModuleNames =
new ArrayList<>();
345 for (String moduleName : enabledModuleNames) {
346 if (!loadedModuleNames.contains(moduleName)) {
347 missingModuleNames.add(moduleName);
350 for (String moduleName : disabledModuleNames) {
351 if (!loadedModuleNames.contains(moduleName)) {
352 missingModuleNames.add(moduleName);
355 for (String moduleName : missingModuleNames) {
356 enabledModuleNames.remove(moduleName);
357 disabledModuleNames.remove(moduleName);
358 String warning = NbBundle.getMessage(
IngestJobSettings.class,
"IngestJobSettings.missingModule.warning", moduleName);
359 logger.log(Level.WARNING, warning);
360 this.warnings.add(warning);
370 if (enabledModuleNames.contains(moduleName)) {
372 }
else if (disabledModuleNames.contains(moduleName)) {
379 enabledModuleNames.add(moduleName);
381 this.moduleTemplates.add(moduleTemplate);
401 fileIngestFilters.put(fSet.getName(), fSet);
406 logger.log(Level.SEVERE,
"Failed to get file filter from .properties file, default filter being used", ex);
421 private static HashSet<String>
getModulesNames(String executionContext, String propertyName, String defaultSetting) {
425 HashSet<String> moduleNames =
new HashSet<>();
427 if (!modulesSetting.isEmpty()) {
428 String[] settingNames = modulesSetting.split(
", ");
429 for (String name : settingNames) {
435 case "Thunderbird Parser":
437 moduleNames.add(
"Email Parser");
439 case "File Extension Mismatch Detection":
440 moduleNames.add(
"Extension Mismatch Detector");
444 moduleNames.add(
"E01 Verifier");
446 case "Archive Extractor":
447 moduleNames.add(
"Embedded File Extractor");
450 moduleNames.add(name);
465 static List<String> getEnabledModules(String context) {
466 return new ArrayList<>(
getModulesNames(context, ENABLED_MODULES_PROPERTY,
""));
480 return moduleSettingsFilePath.contains(PYTHON_CLASS_PROXY_PREFIX);
493 File settingsFile =
new File(moduleSettingsFilePath);
494 if (settingsFile.exists()) {
496 try (NbObjectInputStream in =
new NbObjectInputStream(
new FileInputStream(settingsFile.getAbsolutePath()))) {
498 }
catch (IOException | ClassNotFoundException ex) {
500 logger.log(Level.WARNING, warning, ex);
501 this.warnings.add(warning);
516 if (settings == null) {
532 Path path = Paths.get(
this.moduleSettingsFolderPath, fileName);
533 return path.toAbsolutePath().toString();
543 HashSet<String> enabledModuleNames =
new HashSet<>();
544 HashSet<String> disabledModuleNames =
new HashSet<>();
546 saveModuleSettings(moduleTemplate.getModuleFactory(), moduleTemplate.getModuleSettings());
547 String moduleName = moduleTemplate.getModuleName();
548 if (moduleTemplate.isEnabled()) {
549 enabledModuleNames.add(moduleName);
551 disabledModuleNames.add(moduleName);
571 try (NbObjectOutputStream out =
new NbObjectOutputStream(
new FileOutputStream(moduleSettingsFilePath))) {
572 out.writeObject(settings);
573 }
catch (IOException ex) {
575 logger.log(Level.SEVERE, warning, ex);
576 this.warnings.add(warning);
588 private static String
makeCsvList(Collection<String> collection) {
589 if (collection == null || collection.isEmpty()) {
593 ArrayList<String> list =
new ArrayList<>();
594 list.addAll(collection);
595 StringBuilder csvList =
new StringBuilder();
596 for (
int i = 0; i < list.size() - 1; ++i) {
597 csvList.append(list.get(i)).append(
", ");
599 csvList.append(list.get(list.size() - 1));
600 return csvList.toString();
static final String DISABLED_MODULES_PROPERTY
IngestJobSettings(final String executionContext)
static final String LAST_FILE_INGEST_FILTER_PROPERTY
static List< FilesSet > getStandardFileIngestFilters()
static final String ENABLED_MODULES_PROPERTY
void saveModuleSettings(IngestModuleFactory factory, IngestModuleIngestJobSettings settings)
final IngestType ingestType
void setEnabled(boolean enabled)
List< IngestModuleTemplate > getEnabledIngestModuleTemplates()
String moduleSettingsFolderPath
static HashSet< String > getModulesNames(String executionContext, String propertyName, String defaultSetting)
String getExecutionContext()
static synchronized FilesSetsManager getInstance()
IngestModuleIngestJobSettings getDefaultIngestJobSettings()
static final String MODULE_SETTINGS_FILE_EXT
Map< String, FilesSet > getCustomFileIngestFilters()
static String makeCsvList(Collection< String > collection)
static final String MODULE_SETTINGS_FOLDER
void setIngestModuleTemplates(List< IngestModuleTemplate > moduleTemplates)
static final String MODULE_SETTINGS_FOLDER_PATH
final List< IngestModuleTemplate > moduleTemplates
IngestJobSettings(String executionContext, IngestType ingestType, Collection< IngestModuleTemplate > moduleTemplates, FilesSet fileFilter)
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
void setFileFilter(FilesSet fileIngestFilter)
IngestModuleIngestJobSettings loadModuleSettings(IngestModuleFactory factory)
Path getSavedModuleSettingsFolder()
boolean getProcessUnallocatedSpace()
void createSavedModuleSettingsFolder()
static FilesSet getDefaultFilter()
final List< String > warnings
String getModuleSettingsFilePath(IngestModuleFactory factory)
static String getConfigSetting(String moduleName, String settingName)
List< String > getWarnings()
List< IngestModuleTemplate > getIngestModuleTemplates()
static final Logger logger
synchronized static Logger getLogger(String name)
IngestJobSettings(String executionContext, IngestType ingestType, Collection< IngestModuleTemplate > moduleTemplates)
String getModuleDisplayName()
void saveAs(String executionContext)
boolean isPythonModuleSettingsFile(String moduleSettingsFilePath)
boolean ingoresUnallocatedSpace()
static final CharSequence PYTHON_CLASS_PROXY_PREFIX
static boolean settingExists(String moduleName, String settingName)
IngestJobSettings(String executionContext, IngestType ingestType)