mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-04-21 08:28:48 +02:00
Fixed problems with MySQL user management
This commit is contained in:
parent
a62d13b14b
commit
2e8819dfa8
@ -35,7 +35,7 @@ CreateDb::CreateDb(QString host,QString database,QString username,QString passwo
|
||||
db_pass=password;
|
||||
}
|
||||
|
||||
bool CreateDb::create(QWidget *parent,QString *err_str,RDConfig *config)
|
||||
bool CreateDb::create(QWidget *parent,QString *err_str,RDConfig *rd_config)
|
||||
{
|
||||
QString sql;
|
||||
|
||||
@ -43,7 +43,7 @@ bool CreateDb::create(QWidget *parent,QString *err_str,RDConfig *config)
|
||||
// Open Database
|
||||
//
|
||||
if (!db.isOpen()){
|
||||
db=QSqlDatabase::addDatabase(config->mysqlDriver(),"createDb");
|
||||
db=QSqlDatabase::addDatabase(rd_config->mysqlDriver(),"createDb");
|
||||
if(!db.isValid()) {
|
||||
*err_str+= QString(QObject::tr("Couldn't initialize MySql driver!"));
|
||||
return true;
|
||||
@ -78,8 +78,41 @@ bool CreateDb::create(QWidget *parent,QString *err_str,RDConfig *config)
|
||||
}
|
||||
delete q;
|
||||
|
||||
sql=QString().sprintf("grant all on * to %s identified by \"%s\"",
|
||||
(const char *)db_user,(const char *)db_pass);
|
||||
//
|
||||
// Drop any existing 'rduser'@'%' and 'rduser'@'localhost' users
|
||||
//
|
||||
sql=QString().sprintf("drop user '%s'@'%%'",(const char *)rd_config->mysqlUsername());
|
||||
q=new QSqlQuery(sql,db);
|
||||
delete q;
|
||||
sql=QString().sprintf("drop user '%s'@'localhost'",(const char *)rd_config->mysqlUsername());
|
||||
q=new QSqlQuery(sql,db);
|
||||
delete q;
|
||||
|
||||
sql=QString("flush privileges");
|
||||
q=new QSqlQuery(sql,db);
|
||||
delete q;
|
||||
|
||||
sql=QString().sprintf("create user '%s'@'%%' identified by \"%s\"",
|
||||
(const char *)rd_config->mysqlUsername(),(const char *)rd_config->mysqlPassword());
|
||||
q=new QSqlQuery(sql,db);
|
||||
if (!q->isActive()) {
|
||||
*err_str+=QString().sprintf("Could not create user: '%s'@'%%'",(const char *)sql);
|
||||
return true;
|
||||
}
|
||||
delete q;
|
||||
|
||||
sql=QString().sprintf("create user '%s'@'localhost' identified by \"%s\"",
|
||||
(const char *)rd_config->mysqlUsername(),(const char *)rd_config->mysqlPassword());
|
||||
q=new QSqlQuery(sql,db);
|
||||
if (!q->isActive()) {
|
||||
*err_str+=QString().sprintf("Could not create user: '%s'@'localhost'",(const char *)sql);
|
||||
return true;
|
||||
}
|
||||
delete q;
|
||||
|
||||
sql=QString().sprintf("grant SELECT, INSERT, UPDATE, DELETE, CREATE, DROP,\
|
||||
INDEX, ALTER, LOCK TABLES on %s.* to %s",
|
||||
(const char *)db_name, (const char *)rd_config->mysqlUsername());
|
||||
q=new QSqlQuery(sql,db);
|
||||
if (!q->isActive()) {
|
||||
*err_str+=QString().sprintf("Could not set permissions: %s",(const char *)sql);
|
||||
@ -87,6 +120,10 @@ bool CreateDb::create(QWidget *parent,QString *err_str,RDConfig *config)
|
||||
}
|
||||
delete q;
|
||||
|
||||
sql=QString("flush privileges");
|
||||
q=new QSqlQuery(sql,db);
|
||||
delete q;
|
||||
|
||||
QProcess rddbmgrProcess(parent);
|
||||
QStringList args;
|
||||
args << QString("--create");
|
||||
|
@ -176,7 +176,6 @@ void MainWidget::updateLabels()
|
||||
db = new Db(&err_msg,rd_config);
|
||||
|
||||
if (!db->isOpen()) {
|
||||
QMessageBox::information(this,tr("Cannot Open Database"),tr("Unable to open database. The connection parameters of the [Mysql] section of rd.conf may be incorrect or you may need to create a new database."));
|
||||
label_schema->setVisible(false);
|
||||
db_backup_button->setEnabled(false);
|
||||
db_restore_button->setEnabled(false);
|
||||
@ -234,6 +233,8 @@ void MainWidget::createData()
|
||||
|
||||
delete db_create;
|
||||
|
||||
updateLabels();
|
||||
|
||||
startDaemons();
|
||||
}
|
||||
|
||||
@ -348,7 +349,9 @@ void MainWidget::resizeEvent(QResizeEvent *e)
|
||||
void MainWidget::stopDaemons()
|
||||
{
|
||||
if(system("/usr/bin/systemctl status rivendell")==0) {
|
||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||
system("/usr/bin/systemctl stop rivendell");
|
||||
QApplication::restoreOverrideCursor();
|
||||
db_daemon_start_needed=true;
|
||||
}
|
||||
}
|
||||
@ -357,7 +360,9 @@ void MainWidget::stopDaemons()
|
||||
void MainWidget::startDaemons()
|
||||
{
|
||||
if(db_daemon_start_needed) {
|
||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||
system("/usr/bin/systemctl start rivendell");
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user