23 package org.sleuthkit.autopsy.report;
25 import java.awt.image.BufferedImage;
26 import java.io.BufferedWriter;
28 import java.io.FileNotFoundException;
29 import java.io.FileOutputStream;
30 import java.io.IOException;
31 import java.io.InputStream;
32 import java.io.OutputStream;
33 import java.io.OutputStreamWriter;
34 import java.io.UnsupportedEncodingException;
35 import java.io.Writer;
36 import java.nio.file.Files;
37 import java.nio.file.Path;
38 import java.nio.file.Paths;
39 import java.text.DateFormat;
40 import java.text.SimpleDateFormat;
41 import java.util.ArrayList;
42 import java.util.Date;
43 import java.util.List;
46 import java.util.TreeMap;
47 import java.util.logging.Level;
48 import javax.imageio.ImageIO;
49 import org.openide.filesystems.FileUtil;
50 import org.openide.util.NbBundle;
60 import org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
66 import org.
sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
68 class ReportHTML
implements TableReportModule {
70 private static final Logger logger = Logger.getLogger(ReportHTML.class.getName());
71 private static final String THUMBS_REL_PATH =
"thumbs" + File.separator;
72 private static ReportHTML instance;
73 private static final int MAX_THUMBS_PER_PAGE = 1000;
74 private Case currentCase;
75 private SleuthkitCase skCase;
76 static Integer THUMBNAIL_COLUMNS = 5;
78 private Map<String, Integer> dataTypes;
80 private String thumbsPath;
81 private String currentDataType;
82 private Integer rowCount;
85 private final ReportBranding reportBranding;
88 public static synchronized ReportHTML getDefault() {
89 if (instance == null) {
90 instance =
new ReportHTML();
96 private ReportHTML() {
97 reportBranding =
new ReportBranding();
101 private void refresh() {
102 currentCase = Case.getCurrentCase();
103 skCase = currentCase.getSleuthkitCase();
105 dataTypes =
new TreeMap<>();
109 currentDataType =
"";
115 }
catch (IOException ex) {
127 private String dataTypeToFileName(String dataType) {
131 fileName = fileName.replaceAll(
" ",
"_");
140 private String useDataTypeIcon(String dataType) {
144 OutputStream output = null;
146 logger.log(Level.INFO,
"useDataTypeIcon: dataType = {0}", dataType);
149 BlackboardArtifact.ARTIFACT_TYPE artifactType = null;
150 for (ARTIFACT_TYPE v : ARTIFACT_TYPE.values()) {
151 if (v.getDisplayName().equals(dataType)) {
156 if (null != artifactType) {
158 iconFileName = dataTypeToFileName(artifactType.getDisplayName()) +
".png";
159 iconFilePath = path + File.separator + iconFileName;
162 switch (artifactType) {
163 case TSK_WEB_BOOKMARK:
164 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/bookmarks.png");
167 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/cookies.png");
169 case TSK_WEB_HISTORY:
170 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/history.png");
172 case TSK_WEB_DOWNLOAD:
173 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/downloads.png");
175 case TSK_RECENT_OBJECT:
176 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/recent.png");
178 case TSK_INSTALLED_PROG:
179 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/installed.png");
181 case TSK_KEYWORD_HIT:
182 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/keywords.png");
184 case TSK_HASHSET_HIT:
185 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/hash.png");
187 case TSK_DEVICE_ATTACHED:
188 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/devices.png");
190 case TSK_WEB_SEARCH_QUERY:
191 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/search.png");
193 case TSK_METADATA_EXIF:
194 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/exif.png");
197 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/userbookmarks.png");
199 case TSK_TAG_ARTIFACT:
200 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/userbookmarks.png");
202 case TSK_SERVICE_ACCOUNT:
203 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/account-icon-16.png");
206 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/contact.png");
209 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/message.png");
212 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/calllog.png");
214 case TSK_CALENDAR_ENTRY:
215 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/calendar.png");
217 case TSK_SPEED_DIAL_ENTRY:
218 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/speeddialentry.png");
220 case TSK_BLUETOOTH_PAIRING:
221 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/bluetooth.png");
223 case TSK_GPS_BOOKMARK:
224 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gpsfav.png");
226 case TSK_GPS_LAST_KNOWN_LOCATION:
227 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps-lastlocation.png");
230 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps-search.png");
233 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/computer.png");
235 case TSK_GPS_TRACKPOINT:
236 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps_trackpoint.png");
239 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/gps_trackpoint.png");
242 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/mail-icon-16.png");
244 case TSK_ENCRYPTION_DETECTED:
245 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/encrypted-file.png");
247 case TSK_EXT_MISMATCH_DETECTED:
248 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/mismatch-16.png");
250 case TSK_INTERESTING_ARTIFACT_HIT:
251 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/interesting_item.png");
253 case TSK_INTERESTING_FILE_HIT:
254 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/images/interesting_item.png");
257 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/installed.png");
259 case TSK_REMOTE_DRIVE:
260 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/drive_network.png");
263 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/accounts.png");
266 logger.log(Level.WARNING,
"useDataTypeIcon: unhandled artifact type = " + dataType);
267 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/star.png");
268 iconFileName =
"star.png";
269 iconFilePath = path + File.separator + iconFileName;
272 }
else if (dataType.startsWith(ARTIFACT_TYPE.TSK_ACCOUNT.getDisplayName())) {
280 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/accounts.png");
281 iconFileName =
"accounts.png";
282 iconFilePath = path + File.separator + iconFileName;
284 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/star.png");
285 iconFileName =
"star.png";
286 iconFilePath = path + File.separator + iconFileName;
290 output =
new FileOutputStream(iconFilePath);
291 FileUtil.copy(in, output);
294 }
catch (IOException ex) {
295 logger.log(Level.SEVERE,
"Failed to extract images for HTML report.", ex);
297 if (output != null) {
301 }
catch (IOException ex) {
307 }
catch (IOException ex) {
322 public void startReport(String baseReportDir) {
326 this.path = baseReportDir +
"HTML Report" + File.separator;
327 this.thumbsPath = this.path +
"thumbs" + File.separator;
329 FileUtil.createFolder(
new File(this.path));
330 FileUtil.createFolder(
new File(this.thumbsPath));
331 }
catch (IOException ex) {
332 logger.log(Level.SEVERE,
"Unable to make HTML report folder.");
345 public void endReport() {
350 }
catch (IOException ex) {
351 logger.log(Level.WARNING,
"Could not close the output writer when ending report.", ex);
365 public void startDataType(String name, String description) {
366 String title = dataTypeToFileName(name);
368 out =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(path + title +
".html"),
"UTF-8"));
369 }
catch (FileNotFoundException ex) {
370 logger.log(Level.SEVERE,
"File not found: {0}", ex);
371 }
catch (UnsupportedEncodingException ex) {
372 logger.log(Level.SEVERE,
"Unrecognized encoding");
376 StringBuilder page =
new StringBuilder();
377 page.append(
"<html>\n<head>\n\t<title>").append(name).append(
"</title>\n\t<link rel=\"stylesheet\" type=\"text/css\" href=\"index.css\" />\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n</head>\n<body>\n");
378 page.append(
"<div id=\"header\">").append(name).append(
"</div>\n<div id=\"content\">\n");
379 if (!description.isEmpty()) {
380 page.append(
"<p><strong>");
381 page.append(description);
382 page.append(
"</string></p>\n");
384 out.write(page.toString());
385 currentDataType = name;
387 }
catch (IOException ex) {
388 logger.log(Level.SEVERE,
"Failed to write page head: {0}", ex);
397 public void endDataType() {
398 dataTypes.put(currentDataType, rowCount);
400 out.write(
"</div>\n</body>\n</html>\n");
401 }
catch (IOException ex) {
402 logger.log(Level.SEVERE,
"Failed to write end of HTML report.", ex);
408 }
catch (IOException ex) {
409 logger.log(Level.WARNING,
"Could not close the output writer when ending data type.", ex);
422 public void startSet(String setName) {
423 StringBuilder set =
new StringBuilder();
424 set.append(
"<h1><a name=\"").append(setName).append(
"\">").append(setName).append(
"</a></h1>\n");
425 set.append(
"<div class=\"keyword_list\">\n");
428 out.write(set.toString());
429 }
catch (IOException ex) {
430 logger.log(Level.SEVERE,
"Failed to write set: {0}", ex);
438 public void endSet() {
440 out.write(
"</div>\n");
441 }
catch (IOException ex) {
442 logger.log(Level.SEVERE,
"Failed to write end of set: {0}", ex);
452 public void addSetIndex(List<String> sets) {
453 StringBuilder index =
new StringBuilder();
454 index.append(
"<ul>\n");
455 for (String set : sets) {
456 index.append(
"\t<li><a href=\"#").append(set).append(
"\">").append(set).append(
"</a></li>\n");
458 index.append(
"</ul>\n");
460 out.write(index.toString());
461 }
catch (IOException ex) {
462 logger.log(Level.SEVERE,
"Failed to add set index: {0}", ex);
472 public void addSetElement(String elementName) {
474 out.write(
"<h4>" + elementName +
"</h4>\n");
475 }
catch (IOException ex) {
476 logger.log(Level.SEVERE,
"Failed to write set element: {0}", ex);
486 public void startTable(List<String> titles) {
487 StringBuilder ele =
new StringBuilder();
488 ele.append(
"<table>\n<thead>\n\t<tr>\n");
489 for (String title : titles) {
490 ele.append(
"\t\t<th>").append(title).append(
"</th>\n");
492 ele.append(
"\t</tr>\n</thead>\n");
495 out.write(ele.toString());
496 }
catch (IOException ex) {
497 logger.log(Level.SEVERE,
"Failed to write table start: {0}", ex);
508 public void startContentTagsTable(List<String> columnHeaders) {
509 StringBuilder htmlOutput =
new StringBuilder();
510 htmlOutput.append(
"<table>\n<thead>\n\t<tr>\n");
513 for (String columnHeader : columnHeaders) {
514 htmlOutput.append(
"\t\t<th>").append(columnHeader).append(
"</th>\n");
518 htmlOutput.append(
"\t\t<th></th>\n");
520 htmlOutput.append(
"\t</tr>\n</thead>\n");
523 out.write(htmlOutput.toString());
524 }
catch (IOException ex) {
525 logger.log(Level.SEVERE,
"Failed to write table start: {0}", ex);
533 public void endTable() {
535 out.write(
"</table>\n");
536 }
catch (IOException ex) {
537 logger.log(Level.SEVERE,
"Failed to write end of table: {0}", ex);
547 public void addRow(List<String> row) {
548 StringBuilder builder =
new StringBuilder();
549 builder.append(
"\t<tr>\n");
550 for (String cell : row) {
551 builder.append(
"\t\t<td>").append(cell).append(
"</td>\n");
553 builder.append(
"\t</tr>\n");
557 out.write(builder.toString());
558 }
catch (IOException ex) {
559 logger.log(Level.SEVERE,
"Failed to write row to out.", ex);
560 }
catch (NullPointerException ex) {
561 logger.log(Level.SEVERE,
"Output writer is null. Page was not initialized before writing.", ex);
575 public void addRowWithTaggedContentHyperlink(List<String> row, ContentTag contentTag) {
576 Content content = contentTag.getContent();
577 if (content instanceof AbstractFile ==
false) {
581 AbstractFile file = (AbstractFile) content;
583 StringBuilder localFileLink =
new StringBuilder();
586 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS
587 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS)) {
588 localFileLink.append(
"<a href=\"");
590 String localFilePath = saveContent(file, contentTag.getName().getDisplayName());
591 localFileLink.append(localFilePath);
592 localFileLink.append(
"\" target=\"_top\">");
595 StringBuilder builder =
new StringBuilder();
596 builder.append(
"\t<tr>\n");
597 int positionCounter = 0;
598 for (String cell : row) {
600 if (positionCounter == 1) {
601 builder.append(
"\t\t<td class=\"left_align_cell\">").append(localFileLink.toString()).append(cell).append(
"</a></td>\n");
602 }
else if (positionCounter == 7) {
603 builder.append(
"\t\t<td class=\"right_align_cell\">").append(cell).append(
"</td>\n");
605 builder.append(
"\t\t<td>").append(cell).append(
"</td>\n");
609 builder.append(
"\t</tr>\n");
613 out.write(builder.toString());
614 }
catch (IOException ex) {
615 logger.log(Level.SEVERE,
"Failed to write row to out.", ex);
616 }
catch (NullPointerException ex) {
617 logger.log(Level.SEVERE,
"Output writer is null. Page was not initialized before writing.", ex);
626 public void addThumbnailRows(Set<Content> images) {
627 List<String> currentRow =
new ArrayList<>();
630 for (Content content : images) {
631 if (currentRow.size() == THUMBNAIL_COLUMNS) {
636 if (totalCount == MAX_THUMBS_PER_PAGE) {
640 rowCount = totalCount;
645 startDataType(NbBundle.getMessage(
this.getClass(),
"ReportHTML.addThumbRows.dataType.title", pages),
646 NbBundle.getMessage(
this.getClass(),
"ReportHTML.addThumbRows.dataType.msg"));
647 List<String> emptyHeaders =
new ArrayList<>();
648 for (
int i = 0; i < THUMBNAIL_COLUMNS; i++) {
649 emptyHeaders.add(
"");
651 startTable(emptyHeaders);
654 if (failsContentCheck(content)) {
658 AbstractFile file = (AbstractFile) content;
661 String thumbnailPath = prepareThumbnail(file);
662 if (thumbnailPath == null) {
665 String contentPath = saveContent(file,
"thumbs_fullsize");
668 nameInImage = file.getUniquePath();
669 }
catch (TskCoreException ex) {
670 nameInImage = file.getName();
673 StringBuilder linkToThumbnail =
new StringBuilder();
674 linkToThumbnail.append(
"<div id='thumbnail_link'>");
675 linkToThumbnail.append(
"<a href=\"");
676 linkToThumbnail.append(contentPath);
677 linkToThumbnail.append(
"\" target=\"_top\">");
678 linkToThumbnail.append(
"<img src=\"").append(thumbnailPath).append(
"\" title=\"").append(nameInImage).append(
"\"/>");
679 linkToThumbnail.append(
"</a><br>");
680 linkToThumbnail.append(file.getName()).append(
"<br>");
682 Services services = currentCase.getServices();
683 TagsManager tagsManager = services.getTagsManager();
685 List<ContentTag> tags = tagsManager.getContentTagsByContent(content);
686 if (tags.size() > 0) {
687 linkToThumbnail.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.thumbLink.tags"));
689 for (
int i = 0; i < tags.size(); i++) {
690 ContentTag tag = tags.get(i);
691 linkToThumbnail.append(tag.getName().getDisplayName());
692 if (i != tags.size() - 1) {
693 linkToThumbnail.append(
", ");
696 }
catch (TskCoreException ex) {
697 logger.log(Level.WARNING,
"Could not find get tags for file.", ex);
699 linkToThumbnail.append(
"</div>");
700 currentRow.add(linkToThumbnail.toString());
705 if (currentRow.isEmpty() ==
false) {
706 int extraCells = THUMBNAIL_COLUMNS - currentRow.size();
707 for (
int i = 0; i < extraCells; i++) {
715 rowCount = totalCount;
718 private boolean failsContentCheck(Content c) {
719 if (c instanceof AbstractFile ==
false) {
722 AbstractFile file = (AbstractFile) c;
724 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS
725 || file.getType() == TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS) {
740 public String saveContent(AbstractFile file, String dirName) {
745 StringBuilder localFilePath =
new StringBuilder();
747 localFilePath.append(path);
748 localFilePath.append(dirName2);
749 File localFileFolder =
new File(localFilePath.toString());
750 if (!localFileFolder.exists()) {
751 localFileFolder.mkdirs();
755 String fileName = file.getName();
756 String objectIdSuffix =
"_" + file.getId();
757 int lastDotIndex = fileName.lastIndexOf(
".");
758 if (lastDotIndex != -1 && lastDotIndex != 0) {
760 fileName = fileName.substring(0, lastDotIndex) + objectIdSuffix + fileName.substring(lastDotIndex, fileName.length());
764 fileName += objectIdSuffix;
766 localFilePath.append(File.separator);
767 localFilePath.append(fileName);
771 File localFile =
new File(localFilePath.toString());
772 if (!localFile.exists()) {
773 ExtractFscContentVisitor.extract(file, localFile, null, null);
777 return localFilePath.toString().substring(path.length());
788 public String dateToString(
long date) {
789 SimpleDateFormat sdf =
new java.text.SimpleDateFormat(
"yyyy/MM/dd HH:mm:ss");
790 return sdf.format(
new java.util.Date(date * 1000));
794 public String getRelativeFilePath() {
795 return "HTML Report" + File.separator +
"index.html";
799 public String getName() {
800 return NbBundle.getMessage(this.getClass(),
"ReportHTML.getName.text");
804 public String getDescription() {
805 return NbBundle.getMessage(this.getClass(),
"ReportHTML.getDesc.text");
811 private void writeCss() {
812 Writer cssOut = null;
814 cssOut =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(path +
"index.css"),
"UTF-8"));
815 String css =
"body {margin: 0px; padding: 0px; background: #FFFFFF; font: 13px/20px Arial, Helvetica, sans-serif; color: #535353;}\n"
817 "#content {padding: 30px;}\n"
819 "#header {width:100%; padding: 10px; line-height: 25px; background: #07A; color: #FFF; font-size: 20px;}\n"
821 "h1 {font-size: 20px; font-weight: normal; color: #07A; padding: 0 0 7px 0; margin-top: 25px; border-bottom: 1px solid #D6D6D6;}\n"
823 "h2 {font-size: 20px; font-weight: bolder; color: #07A;}\n"
825 "h3 {font-size: 16px; color: #07A;}\n"
827 "h4 {background: #07A; color: #FFF; font-size: 16px; margin: 0 0 0 25px; padding: 0; padding-left: 15px;}\n"
829 "ul.nav {list-style-type: none; line-height: 35px; padding: 0px; margin-left: 15px;}\n"
831 "ul li a {font-size: 14px; color: #444; text-decoration: none; padding-left: 25px;}\n"
833 "ul li a:hover {text-decoration: underline;}\n"
835 "p {margin: 0 0 20px 0;}\n"
837 "table {white-space:nowrap; min-width: 700px; padding: 2; margin: 0; border-collapse: collapse; border-bottom: 2px solid #e5e5e5;}\n"
839 ".keyword_list table {margin: 0 0 25px 25px; border-bottom: 2px solid #dedede;}\n"
841 "table th {white-space:nowrap; display: table-cell; text-align: center; padding: 2px 4px; background: #e5e5e5; color: #777; font-size: 11px; text-shadow: #e9f9fd 0 1px 0; border-top: 1px solid #dedede; border-bottom: 2px solid #e5e5e5;}\n"
843 "table .left_align_cell{display: table-cell; padding: 2px 4px; font: 13px/20px Arial, Helvetica, sans-serif; min-width: 125px; overflow: auto; text-align: left; }\n"
845 "table .right_align_cell{display: table-cell; padding: 2px 4px; font: 13px/20px Arial, Helvetica, sans-serif; min-width: 125px; overflow: auto; text-align: right; }\n"
847 "table td {white-space:nowrap; display: table-cell; padding: 2px 3px; font: 13px/20px Arial, Helvetica, sans-serif; min-width: 125px; overflow: auto; text-align:left; vertical-align: text-top;}\n"
849 "table tr:nth-child(even) td {background: #f3f3f3;}\n"
851 "div#thumbnail_link {max-width: 200px; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;}";
853 }
catch (FileNotFoundException ex) {
854 logger.log(Level.SEVERE,
"Could not find index.css file to write to.", ex);
855 }
catch (UnsupportedEncodingException ex) {
856 logger.log(Level.SEVERE,
"Did not recognize encoding when writing index.css.", ex);
857 }
catch (IOException ex) {
858 logger.log(Level.SEVERE,
"Error creating Writer for index.css.", ex);
861 if (cssOut != null) {
865 }
catch (IOException ex) {
873 private void writeIndex() {
874 Writer indexOut = null;
875 String indexFilePath = path +
"index.html";
877 indexOut =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(indexFilePath),
"UTF-8"));
878 StringBuilder index =
new StringBuilder();
879 final String reportTitle = reportBranding.getReportTitle();
880 String iconPath = reportBranding.getAgencyLogoPath();
881 if (iconPath == null) {
883 iconPath =
"favicon.ico";
885 iconPath = Paths.get(reportBranding.getAgencyLogoPath()).getFileName().toString();
887 index.append(
"<head>\n<title>").append(reportTitle).append(
" ").append(
888 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.title", currentCase.getDisplayName())).append(
890 index.append(
"<link rel=\"icon\" type=\"image/ico\" href=\"")
891 .append(iconPath).append(
"\" />\n");
892 index.append(
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
893 index.append(
"</head>\n");
894 index.append(
"<frameset cols=\"350px,*\">\n");
895 index.append(
"<frame src=\"nav.html\" name=\"nav\">\n");
896 index.append(
"<frame src=\"summary.html\" name=\"content\">\n");
897 index.append(
"<noframes>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.noFrames.msg")).append(
"<br />\n");
898 index.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.noFrames.seeNav")).append(
"<br />\n");
899 index.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeIndex.seeSum")).append(
"</noframes>\n");
900 index.append(
"</frameset>\n");
901 index.append(
"</html>");
902 indexOut.write(index.toString());
903 Case.getCurrentCase().addReport(indexFilePath, NbBundle.getMessage(
this.getClass(),
904 "ReportHTML.writeIndex.srcModuleName.text"),
"");
905 }
catch (IOException ex) {
906 logger.log(Level.SEVERE,
"Error creating Writer for index.html: {0}", ex);
907 }
catch (TskCoreException ex) {
908 String errorMessage = String.format(
"Error adding %s to case as a report", indexFilePath);
909 logger.log(Level.SEVERE, errorMessage, ex);
912 if (indexOut != null) {
916 }
catch (IOException ex) {
924 private void writeNav() {
925 Writer navOut = null;
927 navOut =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(path +
"nav.html"),
"UTF-8"));
928 StringBuilder nav =
new StringBuilder();
929 nav.append(
"<html>\n<head>\n\t<title>").append(
930 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeNav.title"))
931 .append(
"</title>\n\t<link rel=\"stylesheet\" type=\"text/css\" href=\"index.css\" />\n");
932 nav.append(
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n</head>\n<body>\n");
933 nav.append(
"<div id=\"content\">\n<h1>").append(
934 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeNav.h1")).append(
"</h1>\n");
935 nav.append(
"<ul class=\"nav\">\n");
936 nav.append(
"<li style=\"background: url(summary.png) left center no-repeat;\"><a href=\"summary.html\" target=\"content\">")
937 .append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeNav.summary")).append(
"</a></li>\n");
939 for (String dataType : dataTypes.keySet()) {
940 String dataTypeEsc = dataTypeToFileName(dataType);
941 String iconFileName = useDataTypeIcon(dataType);
942 nav.append(
"<li style=\"background: url('").append(iconFileName)
943 .append(
"') left center no-repeat;\"><a href=\"")
944 .append(dataTypeEsc).append(
".html\" target=\"content\">")
945 .append(dataType).append(
" (").append(dataTypes.get(dataType))
946 .append(
")</a></li>\n");
948 nav.append(
"</ul>\n");
949 nav.append(
"</div>\n</body>\n</html>");
950 navOut.write(nav.toString());
951 }
catch (IOException ex) {
952 logger.log(Level.SEVERE,
"Failed to write end of report navigation menu: {0}", ex);
954 if (navOut != null) {
958 }
catch (IOException ex) {
959 logger.log(Level.WARNING,
"Could not close navigation out writer.");
964 InputStream in = null;
965 OutputStream output = null;
969 String generatorLogoPath = reportBranding.getGeneratorLogoPath();
970 if (generatorLogoPath != null && !generatorLogoPath.isEmpty()) {
971 File from =
new File(generatorLogoPath);
972 File to =
new File(path);
973 FileUtil.copyFile(FileUtil.toFileObject(from), FileUtil.toFileObject(to),
"generator_logo");
976 String agencyLogoPath = reportBranding.getAgencyLogoPath();
977 if (agencyLogoPath != null && !agencyLogoPath.isEmpty()) {
978 Path destinationPath = Paths.get(path);
979 Files.copy(Files.newInputStream(Paths.get(agencyLogoPath)), destinationPath.resolve(Paths.get(agencyLogoPath).getFileName()));
982 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/favicon.ico");
983 output =
new FileOutputStream(
new File(path + File.separator +
"favicon.ico"));
984 FileUtil.copy(in, output);
988 in = getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/report/images/summary.png");
989 output =
new FileOutputStream(
new File(path + File.separator +
"summary.png"));
990 FileUtil.copy(in, output);
994 }
catch (IOException ex) {
995 logger.log(Level.SEVERE,
"Failed to extract images for HTML report.", ex);
997 if (output != null) {
1001 }
catch (IOException ex) {
1007 }
catch (IOException ex) {
1016 private void writeSummary() {
1019 out =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(path +
"summary.html"),
"UTF-8"));
1020 StringBuilder head =
new StringBuilder();
1021 head.append(
"<html>\n<head>\n<title>").append(
1022 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.title")).append(
"</title>\n");
1023 head.append(
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
1024 head.append(
"<style type=\"text/css\">\n");
1025 head.append(
"body { padding: 0px; margin: 0px; font: 13px/20px Arial, Helvetica, sans-serif; color: #535353; }\n");
1026 head.append(
"#wrapper { width: 90%; margin: 0px auto; margin-top: 35px; }\n");
1027 head.append(
"h1 { color: #07A; font-size: 36px; line-height: 42px; font-weight: normal; margin: 0px; border-bottom: 1px solid #81B9DB; }\n");
1028 head.append(
"h1 span { color: #F00; display: block; font-size: 16px; font-weight: bold; line-height: 22px;}\n");
1029 head.append(
"h2 { padding: 0 0 3px 0; margin: 0px; color: #07A; font-weight: normal; border-bottom: 1px dotted #81B9DB; }\n");
1030 head.append(
"table td { padding-right: 25px; }\n");
1031 head.append(
"p.subheadding { padding: 0px; margin: 0px; font-size: 11px; color: #B5B5B5; }\n");
1032 head.append(
".title { width: 660px; margin-bottom: 50px; }\n");
1033 head.append(
".left { float: left; width: 250px; margin-top: 20px; text-align: center; }\n");
1034 head.append(
".left img { max-width: 250px; max-height: 250px; min-width: 200px; min-height: 200px; }\n");
1035 head.append(
".right { float: right; width: 385px; margin-top: 25px; font-size: 14px; }\n");
1036 head.append(
".clear { clear: both; }\n");
1037 head.append(
".info p { padding: 3px 10px; background: #e5e5e5; color: #777; font-size: 12px; font-weight: bold; text-shadow: #e9f9fd 0 1px 0; border-top: 1px solid #dedede; border-bottom: 2px solid #dedede; }\n");
1038 head.append(
".info table { margin: 0 25px 20px 25px; }\n");
1039 head.append(
"</style>\n");
1040 head.append(
"</head>\n<body>\n");
1041 out.write(head.toString());
1043 DateFormat datetimeFormat =
new SimpleDateFormat(
"yyyy/MM/dd HH:mm:ss");
1044 Date date =
new Date();
1045 String datetime = datetimeFormat.format(date);
1047 String caseName = currentCase.getDisplayName();
1048 String caseNumber = currentCase.getNumber();
1049 String examiner = currentCase.getExaminer();
1052 imagecount = currentCase.getDataSources().size();
1053 }
catch (TskCoreException ex) {
1057 StringBuilder summary =
new StringBuilder();
1058 boolean running =
false;
1059 if (IngestManager.getInstance().isIngestRunning()) {
1063 final String reportTitle = reportBranding.getReportTitle();
1064 final String reportFooter = reportBranding.getReportFooter();
1065 final boolean agencyLogoSet = reportBranding.getAgencyLogoPath() != null && !reportBranding.getAgencyLogoPath().isEmpty();
1066 final boolean generatorLogoSet = reportBranding.getGeneratorLogoPath() != null && !reportBranding.getGeneratorLogoPath().isEmpty();
1068 summary.append(
"<div id=\"wrapper\">\n");
1069 summary.append(
"<h1>").append(reportTitle)
1070 .append(running ? NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.warningMsg") :
"")
1072 summary.append(
"<p class=\"subheadding\">").append(
1073 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.reportGenOn.text", datetime)).append(
"</p>\n");
1074 summary.append(
"<div class=\"title\">\n");
1075 if (agencyLogoSet) {
1076 summary.append(
"<div class=\"left\">\n");
1077 summary.append(
"<img src=\"");
1078 summary.append(Paths.get(reportBranding.getAgencyLogoPath()).getFileName().toString());
1079 summary.append(
"\" />\n");
1080 summary.append(
"</div>\n");
1082 final String align = agencyLogoSet ?
"right" :
"left";
1083 summary.append(
"<div class=\"").append(align).append(
"\">\n");
1084 summary.append(
"<table>\n");
1085 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.caseName"))
1086 .append(
"</td><td>").append(caseName).append(
"</td></tr>\n");
1087 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.caseNum"))
1088 .append(
"</td><td>").append(!caseNumber.isEmpty() ? caseNumber : NbBundle
1089 .getMessage(this.getClass(),
"ReportHTML.writeSum.noCaseNum")).append(
"</td></tr>\n");
1090 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.examiner")).append(
"</td><td>")
1091 .append(!examiner.isEmpty() ? examiner : NbBundle
1092 .getMessage(this.getClass(),
"ReportHTML.writeSum.noExaminer"))
1093 .append(
"</td></tr>\n");
1094 summary.append(
"<tr><td>").append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.numImages"))
1095 .append(
"</td><td>").append(imagecount).append(
"</td></tr>\n");
1096 summary.append(
"</table>\n");
1097 summary.append(
"</div>\n");
1098 summary.append(
"<div class=\"clear\"></div>\n");
1099 summary.append(
"</div>\n");
1100 summary.append(NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.imageInfoHeading"));
1101 summary.append(
"<div class=\"info\">\n");
1103 for (Content c : currentCase.getDataSources()) {
1104 summary.append(
"<p>").append(c.getName()).append(
"</p>\n");
1105 if (c instanceof Image) {
1106 Image img = (Image) c;
1108 summary.append(
"<table>\n");
1109 summary.append(
"<tr><td>").append(
1110 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.timezone"))
1111 .append(
"</td><td>").append(img.getTimeZone()).append(
"</td></tr>\n");
1112 for (String imgPath : img.getPaths()) {
1113 summary.append(
"<tr><td>").append(
1114 NbBundle.getMessage(
this.getClass(),
"ReportHTML.writeSum.path"))
1115 .append(
"</td><td>").append(imgPath).append(
"</td></tr>\n");
1117 summary.append(
"</table>\n");
1120 }
catch (TskCoreException ex) {
1121 logger.log(Level.WARNING,
"Unable to get image information for the HTML report.");
1123 summary.append(
"</div>\n");
1124 if (generatorLogoSet) {
1125 summary.append(
"<div class=\"left\">\n");
1126 summary.append(
"<img src=\"generator_logo.png\" />\n");
1127 summary.append(
"</div>\n");
1129 summary.append(
"<div class=\"clear\"></div>\n");
1130 if (reportFooter != null) {
1131 summary.append(
"<p class=\"subheadding\">").append(reportFooter).append(
"</p>\n");
1133 summary.append(
"</div>\n");
1134 summary.append(
"</body></html>");
1135 out.write(summary.toString());
1136 }
catch (FileNotFoundException ex) {
1137 logger.log(Level.SEVERE,
"Could not find summary.html file to write to.");
1138 }
catch (UnsupportedEncodingException ex) {
1139 logger.log(Level.SEVERE,
"Did not recognize encoding when writing summary.hmtl.");
1140 }
catch (IOException ex) {
1141 logger.log(Level.SEVERE,
"Error creating Writer for summary.html.");
1148 }
catch (IOException ex) {
1153 private String prepareThumbnail(AbstractFile file) {
1154 BufferedImage bufferedThumb = ImageUtils.getThumbnail(file, ImageUtils.ICON_SIZE_MEDIUM);
1155 File thumbFile = Paths.get(thumbsPath, file.getName() +
".png").toFile();
1156 if (bufferedThumb == null) {
1160 ImageIO.write(bufferedThumb,
"png", thumbFile);
1161 }
catch (IOException ex) {
1162 logger.log(Level.WARNING,
"Failed to write thumb file to report directory.", ex);
1165 if (thumbFile.exists()
1169 return THUMBS_REL_PATH
1170 + thumbFile.getName();
static String escapeFileName(String fileName)