Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
RunIngestModulesAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2017-2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.ingest.runIngestModuleWizard;
20 
21 import java.awt.Cursor;
22 import java.awt.event.ActionEvent;
23 import java.text.MessageFormat;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.logging.Level;
27 import javax.swing.AbstractAction;
28 import javax.swing.Action;
29 import javax.swing.JOptionPane;
30 import javax.swing.RootPaneContainer;
31 import org.openide.DialogDisplayer;
32 import org.openide.WizardDescriptor;
33 import org.openide.util.NbBundle.Messages;
34 import org.openide.windows.WindowManager;
40 import org.sleuthkit.datamodel.AbstractFile;
41 import org.sleuthkit.datamodel.Content;
42 import org.sleuthkit.datamodel.TskCoreException;
43 
48 public final class RunIngestModulesAction extends AbstractAction {
49 
50  @Messages("RunIngestModulesAction.name=Run Ingest Modules")
51  private static final long serialVersionUID = 1L;
52  private static final Logger logger = Logger.getLogger(SpecialDirectoryNode.class.getName());
53 
54  /*
55  * Note that the execution context is the name of the dialog that used to be
56  * used instead of this wizard and is retained for backwards compatibility.
57  */
58  private static final String EXECUTION_CONTEXT = "org.sleuthkit.autopsy.ingest.RunIngestModulesDialog";
59  private final List<Content> dataSources = new ArrayList<>();
60  private final IngestJobSettings.IngestType ingestType;
61  private final AbstractFile parentFile;
62 
68  private static void showWarnings(IngestJobSettings ingestJobSettings) {
69  List<String> warnings = ingestJobSettings.getWarnings();
70  if (warnings.isEmpty() == false) {
71  StringBuilder warningMessage = new StringBuilder(1024);
72  for (String warning : warnings) {
73  warningMessage.append(warning).append("\n");
74  }
75  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), warningMessage.toString());
76  }
77  }
78 
85  public RunIngestModulesAction(List<Content> dataSources) {
86  this.putValue(Action.NAME, Bundle.RunIngestModulesAction_name());
87  this.dataSources.addAll(dataSources);
89  this.parentFile = null;
90  }
91 
98  public RunIngestModulesAction(AbstractFile parentFile) {
99  this.putValue(Action.NAME, Bundle.RunIngestModulesAction_name());
100  this.parentFile = parentFile;
102  try {
103  this.setEnabled(parentFile.hasChildren());
104  } catch (TskCoreException ex) {
105  this.setEnabled(false);
106  logger.log(Level.SEVERE, String.format("Failed to get children count for parent file %s (objId=%d), RunIngestModulesAction disabled", parentFile.getName(), parentFile.getId()), ex);
107  MessageNotifyUtil.Message.error(Bundle.RunIngestModulesAction_actionPerformed_errorMessage());
108  }
109  }
110 
116  @Messages({
117  "RunIngestModulesAction.actionPerformed.errorMessage=Error querying the case database for the selected item."
118  })
119  @Override
120  public void actionPerformed(ActionEvent e) {
126  RootPaneContainer root = (RootPaneContainer) WindowManager.getDefault().getMainWindow();
127  root.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
128  root.getGlassPane().setVisible(true);
129  RunIngestModulesWizardIterator wizard = new RunIngestModulesWizardIterator(EXECUTION_CONTEXT, this.ingestType, this.dataSources);
130  WizardDescriptor wiz = new WizardDescriptor(wizard);
131  wiz.setTitleFormat(new MessageFormat("{0}"));
132  wiz.setTitle(Bundle.RunIngestModulesAction_name());
133  root.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
134  root.getGlassPane().setVisible(false);
135  if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) {
136  IngestJobSettings ingestJobSettings = wizard.getIngestJobSettings();
137  showWarnings(ingestJobSettings);
138  if (this.parentFile == null) {
139  IngestManager.getInstance().queueIngestJob(this.dataSources, ingestJobSettings);
140  } else {
141  try {
142  Content dataSource = parentFile.getDataSource();
143  List<Content> children = parentFile.getChildren();
144  List<AbstractFile> files = new ArrayList<>();
145  for (Content child : children) {
146  if (child instanceof AbstractFile) {
147  files.add((AbstractFile) child);
148  }
149  }
150  if (!files.isEmpty()) {
151  IngestManager.getInstance().queueIngestJob(dataSource, files, ingestJobSettings);
152  }
153  } catch (TskCoreException ex) {
154  logger.log(Level.SEVERE, String.format("Failed to get data source or children for parent file %s (objId=%d), action failed", parentFile.getName(), parentFile.getId()), ex);
155  MessageNotifyUtil.Message.error(Bundle.RunIngestModulesAction_actionPerformed_errorMessage());
156  }
157  }
158  }
159  }
160 
161  @Override
162  public Object clone() throws CloneNotSupportedException {
163  throw new CloneNotSupportedException("Clone is not supported for the RunIngestModulesAction");
164  }
165 }
static synchronized IngestManager getInstance()
void queueIngestJob(Collection< Content > dataSources, IngestJobSettings settings)

Copyright © 2012-2021 Basis Technology. Generated on: Tue Jan 19 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.