WMI dependency removed, all available protocols checked
This commit is contained in:
parent
18654ca4ef
commit
8262d743d8
6 changed files with 87 additions and 95 deletions
|
|
@ -8,54 +8,12 @@
|
|||
|
||||
namespace adpinfo{
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//static bool is_string_equal(const std::string &lhs, const std::string &rhs){
|
||||
// if (lhs.find(rhs) != std::string::npos)
|
||||
// return true;
|
||||
// return false;
|
||||
//}
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// {false,""} - no error
|
||||
// {true,"descr"} - error with description
|
||||
using RET_TYPE = std::tuple<bool, std::string>;
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//class Adapter{
|
||||
//private:
|
||||
// std::string name{};
|
||||
// std::string descr{};
|
||||
// std::string current_ip_address_v4{};
|
||||
// std::string maskv4{};
|
||||
// std::vector<std::string> dns_address{};
|
||||
|
||||
//public:
|
||||
// explicit Adapter() = default;
|
||||
// ~Adapter() = default;
|
||||
|
||||
// void set_name(std::string_view);
|
||||
// std::string_view get_name()const;
|
||||
|
||||
// void set_description(std::string_view);
|
||||
// std::string_view get_description()const;
|
||||
|
||||
// void set_mac(std::string_view);
|
||||
// std::string_view get_mac()const;
|
||||
|
||||
//// bool operator==(const adapter& rhs) {
|
||||
//// if (!is_string_equal(name, rhs.name))
|
||||
//// return false;
|
||||
//// if (!is_string_equal(mac, rhs.mac))
|
||||
//// return false;
|
||||
//// if (dns_address != rhs.dns_address)
|
||||
//// return false;
|
||||
//// return true;
|
||||
//// }
|
||||
//}adapter;
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
/*
|
||||
* The object uses for collect the information about active network adapters/interfaces
|
||||
* QString m_routeGateway;
|
||||
QString m_vpnLocalAddress;
|
||||
QString m_vpnGateway;
|
||||
*/
|
||||
class NetAdpInfo final{
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
@ -90,12 +48,10 @@ public:
|
|||
explicit NetAdpInfo() = default;
|
||||
~NetAdpInfo() = default;
|
||||
|
||||
RET_TYPE get_adapter_infor(std::string_view );
|
||||
RET_TYPE get_adapter_info(std::string_view );
|
||||
std::string_view get_adapter_route_gateway()const;
|
||||
std::string_view get_adapter_local_address()const;
|
||||
std::string_view get_adapter_local_gateway()const;
|
||||
|
||||
//static std::string get_system_route();
|
||||
};
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ RET_TYPE NetAdpInfo::collect_adapters_data(){
|
|||
std::vector<BYTE> buffer{};
|
||||
IP_ADAPTER_INFO *adapter_info{nullptr};
|
||||
DWORD result{ERROR_BUFFER_OVERFLOW};
|
||||
ULONG buffer_len = sizeof(IP_ADAPTER_INFO) * 3;
|
||||
ULONG buffer_len = sizeof(IP_ADAPTER_INFO) * 10;
|
||||
while (result == ERROR_BUFFER_OVERFLOW){
|
||||
buffer.resize(buffer_len);
|
||||
adapter_info = reinterpret_cast<IP_ADAPTER_INFO*>(&buffer[0]);
|
||||
|
|
@ -141,7 +141,16 @@ RET_TYPE NetAdpInfo::collect_adapters_data(){
|
|||
_tmp->set_name(adapter_iterator->AdapterName);
|
||||
_tmp->set_description(adapter_iterator->Description);
|
||||
_tmp->set_local_address(adapter_iterator->IpAddressList.IpAddress.String);
|
||||
_tmp->set_local_gateway(adapter_iterator->GatewayList.IpAddress.String);
|
||||
std::string lgw = adapter_iterator->GatewayList.IpAddress.String;
|
||||
if (lgw.length() == 0 || lgw.find("0.0.0.0") != std::string::npos)
|
||||
{
|
||||
if (adapter_iterator->DhcpEnabled == 1)
|
||||
{
|
||||
lgw = adapter_iterator->DhcpServer.IpAddress.String;
|
||||
}
|
||||
}
|
||||
_tmp->set_local_gateway(lgw);
|
||||
//_tmp->set_local_gateway(adapter_iterator->GatewayList.IpAddress.String);
|
||||
_tmp->set_route_gateway(get_route_gateway());
|
||||
_adapters.emplace_back(_tmp);
|
||||
adapter_iterator = adapter_iterator->Next;
|
||||
|
|
@ -149,7 +158,7 @@ RET_TYPE NetAdpInfo::collect_adapters_data(){
|
|||
return {false, ""};
|
||||
}
|
||||
|
||||
RET_TYPE NetAdpInfo::get_adapter_infor(std::string_view _adapter_name){
|
||||
RET_TYPE NetAdpInfo::get_adapter_info(std::string_view _adapter_name){
|
||||
|
||||
_index_of_adapter = -1;
|
||||
const auto result{collect_adapters_data()};
|
||||
|
|
@ -161,6 +170,9 @@ RET_TYPE NetAdpInfo::get_adapter_infor(std::string_view _adapter_name){
|
|||
for (auto i = 0; i< len; ++i){
|
||||
auto adap_name = _adapters[i]->get_name();
|
||||
auto adap_desc = _adapters[i]->get_description();
|
||||
qDebug()<<"adap name : "<<QString::fromStdString(adap_name.data());
|
||||
qDebug()<<"adap description : "<<QString::fromStdString(adap_desc.data());
|
||||
qDebug()<<"find_string: "<<QString::fromStdString(_adapter_name.data());
|
||||
if (adap_name.find(_adapter_name) != std::string::npos || adap_desc.find(_adapter_name) != std::string::npos){
|
||||
_index_of_adapter = i;
|
||||
return {false, ""};
|
||||
|
|
|
|||
|
|
@ -11,10 +11,6 @@
|
|||
#include "ikev2_vpn_protocol.h"
|
||||
#include "utils.h"
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <iphlpapi.h>
|
||||
#endif
|
||||
|
||||
static Ikev2Protocol* self = nullptr;
|
||||
static std::mutex rasDialFuncMutex;
|
||||
|
||||
|
|
@ -25,14 +21,6 @@ static void WINAPI RasDialFuncCallback(UINT unMsg,
|
|||
DWORD dwError );
|
||||
}
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//QString m_routeGateway;
|
||||
//QString m_vpnLocalAddress;
|
||||
//QString m_vpnGateway;
|
||||
//static void get_connecting_status(std::string_view _vpn_name,
|
||||
// std::string &_m_route_gateway,
|
||||
// std::string & _m_vpn_local_address,
|
||||
// std::string &_m_vpn_gateway);
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Ikev2Protocol::Ikev2Protocol(const QJsonObject &configuration, QObject* parent) :
|
||||
VpnProtocol(configuration, parent)
|
||||
|
|
@ -184,15 +172,11 @@ void Ikev2Protocol::newConnectionStateEventReceived(UINT unMsg, tagRASCONNSTATE
|
|||
{
|
||||
//get the network settings of adapters
|
||||
std::string p1,p2,p3;
|
||||
const auto ret = adpInfo.get_adapter_infor(tunnelName().toStdString());
|
||||
const auto ret = adpInfo.get_adapter_info(tunnelName().toStdString());
|
||||
if (std::get<0>(ret) == false){
|
||||
p1 = adpInfo.get_adapter_route_gateway();
|
||||
p2 = adpInfo.get_adapter_local_address();
|
||||
p3 = adpInfo.get_adapter_local_gateway();
|
||||
// get_connecting_status(tunnelName().toStdString().c_str(),
|
||||
// p1,
|
||||
// p2,
|
||||
// p3);
|
||||
m_routeGateway = QString::fromStdString(p1);
|
||||
m_vpnLocalAddress = QString::fromStdString(p2);
|
||||
m_vpnGateway = QString::fromStdString(p3);
|
||||
|
|
@ -248,21 +232,21 @@ ErrorCode Ikev2Protocol::start()
|
|||
"-importpfx", certFile.fileName(), "NoExport"
|
||||
});
|
||||
certInstallProcess->setArguments(arguments);
|
||||
qDebug()<<m_config;
|
||||
qDebug() << arguments.join(" ");
|
||||
connect(certInstallProcess.data(), &PrivilegedProcess::errorOccurred, [certInstallProcess](QProcess::ProcessError error) {
|
||||
qDebug() << "PrivilegedProcess errorOccurred" << error;
|
||||
});
|
||||
|
||||
connect(certInstallProcess.data(), &PrivilegedProcess::stateChanged, [certInstallProcess](QProcess::ProcessState newState) {
|
||||
qDebug() << "PrivilegedProcess stateChanged" << newState;
|
||||
});
|
||||
// qDebug() << arguments.join(" ");
|
||||
// connect(certInstallProcess.data(), &PrivilegedProcess::errorOccurred, [certInstallProcess](QProcess::ProcessError error) {
|
||||
// qDebug() << "PrivilegedProcess errorOccurred" << error;
|
||||
// });
|
||||
|
||||
connect(certInstallProcess.data(), &PrivilegedProcess::readyRead, [certInstallProcess]() {
|
||||
auto req = certInstallProcess->readAll();
|
||||
req.waitForFinished();
|
||||
qDebug() << "PrivilegedProcess readyRead" << req.returnValue();
|
||||
});
|
||||
// connect(certInstallProcess.data(), &PrivilegedProcess::stateChanged, [certInstallProcess](QProcess::ProcessState newState) {
|
||||
// qDebug() << "PrivilegedProcess stateChanged" << newState;
|
||||
// });
|
||||
|
||||
// connect(certInstallProcess.data(), &PrivilegedProcess::readyRead, [certInstallProcess]() {
|
||||
// auto req = certInstallProcess->readAll();
|
||||
// req.waitForFinished();
|
||||
// qDebug() << "PrivilegedProcess readyRead" << req.returnValue();
|
||||
// });
|
||||
|
||||
|
||||
certInstallProcess->start();
|
||||
|
|
|
|||
|
|
@ -234,7 +234,6 @@ void OpenVpnProtocol::onReadyReadDataFromManagementServer()
|
|||
{
|
||||
for (;;) {
|
||||
QString line = m_managementServer.readLine().simplified();
|
||||
|
||||
if (line.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -247,6 +246,24 @@ void OpenVpnProtocol::onReadyReadDataFromManagementServer()
|
|||
sendInitialData();
|
||||
} else if (line.startsWith(">STATE")) {
|
||||
if (line.contains("CONNECTED,SUCCESS")) {
|
||||
{
|
||||
std::string p1,p2,p3;
|
||||
const auto &ret = adpInfo.get_adapter_info("TAP-Windows Adapter V9");
|
||||
if (std::get<0>(ret) == false){
|
||||
p1 = adpInfo.get_adapter_route_gateway();
|
||||
p2 = adpInfo.get_adapter_local_address();
|
||||
p3 = adpInfo.get_adapter_local_gateway();
|
||||
m_routeGateway = QString::fromStdString(p1);
|
||||
m_vpnLocalAddress = QString::fromStdString(p2);
|
||||
m_vpnGateway = QString::fromStdString(p3);
|
||||
qDebug()<<"My openvpn m_routeGateway "<<m_routeGateway;
|
||||
qDebug()<<"My openvpn m_vpnLocalAddress "<<m_vpnLocalAddress;
|
||||
qDebug()<<"My openvpn m_vpnGateway "<< m_vpnGateway;
|
||||
}
|
||||
else{
|
||||
qDebug()<<"We can't get information about active adapter:"<<QString::fromStdString(std::get<1>(ret));
|
||||
}
|
||||
}
|
||||
sendByteCount();
|
||||
stopTimeoutTimer();
|
||||
setConnectionState(VpnProtocol::Connected);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
#include "core/defs.h"
|
||||
#include "containers/containers_defs.h"
|
||||
|
||||
#include "3rd/AdpInfo/netadpinfo.h"
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
class QTimer;
|
||||
|
|
@ -69,6 +71,7 @@ protected:
|
|||
QString m_routeGateway;
|
||||
QString m_vpnLocalAddress;
|
||||
QString m_vpnGateway;
|
||||
adpinfo::NetAdpInfo adpInfo;
|
||||
|
||||
QJsonObject m_rawConfig;
|
||||
|
||||
|
|
|
|||
|
|
@ -185,8 +185,28 @@ ErrorCode WireguardProtocol::start()
|
|||
qDebug() << "WireguardProtocol::WireguardProtocol stateChanged" << newState;
|
||||
});
|
||||
|
||||
connect(m_wireguardStartProcess.data(), &PrivilegedProcess::finished, this, [this]() {
|
||||
connect(m_wireguardStartProcess.data(), &PrivilegedProcess::finished, this, [&]() {
|
||||
setConnectionState(ConnectionState::Connected);
|
||||
{
|
||||
//TODO:FIXME: without some ugly sleep we have't get a adapter parametrs
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
std::string p1,p2,p3;
|
||||
const auto &ret = adpInfo.get_adapter_info("WireGuard Tunnel");//serviceName().toStdString());//("AmneziaVPN IKEv2");
|
||||
if (std::get<0>(ret) == false){
|
||||
p1 = adpInfo.get_adapter_route_gateway();
|
||||
p2 = adpInfo.get_adapter_local_address();
|
||||
p3 = adpInfo.get_adapter_local_gateway();
|
||||
m_routeGateway = QString::fromStdString(p1);
|
||||
m_vpnLocalAddress = QString::fromStdString(p2);
|
||||
m_vpnGateway = QString::fromStdString(p3);
|
||||
qDebug()<<"My wireguard m_routeGateway "<<m_routeGateway;
|
||||
qDebug()<<"My wireguard m_vpnLocalAddress "<<m_vpnLocalAddress;
|
||||
qDebug()<<"My wireguard m_vpnGateway "<< m_vpnGateway;
|
||||
}
|
||||
else{
|
||||
qDebug()<<"We can't get information about active adapter:"<<QString::fromStdString(std::get<1>(ret));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
connect(m_wireguardStartProcess.data(), &PrivilegedProcess::readyRead, this, [this]() {
|
||||
|
|
@ -220,19 +240,19 @@ ErrorCode WireguardProtocol::start()
|
|||
|
||||
void WireguardProtocol::updateVpnGateway(const QString &line)
|
||||
{
|
||||
// // line looks like
|
||||
// // PUSH: Received control message: 'PUSH_REPLY,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5,peer-id 0,cipher AES-256-GCM'
|
||||
// // line looks like
|
||||
// // PUSH: Received control message: 'PUSH_REPLY,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5,peer-id 0,cipher AES-256-GCM'
|
||||
|
||||
// QStringList params = line.split(",");
|
||||
// for (const QString &l : params) {
|
||||
// if (l.contains("ifconfig")) {
|
||||
// if (l.split(" ").size() == 3) {
|
||||
// m_vpnLocalAddress = l.split(" ").at(1);
|
||||
// m_vpnGateway = l.split(" ").at(2);
|
||||
// QStringList params = line.split(",");
|
||||
// for (const QString &l : params) {
|
||||
// if (l.contains("ifconfig")) {
|
||||
// if (l.split(" ").size() == 3) {
|
||||
// m_vpnLocalAddress = l.split(" ").at(1);
|
||||
// m_vpnGateway = l.split(" ").at(2);
|
||||
|
||||
// qDebug() << QString("Set vpn local address %1, gw %2").arg(m_vpnLocalAddress).arg(vpnGateway());
|
||||
// }
|
||||
// }
|
||||
// qDebug() << QString("Set vpn local address %1, gw %2").arg(m_vpnLocalAddress).arg(vpnGateway());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue