19package org.sleuthkit.autopsy.centralrepository.datamodel;
22import java.io.IOException;
23import java.nio.file.Files;
24import java.nio.file.InvalidPathException;
25import java.nio.file.Path;
26import java.nio.file.Paths;
27import java.sql.Connection;
28import java.sql.DriverManager;
29import java.sql.SQLException;
30import java.util.logging.Level;
31import java.util.regex.Pattern;
32import org.sleuthkit.autopsy.centralrepository.CentralRepoSettings;
33import org.sleuthkit.autopsy.coreutils.Logger;
34import org.sleuthkit.autopsy.coreutils.ModuleSettings;
35import org.sleuthkit.autopsy.coreutils.PlatformUtil;
82 if (bulkThresholdString ==
null || bulkThresholdString.isEmpty()) {
83 this.bulkThreshold = RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD;
85 this.bulkThreshold = Integer.parseInt(bulkThresholdString);
86 if (getBulkThreshold() <= 0) {
87 this.bulkThreshold = RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD;
90 }
catch (NumberFormatException ex) {
91 this.bulkThreshold = RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD;
96 return String.format(
"SqliteCentralRepoSettings: [db type: sqlite, directory: %s, name: %s]",
getDbDirectory(),
getDbName());
124 Path relativePath = Paths.get(fullPath);
148 if (curPath !=
null && !curPath.isEmpty()) {
151 Path driveLetterOrNetwork = Paths.get(curPath).getRoot();
152 if (driveLetterOrNetwork !=
null) {
159 curPath = absolutePath.toString();
160 if (
new File(curPath).canRead() ==
false) {
162 LOGGER.log(Level.INFO,
"Path to SQLite Central Repository database is not valid: {0}", curPath);
177 if (!dbFile.exists()) {
181 return (!dbFile.isDirectory());
198 if (!dbDir.exists()) {
200 }
else if (!dbDir.isDirectory()) {
227 Files.createDirectories(dbDir.toPath());
229 }
catch (IOException | InvalidPathException | SecurityException ex) {
230 LOGGER.log(Level.SEVERE,
"Failed to create sqlite database directory.", ex);
245 return dbFile.delete();
253 String getConnectionURL() {
254 StringBuilder url =
new StringBuilder();
255 url.append(getJDBCBaseURI());
258 return url.toString();
269 Connection getEphemeralConnection() {
276 String url = getConnectionURL();
277 Class.forName(getDriver());
278 conn = DriverManager.getConnection(url);
279 }
catch (ClassNotFoundException | SQLException ex) {
280 LOGGER.log(Level.SEVERE,
"Failed to acquire ephemeral connection to sqlite.", ex);
293 Connection conn = getEphemeralConnection();
310 Connection conn = getEphemeralConnection();
320 boolean isChanged() {
325 return !
dbName.equals(dbNameString)
327 || !Integer.toString(
bulkThreshold).equals(bulkThresholdString);
346 throw new CentralRepoException(
"Invalid database file name. Name must start with a lowercase letter and can only contain lowercase letters, numbers, and '_'.");
355 int getBulkThreshold() {
366 throw new CentralRepoException(
"Invalid bulk threshold.");
411 String getValidationQuery() {
418 String getJDBCBaseURI() {
String getDefaultDbName()
String getDatabasePathKey()
String getDefaultDbPath()
static CentralRepoSettings getInstance()
String getModuleSettingsKey()
String getDatabaseNameKey()
static boolean executeValidationQuery(Connection conn, String validationQuery)
static void closeConnection(Connection conn)
static boolean schemaVersionIsSet(Connection conn)
void saveDbPath(String fullPath)
void setDbName(String dbName)
static final String DEFAULT_DBDIRECTORY
static final String DEFAULT_DBNAME
boolean verifyConnection()
DatabaseTestResult testStatus()
static final String DATABASE_NAME
boolean verifyDatabaseExists()
boolean verifyDatabaseSchema()
static final Logger LOGGER
String getFileNameWithPath()
boolean createDbDirectory()
static final String JDBC_BASE_URI
void setDbDirectory(String dbDirectory)
static final String JDBC_DRIVER
static final String DB_NAMES_REGEX
void setupDefaultSettings()
SqliteCentralRepoSettings()
static final String BULK_THRESHOLD
static final String DATABASE_PATH
boolean dbDirectoryExists()
static final String PROFILE_NAME
static final String VALIDATION_QUERY
synchronized static Logger getLogger(String name)
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static synchronized String getConfigSetting(String moduleName, String settingName)