19 package org.sleuthkit.autopsy.datasourceprocessors.xry;
21 import com.google.common.collect.Lists;
23 import java.io.IOException;
24 import java.io.UncheckedIOException;
25 import java.nio.file.Files;
26 import java.nio.file.LinkOption;
27 import java.nio.file.Path;
28 import java.nio.file.attribute.BasicFileAttributes;
29 import java.util.Iterator;
30 import java.util.List;
31 import java.util.UUID;
32 import java.util.concurrent.ExecutionException;
33 import java.util.logging.Level;
34 import java.util.stream.Collectors;
35 import java.util.stream.Stream;
36 import javax.swing.JPanel;
37 import javax.swing.SwingWorker;
38 import org.openide.util.NbBundle;
39 import org.openide.util.lookup.ServiceProvider;
40 import org.openide.util.lookup.ServiceProviders;
58 @ServiceProviders(value = {
59 @ServiceProvider(service = DataSourceProcessor.class),
60 @ServiceProvider(service = AutoIngestDataSourceProcessor.class)
66 private static final int XRY_FILES_DEPTH = 1;
75 configPanel = XRYDataSourceProcessorConfigPanel.getInstance();
80 "XRYDataSourceProcessor.dataSourceType=XRY Text Export"
83 return Bundle.XRYDataSourceProcessor_dataSourceType();
99 "XRYDataSourceProcessor.noPathSelected=Please select a folder containing exported XRY text files",
100 "XRYDataSourceProcessor.notReadable=Selected path is not readable",
101 "XRYDataSourceProcessor.notXRYFolder=Selected folder did not contain any XRY text files",
102 "XRYDataSourceProcessor.ioError=I/O error occured trying to test the selected folder",
103 "XRYDataSourceProcessor.childNotReadable=Top level path [ %s ] is not readable",
104 "XRYDataSourceProcessor.notAFolder=The selected path is not a folder"
107 configPanel.clearErrorText();
108 String selectedFilePath = configPanel.getSelectedFilePath();
109 if (selectedFilePath.isEmpty()) {
110 configPanel.setErrorText(Bundle.XRYDataSourceProcessor_noPathSelected());
114 File selectedFile =
new File(selectedFilePath);
115 Path selectedPath = selectedFile.toPath();
118 if (!Files.isReadable(selectedPath)) {
119 configPanel.setErrorText(Bundle.XRYDataSourceProcessor_notReadable());
124 BasicFileAttributes attr = Files.readAttributes(selectedPath,
125 BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
127 if (!attr.isDirectory()) {
128 configPanel.setErrorText(Bundle.XRYDataSourceProcessor_notAFolder());
133 try (Stream<Path> allFiles = Files.walk(selectedPath, XRY_FILES_DEPTH)) {
134 Iterator<Path> allFilesIterator = allFiles.iterator();
135 while (allFilesIterator.hasNext()) {
136 Path currentPath = allFilesIterator.next();
137 if (!Files.isReadable(currentPath)) {
138 Path fileName = currentPath.subpath(currentPath.getNameCount() - 2,
139 currentPath.getNameCount());
140 configPanel.setErrorText(String.format(
141 Bundle.XRYDataSourceProcessor_childNotReadable(),
142 fileName.toString()));
149 if (!XRYFolder.isXRYFolder(selectedPath)) {
150 configPanel.setErrorText(Bundle.XRYDataSourceProcessor_notXRYFolder());
153 }
catch (IOException | UncheckedIOException ex) {
154 configPanel.setErrorText(Bundle.XRYDataSourceProcessor_ioError());
155 logger.log(Level.WARNING,
"[XRY DSP] I/O exception encountered trying to test the XRY folder.", ex);
176 if (XRYFolder.isXRYFolder(dataSourcePath)) {
179 }
catch (IOException ex) {
196 "XRYDataSourceProcessor.noCurrentCase=No case is open."
201 String selectedFilePath = configPanel.getSelectedFilePath();
202 File selectedFile =
new File(selectedFilePath);
203 Path selectedPath = selectedFile.toPath();
206 XRYFolder xryFolder =
new XRYFolder(selectedPath);
209 String uniqueUUID = UUID.randomUUID().toString();
212 callback, fileManager, uniqueUUID);
213 swingWorker.execute();
215 logger.log(Level.WARNING,
"[XRY DSP] No case is currently open.", ex);
217 Lists.newArrayList(Bundle.XRYDataSourceProcessor_noCurrentCase(),
218 ex.getMessage()), Lists.newArrayList());
240 XRYFolder xryFolder =
new XRYFolder(dataSourcePath);
245 callBack, fileManager, deviceId);
246 swingWorker.execute();
248 logger.log(Level.WARNING,
"[XRY DSP] No case is currently open.", ex);
250 Lists.newArrayList(Bundle.XRYDataSourceProcessor_noCurrentCase(),
251 ex.getMessage()), Lists.newArrayList());
257 if (swingWorker != null) {
258 swingWorker.cancel(
true);
265 configPanel.clearSelectedFilePath();
286 this.xryFolder = folder;
287 this.progressMonitor = progressMonitor;
288 this.callback = callback;
289 this.fileManager = fileManager;
290 this.uniqueUUID = uniqueUUID;
295 "XRYDataSourceProcessor.preppingFiles=Preparing to add files to the case database",
296 "XRYDataSourceProcessor.processingFiles=Processing all XRY files..."
299 TskDataException, IOException {
300 progressMonitor.
setProgressText(Bundle.XRYDataSourceProcessor_preppingFiles());
302 List<Path> nonXRYFiles = xryFolder.getNonXRYFiles();
303 List<String> filePaths = nonXRYFiles.stream()
306 .collect(Collectors.toList());
315 progressMonitor.
setProgressText(Bundle.XRYDataSourceProcessor_processingFiles());
316 XRYReportProcessor.process(xryFolder, dataSource);
322 "XRYDataSourceProcessor.unexpectedError=Internal error occurred while processing XRY report"
326 LocalFilesDataSource newDataSource =
get();
328 Lists.newArrayList(), Lists.newArrayList(newDataSource));
329 }
catch (InterruptedException ex) {
330 logger.log(Level.WARNING,
"[XRY DSP] Thread was interrupted while processing the XRY report."
331 +
" The case may or may not have the complete XRY report.", ex);
333 Lists.newArrayList(), Lists.newArrayList());
334 }
catch (ExecutionException ex) {
335 logger.log(Level.SEVERE,
"[XRY DSP] Unexpected internal error while processing XRY report.", ex);
337 Lists.newArrayList(Bundle.XRYDataSourceProcessor_unexpectedError(),
338 ex.toString()), Lists.newArrayList());
351 this.progressMonitor = progressMonitor;
356 "XRYDataSourceProcessor.fileAdded=Added %s to the case database"
359 progressMonitor.
setProgressText(String.format(Bundle.XRYDataSourceProcessor_fileAdded(), newFile.getName()));
FileManager getFileManager()
void setProgressText(String text)
void run(DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)
void fileAdded(AbstractFile newFile)
XRYReportProcessorSwingWorker swingWorker
void setIndeterminate(boolean indeterminate)
final XRYFolder xryFolder
void done(DataSourceProcessorResult result, List< String > errList, List< Content > newDataSources)
final DataSourceProcessorCallback callback
final FileManager fileManager
int canProcess(Path dataSourcePath)
synchronized LocalFilesDataSource addLocalFilesDataSource(String deviceId, String rootVirtualDirectoryName, String timeZone, List< String > localFilePaths, FileAddProgressUpdater progressUpdater)
final XRYDataSourceProcessorConfigPanel configPanel
LocalFilesDataSource doInBackground()
final DataSourceProcessorProgressMonitor progressMonitor
String getDataSourceType()
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
XRYReportProcessorSwingWorker(XRYFolder folder, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback, FileManager fileManager, String uniqueUUID)
void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack)
final DataSourceProcessorProgressMonitor progressMonitor