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;
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());
341 final String plasoModuleName =
"Plaso";
342 boolean plasoLoaded = loadedModuleNames.contains(plasoModuleName);
344 loadedModuleNames.remove(plasoModuleName);
356 if (!enabledModuleNames.contains(plasoModuleName) && !disabledModuleNames.contains(plasoModuleName)) {
357 disabledModuleNames.add(plasoModuleName);
362 loadedModuleNames.add(plasoModuleName);
368 List<String> missingModuleNames =
new ArrayList<>();
369 for (String moduleName : enabledModuleNames) {
370 if (!loadedModuleNames.contains(moduleName)) {
371 missingModuleNames.add(moduleName);
374 for (String moduleName : disabledModuleNames) {
375 if (!loadedModuleNames.contains(moduleName)) {
376 missingModuleNames.add(moduleName);
379 for (String moduleName : missingModuleNames) {
380 enabledModuleNames.remove(moduleName);
381 disabledModuleNames.remove(moduleName);
382 String warning = NbBundle.getMessage(
IngestJobSettings.class,
"IngestJobSettings.missingModule.warning", moduleName);
383 logger.log(Level.WARNING, warning);
384 this.warnings.add(warning);
394 if (enabledModuleNames.contains(moduleName)) {
396 }
else if (disabledModuleNames.contains(moduleName)) {
403 enabledModuleNames.add(moduleName);
405 this.moduleTemplates.add(moduleTemplate);
425 fileIngestFilters.put(fSet.getName(), fSet);
430 logger.log(Level.SEVERE,
"Failed to get file filter from .properties file, default filter being used", ex);
445 private static HashSet<String>
getModulesNames(String executionContext, String propertyName, String defaultSetting) {
449 HashSet<String> moduleNames =
new HashSet<>();
451 if (!modulesSetting.isEmpty()) {
452 String[] settingNames = modulesSetting.split(
", ");
453 for (String name : settingNames) {
459 case "Thunderbird Parser":
461 moduleNames.add(
"Email Parser");
463 case "File Extension Mismatch Detection":
464 moduleNames.add(
"Extension Mismatch Detector");
469 moduleNames.add(
"Data Source Integrity");
471 case "Archive Extractor":
472 moduleNames.add(
"Embedded File Extractor");
474 case "Correlation Engine":
475 moduleNames.add(
"Central Repository");
478 moduleNames.add(
"Picture Analyzer");
480 case "Drone Analyzer":
481 moduleNames.add(
"DJI Drone Analyzer");
484 moduleNames.add(name);
499 static List<String> getEnabledModules(String context) {
500 return new ArrayList<>(
getModulesNames(context, ENABLED_MODULES_PROPERTY,
""));
514 return moduleSettingsFilePath.contains(PYTHON_CLASS_PROXY_PREFIX);
527 File settingsFile =
new File(moduleSettingsFilePath);
528 if (settingsFile.exists()) {
529 try (NbObjectInputStream in =
new NbObjectInputStream(
new FileInputStream(settingsFile.getAbsolutePath()))) {
531 }
catch (IOException | ClassNotFoundException ex) {
533 logger.log(Level.WARNING, warning, ex);
534 this.warnings.add(warning);
537 if (settings == null) {
553 Path path = Paths.get(
this.moduleSettingsFolderPath, fileName);
554 return path.toAbsolutePath().toString();
564 HashSet<String> enabledModuleNames =
new HashSet<>();
565 HashSet<String> disabledModuleNames =
new HashSet<>();
567 saveModuleSettings(moduleTemplate.getModuleFactory(), moduleTemplate.getModuleSettings());
568 String moduleName = moduleTemplate.getModuleName();
569 if (moduleTemplate.isEnabled()) {
570 enabledModuleNames.add(moduleName);
572 disabledModuleNames.add(moduleName);
592 try (NbObjectOutputStream out =
new NbObjectOutputStream(
new FileOutputStream(moduleSettingsFilePath))) {
593 out.writeObject(settings);
594 }
catch (IOException ex) {
596 logger.log(Level.SEVERE, warning, ex);
597 this.warnings.add(warning);
609 private static String
makeCsvList(Collection<String> collection) {
610 if (collection == null || collection.isEmpty()) {
614 ArrayList<String> list =
new ArrayList<>();
615 list.addAll(collection);
616 StringBuilder csvList =
new StringBuilder();
617 for (
int i = 0; i < list.size() - 1; ++i) {
618 csvList.append(list.get(i)).append(
", ");
620 csvList.append(list.get(list.size() - 1));
621 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
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)