From fe9be2353689fec5a91b0744f140fb0ff8925481 Mon Sep 17 00:00:00 2001 From: aiamnezia Date: Thu, 19 Dec 2024 19:20:31 +0400 Subject: [PATCH] Clean service code --- ipc/ipc_interface.rep | 1 - ipc/ipcserver.cpp | 135 +----------------------------------------- ipc/ipcserver.h | 1 - 3 files changed, 1 insertion(+), 136 deletions(-) diff --git a/ipc/ipc_interface.rep b/ipc/ipc_interface.rep index 7dad63bd..1647ea19 100644 --- a/ipc/ipc_interface.rep +++ b/ipc/ipc_interface.rep @@ -34,6 +34,5 @@ class IpcInterface SLOT( bool updateResolvers(const QString& ifname, const QList& resolvers) ); SLOT( int mountDmg(const QString &path, bool mount) ); - SLOT (int installApp(const QString &path)); }; diff --git a/ipc/ipcserver.cpp b/ipc/ipcserver.cpp index 64d046f3..b73ae407 100644 --- a/ipc/ipcserver.cpp +++ b/ipc/ipcserver.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include "logger.h" #include "router.h" @@ -379,136 +378,4 @@ int IpcServer::mountDmg(const QString &path, bool mount) return res; #endif return 0; -} - -int IpcServer::installApp(const QString &path) -{ - Logger logger("IpcServer"); - logger.info() << "Installing app from:" << path; - -#ifdef Q_OS_WINDOWS - QProcess process; - logger.info() << "Launching installer with elevated privileges..."; - process.start(path); - process.waitForFinished(); - logger.info() << "Installer stdout:" << process.readAllStandardOutput(); - logger.info() << "Installer stderr:" << process.readAllStandardError(); - - if (process.exitCode() != 0) { - logger.error() << "Installation error:" << process.readAllStandardError(); - } - return process.exitCode(); - -#elif defined(Q_OS_MACOS) - 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 - logger.info() << "Mounting DMG image..."; - process.start("hdiutil", QStringList() << "attach" << path << "-mountpoint" << mountPoint << "-nobrowse"); - process.waitForFinished(); - - if (process.exitCode() != 0) { - logger.error() << "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()) { - logger.error() << "No .app bundle found in DMG"; - return -1; - } - - QString appPath = it.next(); - QString targetPath = "/Applications/" + QFileInfo(appPath).fileName(); - - // Copy application to /Applications - logger.info() << "Copying app to Applications folder..."; - process.start("cp", QStringList() << "-R" << appPath << targetPath); - process.waitForFinished(); - - // Unmount DMG - logger.info() << "Unmounting DMG..."; - process.start("hdiutil", QStringList() << "detach" << mountPoint); - process.waitForFinished(); - - if (process.exitCode() != 0) { - logger.error() << "Installation error:" << process.readAllStandardError(); - } - return process.exitCode(); - -#elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) - QProcess process; - QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation); - QString extractDir = tempDir + "/amnezia_update"; - - logger.info() << "Using temp directory:" << extractDir; - - // Create extraction directory if it doesn't exist - QDir dir(extractDir); - if (!dir.exists()) { - dir.mkpath("."); - logger.info() << "Created extraction directory"; - } - - // First, extract the zip archive - logger.info() << "Extracting ZIP archive..."; - process.start("unzip", QStringList() << path << "-d" << extractDir); - process.waitForFinished(); - if (process.exitCode() != 0) { - logger.error() << "ZIP extraction error:" << process.readAllStandardError(); - return process.exitCode(); - } - logger.info() << "ZIP archive extracted successfully"; - - // Look for tar file in extracted files - logger.info() << "Looking for TAR file..."; - QDirIterator tarIt(extractDir, QStringList() << "*.tar", QDir::Files); - if (!tarIt.hasNext()) { - logger.error() << "TAR file not found in the extracted archive"; - return -1; - } - - // Extract found tar archive - QString tarPath = tarIt.next(); - logger.info() << "Found TAR file:" << tarPath; - logger.info() << "Extracting TAR archive..."; - - process.start("tar", QStringList() << "-xf" << tarPath << "-C" << extractDir); - process.waitForFinished(); - if (process.exitCode() != 0) { - logger.error() << "TAR extraction error:" << process.readAllStandardError(); - return process.exitCode(); - } - logger.info() << "TAR archive extracted successfully"; - - // Remove tar file as it's no longer needed - QFile::remove(tarPath); - logger.info() << "Removed temporary TAR file"; - - // Find executable file and run it - logger.info() << "Looking for executable file..."; - QDirIterator it(extractDir, QDir::Files | QDir::Executable, QDirIterator::Subdirectories); - if (it.hasNext()) { - QString execPath = it.next(); - logger.info() << "Found executable:" << execPath; - logger.info() << "Launching installer..."; - process.start("sudo", QStringList() << execPath); - process.waitForFinished(); - logger.info() << "Installer finished with exit code:" << process.exitCode(); - return process.exitCode(); - } - - logger.error() << "No executable file found"; - return -1; // Executable not found -#endif - return 0; -} +} \ No newline at end of file diff --git a/ipc/ipcserver.h b/ipc/ipcserver.h index c3aaaf4e..0f0153aa 100644 --- a/ipc/ipcserver.h +++ b/ipc/ipcserver.h @@ -39,7 +39,6 @@ public: virtual bool disableKillSwitch() 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;