diff options
-rw-r--r-- | installer/helpers/installer.php | 24 | ||||
-rw-r--r-- | installer/install.php | 1 | ||||
-rw-r--r-- | installer/libraries/Install_Mysql_Driver.php | 32 | ||||
-rw-r--r-- | installer/libraries/Install_Mysqli_Driver.php | 34 |
4 files changed, 77 insertions, 14 deletions
diff --git a/installer/helpers/installer.php b/installer/helpers/installer.php index e510cf49..8bc73619 100644 --- a/installer/helpers/installer.php +++ b/installer/helpers/installer.php @@ -257,6 +257,11 @@ class installer { self::$database = new $class(self::$config["host"], self::$config["user"], self::$config["password"]); + /* + * If we got this far, then the user/password combination is valid and we can now + * a little more information for the individual that is running the script. We can also + * connect to the database and ask for more information + */ $databases = self::$database->list_dbs(); $dbname = self::$config["dbname"]; $db_config_valid = true; @@ -268,6 +273,25 @@ class installer { $section["msgs"]["Database"] = array("text" => "Database '$dbname' is defined", "error" => false); } + + $missing = array(); + $rights = self::$database->get_access_rights($dbname); + + foreach (array("create", "delete", "insert", "select", "update", "alter") as $priviledge) { + if (empty($rights[$priviledge])) { + $missing[] = $priviledge; + } + } + if (!empty($missing)) { + $db_config_valid = false; + $section["msgs"]["Privileges"] = + array("text" => "The following required priviledges have not been granted: " . + implode(", ", $missing), "error" => true); + } else { + $section["msgs"]["Privileges"] = array("text" => "Required priviledges defined.", + "error" => false); + } + self::$messages[] = $section; diff --git a/installer/install.php b/installer/install.php index 2a140594..694ae2a1 100644 --- a/installer/install.php +++ b/installer/install.php @@ -92,7 +92,6 @@ try { } catch (Exception $e) { die("Specifed User does not have sufficient authority to install Gallery3\n"); } -var_dump($config_valid); installer::display_requirements(!$config_valid); diff --git a/installer/libraries/Install_Mysql_Driver.php b/installer/libraries/Install_Mysql_Driver.php index ae44e040..aac49acd 100644 --- a/installer/libraries/Install_Mysql_Driver.php +++ b/installer/libraries/Install_Mysql_Driver.php @@ -18,27 +18,47 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Install_Mysql_Driver { - private $link; + private $_link; + private $_server; + private $_user; public function __construct($server, $user, $password) { - $this->link = @mysql_connect($server, $user, $password); - if (!$this->link) { + $this->_link = @mysql_connect($server, $user, $password); + if (!$this->_link) { throw new Exception(mysql_error()); } + $this->_server = $server; + $this->_user = $user; } public function __destruct() { - if (!empty($this->link)) { - @mysql_close($this->link); + if (!empty($this->_link)) { + @mysql_close($this->_link); } } public function list_dbs() { - $db_list = mysql_list_dbs($this->link); + $db_list = mysql_list_dbs($this->_link); $databases = array(); while ($row = mysql_fetch_object($db_list)) { $databases[$row->Database] = 1; } return $databases; } + + public function get_access_rights($dbname) { + $select = "SELECT PRIVILEGE_TYPE " . + " FROM `information_schema`.`schema_privileges`" . + " WHERE `GRANTEE` = '\\'{$this->_user}\\'@\\'{$this->_server}\\''" . + " AND `TABLE_SCHEMA` = '$dbname';"; + $privileges = mysql_query($select, $this->_link); + $permissions = array(); + if ($privileges) { + while ($row = mysql_fetch_assoc($privileges)) { + $permissions[strtolower($row["PRIVILEGE_TYPE"])] = 1; + } + } + return $permissions; + } + } diff --git a/installer/libraries/Install_Mysqli_Driver.php b/installer/libraries/Install_Mysqli_Driver.php index 114a42f4..ce141066 100644 --- a/installer/libraries/Install_Mysqli_Driver.php +++ b/installer/libraries/Install_Mysqli_Driver.php @@ -20,24 +20,28 @@ // Convienence wrapper around the Php mysqli class class Install_Mysqli_Driver { - private $mysqli; + private $_mysqli; + private $_server; + private $_user; public function __construct($server, $user, $password) { - $this->mysqli = @mysqli_connect($server, $user, $password); - if (!$this->mysqli) { + $this->_mysqli = @mysqli_connect($server, $user, $password); + if (!$this->_mysqli) { throw new Exception(mysqli_connect_error()); } + $this->_server = $server; + $this->_user = $user; } public function __destruct() { - if (!empty($this->mysqli)) { - @$this->mysqli->close(); - $this->mysqli = null; + if (!empty($this->_mysqli)) { + @$this->_mysqli->close(); + $this->_mysqli = null; } } public function list_dbs() { - $db_list = $this->mysqli->query("SHOW DATABASES"); + $db_list = $this->_mysqli->query("SHOW DATABASES"); $databases = array(); if ($db_list) { while ($row = $db_list->fetch_row()) { @@ -46,5 +50,21 @@ class Install_Mysqli_Driver { } return $databases; } + + public function get_access_rights($dbname) { + $select = "SELECT PRIVILEGE_TYPE " . + " FROM `information_schema`.`schema_privileges`" . + " WHERE `GRANTEE` = '\\'{$this->_user}\\'@\\'{$this->_server}\\''" . + " AND `TABLE_SCHEMA` = '$dbname';"; + $privileges = $this->_mysqli->query($select); + $permissions = array(); + if ($privileges) { + while ($row = $privileges->fetch_row()) { + $permissions[strtolower($row[0])] = 1; + } + } + return $permissions; + } + } |