diff --git a/client/ui/controllers/updateController.cpp b/client/ui/controllers/updateController.cpp index 45acf190..80d04d6a 100644 --- a/client/ui/controllers/updateController.cpp +++ b/client/ui/controllers/updateController.cpp @@ -9,7 +9,8 @@ #include "core/errorstrings.h" #include "version.h" -namespace { +namespace +{ #ifdef Q_OS_MACOS const QString installerPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/AmneziaVPN.dmg"; #elif defined Q_OS_WINDOWS @@ -19,7 +20,8 @@ namespace { #endif } -UpdateController::UpdateController(const std::shared_ptr &settings, QObject *parent) : QObject(parent), m_settings(settings) +UpdateController::UpdateController(const std::shared_ptr &settings, QObject *parent) + : QObject(parent), m_settings(settings) { } @@ -62,19 +64,19 @@ void UpdateController::checkForUpdates() for (auto asset : assets) { QJsonObject assetObject = asset.toObject(); - #ifdef Q_OS_WINDOWS +#ifdef Q_OS_WINDOWS if (assetObject.value("name").toString().endsWith(".exe")) { m_downloadUrl = assetObject.value("browser_download_url").toString(); } - #elif defined(Q_OS_MACOS) +#elif defined(Q_OS_MACOS) if (assetObject.value("name").toString().endsWith(".dmg")) { m_downloadUrl = assetObject.value("browser_download_url").toString(); } - #elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) +#elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) if (assetObject.value("name").toString().contains(".tar.zip")) { m_downloadUrl = assetObject.value("browser_download_url").toString(); } - #endif +#endif } emit updateFound(); @@ -141,5 +143,4 @@ void UpdateController::runInstaller() reply->deleteLater(); }); - } diff --git a/client/ui/controllers/updateController.h b/client/ui/controllers/updateController.h index 986174ac..ea5c22fa 100644 --- a/client/ui/controllers/updateController.h +++ b/client/ui/controllers/updateController.h @@ -22,6 +22,7 @@ public slots: signals: void updateFound(); void errorOccured(const QString &errorMessage); + private: std::shared_ptr m_settings; diff --git a/ipc/ipcserver.cpp b/ipc/ipcserver.cpp index d02fe56a..46c96074 100644 --- a/ipc/ipcserver.cpp +++ b/ipc/ipcserver.cpp @@ -9,8 +9,8 @@ #include "logger.h" #include "router.h" -#include "../core/networkUtilities.h" #include "../client/protocols/protocols_defs.h" +#include "../core/networkUtilities.h" #ifdef Q_OS_WIN #include "../client/platforms/windows/daemon/windowsdaemon.h" #include "../client/platforms/windows/daemon/windowsfirewall.h" @@ -60,12 +60,15 @@ int IpcServer::createPrivilegedProcess() } }); - QObject::connect(pd.serverNode.data(), &QRemoteObjectHost::error, this, - [pd](QRemoteObjectNode::ErrorCode errorCode) { qDebug() << "QRemoteObjectHost::error" << errorCode; }); + QObject::connect(pd.serverNode.data(), &QRemoteObjectHost::error, this, [pd](QRemoteObjectNode::ErrorCode errorCode) { + qDebug() << "QRemoteObjectHost::error" << errorCode; + }); - QObject::connect(pd.serverNode.data(), &QRemoteObjectHost::destroyed, this, [pd]() { qDebug() << "QRemoteObjectHost::destroyed"; }); + QObject::connect(pd.serverNode.data(), &QRemoteObjectHost::destroyed, this, + [pd]() { qDebug() << "QRemoteObjectHost::destroyed"; }); - // connect(pd.ipcProcess.data(), &IpcServerProcess::finished, this, [this, pid=m_localpid](int exitCode, QProcess::ExitStatus exitStatus){ + // connect(pd.ipcProcess.data(), &IpcServerProcess::finished, this, [this, pid=m_localpid](int exitCode, + // QProcess::ExitStatus exitStatus){ // qDebug() << "IpcServerProcess finished" << exitCode << exitStatus; //// if (m_processes.contains(pid)) { //// m_processes[pid].ipcProcess.reset(); @@ -386,17 +389,14 @@ int IpcServer::installApp(const QString &path) // On Windows, simply run the .exe file with administrator privileges QProcess process; process.setProgram("powershell.exe"); - process.setArguments(QStringList() - << "Start-Process" - << path - << "-Verb" - << "RunAs" - << "-Wait"); - + process.setArguments(QStringList() << "Start-Process" << path << "-Verb" + << "RunAs" + << "-Wait"); + qDebug() << "Launching installer with elevated privileges..."; process.start(); process.waitForFinished(); - + if (process.exitCode() != 0) { qDebug() << "Installation error:" << process.readAllStandardError(); } @@ -404,57 +404,47 @@ int IpcServer::installApp(const QString &path) #elif defined(Q_OS_MACOS) // DRAFT - + QProcess process; QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation); QString mountPoint = tempDir + "/AmneziaVPN_mount"; - + // Create mount point QDir dir(mountPoint); if (!dir.exists()) { dir.mkpath("."); } - + // Mount DMG image qDebug() << "Mounting DMG image..."; - process.start("hdiutil", QStringList() - << "attach" - << path - << "-mountpoint" - << mountPoint - << "-nobrowse"); + process.start("hdiutil", QStringList() << "attach" << path << "-mountpoint" << mountPoint << "-nobrowse"); process.waitForFinished(); - + if (process.exitCode() != 0) { qDebug() << "Failed to mount DMG:" << process.readAllStandardError(); return process.exitCode(); } - + // Look for .app bundle in mounted image QDirIterator it(mountPoint, QStringList() << "*.app", QDir::Dirs); if (!it.hasNext()) { qDebug() << "No .app bundle found in DMG"; return -1; } - + QString appPath = it.next(); QString targetPath = "/Applications/" + QFileInfo(appPath).fileName(); - + // Copy application to /Applications qDebug() << "Copying app to Applications folder..."; - process.start("cp", QStringList() - << "-R" - << appPath - << targetPath); + process.start("cp", QStringList() << "-R" << appPath << targetPath); process.waitForFinished(); - + // Unmount DMG qDebug() << "Unmounting DMG..."; - process.start("hdiutil", QStringList() - << "detach" - << mountPoint); + process.start("hdiutil", QStringList() << "detach" << mountPoint); process.waitForFinished(); - + if (process.exitCode() != 0) { qDebug() << "Installation error:" << process.readAllStandardError(); } @@ -464,17 +454,17 @@ int IpcServer::installApp(const QString &path) QProcess process; QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation); QString extractDir = tempDir + "/amnezia_update"; - + qDebug() << "Installing app from:" << path; qDebug() << "Using temp directory:" << extractDir; - + // Create extraction directory if it doesn't exist QDir dir(extractDir); if (!dir.exists()) { dir.mkpath("."); qDebug() << "Created extraction directory"; } - + // First, extract the zip archive qDebug() << "Extracting ZIP archive..."; process.start("unzip", QStringList() << path << "-d" << extractDir); @@ -484,7 +474,7 @@ int IpcServer::installApp(const QString &path) return process.exitCode(); } qDebug() << "ZIP archive extracted successfully"; - + // Look for tar file in extracted files qDebug() << "Looking for TAR file..."; QDirIterator tarIt(extractDir, QStringList() << "*.tar", QDir::Files); @@ -492,12 +482,12 @@ int IpcServer::installApp(const QString &path) qDebug() << "TAR file not found in the extracted archive"; return -1; } - + // Extract found tar archive QString tarPath = tarIt.next(); qDebug() << "Found TAR file:" << tarPath; qDebug() << "Extracting TAR archive..."; - + process.start("tar", QStringList() << "-xf" << tarPath << "-C" << extractDir); process.waitForFinished(); if (process.exitCode() != 0) { @@ -505,11 +495,11 @@ int IpcServer::installApp(const QString &path) return process.exitCode(); } qDebug() << "TAR archive extracted successfully"; - + // Remove tar file as it's no longer needed QFile::remove(tarPath); qDebug() << "Removed temporary TAR file"; - + // Find executable file and run it qDebug() << "Looking for executable file..."; QDirIterator it(extractDir, QDir::Files | QDir::Executable, QDirIterator::Subdirectories); @@ -524,7 +514,7 @@ int IpcServer::installApp(const QString &path) qDebug() << "Installer finished with exit code:" << process.exitCode(); return process.exitCode(); } - + qDebug() << "No executable file found"; return -1; // Executable not found #endif diff --git a/ipc/ipcserver.h b/ipc/ipcserver.h index 7e5b21d1..c3aaaf4e 100644 --- a/ipc/ipcserver.h +++ b/ipc/ipcserver.h @@ -1,11 +1,11 @@ #ifndef IPCSERVER_H #define IPCSERVER_H +#include "../client/daemon/interfaceconfig.h" +#include #include #include #include -#include -#include "../client/daemon/interfaceconfig.h" #include "ipc.h" #include "ipcserverprocess.h" @@ -37,15 +37,17 @@ public: virtual bool enablePeerTraffic(const QJsonObject &configStr) override; virtual bool enableKillSwitch(const QJsonObject &excludeAddr, int vpnAdapterIndex) override; virtual bool disableKillSwitch() override; - virtual bool updateResolvers(const QString& ifname, const QList& resolvers) override; + virtual bool updateResolvers(const QString &ifname, const QList &resolvers) override; virtual int mountDmg(const QString &path, bool mount) override; virtual int installApp(const QString &path) override; private: int m_localpid = 0; - struct ProcessDescriptor { - ProcessDescriptor (QObject *parent = nullptr) { + struct ProcessDescriptor + { + ProcessDescriptor(QObject *parent = nullptr) + { serverNode = QSharedPointer(new QRemoteObjectHost(parent)); ipcProcess = QSharedPointer(new IpcServerProcess(parent)); tun2socksProcess = QSharedPointer(new IpcProcessTun2Socks(parent));