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;
68 private static final String
REPORT_PATH_FMT_STR =
"%s" + File.separator +
"%s %s %s" + File.separator;
88 if (!errorList.isEmpty()) {
89 String errorString =
"";
90 for (String error : errorList) {
91 errorString += error +
"\n";
107 this.reportGenerationPanel = null;
120 this.reportGenerationPanel = panel;
121 this.progressIndicator = panel.getProgressPanel();
131 Map<String, ReportModule> modules =
new HashMap<>();
159 if (modules == null || modules.isEmpty()) {
160 logger.log(Level.SEVERE,
"No report modules found");
165 ReportingConfig config = null;
167 config = ReportingConfigLoader.loadConfig(configName);
168 }
catch (ReportConfigException ex) {
169 logger.log(Level.SEVERE,
"Unable to load reporting configuration " + configName +
". Exiting", ex);
170 progressIndicator.
updateStatusLabel(
"Unable to load reporting configuration " + configName +
". Exiting");
174 if (config == null) {
175 logger.log(Level.SEVERE,
"Unable to load reporting configuration {0}. Exiting", configName);
176 progressIndicator.
updateStatusLabel(
"Unable to load reporting configuration " + configName +
". Exiting");
182 for (Map.Entry<String, ReportModuleConfig> entry : config.getModuleConfigs().entrySet()) {
183 ReportModuleConfig moduleConfig = entry.getValue();
184 if (moduleConfig == null || !moduleConfig.isEnabled()) {
189 String moduleName = entry.getKey();
191 if (module == null) {
192 logger.log(Level.SEVERE,
"Report module {0} not found", moduleName);
193 progressIndicator.
updateStatusLabel(
"Report module " + moduleName +
" not found");
199 if (settings == null) {
217 TableReportSettings tableSettings = config.getTableReportSettings();
218 if (tableSettings == null) {
219 logger.log(Level.SEVERE,
"No table report settings for report module {0}", moduleName);
220 progressIndicator.
updateStatusLabel(
"No table report settings for report module " + moduleName);
229 FileReportSettings fileSettings = config.getFileReportSettings();
230 if (fileSettings == null) {
231 logger.log(Level.SEVERE,
"No file report settings for report module {0}", moduleName);
232 progressIndicator.
updateStatusLabel(
"No file report settings for report module " + moduleName);
243 logger.log(Level.SEVERE,
"Invalid settings for report module {0}", moduleName);
244 progressIndicator.
updateStatusLabel(
"Invalid settings for report module " + moduleName);
251 logger.log(Level.SEVERE,
"Report module {0} has unsupported report module type", moduleName);
252 progressIndicator.
updateStatusLabel(
"Report module " + moduleName +
" has unsupported report module type");
254 }
catch (IOException e) {
255 logger.log(Level.SEVERE,
"Exception while running report module {0}: {1}",
new Object[]{moduleName, e.getMessage()});
256 progressIndicator.
updateStatusLabel(
"Exception while running report module " + moduleName);
269 void displayProgressPanel() {
270 if (reportGenerationPanel == null) {
274 final JDialog dialog =
new JDialog(WindowManager.getDefault().getMainWindow(),
true);
275 dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
276 dialog.setTitle(NbBundle.getMessage(
this.getClass(),
"ReportGenerator.displayProgress.title.text"));
277 dialog.add(this.reportGenerationPanel);
280 reportGenerationPanel.addCloseAction(
new ActionListener() {
282 public void actionPerformed(ActionEvent e) {
287 dialog.addWindowListener(
new WindowAdapter() {
289 public void windowClosing(WindowEvent e) {
290 reportGenerationPanel.close();
294 dialog.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
295 dialog.setVisible(
true);
302 if (generalReportModule != null) {
305 reportSettings.setReportDirectoryPath(reportDir);
306 generalReportModule.generateReport(reportSettings, progressIndicator);
317 if (tableReport != null && tableReportSettings != null && null != tableReportSettings.getArtifactSelections()) {
320 tableReport.startReport(reportDir);
321 TableReportGenerator generator =
new TableReportGenerator(tableReportSettings, progressIndicator, tableReport);
323 tableReport.endReport();
326 errorList = generator.getErrorList();
333 progressIndicator.
complete(finalStatus);
344 if (fileReportModule != null && fileReportSettings != null && null != fileReportSettings.getFileProperties()) {
346 List<FileReportDataTypes> enabled =
new ArrayList<>();
347 for (Entry<FileReportDataTypes, Boolean> e : fileReportSettings.getFileProperties().entrySet()) {
349 enabled.add(e.getKey());
354 progressIndicator.
start();
356 NbBundle.getMessage(
this.getClass(),
"ReportGenerator.progress.queryingDb.text"));
359 List<AbstractFile> files =
getFiles();
360 int numFiles = files.size();
362 fileReportModule.startReport(reportDir);
363 fileReportModule.startTable(enabled);
370 for (AbstractFile file : files) {
379 fileReportModule.addRow(file, enabled);
383 if ((i % 100) == 0) {
385 NbBundle.getMessage(
this.getClass(),
"ReportGenerator.progress.processingFile.text",
391 fileReportModule.endTable();
392 fileReportModule.endReport();
398 if(fileReportSettings.getSelectedDataSources() == null) {
402 return !fileReportSettings.getSelectedDataSources().contains(file.getDataSourceObjectId());
409 if (portableCaseReportModule != null) {
412 portableCaseReportModule.generateReport(reportDir, settings, progressIndicator);
422 List<AbstractFile> absFiles;
425 absFiles = skCase.findAllFilesWhere(
"meta_type != " + TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR.getValue());
428 progressIndicator.
updateStatusLabel(NbBundle.getMessage(
this.getClass(),
"ReportGenerator.errors.reportErrorText") + ex.getLocalizedMessage());
429 logger.log(Level.SEVERE,
"failed to generate reports. Unable to get all files in the image.", ex);
430 return Collections.<AbstractFile>emptyList();
435 if (reportGenerationPanel != null) {
437 if (reportFilePath == null) {
438 reportGenerationPanel.addReport(module.
getName(), null);
439 }
else if (reportFilePath.isEmpty()) {
440 reportGenerationPanel.addReport(module.
getName(), reportDir);
442 reportGenerationPanel.addReport(module.
getName(), reportDir + reportFilePath);
452 throw new IOException(
"Exception while getting open case.", ex);
455 DateFormat dateFormat =
new SimpleDateFormat(
"MM-dd-yyyy-HH-mm-ss");
456 Date date =
new Date();
457 String dateNoTime = dateFormat.format(date);
461 FileUtil.createFolder(
new File(reportPath));
462 }
catch (IOException ex) {
463 throw new IOException(
"Failed to make report folder, unable to generate reports.", ex);
void generatePortableCaseReport(PortableCaseReportModule portableCaseReportModule, PortableCaseReportModuleSettings settings)
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 generateGeneralReport(GeneralReportModule generalReportModule, GeneralReportSettings reportSettings)
void displayReportErrors()
boolean shouldFilterFromReport(AbstractFile file, FileReportSettings fileReportSettings)
String getRelativeFilePath()
void generateReports(Map< String, ReportModule > modules)
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
static String normalize(String canonicalClassName)