From b396b1092d1446234fa8618e32a88269100d0636 Mon Sep 17 00:00:00 2001 From: Andrew Nelless Date: Thu, 7 Jun 2018 16:22:49 +0100 Subject: [PATCH] #6301 Disable activation for Enterprise builds --- CMakeLists.txt | 1 + cmake/Version.cmake | 5 +- src/gui/CMakeLists.txt | 12 ++- src/gui/src/AppConfig.cpp | 14 ++- src/gui/src/AppConfig.h | 5 +- src/gui/src/MainWindow.cpp | 57 +++++++++-- src/gui/src/MainWindow.h | 15 ++- src/gui/src/SettingsDialog.cpp | 8 +- src/gui/src/main.cpp | 172 +++++++++++++++++---------------- 9 files changed, 186 insertions(+), 103 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 61cb4648..5570ca08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ project (synergy C CXX) option (SYNERGY_BUILD_LEGACY_GUI "Build the legacy GUI" ON) option (SYNERGY_BUILD_LEGACY_SERVICE "Build the legacy service (synergyd)" ON) option (SYNERGY_BUILD_LEGACY_INSTALLER "Build the legacy installer" ON) +option (SYNERGY_ENTERPRISE "Build Enterprise" OFF) set (CMAKE_CXX_STANDARD 14) set (CMAKE_CXX_EXTENSIONS OFF) diff --git a/cmake/Version.cmake b/cmake/Version.cmake index 266744e6..74cefd1a 100644 --- a/cmake/Version.cmake +++ b/cmake/Version.cmake @@ -15,7 +15,7 @@ if (NOT DEFINED SYNERGY_VERSION_MINOR) if (DEFINED ENV{SYNERGY_VERSION_MINOR}) set (SYNERGY_VERSION_MINOR $ENV{SYNERGY_VERSION_MINOR}) else() - set (SYNERGY_VERSION_MINOR 9) + set (SYNERGY_VERSION_MINOR 10) endif() endif() @@ -88,3 +88,6 @@ if (SYNERGY_DEVELOPER_MODE) add_definitions (-DSYNERGY_DEVELOPER_MODE=1) endif() +if (SYNERGY_ENTERPRISE) + add_definitions (-DSYNERGY_ENTERPRISE=1) +endif() diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 54cafabc..53dc95b7 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -8,6 +8,12 @@ set (CMAKE_INCLUDE_CURRENT_DIR ON) file (GLOB LEGACY_GUI_SOURCE_FILES src/*.cpp src/*.h) file (GLOB LEGACY_GUI_UI_FILES src/*.ui) +file (GLOB LEGACY_ACTIVATION_FILES src/*Activation* src/*License*) + +if (SYNERGY_ENTERPRISE) + list (REMOVE_ITEM LEGACY_GUI_SOURCE_FILES ${LEGACY_ACTIVATION_FILES}) + list (REMOVE_ITEM LEGACY_GUI_UI_FILES ${LEGACY_ACTIVATION_FILES}) +endif () if (WIN32) set (LEGACY_GUI_RC_FILES res/win/Synergy.rc) @@ -26,15 +32,15 @@ target_link_libraries (synergy shared) if (WIN32) include_directories ($ENV{BONJOUR_SDK_HOME}/Include) if (CMAKE_SIZEOF_VOID_P EQUAL 8) - find_library (DNSSD_LIB dnssd.lib + find_library (DNSSD_LIB dnssd.lib HINTS ENV BONJOUR_SDK_HOME PATH_SUFFIXES "Lib/x64") else() - find_library (DNSSD_LIB dnssd.lib + find_library (DNSSD_LIB dnssd.lib HINTS ENV BONJOUR_SDK_HOME PATH_SUFFIXES "Lib/Win32") endif() - + elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") target_link_libraries (synergy dns_sd) endif() diff --git a/src/gui/src/AppConfig.cpp b/src/gui/src/AppConfig.cpp index 0e15aa58..ba718df9 100644 --- a/src/gui/src/AppConfig.cpp +++ b/src/gui/src/AppConfig.cpp @@ -86,8 +86,8 @@ const QString &AppConfig::logFilename() const { return m_LogFilename; } QString AppConfig::synergyLogDir() const { - // by default log to home dir - return QDir::home().absolutePath() + "/"; + // by default log to home dir + return QDir::home().absolutePath() + "/"; } QString AppConfig::synergyProgramDir() const @@ -188,6 +188,7 @@ void AppConfig::saveSettings() settings().sync(); } +#ifndef SYNERGY_ENTERPRISE bool AppConfig::activationHasRun() const { return m_ActivationHasRun; @@ -198,6 +199,7 @@ AppConfig& AppConfig::activationHasRun(bool value) m_ActivationHasRun = value; return *this; } +#endif QString AppConfig::lastVersion() const { @@ -242,6 +244,7 @@ void AppConfig::setAutoConfigPrompted(bool prompted) m_AutoConfigPrompted = prompted; } +#ifndef SYNERGY_ENTERPRISE void AppConfig::setEdition(Edition e) { m_Edition = e; } @@ -264,6 +267,7 @@ QString AppConfig::serialKey() { return m_Serialkey; } int AppConfig::lastExpiringWarningTime() const { return m_LastExpiringWarningTime; } void AppConfig::setLastExpiringWarningTime(int t) { m_LastExpiringWarningTime = t; } +#endif QString AppConfig::synergysName() const { return m_SynergysName; } @@ -280,7 +284,11 @@ void AppConfig::setCryptoEnabled(bool e) { } bool AppConfig::getCryptoEnabled() const { - return (edition() == kPro) && m_CryptoEnabled; + return +#ifndef SYNERGY_ENTERPRISE + (edition() == kPro) && +#endif + m_CryptoEnabled; } void AppConfig::setAutoHide(bool b) { m_AutoHide = b; } diff --git a/src/gui/src/AppConfig.h b/src/gui/src/AppConfig.h index fb4b37ed..39330d77 100644 --- a/src/gui/src/AppConfig.h +++ b/src/gui/src/AppConfig.h @@ -79,6 +79,7 @@ class AppConfig: public QObject void setAutoConfig(bool autoConfig); bool autoConfigPrompted(); void setAutoConfigPrompted(bool prompted); +#ifndef SYNERGY_ENTERPRISE void setEdition(Edition); Edition edition() const; QString setSerialKey(QString serial); @@ -86,6 +87,7 @@ class AppConfig: public QObject QString serialKey(); int lastExpiringWarningTime() const; void setLastExpiringWarningTime(int t); +#endif QString synergysName() const; QString synergycName() const; @@ -101,9 +103,10 @@ class AppConfig: public QObject void setAutoHide(bool b); bool getAutoHide(); - +#ifndef SYNERGY_ENTERPRISE bool activationHasRun() const; AppConfig& activationHasRun(bool value); +#endif QString lastVersion() const; diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index a55502dd..688f8c68 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -76,11 +76,17 @@ static const char* synergyIconFiles[] = ":/res/icons/16x16/synergy-transfering.png" }; -MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig, - LicenseManager& licenseManager) : - m_Settings(settings), +#ifdef SYNERGY_ENTERPRISE +MainWindow::MainWindow (QSettings& settings, AppConfig& appConfig) +#else +MainWindow::MainWindow (QSettings& settings, AppConfig& appConfig, + LicenseManager& licenseManager) +#endif +: m_Settings(settings), m_AppConfig(&appConfig), +#ifndef SYNERGY_ENTERPRISE m_LicenseManager(&licenseManager), +#endif m_pSynergy(NULL), m_SynergyState(synergyDisconnected), m_ServerConfig(&m_Settings, 5, 3, m_AppConfig->screenName(), this), @@ -101,8 +107,10 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig, m_BonjourInstall(NULL), m_SuppressEmptyServerWarning(false), m_ExpectedRunningState(kStopped), - m_pSslCertificate(NULL), - m_ActivationDialogRunning(false) + m_pSslCertificate(NULL) +#ifndef SYNERGY_ENTERPRISE + , m_ActivationDialogRunning(false) +#endif { setupUi(this); @@ -142,7 +150,7 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig, connect (this, SIGNAL(windowShown()), this, SLOT(on_windowShown()), Qt::QueuedConnection); - +#ifndef SYNERGY_ENTERPRISE connect (m_LicenseManager, SIGNAL(editionChanged(Edition)), this, SLOT(setEdition(Edition)), Qt::QueuedConnection); @@ -151,20 +159,31 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig, connect (m_LicenseManager, SIGNAL(endTrial(bool)), this, SLOT(endTrial(bool)), Qt::QueuedConnection); +#endif connect (m_AppConfig, SIGNAL(sslToggled(bool)), this, SLOT(sslToggled(bool)), Qt::QueuedConnection); +#ifdef SYNERGY_ENTERPRISE + setWindowTitle ("Synergy Enterprise"); +#else setWindowTitle (m_LicenseManager->activeEditionName()); m_LicenseManager->refresh(); +#endif QString lastVersion = m_AppConfig->lastVersion(); QString currentVersion = m_VersionChecker.getVersion(); if (lastVersion != currentVersion) { m_AppConfig->setLastVersion (currentVersion); m_AppConfig->saveSettings(); +#ifndef SYNERGY_ENTERPRISE m_LicenseManager->notifyUpdate (lastVersion, currentVersion); +#endif } + +#ifdef SYNERGY_ENTERPRISE + m_pActivate->setVisible(false); +#endif } MainWindow::~MainWindow() @@ -431,7 +450,9 @@ void MainWindow::updateFromLogLine(const QString &line) // TODO: this code makes Andrew cry checkConnected(line); checkFingerprint(line); +#ifndef SYNERGY_ENTERPRISE checkLicense(line); +#endif } void MainWindow::checkConnected(const QString& line) @@ -456,6 +477,7 @@ void MainWindow::checkConnected(const QString& line) } } +#ifndef SYNERGY_ENTERPRISE void MainWindow::checkLicense(const QString &line) { if (line.contains("trial has expired")) { @@ -463,6 +485,7 @@ void MainWindow::checkLicense(const QString &line) raiseActivationDialog(); } } +#endif void MainWindow::checkFingerprint(const QString& line) { @@ -532,8 +555,9 @@ void MainWindow::restartSynergy() void MainWindow::proofreadInfo() { +#ifndef SYNERGY_ENTERPRISE setEdition(m_AppConfig->edition()); // Why is this here? - +#endif int oldState = m_SynergyState; m_SynergyState = synergyDisconnected; setSynergyState((qSynergyState)oldState); @@ -552,6 +576,7 @@ void MainWindow::clearLog() void MainWindow::startSynergy() { +#ifndef SYNERGY_ENTERPRISE SerialKey serialKey = m_LicenseManager->serialKey(); time_t currentTime = ::time(0); if (serialKey.isExpired(currentTime)) { @@ -559,7 +584,7 @@ void MainWindow::startSynergy() return; } } - +#endif bool desktopMode = appConfig().processMode() == Desktop; bool serviceMode = appConfig().processMode() == Service; @@ -804,9 +829,11 @@ bool MainWindow::serverArgs(QStringList& args, QString& app) #endif args << "-c" << configFilename << "--address" << address(); +#ifndef SYNERGY_ENTERPRISE if (!appConfig().serialKey().isEmpty()) { args << "--serial-key" << appConfig().serialKey(); } +#endif return true; } @@ -1056,7 +1083,9 @@ void MainWindow::serverDetected(const QString name) void MainWindow::setEdition(Edition edition) { +#ifndef SYNERGY_ENTERPRISE setWindowTitle(m_LicenseManager->getEditionName (edition)); +#endif if (m_AppConfig->getCryptoEnabled()) { m_pSslCertificate = new SslCertificate(this); m_pSslCertificate->generateCertificate(); @@ -1065,6 +1094,7 @@ void MainWindow::setEdition(Edition edition) saveSettings(); } +#ifndef SYNERGY_ENTERPRISE void MainWindow::beginTrial(bool isExpiring) { //Hack @@ -1115,6 +1145,7 @@ void MainWindow::endTrial(bool isExpired) } setWindowTitle (m_LicenseManager->activeEditionName()); } +#endif void MainWindow::updateLocalFingerprint() { @@ -1129,11 +1160,13 @@ void MainWindow::updateLocalFingerprint() } } +#ifndef SYNERGY_ENTERPRISE LicenseManager& MainWindow::licenseManager() const { return *m_LicenseManager; } +#endif void MainWindow::on_m_pGroupClient_toggled(bool on) { @@ -1199,6 +1232,7 @@ void MainWindow::on_m_pActionSettings_triggered() void MainWindow::autoAddScreen(const QString name) { if (!m_ServerConfig.ignoreAutoConfigClient()) { +#ifndef SYNERGY_ENTERPRISE if (m_ActivationDialogRunning) { // TODO: refactor this code // add this screen to the pending list and check this list until @@ -1206,6 +1240,7 @@ void MainWindow::autoAddScreen(const QString name) m_PendingClientNames.append(name); return; } +#endif int r = m_ServerConfig.autoAddScreen(name); if (r != kAutoAddScreenOk) { @@ -1244,7 +1279,9 @@ void MainWindow::on_m_pButtonConfigureServer_clicked() void MainWindow::on_m_pActivate_triggered() { +#ifndef SYNERGY_ENTERPRISE raiseActivationDialog(); +#endif } void MainWindow::on_m_pButtonApply_clicked() @@ -1456,6 +1493,7 @@ void MainWindow::bonjourInstallFinished() m_pCheckBoxAutoConfig->setChecked(true); } +#ifndef SYNERGY_ENTERPRISE int MainWindow::raiseActivationDialog() { if (m_ActivationDialogRunning) { @@ -1479,15 +1517,18 @@ int MainWindow::raiseActivationDialog() } return result; } +#endif void MainWindow::on_windowShown() { +#ifndef SYNERGY_ENTERPRISE time_t currentTime = ::time(0); if (!m_AppConfig->activationHasRun() && ((m_AppConfig->edition() == kUnregistered) || (m_LicenseManager->serialKey().isExpired(currentTime)))) { raiseActivationDialog(); } +#endif } QString MainWindow::getProfileRootForArg() diff --git a/src/gui/src/MainWindow.h b/src/gui/src/MainWindow.h index a97fd006..10acc10c 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -95,8 +95,12 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase }; public: +#ifdef SYNERGY_ENTERPRISE + MainWindow(QSettings& settings, AppConfig& appConfig); +#else MainWindow(QSettings& settings, AppConfig& appConfig, LicenseManager& licenseManager); +#endif ~MainWindow(); public: @@ -118,14 +122,17 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase void updateZeroconfService(); void serverDetected(const QString name); void updateLocalFingerprint(); +#ifndef SYNERGY_ENTERPRISE LicenseManager& licenseManager() const; - int raiseActivationDialog(); +#endif public slots: void setEdition(Edition edition); +#ifndef SYNERGY_ENTERPRISE void beginTrial(bool isExpiring); void endTrial(bool isExpired); +#endif void appendLogRaw(const QString& text); void appendLogInfo(const QString& text); void appendLogDebug(const QString& text); @@ -149,7 +156,7 @@ public slots: void logError(); void updateFound(const QString& version); void bonjourInstallFinished(); - void saveSettings(); + void saveSettings(); protected: QSettings& settings() { return m_Settings; } @@ -185,7 +192,9 @@ public slots: void promptAutoConfig(); QString getProfileRootForArg(); void checkConnected(const QString& line); +#ifndef SYNERGY_ENTERPRISE void checkLicense(const QString& line); +#endif void checkFingerprint(const QString& line); bool autoHide(); QString getTimeStamp(); @@ -223,8 +232,10 @@ public slots: qRuningState m_ExpectedRunningState; QMutex m_StopDesktopMutex; SslCertificate* m_pSslCertificate; +#ifndef SYNERGY_ENTERPRISE bool m_ActivationDialogRunning; QStringList m_PendingClientNames; +#endif private slots: void on_m_pCheckBoxAutoConfig_toggled(bool checked); diff --git a/src/gui/src/SettingsDialog.cpp b/src/gui/src/SettingsDialog.cpp index 109d2d06..00b656ac 100644 --- a/src/gui/src/SettingsDialog.cpp +++ b/src/gui/src/SettingsDialog.cpp @@ -2,11 +2,11 @@ * synergy -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -63,7 +63,11 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) : #endif m_pCheckBoxEnableCrypto->setChecked(m_appConfig.getCryptoEnabled()); +#ifdef SYNERGY_ENTERPRISE + m_pCheckBoxEnableCrypto->setEnabled(true); +#else m_pCheckBoxEnableCrypto->setEnabled(m_appConfig.edition() == kPro); +#endif } void SettingsDialog::accept() diff --git a/src/gui/src/main.cpp b/src/gui/src/main.cpp index dda6d306..5d8a5e89 100644 --- a/src/gui/src/main.cpp +++ b/src/gui/src/main.cpp @@ -41,10 +41,10 @@ class QThreadImpl : public QThread { public: - static void msleep(unsigned long msecs) - { - QThread::msleep(msecs); - } + static void msleep(unsigned long msecs) + { + QThread::msleep(msecs); + } }; int waitForTray(); @@ -59,84 +59,90 @@ int main(int argc, char* argv[]) /* Workaround for QTBUG-40332 - "High ping when QNetworkAccessManager is instantiated" */ ::setenv ("QT_BEARER_POLL_TIMEOUT", "-1", 1); #endif - QCoreApplication::setOrganizationName("Synergy"); - QCoreApplication::setOrganizationDomain("http://symless.com/"); - QCoreApplication::setApplicationName("Synergy"); + QCoreApplication::setOrganizationName("Synergy"); + QCoreApplication::setOrganizationDomain("http://symless.com/"); + QCoreApplication::setApplicationName("Synergy"); - QSynergyApplication app(argc, argv); + QSynergyApplication app(argc, argv); #if defined(Q_OS_MAC) - if (app.applicationDirPath().startsWith("/Volumes/")) { - QMessageBox::information( - NULL, "Synergy", - "Please drag Synergy to the Applications folder, and open it from there."); - return 1; - } + if (app.applicationDirPath().startsWith("/Volumes/")) { + QMessageBox::information( + NULL, "Synergy", + "Please drag Synergy to the Applications folder, and open it from there."); + return 1; + } - if (!checkMacAssistiveDevices()) - { - return 1; - } + if (!checkMacAssistiveDevices()) + { + return 1; + } #endif - if (!waitForTray()) - { - return -1; - } + if (!waitForTray()) + { + return -1; + } #ifndef Q_OS_WIN - QApplication::setQuitOnLastWindowClosed(false); + QApplication::setQuitOnLastWindowClosed(false); #endif - QSettings settings; - AppConfig appConfig (&settings); - qRegisterMetaType("Edition"); - LicenseManager licenseManager (&appConfig); + QSettings settings; + AppConfig appConfig (&settings); + qRegisterMetaType("Edition"); +#ifndef SYNERGY_ENTERPRISE + LicenseManager licenseManager (&appConfig); +#endif - app.switchTranslator(appConfig.language()); + app.switchTranslator(appConfig.language()); - MainWindow mainWindow(settings, appConfig, licenseManager); +#ifdef SYNERGY_ENTERPRISE + MainWindow mainWindow(settings, appConfig); +#else + MainWindow mainWindow(settings, appConfig, licenseManager); +#endif - QObject::connect(dynamic_cast(&app), SIGNAL(aboutToQuit()), - &mainWindow, SLOT(saveSettings())); + QObject::connect(dynamic_cast(&app), SIGNAL(aboutToQuit()), + &mainWindow, SLOT(saveSettings())); - SetupWizard setupWizard(mainWindow, true); + SetupWizard setupWizard(mainWindow, true); - if (appConfig.wizardShouldRun()) - { - setupWizard.show(); - } - else - { - mainWindow.open(); - } + if (appConfig.wizardShouldRun()) + { + setupWizard.show(); + } + else + { + mainWindow.open(); + } - return app.exec(); + return app.exec(); } int waitForTray() { - // on linux, the system tray may not be available immediately after logging in, - // so keep retrying but give up after a short time. - int trayAttempts = 0; - while (true) - { - if (QSystemTrayIcon::isSystemTrayAvailable()) - { - break; - } + // on linux, the system tray may not be available immediately after logging in, + // so keep retrying but give up after a short time. + int trayAttempts = 0; + while (true) + { + if (QSystemTrayIcon::isSystemTrayAvailable()) + { + break; + } - if (++trayAttempts > TRAY_RETRY_COUNT) - { - QMessageBox::critical(NULL, "Synergy", - QObject::tr("System tray is unavailable, don't close your window.")); - return true; - } + if (++trayAttempts > TRAY_RETRY_COUNT) + { + QMessageBox::critical(NULL, "Synergy", + QObject::tr("System tray is unavailable, don't close your window.")); + return true; + } - QThreadImpl::msleep(TRAY_RETRY_WAIT); - } - return true; + QThreadImpl::msleep(TRAY_RETRY_WAIT); + } + return true; } #if defined(Q_OS_MAC) @@ -144,36 +150,36 @@ bool checkMacAssistiveDevices() { #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 // mavericks - // new in mavericks, applications are trusted individually - // with use of the accessibility api. this call will show a - // prompt which can show the security/privacy/accessibility - // tab, with a list of allowed applications. synergy should - // show up there automatically, but will be unchecked. + // new in mavericks, applications are trusted individually + // with use of the accessibility api. this call will show a + // prompt which can show the security/privacy/accessibility + // tab, with a list of allowed applications. synergy should + // show up there automatically, but will be unchecked. - if (AXIsProcessTrusted()) { - return true; - } + if (AXIsProcessTrusted()) { + return true; + } - const void* keys[] = { kAXTrustedCheckOptionPrompt }; - const void* trueValue[] = { kCFBooleanTrue }; - CFDictionaryRef options = CFDictionaryCreate(NULL, keys, trueValue, 1, NULL, NULL); + const void* keys[] = { kAXTrustedCheckOptionPrompt }; + const void* trueValue[] = { kCFBooleanTrue }; + CFDictionaryRef options = CFDictionaryCreate(NULL, keys, trueValue, 1, NULL, NULL); - bool result = AXIsProcessTrustedWithOptions(options); - CFRelease(options); - return result; + bool result = AXIsProcessTrustedWithOptions(options); + CFRelease(options); + return result; #else - // now deprecated in mavericks. - bool result = AXAPIEnabled(); - if (!result) { - QMessageBox::information( - NULL, "Synergy", - "Please enable access to assistive devices " - "System Preferences -> Security & Privacy -> " - "Privacy -> Accessibility, then re-open Synergy."); - } - return result; + // now deprecated in mavericks. + bool result = AXAPIEnabled(); + if (!result) { + QMessageBox::information( + NULL, "Synergy", + "Please enable access to assistive devices " + "System Preferences -> Security & Privacy -> " + "Privacy -> Accessibility, then re-open Synergy."); + } + return result; #endif }