From dbbd42b2f381f1adf9f2933d8942c175d27accbe Mon Sep 17 00:00:00 2001 From: "Leroy.H.Y" Date: Tue, 29 Oct 2019 17:07:20 +0800 Subject: [PATCH] [add] Partly added routing edit 2 Former-commit-id: 736e3ac9ccb8598b2dae24e3cb4f98b1302925e9 --- Build.Counter | 2 +- src/QvCoreConfigObjects.h | 8 +- src/QvCoreConfigOperations.h | 1 + src/QvCoreConfigOperations_Generation.cpp | 20 +- src/QvUtils.cpp | 29 + src/QvUtils.h | 4 + src/ui/w_InboundEditor.cpp | 13 +- src/ui/w_PrefrencesWindow.cpp | 3 - src/ui/w_RoutesEditor.cpp | 326 +++++++-- src/ui/w_RoutesEditor.h | 21 +- src/ui/w_RoutesEditor.ui | 816 +++++++++++----------- 11 files changed, 778 insertions(+), 465 deletions(-) diff --git a/Build.Counter b/Build.Counter index fe4afb0d..878d5a02 100644 --- a/Build.Counter +++ b/Build.Counter @@ -1 +1 @@ -106 +146 diff --git a/src/QvCoreConfigObjects.h b/src/QvCoreConfigObjects.h index b0a45030..e2ff692f 100644 --- a/src/QvCoreConfigObjects.h +++ b/src/QvCoreConfigObjects.h @@ -61,8 +61,8 @@ namespace Qv2ray // // struct RuleObject { - // Added due to @aliyuchang33 - bool enabled; + // Added due to the request of @aliyuchang33 + bool QV2RAY_RULE_ENABLED; // string type; list domain; @@ -76,8 +76,8 @@ namespace Qv2ray string attrs; string outboundTag; string balancerTag; - RuleObject() : enabled(true), type("field"), domain(), ip(), port(), network(), source(), user(), inboundTag(), protocol(), attrs(), outboundTag(), balancerTag() {} - XTOSTRUCT(O(enabled, type, domain, ip, port, network, source, user, inboundTag, protocol, attrs, outboundTag, balancerTag)) + RuleObject() : QV2RAY_RULE_ENABLED(true), type("field"), domain(), ip(), port(""), network(""), source(), user(), inboundTag(), protocol(), attrs(), outboundTag(""), balancerTag("") {} + XTOSTRUCT(O(QV2RAY_RULE_ENABLED, type, domain, ip, port, network, source, user, inboundTag, protocol, attrs, outboundTag, balancerTag)) }; // // diff --git a/src/QvCoreConfigOperations.h b/src/QvCoreConfigOperations.h index 2059dc05..039ce3f9 100644 --- a/src/QvCoreConfigOperations.h +++ b/src/QvCoreConfigOperations.h @@ -43,6 +43,7 @@ namespace Qv2ray QJsonDocument doc = QJsonDocument::fromJson(QByteArray::fromStdString(json.toStdString())); return doc.object(); } + template QJsonObject GetRootObject(RuleObject t); template QJsonObject GetRootObject(StreamSettingsObject t); template QJsonObject GetRootObject(VMessServerObject t); // diff --git a/src/QvCoreConfigOperations_Generation.cpp b/src/QvCoreConfigOperations_Generation.cpp index 34568537..3d5905b8 100644 --- a/src/QvCoreConfigOperations_Generation.cpp +++ b/src/QvCoreConfigOperations_Generation.cpp @@ -246,8 +246,24 @@ namespace Qv2ray } else { // For some config files that has routing entries already. // We don't add extra routings. - // this part has been left blanking - LOG(MODULE_CONNECTION, "Skip adding 'freedom' entry.") + // + // HOWEVER, we need to verify the QV2RAY_RULE_ENABLED entry. + QJsonObject routing = root["routing"].toObject(); + QJsonArray rules; + LOG(MODULE_CONNECTION, "Processing an existing routing table.") + + for (auto _a : routing["rules"].toArray()) { + auto _b = _a.toObject(); + + if (_b.contains("QV2RAY_RULE_ENABLED") && _b["QV2RAY_RULE_ENABLED"].toBool() == true) { + rules.append(_b); + } else { + LOG(MODULE_CONFIG, "Discarded a rule as it's been set DISABLED") + } + } + + routing["rules"] = rules; + root["routing"] = routing; } // Let's process some api features. diff --git a/src/QvUtils.cpp b/src/QvUtils.cpp index 78393cc6..dbc72faf 100644 --- a/src/QvUtils.cpp +++ b/src/QvUtils.cpp @@ -15,6 +15,20 @@ namespace Qv2ray StringToFile(&str, &config); } + const QString GenerateRandomString(int len) + { + const QString possibleCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); + QString randomString; + + for (int i = 0; i < len; ++i) { + int index = qrand() % possibleCharacters.length(); + QChar nextChar = possibleCharacters.at(index); + randomString.append(nextChar); + } + + return randomString; + } + Qv2rayConfig GetGlobalConfig() { return GlobalConfig; @@ -138,6 +152,21 @@ namespace Qv2ray return QString(QByteArray::fromBase64(ba)); } + QStringList SplitLines(const QString &_string) + { + return _string.split(QRegExp("[\r\n]"), QString::SkipEmptyParts); + } + + QList SplitLinesStdString(const QString &_string) + { + QList list; + + for (auto line : _string.split(QRegExp("[\r\n]"), QString::SkipEmptyParts)) { + list.append(line.toStdString()); + } + + return list; + } void LoadGlobalConfig() { QFile file(QV2RAY_CONFIG_FILE); diff --git a/src/QvUtils.h b/src/QvUtils.h index e6c15a2d..b9d164b7 100644 --- a/src/QvUtils.h +++ b/src/QvUtils.h @@ -15,9 +15,13 @@ namespace Qv2ray QString Base64Encode(QString string); QString Base64Decode(QString string); + QStringList SplitLines(const QString &str); + QList SplitLinesStdString(const QString &_string); bool CheckFile(QDir dir, QString fileName); + const QString GenerateRandomString(int len = 12); + void SetConfigDirPath(const QString *path); QString GetConfigDirPath(); diff --git a/src/ui/w_InboundEditor.cpp b/src/ui/w_InboundEditor.cpp index 841dea74..4985020b 100644 --- a/src/ui/w_InboundEditor.cpp +++ b/src/ui/w_InboundEditor.cpp @@ -8,9 +8,10 @@ static bool isLoading = false; InboundEditor::InboundEditor(QJsonObject root, QWidget *parent) : QDialog(parent), - ui(new Ui::InboundEditor) + ui(new Ui::InboundEditor), + original(root) { - original = root; + ui->setupUi(this); this->root = root; auto inboundType = root["protocol"].toString(); allocate = root["allocate"].toObject(); @@ -30,7 +31,6 @@ InboundEditor::InboundEditor(QJsonObject root, QWidget *parent) : tr("Inbound: ") + inboundType); } - ui->setupUi(this); LoadUIData(); } @@ -67,8 +67,10 @@ void InboundEditor::LoadUIData() ui->refreshNumberBox->setValue(allocate["refresh"].toInt()); ui->concurrencyNumberBox->setValue(allocate["concurrency"].toInt()); ui->enableSniffingCB->setChecked(sniffing["enabled"].toBool()); + // + ui->destOverrideList->setEnabled(sniffing["enabled"].toBool()); - foreach (auto item, sniffing["destOverride"].toArray()) { + for (auto item : sniffing["destOverride"].toArray()) { if (item.toString().toLower() == "http") ui->destOverrideList->item(0)->setCheckState(Qt::Checked); if (item.toString().toLower() == "tls") ui->destOverrideList->item(1)->setCheckState(Qt::Checked); @@ -281,6 +283,7 @@ void InboundEditor::on_enableSniffingCB_stateChanged(int arg1) { PREPARE_RETURN sniffing["enabled"] = arg1 == Qt::Checked; + ui->destOverrideList->setEnabled(arg1 == Qt::Checked); } void InboundEditor::on_destOverrideList_itemChanged(QListWidgetItem *item) @@ -292,7 +295,7 @@ void InboundEditor::on_destOverrideList_itemChanged(QListWidgetItem *item) for (int i = 0; i < ui->destOverrideList->count(); i++) { auto _item = ui->destOverrideList->item(i); - if (item->checkState() == Qt::Checked) { + if (_item->checkState() == Qt::Checked) { list.append(_item->text().toLower()); } } diff --git a/src/ui/w_PrefrencesWindow.cpp b/src/ui/w_PrefrencesWindow.cpp index bbdd4a46..640c7821 100644 --- a/src/ui/w_PrefrencesWindow.cpp +++ b/src/ui/w_PrefrencesWindow.cpp @@ -491,7 +491,6 @@ void PrefrencesWindow::on_nsBarLineAddBTN_clicked() ui->nsBarLineDelBTN->setEnabled(true); LOG(MODULE_UI, "Adding new line Id: " + to_string(CurrentBarLineId)) ui->nsBarLinesList->setCurrentRow(static_cast(CurrentBarPage.Lines.size() - 1)); - // TODO Some UI Works such as enabling ui. } void PrefrencesWindow::on_nsBarLineDelBTN_clicked() @@ -608,14 +607,12 @@ QString PrefrencesWindow::GetBarLineDescription(QvBarLine line) QString result = "Empty"; result = NetSpeedPluginMessages[line.ContentType]; - // BUG Content type is null, then set empty; if (line.ContentType == 0) { result += " (" + QSTRING(line.Message) + ")"; } result = result.append(line.Bold ? ", " + tr("Bold") : ""); result = result.append(line.Italic ? ", " + tr("Italic") : ""); - // TODO : Set more descriptions return result; } diff --git a/src/ui/w_RoutesEditor.cpp b/src/ui/w_RoutesEditor.cpp index a99ee7a1..a495fbfb 100644 --- a/src/ui/w_RoutesEditor.cpp +++ b/src/ui/w_RoutesEditor.cpp @@ -11,6 +11,7 @@ RouteEditor::RouteEditor(QJsonObject connection, QWidget *parent) : QDialog(parent), root(connection), + original(connection), ui(new Ui::RouteEditor) { ui->setupUi(this); @@ -19,6 +20,7 @@ RouteEditor::RouteEditor(QJsonObject connection, QWidget *parent) : outbounds = root["outbounds"].toArray(); DomainStrategy = root["routing"].toObject()["domainStrategy"].toString(); + // Applying Balancers. for (auto _balancer : root["routing"].toObject()["balancers"].toArray()) { auto __balancer = _balancer.toObject(); Balancers[__balancer["tag"].toString()] = QList(); @@ -54,40 +56,83 @@ RouteEditor::RouteEditor(QJsonObject connection, QWidget *parent) : ui->inboundsList->addItem(inItem); } - for (auto route : rules) { + ui->routesTable->clearContents(); + + for (int i = 0; i < rules.size(); i++) { +#define rule rules[i] + // Set up balancers. + + if (QSTRING(rule.balancerTag).isEmpty()) { + // Default balancer tag. + auto bTag = GenerateRandomString(); + rule.balancerTag = bTag.toStdString(); + Balancers[bTag] = QStringList(); + } + + // ui->routesTable->insertRow(ui->routesTable->rowCount()); - // There will be an additional check on the final configuration generation process. + // + // WARNING There should be an additional check on the final configuration generation process. auto enabledItem = new QTableWidgetItem(tr("Enabled")); - enabledItem->setCheckState(route.enabled ? Qt::Checked : Qt::Unchecked); + enabledItem->setCheckState(rule.QV2RAY_RULE_ENABLED ? Qt::Checked : Qt::Unchecked); ui->routesTable->setItem(ui->routesTable->rowCount() - 1, 0, enabledItem); - ui->routesTable->setItem(ui->routesTable->rowCount() - 1, 1, new QTableWidgetItem(route.inboundTag.size() > 0 ? Stringify(route.inboundTag) : tr("Any"))); - ui->routesTable->setItem(ui->routesTable->rowCount() - 1, 2, new QTableWidgetItem(QString::number(route.domain.size() + route.ip.size()) + " " + tr("Items"))); - ui->routesTable->setItem(ui->routesTable->rowCount() - 1, 3, new QTableWidgetItem(QSTRING(route.outboundTag))); + // + ui->routesTable->setItem(ui->routesTable->rowCount() - 1, 1, new QTableWidgetItem(rule.inboundTag.size() > 0 ? Stringify(rule.inboundTag) : tr("Any"))); + ui->routesTable->setItem(ui->routesTable->rowCount() - 1, 2, new QTableWidgetItem(QString::number(rule.domain.size() + rule.ip.size()) + " " + tr("Items"))); + ui->routesTable->setItem(ui->routesTable->rowCount() - 1, 3, new QTableWidgetItem(QSTRING(rule.outboundTag))); +#undef rule + } + + if (rules.size() > 0) { + ui->routesTable->setCurrentItem(ui->routesTable->item(0, 0)); + currentRuleIndex = 0; + ShowRuleDetail(CurrentRule); + } else { + ui->delRouteBtn->setEnabled(false); + + if (ui->inboundsList->count() > 0) ui->inboundsList->setCurrentRow(0); + + if (ui->outboundsList->count() > 0) ui->outboundsList->setCurrentRow(0); } } QJsonObject RouteEditor::OpenEditor() { - this->exec(); - QJsonArray balancers; + auto result = this->exec(); - for (auto item : Balancers) { - QJsonObject balancerEntry; - balancerEntry["tag"] = Balancers.key(item); - balancerEntry["selector"] = QJsonArray::fromStringList(item); - balancers.append(balancerEntry); + if (result == QDialog::Accepted) { + QJsonArray balancers; + + for (auto item : Balancers) { + QJsonObject balancerEntry; + auto key = Balancers.key(item); + + if (!key.isEmpty()) { + balancerEntry["tag"] = key; + balancerEntry["selector"] = QJsonArray::fromStringList(item); + balancers.append(balancerEntry); + } + } + + // + QJsonArray rulesArray; + + for (auto _rule : rules) { + rulesArray.append(GetRootObject(_rule)); + } + + QJsonObject routing; + routing["domainStrategy"] = DomainStrategy; + routing["rules"] = rulesArray; + routing["balancers"] = balancers; + // + root["inbounds"] = inbounds; + root["outbounds"] = outbounds; + root["routing"] = routing; + return root; + } else { + return original; } - - // - QJsonObject routing; - routing["domainStrategy"] = DomainStrategy; - routing["rules"] = GetRootObject(rules.toStdList()); - routing["balancers"] = balancers; - // - root["inbounds"] = inbounds; - root["outbounds"] = outbounds; - root["routing"] = routing; - return root; } RouteEditor::~RouteEditor() @@ -149,38 +194,48 @@ void RouteEditor::ShowRuleDetail(RuleObject rule) int index = FindIndexByTag(outbounds, &outboundTag); ui->outboundsList->setCurrentRow(index); // - auto protocols = QList::fromStdList(CurrentRule.protocol); + auto network = QSTRING(rule.network).toLower(); + ui->netUDPRB->setChecked(network.contains("udp")); + ui->netTCPRB->setChecked(network.contains("tcp")); + ui->netBothRB->setChecked(network.contains("tcp") && network.contains("udp")); // // Set protocol checkboxes. - ui->routeProtocolHTTPCB->setChecked(false); - ui->routeProtocolBTCB->setChecked(false); - ui->routeProtocolTLSCB->setChecked(false); - - if (protocols.contains("http")) { - ui->routeProtocolHTTPCB->setChecked(true); - } - - if (protocols.contains("tls")) { - ui->routeProtocolTLSCB->setChecked(true); - } - - if (protocols.contains("bittorrent")) { - ui->routeProtocolBTCB->setChecked(true); - } - + auto protocols = QList::fromStdList(CurrentRule.protocol); + ui->routeProtocolHTTPCB->setChecked(protocols.contains("http")); + ui->routeProtocolTLSCB->setChecked(protocols.contains("tls")); + ui->routeProtocolBTCB->setChecked(protocols.contains("bittorrent")); + // + // Port ui->routePortTxt->setText(QSTRING(CurrentRule.port)); // - QString users = std::accumulate(CurrentRule.user.begin(), CurrentRule.user.end(), QString(), [](QString result, const string & str) { - result.append(QSTRING(str) + NEWLINE); - return result; - }); + // Users + QString users = Stringify(CurrentRule.user, NEWLINE); ui->routeUserTxt->setPlainText(users); // + // Incoming Sources + QString sources = Stringify(CurrentRule.source, NEWLINE); + ui->sourceIPList->setPlainText(sources); + // + // Domains + QString domains = Stringify(CurrentRule.domain, NEWLINE); + ui->hostList->setPlainText(domains); + // + // Outcoming IPs + QString ips = Stringify(CurrentRule.ip, NEWLINE); + ui->ipList->setPlainText(ips); + // + // Set Balancer + ui->balancerSelectionCombo->clear(); + ui->balancerSelectionCombo->addItems(Balancers[QSTRING(CurrentRule.balancerTag)]); + ui->balancerList->clear(); + ui->balancerList->addItems(Balancers[QSTRING(CurrentRule.balancerTag)]); if (rule.inboundTag.size() == 0) { for (int i = 0; i < ui->inboundsList->count(); i++) { ui->inboundsList->item(i)->setCheckState(Qt::Checked); } + + ui->inboundsList->setCurrentRow(0); } else { for (auto inboundTag : rule.inboundTag) { auto inTag = QSTRING(inboundTag); @@ -195,6 +250,7 @@ void RouteEditor::ShowRuleDetail(RuleObject rule) } ui->inboundsList->item(_index)->setCheckState(Qt::Checked); + ui->inboundsList->setCurrentRow(_index); STATUS("OK") } else { STATUS("Cannot find inbound by a tag, possible currupted files?") @@ -205,18 +261,6 @@ void RouteEditor::ShowRuleDetail(RuleObject rule) } } -void RouteEditor::on_routesTable_cellClicked(int row, int column) -{ - Q_UNUSED(column) - - if (row < 0) { - return; - } - - currentRuleIndex = row; - ShowRuleDetail(CurrentRule); -} - void RouteEditor::on_editOutboundBtn_clicked() { QJsonObject result; @@ -265,6 +309,9 @@ void RouteEditor::on_editInboundBtn_clicked() { QJsonObject result; int row = ui->inboundsList->currentRow(); + + if (row < 0) return; + auto currentInbound = inbounds[row].toObject(); auto protocol = currentInbound["protocol"].toString(); @@ -328,27 +375,190 @@ void RouteEditor::on_routeProtocolBTCB_stateChanged(int arg1) CurrentRule.protocol = protocols.toStdList(); STATUS("Protocol list changed.") } - void RouteEditor::on_balabcerAddBtn_clicked() { + if (!ui->balancerSelectionCombo->currentText().isEmpty()) { + this->Balancers[QSTRING(CurrentRule.balancerTag)].append(ui->balancerSelectionCombo->currentText()); + } + + ui->balancerList->addItem(ui->balancerSelectionCombo->currentText()); + ui->balancerSelectionCombo->setEditText(""); + STATUS("OK") } void RouteEditor::on_balancerDelBtn_clicked() { + if (ui->balancerList->currentRow() < 0) { + return; + } + + Balancers[QSTRING(CurrentRule.balancerTag)].removeAt(ui->balancerList->currentRow()); + ui->balancerList->takeItem(ui->balancerList->currentRow()); + STATUS("Removed a balancer entry.") } void RouteEditor::on_hostList_textChanged() { + CurrentRule.domain = SplitLinesStdString(ui->hostList->toPlainText()).toStdList(); } void RouteEditor::on_ipList_textChanged() { + CurrentRule.ip = SplitLinesStdString(ui->ipList->toPlainText()).toStdList(); } void RouteEditor::on_routePortTxt_textEdited(const QString &arg1) { + CurrentRule.port = arg1.toStdString(); } void RouteEditor::on_routeUserTxt_textEdited(const QString &arg1) { + CurrentRule.user = SplitLinesStdString(arg1).toStdList(); +} + +void RouteEditor::on_routesTable_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn) +{ + Q_UNUSED(currentColumn) + Q_UNUSED(previousColumn) + Q_UNUSED(previousRow) + + if (currentRow < 0) { + return; + } + + currentRuleIndex = currentRow; + ShowRuleDetail(CurrentRule); +} + +void RouteEditor::on_addRouteBtn_clicked() +{ + // Add Route + RuleObject rule; + // + + if (QSTRING(rule.balancerTag).isEmpty()) { + // Default balancer tag. + auto bTag = GenerateRandomString(); + rule.balancerTag = bTag.toStdString(); + Balancers[bTag] = QStringList(); + } + + // + ui->routesTable->insertRow(ui->routesTable->rowCount()); + // WARNING There will be an additional check on the final configuration generation process. + auto enabledItem = new QTableWidgetItem(tr("Enabled")); + enabledItem->setCheckState(rule.QV2RAY_RULE_ENABLED ? Qt::Checked : Qt::Unchecked); + ui->routesTable->setItem(ui->routesTable->rowCount() - 1, 0, enabledItem); + ui->routesTable->setItem(ui->routesTable->rowCount() - 1, 1, new QTableWidgetItem(rule.inboundTag.size() > 0 ? Stringify(rule.inboundTag) : tr("Any"))); + ui->routesTable->setItem(ui->routesTable->rowCount() - 1, 2, new QTableWidgetItem(QString::number(rule.domain.size() + rule.ip.size()) + " " + tr("Items"))); + ui->routesTable->setItem(ui->routesTable->rowCount() - 1, 3, new QTableWidgetItem(QSTRING(rule.outboundTag))); + rules.append(rule); + currentRuleIndex = ui->routesTable->rowCount() - 1; + ui->routesTable->setCurrentCell(currentRuleIndex, 0); + ShowRuleDetail(CurrentRule); + ui->delRouteBtn->setEnabled(true); +} + +void RouteEditor::on_changeIOBtn_clicked() +{ + QString outbound = ""; + + if (ui->outboundsList->currentRow() < 0) { + // Don't return as someone may use the outboundTag + // + //QvMessageBox(this, tr("Changing route inbound/outbound"), tr("Please select an outbound from the list.")); + //return; + QvMessageBox(this, tr("Changing route inbound/outbound"), + tr("You didn't select an outbound.") + NEWLINE + + tr("Banlancer will be used.")); + } else { + outbound = outbounds[ui->outboundsList->currentRow()].toObject()["tag"].toString(); + } + + QList new_inbounds; + QList new_inbounds_name; + + for (int i = 0; i < ui->inboundsList->count(); i++) { + auto _item = ui->inboundsList->item(i); + + if (_item->checkState() == Qt::Checked) { + // WARN there are possiblilties that someone may forget to set the tag. + new_inbounds.append(inbounds[i].toObject()["tag"].toString().toStdString()); + new_inbounds_name.append(_item->text().toStdString()); + } + } + + if (new_inbounds.size() == 0) { + // TODO what to do? + } + + if (new_inbounds.contains("")) { + // Empty tag. + auto result1 = QvMessageBoxAsk(this, tr("Changing route inbound/outbound"), tr("One or more inbound config(s) have no tag configured, do you still want to continue?")); + + if (result1 != QMessageBox::Yes) { + return; + } + } + + auto result = QvMessageBoxAsk(this, tr("Changing route inbound/outbound"), + tr("Are you sure to change the inbound/outbound of currently selected route?") + NEWLINE + + tr("Current inbound/outbound combinations:") + NEWLINE + NEWLINE + tr("Inbounds: ") + NEWLINE + + Stringify(new_inbounds_name.toStdList(), NEWLINE) + NEWLINE + tr("Outbound: ") + outbound); + + if (result != QMessageBox::Yes) { + STATUS("Canceled changing inbound/outbound combination.") + return; + } + + CurrentRule.inboundTag = new_inbounds.toStdList(); + CurrentRule.outboundTag = outbound.toStdString(); + STATUS("OK") +} + +void RouteEditor::on_routesTable_cellChanged(int row, int column) +{ + if (column != 0) { + // Impossible + return; + } + + if (row < 0) { + return; + } + + if (rules.size() <= row) { + LOG(MODULE_UI, "INFO: This message is possibly caused by adding a new route.") + LOG(MODULE_UI, "INFO: ... But may indicate to other bugs if you didn't do that.") + return; + } + + rules[row].QV2RAY_RULE_ENABLED = ui->routesTable->item(row, column)->checkState() == Qt::Checked; + STATUS((rules[row].QV2RAY_RULE_ENABLED ? "Enabled a route" : "Disabled a route")) +} + +void RouteEditor::on_netBothRB_clicked() +{ + CurrentRule.network = "tcp,udp"; +} + +void RouteEditor::on_netUDPRB_clicked() +{ + CurrentRule.network = "udp"; +} + +void RouteEditor::on_netTCPRB_clicked() +{ + CurrentRule.network = "tcp"; +} + +void RouteEditor::on_routeUserTxt_textChanged() +{ + CurrentRule.user = SplitLinesStdString(ui->routeUserTxt->toPlainText()).toStdList(); +} + +void RouteEditor::on_sourceIPList_textChanged() +{ + CurrentRule.source = SplitLinesStdString(ui->sourceIPList->toPlainText()).toStdList(); } diff --git a/src/ui/w_RoutesEditor.h b/src/ui/w_RoutesEditor.h index 3471094e..6158a41f 100644 --- a/src/ui/w_RoutesEditor.h +++ b/src/ui/w_RoutesEditor.h @@ -27,8 +27,6 @@ class RouteEditor : public QDialog void on_inboundsList_currentRowChanged(int currentRow); - void on_routesTable_cellClicked(int row, int column); - void on_editOutboundBtn_clicked(); void on_insertDirectBtn_clicked(); @@ -53,6 +51,24 @@ class RouteEditor : public QDialog void on_routeUserTxt_textEdited(const QString &arg1); + void on_routesTable_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn); + + void on_addRouteBtn_clicked(); + + void on_changeIOBtn_clicked(); + + void on_routesTable_cellChanged(int row, int column); + + void on_netBothRB_clicked(); + + void on_netUDPRB_clicked(); + + void on_netTCPRB_clicked(); + + void on_routeUserTxt_textChanged(); + + void on_sourceIPList_textChanged(); + private: void ShowRuleDetail(RuleObject rule); int currentRuleIndex; @@ -63,6 +79,7 @@ class RouteEditor : public QDialog QJsonArray inbounds; QJsonArray outbounds; QJsonObject root; + QJsonObject original; Ui::RouteEditor *ui; }; diff --git a/src/ui/w_RoutesEditor.ui b/src/ui/w_RoutesEditor.ui index adda60cb..6c0145ee 100644 --- a/src/ui/w_RoutesEditor.ui +++ b/src/ui/w_RoutesEditor.ui @@ -7,7 +7,7 @@ 0 0 1010 - 610 + 625 @@ -22,14 +22,181 @@ true - + + + + + Outbound List + + + + + + + + ... + + + + :/icons/add_connection_btn.png:/icons/add_connection_btn.png + + + + + + + ... + + + + :/icons/remove_connection_btn.png:/icons/remove_connection_btn.png + + + + + + + + + + + :/icons/edit_connection_btn.png:/icons/edit_connection_btn.png + + + + + + + D + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + QAbstractItemView::NoEditTriggers + + + + + + + Outbound Information + + + + + + + + + + + true + + + + + + + Tag + + + + + + + Type + + + + + + + + + + true + + + + + + + Address + + + + + + + + + + true + + + + + + + Port + + + + + + + + + + true + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Routes - - + + QAbstractItemView::NoEditTriggers @@ -52,7 +219,7 @@ - DomainOrIP + Domain/IP @@ -62,104 +229,7 @@ - - - - Route Information - - - - - - Protocol - - - - - - - - - HTTP - - - - - - - TLS - - - - - - - BitTorrent - - - - - - - - - Port - - - - - - - e.g. 80, 443, 8000-8080 - - - - - - - Users - - - - - - - - - - Network - - - - - - - - - TCP - - - - - - - UDP - - - - - - - Both - - - - - - - - - + @@ -218,92 +288,190 @@ - + + + + 0 + 320 + + Route Details - - - - - Target Host List - - - + + + + - + + + + + + Network + + + + + + + + + TCP + + + + + + + UDP + + + + + + + Both + + + + + + + + + Protocol + + + + + + + + + HTTP + + + + + + + TLS + + + + + + + BitTorrent + + + + + + + + + Port + + + + + + + e.g. 80, 443, 8000-8080 + + + + + + + Balancers + + + + + + + + + true + + + + + + + ... + + + + :/icons/remove_connection_btn.png:/icons/remove_connection_btn.png + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + ... + + + + :/icons/add_connection_btn.png:/icons/add_connection_btn.png + + + + + + + + + + + + + + Target IP List - - - - - + + - Balancer + Users - - - - - - true - - - - - - - ... - - - - :/icons/remove_connection_btn.png:/icons/remove_connection_btn.png - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - ... - - - - :/icons/add_connection_btn.png:/icons/add_connection_btn.png - - - - - - - + + - - + + + + Target Host List + + - + Source IP List @@ -321,22 +489,9 @@ Inbound List - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - + + + @@ -360,28 +515,32 @@ - + - Add Defaults + + + + + :/icons/edit_connection_btn.png:/icons/edit_connection_btn.png - + - Edit + D - + - Qt::Horizontal + Qt::Vertical - 40 - 20 + 20 + 40 @@ -389,213 +548,90 @@ + + + Inbound Information - - - - - Tag - - + + + + + + + Type + + + + + + + Port + + + + + + + + + + + + + + Address + + + + + + + Tag + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + Qt::Vertical - - - - - - Type + + + 20 + 31 + - - - - - - - - - - - - - Address - - - - - - - - - - - - - - Port - - - - - - - - - + - - - - - - - - - - Outbound List - - - - - - QAbstractItemView::NoEditTriggers - - - - - - - Outbound Information - - - - - - Tag - - - - - - - - - - - - - - Type - - - - - - - - - - - - - - Address - - - - - - - - - - - - - - Port - - - - - - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - ... - - - - :/icons/add_connection_btn.png:/icons/add_connection_btn.png - - - - - - - ... - - - - :/icons/remove_connection_btn.png:/icons/remove_connection_btn.png - - - - - - - Edit - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - -