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(),
|
||||
ServerController::genVarsForScript(credentials, container, containerConfig));
|
||||
|
||||
qDebug().noquote() << textCfg;
|
||||
//qDebug().noquote() << textCfg;
|
||||
return textCfg;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#define APPLICATION_NAME "AmneziaVPN"
|
||||
#define SERVICE_NAME "AmneziaVPN-service"
|
||||
#define ORGANIZATION_NAME "AmneziaVPN.ORG"
|
||||
#define APP_MAJOR_VERSION "1.7.3"
|
||||
#define APP_VERSION "1.7.3.0"
|
||||
#define APP_MAJOR_VERSION "1.7.4"
|
||||
#define APP_VERSION "1.7.4.0"
|
||||
|
||||
#endif // DEFINES_H
|
||||
|
|
|
|||
|
|
@ -225,15 +225,6 @@ void Settings::addVpnSite(RouteMode mode, const QString &site, const QString &ip
|
|||
|
||||
sites.insert(site, ip);
|
||||
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
|
||||
|
|
@ -241,10 +232,10 @@ QStringList Settings::getVpnIps(RouteMode mode) const
|
|||
QStringList ips;
|
||||
const QVariantMap &m = vpnSites(mode);
|
||||
for (auto i = m.constBegin(); i != m.constEnd(); ++i) {
|
||||
if (Utils::checkIPFormat(i.key())) {
|
||||
if (Utils::checkIpSubnetFormat(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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1143,13 +1143,17 @@ void MainWindow::setupSitesPageConnections()
|
|||
m_settings.removeVpnSites(mode, sites);
|
||||
}
|
||||
|
||||
|
||||
if (m_vpnConnection->connectionState() == VpnProtocol::Connected) {
|
||||
QModelIndexList indexesIps = selection->selectedRows(1);
|
||||
|
||||
QStringList ips;
|
||||
for (const QModelIndex &index : indexesIps) {
|
||||
ips.append(index.data().toString());
|
||||
if (index.data().toString().isEmpty()) {
|
||||
ips.append(index.sibling(index.row(), 0).data().toString());
|
||||
}
|
||||
else {
|
||||
ips.append(index.data().toString());
|
||||
}
|
||||
}
|
||||
|
||||
m_vpnConnection->deleteRoutes(ips);
|
||||
|
|
@ -1816,15 +1820,13 @@ void MainWindow::onPushButtonAddCustomSitesClicked()
|
|||
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) {
|
||||
m_settings.addVpnSite(mode, newSite, ip);
|
||||
|
||||
m_vpnConnection->addRoutes(QStringList() << ip);
|
||||
m_vpnConnection->flushDns();
|
||||
if (!ip.isEmpty()) {
|
||||
m_vpnConnection->addRoutes(QStringList() << ip);
|
||||
m_vpnConnection->flushDns();
|
||||
}
|
||||
|
||||
updateSitesPage();
|
||||
};
|
||||
|
|
@ -1834,7 +1836,7 @@ void MainWindow::onPushButtonAddCustomSitesClicked()
|
|||
QString ipv4Addr;
|
||||
for (const QHostAddress &addr: hostInfo.addresses()) {
|
||||
if (addr.protocol() == QAbstractSocket::NetworkLayerProtocol::IPv4Protocol) {
|
||||
cbProcess(hostInfo.hostName(),addr.toString());
|
||||
cbProcess(hostInfo.hostName(), addr.toString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -1843,7 +1845,7 @@ void MainWindow::onPushButtonAddCustomSitesClicked()
|
|||
ui->lineEdit_sites_add_custom->clear();
|
||||
|
||||
if (Utils::ipAddressWithSubnetRegExp().exactMatch(newSite)) {
|
||||
cbProcess(newSite, newSite);
|
||||
cbProcess(newSite, "");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -139,30 +139,26 @@ QString Utils::getStringBetween(const QString& s, const QString& a, const QStrin
|
|||
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(".");
|
||||
if(count != 3)
|
||||
return false;
|
||||
if(count != 3) return false;
|
||||
|
||||
QStringList list = ip.trimmed().split(".");
|
||||
for (const QString &it : list) {
|
||||
if(it.toInt() <= 255 && it.toInt() >= 0)
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
QHostAddress addr(ip);
|
||||
return (addr.protocol() == QAbstractSocket::NetworkLayerProtocol::IPv4Protocol);
|
||||
}
|
||||
|
||||
bool Utils::checkIpSubnetFormat(const QString &ip)
|
||||
{
|
||||
if (!ip.contains("/")) return checkIPFormat(ip);
|
||||
if (!ip.contains("/")) return checkIPv4Format(ip);
|
||||
|
||||
QStringList parts = ip.split("/");
|
||||
if (parts.size() != 2) return false;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public:
|
|||
|
||||
static QString getIPAddress(const QString& host);
|
||||
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 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}"
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ bool RouterMac::routeAdd(const QString &ipWithSubnet, const QString &gw)
|
|||
QString ip = Utils::ipAddressFromIpWithSubnet(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;
|
||||
return false;
|
||||
}
|
||||
|
|
@ -74,7 +74,7 @@ bool RouterMac::routeDelete(const QString &ipWithSubnet, const QString &gw)
|
|||
QString ip = Utils::ipAddressFromIpWithSubnet(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;
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,11 @@ int RouterWin::routeAddList(const QString &gw, const QStringList &ips)
|
|||
// .arg(ips.join("\n"));
|
||||
|
||||
|
||||
if (!Utils::checkIPv4Format(gw)) {
|
||||
qCritical().noquote() << "Trying to add invalid route, gw: " << gw;
|
||||
return 0;
|
||||
}
|
||||
|
||||
PMIB_IPFORWARDTABLE pIpForwardTable = NULL;
|
||||
DWORD dwSize = 0;
|
||||
BOOL bOrder = FALSE;
|
||||
|
|
@ -99,12 +104,18 @@ int RouterWin::routeAddList(const QString &gw, const QStringList &ips)
|
|||
ipfrow.dwForwardMetric5 = 0;
|
||||
|
||||
for (int i = 0; i < ips.size(); ++i) {
|
||||
QString ip = ips.at(i);
|
||||
if (ip.isEmpty()) continue;
|
||||
QString ipWithMask = ips.at(i);
|
||||
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);
|
||||
|
||||
// address
|
||||
ipfrow.dwForwardDest = inet_addr(Utils::ipAddressFromIpWithSubnet(ip).toStdString().c_str());
|
||||
ipfrow.dwForwardDest = inet_addr(ip.toStdString().c_str());
|
||||
|
||||
// mask
|
||||
in_addr maskAddr;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue