2022-10-06 Fred Gleason <fredg@paravelsystems.com>

* Changed the type of the 'REPLICATORS.URL_PASSWORD` field in the
	database to 'text'.
	* Applied Base64 encoding to the 'REPLICATORS.URL_PASSWORD' field in
	the database.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason 2022-10-06 16:48:01 -04:00
parent 285a095ada
commit ddd62c10ed
9 changed files with 97 additions and 10 deletions

View File

@ -23465,3 +23465,8 @@
* Applied Base64 encoding to the 'USERS.PASSWORD' field in the
database.
* Incremented the database version to 359.
2022-10-06 Fred Gleason <fredg@paravelsystems.com>
* Changed the type of the 'REPLICATORS.URL_PASSWORD` field in the
database to 'text'.
* Applied Base64 encoding to the 'REPLICATORS.URL_PASSWORD' field in
the database.

View File

@ -16,6 +16,6 @@ BITRATE int(10) unsigned
QUALITY int(10) unsigned
URL varchar(255)
URL_USERNAME varchar(64)
URL_PASSWORD varchar(64)
URL_PASSWORD text Base64 encoded
ENABLE_METADATA enum('N','Y')
NORMALIZATION_LEVEL int(11) signed

View File

@ -24,7 +24,7 @@
/*
* Current Database Version
*/
#define RD_VERSION_DATABASE 359
#define RD_VERSION_DATABASE 360
#endif // DBVERSION_H

View File

@ -157,13 +157,13 @@ void RDReplicator::setUrlUsername(const QString &str) const
QString RDReplicator::urlPassword() const
{
return GetValue("URL_PASSWORD").toString();
return QByteArray::fromBase64(GetValue("URL_PASSWORD").toString().toUtf8());
}
void RDReplicator::setUrlPassword(const QString &str) const
{
SetRow("URL_PASSWORD",str);
SetRow("URL_PASSWORD",str.toUtf8().toBase64());
}
@ -227,7 +227,7 @@ QVariant RDReplicator::GetValue(const QString &field) const
}
void RDReplicator::SetRow(const QString &param,QString value) const
void RDReplicator::SetRow(const QString &param,const QString &value) const
{
QString sql;
@ -238,6 +238,24 @@ void RDReplicator::SetRow(const QString &param,QString value) const
}
void RDReplicator::SetRow(const QString &param,const QByteArray &value) const
{
QString sql;
if(value.size()==0) {
sql=QString("update `REPLICATORS` set `")+
param+"`=NULL where "+
"`NAME`='"+RDEscapeString(replicator_name)+"'";
}
else {
sql=QString("update `REPLICATORS` set `")+
param+"`='"+RDEscapeString(value)+"' where "+
"`NAME`='"+RDEscapeString(replicator_name)+"'";
}
RDSqlQuery::apply(sql);
}
void RDReplicator::SetRow(const QString &param,int value) const
{
QString sql;

View File

@ -2,7 +2,7 @@
//
// Abstract a Rivendell replicator configuration
//
// (C) Copyright 2010,2016 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2010-2022 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
@ -21,7 +21,7 @@
#ifndef RDREPLICATOR_H
#define RDREPLICATOR_H
#include <qvariant.h>
#include <QVariant>
#include <rdsettings.h>
@ -62,7 +62,8 @@ class RDReplicator
private:
QVariant GetValue(const QString &field) const;
void SetRow(const QString &param,QString value) const;
void SetRow(const QString &param,const QString &value) const;
void SetRow(const QString &param,const QByteArray &value) const;
void SetRow(const QString &param,int value) const;
void SetRow(const QString &param,unsigned value) const;
QString replicator_name;

View File

@ -227,7 +227,8 @@ void MainObject::LoadReplicators()
config->setQuality(q->value(6).toUInt());
config->setUrl(q->value(7).toString());
config->setUrlUsername(q->value(8).toString());
config->setUrlPassword(q->value(9).toString());
config->
setUrlPassword(QByteArray::fromBase64(q->value(9).toString().toUtf8()));
config->setEnableMetadata(RDBool(q->value(10).toString()));
config->setNormalizeLevel(q->value(11).toInt());
switch(config->type()) {

View File

@ -41,6 +41,36 @@ bool MainObject::RevertSchema(int cur_schema,int set_schema,QString *err_msg)
// NEW SCHEMA REVERSIONS GO HERE...
//
// Revert 360
//
if((cur_schema==360)&&(set_schema<cur_schema)) {
sql=QString("select ")+
"`NAME`,"+ // 00
"`URL_PASSWORD` "+ // 01
"from `REPLICATORS`";
q=new RDSqlQuery(sql);
while(q->next()) {
if(!q->value(1).isNull()) {
sql=QString("update `REPLICATORS` set ")+
"`URL_PASSWORD`='"+
RDEscapeString(QByteArray::fromBase64(q->value(1).toString().toUtf8()))+"' "+
"where `NAME`='"+RDEscapeString(q->value(0).toString())+"'";
if(!RDSqlQuery::apply(sql,err_msg)) {
return false;
}
}
}
delete q;
sql=QString("alter table `REPLICATORS` ")+
"modify column `URL_PASSWORD` varchar(64)";
if(!RDSqlQuery::apply(sql,err_msg)) {
return false;
}
WriteSchemaVersion(--cur_schema);
}
//
// Revert 359
//
@ -70,6 +100,7 @@ bool MainObject::RevertSchema(int cur_schema,int set_schema,QString *err_msg)
if(!RDSqlQuery::apply(sql,err_msg)) {
return false;
}
WriteSchemaVersion(--cur_schema);
}

View File

@ -160,7 +160,7 @@ void MainObject::InitializeSchemaMap() {
global_version_map["3.4"]=317;
global_version_map["3.5"]=346;
global_version_map["3.6"]=347;
global_version_map["4.0"]=359;
global_version_map["4.0"]=360;
}

View File

@ -11083,6 +11083,37 @@ bool MainObject::UpdateSchema(int cur_schema,int set_schema,QString *err_msg)
WriteSchemaVersion(++cur_schema);
}
if((cur_schema<360)&&(set_schema>cur_schema)) {
sql=QString("alter table `REPLICATORS` ")+
"modify column `URL_PASSWORD` text";
if(!RDSqlQuery::apply(sql,err_msg)) {
return false;
}
sql=QString("select ")+
"`NAME`,"+ // 00
"`URL_PASSWORD` "+ // 01
"from `REPLICATORS`";
q=new RDSqlQuery(sql);
while(q->next()) {
if(q->value(1).toString().isEmpty()) {
sql=QString("update `REPLICATORS` set ")+
"`URL_PASSWORD`=null ";
}
else {
sql=QString("update `REPLICATORS` set ")+
"`URL_PASSWORD`='"+
RDEscapeString(q->value(1).toString().toUtf8().toBase64())+"' ";
}
sql+="where `NAME`='"+RDEscapeString(q->value(0).toString())+"'";
if(!RDSqlQuery::apply(sql,err_msg)) {
return false;
}
}
delete q;
WriteSchemaVersion(++cur_schema);
}
// NEW SCHEMA UPDATES GO HERE...