Custom routing fixes
This commit is contained in:
parent
c4235a60c8
commit
dd959e7b26
8 changed files with 42 additions and 42 deletions
|
|
@ -32,6 +32,6 @@ QString ShadowSocksConfigurator::genShadowSocksConfig(const ServerCredentials &c
|
||||||
QString textCfg = ServerController::replaceVars(QJsonDocument(config).toJson(),
|
QString textCfg = ServerController::replaceVars(QJsonDocument(config).toJson(),
|
||||||
ServerController::genVarsForScript(credentials, container, containerConfig));
|
ServerController::genVarsForScript(credentials, container, containerConfig));
|
||||||
|
|
||||||
qDebug().noquote() << textCfg;
|
//qDebug().noquote() << textCfg;
|
||||||
return textCfg;
|
return textCfg;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
#define APPLICATION_NAME "AmneziaVPN"
|
#define APPLICATION_NAME "AmneziaVPN"
|
||||||
#define SERVICE_NAME "AmneziaVPN-service"
|
#define SERVICE_NAME "AmneziaVPN-service"
|
||||||
#define ORGANIZATION_NAME "AmneziaVPN.ORG"
|
#define ORGANIZATION_NAME "AmneziaVPN.ORG"
|
||||||
#define APP_MAJOR_VERSION "1.7.3"
|
#define APP_MAJOR_VERSION "1.7.4"
|
||||||
#define APP_VERSION "1.7.3.0"
|
#define APP_VERSION "1.7.4.0"
|
||||||
|
|
||||||
#endif // DEFINES_H
|
#endif // DEFINES_H
|
||||||
|
|
|
||||||
|
|
@ -225,15 +225,6 @@ void Settings::addVpnSite(RouteMode mode, const QString &site, const QString &ip
|
||||||
|
|
||||||
sites.insert(site, ip);
|
sites.insert(site, ip);
|
||||||
setVpnSites(mode, sites);
|
setVpnSites(mode, sites);
|
||||||
|
|
||||||
// QStringList l = sites.value(site).toStringList();
|
|
||||||
// if (!l.contains(ip)) {
|
|
||||||
// if (!ip.isEmpty()) l.append(ip);
|
|
||||||
// //l.append(ip);
|
|
||||||
// sites.insert(site, l);
|
|
||||||
// setVpnSites(mode, sites);
|
|
||||||
// qDebug() << "sites after" << vpnSites(mode);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Settings::getVpnIps(RouteMode mode) const
|
QStringList Settings::getVpnIps(RouteMode mode) const
|
||||||
|
|
@ -241,10 +232,10 @@ QStringList Settings::getVpnIps(RouteMode mode) const
|
||||||
QStringList ips;
|
QStringList ips;
|
||||||
const QVariantMap &m = vpnSites(mode);
|
const QVariantMap &m = vpnSites(mode);
|
||||||
for (auto i = m.constBegin(); i != m.constEnd(); ++i) {
|
for (auto i = m.constBegin(); i != m.constEnd(); ++i) {
|
||||||
if (Utils::checkIPFormat(i.key())) {
|
if (Utils::checkIpSubnetFormat(i.key())) {
|
||||||
ips.append(i.key());
|
ips.append(i.key());
|
||||||
}
|
}
|
||||||
else if (Utils::checkIPFormat(i.value().toString())) {
|
else if (Utils::checkIpSubnetFormat(i.value().toString())) {
|
||||||
ips.append(i.value().toString());
|
ips.append(i.value().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1143,14 +1143,18 @@ void MainWindow::setupSitesPageConnections()
|
||||||
m_settings.removeVpnSites(mode, sites);
|
m_settings.removeVpnSites(mode, sites);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (m_vpnConnection->connectionState() == VpnProtocol::Connected) {
|
if (m_vpnConnection->connectionState() == VpnProtocol::Connected) {
|
||||||
QModelIndexList indexesIps = selection->selectedRows(1);
|
QModelIndexList indexesIps = selection->selectedRows(1);
|
||||||
|
|
||||||
QStringList ips;
|
QStringList ips;
|
||||||
for (const QModelIndex &index : indexesIps) {
|
for (const QModelIndex &index : indexesIps) {
|
||||||
|
if (index.data().toString().isEmpty()) {
|
||||||
|
ips.append(index.sibling(index.row(), 0).data().toString());
|
||||||
|
}
|
||||||
|
else {
|
||||||
ips.append(index.data().toString());
|
ips.append(index.data().toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_vpnConnection->deleteRoutes(ips);
|
m_vpnConnection->deleteRoutes(ips);
|
||||||
m_vpnConnection->flushDns();
|
m_vpnConnection->flushDns();
|
||||||
|
|
@ -1816,15 +1820,13 @@ void MainWindow::onPushButtonAddCustomSitesClicked()
|
||||||
newSite = newSite.split("/", QString::SkipEmptyParts).first();
|
newSite = newSite.split("/", QString::SkipEmptyParts).first();
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Adding site" << newSite;
|
|
||||||
|
|
||||||
//qDebug() << "sites:" << m_settings.vpnSites(mode);
|
|
||||||
|
|
||||||
const auto &cbProcess = [this, mode](const QString &newSite, const QString &ip) {
|
const auto &cbProcess = [this, mode](const QString &newSite, const QString &ip) {
|
||||||
m_settings.addVpnSite(mode, newSite, ip);
|
m_settings.addVpnSite(mode, newSite, ip);
|
||||||
|
|
||||||
|
if (!ip.isEmpty()) {
|
||||||
m_vpnConnection->addRoutes(QStringList() << ip);
|
m_vpnConnection->addRoutes(QStringList() << ip);
|
||||||
m_vpnConnection->flushDns();
|
m_vpnConnection->flushDns();
|
||||||
|
}
|
||||||
|
|
||||||
updateSitesPage();
|
updateSitesPage();
|
||||||
};
|
};
|
||||||
|
|
@ -1843,7 +1845,7 @@ void MainWindow::onPushButtonAddCustomSitesClicked()
|
||||||
ui->lineEdit_sites_add_custom->clear();
|
ui->lineEdit_sites_add_custom->clear();
|
||||||
|
|
||||||
if (Utils::ipAddressWithSubnetRegExp().exactMatch(newSite)) {
|
if (Utils::ipAddressWithSubnetRegExp().exactMatch(newSite)) {
|
||||||
cbProcess(newSite, newSite);
|
cbProcess(newSite, "");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -139,30 +139,26 @@ QString Utils::getStringBetween(const QString& s, const QString& a, const QStrin
|
||||||
return s.mid(ap, bp - ap).trimmed();
|
return s.mid(ap, bp - ap).trimmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Utils::checkIPFormat(const QString& ip)
|
bool Utils::checkIPv4Format(const QString& ip)
|
||||||
{
|
{
|
||||||
|
if (ip.isEmpty()) return false;
|
||||||
int count = ip.count(".");
|
int count = ip.count(".");
|
||||||
if(count != 3)
|
if(count != 3) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
QStringList list = ip.trimmed().split(".");
|
QHostAddress addr(ip);
|
||||||
for (const QString &it : list) {
|
return (addr.protocol() == QAbstractSocket::NetworkLayerProtocol::IPv4Protocol);
|
||||||
if(it.toInt() <= 255 && it.toInt() >= 0)
|
|
||||||
continue;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Utils::checkIpSubnetFormat(const QString &ip)
|
bool Utils::checkIpSubnetFormat(const QString &ip)
|
||||||
{
|
{
|
||||||
if (!ip.contains("/")) return checkIPFormat(ip);
|
if (!ip.contains("/")) return checkIPv4Format(ip);
|
||||||
|
|
||||||
QStringList parts = ip.split("/");
|
QStringList parts = ip.split("/");
|
||||||
if (parts.size() != 2) return false;
|
if (parts.size() != 2) return false;
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
if (parts.at(1).toInt(&ok) <= 32 && ok) return checkIPFormat(parts.at(0));
|
int subnet = parts.at(1).toInt(&ok);
|
||||||
|
if (subnet >= 0 && subnet <= 32 && ok) return checkIPv4Format(parts.at(0));
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ public:
|
||||||
|
|
||||||
static QString getIPAddress(const QString& host);
|
static QString getIPAddress(const QString& host);
|
||||||
static QString getStringBetween(const QString& s, const QString& a, const QString& b);
|
static QString getStringBetween(const QString& s, const QString& a, const QString& b);
|
||||||
static bool checkIPFormat(const QString& ip);
|
static bool checkIPv4Format(const QString& ip);
|
||||||
static bool checkIpSubnetFormat(const QString& ip);
|
static bool checkIpSubnetFormat(const QString& ip);
|
||||||
static QRegExp ipAddressRegExp() { return QRegExp("^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\\.(?!$)|$)){4}$"); }
|
static QRegExp ipAddressRegExp() { return QRegExp("^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\\.(?!$)|$)){4}$"); }
|
||||||
static QRegExp ipAddressPortRegExp() { return QRegExp("^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}"
|
static QRegExp ipAddressPortRegExp() { return QRegExp("^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}"
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ bool RouterMac::routeAdd(const QString &ipWithSubnet, const QString &gw)
|
||||||
QString ip = Utils::ipAddressFromIpWithSubnet(ipWithSubnet);
|
QString ip = Utils::ipAddressFromIpWithSubnet(ipWithSubnet);
|
||||||
QString mask = Utils::netMaskFromIpWithSubnet(ipWithSubnet);
|
QString mask = Utils::netMaskFromIpWithSubnet(ipWithSubnet);
|
||||||
|
|
||||||
if (!Utils::checkIPFormat(ip) || !Utils::checkIPFormat(gw)) {
|
if (!Utils::checkIPv4Format(ip) || !Utils::checkIPv4Format(gw)) {
|
||||||
qCritical().noquote() << "Critical, trying to add invalid route: " << ip << gw;
|
qCritical().noquote() << "Critical, trying to add invalid route: " << ip << gw;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -74,7 +74,7 @@ bool RouterMac::routeDelete(const QString &ipWithSubnet, const QString &gw)
|
||||||
QString ip = Utils::ipAddressFromIpWithSubnet(ipWithSubnet);
|
QString ip = Utils::ipAddressFromIpWithSubnet(ipWithSubnet);
|
||||||
QString mask = Utils::netMaskFromIpWithSubnet(ipWithSubnet);
|
QString mask = Utils::netMaskFromIpWithSubnet(ipWithSubnet);
|
||||||
|
|
||||||
if (!Utils::checkIPFormat(ip) || !Utils::checkIPFormat(gw)) {
|
if (!Utils::checkIPv4Format(ip) || !Utils::checkIPv4Format(gw)) {
|
||||||
qCritical().noquote() << "Critical, trying to remove invalid route: " << ip << gw;
|
qCritical().noquote() << "Critical, trying to remove invalid route: " << ip << gw;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,11 @@ int RouterWin::routeAddList(const QString &gw, const QStringList &ips)
|
||||||
// .arg(ips.join("\n"));
|
// .arg(ips.join("\n"));
|
||||||
|
|
||||||
|
|
||||||
|
if (!Utils::checkIPv4Format(gw)) {
|
||||||
|
qCritical().noquote() << "Trying to add invalid route, gw: " << gw;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
PMIB_IPFORWARDTABLE pIpForwardTable = NULL;
|
PMIB_IPFORWARDTABLE pIpForwardTable = NULL;
|
||||||
DWORD dwSize = 0;
|
DWORD dwSize = 0;
|
||||||
BOOL bOrder = FALSE;
|
BOOL bOrder = FALSE;
|
||||||
|
|
@ -99,12 +104,18 @@ int RouterWin::routeAddList(const QString &gw, const QStringList &ips)
|
||||||
ipfrow.dwForwardMetric5 = 0;
|
ipfrow.dwForwardMetric5 = 0;
|
||||||
|
|
||||||
for (int i = 0; i < ips.size(); ++i) {
|
for (int i = 0; i < ips.size(); ++i) {
|
||||||
QString ip = ips.at(i);
|
QString ipWithMask = ips.at(i);
|
||||||
if (ip.isEmpty()) continue;
|
QString ip = Utils::ipAddressFromIpWithSubnet(ipWithMask);
|
||||||
|
|
||||||
|
if (!Utils::checkIPv4Format(ip)) {
|
||||||
|
qCritical().noquote() << "Critical, trying to add invalid route, ip: " << ip;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
QString mask = Utils::netMaskFromIpWithSubnet(ip);
|
QString mask = Utils::netMaskFromIpWithSubnet(ip);
|
||||||
|
|
||||||
// address
|
// address
|
||||||
ipfrow.dwForwardDest = inet_addr(Utils::ipAddressFromIpWithSubnet(ip).toStdString().c_str());
|
ipfrow.dwForwardDest = inet_addr(ip.toStdString().c_str());
|
||||||
|
|
||||||
// mask
|
// mask
|
||||||
in_addr maskAddr;
|
in_addr maskAddr;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue