mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-06-05 06:32:34 +02:00
Merge branch 'RDDBConfig' of https://github.com/deltecent/rivendell into deltecent-RDDBConfig
This commit is contained in:
commit
1c5a6d3954
@ -494,6 +494,7 @@ AC_CONFIG_FILES([rivendell.spec \
|
||||
utils/rdclilogedit/Makefile \
|
||||
utils/rdcollect/Makefile \
|
||||
utils/rdconvert/Makefile \
|
||||
utils/rddbconfig/Makefile \
|
||||
utils/rddbmgr/Makefile \
|
||||
utils/rddelete/Makefile \
|
||||
utils/rddgimport/Makefile \
|
||||
|
@ -30,6 +30,7 @@ SUBDIRS = $(ALSACONFIG_RD_OPT)\
|
||||
rdclilogedit\
|
||||
rdcollect\
|
||||
rdconvert\
|
||||
rddbconfig\
|
||||
rddbmgr\
|
||||
rddelete\
|
||||
rddiscimport\
|
||||
|
49
utils/rddbconfig/Makefile.am
Normal file
49
utils/rddbconfig/Makefile.am
Normal file
@ -0,0 +1,49 @@
|
||||
## Makefile.am
|
||||
##
|
||||
## (C) Copyright 2009,2016-2018 Fred Gleason <fredg@paravelsystems.com>
|
||||
##
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License version 2 as
|
||||
## published by the Free Software Foundation.
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public
|
||||
## License along with this program; if not, write to the Free Software
|
||||
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
##
|
||||
## Use automake to process this into a Makefile.in
|
||||
##
|
||||
|
||||
AM_CPPFLAGS = -Wall -DPREFIX=\"$(prefix)\" -I$(top_srcdir)/lib -I$(top_srcdir)/rdhpi @QT4_CFLAGS@ -DQT3_SUPPORT -I/usr/include/Qt3Support
|
||||
LIBS = -L$(top_srcdir)/lib -L$(top_srcdir)/rdhpi
|
||||
MOC = @QT_MOC@
|
||||
|
||||
# The dependency for qt's Meta Object Compiler (moc)
|
||||
moc_%.cpp: %.h
|
||||
$(MOC) $< -o $@
|
||||
|
||||
bin_PROGRAMS = rddbconfig
|
||||
|
||||
dist_rddbconfig_SOURCES = rddbconfig.cpp rddbconfig.h mysql_login.cpp mysql_login.h \
|
||||
db.cpp db.h createdb.cpp createdb.h
|
||||
|
||||
nodist_rddbconfig_SOURCES = moc_rddbconfig.cpp moc_mysql_login.cpp
|
||||
|
||||
rddbconfig_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @LIBALSA@ @QT4_LIBS@ -lQt3Support
|
||||
|
||||
EXTRA_DIST = rddbconfig.pro
|
||||
|
||||
CLEANFILES = *~\
|
||||
*.qm\
|
||||
moc_*
|
||||
|
||||
MAINTAINERCLEANFILES = *~\
|
||||
*.tar.gz\
|
||||
aclocal.m4\
|
||||
configure\
|
||||
Makefile.in\
|
||||
moc_*
|
154
utils/rddbconfig/createdb.cpp
Normal file
154
utils/rddbconfig/createdb.cpp
Normal file
@ -0,0 +1,154 @@
|
||||
// createdb.cpp
|
||||
//
|
||||
// Create Rivendell MySQL database RDDbConfig
|
||||
//
|
||||
// (C) Copyright 2002-2018 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public
|
||||
// License along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#include <qapplication.h>
|
||||
#include <qprocess.h>
|
||||
#include <qmessagebox.h>
|
||||
|
||||
#include <rdconfig.h>
|
||||
#include <rdpaths.h>
|
||||
|
||||
#include "createdb.h"
|
||||
|
||||
CreateDb::CreateDb(QString host,QString database,QString username,QString password)
|
||||
{
|
||||
db_host=host;
|
||||
db_name=database;
|
||||
db_user=username;
|
||||
db_pass=password;
|
||||
}
|
||||
|
||||
bool CreateDb::create(QWidget *parent,QString *err_str,RDConfig *rd_config)
|
||||
{
|
||||
QString sql;
|
||||
|
||||
//
|
||||
// Open Database
|
||||
//
|
||||
QSqlDatabase db=QSqlDatabase::addDatabase(rd_config->mysqlDriver(),"createDb");
|
||||
if(!db.isValid()) {
|
||||
*err_str+= QString(QObject::tr("Couldn't initialize MySql driver!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
db.setHostName(db_host);
|
||||
db.setDatabaseName("mysql");
|
||||
db.setUserName(db_user);
|
||||
db.setPassword(db_pass);
|
||||
if(!db.open()) {
|
||||
*err_str+=QString().sprintf("Couldn't open MySQL connection on %s",(const char *)db_host);
|
||||
return true;
|
||||
}
|
||||
|
||||
QSqlQuery *q;
|
||||
|
||||
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 old database"));
|
||||
return true;
|
||||
}
|
||||
delete q;
|
||||
|
||||
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 new database"));
|
||||
return true;
|
||||
}
|
||||
delete q;
|
||||
|
||||
//
|
||||
// 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);
|
||||
return true;
|
||||
}
|
||||
delete q;
|
||||
|
||||
sql=QString("flush privileges");
|
||||
q=new QSqlQuery(sql,db);
|
||||
delete q;
|
||||
|
||||
QProcess rddbmgrProcess(parent);
|
||||
QStringList args;
|
||||
args << QString("--create");
|
||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||
rddbmgrProcess.start(QString(RD_PREFIX)+"/sbin/rddbmgr",args);
|
||||
rddbmgrProcess.waitForFinished();
|
||||
QApplication::restoreOverrideCursor();
|
||||
if (rddbmgrProcess.exitCode()) {
|
||||
*err_str+=QString().sprintf("Failed to create %s database. Rddbmgr exit code=%d",
|
||||
(const char *)db_name,rddbmgrProcess.exitCode());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
CreateDb::~CreateDb()
|
||||
{
|
||||
{
|
||||
QSqlDatabase db=QSqlDatabase::database("createDb");
|
||||
db.close();
|
||||
}
|
||||
QSqlDatabase::removeDatabase("createDb");
|
||||
}
|
||||
|
||||
bool CreateDb::isOpen()
|
||||
{
|
||||
QSqlDatabase db=QSqlDatabase::database("createDb");
|
||||
return db.isOpen();
|
||||
}
|
||||
|
46
utils/rddbconfig/createdb.h
Normal file
46
utils/rddbconfig/createdb.h
Normal file
@ -0,0 +1,46 @@
|
||||
// createdb.h
|
||||
//
|
||||
// Create a Rivendell Database
|
||||
//
|
||||
// (C) Copyright 2002-2018 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public
|
||||
// License along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#ifndef CREATEDB_H
|
||||
#define CREATEDB_H
|
||||
|
||||
#include <qsqldatabase.h>
|
||||
#include <qsqlquery.h>
|
||||
|
||||
#include <rdconfig.h>
|
||||
|
||||
class CreateDb
|
||||
{
|
||||
public:
|
||||
CreateDb(QString host,QString database,QString username,QString password);
|
||||
~CreateDb();
|
||||
bool create(QWidget *parent,QString *err_str, RDConfig *config);
|
||||
bool isOpen();
|
||||
|
||||
private:
|
||||
QString db_host;
|
||||
QString db_name;
|
||||
QString db_user;
|
||||
QString db_pass;
|
||||
};
|
||||
|
||||
#endif // CREATEDB_H
|
||||
|
||||
|
76
utils/rddbconfig/db.cpp
Normal file
76
utils/rddbconfig/db.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
// db.cpp
|
||||
//
|
||||
// Create Rivendell MySQL database RDDbConfig
|
||||
//
|
||||
// (C) Copyright 2002-2018 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public
|
||||
// License along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#include <qsqldatabase.h>
|
||||
#include <qsqlquery.h>
|
||||
|
||||
#include "db.h"
|
||||
|
||||
Db::Db(QString *err_str,RDConfig *config)
|
||||
{
|
||||
QSqlQuery *q;
|
||||
db_schema=0;
|
||||
|
||||
//
|
||||
// Open Database
|
||||
//
|
||||
QSqlDatabase db=QSqlDatabase::addDatabase(config->mysqlDriver(),"Rivendell");
|
||||
if(!db.isValid()) {
|
||||
*err_str+= QString(QObject::tr("Couldn't initialize MySql driver!"));
|
||||
return;
|
||||
}
|
||||
db.setHostName(config->mysqlHostname());
|
||||
db.setDatabaseName(config->mysqlDbname());
|
||||
db.setUserName(config->mysqlUsername());
|
||||
db.setPassword(config->mysqlPassword());
|
||||
if(!db.open()) {
|
||||
*err_str+=QString().sprintf("Couldn't open MySQL connection on %s",
|
||||
(const char *)config->mysqlHostname());
|
||||
return;
|
||||
}
|
||||
|
||||
q=new QSqlQuery("select DB from VERSION",db);
|
||||
if(q->first()) {
|
||||
db_schema=q->value(0).toUInt();
|
||||
}
|
||||
delete q;
|
||||
}
|
||||
|
||||
|
||||
Db::~Db()
|
||||
{
|
||||
{
|
||||
QSqlDatabase db=QSqlDatabase::database("Rivendell");
|
||||
db.close();
|
||||
}
|
||||
QSqlDatabase::removeDatabase("Rivendell");
|
||||
}
|
||||
|
||||
bool Db::isOpen()
|
||||
{
|
||||
QSqlDatabase db=QSqlDatabase::database("Rivendell");
|
||||
return db.isOpen();
|
||||
}
|
||||
|
||||
unsigned Db::schema()
|
||||
{
|
||||
return db_schema;
|
||||
}
|
||||
|
42
utils/rddbconfig/db.h
Normal file
42
utils/rddbconfig/db.h
Normal file
@ -0,0 +1,42 @@
|
||||
// db.h
|
||||
//
|
||||
// Create a Rivendell Database
|
||||
//
|
||||
// (C) Copyright 2002-2018 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public
|
||||
// License along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#ifndef DB_H
|
||||
#define DB_H
|
||||
|
||||
#include <qsqldatabase.h>
|
||||
|
||||
#include <rdconfig.h>
|
||||
|
||||
class Db
|
||||
{
|
||||
public:
|
||||
Db(QString *err_str,RDConfig *config);
|
||||
~Db();
|
||||
bool isOpen();
|
||||
unsigned schema();
|
||||
|
||||
private:
|
||||
unsigned db_schema;
|
||||
};
|
||||
|
||||
#endif // DB_H
|
||||
|
||||
|
140
utils/rddbconfig/mysql_login.cpp
Normal file
140
utils/rddbconfig/mysql_login.cpp
Normal file
@ -0,0 +1,140 @@
|
||||
// mysql_login.cpp
|
||||
//
|
||||
// mySQL Administrative Login widget for RDDbConfig
|
||||
//
|
||||
// (C) Copyright 2002-2018 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public
|
||||
// License along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#include <qdialog.h>
|
||||
|
||||
#include <qdialog.h>
|
||||
#include <qsize.h>
|
||||
#include <qsizepolicy.h>
|
||||
#include <qsqldatabase.h>
|
||||
#include <qpushbutton.h>
|
||||
#include <qcombobox.h>
|
||||
#include <qlabel.h>
|
||||
#include <qcheckbox.h>
|
||||
#include <qpixmap.h>
|
||||
#include <q3progressdialog.h>
|
||||
#include <qtimer.h>
|
||||
|
||||
#include <rdlabel.h>
|
||||
|
||||
#include "mysql_login.h"
|
||||
|
||||
MySqlLogin::MySqlLogin(QString *username,QString *password, QWidget *parent)
|
||||
: QDialog(parent,"",true)
|
||||
{
|
||||
setCaption(tr("mySQL Admin"));
|
||||
login_name=username;
|
||||
login_password=password;
|
||||
|
||||
//
|
||||
// Create Fonts
|
||||
//
|
||||
QFont font=QFont("Helvetica",12,QFont::Normal);
|
||||
font.setPixelSize(12);
|
||||
|
||||
//
|
||||
// Message Label
|
||||
//
|
||||
RDLabel *label=new RDLabel(tr("Enter your MySQL administrator username and password\nThe Hostname and Database are found in /etc/rd.conf"),this);
|
||||
label->setFont(font);
|
||||
label->setGeometry(10,10,sizeHint().width()-20,30);
|
||||
label->setAlignment(Qt::AlignCenter);
|
||||
|
||||
//
|
||||
// MySql Login Name
|
||||
//
|
||||
login_name_edit=new QLineEdit(this);
|
||||
login_name_edit->setFont(font);
|
||||
login_name_edit->setGeometry(sizeHint().width()/2-125+90,50,140,19);
|
||||
login_name_edit->setMaxLength(16);
|
||||
login_name_edit->setFocus();
|
||||
QLabel *login_name_label=new QLabel(login_name_edit,tr("&Username:"),this);
|
||||
login_name_label->setFont(font);
|
||||
login_name_label->setGeometry(sizeHint().width()/2-125,50,85,19);
|
||||
login_name_label->setAlignment(Qt::AlignRight|Qt::ShowPrefix);
|
||||
|
||||
//
|
||||
// MySql Login Password
|
||||
//
|
||||
login_password_edit=new QLineEdit(this);
|
||||
login_password_edit->setFont(font);
|
||||
login_password_edit->setGeometry(sizeHint().width()/2-125+90,70,140,19);
|
||||
login_password_edit->setMaxLength(16);
|
||||
login_password_edit->setEchoMode(QLineEdit::Password);
|
||||
QLabel *login_password_label=new QLabel(login_password_edit,tr("&Password:"),this);
|
||||
login_password_label->setFont(font);
|
||||
login_password_label->setGeometry(sizeHint().width()/2-125,70,85,19);
|
||||
login_password_label->setAlignment(Qt::AlignRight|Qt::ShowPrefix);
|
||||
|
||||
//
|
||||
// OK Button
|
||||
//
|
||||
QPushButton *ok_button=new QPushButton(this);
|
||||
ok_button->setGeometry(sizeHint().width()/2-90,sizeHint().height()-60,80,50);
|
||||
ok_button->setFont(font);
|
||||
ok_button->setText(tr("&OK"));
|
||||
ok_button->setDefault(true);
|
||||
connect(ok_button,SIGNAL(clicked()),this,SLOT(okData()));
|
||||
|
||||
//
|
||||
// Cancel Button
|
||||
//
|
||||
QPushButton *cancel_button=new QPushButton(this);
|
||||
cancel_button->setGeometry(sizeHint().width()/2+10,sizeHint().height()-60,
|
||||
80,50);
|
||||
cancel_button->setFont(font);
|
||||
cancel_button->setText(tr("&Cancel"));
|
||||
connect(cancel_button,SIGNAL(clicked()),this,SLOT(cancelData()));
|
||||
}
|
||||
|
||||
|
||||
MySqlLogin::~MySqlLogin()
|
||||
{
|
||||
delete login_name_edit;
|
||||
delete login_password_edit;
|
||||
}
|
||||
|
||||
|
||||
QSize MySqlLogin::sizeHint() const
|
||||
{
|
||||
return QSize(340,160);
|
||||
}
|
||||
|
||||
|
||||
QSizePolicy MySqlLogin::sizePolicy() const
|
||||
{
|
||||
return QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
|
||||
}
|
||||
|
||||
|
||||
void MySqlLogin::okData()
|
||||
{
|
||||
*login_name=login_name_edit->text();
|
||||
*login_password=login_password_edit->text();
|
||||
|
||||
done(0);
|
||||
}
|
||||
|
||||
|
||||
void MySqlLogin::cancelData()
|
||||
{
|
||||
done(1);
|
||||
}
|
||||
|
53
utils/rddbconfig/mysql_login.h
Normal file
53
utils/rddbconfig/mysql_login.h
Normal file
@ -0,0 +1,53 @@
|
||||
// mysql_login.h
|
||||
//
|
||||
// mySQL Administrative Login Widget for RDAdmin.
|
||||
//
|
||||
// (C) Copyright 2002-2003,2016 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public
|
||||
// License along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#ifndef MYSQL_LOGIN_H
|
||||
#define MYSQL_LOGIN_H
|
||||
|
||||
#include <qdialog.h>
|
||||
#include <qlineedit.h>
|
||||
#include <qtextedit.h>
|
||||
#include <qpixmap.h>
|
||||
#include <qradiobutton.h>
|
||||
|
||||
class MySqlLogin : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MySqlLogin(QString *username,QString *password, QWidget *parent=0);
|
||||
~MySqlLogin();
|
||||
QSize sizeHint() const;
|
||||
QSizePolicy sizePolicy() const;
|
||||
|
||||
private slots:
|
||||
void okData();
|
||||
void cancelData();
|
||||
|
||||
private:
|
||||
QString *login_name;
|
||||
QLineEdit *login_name_edit;
|
||||
QString *login_password;
|
||||
QLineEdit *login_password_edit;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
412
utils/rddbconfig/rddbconfig.cpp
Normal file
412
utils/rddbconfig/rddbconfig.cpp
Normal file
@ -0,0 +1,412 @@
|
||||
// rddbconfig.cpp
|
||||
//
|
||||
// A Qt-based application to configure, backup, and restore
|
||||
// the Rivendell database.
|
||||
//
|
||||
// (C) Copyright 2009-2018 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public
|
||||
// License along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#define LINE fprintf(stderr,"%s:%d\n",__FILE__,__LINE__);
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <qapplication.h>
|
||||
#include <qprocess.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <q3filedialog.h>
|
||||
|
||||
#include <rdconfig.h>
|
||||
|
||||
#include "../../icons/rivendell-22x22.xpm"
|
||||
|
||||
#include <rddbconfig.h>
|
||||
|
||||
#include "db.h"
|
||||
#include "createdb.h"
|
||||
#include "mysql_login.h"
|
||||
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
MainWidget::MainWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
QString err_msg;
|
||||
|
||||
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)
|
||||
//
|
||||
rd_config=new RDConfig();
|
||||
rd_config->load();
|
||||
rd_config->setModuleName("rddbconfig");
|
||||
|
||||
setWindowTitle(tr("RDDbConfig")+" v"+VERSION);
|
||||
|
||||
//
|
||||
// Create And Set Icon
|
||||
//
|
||||
setWindowIcon(QPixmap(rivendell_22x22_xpm));
|
||||
|
||||
//
|
||||
// Fix the Window Size
|
||||
//
|
||||
setMinimumWidth(sizeHint().width());
|
||||
setMinimumHeight(sizeHint().height());
|
||||
|
||||
//
|
||||
// Generate Fonts
|
||||
//
|
||||
QFont font("Helvetica",12,QFont::Normal);
|
||||
font.setPixelSize(12);
|
||||
QFont label_font("Helvetica",12,QFont::Bold);
|
||||
label_font.setPixelSize(12);
|
||||
QFont day_font=QFont("Helvetica",12,QFont::Normal);
|
||||
day_font.setPixelSize(12);
|
||||
|
||||
//
|
||||
// Labels
|
||||
//
|
||||
QLabel *label=new QLabel(tr("Select an operation:"),this);
|
||||
label->setGeometry(0,90,sizeHint().width(),16);
|
||||
label->setFont(label_font);
|
||||
label->setAlignment(Qt::AlignCenter);
|
||||
|
||||
label_hostname=new QLabel(QString().sprintf("SQL Server: %s",
|
||||
(const char *)rd_config->mysqlHostname()),this);
|
||||
label_hostname->setGeometry(0,5,sizeHint().width(),16);
|
||||
label_hostname->setFont(day_font);
|
||||
label_hostname->setAlignment(Qt::AlignCenter);
|
||||
|
||||
label_username=new QLabel(QString().sprintf("SQL Usename: %s",
|
||||
(const char *)rd_config->mysqlUsername()),this);
|
||||
label_username->setGeometry(0,20,sizeHint().width(),16);
|
||||
label_username->setFont(day_font);
|
||||
label_username->setAlignment(Qt::AlignCenter);
|
||||
|
||||
label_dbname=new QLabel(QString().sprintf("SQL Database: %s",
|
||||
(const char *)rd_config->mysqlDbname()),this);
|
||||
label_dbname->setGeometry(0,35,sizeHint().width(),16);
|
||||
label_dbname->setFont(day_font);
|
||||
label_dbname->setAlignment(Qt::AlignCenter);
|
||||
|
||||
label_schema=new QLabel(this);
|
||||
label_schema->setGeometry(0,50,sizeHint().width(),16);
|
||||
label_schema->setFont(day_font);
|
||||
label_schema->setAlignment(Qt::AlignCenter);
|
||||
|
||||
//
|
||||
// Create Button
|
||||
//
|
||||
db_create_button=new QPushButton(tr("Create"),this);
|
||||
db_create_button->setFont(label_font);
|
||||
connect(db_create_button,SIGNAL(clicked()),this,SLOT(createData()));
|
||||
|
||||
//
|
||||
// Backup Button
|
||||
//
|
||||
db_backup_button=new QPushButton(tr("Backup"),this);
|
||||
db_backup_button->setFont(label_font);
|
||||
connect(db_backup_button,SIGNAL(clicked()),this,SLOT(backupData()));
|
||||
|
||||
//
|
||||
// Restore Button
|
||||
//
|
||||
db_restore_button=new QPushButton(tr("Restore"),this);
|
||||
db_restore_button->setFont(label_font);
|
||||
connect(db_restore_button,SIGNAL(clicked()),this,SLOT(restoreData()));
|
||||
|
||||
//
|
||||
// Close Button
|
||||
//
|
||||
db_close_button=new QPushButton(tr("Close"),this);
|
||||
db_close_button->setFont(label_font);
|
||||
connect(db_close_button,SIGNAL(clicked()),this,SLOT(closeData()));
|
||||
|
||||
updateLabels();
|
||||
}
|
||||
|
||||
|
||||
MainWidget::~MainWidget()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QSize MainWidget::sizeHint() const
|
||||
{
|
||||
return QSize(280,330);
|
||||
}
|
||||
|
||||
|
||||
QSizePolicy MainWidget::sizePolicy() const
|
||||
{
|
||||
return QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
|
||||
}
|
||||
|
||||
void MainWidget::updateLabels()
|
||||
{
|
||||
QString err_msg="";
|
||||
|
||||
if(db!=NULL) {
|
||||
delete db;
|
||||
}
|
||||
db = new Db(&err_msg,rd_config);
|
||||
|
||||
if (!db->isOpen()) {
|
||||
label_schema->setText("DB Version: unknown");
|
||||
db_backup_button->setEnabled(false);
|
||||
db_restore_button->setEnabled(false);
|
||||
}
|
||||
else {
|
||||
label_schema->setText(QString().sprintf("DB Version: %d",db->schema()));
|
||||
db_backup_button->setEnabled(true);
|
||||
db_restore_button->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWidget::closeData()
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void MainWidget::createData()
|
||||
{
|
||||
MySqlLogin *mysql_login;
|
||||
QString hostname=rd_config->mysqlHostname();
|
||||
QString dbname=rd_config->mysqlDbname();
|
||||
QString admin_name;
|
||||
QString admin_pwd;
|
||||
QString err_str;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
mysql_login=new MySqlLogin(&admin_name,&admin_pwd);
|
||||
|
||||
if(mysql_login->exec()) {
|
||||
delete mysql_login;
|
||||
return;
|
||||
}
|
||||
|
||||
delete mysql_login;
|
||||
|
||||
if(admin_name.isEmpty()||admin_pwd.isEmpty()) {
|
||||
QMessageBox::critical(this,tr("RDDbConfig Error"),tr("Did not specify username and/or password."));
|
||||
return;
|
||||
}
|
||||
|
||||
stopDaemons();
|
||||
|
||||
CreateDb *db_create=new CreateDb(hostname,dbname,admin_name,admin_pwd);
|
||||
|
||||
if(db_create->create(this,&err_str,rd_config)) {
|
||||
QMessageBox::critical(this,tr("RDDbConfig Error"),err_str);
|
||||
}
|
||||
else {
|
||||
QMessageBox::information(this,tr("Success"),tr("A new database has been successfully created."));
|
||||
}
|
||||
|
||||
startDaemons();
|
||||
|
||||
updateLabels();
|
||||
|
||||
delete db_create;
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::backupData()
|
||||
{
|
||||
QString filename;
|
||||
|
||||
if (!db->isOpen()) {
|
||||
QMessageBox::critical(this,tr("RDDbConfig Error"),
|
||||
QString().sprintf("Could not open %s database.",
|
||||
(const char *)rd_config->mysqlDbname()));
|
||||
return;
|
||||
}
|
||||
|
||||
filename=Q3FileDialog::getSaveFileName("rivendell.sql",
|
||||
"MySQL (*.sql)",this,"open file dialog","Enter the MySQL Backup Filename");
|
||||
|
||||
if (!filename.isEmpty()) {
|
||||
QProcess backupProcess(this);
|
||||
QStringList args;
|
||||
args << QString().sprintf("--user=%s",(const char *)rd_config->mysqlUsername())
|
||||
<< QString().sprintf("--password=%s",(const char *)rd_config->mysqlPassword())
|
||||
<< QString().sprintf("--host=%s",(const char *)rd_config->mysqlHostname())
|
||||
<< rd_config->mysqlDbname();
|
||||
backupProcess.setStandardOutputFile(filename);
|
||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||
backupProcess.start("mysqldump", args);
|
||||
backupProcess.waitForFinished();
|
||||
QApplication::restoreOverrideCursor();
|
||||
if (backupProcess.exitCode()) {
|
||||
fprintf(stderr,"Exit Code=%d\n",backupProcess.exitCode());
|
||||
QMessageBox::critical(this,tr("RDDbConfig Error"),
|
||||
QString(backupProcess.readAllStandardError()));
|
||||
}
|
||||
else {
|
||||
QMessageBox::information(this,"Database Backed Up Successfully",
|
||||
QString().sprintf("Backed up %s database to %s",
|
||||
(const char *)rd_config->mysqlDbname(),
|
||||
(const char *)filename));
|
||||
rd_config->log("rddbconfig",RDConfig::LogInfo,
|
||||
QString().sprintf("Backed up %s database to %s",
|
||||
(const char *)rd_config->mysqlDbname(),
|
||||
(const char *)filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::restoreData()
|
||||
{
|
||||
QString filename;
|
||||
|
||||
if (!db->isOpen()) {
|
||||
QMessageBox::critical(this,tr("RDDbConfig Error"),
|
||||
tr("Could not open Rivendell database."));
|
||||
return;
|
||||
}
|
||||
|
||||
filename=Q3FileDialog::getOpenFileName("",
|
||||
"MySQL (*.sql);;All Files(*)",this,"open file dialog",
|
||||
"Choose the MySQL Backup File to Restore");
|
||||
|
||||
if(!filename.isEmpty()) {
|
||||
if (QMessageBox::question(this,tr("Restore Entire Database"),tr("Are you sure you want to restore your entire Rivendell database?"),(QMessageBox::No|QMessageBox::Yes)) != QMessageBox::Yes) {
|
||||
return;
|
||||
}
|
||||
QProcess restoreProcess(this);
|
||||
QStringList args;
|
||||
args << QString().sprintf("--user=%s",(const char *)rd_config->mysqlUsername())
|
||||
<< QString().sprintf("--password=%s",(const char *)rd_config->mysqlPassword())
|
||||
<< QString().sprintf("--host=%s",(const char *)rd_config->mysqlHostname())
|
||||
<< rd_config->mysqlDbname();
|
||||
restoreProcess.setStandardInputFile(filename);
|
||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||
stopDaemons();
|
||||
restoreProcess.start("mysql", args);
|
||||
restoreProcess.waitForFinished();
|
||||
QApplication::restoreOverrideCursor();
|
||||
if (restoreProcess.exitCode()) {
|
||||
QMessageBox::critical(this,tr("RDDbConfig Error"),
|
||||
QString(restoreProcess.readAllStandardError()));
|
||||
}
|
||||
else {
|
||||
QMessageBox::information(this,"Database Restored Successfully",
|
||||
QString().sprintf("Restored %s database from %s",
|
||||
(const char *)rd_config->mysqlDbname(),
|
||||
(const char *)filename));
|
||||
rd_config->log("rddbconfig",RDConfig::LogInfo,
|
||||
QString().sprintf("Restored %s database from %s",
|
||||
(const char *)rd_config->mysqlDbname(),
|
||||
(const char *)filename));
|
||||
}
|
||||
startDaemons();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
db_create_button->
|
||||
setGeometry(size().width()/2-80,110,160,50);
|
||||
db_backup_button->
|
||||
setGeometry(size().width()/2-80,165,160,50);
|
||||
db_restore_button->
|
||||
setGeometry(size().width()/2-80,220,160,50);
|
||||
db_close_button->
|
||||
setGeometry(size().width()/2-80,275,160,50);
|
||||
}
|
||||
|
||||
|
||||
int MainWidget::statusDaemons(QString service)
|
||||
{
|
||||
QProcess statusProcess(this);
|
||||
QStringList args;
|
||||
args << "status" << service;
|
||||
statusProcess.start("systemctl", args);
|
||||
statusProcess.waitForFinished();
|
||||
return statusProcess.exitCode();
|
||||
}
|
||||
|
||||
void MainWidget::stopDaemons()
|
||||
{
|
||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||
if(!statusDaemons("rivendell")) {
|
||||
QProcess stopProcess(this);
|
||||
QStringList args;
|
||||
args << "stop" << "rivendell";
|
||||
stopProcess.start("systemctl", args);
|
||||
stopProcess.waitForFinished();
|
||||
if (!stopProcess.exitCode()) {
|
||||
db_daemon_start_needed=true;
|
||||
}
|
||||
}
|
||||
QApplication::restoreOverrideCursor();
|
||||
#if 0
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::startDaemons()
|
||||
{
|
||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||
if(statusDaemons("rivendell")) {
|
||||
QProcess startProcess(this);
|
||||
QStringList args;
|
||||
args << "start" << "rivendell";
|
||||
startProcess.start("systemctl", args);
|
||||
startProcess.waitForFinished();
|
||||
}
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
//
|
||||
// Start GUI
|
||||
//
|
||||
QApplication::setStyle(RD_GUI_STYLE);
|
||||
QApplication a(argc,argv);
|
||||
MainWidget *w=new MainWidget();
|
||||
a.setMainWidget(w);
|
||||
w->setGeometry(QRect(QPoint(0,0),w->sizeHint()));
|
||||
w->move(250,250);
|
||||
w->show();
|
||||
return a.exec();
|
||||
}
|
80
utils/rddbconfig/rddbconfig.h
Normal file
80
utils/rddbconfig/rddbconfig.h
Normal file
@ -0,0 +1,80 @@
|
||||
// rddbconfig.h
|
||||
//
|
||||
// A Qt-based application to configure, backup, and restore
|
||||
// the Rivendell database.
|
||||
//
|
||||
// (C) Copyright 2009-2018 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public
|
||||
// License along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#ifndef RDDBCONFIG_H
|
||||
#define RDDBCONFIG_H
|
||||
|
||||
#include <qwidget.h>
|
||||
#include <q3listbox.h>
|
||||
#include <qlabel.h>
|
||||
#include <qmessagebox.h>
|
||||
|
||||
#include <rdtransportbutton.h>
|
||||
|
||||
#include <rd.h>
|
||||
#include <rdconfig.h>
|
||||
|
||||
#include "db.h"
|
||||
|
||||
#define RDDBCONFIG_USAGE "\n\n";
|
||||
|
||||
class MainWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainWidget(QWidget *parent=0);
|
||||
~MainWidget();
|
||||
QSize sizeHint() const;
|
||||
QSizePolicy sizePolicy() const;
|
||||
|
||||
private slots:
|
||||
int statusDaemons(QString service);
|
||||
void stopDaemons();
|
||||
void startDaemons();
|
||||
void createData();
|
||||
void backupData();
|
||||
void restoreData();
|
||||
void closeData();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
|
||||
private:
|
||||
void updateLabels();
|
||||
RDConfig *rd_config;
|
||||
bool db_manage_daemons;
|
||||
bool db_daemon_start_needed;
|
||||
QFont label_font;
|
||||
QFont day_font;
|
||||
QPushButton *db_create_button;
|
||||
QPushButton *db_backup_button;
|
||||
QPushButton *db_restore_button;
|
||||
QPushButton *db_close_button;
|
||||
QLabel *label_hostname;
|
||||
QLabel *label_username;
|
||||
QLabel *label_dbname;
|
||||
QLabel *label_schema;
|
||||
|
||||
Db *db;
|
||||
bool db_open;
|
||||
};
|
||||
|
||||
#endif // RDDBCONFIG_H
|
Loading…
x
Reference in New Issue
Block a user