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;
56 private static final CharSequence
PYTHON_CLASS_PROXY_PREFIX =
"org.python.proxies.".subSequence(0,
"org.python.proxies.".length() - 1);
60 private final List<String>
warnings =
new ArrayList<>();
115 this.executionContext = executionContext +
"." + this.ingestType.name();
139 this.executionContext = executionContext +
"." + this.ingestType.name();
141 this.moduleTemplates.addAll(moduleTemplates);
190 public void saveAs(String executionContext) {
203 List<String> warningMessages =
new ArrayList<>(this.
warnings);
204 this.warnings.clear();
205 return warningMessages;
227 if (fileFilter == null) {
239 this.fileFilter = fileIngestFilter;
248 return Collections.unmodifiableList(this.moduleTemplates);
257 this.moduleTemplates.clear();
258 this.moduleTemplates.addAll(moduleTemplates);
267 List<IngestModuleTemplate> enabledModuleTemplates =
new ArrayList<>();
269 if (moduleTemplate.isEnabled()) {
270 enabledModuleTemplates.add(moduleTemplate);
273 return enabledModuleTemplates;
283 boolean processUnallocated =
true;
284 if (!Objects.isNull(
this.fileFilter)) {
287 return processUnallocated;
297 Files.createDirectories(folder);
298 this.moduleSettingsFolderPath = folder.toAbsolutePath().toString();
299 }
catch (IOException | SecurityException ex) {
300 logger.log(Level.SEVERE,
"Failed to create ingest module settings directory " +
this.moduleSettingsFolderPath, ex);
301 this.warnings.add(NbBundle.getMessage(
IngestJobSettings.class,
"IngestJobSettings.createModuleSettingsFolder.warning"));
314 List<IngestModuleFactory> moduleFactories =
new ArrayList<>();
315 List<IngestModuleFactory> allModuleFactories = IngestModuleFactoryLoader.getIngestModuleFactories();
316 HashSet<String> loadedModuleNames =
new HashSet<>();
321 moduleFactories.add(moduleFactory);
323 moduleFactories.add(moduleFactory);
324 }
else if (this.ingestType.equals(
IngestType.
FILES_ONLY) && moduleFactory.isFileIngestModuleFactory()) {
325 moduleFactories.add(moduleFactory);
330 loadedModuleNames.add(moduleFactory.getModuleDisplayName());
343 List<String> missingModuleNames =
new ArrayList<>();
344 for (String moduleName : enabledModuleNames) {
345 if (!loadedModuleNames.contains(moduleName)) {
346 missingModuleNames.add(moduleName);
349 for (String moduleName : disabledModuleNames) {
350 if (!loadedModuleNames.contains(moduleName)) {
351 missingModuleNames.add(moduleName);
354 for (String moduleName : missingModuleNames) {
355 enabledModuleNames.remove(moduleName);
356 disabledModuleNames.remove(moduleName);
357 String warning = NbBundle.getMessage(
IngestJobSettings.class,
"IngestJobSettings.missingModule.warning", moduleName);
358 logger.log(Level.WARNING, warning);
359 this.warnings.add(warning);
369 if (enabledModuleNames.contains(moduleName)) {
371 }
else if (disabledModuleNames.contains(moduleName)) {
378 enabledModuleNames.add(moduleName);
380 this.moduleTemplates.add(moduleTemplate);
400 fileIngestFilters.put(fSet.getName(), fSet);
405 logger.log(Level.SEVERE,
"Failed to get file filter from .properties file, default filter being used", ex);
420 private static HashSet<String>
getModulesNames(String executionContext, String propertyName, String defaultSetting) {
424 HashSet<String> moduleNames =
new HashSet<>();
426 if (!modulesSetting.isEmpty()) {
427 String[] settingNames = modulesSetting.split(
", ");
428 for (String name : settingNames) {
434 case "Thunderbird Parser":
436 moduleNames.add(
"Email Parser");
438 case "File Extension Mismatch Detection":
439 moduleNames.add(
"Extension Mismatch Detector");
444 moduleNames.add(
"Data Source Integrity");
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()) {
495 try (NbObjectInputStream in =
new NbObjectInputStream(
new FileInputStream(settingsFile.getAbsolutePath()))) {
497 }
catch (IOException | ClassNotFoundException ex) {
499 logger.log(Level.WARNING, warning, ex);
500 this.warnings.add(warning);
503 if (settings == null) {
519 Path path = Paths.get(
this.moduleSettingsFolderPath, fileName);
520 return path.toAbsolutePath().toString();
530 HashSet<String> enabledModuleNames =
new HashSet<>();
531 HashSet<String> disabledModuleNames =
new HashSet<>();
533 saveModuleSettings(moduleTemplate.getModuleFactory(), moduleTemplate.getModuleSettings());
534 String moduleName = moduleTemplate.getModuleName();
535 if (moduleTemplate.isEnabled()) {
536 enabledModuleNames.add(moduleName);
538 disabledModuleNames.add(moduleName);
558 try (NbObjectOutputStream out =
new NbObjectOutputStream(
new FileOutputStream(moduleSettingsFilePath))) {
559 out.writeObject(settings);
560 }
catch (IOException ex) {
562 logger.log(Level.SEVERE, warning, ex);
563 this.warnings.add(warning);
575 private static String
makeCsvList(Collection<String> collection) {
576 if (collection == null || collection.isEmpty()) {
580 ArrayList<String> list =
new ArrayList<>();
581 list.addAll(collection);
582 StringBuilder csvList =
new StringBuilder();
583 for (
int i = 0; i < list.size() - 1; ++i) {
584 csvList.append(list.get(i)).append(
", ");
586 csvList.append(list.get(list.size() - 1));
587 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)