From 7ac32a19b563bb17abe7fe9c9fbc245682e34711 Mon Sep 17 00:00:00 2001 From: Daniel Molkentin Date: Wed, 17 Dec 2014 19:14:42 +0100 Subject: [PATCH] Do not show the HTTP-reconnect popup when its not warranted Fixes usability issues in the workaround of #2607 --- src/gui/owncloudsetupwizard.cpp | 44 ++++++++++++++++++++-------- src/gui/owncloudsetupwizard.h | 3 +- src/gui/wizard/owncloudsetuppage.cpp | 6 ++-- src/gui/wizard/owncloudsetuppage.h | 2 +- src/gui/wizard/owncloudwizard.cpp | 4 +-- src/gui/wizard/owncloudwizard.h | 2 +- 6 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/gui/owncloudsetupwizard.cpp b/src/gui/owncloudsetupwizard.cpp index 689d36ebe..7672996d4 100644 --- a/src/gui/owncloudsetupwizard.cpp +++ b/src/gui/owncloudsetupwizard.cpp @@ -186,15 +186,14 @@ void OwncloudSetupWizard::slotNoOwnCloudFoundAuth(QNetworkReply *reply) _ocWizard->displayError(tr("Failed to connect to %1 at %2:
%3") .arg(Theme::instance()->appNameGUI(), reply->url().toString(), - reply->errorString())); + reply->errorString()), checkDowngradeAdvised(reply)); } void OwncloudSetupWizard::slotNoOwnCloudFoundAuthTimeout(const QUrl&url) { - _ocWizard->displayError(tr("Failed to connect to %1 at %2:
%3") + _ocWizard->displayError(tr("Timeout while trying to connect to %1 at %2.") .arg(Theme::instance()->appNameGUI(), - url.toString(), - "Timeout")); + url.toString()), false); } void OwncloudSetupWizard::slotConnectToOCUrl( const QString& url ) @@ -219,6 +218,28 @@ void OwncloudSetupWizard::testOwnCloudConnect() job->start(); } +bool OwncloudSetupWizard::checkDowngradeAdvised(QNetworkReply* reply) +{ + bool downgradeAdvised = (reply->url().scheme() == QLatin1String("https")); + + switch (reply->error()) { + case QNetworkReply::NoError: + case QNetworkReply::ContentNotFoundError: + case QNetworkReply::ConnectionRefusedError: + case QNetworkReply::HostNotFoundError: + case QNetworkReply::TimeoutError: + downgradeAdvised = false; + // fall through + default: + _ocWizard->show(); + _ocWizard->back(); + // Adhere to HSTS, even though we do not parse it properly + downgradeAdvised &= !reply->hasRawHeader("Strict-Transport-Security"); + break; + } + return downgradeAdvised; +} + void OwncloudSetupWizard::slotConnectionCheck(QNetworkReply* reply) { switch (reply->error()) { @@ -226,11 +247,8 @@ void OwncloudSetupWizard::slotConnectionCheck(QNetworkReply* reply) case QNetworkReply::ContentNotFoundError: _ocWizard->successfulStep(); break; - default: - _ocWizard->show(); - _ocWizard->back(); - _ocWizard->displayError(reply->errorString()); + _ocWizard->displayError(reply->errorString(), checkDowngradeAdvised(reply)); break; } } @@ -254,7 +272,7 @@ void OwncloudSetupWizard::slotCreateLocalAndRemoteFolders(const QString& localFo } else { res += tr("failed."); qDebug() << "Failed to create " << fi.path(); - _ocWizard->displayError(tr("Could not create local folder %1").arg(localFolder)); + _ocWizard->displayError(tr("Could not create local folder %1").arg(localFolder), false); nextStep = false; } _ocWizard->appendToConfigurationLog( res ); @@ -290,7 +308,7 @@ void OwncloudSetupWizard::slotAuthCheckReply(QNetworkReply *reply) } if( !ok ) { - _ocWizard->displayError(error); + _ocWizard->displayError(error, false); } finalizeSetup( ok ); @@ -318,20 +336,20 @@ void OwncloudSetupWizard::slotCreateRemoteFolderFinished( QNetworkReply::Network } else if( error == 202 ) { _ocWizard->appendToConfigurationLog( tr("The remote folder %1 already exists. Connecting it for syncing.").arg(_remoteFolder)); } else if( error > 202 && error < 300 ) { - _ocWizard->displayError( tr("The folder creation resulted in HTTP error code %1").arg((int)error )); + _ocWizard->displayError( tr("The folder creation resulted in HTTP error code %1").arg((int)error ), false); _ocWizard->appendToConfigurationLog( tr("The folder creation resulted in HTTP error code %1").arg((int)error) ); } else if( error == QNetworkReply::OperationCanceledError ) { _ocWizard->displayError( tr("The remote folder creation failed because the provided credentials " "are wrong!" - "
Please go back and check your credentials.

")); + "
Please go back and check your credentials.

