Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warnings for old server versions #4523 #4531

Merged
merged 1 commit into from
Mar 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ static const char httpUserC[] = "http_user";
static const char caCertsKeyC[] = "CaCertificates";
static const char accountsC[] = "Accounts";
static const char versionC[] = "version";
static const char serverVersionC[] = "serverVersion";
}


Expand Down Expand Up @@ -165,6 +166,7 @@ void AccountManager::saveAccountState(AccountState* a)
void AccountManager::saveAccountHelper(Account* acc, QSettings& settings, bool saveCredentials)
{
settings.setValue(QLatin1String(urlC), acc->_url.toString());
settings.setValue(QLatin1String(serverVersionC), acc->_serverVersion);
if (acc->_credentials) {
if (saveCredentials) {
// Only persist the credentials if the parameter is set, on migration from 1.8.x
Expand Down Expand Up @@ -210,6 +212,7 @@ AccountPtr AccountManager::loadAccountHelper(QSettings& settings)
auto acc = createAccount();

acc->setUrl(settings.value(QLatin1String(urlC)).toUrl());
acc->_serverVersion = settings.value(QLatin1String(serverVersionC)).toString();

// We want to only restore settings for that auth type and the user value
acc->_settingsMap.insert(QLatin1String(userC), settings.value(userC));
Expand Down
6 changes: 5 additions & 1 deletion src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,11 @@ void AccountSettings::slotAccountStateChanged(int state)
}

if (state == AccountState::Connected) {
showConnectionLabel( tr("Connected to %1.").arg(serverWithUser) );
QStringList errors;
if (account->serverVersionUnsupported()) {
errors << tr("The server version %1 is old and unsupported! Proceed at your own risk.").arg(account->serverVersion());
}
showConnectionLabel( tr("Connected to %1.").arg(serverWithUser), errors );
} else if (state == AccountState::ServiceUnavailable) {
showConnectionLabel( tr("Server %1 is temporarily unavailable.").arg(server) );
} else if (state == AccountState::SignedOut) {
Expand Down
10 changes: 10 additions & 0 deletions src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,14 @@ void Application::slotAccountStateRemoved(AccountState *accountState)
if (_gui) {
disconnect(accountState, SIGNAL(stateChanged(int)),
_gui, SLOT(slotAccountStateChanged()));
disconnect(accountState->account().data(), SIGNAL(serverVersionChanged(Account*,QString,QString)),
_gui, SLOT(slotTrayMessageIfServerUnsupported(Account*)));
}
if (_folderManager) {
disconnect(accountState, SIGNAL(stateChanged(int)),
_folderManager.data(), SLOT(slotAccountStateChanged()));
disconnect(accountState->account().data(), SIGNAL(serverVersionChanged(Account*,QString,QString)),
_folderManager.data(), SLOT(slotServerVersionChanged(Account*)));
}

// if there is no more account, show the wizard.
Expand All @@ -237,8 +241,14 @@ void Application::slotAccountStateAdded(AccountState *accountState)
{
connect(accountState, SIGNAL(stateChanged(int)),
_gui, SLOT(slotAccountStateChanged()));
connect(accountState->account().data(), SIGNAL(serverVersionChanged(Account*,QString,QString)),
_gui, SLOT(slotTrayMessageIfServerUnsupported(Account*)));
connect(accountState, SIGNAL(stateChanged(int)),
_folderManager.data(), SLOT(slotAccountStateChanged()));
connect(accountState->account().data(), SIGNAL(serverVersionChanged(Account*,QString,QString)),
_folderManager.data(), SLOT(slotServerVersionChanged(Account*)));

_gui->slotTrayMessageIfServerUnsupported(accountState->account().data());
}

void Application::slotCleanup()
Expand Down
15 changes: 15 additions & 0 deletions src/gui/folderman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,21 @@ void FolderMan::slotForwardFolderSyncStateChange()
}
}

void FolderMan::slotServerVersionChanged(Account *account)
{
// Pause folders if the server version is unsupported
if (account->serverVersionUnsupported()) {
qDebug() << "The server version is unsupported:" << account->serverVersion()
<< "pausing all folders on the account";

foreach (auto& f, _folderMap) {
if (f->accountState()->account().data() == account) {
f->setSyncPaused(true);
}
}
}
}

void FolderMan::slotFolderSyncStarted( )
{
qDebug() << ">===================================== sync started for " << _currentSyncFolder->remoteUrl().toString();
Expand Down
2 changes: 2 additions & 0 deletions src/gui/folderman.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ private slots:
// FolderMan::folderSyncStateChange(Folder*) signal.
void slotForwardFolderSyncStateChange();

void slotServerVersionChanged(Account* account);

private:
/** Adds a new folder, does not add it to the account settings and
* does not set an account on the new folder.
Expand Down
12 changes: 12 additions & 0 deletions src/gui/owncloudgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,18 @@ void ownCloudGui::slotAccountStateChanged()
slotComputeOverallSyncStatus();
}

void ownCloudGui::slotTrayMessageIfServerUnsupported(Account* account)
{
if (account->serverVersionUnsupported()) {
slotShowTrayMessage(
tr("Unsupported Server Version"),
tr("The server on account %1 runs an old and unsupported version %2. "
"Using this client with unsupported server versions is untested and "
"potentially dangerous. Proceed at your own risk.")
.arg(account->displayName(), account->serverVersion()));
}
}

void ownCloudGui::slotComputeOverallSyncStatus()
{
bool allSignedOut = true;
Expand Down
1 change: 1 addition & 0 deletions src/gui/owncloudgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public slots:
void slotHelp();
void slotOpenPath(const QString& path);
void slotAccountStateChanged();
void slotTrayMessageIfServerUnsupported(Account *account);
void slotShowShareDialog(const QString &sharePath, const QString &localPath, bool resharingAllowed);
void slotRemoveDestroyedShareDialogs();

Expand Down
17 changes: 14 additions & 3 deletions src/libsync/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,23 +472,34 @@ void Account::setCapabilities(const QVariantMap &caps)
_capabilities = Capabilities(caps);
}

QString Account::serverVersion()
QString Account::serverVersion() const
{
return _serverVersion;
}

int Account::serverVersionInt()
int Account::serverVersionInt() const
{
// FIXME: Use Qt 5.5 QVersionNumber
auto components = serverVersion().split('.');
return (components.value(0).toInt() << 16)
+ (components.value(1).toInt() << 8)
+ components.value(2).toInt();
+ components.value(2).toInt();
}

bool Account::serverVersionUnsupported() const
{
return serverVersionInt() < 0x070000;
}

void Account::setServerVersion(const QString& version)
{
if (version == _serverVersion) {
return;
}

auto oldServerVersion = _serverVersion;
_serverVersion = version;
emit serverVersionChanged(this, oldServerVersion, version);
}

bool Account::rootEtagChangesNotOnlySubFolderEtags()
Expand Down
18 changes: 16 additions & 2 deletions src/libsync/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,20 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject {
void setCapabilities(const QVariantMap &caps);
const Capabilities &capabilities() const;
void setServerVersion(const QString &version);
QString serverVersion();
int serverVersionInt();
QString serverVersion() const;
int serverVersionInt() const;

/** Whether the server is too old.
*
* Not supporting server versions is a gradual process. There's a hard
* compatibility limit (see ConnectionValidator) that forbids connecting
* to extremely old servers. And there's a weak "untested, not
* recommended, potentially dangerous" limit, that users might want
* to go beyond.
*
* This function returns true if the server is beyond the weak limit.
*/
bool serverVersionUnsupported() const;

// Fixed from 8.1 https://github.com/owncloud/client/issues/3730
bool rootEtagChangesNotOnlySubFolderEtags();
Expand All @@ -181,6 +193,8 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject {
// e.g. when the approved SSL certificates changed
void wantsAccountSaved(Account* acc);

void serverVersionChanged(Account* account, const QString& newVersion, const QString& oldVersion);

protected Q_SLOTS:
void slotHandleSslErrors(QNetworkReply*,QList<QSslError>);
void slotCredentialsFetched();
Expand Down
4 changes: 4 additions & 0 deletions src/libsync/connectionvalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,17 @@ void ConnectionValidator::slotStatusFound(const QUrl&url, const QVariantMap &inf
QString version = CheckServerJob::version(info);
_account->setServerVersion(version);

// We cannot deal with servers < 5.0.0
if (version.contains('.') && version.split('.')[0].toInt() < 5) {
_errors.append( tr("The configured server for this client is too old") );
_errors.append( tr("Please update to the latest server and restart the client.") );
reportResult( ServerVersionMismatch );
return;
}

// We attempt to work with servers >= 5.0.0 but warn users.
// Check usages of Account::serverVersionUnsupported() for details.

// now check the authentication
if (_account->credentials()->ready())
QTimer::singleShot( 0, this, SLOT( checkAuthentication() ));
Expand Down