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.SQLException;
30 import java.sql.Statement;
31 import java.text.SimpleDateFormat;
32 import java.util.Date;
33 import org.apache.commons.io.FileUtils;
34 import org.openide.util.NbBundle;
49 private static final String
DOTAUT =
".aut";
68 private final CaseDbConnectionInfo
db;
79 boolean copySourceImages,
82 this.imageInputFolder = imageInput;
83 this.caseInputFolder = caseInput;
84 this.imageOutputFolder = imageOutput;
85 this.caseOutputFolder = caseOutput;
103 Path getImageInputFolder() {
107 Path getImageOutputFolder() {
111 String getOldCaseName() {
115 String getNewCaseName() {
119 boolean getCopySourceImages() {
123 boolean getDeleteCase() {
127 String getPostgreSQLDbName() {
131 String getAutFileName() {
135 String getRawFolderName() {
139 CaseDbConnectionInfo getDb() {
143 void setPostgreSQLDbName(String dbName) {
144 this.postgreSQLDbName = dbName;
159 Class.forName(
"org.postgresql.Driver");
162 Path oldDatabasePath = icd.getCaseInputFolder().resolve(AUTOPSY_DB_FILE);
163 if (
false == oldDatabasePath.toFile().exists()) {
164 throw new Exception(NbBundle.getMessage(
SingleUserCaseConverter.class,
"SingleUserCaseConverter.BadDatabaseFileName"));
168 XMLCaseManagement oldXmlCaseManagement =
new XMLCaseManagement();
169 oldXmlCaseManagement.open(icd.getCaseInputFolder().resolve(icd.getAutFileName()).toString());
171 throw new Exception(NbBundle.getMessage(
SingleUserCaseConverter.class,
"SingleUserCaseConverter.AlreadyMultiUser"));
175 SimpleDateFormat dateFormat =
new SimpleDateFormat(
"yyyyMMdd_HHmmss");
176 Date date =
new Date();
177 String dbName =
Case.sanitizeCaseName(icd.getNewCaseName()) +
"_" + dateFormat.format(date);
178 String solrName = dbName;
179 icd.setPostgreSQLDbName(dbName);
194 XMLCaseManagement newXmlCaseManagement =
new XMLCaseManagement();
195 newXmlCaseManagement.create(icd.getCaseOutputFolder().toString(),
196 icd.getNewCaseName(),
197 oldXmlCaseManagement.getCaseExaminer(),
198 oldXmlCaseManagement.getCaseNumber(),
202 newXmlCaseManagement.setCreatedDate(oldXmlCaseManagement.getCreatedDate());
208 if (icd.getDeleteCase()) {
209 FileUtils.deleteDirectory(icd.getCaseInputFolder().toFile());
222 File thePath = icd.getImageInputFolder().resolve(icd.getOldCaseName()).toFile();
223 if (thePath.isDirectory()) {
227 thePath = icd.getImageInputFolder().resolve(icd.getRawFolderName()).toFile();
228 if (thePath.isDirectory()) {
232 return icd.getImageInputFolder().toFile();
248 Path source = icd.getCaseInputFolder();
249 if (source.toFile().exists()) {
250 destination = icd.getCaseOutputFolder().resolve(hostName);
251 FileUtils.copyDirectory(source.toFile(), destination.toFile());
254 source = icd.getCaseInputFolder().resolve(TIMELINE_FILE);
255 if (source.toFile().exists()) {
257 FileUtils.copyFile(source.toFile(), destination.toFile());
261 File oldAutopsyFile = Paths.get(icd.getCaseOutputFolder().toString(), hostName, icd.getOldCaseName() +
DOTAUT).toFile();
262 if (oldAutopsyFile.exists()) {
263 oldAutopsyFile.delete();
267 File oldDatabaseFile = Paths.get(icd.getCaseOutputFolder().toString(), hostName,
AUTOPSY_DB_FILE).toFile();
268 if (oldDatabaseFile.exists()) {
269 oldDatabaseFile.delete();
273 File oldTimelineFile = Paths.get(icd.getCaseOutputFolder().toString(), hostName,
TIMELINE_FILE).toFile();
274 if (oldTimelineFile.exists()) {
275 oldTimelineFile.delete();
295 SleuthkitCase newCase = SleuthkitCase.newCase(icd.getPostgreSQLDbName(), icd.getDb(), icd.getCaseOutputFolder().toString());
299 Class.forName(
"org.sqlite.JDBC");
304 Statement inputStatement = sqliteConnection.createStatement();
305 ResultSet inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_artifact_types");
306 Statement outputStatement;
307 Statement numberingPK;
310 while (inputResultSet.next()) {
312 long value = inputResultSet.getLong(1);
313 if (value > biggestPK) {
316 Statement check = postgreSQLConnection.createStatement();
317 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) +
"'");
318 if (!checkResult.isBeforeFirst()) {
319 String sql =
"INSERT INTO blackboard_artifact_types (artifact_type_id, type_name, display_name) VALUES ("
321 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(2)) +
"',"
323 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
327 }
catch (SQLException ex) {
328 if (ex.getErrorCode() != 0) {
329 throw new SQLException(ex);
333 numberingPK = postgreSQLConnection.createStatement();
334 numberingPK.execute(
"ALTER SEQUENCE blackboard_artifact_types_artifact_type_id_seq RESTART WITH " + (biggestPK + 1));
338 inputStatement = sqliteConnection.createStatement();
339 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_attribute_types");
341 while (inputResultSet.next()) {
343 long value = inputResultSet.getLong(1);
344 if (value > biggestPK) {
347 Statement check = postgreSQLConnection.createStatement();
348 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) +
"'");
349 if (!checkResult.isBeforeFirst()) {
350 String sql =
"INSERT INTO blackboard_attribute_types (attribute_type_id, type_name, display_name) VALUES ("
352 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(2)) +
"',"
355 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
359 }
catch (SQLException ex) {
360 if (ex.getErrorCode() != 0) {
361 throw new SQLException(ex);
365 numberingPK = postgreSQLConnection.createStatement();
366 numberingPK.execute(
"ALTER SEQUENCE blackboard_attribute_types_attribute_type_id_seq RESTART WITH " + (biggestPK + 1));
370 inputStatement = sqliteConnection.createStatement();
371 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_objects");
373 while (inputResultSet.next()) {
374 outputStatement = postgreSQLConnection.createStatement();
376 long value = inputResultSet.getLong(1);
377 if (value > biggestPK) {
380 outputStatement.executeUpdate(
"INSERT INTO tsk_objects (obj_id, par_obj_id, type) VALUES ("
383 + inputResultSet.getInt(3) +
")");
384 }
catch (SQLException ex) {
385 if (ex.getErrorCode() != 0) {
386 throw new SQLException(ex);
390 numberingPK = postgreSQLConnection.createStatement();
391 numberingPK.execute(
"ALTER SEQUENCE tsk_objects_obj_id_seq RESTART WITH " + (biggestPK + 1));
394 inputStatement = sqliteConnection.createStatement();
395 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_image_names");
397 while (inputResultSet.next()) {
398 outputStatement = postgreSQLConnection.createStatement();
400 outputStatement.executeUpdate(
"INSERT INTO tsk_image_names (obj_id, name, sequence) VALUES ("
401 + inputResultSet.getLong(1) +
",'"
402 + inputResultSet.getString(2) +
"',"
403 + inputResultSet.getInt(3) +
")");
404 }
catch (SQLException ex) {
405 if (ex.getErrorCode() != 0) {
406 throw new SQLException(ex);
413 inputStatement = sqliteConnection.createStatement();
414 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_image_info");
416 while (inputResultSet.next()) {
418 long value = inputResultSet.getLong(1);
419 if (value > biggestPK) {
422 String sql =
"INSERT INTO tsk_image_info (obj_id, type, ssize, tzone, size, md5, display_name) VALUES ("
431 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
437 }
catch (SQLException ex) {
438 if (ex.getErrorCode() != 0) {
439 throw new SQLException(ex);
443 numberingPK = postgreSQLConnection.createStatement();
444 numberingPK.execute(
"ALTER SEQUENCE tsk_image_info_obj_id_seq RESTART WITH " + (biggestPK + 1));
448 inputStatement = sqliteConnection.createStatement();
449 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_fs_info");
451 while (inputResultSet.next()) {
453 long value = inputResultSet.getLong(1);
454 if (value > biggestPK) {
457 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 ("
459 + inputResultSet.getLong(2) +
","
460 + inputResultSet.getInt(3) +
","
461 + inputResultSet.getLong(4) +
","
462 + inputResultSet.getLong(5) +
","
463 + inputResultSet.getLong(6) +
","
464 + inputResultSet.getLong(7) +
","
465 + inputResultSet.getLong(8) +
","
468 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
472 }
catch (SQLException ex) {
473 if (ex.getErrorCode() != 0) {
474 throw new SQLException(ex);
478 numberingPK = postgreSQLConnection.createStatement();
479 numberingPK.execute(
"ALTER SEQUENCE tsk_fs_info_obj_id_seq RESTART WITH " + (biggestPK + 1));
483 inputStatement = sqliteConnection.createStatement();
484 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_files_path");
486 while (inputResultSet.next()) {
487 outputStatement = postgreSQLConnection.createStatement();
489 long value = inputResultSet.getLong(1);
490 if (value > biggestPK) {
493 outputStatement.executeUpdate(
"INSERT INTO tsk_files_path (obj_id, path) VALUES ("
495 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(2)) +
"')");
496 }
catch (SQLException ex) {
497 if (ex.getErrorCode() != 0) {
498 throw new SQLException(ex);
502 numberingPK = postgreSQLConnection.createStatement();
503 numberingPK.execute(
"ALTER SEQUENCE tsk_files_path_obj_id_seq RESTART WITH " + (biggestPK + 1));
507 inputStatement = sqliteConnection.createStatement();
508 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_files");
510 while (inputResultSet.next()) {
512 long value = inputResultSet.getLong(1);
513 if (value > biggestPK) {
516 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 ("
521 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(5)) +
"',"
543 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
548 }
catch (SQLException ex) {
549 if (ex.getErrorCode() != 0) {
550 throw new SQLException(ex);
554 numberingPK = postgreSQLConnection.createStatement();
555 numberingPK.execute(
"ALTER SEQUENCE tsk_files_obj_id_seq RESTART WITH " + (biggestPK + 1));
558 inputStatement = sqliteConnection.createStatement();
559 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_file_layout");
561 while (inputResultSet.next()) {
562 outputStatement = postgreSQLConnection.createStatement();
564 outputStatement.executeUpdate(
"INSERT INTO tsk_file_layout (obj_id, byte_start, byte_len, sequence) VALUES ("
565 + inputResultSet.getLong(1) +
","
566 + inputResultSet.getLong(2) +
","
567 + inputResultSet.getLong(3) +
","
568 + inputResultSet.getInt(4) +
")");
569 }
catch (SQLException ex) {
570 if (ex.getErrorCode() != 0) {
571 throw new SQLException(ex);
577 inputStatement = sqliteConnection.createStatement();
578 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_db_info");
580 while (inputResultSet.next()) {
581 outputStatement = postgreSQLConnection.createStatement();
583 Statement check = postgreSQLConnection.createStatement();
584 ResultSet checkResult = check.executeQuery(
"SELECT * FROM tsk_db_info WHERE schema_ver=" + inputResultSet.getInt(1) +
" AND tsk_ver=" + inputResultSet.getInt(2));
585 if (!checkResult.isBeforeFirst()) {
586 outputStatement.executeUpdate(
"INSERT INTO tsk_db_info (schema_ver, tsk_ver) VALUES ("
590 }
catch (SQLException ex) {
591 if (ex.getErrorCode() != 0) {
592 throw new SQLException(ex);
599 inputStatement = sqliteConnection.createStatement();
600 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tag_names");
602 while (inputResultSet.next()) {
604 long value = inputResultSet.getLong(1);
605 if (value > biggestPK) {
608 String sql =
"INSERT INTO tag_names (tag_name_id, display_name, description, color) VALUES ("
611 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(3)) +
"','"
612 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(4)) +
"')";
614 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
618 }
catch (SQLException ex) {
619 if (ex.getErrorCode() != 0) {
620 throw new SQLException(ex);
624 numberingPK = postgreSQLConnection.createStatement();
625 numberingPK.execute(
"ALTER SEQUENCE tag_names_tag_name_id_seq RESTART WITH " + (biggestPK + 1));
629 inputStatement = sqliteConnection.createStatement();
630 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM reports");
632 while (inputResultSet.next()) {
633 outputStatement = postgreSQLConnection.createStatement();
635 long value = inputResultSet.getLong(1);
636 if (value > biggestPK) {
639 outputStatement.executeUpdate(
"INSERT INTO reports (report_id, path, crtime, src_module_name, report_name) VALUES ("
641 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(2)) +
"',"
642 + inputResultSet.getInt(3) +
",'"
643 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(4)) +
"','"
644 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(5)) +
"')");
646 }
catch (SQLException ex) {
647 if (ex.getErrorCode() != 0) {
648 throw new SQLException(ex);
652 numberingPK = postgreSQLConnection.createStatement();
653 numberingPK.execute(
"ALTER SEQUENCE reports_report_id_seq RESTART WITH " + (biggestPK + 1));
656 biggestPK = Long.MIN_VALUE;
657 inputStatement = sqliteConnection.createStatement();
658 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_artifacts");
660 while (inputResultSet.next()) {
661 outputStatement = postgreSQLConnection.createStatement();
663 long value = inputResultSet.getLong(1);
664 if (value > biggestPK) {
667 outputStatement.executeUpdate(
"INSERT INTO blackboard_artifacts (artifact_id, obj_id, artifact_type_id) VALUES ("
669 + inputResultSet.getLong(2) +
","
670 + inputResultSet.getLong(3) +
")");
672 }
catch (SQLException ex) {
673 if (ex.getErrorCode() != 0) {
674 throw new SQLException(ex);
678 numberingPK = postgreSQLConnection.createStatement();
679 numberingPK.execute(
"ALTER SEQUENCE blackboard_artifacts_artifact_id_seq RESTART WITH " + (biggestPK + 1));
682 inputStatement = sqliteConnection.createStatement();
683 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_attributes");
685 while (inputResultSet.next()) {
687 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 ("
688 + inputResultSet.getLong(1) +
","
689 + inputResultSet.getLong(2) +
","
692 + inputResultSet.getLong(5) +
","
693 + inputResultSet.getInt(6) +
","
699 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
707 }
catch (SQLException ex) {
708 if (ex.getErrorCode() != 0) {
709 throw new SQLException(ex);
716 inputStatement = sqliteConnection.createStatement();
717 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_vs_parts");
719 while (inputResultSet.next()) {
721 long value = inputResultSet.getLong(1);
722 if (value > biggestPK) {
725 String sql =
"INSERT INTO tsk_vs_parts (obj_id, addr, start, length, descr, flags) VALUES ("
727 + inputResultSet.getLong(2) +
","
728 + inputResultSet.getLong(3) +
","
729 + inputResultSet.getLong(4) +
","
731 + inputResultSet.getInt(6) +
")";
732 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
736 }
catch (SQLException ex) {
737 if (ex.getErrorCode() != 0) {
738 throw new SQLException(ex);
742 numberingPK = postgreSQLConnection.createStatement();
743 numberingPK.execute(
"ALTER SEQUENCE tsk_vs_parts_obj_id_seq RESTART WITH " + (biggestPK + 1));
747 inputStatement = sqliteConnection.createStatement();
748 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_vs_info");
750 while (inputResultSet.next()) {
751 outputStatement = postgreSQLConnection.createStatement();
753 long value = inputResultSet.getLong(1);
754 if (value > biggestPK) {
757 outputStatement.executeUpdate(
"INSERT INTO tsk_vs_info (obj_id, vs_type, img_offset, block_size) VALUES ("
759 + inputResultSet.getInt(2) +
","
760 + inputResultSet.getLong(3) +
","
761 + inputResultSet.getLong(4) +
")");
763 }
catch (SQLException ex) {
764 if (ex.getErrorCode() != 0) {
765 throw new SQLException(ex);
769 numberingPK = postgreSQLConnection.createStatement();
770 numberingPK.execute(
"ALTER SEQUENCE tsk_vs_info_obj_id_seq RESTART WITH " + (biggestPK + 1));
774 inputStatement = sqliteConnection.createStatement();
775 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_files_derived");
777 while (inputResultSet.next()) {
779 long value = inputResultSet.getLong(1);
780 if (value > biggestPK) {
783 String sql =
"INSERT INTO tsk_files_derived (obj_id, derived_id, rederive) VALUES ("
785 + inputResultSet.getLong(2) +
","
787 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
791 }
catch (SQLException ex) {
792 if (ex.getErrorCode() != 0) {
793 throw new SQLException(ex);
797 numberingPK = postgreSQLConnection.createStatement();
798 numberingPK.execute(
"ALTER SEQUENCE tsk_files_derived_obj_id_seq RESTART WITH " + (biggestPK + 1));
802 inputStatement = sqliteConnection.createStatement();
803 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_files_derived_method");
805 while (inputResultSet.next()) {
807 long value = inputResultSet.getLong(1);
808 if (value > biggestPK) {
811 String sql =
"INSERT INTO tsk_files_derived_method (derived_id, tool_name, tool_version, other) VALUES ("
813 + inputResultSet.getString(2) +
"','"
814 + inputResultSet.getString(3) +
"',"
816 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
820 }
catch (SQLException ex) {
821 if (ex.getErrorCode() != 0) {
822 throw new SQLException(ex);
826 numberingPK = postgreSQLConnection.createStatement();
827 numberingPK.execute(
"ALTER SEQUENCE tsk_files_derived_method_derived_id_seq RESTART WITH " + (biggestPK + 1));
831 inputStatement = sqliteConnection.createStatement();
832 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM content_tags");
834 while (inputResultSet.next()) {
835 outputStatement = postgreSQLConnection.createStatement();
837 long value = inputResultSet.getLong(1);
838 if (value > biggestPK) {
841 outputStatement.executeUpdate(
"INSERT INTO content_tags (tag_id, obj_id, tag_name_id, comment, begin_byte_offset, end_byte_offset) VALUES ("
843 + inputResultSet.getLong(2) +
","
844 + inputResultSet.getLong(3) +
",'"
845 + inputResultSet.getString(4) +
"',"
846 + inputResultSet.getLong(5) +
","
847 + inputResultSet.getLong(6) +
")");
849 }
catch (SQLException ex) {
850 if (ex.getErrorCode() != 0) {
851 throw new SQLException(ex);
855 numberingPK = postgreSQLConnection.createStatement();
856 numberingPK.execute(
"ALTER SEQUENCE content_tags_tag_id_seq RESTART WITH " + (biggestPK + 1));
860 inputStatement = sqliteConnection.createStatement();
861 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_artifact_tags");
863 while (inputResultSet.next()) {
864 outputStatement = postgreSQLConnection.createStatement();
866 long value = inputResultSet.getLong(1);
867 if (value > biggestPK) {
870 outputStatement.executeUpdate(
"INSERT INTO blackboard_artifact_tags (tag_id, artifact_id, tag_name_id, comment) VALUES ("
872 + inputResultSet.getLong(2) +
","
873 + inputResultSet.getLong(3) +
",'"
874 + inputResultSet.getString(4) +
"')");
876 }
catch (SQLException ex) {
877 if (ex.getErrorCode() != 0) {
878 throw new SQLException(ex);
882 numberingPK = postgreSQLConnection.createStatement();
883 numberingPK.execute(
"ALTER SEQUENCE blackboard_artifact_tags_tag_id_seq RESTART WITH " + (biggestPK + 1));
885 sqliteConnection.close();
886 postgreSQLConnection.close();
905 boolean unique =
false;
906 String sanitizedDbName = icd.getPostgreSQLDbName();
908 sanitizedDbName = sanitizedDbName.substring(0, MAX_DB_NAME_LENGTH);
911 if (postgreSQLConnection != null) {
912 while (unique ==
false) {
913 Statement st = postgreSQLConnection.createStatement();
914 ResultSet answer = st.executeQuery(
"SELECT datname FROM pg_catalog.pg_database WHERE LOWER(datname) LIKE LOWER('" + sanitizedDbName +
"%')");
916 if (!answer.next()) {
920 if (number == Integer.MAX_VALUE) {
922 throw new Exception(NbBundle.getMessage(
SingleUserCaseConverter.class,
"SingleUserCaseConverter.NonUniqueDatabaseName"));
924 sanitizedDbName =
"db_" + Integer.toString(number) +
"_" + icd.getPostgreSQLDbName();
928 sanitizedDbName = sanitizedDbName.substring(0, MAX_DB_NAME_LENGTH);
933 postgreSQLConnection.close();
939 icd.setPostgreSQLDbName(sanitizedDbName);
951 if (icd.getCopySourceImages()) {
953 File imageDestination =
new File(icd.getImageOutputFolder().toString());
956 if (imageSource.exists()) {
957 FileUtils.copyDirectory(imageSource, imageDestination);
960 throw new Exception(NbBundle.getMessage(
SingleUserCaseConverter.class,
"SingleUserCaseConverter.UnableToCopySourceImages"));
977 String input = icd.getImageInputFolder().toString();
978 String output = icd.getImageOutputFolder().toString();
982 if (postgresqlConnection != null) {
986 Statement updateStatement = postgresqlConnection.createStatement();
987 updateStatement.executeUpdate(
"UPDATE reports SET path=CONCAT('" + hostName +
"/', path) WHERE path IS NOT NULL AND path != ''");
990 updateStatement = postgresqlConnection.createStatement();
991 updateStatement.executeUpdate(
"UPDATE tsk_files_path SET path=CONCAT('" + hostName +
"\\', path) WHERE path IS NOT NULL AND path != ''");
993 String caseName = icd.getRawFolderName().toLowerCase();
995 if (icd.getCopySourceImages()) {
997 Statement inputStatement = postgresqlConnection.createStatement();
998 ResultSet inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_image_names");
1000 while (inputResultSet.next()) {
1001 Path oldPath = Paths.get(inputResultSet.getString(2));
1003 for (
int x = 0; x < oldPath.getNameCount(); ++x) {
1004 if (oldPath.getName(x).toString().toLowerCase().equals(caseName)) {
1005 Path newPath = Paths.get(output, oldPath.subpath(x + 1, oldPath.getNameCount()).toString());
1006 updateStatement = postgresqlConnection.createStatement();
1007 updateStatement.executeUpdate(
"UPDATE tsk_image_names SET name='" + newPath.toString() +
"' WHERE obj_id = " + inputResultSet.getInt(1));
1013 postgresqlConnection.close();
1015 throw new Exception(NbBundle.getMessage(
SingleUserCaseConverter.class,
"SingleUserCaseConverter.CanNotOpenDatabase"));
1031 int value = rs.getInt(index);
1035 return Integer.toString(value);
1051 long value = rs.getLong(index);
1055 return Long.toString(value);
1070 private static void populateNullableString(PreparedStatement pst, ResultSet rs,
int rsIndex,
int psIndex)
throws SQLException {
1071 String nullableString = rs.getString(rsIndex);
1073 pst.setNull(psIndex, java.sql.Types.NULL);
1075 pst.setString(psIndex, SleuthkitCase.escapeSingleQuotes(nullableString));
1091 byte[] nullableBytes = rs.getBytes(rsIndex);
1093 pst.setNull(psIndex, java.sql.Types.NULL);
1095 pst.setBytes(psIndex, nullableBytes);
1111 double nullableNumeric = rs.getDouble(rsIndex);
1113 pst.setNull(psIndex, java.sql.Types.NULL);
1115 pst.setDouble(psIndex, nullableNumeric);
1143 return DriverManager.getConnection(
"jdbc:postgresql://"
1144 + icd.getDb().getHost() +
":"
1145 + icd.getDb().getPort() +
"/"
1147 icd.getDb().getUserName(),
1148 icd.getDb().getPassword());
1161 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
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)