"), false); _ocWizard->appendToConfigurationLog( tr("

Remote folder creation failed probably because the provided credentials are wrong." "
Please go back and check your credentials.

")); _remoteFolder.clear(); success = false; } else { _ocWizard->appendToConfigurationLog( tr("Remote folder %1 creation failed with error %2.").arg(_remoteFolder).arg(error)); - _ocWizard->displayError( tr("Remote folder %1 creation failed with error %2.").arg(_remoteFolder).arg(error) ); + _ocWizard->displayError( tr("Remote folder %1 creation failed with error %2.").arg(_remoteFolder).arg(error), false ); _remoteFolder.clear(); success = false; } diff --git a/src/gui/owncloudsetupwizard.h b/src/gui/owncloudsetupwizard.h index 2c42c8f51..67cd08a26 100644 --- a/src/gui/owncloudsetupwizard.h +++ b/src/gui/owncloudsetupwizard.h @@ -62,7 +62,6 @@ class OwncloudSetupWizard : public QObject public: /** Run the wizard */ static void runWizard(QObject *obj, const char* amember, QWidget *parent = 0 ); - signals: // overall dialog close signal. void ownCloudWizardDone( int ); @@ -85,13 +84,13 @@ private slots: private: explicit OwncloudSetupWizard(QObject *parent = 0 ); ~OwncloudSetupWizard(); - void startWizard(); void testOwnCloudConnect(); void createRemoteFolder(); void finalizeSetup( bool ); bool ensureStartFromScratch(const QString &localFolder); void replaceDefaultAccountWith(Account *newAccount); + bool checkDowngradeAdvised(QNetworkReply* reply); Account* _account; OwncloudWizard* _ocWizard; diff --git a/src/gui/wizard/owncloudsetuppage.cpp b/src/gui/wizard/owncloudsetuppage.cpp index 0e2526615..e749e8660 100644 --- a/src/gui/wizard/owncloudsetuppage.cpp +++ b/src/gui/wizard/owncloudsetuppage.cpp @@ -201,7 +201,7 @@ QString OwncloudSetupPage::url() const bool OwncloudSetupPage::validatePage() { if( ! _authTypeKnown) { - setErrorString(QString::null); + setErrorString(QString::null, false); _checking = true; startSpinner (); emit completeChanged(); @@ -224,12 +224,12 @@ void OwncloudSetupPage::setAuthType (WizardCommon::AuthType type) stopSpinner(); } -void OwncloudSetupPage::setErrorString( const QString& err ) +void OwncloudSetupPage::setErrorString( const QString& err, bool retryHTTPonly ) { if( err.isEmpty()) { _ui.errorLabel->setVisible(false); } else { - if (_ui.leUrl->text().startsWith("https://")) { + if (retryHTTPonly) { QString msg = tr("

Could not connect securely:

%1

Do you want to connect unencrypted instead (not recommended)?

").arg(err); QString title = tr("Connection failed"); if (QMessageBox::question(this, title, msg, QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) { diff --git a/src/gui/wizard/owncloudsetuppage.h b/src/gui/wizard/owncloudsetuppage.h index 2974c0d88..5385b2d09 100644 --- a/src/gui/wizard/owncloudsetuppage.h +++ b/src/gui/wizard/owncloudsetuppage.h @@ -46,7 +46,7 @@ public: void setAuthType(WizardCommon::AuthType type); public slots: - void setErrorString( const QString& ); + void setErrorString( const QString&, bool retryHTTPonly ); void setConfigExists( bool ); void startSpinner(); void stopSpinner(); diff --git a/src/gui/wizard/owncloudwizard.cpp b/src/gui/wizard/owncloudwizard.cpp index a02f802a8..24f0de242 100644 --- a/src/gui/wizard/owncloudwizard.cpp +++ b/src/gui/wizard/owncloudwizard.cpp @@ -182,11 +182,11 @@ void OwncloudWizard::slotCurrentPageChanged( int id ) setOption(QWizard::HaveCustomButton1, id == WizardCommon::Page_AdvancedSetup); } -void OwncloudWizard::displayError( const QString& msg ) +void OwncloudWizard::displayError( const QString& msg, bool retryHTTPonly ) { switch (currentId()) { case WizardCommon::Page_ServerSetup: - _setupPage->setErrorString( msg ); + _setupPage->setErrorString( msg, retryHTTPonly ); break; case WizardCommon::Page_HttpCreds: diff --git a/src/gui/wizard/owncloudwizard.h b/src/gui/wizard/owncloudwizard.h index a2f45ad6e..eb952e7e7 100644 --- a/src/gui/wizard/owncloudwizard.h +++ b/src/gui/wizard/owncloudwizard.h @@ -54,7 +54,7 @@ public: void enableFinishOnResultWidget(bool enable); - void displayError( const QString& ); + void displayError( const QString&, bool retryHTTPonly); void setMultipleFoldersExist( bool ); void setConfigExists( bool ); bool configExists();