1
0
mirror of https://github.com/ElvishArtisan/rivendell.git synced 2025-05-30 15:42:34 +02:00

Requires root privileges

Improved error detection and reporting
This commit is contained in:
Patrick Linstruth 2018-10-08 16:40:05 -07:00
parent b89e38e52b
commit a62d13b14b
3 changed files with 25 additions and 24 deletions

@ -20,6 +20,7 @@
#include <qapplication.h>
#include <qprocess.h>
#include <qmessagebox.h>
#include <rdconfig.h>
#include <rdpaths.h>
@ -34,7 +35,7 @@ CreateDb::CreateDb(QString host,QString database,QString username,QString passwo
db_pass=password;
}
bool CreateDb::create(QObject *parent,QString *err_str,RDConfig *config)
bool CreateDb::create(QWidget *parent,QString *err_str,RDConfig *config)
{
QString sql;
@ -64,7 +65,7 @@ bool CreateDb::create(QObject *parent,QString *err_str,RDConfig *config)
sql=QString().sprintf("drop database if exists `%s`",(const char *)db_name);
q=new QSqlQuery(sql,db);
if (!q->isActive()) {
*err_str+=QString(QObject::tr("Could not remove database"));
*err_str+=QString(QObject::tr("Could not remove old database"));
return true;
}
delete q;
@ -72,12 +73,13 @@ bool CreateDb::create(QObject *parent,QString *err_str,RDConfig *config)
sql=QString().sprintf("create database if not exists `%s`",(const char *)db_name);
q=new QSqlQuery(sql,db);
if (!q->isActive()) {
*err_str+=QString(QObject::tr("Could not create database"));
*err_str+=QString(QObject::tr("Could not create new database"));
return true;
}
delete q;
sql=QString().sprintf("grant all on * to %s identified by \"%s\"",(const char *)db_user,(const char *)db_pass);
sql=QString().sprintf("grant all on * to %s identified by \"%s\"",
(const char *)db_user,(const char *)db_pass);
q=new QSqlQuery(sql,db);
if (!q->isActive()) {
*err_str+=QString().sprintf("Could not set permissions: %s",(const char *)sql);
@ -93,7 +95,8 @@ bool CreateDb::create(QObject *parent,QString *err_str,RDConfig *config)
rddbmgrProcess.waitForFinished();
QApplication::restoreOverrideCursor();
if (rddbmgrProcess.exitCode()) {
fprintf(stderr,"Exit Code=%d\n",rddbmgrProcess.exitCode());
*err_str+=QString().sprintf("Failed to create %s database. Rddbmgr exit code=%d",
(const char *)db_name,rddbmgrProcess.exitCode());
return true;
}
}

@ -65,11 +65,11 @@ MySqlLogin::MySqlLogin(QString msg,QString *hostname,QString *dbname,QString *us
// MySql Host Name
//
login_host_edit=new QLineEdit(this);
login_host_edit->setReadOnly(true);
login_host_edit->setFont(font);
login_host_edit->setGeometry(100,sizeHint().height()-150,200,19);
login_host_edit->setMaxLength(64);
login_host_edit->setText(*login_host);
login_host_edit->setFocus();
QLabel *login_host_label=new QLabel(login_host_edit,tr("&Hostname:"),this);
login_host_label->setFont(font);
login_host_label->setGeometry(10,sizeHint().height()-150,85,19);
@ -79,11 +79,11 @@ MySqlLogin::MySqlLogin(QString msg,QString *hostname,QString *dbname,QString *us
// MySql Database Name
//
login_dbname_edit=new QLineEdit(this);
login_dbname_edit->setReadOnly(true);
login_dbname_edit->setFont(font);
login_dbname_edit->setGeometry(100,sizeHint().height()-130,200,19);
login_dbname_edit->setMaxLength(64);
login_dbname_edit->setText(*login_dbname);
login_dbname_edit->setFocus();
QLabel *login_dbname_label=new QLabel(login_dbname_edit,tr("&Database:"),this);
login_dbname_label->setFont(font);
login_dbname_label->setGeometry(10,sizeHint().height()-130,85,19);

@ -51,6 +51,12 @@ MainWidget::MainWidget(QWidget *parent)
db_daemon_start_needed=false;
db=NULL;
if(geteuid()!=0) {
QMessageBox::critical(this,tr("RDDbConfig Error"),
tr("This application requires root permissions."));
exit(256);
}
//
// Open rd.conf(5)
//
@ -170,7 +176,7 @@ void MainWidget::updateLabels()
db = new Db(&err_msg,rd_config);
if (!db->isOpen()) {
QMessageBox::critical(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."));
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);
@ -198,12 +204,6 @@ void MainWidget::createData()
QString msg="Message";
QString err_str;
if(geteuid()!=0) {
QMessageBox::warning(this,tr("RDDbConfig error"),
tr("Create requires root permissions."));
return;
}
if (db->isOpen()) {
if (QMessageBox::question(this,tr("Create Database"),tr("Creating a new database will erase all of your data. Are you sure you want to create a new database?"),(QMessageBox::No|QMessageBox::Yes)) != QMessageBox::Yes) {
return;
@ -217,6 +217,7 @@ void MainWidget::createData()
delete mysql_login;
if(admin_name.isEmpty()||admin_pwd.isEmpty()||hostname.isEmpty()||dbname.isEmpty()) {
QMessageBox::critical(this,tr("RDDbConfig Error"),tr("Did not specify username and/or password."));
return;
}
@ -225,7 +226,10 @@ void MainWidget::createData()
CreateDb *db_create=new CreateDb(hostname,dbname,admin_name,admin_pwd);
if(db_create->create(this,&err_str,rd_config)) {
fprintf(stderr,"err_str: %s\n",(const char *)err_str);
QMessageBox::critical(this,tr("RDDbConfig Error"),err_str);
}
else {
QMessageBox::information(this,tr("Success"),tr("A new database has been successfully created."));
}
delete db_create;
@ -262,7 +266,7 @@ void MainWidget::backupData()
QApplication::restoreOverrideCursor();
if (backupProcess.exitCode()) {
fprintf(stderr,"Exit Code=%d\n",backupProcess.exitCode());
QMessageBox::critical(this,tr("RDDbConfig error"),
QMessageBox::critical(this,tr("RDDbConfig Error"),
QString(backupProcess.readAllStandardError()));
}
else {
@ -283,14 +287,8 @@ void MainWidget::restoreData()
{
QString filename;
if(geteuid()!=0) {
QMessageBox::warning(this,tr("RDDbConfig error"),
tr("Restore requires root permissions."));
return;
}
if (!db->isOpen()) {
QMessageBox::critical(this,tr("RDDbConfig error"),
QMessageBox::critical(this,tr("RDDbConfig Error"),
tr("Could not open Rivendell database."));
return;
}
@ -316,7 +314,7 @@ void MainWidget::restoreData()
restoreProcess.waitForFinished();
QApplication::restoreOverrideCursor();
if (restoreProcess.exitCode()) {
QMessageBox::critical(this,tr("RDDbConfig error"),
QMessageBox::critical(this,tr("RDDbConfig Error"),
QString(restoreProcess.readAllStandardError()));
}
else {