2023-05-22 22:11:20 +08:00
|
|
|
#ifndef IMPORTCONTROLLER_H
|
|
|
|
|
#define IMPORTCONTROLLER_H
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
|
|
#include "ui/models/containers_model.h"
|
2023-07-24 16:31:04 +09:00
|
|
|
#include "ui/models/servers_model.h"
|
2023-05-22 22:11:20 +08:00
|
|
|
|
2024-04-19 00:23:15 +07:00
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
enum class ConfigTypes {
|
|
|
|
|
Amnezia,
|
|
|
|
|
OpenVpn,
|
|
|
|
|
WireGuard,
|
|
|
|
|
Awg,
|
|
|
|
|
Xray,
|
2024-05-27 16:15:55 +01:00
|
|
|
ShadowSocks,
|
2024-04-19 00:23:15 +07:00
|
|
|
Backup,
|
|
|
|
|
Invalid
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-22 22:11:20 +08:00
|
|
|
class ImportController : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
explicit ImportController(const QSharedPointer<ServersModel> &serversModel,
|
|
|
|
|
const QSharedPointer<ContainersModel> &containersModel,
|
2023-07-24 16:31:04 +09:00
|
|
|
const std::shared_ptr<Settings> &settings, QObject *parent = nullptr);
|
2023-05-22 22:11:20 +08:00
|
|
|
|
|
|
|
|
public slots:
|
2023-06-05 15:49:10 +08:00
|
|
|
void importConfig();
|
2025-12-02 05:13:26 +02:00
|
|
|
void clearConfigFileName();
|
2024-03-14 04:22:10 +07:00
|
|
|
bool extractConfigFromFile(const QString &fileName);
|
|
|
|
|
bool extractConfigFromData(QString data);
|
2023-07-25 16:56:10 +09:00
|
|
|
bool extractConfigFromQr(const QByteArray &data);
|
2023-06-05 15:49:10 +08:00
|
|
|
QString getConfig();
|
|
|
|
|
QString getConfigFileName();
|
2024-04-21 17:58:57 +05:00
|
|
|
QString getMaliciousWarningText();
|
2023-05-22 22:11:20 +08:00
|
|
|
|
2023-08-13 11:28:32 +05:00
|
|
|
#if defined Q_OS_ANDROID || defined Q_OS_IOS
|
2023-07-25 16:56:10 +09:00
|
|
|
void startDecodingQr();
|
2023-11-21 22:48:52 +03:00
|
|
|
bool parseQrCodeChunk(const QString &code);
|
2023-08-13 11:28:32 +05:00
|
|
|
|
|
|
|
|
double getQrCodeScanProgressBarValue();
|
|
|
|
|
QString getQrCodeScanProgressString();
|
2023-07-25 16:56:10 +09:00
|
|
|
#endif
|
|
|
|
|
|
2023-11-21 22:48:52 +03:00
|
|
|
#if defined Q_OS_ANDROID
|
|
|
|
|
static bool decodeQrCode(const QString &code);
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-04-19 00:23:15 +07:00
|
|
|
bool isNativeWireGuardConfig();
|
|
|
|
|
void processNativeWireGuardConfig();
|
|
|
|
|
|
2023-05-22 22:11:20 +08:00
|
|
|
signals:
|
|
|
|
|
void importFinished();
|
2024-05-25 13:00:51 +03:00
|
|
|
void importErrorOccurred(ErrorCode errorCode, bool goToPageHome);
|
2023-06-13 20:03:20 +09:00
|
|
|
|
2023-07-25 16:56:10 +09:00
|
|
|
void qrDecodingFinished();
|
|
|
|
|
|
2024-03-14 04:22:10 +07:00
|
|
|
void restoreAppConfig(const QByteArray &data);
|
|
|
|
|
|
2023-05-22 22:11:20 +08:00
|
|
|
private:
|
2023-06-05 15:49:10 +08:00
|
|
|
QJsonObject extractOpenVpnConfig(const QString &data);
|
|
|
|
|
QJsonObject extractWireGuardConfig(const QString &data);
|
2024-05-27 16:15:55 +01:00
|
|
|
QJsonObject extractXrayConfig(const QString &data, const QString &description = "");
|
2023-05-22 22:11:20 +08:00
|
|
|
|
2024-04-21 17:58:57 +05:00
|
|
|
void checkForMaliciousStrings(const QJsonObject &protocolConfig);
|
|
|
|
|
|
2024-09-13 12:38:48 +04:00
|
|
|
void processAmneziaConfig(QJsonObject &config);
|
|
|
|
|
|
2023-08-13 11:28:32 +05:00
|
|
|
#if defined Q_OS_ANDROID || defined Q_OS_IOS
|
2023-07-25 16:56:10 +09:00
|
|
|
void stopDecodingQr();
|
2023-08-13 11:28:32 +05:00
|
|
|
#endif
|
2023-07-25 16:56:10 +09:00
|
|
|
|
2023-05-22 22:11:20 +08:00
|
|
|
QSharedPointer<ServersModel> m_serversModel;
|
|
|
|
|
QSharedPointer<ContainersModel> m_containersModel;
|
|
|
|
|
std::shared_ptr<Settings> m_settings;
|
|
|
|
|
|
2023-06-05 15:49:10 +08:00
|
|
|
QJsonObject m_config;
|
|
|
|
|
QString m_configFileName;
|
2024-04-19 00:23:15 +07:00
|
|
|
ConfigTypes m_configType;
|
2024-04-21 17:58:57 +05:00
|
|
|
QString m_maliciousWarningText;
|
2023-07-25 16:56:10 +09:00
|
|
|
|
2023-08-13 11:28:32 +05:00
|
|
|
#if defined Q_OS_ANDROID || defined Q_OS_IOS
|
2023-07-25 16:56:10 +09:00
|
|
|
QMap<int, QByteArray> m_qrCodeChunks;
|
|
|
|
|
bool m_isQrCodeProcessed;
|
|
|
|
|
int m_totalQrCodeChunksCount;
|
|
|
|
|
int m_receivedQrCodeChunksCount;
|
|
|
|
|
#endif
|
2023-05-22 22:11:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // IMPORTCONTROLLER_H
|