Clean service code
This commit is contained in:
parent
11f9c7bc7c
commit
fe9be23536
3 changed files with 1 additions and 136 deletions
|
|
@ -34,6 +34,5 @@ class IpcInterface
|
||||||
SLOT( bool updateResolvers(const QString& ifname, const QList<QHostAddress>& resolvers) );
|
SLOT( bool updateResolvers(const QString& ifname, const QList<QHostAddress>& resolvers) );
|
||||||
|
|
||||||
SLOT( int mountDmg(const QString &path, bool mount) );
|
SLOT( int mountDmg(const QString &path, bool mount) );
|
||||||
SLOT (int installApp(const QString &path));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QLocalSocket>
|
#include <QLocalSocket>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QProcess>
|
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "router.h"
|
#include "router.h"
|
||||||
|
|
@ -380,135 +379,3 @@ int IpcServer::mountDmg(const QString &path, bool mount)
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
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;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ public:
|
||||||
virtual bool disableKillSwitch() override;
|
virtual bool disableKillSwitch() override;
|
||||||
virtual bool updateResolvers(const QString &ifname, const QList<QHostAddress> &resolvers) override;
|
virtual bool updateResolvers(const QString &ifname, const QList<QHostAddress> &resolvers) override;
|
||||||
virtual int mountDmg(const QString &path, bool mount) override;
|
virtual int mountDmg(const QString &path, bool mount) override;
|
||||||
virtual int installApp(const QString &path) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_localpid = 0;
|
int m_localpid = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue