mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-19 10:20:17 -06:00
dbhub: Improve UI for pushing databases
This improves the user experience for pushing database files. Before this you had to type in the entire URL for pushing, e.g.: https://db4s-beta.dbhub.io:5550/username/databasename With this the host name as well as the user name is taken from the currently active client certificate. So all you have to type in now is the database name. And for this we make a sensible automatic suggestion based on the name of the local file you're trying to push. Note that while this makes pushing databases a lot easier, it still doesn't implement proper version control or any extra code for handling conflicts etc.
This commit is contained in:
@@ -235,6 +235,23 @@ const QList<QSslCertificate>& RemoteDatabase::caCertificates() const
|
||||
return certs;
|
||||
}
|
||||
|
||||
QString RemoteDatabase::getInfoFromClientCert(const QString& cert, CertInfo info) const
|
||||
{
|
||||
// Get the common name of the certificate and split it into user name and server address
|
||||
QString cn = m_clientCertFiles[cert].subjectInfo(QSslCertificate::CommonName).at(0);
|
||||
QStringList cn_parts = cn.split("@");
|
||||
if(cn_parts.size() < 2)
|
||||
return QString();
|
||||
|
||||
// Return requested part of the CN
|
||||
if(info == CertInfoUser)
|
||||
return cn_parts.first();
|
||||
else if(info == CertInfoServer)
|
||||
return cn_parts.last();
|
||||
else
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool RemoteDatabase::prepareSsl(QNetworkRequest* request, const QString& clientCert)
|
||||
{
|
||||
// Check if client cert exists
|
||||
|
||||
@@ -22,8 +22,15 @@ public:
|
||||
|
||||
void reloadSettings();
|
||||
|
||||
enum CertInfo
|
||||
{
|
||||
CertInfoUser,
|
||||
CertInfoServer,
|
||||
};
|
||||
|
||||
const QList<QSslCertificate>& caCertificates() const;
|
||||
const QMap<QString, QSslCertificate>& clientCertificates() const { return m_clientCertFiles; }
|
||||
QString getInfoFromClientCert(const QString& cert, CertInfo info) const;
|
||||
|
||||
enum RequestType
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <QSslCertificate>
|
||||
#include <QInputDialog>
|
||||
#include <QFileInfo>
|
||||
|
||||
#include "RemoteDock.h"
|
||||
#include "ui_RemoteDock.h"
|
||||
@@ -55,11 +56,8 @@ void RemoteDock::setNewIdentity()
|
||||
return;
|
||||
|
||||
// Open root directory. Get host name from client cert
|
||||
QString cn = remoteDatabase.clientCertificates()[cert].subjectInfo(QSslCertificate::CommonName).at(0);
|
||||
QStringList cn_parts = cn.split("@");
|
||||
if(cn_parts.size() < 2)
|
||||
return;
|
||||
remoteModel->setNewRootDir(QString("https://%1:5550/").arg(cn_parts.last()), cert);
|
||||
QString host = remoteDatabase.getInfoFromClientCert(cert, RemoteDatabase::CertInfoServer);
|
||||
remoteModel->setNewRootDir(QString("https://%1:5550/").arg(host), cert);
|
||||
|
||||
// Enable buttons if necessary
|
||||
enableButtons();
|
||||
@@ -88,7 +86,23 @@ void RemoteDock::enableButtons()
|
||||
|
||||
void RemoteDock::pushDatabase()
|
||||
{
|
||||
QString url = QInputDialog::getText(this, qApp->applicationName(), tr("Please enter the URL of the database file to save."));
|
||||
if(!url.isEmpty())
|
||||
remoteDatabase.push(mainWindow->getDb().currentFile(), url, remoteModel->currentClientCertificate());
|
||||
// Ask for file name to save under. The default suggestion is the local file name. If it is a remote file (like when it initially was fetched using DB4S),
|
||||
// the extra bit of information at the end of the name gets removed first.
|
||||
QString name = QFileInfo(mainWindow->getDb().currentFile()).fileName();
|
||||
name = name.remove(QRegExp("_[0-9]+.remotedb$"));
|
||||
name = QInputDialog::getText(this, qApp->applicationName(),
|
||||
tr("Please enter the database name to push to."),
|
||||
QLineEdit::Normal,
|
||||
name);
|
||||
if(name.isEmpty())
|
||||
return;
|
||||
|
||||
// Build push URL
|
||||
QString url = QString("https://%1:5550/").arg(remoteDatabase.getInfoFromClientCert(remoteModel->currentClientCertificate(), RemoteDatabase::CertInfoServer));
|
||||
url.append(remoteDatabase.getInfoFromClientCert(remoteModel->currentClientCertificate(), RemoteDatabase::CertInfoUser));
|
||||
url.append("/");
|
||||
url.append(name);
|
||||
|
||||
// Push database
|
||||
remoteDatabase.push(mainWindow->getDb().currentFile(), url, remoteModel->currentClientCertificate());
|
||||
}
|
||||
|
||||
@@ -110,12 +110,8 @@ RemoteModel::~RemoteModel()
|
||||
|
||||
void RemoteModel::setNewRootDir(const QString& url, const QString& cert)
|
||||
{
|
||||
// Extract user name
|
||||
QString cn = remoteDatabase.clientCertificates()[cert].subjectInfo(QSslCertificate::CommonName).at(0);
|
||||
QStringList cn_parts = cn.split("@");
|
||||
if(cn_parts.size() < 2)
|
||||
return;
|
||||
currentUserName = cn_parts.first();
|
||||
// Get user name from client cert
|
||||
currentUserName = remoteDatabase.getInfoFromClientCert(cert, RemoteDatabase::CertInfoUser);
|
||||
|
||||
// Save settings
|
||||
currentRootDirectory = url;
|
||||
|
||||
Reference in New Issue
Block a user