use DbManager for updating the password of a mysql-db

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2019-02-24 08:52:50 +01:00
parent 410bfe2c97
commit 2f38de90e5
2 changed files with 31 additions and 32 deletions

View File

@@ -320,14 +320,9 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
// Begin root-session // Begin root-session
Database::needRoot(true, $result['dbserver']); Database::needRoot(true, $result['dbserver']);
$dbmgr = new \Froxlor\Database\DbManager($this->logger());
foreach (array_map('trim', explode(',', Settings::Get('system.mysql_access_host'))) as $mysql_access_host) { foreach (array_map('trim', explode(',', Settings::Get('system.mysql_access_host'))) as $mysql_access_host) {
$stmt = Database::prepare("SET PASSWORD FOR :dbname@:host = PASSWORD(:password)"); $dbmgr->getManager()->grantPrivilegesTo($result['databasename'], $password, $mysql_access_host, false, true);
$params = array(
"dbname" => $result['databasename'],
"host" => $mysql_access_host,
"password" => $password
);
Database::pexecute($stmt, $params, true, true);
} }
$stmt = Database::prepare("FLUSH PRIVILEGES"); $stmt = Database::prepare("FLUSH PRIVILEGES");

View File

@@ -72,9 +72,12 @@ class DbManagerMySQL
* @param string $access_host * @param string $access_host
* @param bool $p_encrypted * @param bool $p_encrypted
* optional, whether the password is encrypted or not, default false * optional, whether the password is encrypted or not, default false
* @param bool $update
* optional, whether to update the password only (not create user)
*/ */
public function grantPrivilegesTo($username = null, $password = null, $access_host = null, $p_encrypted = false) public function grantPrivilegesTo($username = null, $password = null, $access_host = null, $p_encrypted = false, $update = false)
{ {
if (! $update) {
// mysql8 compatibility // mysql8 compatibility
if (version_compare(Database::getAttribute(\PDO::ATTR_SERVER_VERSION), '8.0.11', '>=')) { if (version_compare(Database::getAttribute(\PDO::ATTR_SERVER_VERSION), '8.0.11', '>=')) {
// create user // create user
@@ -100,6 +103,7 @@ class DbManagerMySQL
"host" => $access_host "host" => $access_host
)); ));
} }
}
// set passoword // set passoword
if (version_compare(Database::getAttribute(\PDO::ATTR_SERVER_VERSION), '5.7.6', '<')) { if (version_compare(Database::getAttribute(\PDO::ATTR_SERVER_VERSION), '5.7.6', '<')) {
if ($p_encrypted) { if ($p_encrypted) {