Autopsy  4.5.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-2017 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;
41 import org.sleuthkit.datamodel.AbstractFile;
42 import org.sleuthkit.datamodel.BlackboardArtifact;
43 import org.sleuthkit.datamodel.TskCoreException;
44 
49 @ActionID(category = "Tools", id = "org.sleuthkit.autopsy.timeline.Timeline")
50 @ActionRegistration(displayName = "#CTL_MakeTimeline", lazy = false)
51 @ActionReferences(value = {
52  @ActionReference(path = "Menu/Tools", position = 102),
53  @ActionReference(path = "Toolbars/Case", position = 102)})
54 public final class OpenTimelineAction extends CallableSystemAction {
55 
56  private static final long serialVersionUID = 1L;
57  private static final Logger logger = Logger.getLogger(OpenTimelineAction.class.getName());
58  private static final int FILE_LIMIT = 6_000_000;
59 
60  private static TimeLineController timeLineController = null;
61 
62  private final JMenuItem menuItem;
63  private final JButton toolbarButton = new JButton(getName(),
64  new ImageIcon(getClass().getResource("images/btn_icon_timeline_colorized_26.png"))); //NON-NLS
65 
70  synchronized static void invalidateController() {
71  timeLineController = null;
72  }
73 
74  public OpenTimelineAction() {
75  toolbarButton.addActionListener(actionEvent -> performAction());
76  menuItem = super.getMenuPresenter();
77  this.setEnabled(false);
78  }
79 
80  @Override
81  public boolean isEnabled() {
87  return super.isEnabled() && Case.isCaseOpen() && Installer.isJavaFxInited();
88  }
89 
90  @Override
92  public void performAction() {
93  if (tooManyFiles()) {
94  Platform.runLater(PromptDialogManager::showTooManyFiles);
95  synchronized (OpenTimelineAction.this) {
96  if (timeLineController != null) {
97  timeLineController.shutDownTimeLine();
98  }
99  }
100  setEnabled(false);
101  }else if("false".equals(ModuleSettings.getConfigSetting("timeline", "enable_timeline"))) {
102  Platform.runLater(PromptDialogManager::showTimeLineDisabledMessage);
103  setEnabled(false);
104  }else {
105  showTimeline();
106  }
107  }
108 
109  @NbBundle.Messages({
110  "OpenTimelineAction.settingsErrorMessage=Failed to initialize timeline settings.",
111  "OpenTimeLineAction.msgdlg.text=Could not create timeline, there are no data sources."})
112  synchronized private void showTimeline(AbstractFile file, BlackboardArtifact artifact) {
113  try {
114  Case currentCase = Case.getCurrentCase();
115  if (currentCase.hasData() == false) {
116  MessageNotifyUtil.Message.info(Bundle.OpenTimeLineAction_msgdlg_text());
117  logger.log(Level.INFO, "Could not create timeline, there are no data sources.");// NON-NLS
118  return;
119  }
120  try {
121  if (timeLineController == null) {
122  timeLineController = new TimeLineController(currentCase);
123  } else if (timeLineController.getAutopsyCase() != currentCase) {
124  timeLineController.shutDownTimeLine();
125  timeLineController = new TimeLineController(currentCase);
126  }
127 
128  timeLineController.showTimeLine(file, artifact);
129 
130  } catch (IOException iOException) {
131  MessageNotifyUtil.Message.error(Bundle.OpenTimelineAction_settingsErrorMessage());
132  logger.log(Level.SEVERE, "Failed to initialize per case timeline settings.", iOException);
133  }
134  } catch (IllegalStateException e) {
135  //there is no case... Do nothing.
136  }
137  }
138 
143  public void showTimeline() {
144  showTimeline(null, null);
145  }
146 
155  public void showFileInTimeline(AbstractFile file) {
156  showTimeline(file, null);
157  }
158 
166  public void showArtifactInTimeline(BlackboardArtifact artifact) {
167  showTimeline(null, artifact);
168  }
169 
170  @Override
171  @NbBundle.Messages("OpenTimelineAction.displayName=Timeline")
172  public String getName() {
173  return Bundle.OpenTimelineAction_displayName();
174  }
175 
176  @Override
177  public HelpCtx getHelpCtx() {
178  return HelpCtx.DEFAULT_HELP;
179  }
180 
181  @Override
182  public boolean asynchronous() {
183  return false; // run on edt
184  }
185 
191  @Override
192  public void setEnabled(boolean enable) {
193  super.setEnabled(enable);
194  menuItem.setEnabled(enable);
195  toolbarButton.setEnabled(enable);
196  }
197 
203  @Override
204  public Component getToolbarPresenter() {
205  return toolbarButton;
206  }
207 
208  @Override
209  public JMenuItem getMenuPresenter() {
210  return menuItem;
211  }
212 
213  private boolean tooManyFiles() {
214  try {
215  return FILE_LIMIT < Case.getCurrentCase().getSleuthkitCase().countFilesWhere("1 = 1");
216  } catch (IllegalStateException ex) {
217  logger.log(Level.SEVERE, "Can not open timeline with no case open.", ex);
218  } catch (TskCoreException ex) {
219  logger.log(Level.SEVERE, "Error counting files in the DB.", ex);
220  }
221  //if there is any doubt (no case, tskcore error, etc) just disable .
222  return false;
223  }
224 }
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: Tue Feb 20 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.