| | |
| | | if(!is_array($host_list)) $host_list = explode(',', $host_list); |
| | | |
| | | $success = true; |
| | | |
| | | if(!preg_match('/\*[A-F0-9]{40}$/', $database_password)) { |
| | | $result = $link->query("SELECT PASSWORD('" . $link->escape_string($database_password) . "') as `crypted`"); |
| | | if($result) { |
| | | $row = $result->fetch_assoc(); |
| | | $database_password = $row['crypted']; |
| | | $result->free(); |
| | | } |
| | | } |
| | | // loop through hostlist |
| | | foreach($host_list as $db_host) { |
| | | $db_host = trim($db_host); |
| | |
| | | if($valid == false) continue; |
| | | |
| | | if($action == 'GRANT') { |
| | | if(!$link->query("GRANT " . ($user_read_only ? "SELECT" : "ALL") . " ON ".$link->escape_string($database_name).".* TO '".$link->escape_string($database_user)."'@'$db_host' IDENTIFIED BY PASSWORD '".$link->escape_string($database_password)."';")) $success = false; |
| | | $app->log("GRANT " . ($user_read_only ? "SELECT" : "ALL") . " ON ".$link->escape_string($database_name).".* TO '".$link->escape_string($database_user)."'@'$db_host' IDENTIFIED BY PASSWORD '".$link->escape_string($database_password)."'; success? " . ($success ? 'yes' : 'no'), LOGLEVEL_DEBUG); |
| | | if(!$link->query("GRANT " . ($user_read_only ? "SELECT" : "ALL") . " ON `".$link->escape_string($database_name)."`.* TO '".$link->escape_string($database_user)."'@'$db_host' IDENTIFIED BY PASSWORD '".$link->escape_string($database_password)."';")) $success = false; |
| | | $app->log("GRANT " . ($user_read_only ? "SELECT" : "ALL") . " ON `".$link->escape_string($database_name)."`.* TO '".$link->escape_string($database_user)."'@'$db_host' IDENTIFIED BY PASSWORD '".$link->escape_string($database_password)."'; success? " . ($success ? 'yes' : 'no'), LOGLEVEL_DEBUG); |
| | | } elseif($action == 'REVOKE') { |
| | | if(!$link->query("REVOKE ALL PRIVILEGES ON ".$link->escape_string($database_name).".* FROM '".$link->escape_string($database_user)."'@'$db_host' IDENTIFIED BY PASSWORD '".$link->escape_string($database_password)."';")) $success = false; |
| | | if(!$link->query("REVOKE ALL PRIVILEGES ON `".$link->escape_string($database_name)."`.* FROM '".$link->escape_string($database_user)."'@'$db_host' IDENTIFIED BY PASSWORD '".$link->escape_string($database_password)."';")) $success = false; |
| | | } elseif($action == 'DROP') { |
| | | if(!$link->query("DROP USER '".$link->escape_string($database_user)."'@'$db_host';")) $success = false; |
| | | } elseif($action == 'RENAME') { |
| | |
| | | } |
| | | |
| | | //* Create the new database |
| | | if ($link->query('CREATE DATABASE '.$link->escape_string($data['new']['database_name']).$query_charset_table)) { |
| | | if ($link->query('CREATE DATABASE `'.$link->escape_string($data['new']['database_name']).'`'.$query_charset_table)) { |
| | | $app->log('Created MySQL database: '.$data['new']['database_name'], LOGLEVEL_DEBUG); |
| | | } else { |
| | | $app->log('Unable to create the database: '.$link->error, LOGLEVEL_WARNING); |
| | |
| | | $old_host_list .= 'localhost'; |
| | | |
| | | // Create the database user if database was disabled before |
| | | if($data['new']['active'] == 'y' && $data['old']['active'] == 'n') { |
| | | if($data['new']['active'] == 'y') { |
| | | if($db_user) { |
| | | if($db_user['database_user'] == 'root') $app->log('User root not allowed for Client databases', LOGLEVEL_WARNING); |
| | | else $this->process_host_list('GRANT', $data['new']['database_name'], $db_user['database_user'], $db_user['database_password'], $host_list, $link); |
| | |
| | | } |
| | | |
| | | |
| | | if($link->query('DROP DATABASE '.$link->escape_string($data['old']['database_name']))) { |
| | | if($link->query('DROP DATABASE `'.$link->escape_string($data['old']['database_name'].'`'))) { |
| | | $app->log('Dropping MySQL database: '.$data['old']['database_name'], LOGLEVEL_DEBUG); |
| | | } else { |
| | | $app->log('Error while dropping MySQL database: '.$data['old']['database_name'].' '.$link->error, LOGLEVEL_WARNING); |