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;
 
   60 @ServiceProviders(value = {
 
   61     @ServiceProvider(service = DataSourceProcessor.class),
 
   62     @ServiceProvider(service = AutoIngestDataSourceProcessor.class)
 
   68     private static final int XRY_FILES_DEPTH = 1;
 
   77         configPanel = XRYDataSourceProcessorConfigPanel.getInstance();
 
   82         "XRYDataSourceProcessor.dataSourceType=XRY Text Export" 
   85         return Bundle.XRYDataSourceProcessor_dataSourceType();
 
  101         "XRYDataSourceProcessor.noPathSelected=Please select a folder containing exported XRY text files",
 
  102         "XRYDataSourceProcessor.notReadable=Selected path is not readable",
 
  103         "XRYDataSourceProcessor.notXRYFolder=Selected folder did not contain any XRY text files",
 
  104         "XRYDataSourceProcessor.ioError=I/O error occured trying to test the selected folder",
 
  105         "XRYDataSourceProcessor.childNotReadable=Top level path [ %s ] is not readable",
 
  106         "XRYDataSourceProcessor.notAFolder=The selected path is not a folder" 
  109         configPanel.clearErrorText();
 
  110         String selectedFilePath = configPanel.getSelectedFilePath();
 
  111         if (selectedFilePath.isEmpty()) {
 
  112             configPanel.setErrorText(Bundle.XRYDataSourceProcessor_noPathSelected());
 
  116         File selectedFile = 
new File(selectedFilePath);
 
  117         Path selectedPath = selectedFile.toPath();
 
  120         if (!Files.isReadable(selectedPath)) {
 
  121             configPanel.setErrorText(Bundle.XRYDataSourceProcessor_notReadable());
 
  126             BasicFileAttributes attr = Files.readAttributes(selectedPath,
 
  127                     BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
 
  129             if (!attr.isDirectory()) {
 
  130                 configPanel.setErrorText(Bundle.XRYDataSourceProcessor_notAFolder());
 
  135             try (Stream<Path> allFiles = Files.walk(selectedPath, XRY_FILES_DEPTH)) {
 
  136                 Iterator<Path> allFilesIterator = allFiles.iterator();
 
  137                 while (allFilesIterator.hasNext()) {
 
  138                     Path currentPath = allFilesIterator.next();
 
  139                     if (!Files.isReadable(currentPath)) {
 
  140                         Path fileName = currentPath.subpath(currentPath.getNameCount() - 2, 
 
  141                                 currentPath.getNameCount());
 
  142                         configPanel.setErrorText(String.format(
 
  143                                 Bundle.XRYDataSourceProcessor_childNotReadable(),
 
  144                                 fileName.toString()));
 
  151             if (!XRYFolder.isXRYFolder(selectedPath)) {
 
  152                 configPanel.setErrorText(Bundle.XRYDataSourceProcessor_notXRYFolder());
 
  155         } 
catch (IOException | UncheckedIOException ex) {
 
  156             configPanel.setErrorText(Bundle.XRYDataSourceProcessor_ioError());
 
  157             logger.log(Level.WARNING, 
"[XRY DSP] I/O exception encountered trying to test the XRY folder.", ex);
 
  178             if (XRYFolder.isXRYFolder(dataSourcePath)) {
 
  181         } 
catch (IOException ex) {
 
  198         run(null, progressMonitor, callback);
 
  218         "XRYDataSourceProcessor.noCurrentCase=No case is open." 
  222         String selectedFilePath = configPanel.getSelectedFilePath();
 
  223         File selectedFile = 
new File(selectedFilePath);
 
  224         Path selectedPath = selectedFile.toPath();
 
  227             XRYFolder xryFolder = 
new XRYFolder(selectedPath);
 
  229             String uniqueUUID = UUID.randomUUID().toString();
 
  232                     callback, currentCase, uniqueUUID, host);
 
  233             swingWorker.execute();
 
  235             logger.log(Level.WARNING, 
"[XRY DSP] No case is currently open.", ex);
 
  237                     Lists.newArrayList(Bundle.XRYDataSourceProcessor_noCurrentCase(),
 
  238                             ex.getMessage()), Lists.newArrayList());
 
  244         process(deviceId, dataSourcePath, null, progressMonitor, callBack);
 
  266             XRYFolder xryFolder = 
new XRYFolder(dataSourcePath);
 
  270                     callBack, currentCase, deviceId, host);
 
  271             swingWorker.execute();
 
  273             logger.log(Level.WARNING, 
"[XRY DSP] No case is currently open.", ex);
 
  275                     Lists.newArrayList(Bundle.XRYDataSourceProcessor_noCurrentCase(),
 
  276                             ex.getMessage()), Lists.newArrayList());
 
  282         if (swingWorker != null) {
 
  283             swingWorker.cancel(
true);
 
  290         configPanel.clearSelectedFilePath();
 
  309                 Case currentCase, String uniqueUUID, 
Host host) {
 
  311             this.xryFolder = folder;
 
  312             this.progressMonitor = progressMonitor;
 
  313             this.callback = callback;
 
  314             this.currentCase = currentCase;
 
  315             this.uniqueUUID = uniqueUUID;
 
  321             "XRYDataSourceProcessor.preppingFiles=Preparing to add files to the case database",
 
  322             "XRYDataSourceProcessor.processingFiles=Processing all XRY files..." 
  326             progressMonitor.
setProgressText(Bundle.XRYDataSourceProcessor_preppingFiles());
 
  328             List<Path> nonXRYFiles = xryFolder.getNonXRYFiles();
 
  329             List<String> filePaths = nonXRYFiles.stream()
 
  332                     .collect(Collectors.toList());
 
  342             progressMonitor.
setProgressText(Bundle.XRYDataSourceProcessor_processingFiles());
 
  343             XRYReportProcessor.process(xryFolder, dataSource, currentCase.
getSleuthkitCase());
 
  349             "XRYDataSourceProcessor.unexpectedError=Internal error occurred while processing XRY report" 
  355                         Lists.newArrayList(), Lists.newArrayList(newDataSource));
 
  356             } 
catch (InterruptedException ex) {
 
  357                 logger.log(Level.WARNING, 
"[XRY DSP] Thread was interrupted while processing the XRY report." 
  358                         + 
" The case may or may not have the complete XRY report.", ex);
 
  360                         Lists.newArrayList(), Lists.newArrayList());
 
  361             } 
catch (ExecutionException ex) {
 
  362                 logger.log(Level.SEVERE, 
"[XRY DSP] Unexpected internal error while processing XRY report.", ex);
 
  364                         Lists.newArrayList(Bundle.XRYDataSourceProcessor_unexpectedError(),
 
  365                                 ex.toString()), Lists.newArrayList());
 
  378                 this.progressMonitor = progressMonitor;
 
  383                 "XRYDataSourceProcessor.fileAdded=Added %s to the case database" 
  386                 progressMonitor.
setProgressText(String.format(Bundle.XRYDataSourceProcessor_fileAdded(), newFile.
getName()));
 
FileManager getFileManager()
 
void process(String deviceId, Path dataSourcePath, Host host, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack)
 
LocalFilesDataSource addLocalFilesDataSource(String deviceId, String rootVirtualDirectoryName, String timeZone, List< String > localFilePaths, FileAddProgressUpdater progressUpdater)
 
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
 
XRYReportProcessorSwingWorker(XRYFolder folder, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback, Case currentCase, String uniqueUUID, Host host)
 
int canProcess(Path dataSourcePath)
 
void run(Host host, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callback)
 
SleuthkitCase getSleuthkitCase()
 
final XRYDataSourceProcessorConfigPanel configPanel
 
LocalFilesDataSource doInBackground()
 
final DataSourceProcessorProgressMonitor progressMonitor
 
String getDataSourceType()
 
synchronized static Logger getLogger(String name)
 
static Case getCurrentCaseThrows()
 
void process(String deviceId, Path dataSourcePath, DataSourceProcessorProgressMonitor progressMonitor, DataSourceProcessorCallback callBack)
 
final DataSourceProcessorProgressMonitor progressMonitor