From ceae3caa37cb631166f4d23c03c4d0056cf77fd3 Mon Sep 17 00:00:00 2001 From: hawk Date: Sun, 10 Feb 2019 10:06:59 +0500 Subject: [PATCH 1/4] sqlite3 databases: check that the file exists and is writeable --- functions.inc.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/functions.inc.php b/functions.inc.php index fc234fbb..c1c1cfd4 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1484,7 +1484,19 @@ function db_connect_with_errors() { $queries[] = 'SET CHARACTER SET utf8'; $queries[] = "SET COLLATION_CONNECTION='utf8_general_ci'"; } elseif (db_sqlite()) { - $dsn = "sqlite:{$CONF['database_name']}"; + $db = $CONF['database_name']; + + if (!file_exists($db)) { + $error_text = 'SQLite database missing: '. $db; + return array($link, $error_text); + } + + if (!is_writeable($db)) { + $error_text = 'SQLite database not writeable: '. $db; + return array($link, $error_text); + } + + $dsn = "sqlite:{$db}"; $username_password = false; } elseif (db_pgsql()) { if (!isset($CONF['database_port'])) { @@ -1509,7 +1521,6 @@ function db_connect_with_errors() { } } catch (PDOException $e) { $error_text = 'PDO exception: '. $e->getMessage(); - error_log($error_text); } return array($link, $error_text); From 4f2dab357c78932ff43cf229b12c99cfb16590fb Mon Sep 17 00:00:00 2001 From: 8ctopus Date: Sun, 10 Feb 2019 10:56:08 +0500 Subject: [PATCH 2/4] the directory the SQLite database is in must be writeable --- functions.inc.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/functions.inc.php b/functions.inc.php index c1c1cfd4..5350f823 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1496,6 +1496,11 @@ function db_connect_with_errors() { return array($link, $error_text); } + if (!is_writeable(dirname($db))) { + $error_text = 'The directory the SQLite database is in is not writeable: '. dirname($db); + return array($link, $error_text); + } + $dsn = "sqlite:{$db}"; $username_password = false; } elseif (db_pgsql()) { From 5528d8be309a2993498e57cf305c93cf0415e847 Mon Sep 17 00:00:00 2001 From: 8ctopus Date: Sun, 10 Feb 2019 11:04:04 +0500 Subject: [PATCH 3/4] added: line break so $error_text is on its own line --- public/setup.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/setup.php b/public/setup.php index 940ec8dd..d824e782 100644 --- a/public/setup.php +++ b/public/setup.php @@ -32,7 +32,7 @@ require(dirname(__FILE__) . '/../templates/header.php');
    Testing database connection (using {$CONF['database_type']}) - Success"; } else { print "
  • Error: Can't connect to database
    \n"; - print "Please check the \$CONF['database_*'] parameters in config.local.php.\n"; + print "Please check the \$CONF['database_*'] parameters in config.local.php.
    \n"; print "$error_text
  • \n"; $error ++; } From 637220a3fb1e3401e6cbfee0608f274a0e071fbe Mon Sep 17 00:00:00 2001 From: 8ctopus Date: Sun, 10 Feb 2019 11:37:54 +0500 Subject: [PATCH 4/4] fixed: typos --- CHANGELOG.TXT | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT index 4f8efa05..c5f20165 100644 --- a/CHANGELOG.TXT +++ b/CHANGELOG.TXT @@ -10,7 +10,7 @@ Version X.X - master ------------------------------------------------- - Add support for password expiration (see https://github.com/postfixadmin/postfixadmin/pull/200 and README.password_expiration ) - - Improve ADDITIONS/postfxiadmin-mailbox-postcreate.sh + - Improve ADDITIONS/postfixadmin-mailbox-postcreate.sh - Add Date header into smtp_from() (see https://github.com/postfixadmin/postfixadmin/issues/203 ) - PostgreSQL fixes ( 1e158245d613fd1d8d5c1d59e26e940eb71f5b32 ) - vacation.pl fixes (perl libraries; see https://github.com/postfixadmin/postfixadmin/pull/194 ) @@ -20,7 +20,7 @@ Version X.X - master - Update installation instructions. (see: https://github.com/postfixadmin/postfixadmin/issues/189 https://github.com/postfixadmin/postfixadmin/issues/188 ) - Encryption improvements (see: php_crypt / encrypt_difficulty in sample config) - Sqlite improvements (see https://github.com/postfixadmin/postfixadmin/issues/177 and https://github.com/postfixadmin/postfixadmin/issues/176 ) - - MySQL 8 compatability (see https://github.com/postfixadmin/postfixadmin/pull/175 ) + - MySQL 8 compatibility (see https://github.com/postfixadmin/postfixadmin/pull/175 ) - Internally the database functions have been refactored to use PDO rather than the lower level mysql_, mysqli_, pg_ etc functions. ( see: https://github.com/postfixadmin/postfixadmin/pull/231 ) Version 3.2 - 2018/05/02