Merge branch 'dev' of github.com:amnezia-vpn/amnezia-client into feature/new-gui
This commit is contained in:
commit
e0d93eaa9f
15 changed files with 218 additions and 116 deletions
|
|
@ -15,7 +15,7 @@ public:
|
|||
explicit IOSVpnProtocol(amnezia::Proto proto, const QJsonObject& configuration, QObject* parent = nullptr);
|
||||
static IOSVpnProtocol* instance();
|
||||
|
||||
virtual ~IOSVpnProtocol() override = default;
|
||||
virtual ~IOSVpnProtocol() override;
|
||||
|
||||
bool initialize();
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,12 @@ IOSVpnProtocol::IOSVpnProtocol(Proto proto, const QJsonObject &configuration, QO
|
|||
connect(this, &IOSVpnProtocol::newTransmittedDataCount, this, &IOSVpnProtocol::setBytesChanged);
|
||||
}
|
||||
|
||||
IOSVpnProtocol::~IOSVpnProtocol()
|
||||
{
|
||||
qDebug() << "IOSVpnProtocol::~IOSVpnProtocol()";
|
||||
IOSVpnProtocol::stop();
|
||||
}
|
||||
|
||||
IOSVpnProtocol* IOSVpnProtocol::instance() {
|
||||
return s_instance;
|
||||
}
|
||||
|
|
@ -158,9 +164,12 @@ void IOSVpnProtocol::checkStatus()
|
|||
}
|
||||
|
||||
m_checkingStatus = true;
|
||||
|
||||
QPointer<IOSVpnProtocol> weakSelf = this;
|
||||
|
||||
[m_controller checkStatusWithCallback:^(NSString* serverIpv4Gateway, NSString* deviceIpv4Address,
|
||||
NSString* configString) {
|
||||
if (!weakSelf) return;
|
||||
QString config = QString::fromNSString(configString);
|
||||
|
||||
m_checkingStatus = false;
|
||||
|
|
@ -185,7 +194,7 @@ void IOSVpnProtocol::checkStatus()
|
|||
}
|
||||
}
|
||||
|
||||
emit newTransmittedDataCount(rxBytes, txBytes);
|
||||
emit weakSelf->newTransmittedDataCount(rxBytes, txBytes);
|
||||
}];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ QString OpenVpnProtocol::defaultConfigPath()
|
|||
void OpenVpnProtocol::stop()
|
||||
{
|
||||
qDebug() << "OpenVpnProtocol::stop()";
|
||||
setConnectionState(VpnProtocol::Disconnecting);
|
||||
|
||||
// TODO: need refactoring
|
||||
// sendTermSignal() will even return true while server connected ???
|
||||
|
|
@ -52,10 +53,10 @@ void OpenVpnProtocol::stop()
|
|||
if (!sendTermSignal()) {
|
||||
killOpenVpnProcess();
|
||||
}
|
||||
QThread::msleep(10);
|
||||
m_managementServer.stop();
|
||||
qApp->processEvents();
|
||||
setConnectionState(Vpn::ConnectionState::Disconnecting);
|
||||
}
|
||||
setConnectionState(VpnProtocol::Disconnected);
|
||||
}
|
||||
|
||||
ErrorCode OpenVpnProtocol::prepare()
|
||||
|
|
@ -78,11 +79,9 @@ ErrorCode OpenVpnProtocol::prepare()
|
|||
|
||||
void OpenVpnProtocol::killOpenVpnProcess()
|
||||
{
|
||||
#ifndef Q_OS_IOS
|
||||
if (m_openVpnProcess){
|
||||
m_openVpnProcess->close();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void OpenVpnProtocol::readOpenVpnConfiguration(const QJsonObject &configuration)
|
||||
|
|
@ -150,7 +149,6 @@ void OpenVpnProtocol::updateRouteGateway(QString line)
|
|||
|
||||
ErrorCode OpenVpnProtocol::start()
|
||||
{
|
||||
#ifndef Q_OS_IOS
|
||||
//qDebug() << "Start OpenVPN connection";
|
||||
OpenVpnProtocol::stop();
|
||||
|
||||
|
|
@ -164,6 +162,27 @@ ErrorCode OpenVpnProtocol::start()
|
|||
return lastError();
|
||||
}
|
||||
|
||||
// Detect default gateway
|
||||
#ifdef Q_OS_MAC
|
||||
QProcess p;
|
||||
p.setProcessChannelMode(QProcess::MergedChannels);
|
||||
|
||||
p.start("route", QStringList() << "-n" << "get" << "default");
|
||||
p.waitForFinished();
|
||||
QString s = p.readAll();
|
||||
|
||||
QRegularExpression rx(R"(gateway:\s*(\d+\.\d+\.\d+\.\d+))");
|
||||
QRegularExpressionMatch match = rx.match(s);
|
||||
if (match.hasMatch()) {
|
||||
m_routeGateway = match.captured(1);
|
||||
qDebug() << "Set VPN route gateway" << m_routeGateway;
|
||||
}
|
||||
else {
|
||||
qWarning() << "Unable to set VPN route gateway, output:\n" << s;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// QString vpnLogFileNamePath = Utils::systemLogPath() + "/openvpn.log";
|
||||
// Utils::createEmptyFile(vpnLogFileNamePath);
|
||||
|
||||
|
|
@ -216,9 +235,6 @@ ErrorCode OpenVpnProtocol::start()
|
|||
//startTimeoutTimer();
|
||||
|
||||
return ErrorCode::NoError;
|
||||
#else
|
||||
return ErrorCode::NotImplementedError;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool OpenVpnProtocol::sendTermSignal()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue