19 package org.sleuthkit.autopsy.timeline.snapshot;
21 import com.github.mustachejava.DefaultMustacheFactory;
22 import com.github.mustachejava.Mustache;
23 import com.github.mustachejava.MustacheFactory;
24 import java.awt.image.BufferedImage;
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.io.InputStreamReader;
28 import java.io.Writer;
29 import java.nio.charset.Charset;
30 import java.nio.file.Files;
31 import java.nio.file.Path;
32 import java.nio.file.Paths;
33 import java.text.SimpleDateFormat;
34 import java.util.Date;
35 import java.util.HashMap;
36 import javax.imageio.ImageIO;
37 import org.apache.commons.lang3.StringUtils;
38 import org.joda.time.format.DateTimeFormat;
52 private final static MustacheFactory
mf =
new DefaultMustacheFactory();
61 private final BufferedImage
image;
82 this.image = snapshot;
98 Files.createDirectories(reportFolderPath);
101 ImageIO.write(image,
"png", reportFolderPath.resolve(
"snapshot.png").toFile());
118 HashMap<String, Object> snapShotContext =
new HashMap<>();
119 snapShotContext.put(
"reportTitle", reportName);
120 snapShotContext.put(
"startTime", zoomParams.
getTimeRange().getStart().toString(DateTimeFormat.fullDateTime()));
121 snapShotContext.put(
"endTime", zoomParams.
getTimeRange().getEnd().toString(DateTimeFormat.fullDateTime()));
122 snapShotContext.put(
"zoomParams", zoomParams);
124 fillTemplateAndWrite(
"/org/sleuthkit/autopsy/timeline/snapshot/snapshot_template.html",
"Snapshot", snapShotContext, reportFolderPath.resolve(
"snapshot.html"));
137 HashMap<String, Object> indexContext =
new HashMap<>();
138 indexContext.put(
"reportBranding", reportBranding);
139 indexContext.put(
"reportName", reportName);
140 Path reportIndexFile = reportFolderPath.resolve(
"index.html");
142 fillTemplateAndWrite(
"/org/sleuthkit/autopsy/timeline/snapshot/index_template.html",
"Index", indexContext, reportIndexFile);
143 return reportIndexFile;
153 HashMap<String, Object> summaryContext =
new HashMap<>();
154 summaryContext.put(
"reportName", reportName);
155 summaryContext.put(
"reportBranding", reportBranding);
156 summaryContext.put(
"generationDateTime",
new SimpleDateFormat(
"yyyy/MM/dd HH:mm:ss").format(generationDate));
158 summaryContext.put(
"currentCase", currentCase);
160 fillTemplateAndWrite(
"/org/sleuthkit/autopsy/timeline/snapshot/summary_template.html",
"Summary", summaryContext, reportFolderPath.resolve(
"summary.html"));
179 private void fillTemplateAndWrite(
final String templateLocation,
final String templateName, Object context,
final Path outPutFile)
throws IOException {
181 Mustache summaryMustache = mf.compile(
new InputStreamReader(
SnapShotReportWriter.class.getResourceAsStream(templateLocation)), templateName);
182 try (Writer writer = Files.newBufferedWriter(outPutFile, Charset.forName(
"UTF-8"))) {
183 summaryMustache.execute(writer, context);
197 if (StringUtils.isNotBlank(generatorLogoPath)) {
198 Files.copy(Files.newInputStream(Paths.get(generatorLogoPath)), reportFolderPath.resolve(
"generator_logo.png"));
201 if (StringUtils.isNotBlank(agencyLogoPath)) {
202 Files.copy(Files.newInputStream(Paths.get(agencyLogoPath)), reportFolderPath.resolve(
"agency_logo.png"));
206 try (InputStream navStream =
SnapShotReportWriter.class.getResourceAsStream(
"/org/sleuthkit/autopsy/timeline/snapshot/navigation.html")) {
207 Files.copy(navStream, reportFolderPath.resolve(
"nav.html"));
210 if (StringUtils.isBlank(agencyLogoPath)) {
212 try (InputStream faviconStream =
SnapShotReportWriter.class.getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/favicon.ico")) {
213 Files.copy(faviconStream, reportFolderPath.resolve(
"favicon.ico"));
216 Files.copy(Files.newInputStream(Paths.get(agencyLogoPath)), reportFolderPath.resolve(
"favicon.ico"));
220 try (InputStream summaryStream =
SnapShotReportWriter.class.getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/summary.png")) {
221 Files.copy(summaryStream, reportFolderPath.resolve(
"summary.png"));
224 try (InputStream snapshotIconStream =
SnapShotReportWriter.class.getResourceAsStream(
"/org/sleuthkit/autopsy/timeline/images/image.png")) {
225 Files.copy(snapshotIconStream, reportFolderPath.resolve(
"snapshot_icon.png"));
228 try (InputStream resource =
SnapShotReportWriter.class.getResourceAsStream(
"/org/sleuthkit/autopsy/timeline/snapshot/index.css")) {
229 Files.copy(resource, reportFolderPath.resolve(
"index.css"));
232 try (InputStream resource =
SnapShotReportWriter.class.getResourceAsStream(
"/org/sleuthkit/autopsy/timeline/snapshot/summary.css")) {
233 Files.copy(resource, reportFolderPath.resolve(
"summary.css"));
final ZoomParams zoomParams
String getAgencyLogoPath()
String getGeneratorLogoPath()
static synchronized IngestManager getInstance()
final Date generationDate
boolean isIngestRunning()
static final MustacheFactory mf
void fillTemplateAndWrite(final String templateLocation, final String templateName, Object context, final Path outPutFile)
final BufferedImage image
SnapShotReportWriter(Case currentCase, Path reportFolderPath, String reportName, ZoomParams zoomParams, Date generationDate, BufferedImage snapshot)
final ReportBranding reportBranding
final Path reportFolderPath
void writeSnapShotHTMLFile()