2023-08-27 10:46:41 -07:00
|
|
|
#ifndef IOS_CONTROLLER_H
|
|
|
|
|
#define IOS_CONTROLLER_H
|
|
|
|
|
|
|
|
|
|
#include "protocols/vpnprotocol.h"
|
2025-12-18 16:36:12 +02:00
|
|
|
#include <functional>
|
|
|
|
|
#include <QVariant>
|
|
|
|
|
#include <QVariantMap>
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
#include <QList>
|
2025-12-30 04:45:32 +02:00
|
|
|
#include <QElapsedTimer>
|
|
|
|
|
#include <atomic>
|
2023-08-27 10:46:41 -07:00
|
|
|
|
|
|
|
|
#ifdef __OBJC__
|
2023-09-13 16:11:08 +05:00
|
|
|
#import <Foundation/Foundation.h>
|
2023-08-27 10:46:41 -07:00
|
|
|
@class NETunnelProviderManager;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
using namespace amnezia;
|
|
|
|
|
|
2023-09-13 16:11:08 +05:00
|
|
|
struct Action
|
|
|
|
|
{
|
|
|
|
|
static const char *start;
|
|
|
|
|
static const char *restart;
|
|
|
|
|
static const char *stop;
|
|
|
|
|
static const char *getTunnelId;
|
|
|
|
|
static const char *getStatus;
|
2023-08-27 10:46:41 -07:00
|
|
|
};
|
|
|
|
|
|
2023-09-13 16:11:08 +05:00
|
|
|
struct MessageKey
|
|
|
|
|
{
|
|
|
|
|
static const char *action;
|
|
|
|
|
static const char *tunnelId;
|
|
|
|
|
static const char *config;
|
|
|
|
|
static const char *errorCode;
|
|
|
|
|
static const char *host;
|
|
|
|
|
static const char *port;
|
|
|
|
|
static const char *isOnDemand;
|
2023-10-22 16:21:59 +03:00
|
|
|
static const char *SplitTunnelType;
|
|
|
|
|
static const char *SplitTunnelSites;
|
2023-08-27 10:46:41 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class IosController : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2023-09-13 16:11:08 +05:00
|
|
|
static IosController *Instance();
|
2023-08-27 10:46:41 -07:00
|
|
|
|
|
|
|
|
virtual ~IosController() override = default;
|
|
|
|
|
|
|
|
|
|
bool initialize();
|
2023-09-13 16:11:08 +05:00
|
|
|
bool connectVpn(amnezia::Proto proto, const QJsonObject &configuration);
|
2023-08-27 10:46:41 -07:00
|
|
|
void disconnectVpn();
|
|
|
|
|
|
|
|
|
|
void vpnStatusDidChange(void *pNotification);
|
2025-08-10 06:12:19 +03:00
|
|
|
|
2023-08-27 10:46:41 -07:00
|
|
|
void vpnConfigurationDidChange(void *pNotification);
|
|
|
|
|
|
2023-09-13 16:11:08 +05:00
|
|
|
void getBackendLogs(std::function<void(const QString &)> &&callback);
|
2023-08-27 10:46:41 -07:00
|
|
|
void checkStatus();
|
2024-05-16 06:19:56 -07:00
|
|
|
|
|
|
|
|
bool shareText(const QStringList &filesToSend);
|
|
|
|
|
QString openFile();
|
|
|
|
|
|
2025-12-18 16:36:12 +02:00
|
|
|
void purchaseProduct(const QString &productId,
|
|
|
|
|
std::function<void(bool success,
|
|
|
|
|
const QString &transactionId,
|
|
|
|
|
const QString &purchasedProductId,
|
|
|
|
|
const QString &originalTransactionId,
|
|
|
|
|
const QString &errorString)> &&callback);
|
|
|
|
|
void restorePurchases(std::function<void(bool success,
|
|
|
|
|
const QList<QVariantMap> &transactions,
|
|
|
|
|
const QString &errorString)> &&callback);
|
|
|
|
|
|
|
|
|
|
// Fetch product info for given product identifiers and return basic fields for logging
|
|
|
|
|
void fetchProducts(const QStringList &productIds,
|
|
|
|
|
std::function<void(const QList<QVariantMap> &products,
|
|
|
|
|
const QStringList &invalidIds,
|
|
|
|
|
const QString &errorString)> &&callback);
|
|
|
|
|
|
2024-05-16 06:19:56 -07:00
|
|
|
void requestInetAccess();
|
2025-12-29 19:18:03 +08:00
|
|
|
bool isTestFlight();
|
2023-08-27 10:46:41 -07:00
|
|
|
signals:
|
2023-08-30 15:10:44 +05:00
|
|
|
void connectionStateChanged(Vpn::ConnectionState state);
|
2023-08-27 10:46:41 -07:00
|
|
|
void bytesChanged(quint64 receivedBytes, quint64 sentBytes);
|
2023-09-01 14:49:10 +03:00
|
|
|
void importConfigFromOutside(const QString);
|
2023-09-13 16:11:08 +05:00
|
|
|
void importBackupFromOutside(const QString);
|
2023-08-27 10:46:41 -07:00
|
|
|
|
2024-05-16 06:19:56 -07:00
|
|
|
void finished();
|
|
|
|
|
|
2023-08-27 10:46:41 -07:00
|
|
|
protected slots:
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
explicit IosController();
|
|
|
|
|
|
|
|
|
|
bool setupOpenVPN();
|
|
|
|
|
bool setupCloak();
|
|
|
|
|
bool setupWireGuard();
|
2023-10-06 22:05:48 +05:00
|
|
|
bool setupAwg();
|
2024-06-30 12:19:38 +03:00
|
|
|
bool setupXray();
|
2024-07-09 14:56:39 +07:00
|
|
|
bool setupSSXray();
|
2023-08-27 10:46:41 -07:00
|
|
|
|
|
|
|
|
bool startOpenVPN(const QString &config);
|
|
|
|
|
bool startWireGuard(const QString &jsonConfig);
|
2024-06-30 12:19:38 +03:00
|
|
|
bool startXray(const QString &jsonConfig);
|
2023-08-27 10:46:41 -07:00
|
|
|
|
|
|
|
|
void startTunnel();
|
2025-12-30 04:45:32 +02:00
|
|
|
void emitConnectionStateIfChanged(Vpn::ConnectionState state);
|
2023-08-27 10:46:41 -07:00
|
|
|
|
|
|
|
|
private:
|
2023-09-13 16:11:08 +05:00
|
|
|
void *m_iosControllerWrapper {};
|
2023-08-27 10:46:41 -07:00
|
|
|
#ifdef __OBJC__
|
2023-09-13 16:11:08 +05:00
|
|
|
NETunnelProviderManager *m_currentTunnel {};
|
|
|
|
|
NSString *m_serverAddress {};
|
|
|
|
|
bool isOurManager(NETunnelProviderManager *manager);
|
|
|
|
|
void sendVpnExtensionMessage(NSDictionary *message, std::function<void(NSDictionary *)> callback = nullptr);
|
2023-08-27 10:46:41 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
amnezia::Proto m_proto;
|
|
|
|
|
QJsonObject m_rawConfig;
|
|
|
|
|
QString m_tunnelId;
|
2025-12-30 04:45:32 +02:00
|
|
|
uint64_t m_txBytes = 0;
|
|
|
|
|
uint64_t m_rxBytes = 0;
|
|
|
|
|
bool m_handshakeAwaiting = false;
|
|
|
|
|
bool m_handshakeConfirmed = false;
|
|
|
|
|
QElapsedTimer m_handshakeTimer;
|
|
|
|
|
Vpn::ConnectionState m_lastEmittedState = Vpn::ConnectionState::Unknown;
|
|
|
|
|
std::atomic_bool m_statusRequestInFlight { false };
|
2023-08-27 10:46:41 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // IOS_CONTROLLER_H
|