19 package org.sleuthkit.autopsy.casemodule;
22 import java.io.IOException;
23 import java.nio.file.Path;
24 import java.nio.file.Paths;
25 import java.sql.Connection;
26 import java.sql.DriverManager;
27 import java.sql.PreparedStatement;
28 import java.sql.ResultSet;
29 import java.sql.ResultSetMetaData;
30 import java.sql.SQLException;
31 import java.sql.Statement;
32 import java.text.SimpleDateFormat;
33 import java.util.Date;
34 import org.apache.commons.io.FileUtils;
35 import org.openide.util.NbBundle;
72 private final CaseDbConnectionInfo
db;
83 boolean copySourceImages,
86 this.imageInputFolder = imageInput;
87 this.caseInputFolder = caseInput;
88 this.imageOutputFolder = imageOutput;
89 this.caseOutputFolder = caseOutput;
107 Path getImageInputFolder() {
111 Path getImageOutputFolder() {
115 String getOldCaseName() {
119 String getNewCaseName() {
123 boolean getCopySourceImages() {
127 boolean getDeleteCase() {
131 String getPostgreSQLDbName() {
135 String getAutFileName() {
139 String getRawFolderName() {
143 CaseDbConnectionInfo getDb() {
147 void setPostgreSQLDbName(String dbName) {
148 this.postgreSQLDbName = dbName;
163 Class.forName(
"org.postgresql.Driver");
166 Path oldDatabasePath = icd.getCaseInputFolder().resolve(AUTOPSY_DB_FILE);
167 if (
false == oldDatabasePath.toFile().exists()) {
168 throw new Exception(NbBundle.getMessage(
SingleUserCaseConverter.class,
"SingleUserCaseConverter.BadDatabaseFileName"));
174 throw new Exception(NbBundle.getMessage(
SingleUserCaseConverter.class,
"SingleUserCaseConverter.AlreadyMultiUser"));
184 SimpleDateFormat dateFormat =
new SimpleDateFormat(
"yyyyMMdd_HHmmss");
185 Date date =
new Date();
186 String dbName = icd.getNewCaseName() +
"_" + dateFormat.format(date);
187 icd.setPostgreSQLDbName(dbName);
203 icd.getCaseOutputFolder().toString(),
204 icd.getNewCaseName(),
211 newCaseMetadata.setCaseDatabaseName(dbName);
213 newCaseMetadata.setCreatedDate(oldCaseMetadata.getCreatedDate());
214 newCaseMetadata.setCreatedByVersion(oldCaseMetadata.getCreatedByVersion());
220 if (icd.getDeleteCase()) {
221 FileUtils.deleteDirectory(icd.getCaseInputFolder().toFile());
234 File thePath = icd.getImageInputFolder().resolve(icd.getOldCaseName()).toFile();
235 if (thePath.isDirectory()) {
239 thePath = icd.getImageInputFolder().resolve(icd.getRawFolderName()).toFile();
240 if (thePath.isDirectory()) {
244 return icd.getImageInputFolder().toFile();
260 Path source = icd.getCaseInputFolder();
261 if (source.toFile().exists()) {
262 destination = icd.getCaseOutputFolder().resolve(hostName);
263 FileUtils.copyDirectory(source.toFile(), destination.toFile());
266 source = icd.getCaseInputFolder().resolve(TIMELINE_FILE);
267 if (source.toFile().exists()) {
269 FileUtils.copyFile(source.toFile(), destination.toFile());
273 File oldAutopsyFile = Paths.get(icd.getCaseOutputFolder().toString(), hostName, icd.getOldCaseName() +
DOTAUT).toFile();
274 if (oldAutopsyFile.exists()) {
275 oldAutopsyFile.delete();
279 File oldDatabaseFile = Paths.get(icd.getCaseOutputFolder().toString(), hostName,
AUTOPSY_DB_FILE).toFile();
280 if (oldDatabaseFile.exists()) {
281 oldDatabaseFile.delete();
285 File oldTimelineFile = Paths.get(icd.getCaseOutputFolder().toString(), hostName,
TIMELINE_FILE).toFile();
286 if (oldTimelineFile.exists()) {
287 oldTimelineFile.delete();
307 SleuthkitCase newCase = SleuthkitCase.newCase(icd.getPostgreSQLDbName(), icd.getDb(), icd.getCaseOutputFolder().toString());
311 Class.forName(
"org.sqlite.JDBC");
316 Statement inputStatement = sqliteConnection.createStatement();
317 ResultSet inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_artifact_types");
318 Statement outputStatement;
319 Statement numberingPK;
322 while (inputResultSet.next()) {
324 long value = inputResultSet.getLong(1);
325 if (value > biggestPK) {
328 Statement check = postgreSQLConnection.createStatement();
329 ResultSet checkResult = check.executeQuery(
"SELECT * FROM blackboard_artifact_types WHERE artifact_type_id=" + value +
" AND type_name LIKE '" + inputResultSet.getString(2) +
"' AND display_name LIKE '" + inputResultSet.getString(3) +
"'");
330 if (!checkResult.isBeforeFirst()) {
331 String sql =
"INSERT INTO blackboard_artifact_types (artifact_type_id, type_name, display_name) VALUES ("
333 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(2)) +
"',"
335 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
339 }
catch (SQLException ex) {
340 if (ex.getErrorCode() != 0) {
341 throw new SQLException(ex);
345 numberingPK = postgreSQLConnection.createStatement();
346 numberingPK.execute(
"ALTER SEQUENCE blackboard_artifact_types_artifact_type_id_seq RESTART WITH " + (biggestPK + 1));
350 inputStatement = sqliteConnection.createStatement();
351 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_attribute_types");
353 while (inputResultSet.next()) {
355 long value = inputResultSet.getLong(1);
356 if (value > biggestPK) {
359 Statement check = postgreSQLConnection.createStatement();
360 ResultSet checkResult = check.executeQuery(
"SELECT * FROM blackboard_attribute_types WHERE attribute_type_id=" + value +
" AND type_name LIKE '" + inputResultSet.getString(2) +
"' AND display_name LIKE '" + inputResultSet.getString(3) +
"'");
361 if (!checkResult.isBeforeFirst()) {
362 String sql =
"INSERT INTO blackboard_attribute_types (attribute_type_id, type_name, display_name) VALUES ("
364 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(2)) +
"',"
367 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
371 }
catch (SQLException ex) {
372 if (ex.getErrorCode() != 0) {
373 throw new SQLException(ex);
377 numberingPK = postgreSQLConnection.createStatement();
378 numberingPK.execute(
"ALTER SEQUENCE blackboard_attribute_types_attribute_type_id_seq RESTART WITH " + (biggestPK + 1));
382 inputStatement = sqliteConnection.createStatement();
383 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_objects");
385 while (inputResultSet.next()) {
386 outputStatement = postgreSQLConnection.createStatement();
388 long value = inputResultSet.getLong(1);
389 if (value > biggestPK) {
392 outputStatement.executeUpdate(
"INSERT INTO tsk_objects (obj_id, par_obj_id, type) VALUES ("
395 + inputResultSet.getInt(3) +
")");
396 }
catch (SQLException ex) {
397 if (ex.getErrorCode() != 0) {
398 throw new SQLException(ex);
402 numberingPK = postgreSQLConnection.createStatement();
403 numberingPK.execute(
"ALTER SEQUENCE tsk_objects_obj_id_seq RESTART WITH " + (biggestPK + 1));
406 inputStatement = sqliteConnection.createStatement();
407 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_image_names");
409 while (inputResultSet.next()) {
410 outputStatement = postgreSQLConnection.createStatement();
412 outputStatement.executeUpdate(
"INSERT INTO tsk_image_names (obj_id, name, sequence) VALUES ("
413 + inputResultSet.getLong(1) +
",'"
414 + inputResultSet.getString(2) +
"',"
415 + inputResultSet.getInt(3) +
")");
416 }
catch (SQLException ex) {
417 if (ex.getErrorCode() != 0) {
418 throw new SQLException(ex);
425 inputStatement = sqliteConnection.createStatement();
426 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_image_info");
428 while (inputResultSet.next()) {
430 long value = inputResultSet.getLong(1);
431 if (value > biggestPK) {
434 String sql =
"INSERT INTO tsk_image_info (obj_id, type, ssize, tzone, size, md5, display_name) VALUES ("
443 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
449 }
catch (SQLException ex) {
450 if (ex.getErrorCode() != 0) {
451 throw new SQLException(ex);
455 numberingPK = postgreSQLConnection.createStatement();
456 numberingPK.execute(
"ALTER SEQUENCE tsk_image_info_obj_id_seq RESTART WITH " + (biggestPK + 1));
460 inputStatement = sqliteConnection.createStatement();
461 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_fs_info");
463 while (inputResultSet.next()) {
465 long value = inputResultSet.getLong(1);
466 if (value > biggestPK) {
469 String sql =
"INSERT INTO tsk_fs_info (obj_id, img_offset, fs_type, block_size, block_count, root_inum, first_inum, last_inum, display_name) VALUES ("
471 + inputResultSet.getLong(2) +
","
472 + inputResultSet.getInt(3) +
","
473 + inputResultSet.getLong(4) +
","
474 + inputResultSet.getLong(5) +
","
475 + inputResultSet.getLong(6) +
","
476 + inputResultSet.getLong(7) +
","
477 + inputResultSet.getLong(8) +
","
480 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
484 }
catch (SQLException ex) {
485 if (ex.getErrorCode() != 0) {
486 throw new SQLException(ex);
490 numberingPK = postgreSQLConnection.createStatement();
491 numberingPK.execute(
"ALTER SEQUENCE tsk_fs_info_obj_id_seq RESTART WITH " + (biggestPK + 1));
495 inputStatement = sqliteConnection.createStatement();
496 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_files_path");
498 while (inputResultSet.next()) {
499 outputStatement = postgreSQLConnection.createStatement();
501 long value = inputResultSet.getLong(1);
502 if (value > biggestPK) {
508 int encoding = TskData.EncodingType.NONE.getType();
509 ResultSetMetaData rsMetaData = inputResultSet.getMetaData();
510 if (rsMetaData.getColumnCount() == 3) {
511 encoding = inputResultSet.getInt(3);
513 outputStatement.executeUpdate(
"INSERT INTO tsk_files_path (obj_id, path, encoding_type) VALUES ("
515 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(2)) +
"', "
517 }
catch (SQLException ex) {
518 if (ex.getErrorCode() != 0) {
519 throw new SQLException(ex);
523 numberingPK = postgreSQLConnection.createStatement();
524 numberingPK.execute(
"ALTER SEQUENCE tsk_files_path_obj_id_seq RESTART WITH " + (biggestPK + 1));
528 inputStatement = sqliteConnection.createStatement();
529 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_files");
531 while (inputResultSet.next()) {
533 long value = inputResultSet.getLong(1);
534 if (value > biggestPK) {
537 String sql =
"INSERT INTO tsk_files (obj_id, fs_obj_id, attr_type, attr_id, name, meta_addr, meta_seq, type, has_layout, has_path, dir_type, meta_type, dir_flags, meta_flags, size, ctime, crtime, atime, mtime, mode, uid, gid, md5, known, parent_path) VALUES ("
542 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(5)) +
"',"
564 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
569 }
catch (SQLException ex) {
570 if (ex.getErrorCode() != 0) {
571 throw new SQLException(ex);
575 numberingPK = postgreSQLConnection.createStatement();
576 numberingPK.execute(
"ALTER SEQUENCE tsk_files_obj_id_seq RESTART WITH " + (biggestPK + 1));
579 inputStatement = sqliteConnection.createStatement();
580 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_file_layout");
582 while (inputResultSet.next()) {
583 outputStatement = postgreSQLConnection.createStatement();
585 outputStatement.executeUpdate(
"INSERT INTO tsk_file_layout (obj_id, byte_start, byte_len, sequence) VALUES ("
586 + inputResultSet.getLong(1) +
","
587 + inputResultSet.getLong(2) +
","
588 + inputResultSet.getLong(3) +
","
589 + inputResultSet.getInt(4) +
")");
590 }
catch (SQLException ex) {
591 if (ex.getErrorCode() != 0) {
592 throw new SQLException(ex);
598 inputStatement = sqliteConnection.createStatement();
599 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_db_info");
601 while (inputResultSet.next()) {
602 outputStatement = postgreSQLConnection.createStatement();
604 Statement check = postgreSQLConnection.createStatement();
605 ResultSet checkResult = check.executeQuery(
"SELECT * FROM tsk_db_info WHERE schema_ver=" + inputResultSet.getInt(1) +
" AND tsk_ver=" + inputResultSet.getInt(2));
606 if (!checkResult.isBeforeFirst()) {
607 outputStatement.executeUpdate(
"INSERT INTO tsk_db_info (schema_ver, tsk_ver) VALUES ("
611 }
catch (SQLException ex) {
612 if (ex.getErrorCode() != 0) {
613 throw new SQLException(ex);
620 inputStatement = sqliteConnection.createStatement();
621 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tag_names");
623 while (inputResultSet.next()) {
625 long value = inputResultSet.getLong(1);
626 if (value > biggestPK) {
629 String sql =
"INSERT INTO tag_names (tag_name_id, display_name, description, color) VALUES ("
632 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(3)) +
"','"
633 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(4)) +
"')";
635 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
639 }
catch (SQLException ex) {
640 if (ex.getErrorCode() != 0) {
641 throw new SQLException(ex);
645 numberingPK = postgreSQLConnection.createStatement();
646 numberingPK.execute(
"ALTER SEQUENCE tag_names_tag_name_id_seq RESTART WITH " + (biggestPK + 1));
650 inputStatement = sqliteConnection.createStatement();
651 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM reports");
653 while (inputResultSet.next()) {
654 outputStatement = postgreSQLConnection.createStatement();
656 long value = inputResultSet.getLong(1);
657 if (value > biggestPK) {
660 outputStatement.executeUpdate(
"INSERT INTO reports (report_id, path, crtime, src_module_name, report_name) VALUES ("
662 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(2)) +
"',"
663 + inputResultSet.getInt(3) +
",'"
664 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(4)) +
"','"
665 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(5)) +
"')");
667 }
catch (SQLException ex) {
668 if (ex.getErrorCode() != 0) {
669 throw new SQLException(ex);
673 numberingPK = postgreSQLConnection.createStatement();
674 numberingPK.execute(
"ALTER SEQUENCE reports_report_id_seq RESTART WITH " + (biggestPK + 1));
677 biggestPK = Long.MIN_VALUE;
678 inputStatement = sqliteConnection.createStatement();
679 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_artifacts");
681 while (inputResultSet.next()) {
682 outputStatement = postgreSQLConnection.createStatement();
684 long value = inputResultSet.getLong(1);
685 if (value > biggestPK) {
688 outputStatement.executeUpdate(
"INSERT INTO blackboard_artifacts (artifact_id, obj_id, artifact_type_id) VALUES ("
690 + inputResultSet.getLong(2) +
","
691 + inputResultSet.getLong(3) +
")");
693 }
catch (SQLException ex) {
694 if (ex.getErrorCode() != 0) {
695 throw new SQLException(ex);
699 numberingPK = postgreSQLConnection.createStatement();
700 numberingPK.execute(
"ALTER SEQUENCE blackboard_artifacts_artifact_id_seq RESTART WITH " + (biggestPK + 1));
703 inputStatement = sqliteConnection.createStatement();
704 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_attributes");
706 while (inputResultSet.next()) {
708 String sql =
"INSERT INTO blackboard_attributes (artifact_id, artifact_type_id, source, context, attribute_type_id, value_type, value_byte, value_text, value_int32, value_int64, value_double) VALUES ("
709 + inputResultSet.getLong(1) +
","
710 + inputResultSet.getLong(2) +
","
713 + inputResultSet.getLong(5) +
","
714 + inputResultSet.getInt(6) +
","
720 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
728 }
catch (SQLException ex) {
729 if (ex.getErrorCode() != 0) {
730 throw new SQLException(ex);
737 inputStatement = sqliteConnection.createStatement();
738 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_vs_parts");
740 while (inputResultSet.next()) {
742 long value = inputResultSet.getLong(1);
743 if (value > biggestPK) {
746 String sql =
"INSERT INTO tsk_vs_parts (obj_id, addr, start, length, descr, flags) VALUES ("
748 + inputResultSet.getLong(2) +
","
749 + inputResultSet.getLong(3) +
","
750 + inputResultSet.getLong(4) +
","
752 + inputResultSet.getInt(6) +
")";
753 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
757 }
catch (SQLException ex) {
758 if (ex.getErrorCode() != 0) {
759 throw new SQLException(ex);
763 numberingPK = postgreSQLConnection.createStatement();
764 numberingPK.execute(
"ALTER SEQUENCE tsk_vs_parts_obj_id_seq RESTART WITH " + (biggestPK + 1));
768 inputStatement = sqliteConnection.createStatement();
769 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_vs_info");
771 while (inputResultSet.next()) {
772 outputStatement = postgreSQLConnection.createStatement();
774 long value = inputResultSet.getLong(1);
775 if (value > biggestPK) {
778 outputStatement.executeUpdate(
"INSERT INTO tsk_vs_info (obj_id, vs_type, img_offset, block_size) VALUES ("
780 + inputResultSet.getInt(2) +
","
781 + inputResultSet.getLong(3) +
","
782 + inputResultSet.getLong(4) +
")");
784 }
catch (SQLException ex) {
785 if (ex.getErrorCode() != 0) {
786 throw new SQLException(ex);
790 numberingPK = postgreSQLConnection.createStatement();
791 numberingPK.execute(
"ALTER SEQUENCE tsk_vs_info_obj_id_seq RESTART WITH " + (biggestPK + 1));
795 inputStatement = sqliteConnection.createStatement();
796 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_files_derived");
798 while (inputResultSet.next()) {
800 long value = inputResultSet.getLong(1);
801 if (value > biggestPK) {
804 String sql =
"INSERT INTO tsk_files_derived (obj_id, derived_id, rederive) VALUES ("
806 + inputResultSet.getLong(2) +
","
808 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
812 }
catch (SQLException ex) {
813 if (ex.getErrorCode() != 0) {
814 throw new SQLException(ex);
818 numberingPK = postgreSQLConnection.createStatement();
819 numberingPK.execute(
"ALTER SEQUENCE tsk_files_derived_obj_id_seq RESTART WITH " + (biggestPK + 1));
823 inputStatement = sqliteConnection.createStatement();
824 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_files_derived_method");
826 while (inputResultSet.next()) {
828 long value = inputResultSet.getLong(1);
829 if (value > biggestPK) {
832 String sql =
"INSERT INTO tsk_files_derived_method (derived_id, tool_name, tool_version, other) VALUES ("
834 + inputResultSet.getString(2) +
"','"
835 + inputResultSet.getString(3) +
"',"
837 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
841 }
catch (SQLException ex) {
842 if (ex.getErrorCode() != 0) {
843 throw new SQLException(ex);
847 numberingPK = postgreSQLConnection.createStatement();
848 numberingPK.execute(
"ALTER SEQUENCE tsk_files_derived_method_derived_id_seq RESTART WITH " + (biggestPK + 1));
852 inputStatement = sqliteConnection.createStatement();
853 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM content_tags");
855 while (inputResultSet.next()) {
856 outputStatement = postgreSQLConnection.createStatement();
858 long value = inputResultSet.getLong(1);
859 if (value > biggestPK) {
862 outputStatement.executeUpdate(
"INSERT INTO content_tags (tag_id, obj_id, tag_name_id, comment, begin_byte_offset, end_byte_offset) VALUES ("
864 + inputResultSet.getLong(2) +
","
865 + inputResultSet.getLong(3) +
",'"
866 + inputResultSet.getString(4) +
"',"
867 + inputResultSet.getLong(5) +
","
868 + inputResultSet.getLong(6) +
")");
870 }
catch (SQLException ex) {
871 if (ex.getErrorCode() != 0) {
872 throw new SQLException(ex);
876 numberingPK = postgreSQLConnection.createStatement();
877 numberingPK.execute(
"ALTER SEQUENCE content_tags_tag_id_seq RESTART WITH " + (biggestPK + 1));
881 inputStatement = sqliteConnection.createStatement();
882 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_artifact_tags");
884 while (inputResultSet.next()) {
885 outputStatement = postgreSQLConnection.createStatement();
887 long value = inputResultSet.getLong(1);
888 if (value > biggestPK) {
891 outputStatement.executeUpdate(
"INSERT INTO blackboard_artifact_tags (tag_id, artifact_id, tag_name_id, comment) VALUES ("
893 + inputResultSet.getLong(2) +
","
894 + inputResultSet.getLong(3) +
",'"
895 + inputResultSet.getString(4) +
"')");
897 }
catch (SQLException ex) {
898 if (ex.getErrorCode() != 0) {
899 throw new SQLException(ex);
903 numberingPK = postgreSQLConnection.createStatement();
904 numberingPK.execute(
"ALTER SEQUENCE blackboard_artifact_tags_tag_id_seq RESTART WITH " + (biggestPK + 1));
906 sqliteConnection.close();
907 postgreSQLConnection.close();
926 boolean unique =
false;
927 String sanitizedDbName = icd.getPostgreSQLDbName();
929 sanitizedDbName = sanitizedDbName.substring(0, MAX_DB_NAME_LENGTH);
932 if (postgreSQLConnection != null) {
933 while (unique ==
false) {
934 Statement st = postgreSQLConnection.createStatement();
935 ResultSet answer = st.executeQuery(
"SELECT datname FROM pg_catalog.pg_database WHERE LOWER(datname) LIKE LOWER('" + sanitizedDbName +
"%')");
937 if (!answer.next()) {
941 if (number == Integer.MAX_VALUE) {
943 throw new Exception(NbBundle.getMessage(
SingleUserCaseConverter.class,
"SingleUserCaseConverter.NonUniqueDatabaseName"));
945 sanitizedDbName =
"db_" + Integer.toString(number) +
"_" + icd.getPostgreSQLDbName();
949 sanitizedDbName = sanitizedDbName.substring(0, MAX_DB_NAME_LENGTH);
954 postgreSQLConnection.close();
960 icd.setPostgreSQLDbName(sanitizedDbName);
972 if (icd.getCopySourceImages()) {
974 File imageDestination =
new File(icd.getImageOutputFolder().toString());
977 if (imageSource.exists()) {
978 FileUtils.copyDirectory(imageSource, imageDestination);
981 throw new Exception(NbBundle.getMessage(
SingleUserCaseConverter.class,
"SingleUserCaseConverter.UnableToCopySourceImages"));
998 String input = icd.getImageInputFolder().toString();
999 String output = icd.getImageOutputFolder().toString();
1003 if (postgresqlConnection != null) {
1007 Statement updateStatement = postgresqlConnection.createStatement();
1008 updateStatement.executeUpdate(
"UPDATE reports SET path=CONCAT('" + hostName +
"/', path) WHERE path IS NOT NULL AND path != ''");
1011 updateStatement = postgresqlConnection.createStatement();
1012 updateStatement.executeUpdate(
"UPDATE tsk_files_path SET path=CONCAT('" + hostName +
"\\', path) WHERE path IS NOT NULL AND path != ''");
1014 String caseName = icd.getRawFolderName().toLowerCase();
1016 if (icd.getCopySourceImages()) {
1018 Statement inputStatement = postgresqlConnection.createStatement();
1019 ResultSet inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_image_names");
1021 while (inputResultSet.next()) {
1022 Path oldPath = Paths.get(inputResultSet.getString(2));
1024 for (
int x = 0; x < oldPath.getNameCount(); ++x) {
1025 if (oldPath.getName(x).toString().toLowerCase().equals(caseName)) {
1026 Path newPath = Paths.get(output, oldPath.subpath(x + 1, oldPath.getNameCount()).toString());
1027 updateStatement = postgresqlConnection.createStatement();
1028 updateStatement.executeUpdate(
"UPDATE tsk_image_names SET name='" + newPath.toString() +
"' WHERE obj_id = " + inputResultSet.getInt(1));
1034 postgresqlConnection.close();
1036 throw new Exception(NbBundle.getMessage(
SingleUserCaseConverter.class,
"SingleUserCaseConverter.CanNotOpenDatabase"));
1052 int value = rs.getInt(index);
1056 return Integer.toString(value);
1072 long value = rs.getLong(index);
1076 return Long.toString(value);
1091 private static void populateNullableString(PreparedStatement pst, ResultSet rs,
int rsIndex,
int psIndex)
throws SQLException {
1092 String nullableString = rs.getString(rsIndex);
1094 pst.setNull(psIndex, java.sql.Types.NULL);
1096 pst.setString(psIndex, SleuthkitCase.escapeSingleQuotes(nullableString));
1112 byte[] nullableBytes = rs.getBytes(rsIndex);
1114 pst.setNull(psIndex, java.sql.Types.NULL);
1116 pst.setBytes(psIndex, nullableBytes);
1132 double nullableNumeric = rs.getDouble(rsIndex);
1134 pst.setNull(psIndex, java.sql.Types.NULL);
1136 pst.setDouble(psIndex, nullableNumeric);
1164 return DriverManager.getConnection(
"jdbc:postgresql://"
1165 + icd.getDb().getHost() +
":"
1166 + icd.getDb().getPort() +
"/"
1168 icd.getDb().getUserName(),
1169 icd.getDb().getPassword());
1182 return DriverManager.getConnection(
"jdbc:sqlite:" + icd.getCaseInputFolder().resolve(AUTOPSY_DB_FILE).toString(),
"",
"");
static Connection getPostgreSQLConnection(ImportCaseData icd)
final Path caseInputFolder
final Path imageOutputFolder
static void populateNullableNumeric(PreparedStatement pst, ResultSet rs, int rsIndex, int psIndex)
static String getNullableInt(ResultSet rs, int index)
static final int MAX_DB_NAME_LENGTH
static void deconflictDatabaseName(ImportCaseData icd)
static Connection getSQLiteConnection(ImportCaseData icd)
final String rawFolderName
ImportCaseData(Path imageInput, Path caseInput, Path imageOutput, Path caseOutput, String oldCaseName, String newCaseName, String autFileName, String rawFolderName, boolean copySourceImages, boolean deleteCase)
Path getCaseOutputFolder()
static void importCase(ImportCaseData icd)
static final String POSTGRES_DEFAULT_DB_NAME
static CaseDbConnectionInfo getDatabaseConnectionInfo()
static final String TIMELINE_FILE
final CaseDbConnectionInfo db
static void copyImages(ImportCaseData icd)
static final String DOTAUT
static final String MODULE_FOLDER
final Path imageInputFolder
final boolean copySourceImages
static void populateNullableString(PreparedStatement pst, ResultSet rs, int rsIndex, int psIndex)
static String getNullableLong(ResultSet rs, int index)
static void populateNullableByteArray(PreparedStatement pst, ResultSet rs, int rsIndex, int psIndex)
static final String AUTOPSY_DB_FILE
static final String TIMELINE_FOLDER
static void copyResults(ImportCaseData icd)
static String getLocalHostName()
static void importDb(ImportCaseData icd)
Path getCaseInputFolder()
final Path caseOutputFolder
static void fixPaths(ImportCaseData icd)
static File findInputFolder(ImportCaseData icd)
static Connection getPostgreSQLConnection(ImportCaseData icd, String dbName)