19 package org.sleuthkit.autopsy.report.infrastructure;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import java.awt.event.WindowAdapter;
30 import java.awt.event.WindowEvent;
32 import java.io.IOException;
33 import java.text.DateFormat;
34 import java.text.SimpleDateFormat;
35 import java.util.ArrayList;
36 import java.util.Collections;
37 import java.util.Date;
38 import java.util.HashMap;
39 import java.util.List;
41 import java.util.Map.Entry;
42 import java.util.logging.Level;
43 import javax.swing.JDialog;
44 import org.openide.filesystems.FileUtil;
45 import org.openide.util.NbBundle;
46 import org.openide.windows.WindowManager;
66 private static final String
REPORT_PATH_FMT_STR =
"%s" + File.separator +
"%s %s %s" + File.separator;
86 if (!errorList.isEmpty()) {
87 String errorString =
"";
88 for (String error : errorList) {
89 errorString += error +
"\n";
105 this.reportGenerationPanel = null;
118 this.reportGenerationPanel = panel;
119 this.progressIndicator = panel.getProgressPanel();
128 ReportingConfig config = null;
130 config = ReportingConfigLoader.loadConfig(configName);
131 }
catch (ReportConfigException ex) {
132 logger.log(Level.SEVERE,
"Unable to load reporting configuration " + configName +
". Exiting", ex);
133 progressIndicator.
updateStatusLabel(
"Unable to load reporting configuration " + configName +
". Exiting");
137 if (config == null) {
138 logger.log(Level.SEVERE,
"Unable to load reporting configuration {0}. Exiting", configName);
139 progressIndicator.
updateStatusLabel(
"Unable to load reporting configuration " + configName +
". Exiting");
145 Map<String, ReportModule> modules =
new HashMap<>();
147 modules.put(module.getClass().getCanonicalName(), module);
151 modules.put(module.getClass().getCanonicalName(), module);
155 modules.put(module.getClass().getCanonicalName(), module);
162 for (Map.Entry<String, ReportModuleConfig> entry : config.getModuleConfigs().entrySet()) {
163 ReportModuleConfig moduleConfig = entry.getValue();
164 if (moduleConfig == null || !moduleConfig.isEnabled()) {
169 String moduleName = entry.getKey();
171 if (module == null) {
172 logger.log(Level.SEVERE,
"Report module {0} not found", moduleName);
173 progressIndicator.
updateStatusLabel(
"Report module " + moduleName +
" not found");
179 if (settings == null) {
197 TableReportSettings tableSettings = config.getTableReportSettings();
198 if (tableSettings == null) {
199 logger.log(Level.SEVERE,
"No table report settings for report module {0}", moduleName);
200 progressIndicator.
updateStatusLabel(
"No table report settings for report module " + moduleName);
209 FileReportSettings fileSettings = config.getFileReportSettings();
210 if (fileSettings == null) {
211 logger.log(Level.SEVERE,
"No file report settings for report module {0}", moduleName);
212 progressIndicator.
updateStatusLabel(
"No file report settings for report module " + moduleName);
223 logger.log(Level.SEVERE,
"Invalid settings for report module {0}", moduleName);
224 progressIndicator.
updateStatusLabel(
"Invalid settings for report module " + moduleName);
231 logger.log(Level.SEVERE,
"Report module {0} has unsupported report module type", moduleName);
232 progressIndicator.
updateStatusLabel(
"Report module " + moduleName +
" has unsupported report module type");
234 }
catch (IOException e) {
235 logger.log(Level.SEVERE,
"Exception while running report module {0}: {1}",
new Object[]{moduleName, e.getMessage()});
236 progressIndicator.
updateStatusLabel(
"Exception while running report module " + moduleName);
249 void displayProgressPanel() {
250 if (reportGenerationPanel == null) {
254 final JDialog dialog =
new JDialog(WindowManager.getDefault().getMainWindow(),
true);
255 dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
256 dialog.setTitle(NbBundle.getMessage(
this.getClass(),
"ReportGenerator.displayProgress.title.text"));
257 dialog.add(this.reportGenerationPanel);
260 reportGenerationPanel.addCloseAction(
new ActionListener() {
262 public void actionPerformed(ActionEvent e) {
267 dialog.addWindowListener(
new WindowAdapter() {
269 public void windowClosing(WindowEvent e) {
270 reportGenerationPanel.close();
274 dialog.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
275 dialog.setVisible(
true);
282 if (generalReportModule != null) {
285 generalReportModule.generateReport(reportDir, progressIndicator);
296 if (tableReport != null && tableReportSettings != null && null != tableReportSettings.getArtifactSelections()) {
299 tableReport.startReport(reportDir);
300 TableReportGenerator generator =
new TableReportGenerator(tableReportSettings, progressIndicator, tableReport);
302 tableReport.endReport();
305 errorList = generator.getErrorList();
316 if (fileReportModule != null && fileReportSettings != null && null != fileReportSettings.getFileProperties()) {
318 List<FileReportDataTypes> enabled =
new ArrayList<>();
319 for (Entry<FileReportDataTypes, Boolean> e : fileReportSettings.getFileProperties().entrySet()) {
321 enabled.add(e.getKey());
326 progressIndicator.
start();
328 NbBundle.getMessage(
this.getClass(),
"ReportGenerator.progress.queryingDb.text"));
331 List<AbstractFile> files =
getFiles();
332 int numFiles = files.size();
334 fileReportModule.startReport(reportDir);
335 fileReportModule.startTable(enabled);
342 for (AbstractFile file : files) {
347 fileReportModule.addRow(file, enabled);
351 if ((i % 100) == 0) {
353 NbBundle.getMessage(
this.getClass(),
"ReportGenerator.progress.processingFile.text",
359 fileReportModule.endTable();
360 fileReportModule.endReport();
369 if (portableCaseReportModule != null) {
372 portableCaseReportModule.generateReport(reportDir, settings, progressIndicator);
382 List<AbstractFile> absFiles;
385 absFiles = skCase.findAllFilesWhere(
"meta_type != " + TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR.getValue());
388 progressIndicator.
updateStatusLabel(NbBundle.getMessage(
this.getClass(),
"ReportGenerator.errors.reportErrorText") + ex.getLocalizedMessage());
389 logger.log(Level.SEVERE,
"failed to generate reports. Unable to get all files in the image.", ex);
390 return Collections.<AbstractFile>emptyList();
395 if (reportGenerationPanel != null) {
397 if (reportFilePath == null) {
398 reportGenerationPanel.addReport(module.
getName(), null);
399 }
else if (reportFilePath.isEmpty()) {
400 reportGenerationPanel.addReport(module.
getName(), reportDir);
402 reportGenerationPanel.addReport(module.
getName(), reportDir + reportFilePath);
412 throw new IOException(
"Exception while getting open case.", ex);
415 DateFormat dateFormat =
new SimpleDateFormat(
"MM-dd-yyyy-HH-mm-ss");
416 Date date =
new Date();
417 String dateNoTime = dateFormat.format(date);
421 FileUtil.createFolder(
new File(reportPath));
422 }
catch (IOException ex) {
423 throw new IOException(
"Failed to make report folder, unable to generate reports.", ex);
void generatePortableCaseReport(PortableCaseReportModule portableCaseReportModule, PortableCaseReportModuleSettings settings)
void generateGeneralReport(GeneralReportModule generalReportModule)
static final String REPORTS_DIR
void generateTableReport(TableReportModule tableReport, TableReportSettings tableReportSettings)
final ReportGenerationPanel reportGenerationPanel
final ReportProgressPanel progressIndicator
void complete(ReportStatus reportStatus)
void generateFileListReport(FileReportModule fileReportModule, FileReportSettings fileReportSettings)
static String getReportsDirectory()
String getReportDirectory()
static final Logger logger
List< AbstractFile > getFiles()
void setIndeterminate(boolean indeterminate)
default ReportModuleSettings getDefaultConfiguration()
ReportGenerator(String configName, ReportProgressIndicator progressIndicator)
default void setConfiguration(ReportModuleSettings settings)
void displayReportErrors()
String getRelativeFilePath()
void setMaximumProgress(int max)
SleuthkitCase getSleuthkitCase()
void setupProgressPanel(ReportModule module, String reportDir)
synchronized static Logger getLogger(String name)
static String createReportDirectory(ReportModule module)
static Case getCurrentCaseThrows()
void updateStatusLabel(String statusMessage)
static final String REPORT_PATH_FMT_STR