mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-06 21:00:22 +00:00
Added overwrite flag to PlatformUtil resource file extraction method, use for pipeline config
This commit is contained in:
parent
bd46a5a8f1
commit
e8773786f4
@ -208,11 +208,11 @@ public class PlatformUtil {
|
|||||||
* @throws IOException exception thrown if extract the file failed for IO
|
* @throws IOException exception thrown if extract the file failed for IO
|
||||||
* reasons
|
* reasons
|
||||||
*/
|
*/
|
||||||
public static <T> boolean extractResourceToUserConfigDir(final Class<T> resourceClass, final String resourceFile) throws IOException {
|
public static <T> boolean extractResourceToUserConfigDir(final Class<T> resourceClass, final String resourceFile, boolean overWrite) throws IOException {
|
||||||
final File userDir = new File(getUserConfigDirectory());
|
final File userDir = new File(getUserConfigDirectory());
|
||||||
|
|
||||||
final File resourceFileF = new File(userDir + File.separator + resourceFile);
|
final File resourceFileF = new File(userDir + File.separator + resourceFile);
|
||||||
if (resourceFileF.exists()) {
|
if (resourceFileF.exists() && !overWrite) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ public class XMLUtil {
|
|||||||
*/
|
*/
|
||||||
public static <T> boolean xmlIsValid(DOMSource xmlfile, Class<T> clazz, String schemaFile) {
|
public static <T> boolean xmlIsValid(DOMSource xmlfile, Class<T> clazz, String schemaFile) {
|
||||||
try{
|
try{
|
||||||
PlatformUtil.extractResourceToUserConfigDir(clazz, schemaFile);
|
PlatformUtil.extractResourceToUserConfigDir(clazz, schemaFile, false);
|
||||||
File schemaLoc = new File(PlatformUtil.getUserConfigDirectory() + File.separator + schemaFile);
|
File schemaLoc = new File(PlatformUtil.getUserConfigDirectory() + File.separator + schemaFile);
|
||||||
SchemaFactory schm = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
SchemaFactory schm = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||||
try{
|
try{
|
||||||
|
@ -24,6 +24,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||||
|
import org.sleuthkit.autopsy.coreutils.ModuleSettings;
|
||||||
import org.sleuthkit.autopsy.coreutils.PlatformUtil;
|
import org.sleuthkit.autopsy.coreutils.PlatformUtil;
|
||||||
import org.sleuthkit.autopsy.coreutils.XMLUtil;
|
import org.sleuthkit.autopsy.coreutils.XMLUtil;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
@ -39,12 +40,15 @@ import org.w3c.dom.NodeList;
|
|||||||
final class IngestPipelinesConfiguration {
|
final class IngestPipelinesConfiguration {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(IngestPipelinesConfiguration.class.getName());
|
private static final Logger logger = Logger.getLogger(IngestPipelinesConfiguration.class.getName());
|
||||||
private final static String PIPELINES_CONFIG_FILE = "pipeline_config.xml";
|
private static final String PIPELINE_CONFIG_FILE_VERSION_KEY = "PipelineConfigFileVersion";
|
||||||
private final static String PIPELINES_CONFIG_FILE_XSD = "PipelineConfigSchema.xsd";
|
private static final String PIPELINE_CONFIG_FILE_VERSION_NO_STRING = "1";
|
||||||
|
private static final int PIPELINE_CONFIG_FILE_VERSION_NO = 1;
|
||||||
|
private static final String PIPELINES_CONFIG_FILE = "pipeline_config.xml";
|
||||||
|
private static final String PIPELINES_CONFIG_FILE_XSD = "PipelineConfigSchema.xsd";
|
||||||
private static final String XML_PIPELINE_ELEM = "PIPELINE";
|
private static final String XML_PIPELINE_ELEM = "PIPELINE";
|
||||||
private static final String XML_PIPELINE_TYPE_ATTR = "type";
|
private static final String XML_PIPELINE_TYPE_ATTR = "type";
|
||||||
private final static String DATA_SOURCE_INGEST_PIPELINE_TYPE = "ImageAnalysis";
|
private static final String DATA_SOURCE_INGEST_PIPELINE_TYPE = "ImageAnalysis";
|
||||||
private final static String FILE_INGEST_PIPELINE_TYPE = "FileAnalysis";
|
private static final String FILE_INGEST_PIPELINE_TYPE = "FileAnalysis";
|
||||||
private static final String XML_MODULE_ELEM = "MODULE";
|
private static final String XML_MODULE_ELEM = "MODULE";
|
||||||
private static final String XML_MODULE_CLASS_NAME_ATTR = "location";
|
private static final String XML_MODULE_CLASS_NAME_ATTR = "location";
|
||||||
private static IngestPipelinesConfiguration instance;
|
private static IngestPipelinesConfiguration instance;
|
||||||
@ -73,65 +77,77 @@ final class IngestPipelinesConfiguration {
|
|||||||
|
|
||||||
private void readPipelinesConfigurationFile() {
|
private void readPipelinesConfigurationFile() {
|
||||||
try {
|
try {
|
||||||
PlatformUtil.extractResourceToUserConfigDir(IngestPipelinesConfiguration.class, PIPELINES_CONFIG_FILE);
|
boolean overWrite;
|
||||||
} catch (IOException ex) {
|
if (!ModuleSettings.settingExists(this.getClass().getSimpleName(), PIPELINE_CONFIG_FILE_VERSION_KEY)) {
|
||||||
logger.log(Level.SEVERE, "Error copying default pipeline configuration to user dir", ex);
|
ModuleSettings.setConfigSetting(this.getClass().getSimpleName(), PIPELINE_CONFIG_FILE_VERSION_KEY, PIPELINE_CONFIG_FILE_VERSION_NO_STRING);
|
||||||
return;
|
overWrite = true;
|
||||||
}
|
} else {
|
||||||
|
int versionNumber = Integer.parseInt(ModuleSettings.getConfigSetting(this.getClass().getSimpleName(), PIPELINE_CONFIG_FILE_VERSION_KEY));
|
||||||
String configFilePath = PlatformUtil.getUserConfigDirectory() + File.separator + PIPELINES_CONFIG_FILE;
|
overWrite = versionNumber < PIPELINE_CONFIG_FILE_VERSION_NO;
|
||||||
Document doc = XMLUtil.loadDoc(IngestPipelinesConfiguration.class, configFilePath, PIPELINES_CONFIG_FILE_XSD);
|
// TODO: Migrate user edits
|
||||||
if (doc == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Element rootElement = doc.getDocumentElement();
|
|
||||||
if (rootElement == null) {
|
|
||||||
logger.log(Level.SEVERE, "Invalid pipelines config file");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
NodeList pipelineElements = rootElement.getElementsByTagName(XML_PIPELINE_ELEM);
|
|
||||||
int numPipelines = pipelineElements.getLength();
|
|
||||||
if (numPipelines < 1 || numPipelines > 2) {
|
|
||||||
logger.log(Level.SEVERE, "Invalid pipelines config file");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> pipelineConfig = null;
|
|
||||||
for (int pipelineNum = 0; pipelineNum < numPipelines; ++pipelineNum) {
|
|
||||||
Element pipelineElement = (Element) pipelineElements.item(pipelineNum);
|
|
||||||
String pipelineTypeAttr = pipelineElement.getAttribute(XML_PIPELINE_TYPE_ATTR);
|
|
||||||
if (pipelineTypeAttr != null) {
|
|
||||||
switch (pipelineTypeAttr) {
|
|
||||||
case DATA_SOURCE_INGEST_PIPELINE_TYPE:
|
|
||||||
pipelineConfig = dataSourceIngestPipelineConfig;
|
|
||||||
break;
|
|
||||||
case FILE_INGEST_PIPELINE_TYPE:
|
|
||||||
pipelineConfig = fileIngestPipelineConfig;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
logger.log(Level.SEVERE, "Invalid pipelines config file");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an ordered list of class names. The sequence of class
|
boolean fileCopied = PlatformUtil.extractResourceToUserConfigDir(IngestPipelinesConfiguration.class, PIPELINES_CONFIG_FILE, overWrite);
|
||||||
// names defines the sequence of modules in the pipeline.
|
if (!fileCopied) {
|
||||||
if (pipelineConfig != null) {
|
logger.log(Level.SEVERE, "Failure copying default pipeline configuration to user dir");
|
||||||
NodeList modulesElems = pipelineElement.getElementsByTagName(XML_MODULE_ELEM);
|
}
|
||||||
int numModules = modulesElems.getLength();
|
|
||||||
if (numModules == 0) {
|
String configFilePath = PlatformUtil.getUserConfigDirectory() + File.separator + PIPELINES_CONFIG_FILE;
|
||||||
break;
|
Document doc = XMLUtil.loadDoc(IngestPipelinesConfiguration.class, configFilePath, PIPELINES_CONFIG_FILE_XSD);
|
||||||
|
if (doc == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Element rootElement = doc.getDocumentElement();
|
||||||
|
if (rootElement == null) {
|
||||||
|
logger.log(Level.SEVERE, "Invalid pipelines config file");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeList pipelineElements = rootElement.getElementsByTagName(XML_PIPELINE_ELEM);
|
||||||
|
int numPipelines = pipelineElements.getLength();
|
||||||
|
if (numPipelines < 1 || numPipelines > 2) {
|
||||||
|
logger.log(Level.SEVERE, "Invalid pipelines config file");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> pipelineConfig = null;
|
||||||
|
for (int pipelineNum = 0; pipelineNum < numPipelines; ++pipelineNum) {
|
||||||
|
Element pipelineElement = (Element) pipelineElements.item(pipelineNum);
|
||||||
|
String pipelineTypeAttr = pipelineElement.getAttribute(XML_PIPELINE_TYPE_ATTR);
|
||||||
|
if (pipelineTypeAttr != null) {
|
||||||
|
switch (pipelineTypeAttr) {
|
||||||
|
case DATA_SOURCE_INGEST_PIPELINE_TYPE:
|
||||||
|
pipelineConfig = dataSourceIngestPipelineConfig;
|
||||||
|
break;
|
||||||
|
case FILE_INGEST_PIPELINE_TYPE:
|
||||||
|
pipelineConfig = fileIngestPipelineConfig;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
logger.log(Level.SEVERE, "Invalid pipelines config file");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (int moduleNum = 0; moduleNum < numModules; ++moduleNum) {
|
|
||||||
Element moduleElement = (Element) modulesElems.item(moduleNum);
|
// Create an ordered list of class names. The sequence of class
|
||||||
final String moduleClassName = moduleElement.getAttribute(XML_MODULE_CLASS_NAME_ATTR);
|
// names defines the sequence of modules in the pipeline.
|
||||||
if (moduleClassName != null) {
|
if (pipelineConfig != null) {
|
||||||
pipelineConfig.add(moduleClassName);
|
NodeList modulesElems = pipelineElement.getElementsByTagName(XML_MODULE_ELEM);
|
||||||
|
int numModules = modulesElems.getLength();
|
||||||
|
if (numModules == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (int moduleNum = 0; moduleNum < numModules; ++moduleNum) {
|
||||||
|
Element moduleElement = (Element) modulesElems.item(moduleNum);
|
||||||
|
final String moduleClassName = moduleElement.getAttribute(XML_MODULE_CLASS_NAME_ATTR);
|
||||||
|
if (moduleClassName != null) {
|
||||||
|
pipelineConfig.add(moduleClassName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
logger.log(Level.SEVERE, "Error copying default pipeline configuration to user dir", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ class FileExtMismatchXML {
|
|||||||
this.filePath = filePath;
|
this.filePath = filePath;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
boolean extracted = PlatformUtil.extractResourceToUserConfigDir(FileExtMismatchXML.class, DEFAULT_CONFIG_FILE_NAME);
|
boolean extracted = PlatformUtil.extractResourceToUserConfigDir(FileExtMismatchXML.class, DEFAULT_CONFIG_FILE_NAME, false);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.log(Level.SEVERE, "Error copying default mismatch configuration to user dir ", ex);
|
logger.log(Level.SEVERE, "Error copying default mismatch configuration to user dir ", ex);
|
||||||
}
|
}
|
||||||
|
@ -322,7 +322,7 @@ class SearchEngineURLQueryAnalyzer extends Extract {
|
|||||||
@Override
|
@Override
|
||||||
void init() throws IngestModuleException {
|
void init() throws IngestModuleException {
|
||||||
try {
|
try {
|
||||||
PlatformUtil.extractResourceToUserConfigDir(SearchEngineURLQueryAnalyzer.class, XMLFILE);
|
PlatformUtil.extractResourceToUserConfigDir(SearchEngineURLQueryAnalyzer.class, XMLFILE, false);
|
||||||
init2();
|
init2();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
String message = "Unable to find " + XMLFILE;
|
String message = "Unable to find " + XMLFILE;
|
||||||
|
@ -87,7 +87,7 @@ class UsbDeviceIdMapper {
|
|||||||
*/
|
*/
|
||||||
private void loadDeviceMap() throws FileNotFoundException, IOException {
|
private void loadDeviceMap() throws FileNotFoundException, IOException {
|
||||||
devices = new HashMap<>();
|
devices = new HashMap<>();
|
||||||
PlatformUtil.extractResourceToUserConfigDir(this.getClass(), DataFile);
|
PlatformUtil.extractResourceToUserConfigDir(this.getClass(), DataFile, false);
|
||||||
try (Scanner dat = new Scanner(new FileInputStream(new java.io.File(PlatformUtil.getUserConfigDirectory() + File.separator + "USB_DATA.txt")))) {
|
try (Scanner dat = new Scanner(new FileInputStream(new java.io.File(PlatformUtil.getUserConfigDirectory() + File.separator + "USB_DATA.txt")))) {
|
||||||
/* Syntax of file:
|
/* Syntax of file:
|
||||||
*
|
*
|
||||||
|
@ -100,7 +100,7 @@ class ScalpelCarverIngestModule extends IngestModuleAdapter implements FileInges
|
|||||||
// copy the default config file to the user's home directory if one
|
// copy the default config file to the user's home directory if one
|
||||||
// is not already there
|
// is not already there
|
||||||
try {
|
try {
|
||||||
PlatformUtil.extractResourceToUserConfigDir(this.getClass(), configFileName);
|
PlatformUtil.extractResourceToUserConfigDir(this.getClass(), configFileName, false);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
String message = "Could not obtain the path to the Scalpel configuration file.";
|
String message = "Could not obtain the path to the Scalpel configuration file.";
|
||||||
logger.log(Level.SEVERE, message, ex);
|
logger.log(Level.SEVERE, message, ex);
|
||||||
|
0
git-daemon-export-okay
Normal file
0
git-daemon-export-okay
Normal file
Loading…
x
Reference in New Issue
Block a user