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);
159 String agencyLogo =
"agency_logo.png";
161 agencyLogo = Paths.get(reportBranding.
getAgencyLogoPath()).getFileName().toString();
163 summaryContext.put(
"agencyLogoFileName", agencyLogo);
164 fillTemplateAndWrite(
"/org/sleuthkit/autopsy/timeline/snapshot/summary_template.html",
"Summary", summaryContext, reportFolderPath.resolve(
"summary.html"));
183 private void fillTemplateAndWrite(
final String templateLocation,
final String templateName, Object context,
final Path outPutFile)
throws IOException {
185 Mustache summaryMustache = mf.compile(
new InputStreamReader(
SnapShotReportWriter.class.getResourceAsStream(templateLocation)), templateName);
186 try (Writer writer = Files.newBufferedWriter(outPutFile, Charset.forName(
"UTF-8"))) {
187 summaryMustache.execute(writer, context);
201 if (StringUtils.isNotBlank(generatorLogoPath)) {
202 Files.copy(Files.newInputStream(Paths.get(generatorLogoPath)), reportFolderPath.resolve(
"generator_logo.png"));
205 if (StringUtils.isNotBlank(agencyLogoPath)) {
206 Files.copy(Files.newInputStream(Paths.get(agencyLogoPath)), reportFolderPath.resolve(Paths.get(reportBranding.
getAgencyLogoPath()).getFileName()));
210 try (InputStream navStream =
SnapShotReportWriter.class.getResourceAsStream(
"/org/sleuthkit/autopsy/timeline/snapshot/navigation.html")) {
211 Files.copy(navStream, reportFolderPath.resolve(
"nav.html"));
214 if (StringUtils.isBlank(agencyLogoPath)) {
216 try (InputStream faviconStream =
SnapShotReportWriter.class.getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/favicon.ico")) {
217 Files.copy(faviconStream, reportFolderPath.resolve(
"favicon.ico"));
220 Files.copy(Files.newInputStream(Paths.get(agencyLogoPath)), reportFolderPath.resolve(
"favicon.ico"));
224 try (InputStream summaryStream =
SnapShotReportWriter.class.getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/summary.png")) {
225 Files.copy(summaryStream, reportFolderPath.resolve(
"summary.png"));
228 try (InputStream snapshotIconStream =
SnapShotReportWriter.class.getResourceAsStream(
"/org/sleuthkit/autopsy/timeline/images/image.png")) {
229 Files.copy(snapshotIconStream, reportFolderPath.resolve(
"snapshot_icon.png"));
232 try (InputStream resource =
SnapShotReportWriter.class.getResourceAsStream(
"/org/sleuthkit/autopsy/timeline/snapshot/index.css")) {
233 Files.copy(resource, reportFolderPath.resolve(
"index.css"));
236 try (InputStream resource =
SnapShotReportWriter.class.getResourceAsStream(
"/org/sleuthkit/autopsy/timeline/snapshot/summary.css")) {
237 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()