19 package org.sleuthkit.autopsy.ingest;
21 import java.io.IOException;
22 import java.nio.file.Path;
23 import java.nio.file.Paths;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.logging.Level;
30 import org.w3c.dom.Document;
31 import org.w3c.dom.Element;
32 import org.w3c.dom.NodeList;
38 final class IngestPipelinesConfiguration {
40 private static final Logger logger = Logger.getLogger(IngestPipelinesConfiguration.class.getName());
41 private static final String PIPELINES_CONFIG_FILE =
"PipelineConfig.xml";
42 private static final String PIPELINE_ELEM =
"PIPELINE";
43 private static final int NUMBER_OF_PIPELINE_DEFINITIONS = 3;
44 private static final String PIPELINE_TYPE_ATTR =
"type";
45 private static final String STAGE_ONE_DATA_SOURCE_INGEST_PIPELINE_ELEM =
"ImageAnalysisStageOne";
46 private static final String STAGE_TWO_DATA_SOURCE_INGEST_PIPELINE_ELEM =
"ImageAnalysisStageTwo";
47 private static final String FILE_INGEST_PIPELINE_ELEM =
"FileAnalysis";
48 private static final String INGEST_MODULE_ELEM =
"MODULE";
50 private static IngestPipelinesConfiguration instance;
52 private final List<String> stageOneDataSourceIngestPipelineConfig =
new ArrayList<>();
53 private final List<String> fileIngestPipelineConfig =
new ArrayList<>();
54 private final List<String> stageTwoDataSourceIngestPipelineConfig =
new ArrayList<>();
61 synchronized static IngestPipelinesConfiguration getInstance() {
62 if (instance == null) {
63 Logger.getLogger(IngestPipelinesConfiguration.class.getName()).log(Level.INFO,
"Creating ingest module loader instance");
64 instance =
new IngestPipelinesConfiguration();
73 private IngestPipelinesConfiguration() {
74 this.readPipelinesConfigurationFile();
83 List<String> getStageOneDataSourceIngestPipelineConfig() {
84 return new ArrayList<>(stageOneDataSourceIngestPipelineConfig);
93 List<String> getFileIngestPipelineConfig() {
94 return new ArrayList<>(fileIngestPipelineConfig);
103 List<String> getStageTwoDataSourceIngestPipelineConfig() {
104 return new ArrayList<>(stageTwoDataSourceIngestPipelineConfig);
110 private void readPipelinesConfigurationFile() {
112 PlatformUtil.extractResourceToUserConfigDir(IngestPipelinesConfiguration.class, PIPELINES_CONFIG_FILE,
false);
114 Path configFilePath = Paths.get(PlatformUtil.getUserConfigDirectory(), PIPELINES_CONFIG_FILE);
115 Document doc = XMLUtil.loadDoc(IngestPipelinesConfiguration.class, configFilePath.toAbsolutePath().toString());
121 Element rootElement = doc.getDocumentElement();
122 if (null == rootElement) {
123 logger.log(Level.SEVERE,
"Invalid pipelines config file");
129 NodeList pipelineElements = rootElement.getElementsByTagName(IngestPipelinesConfiguration.PIPELINE_ELEM);
130 int numPipelines = pipelineElements.getLength();
131 if (numPipelines != IngestPipelinesConfiguration.NUMBER_OF_PIPELINE_DEFINITIONS) {
132 logger.log(Level.SEVERE,
"Invalid pipelines config file");
138 List<String> pipelineConfig = null;
139 for (
int pipelineNum = 0; pipelineNum < numPipelines; ++pipelineNum) {
140 Element pipelineElement = (Element) pipelineElements.item(pipelineNum);
141 String pipelineTypeAttr = pipelineElement.getAttribute(PIPELINE_TYPE_ATTR);
142 if (null != pipelineTypeAttr) {
143 switch (pipelineTypeAttr) {
144 case STAGE_ONE_DATA_SOURCE_INGEST_PIPELINE_ELEM:
145 pipelineConfig = this.stageOneDataSourceIngestPipelineConfig;
147 case FILE_INGEST_PIPELINE_ELEM:
148 pipelineConfig = this.fileIngestPipelineConfig;
150 case STAGE_TWO_DATA_SOURCE_INGEST_PIPELINE_ELEM:
151 pipelineConfig = this.stageTwoDataSourceIngestPipelineConfig;
154 logger.log(Level.SEVERE,
"Invalid pipelines config file");
161 if (pipelineConfig != null) {
162 NodeList modulesElems = pipelineElement.getElementsByTagName(INGEST_MODULE_ELEM);
163 int numModules = modulesElems.getLength();
164 for (
int moduleNum = 0; moduleNum < numModules; ++moduleNum) {
165 Element moduleElement = (Element) modulesElems.item(moduleNum);
166 String className = moduleElement.getTextContent();
167 if (null != className && !className.isEmpty()) {
168 pipelineConfig.add(className);
173 }
catch (IOException ex) {
174 logger.log(Level.SEVERE,
"Error copying default pipeline configuration to user dir", ex);