Autopsy  4.7.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
OpenTimelineAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014-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.timeline;
20 
21 import java.awt.Component;
22 import java.io.IOException;
23 import java.util.logging.Level;
24 import javafx.application.Platform;
25 import javax.swing.ImageIcon;
26 import javax.swing.JButton;
27 import javax.swing.JMenuItem;
28 import org.openide.awt.ActionID;
29 import org.openide.awt.ActionReference;
30 import org.openide.awt.ActionReferences;
31 import org.openide.awt.ActionRegistration;
32 import org.openide.util.HelpCtx;
33 import org.openide.util.NbBundle;
34 import org.openide.util.actions.CallableSystemAction;
42 import org.sleuthkit.datamodel.AbstractFile;
43 import org.sleuthkit.datamodel.BlackboardArtifact;
44 import org.sleuthkit.datamodel.TskCoreException;
45 
50 @ActionID(category = "Tools", id = "org.sleuthkit.autopsy.timeline.Timeline")
51 @ActionRegistration(displayName = "#CTL_MakeTimeline", lazy = false)
52 @ActionReferences(value = {
53  @ActionReference(path = "Menu/Tools", position = 102),
54  @ActionReference(path = "Toolbars/Case", position = 102)})
55 public final class OpenTimelineAction extends CallableSystemAction {
56 
57  private static final long serialVersionUID = 1L;
58  private static final Logger logger = Logger.getLogger(OpenTimelineAction.class.getName());
59  private static final int FILE_LIMIT = 6_000_000;
60 
61  private static TimeLineController timeLineController = null;
62 
63  private final JMenuItem menuItem;
64  private final JButton toolbarButton = new JButton(getName(),
65  new ImageIcon(getClass().getResource("images/btn_icon_timeline_colorized_26.png"))); //NON-NLS
66 
71  synchronized static void invalidateController() {
72  timeLineController = null;
73  }
74 
75  public OpenTimelineAction() {
76  toolbarButton.addActionListener(actionEvent -> performAction());
77  menuItem = super.getMenuPresenter();
78  this.setEnabled(false);
79  }
80 
81  @Override
82  public boolean isEnabled() {
88  return super.isEnabled() && Case.isCaseOpen() && Installer.isJavaFxInited();
89  }
90 
91  @Override
93  public void performAction() {
94  if (tooManyFiles()) {
95  Platform.runLater(PromptDialogManager::showTooManyFiles);
96  synchronized (OpenTimelineAction.this) {
97  if (timeLineController != null) {
98  timeLineController.shutDownTimeLine();
99  }
100  }
101  setEnabled(false);
102  }else if("false".equals(ModuleSettings.getConfigSetting("timeline", "enable_timeline"))) {
103  Platform.runLater(PromptDialogManager::showTimeLineDisabledMessage);
104  setEnabled(false);
105  }else {
106  showTimeline();
107  }
108  }
109 
110  @NbBundle.Messages({
111  "OpenTimelineAction.settingsErrorMessage=Failed to initialize timeline settings.",
112  "OpenTimeLineAction.msgdlg.text=Could not create timeline, there are no data sources."})
113  synchronized private void showTimeline(AbstractFile file, BlackboardArtifact artifact) {
114  try {
115  Case currentCase = Case.getCurrentCaseThrows();
116  if (currentCase.hasData() == false) {
117  MessageNotifyUtil.Message.info(Bundle.OpenTimeLineAction_msgdlg_text());
118  logger.log(Level.INFO, "Could not create timeline, there are no data sources.");// NON-NLS
119  return;
120  }
121  try {
122  if (timeLineController == null) {
123  timeLineController = new TimeLineController(currentCase);
124  } else if (timeLineController.getAutopsyCase() != currentCase) {
125  timeLineController.shutDownTimeLine();
126  timeLineController = new TimeLineController(currentCase);
127  }
128 
129  timeLineController.showTimeLine(file, artifact);
130 
131  } catch (IOException iOException) {
132  MessageNotifyUtil.Message.error(Bundle.OpenTimelineAction_settingsErrorMessage());
133  logger.log(Level.SEVERE, "Failed to initialize per case timeline settings.", iOException);
134  }
135  } catch (NoCurrentCaseException e) {
136  //there is no case... Do nothing.
137  }
138  }
139 
144  public void showTimeline() {
145  showTimeline(null, null);
146  }
147 
156  public void showFileInTimeline(AbstractFile file) {
157  showTimeline(file, null);
158  }
159 
167  public void showArtifactInTimeline(BlackboardArtifact artifact) {
168  showTimeline(null, artifact);
169  }
170 
171  @Override
172  @NbBundle.Messages("OpenTimelineAction.displayName=Timeline")
173  public String getName() {
174  return Bundle.OpenTimelineAction_displayName();
175  }
176 
177  @Override
178  public HelpCtx getHelpCtx() {
179  return HelpCtx.DEFAULT_HELP;
180  }
181 
182  @Override
183  public boolean asynchronous() {
184  return false; // run on edt
185  }
186 
192  @Override
193  public void setEnabled(boolean enable) {
194  super.setEnabled(enable);
195  menuItem.setEnabled(enable);
196  toolbarButton.setEnabled(enable);
197  }
198 
204  @Override
205  public Component getToolbarPresenter() {
206  return toolbarButton;
207  }
208 
209  @Override
210  public JMenuItem getMenuPresenter() {
211  return menuItem;
212  }
213 
214  private boolean tooManyFiles() {
215  try {
216  return FILE_LIMIT < Case.getCurrentCaseThrows().getSleuthkitCase().countFilesWhere("1 = 1");
217  } catch (NoCurrentCaseException ex) {
218  logger.log(Level.SEVERE, "Can not open timeline with no case open.", ex);
219  } catch (TskCoreException ex) {
220  logger.log(Level.SEVERE, "Error counting files in the DB.", ex);
221  }
222  //if there is any doubt (no case, tskcore error, etc) just disable .
223  return false;
224  }
225 }
synchronized void showTimeline(AbstractFile file, BlackboardArtifact artifact)
static String getConfigSetting(String moduleName, String settingName)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jun 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.