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;
67 private static final String
REPORT_PATH_FMT_STR =
"%s" + File.separator +
"%s %s %s" + File.separator;
87 if (!errorList.isEmpty()) {
88 String errorString =
"";
89 for (String error : errorList) {
90 errorString += error +
"\n";
106 this.reportGenerationPanel = null;
119 this.reportGenerationPanel = panel;
120 this.progressIndicator = panel.getProgressPanel();
130 Map<String, ReportModule> modules =
new HashMap<>();
158 if (modules == null || modules.isEmpty()) {
159 logger.log(Level.SEVERE,
"No report modules found");
164 ReportingConfig config = null;
166 config = ReportingConfigLoader.loadConfig(configName);
167 }
catch (ReportConfigException ex) {
168 logger.log(Level.SEVERE,
"Unable to load reporting configuration " + configName +
". Exiting", ex);
169 progressIndicator.
updateStatusLabel(
"Unable to load reporting configuration " + configName +
". Exiting");
173 if (config == null) {
174 logger.log(Level.SEVERE,
"Unable to load reporting configuration {0}. Exiting", configName);
175 progressIndicator.
updateStatusLabel(
"Unable to load reporting configuration " + configName +
". Exiting");
181 for (Map.Entry<String, ReportModuleConfig> entry : config.getModuleConfigs().entrySet()) {
182 ReportModuleConfig moduleConfig = entry.getValue();
183 if (moduleConfig == null || !moduleConfig.isEnabled()) {
188 String moduleName = entry.getKey();
190 if (module == null) {
191 logger.log(Level.SEVERE,
"Report module {0} not found", moduleName);
192 progressIndicator.
updateStatusLabel(
"Report module " + moduleName +
" not found");
198 if (settings == null) {
216 TableReportSettings tableSettings = config.getTableReportSettings();
217 if (tableSettings == null) {
218 logger.log(Level.SEVERE,
"No table report settings for report module {0}", moduleName);
219 progressIndicator.
updateStatusLabel(
"No table report settings for report module " + moduleName);
228 FileReportSettings fileSettings = config.getFileReportSettings();
229 if (fileSettings == null) {
230 logger.log(Level.SEVERE,
"No file report settings for report module {0}", moduleName);
231 progressIndicator.
updateStatusLabel(
"No file report settings for report module " + moduleName);
242 logger.log(Level.SEVERE,
"Invalid settings for report module {0}", moduleName);
243 progressIndicator.
updateStatusLabel(
"Invalid settings for report module " + moduleName);
250 logger.log(Level.SEVERE,
"Report module {0} has unsupported report module type", moduleName);
251 progressIndicator.
updateStatusLabel(
"Report module " + moduleName +
" has unsupported report module type");
253 }
catch (IOException e) {
254 logger.log(Level.SEVERE,
"Exception while running report module {0}: {1}",
new Object[]{moduleName, e.getMessage()});
255 progressIndicator.
updateStatusLabel(
"Exception while running report module " + moduleName);
268 void displayProgressPanel() {
269 if (reportGenerationPanel == null) {
273 final JDialog dialog =
new JDialog(WindowManager.getDefault().getMainWindow(),
true);
274 dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
275 dialog.setTitle(NbBundle.getMessage(
this.getClass(),
"ReportGenerator.displayProgress.title.text"));
276 dialog.add(this.reportGenerationPanel);
279 reportGenerationPanel.addCloseAction(
new ActionListener() {
281 public void actionPerformed(ActionEvent e) {
286 dialog.addWindowListener(
new WindowAdapter() {
288 public void windowClosing(WindowEvent e) {
289 reportGenerationPanel.close();
293 dialog.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
294 dialog.setVisible(
true);
301 if (generalReportModule != null) {
304 generalReportModule.generateReport(reportDir, progressIndicator);
315 if (tableReport != null && tableReportSettings != null && null != tableReportSettings.getArtifactSelections()) {
318 tableReport.startReport(reportDir);
319 TableReportGenerator generator =
new TableReportGenerator(tableReportSettings, progressIndicator, tableReport);
321 tableReport.endReport();
324 errorList = generator.getErrorList();
335 if (fileReportModule != null && fileReportSettings != null && null != fileReportSettings.getFileProperties()) {
337 List<FileReportDataTypes> enabled =
new ArrayList<>();
338 for (Entry<FileReportDataTypes, Boolean> e : fileReportSettings.getFileProperties().entrySet()) {
340 enabled.add(e.getKey());
345 progressIndicator.
start();
347 NbBundle.getMessage(
this.getClass(),
"ReportGenerator.progress.queryingDb.text"));
350 List<AbstractFile> files =
getFiles();
351 int numFiles = files.size();
353 fileReportModule.startReport(reportDir);
354 fileReportModule.startTable(enabled);
361 for (AbstractFile file : files) {
366 fileReportModule.addRow(file, enabled);
370 if ((i % 100) == 0) {
372 NbBundle.getMessage(
this.getClass(),
"ReportGenerator.progress.processingFile.text",
378 fileReportModule.endTable();
379 fileReportModule.endReport();
388 if (portableCaseReportModule != null) {
391 portableCaseReportModule.generateReport(reportDir, settings, progressIndicator);
401 List<AbstractFile> absFiles;
404 absFiles = skCase.findAllFilesWhere(
"meta_type != " + TskData.TSK_FS_META_TYPE_ENUM.TSK_FS_META_TYPE_DIR.getValue());
407 progressIndicator.
updateStatusLabel(NbBundle.getMessage(
this.getClass(),
"ReportGenerator.errors.reportErrorText") + ex.getLocalizedMessage());
408 logger.log(Level.SEVERE,
"failed to generate reports. Unable to get all files in the image.", ex);
409 return Collections.<AbstractFile>emptyList();
414 if (reportGenerationPanel != null) {
416 if (reportFilePath == null) {
417 reportGenerationPanel.addReport(module.
getName(), null);
418 }
else if (reportFilePath.isEmpty()) {
419 reportGenerationPanel.addReport(module.
getName(), reportDir);
421 reportGenerationPanel.addReport(module.
getName(), reportDir + reportFilePath);
431 throw new IOException(
"Exception while getting open case.", ex);
434 DateFormat dateFormat =
new SimpleDateFormat(
"MM-dd-yyyy-HH-mm-ss");
435 Date date =
new Date();
436 String dateNoTime = dateFormat.format(date);
440 FileUtil.createFolder(
new File(reportPath));
441 }
catch (IOException ex) {
442 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 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)