Fix determining whether GUI address is local

The port must be stripped from the address before passing it to
`isLocal()` which only expects a hostname.
This commit is contained in:
Martchus 2022-09-25 22:40:25 +02:00
parent 3320f712db
commit 4f58b2cb7e
3 changed files with 11 additions and 1 deletions

View File

@ -87,7 +87,7 @@ bool SyncthingConfig::restore(const QString &configFilePath)
QString SyncthingConfig::syncthingUrl() const QString SyncthingConfig::syncthingUrl() const
{ {
return (guiEnforcesSecureConnection || !isLocal(guiAddress) ? QStringLiteral("https://") : QStringLiteral("http://")) + guiAddress; return (guiEnforcesSecureConnection || !isLocal(stripPort(guiAddress)) ? QStringLiteral("https://") : QStringLiteral("http://")) + guiAddress;
} }
} // namespace Data } // namespace Data

View File

@ -104,6 +104,15 @@ QString rescanIntervalString(int rescanInterval, bool fileSystemWatcherEnabled)
: QCoreApplication::translate("Data::Utils", ", file system watcher disabled")); : QCoreApplication::translate("Data::Utils", ", file system watcher disabled"));
} }
/*!
* \brief Strips the port from the specified \a address.
*/
QString stripPort(const QString &address)
{
const auto portStart = address.lastIndexOf(QChar(':'));
return portStart < 0 ? address : address.mid(0, portStart);
}
/*! /*!
* \brief Returns whether the specified \a hostName is the local machine. * \brief Returns whether the specified \a hostName is the local machine.
*/ */

View File

@ -33,6 +33,7 @@ LIB_SYNCTHING_CONNECTOR_EXPORT QString directoryStatusString(const Data::Syncthi
LIB_SYNCTHING_CONNECTOR_EXPORT QString syncCompleteString( LIB_SYNCTHING_CONNECTOR_EXPORT QString syncCompleteString(
const std::vector<const SyncthingDir *> &completedDirs, const SyncthingDev *remoteDevice = nullptr); const std::vector<const SyncthingDir *> &completedDirs, const SyncthingDev *remoteDevice = nullptr);
LIB_SYNCTHING_CONNECTOR_EXPORT QString rescanIntervalString(int rescanInterval, bool fileSystemWatcherEnabled); LIB_SYNCTHING_CONNECTOR_EXPORT QString rescanIntervalString(int rescanInterval, bool fileSystemWatcherEnabled);
LIB_SYNCTHING_CONNECTOR_EXPORT QString stripPort(const QString &address);
LIB_SYNCTHING_CONNECTOR_EXPORT bool isLocal(const QString &hostName); LIB_SYNCTHING_CONNECTOR_EXPORT bool isLocal(const QString &hostName);
LIB_SYNCTHING_CONNECTOR_EXPORT bool isLocal(const QString &hostName, const QHostAddress &hostAddress); LIB_SYNCTHING_CONNECTOR_EXPORT bool isLocal(const QString &hostName, const QHostAddress &hostAddress);
LIB_SYNCTHING_CONNECTOR_EXPORT bool setDirectoriesPaused(QJsonObject &syncthingConfig, const QStringList &dirIds, bool paused); LIB_SYNCTHING_CONNECTOR_EXPORT bool setDirectoriesPaused(QJsonObject &syncthingConfig, const QStringList &dirIds, bool paused);