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.text.MessageFormat;
29 import java.util.ArrayList;
30 import java.util.Collection;
31 import java.util.Collections;
32 import java.util.HashSet;
33 import java.util.List;
35 import java.util.Objects;
36 import java.util.logging.Level;
37 import org.openide.util.NbBundle;
38 import org.openide.util.io.NbObjectInputStream;
39 import org.openide.util.io.NbObjectOutputStream;
65 ).toAbsolutePath().toString();
68 private static final CharSequence
PYTHON_CLASS_PROXY_PREFIX =
"org.python.proxies.".subSequence(0,
"org.python.proxies.".length() - 1);
72 private final List<String>
warnings =
new ArrayList<>();
80 static String getBaseSettingsPath() {
92 static String getModuleSettingsResource(String executionContext) {
93 return Paths.get(MODULE_SETTINGS_FOLDER, executionContext).toString();
109 return Paths.get(getBaseSettingsPath(), executionContext);
146 this.executionContext = executionContext +
"." + this.ingestType.name();
170 this.executionContext = executionContext +
"." + this.ingestType.name();
172 this.moduleTemplates.addAll(moduleTemplates);
221 public void saveAs(String executionContext) {
234 List<String> warningMessages =
new ArrayList<>(this.
warnings);
235 this.warnings.clear();
236 return warningMessages;
258 if (fileFilter == null) {
270 this.fileFilter = fileIngestFilter;
279 return Collections.unmodifiableList(this.moduleTemplates);
288 this.moduleTemplates.clear();
289 this.moduleTemplates.addAll(moduleTemplates);
298 List<IngestModuleTemplate> enabledModuleTemplates =
new ArrayList<>();
300 if (moduleTemplate.isEnabled()) {
301 enabledModuleTemplates.add(moduleTemplate);
304 return enabledModuleTemplates;
314 boolean processUnallocated =
true;
315 if (!Objects.isNull(
this.fileFilter)) {
318 return processUnallocated;
328 Files.createDirectories(folder);
329 this.moduleSettingsFolderPath = folder.toAbsolutePath().toString();
330 }
catch (IOException | SecurityException ex) {
331 logger.log(Level.SEVERE,
"Failed to create ingest module settings directory " +
this.moduleSettingsFolderPath, ex);
332 this.warnings.add(NbBundle.getMessage(
IngestJobSettings.class,
"IngestJobSettings.createModuleSettingsFolder.warning"));
345 List<IngestModuleFactory> moduleFactories =
new ArrayList<>();
346 List<IngestModuleFactory> allModuleFactories = IngestModuleFactoryLoader.getIngestModuleFactories();
347 HashSet<String> loadedModuleNames =
new HashSet<>();
351 if (moduleFactory.isDataArtifactIngestModuleFactory() || ingestType.equals(
IngestType.
ALL_MODULES)) {
352 moduleFactories.add(moduleFactory);
354 moduleFactories.add(moduleFactory);
355 }
else if (this.ingestType.equals(
IngestType.
FILES_ONLY) && moduleFactory.isFileIngestModuleFactory()) {
356 moduleFactories.add(moduleFactory);
361 loadedModuleNames.add(moduleFactory.getModuleDisplayName());
371 final String plasoModuleName =
"Plaso";
372 boolean plasoLoaded = loadedModuleNames.contains(plasoModuleName);
374 loadedModuleNames.remove(plasoModuleName);
386 if (!enabledModuleNames.contains(plasoModuleName) && !disabledModuleNames.contains(plasoModuleName)) {
387 disabledModuleNames.add(plasoModuleName);
392 loadedModuleNames.add(plasoModuleName);
398 List<String> missingModuleNames =
new ArrayList<>();
399 for (String moduleName : enabledModuleNames) {
400 if (!loadedModuleNames.contains(moduleName)) {
401 missingModuleNames.add(moduleName);
404 for (String moduleName : disabledModuleNames) {
405 if (!loadedModuleNames.contains(moduleName)) {
406 logger.log(Level.WARNING, MessageFormat.format(
"A module marked as disabled in the ingest job settings, ''{0}'', could not be found.", moduleName));
409 for (String moduleName : missingModuleNames) {
410 enabledModuleNames.remove(moduleName);
411 disabledModuleNames.remove(moduleName);
412 String warning = NbBundle.getMessage(
IngestJobSettings.class,
"IngestJobSettings.missingModule.warning", moduleName);
413 logger.log(Level.WARNING, warning);
414 this.warnings.add(warning);
424 if (enabledModuleNames.contains(moduleName)) {
426 }
else if (disabledModuleNames.contains(moduleName)) {
433 enabledModuleNames.add(moduleName);
435 this.moduleTemplates.add(moduleTemplate);
442 String ingestModuleResource = getModuleSettingsResource(this.executionContext);
456 fileIngestFilters.put(fSet.getName(), fSet);
461 logger.log(Level.SEVERE,
"Failed to get file filter from .properties file, default filter being used", ex);
476 private static HashSet<String>
getModulesNames(String executionContext, String propertyName, String defaultSetting) {
477 String ingestModuleResource = getModuleSettingsResource(executionContext);
481 HashSet<String> moduleNames =
new HashSet<>();
483 if (!modulesSetting.isEmpty()) {
484 String[] settingNames = modulesSetting.split(
", ");
485 for (String name : settingNames) {
491 case "Thunderbird Parser":
493 moduleNames.add(
"Email Parser");
495 case "File Extension Mismatch Detection":
496 moduleNames.add(
"Extension Mismatch Detector");
501 moduleNames.add(
"Data Source Integrity");
503 case "Archive Extractor":
504 moduleNames.add(
"Embedded File Extractor");
506 case "Correlation Engine":
507 moduleNames.add(
"Central Repository");
510 moduleNames.add(
"Picture Analyzer");
512 case "Drone Analyzer":
513 moduleNames.add(
"DJI Drone Analyzer");
516 moduleNames.add(name);
531 static List<String> getEnabledModules(String context) {
532 return new ArrayList<>(
getModulesNames(context, ENABLED_MODULES_PROPERTY,
""));
546 return moduleSettingsFilePath.contains(PYTHON_CLASS_PROXY_PREFIX);
559 File settingsFile =
new File(moduleSettingsFilePath);
560 if (settingsFile.exists()) {
561 try (NbObjectInputStream in =
new NbObjectInputStream(
new FileInputStream(settingsFile.getAbsolutePath()))) {
563 }
catch (IOException | ClassNotFoundException ex) {
565 logger.log(Level.WARNING, warning, ex);
566 this.warnings.add(warning);
569 if (settings == null) {
585 Path path = Paths.get(
this.moduleSettingsFolderPath, fileName);
586 return path.toAbsolutePath().toString();
596 HashSet<String> enabledModuleNames =
new HashSet<>();
597 HashSet<String> disabledModuleNames =
new HashSet<>();
599 saveModuleSettings(moduleTemplate.getModuleFactory(), moduleTemplate.getModuleSettings());
600 String moduleName = moduleTemplate.getModuleName();
601 if (moduleTemplate.isEnabled()) {
602 enabledModuleNames.add(moduleName);
604 disabledModuleNames.add(moduleName);
608 String ingestModuleResource = getModuleSettingsResource(this.executionContext);
626 try (NbObjectOutputStream out =
new NbObjectOutputStream(
new FileOutputStream(moduleSettingsFilePath))) {
627 out.writeObject(settings);
628 }
catch (IOException ex) {
630 logger.log(Level.SEVERE, warning, ex);
631 this.warnings.add(warning);
643 private static String
makeCsvList(Collection<String> collection) {
644 if (collection == null || collection.isEmpty()) {
648 ArrayList<String> list =
new ArrayList<>();
649 list.addAll(collection);
650 StringBuilder csvList =
new StringBuilder();
651 for (
int i = 0; i < list.size() - 1; ++i) {
652 csvList.append(list.get(i)).append(
", ");
654 csvList.append(list.get(list.size() - 1));
655 return csvList.toString();
static synchronized String getConfigSetting(String moduleName, String settingName)
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()
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 synchronized boolean settingExists(String moduleName, String settingName)
static final String MODULE_SETTINGS_FOLDER_PATH
final List< IngestModuleTemplate > moduleTemplates
static final String MODULE_SETTINGS_FOLDER_NAME
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)
List< String > getWarnings()
default IngestModuleIngestJobSettings getDefaultIngestJobSettings()
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
IngestJobSettings(String executionContext, IngestType ingestType)
static String normalize(String canonicalClassName)