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();
134 Map<String, ReportModule> modules =
new HashMap<>();
154 "ReportGenerator.error.noReportModules=No report modules found",
155 "# {0} - report configuration name",
"ReportGenerator.error.unableToLoadConfig=Unable to load reporting configuration {0}.",
156 "# {0} - report module name",
"ReportGenerator.error.moduleNotFound=Report module {0} not found",
157 "# {0} - report module name",
"ReportGenerator.error.noTableReportSettings=No table report settings for report module {0}",
158 "# {0} - report module name",
"ReportGenerator.error.noFileReportSettings=No file report settings for report module {0}",
159 "# {0} - report module name",
"ReportGenerator.error.invalidSettings=Invalid settings for report module {0}",
160 "# {0} - report module name",
"ReportGenerator.error.unsupportedType=Report module {0} has unsupported report module type",
161 "# {0} - report module name",
"ReportGenerator.error.exception=Exception while running report module {0}"})
175 if (modules == null || modules.isEmpty()) {
176 logger.log(Level.SEVERE, Bundle.ReportGenerator_error_noReportModules());
177 progressIndicator.
updateStatusLabel(Bundle.ReportGenerator_error_noReportModules());
181 ReportingConfig config = null;
183 config = ReportingConfigLoader.loadConfig(configName);
184 }
catch (ReportConfigException ex) {
185 logger.log(Level.SEVERE, Bundle.ReportGenerator_error_unableToLoadConfig(configName), ex);
186 progressIndicator.
updateStatusLabel(Bundle.ReportGenerator_error_unableToLoadConfig(configName));
190 if (config == null) {
191 logger.log(Level.SEVERE, Bundle.ReportGenerator_error_unableToLoadConfig(configName));
192 progressIndicator.
updateStatusLabel(Bundle.ReportGenerator_error_unableToLoadConfig(configName));
198 for (Map.Entry<String, ReportModuleConfig> entry : config.getModuleConfigs().entrySet()) {
199 ReportModuleConfig moduleConfig = entry.getValue();
200 if (moduleConfig == null || !moduleConfig.isEnabled()) {
205 String moduleName = entry.getKey();
207 if (module == null) {
208 logger.log(Level.SEVERE, Bundle.ReportGenerator_error_moduleNotFound(moduleName));
209 progressIndicator.
updateStatusLabel(Bundle.ReportGenerator_error_moduleNotFound(moduleName));
215 if (settings == null) {
233 TableReportSettings tableSettings = config.getTableReportSettings();
234 if (tableSettings == null) {
235 logger.log(Level.SEVERE, Bundle.ReportGenerator_error_noTableReportSettings(moduleName));
236 progressIndicator.
updateStatusLabel(Bundle.ReportGenerator_error_noTableReportSettings(moduleName));
245 FileReportSettings fileSettings = config.getFileReportSettings();
246 if (fileSettings == null) {
247 logger.log(Level.SEVERE, Bundle.ReportGenerator_error_noFileReportSettings(moduleName));
248 progressIndicator.
updateStatusLabel(Bundle.ReportGenerator_error_noFileReportSettings(moduleName));
259 logger.log(Level.SEVERE, Bundle.ReportGenerator_error_invalidSettings(moduleName));
260 progressIndicator.
updateStatusLabel(Bundle.ReportGenerator_error_invalidSettings(moduleName));
267 logger.log(Level.SEVERE, Bundle.ReportGenerator_error_unsupportedType(moduleName));
268 progressIndicator.
updateStatusLabel(Bundle.ReportGenerator_error_unsupportedType(moduleName));
270 }
catch (IOException e) {
271 logger.log(Level.SEVERE, Bundle.ReportGenerator_error_exception(moduleName));
272 progressIndicator.
updateStatusLabel(Bundle.ReportGenerator_error_exception(moduleName));
285 void displayProgressPanel() {
286 if (reportGenerationPanel == null) {
290 final JDialog dialog =
new JDialog(WindowManager.getDefault().getMainWindow(),
true);
291 dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
292 dialog.setTitle(NbBundle.getMessage(
this.getClass(),
"ReportGenerator.displayProgress.title.text"));
293 dialog.add(this.reportGenerationPanel);
296 reportGenerationPanel.addCloseAction(
new ActionListener() {
298 public void actionPerformed(ActionEvent e) {
303 dialog.addWindowListener(
new WindowAdapter() {
305 public void windowClosing(WindowEvent e) {
306 reportGenerationPanel.close();
310 dialog.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
311 dialog.setVisible(
true);
318 if (generalReportModule != null) {
321 reportSettings.setReportDirectoryPath(reportDir);
322 generalReportModule.generateReport(reportSettings, progressIndicator);
333 if (tableReport != null && tableReportSettings != null && null != tableReportSettings.getArtifactSelections()) {
336 tableReport.startReport(reportDir);
337 TableReportGenerator generator =
new TableReportGenerator(tableReportSettings, progressIndicator, tableReport);
339 tableReport.endReport();
342 errorList = generator.getErrorList();
349 progressIndicator.
complete(finalStatus);
360 if (fileReportModule != null && fileReportSettings != null && null != fileReportSettings.getFileProperties()) {
362 List<FileReportDataTypes> enabled =
new ArrayList<>();
363 for (Entry<FileReportDataTypes, Boolean> e : fileReportSettings.getFileProperties().entrySet()) {
365 enabled.add(e.getKey());
370 progressIndicator.
start();
372 NbBundle.getMessage(
this.getClass(),
"ReportGenerator.progress.queryingDb.text"));
375 List<AbstractFile> files =
getFiles();
376 int numFiles = files.size();
378 fileReportModule.startReport(reportDir);
379 fileReportModule.startTable(enabled);
386 for (AbstractFile file : files) {
395 fileReportModule.addRow(file, enabled);
399 if ((i % 100) == 0) {
401 NbBundle.getMessage(
this.getClass(),
"ReportGenerator.progress.processingFile.text",
407 fileReportModule.endTable();
408 fileReportModule.endReport();
414 if (fileReportSettings.getSelectedDataSources() == null) {
418 return !fileReportSettings.getSelectedDataSources().contains(file.getDataSourceObjectId());
425 if (portableCaseReportModule != null) {
428 portableCaseReportModule.generateReport(reportDir, settings, progressIndicator);
438 List<AbstractFile> absFiles;
441 absFiles = skCase.findAllFilesWhere(
"meta_type != " + TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR.getValue());
444 progressIndicator.
updateStatusLabel(NbBundle.getMessage(
this.getClass(),
"ReportGenerator.errors.reportErrorText") + ex.getLocalizedMessage());
445 logger.log(Level.SEVERE,
"failed to generate reports. Unable to get all files in the image.", ex);
446 return Collections.<AbstractFile>emptyList();
451 if (reportGenerationPanel != null) {
453 if (reportFilePath == null) {
454 reportGenerationPanel.addReport(module.
getName(), null);
455 }
else if (reportFilePath.isEmpty()) {
456 reportGenerationPanel.addReport(module.
getName(), reportDir);
458 reportGenerationPanel.addReport(module.
getName(), reportDir + reportFilePath);
468 throw new IOException(
"Exception while getting open case.", ex);
471 DateFormat dateFormat =
new SimpleDateFormat(
"MM-dd-yyyy-HH-mm-ss");
472 Date date =
new Date();
473 String dateNoTime = dateFormat.format(date);
477 FileUtil.createFolder(
new File(reportPath));
478 }
catch (IOException ex) {
479 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)