mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
feat: resolve profile domain
This commit is contained in:
@@ -429,7 +429,7 @@ namespace NekoRay {
|
|||||||
{"enabled", true},
|
{"enabled", true},
|
||||||
{"concurrency", dataStore->mux_cool},
|
{"concurrency", dataStore->mux_cool},
|
||||||
};
|
};
|
||||||
auto stream = GetStreamSettings(ent->bean);
|
auto stream = GetStreamSettings(ent->bean.data());
|
||||||
if (stream != nullptr && !stream->packet_encoding.isEmpty()) {
|
if (stream != nullptr && !stream->packet_encoding.isEmpty()) {
|
||||||
muxObj["packetEncoding"] = stream->packet_encoding;
|
muxObj["packetEncoding"] = stream->packet_encoding;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
#include "AbstractBean.hpp"
|
#include "includes.h"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QHostInfo>
|
||||||
|
|
||||||
namespace NekoRay::fmt {
|
namespace NekoRay::fmt {
|
||||||
AbstractBean::AbstractBean(int version) {
|
AbstractBean::AbstractBean(int version) {
|
||||||
@@ -33,4 +38,38 @@ namespace NekoRay::fmt {
|
|||||||
QString AbstractBean::DisplayTypeAndName() {
|
QString AbstractBean::DisplayTypeAndName() {
|
||||||
return QString(" [%1] %2").arg(DisplayType(), DisplayName());
|
return QString(" [%1] %2").arg(DisplayType(), DisplayName());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
void AbstractBean::ResolveDomainToIP(const std::function<void()> &onFinished) {
|
||||||
|
bool noResolve = false;
|
||||||
|
if (dynamic_cast<ChainBean *>(this) != nullptr) noResolve = true;
|
||||||
|
if (dynamic_cast<CustomBean *>(this) != nullptr) noResolve = true;
|
||||||
|
if (dynamic_cast<NaiveBean *>(this) != nullptr) noResolve = true;
|
||||||
|
if (IsIpAddress(serverAddress)) noResolve = true;
|
||||||
|
if (noResolve) {
|
||||||
|
onFinished();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QHostInfo::lookupHost(serverAddress, QApplication::instance(), [=](const QHostInfo &host) {
|
||||||
|
auto addr = host.addresses();
|
||||||
|
if (!addr.isEmpty()) {
|
||||||
|
auto domain = serverAddress;
|
||||||
|
auto stream = GetStreamSettings(this);
|
||||||
|
|
||||||
|
// replace serverAddress
|
||||||
|
serverAddress = addr.first().toString();
|
||||||
|
|
||||||
|
// replace ws tls
|
||||||
|
if (stream != nullptr) {
|
||||||
|
if (stream->security == "tls" && !stream->sni.isEmpty()) {
|
||||||
|
stream->sni = domain;
|
||||||
|
}
|
||||||
|
if (stream->network == "ws" && !stream->host.isEmpty()) {
|
||||||
|
stream->host = domain;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onFinished();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -27,8 +27,14 @@ namespace NekoRay::fmt {
|
|||||||
|
|
||||||
explicit AbstractBean(int version);
|
explicit AbstractBean(int version);
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
QString ToNekorayShareLink(const QString &type);
|
QString ToNekorayShareLink(const QString &type);
|
||||||
|
|
||||||
|
void ResolveDomainToIP(const std::function<void()> &onFinished);
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
[[nodiscard]] virtual QString DisplayAddress();
|
[[nodiscard]] virtual QString DisplayAddress();
|
||||||
|
|
||||||
[[nodiscard]] virtual QString DisplayName();
|
[[nodiscard]] virtual QString DisplayName();
|
||||||
@@ -37,6 +43,8 @@ namespace NekoRay::fmt {
|
|||||||
|
|
||||||
virtual QString DisplayTypeAndName();
|
virtual QString DisplayTypeAndName();
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
virtual bool NeedExternal() { return false; };
|
virtual bool NeedExternal() { return false; };
|
||||||
|
|
||||||
virtual CoreObjOutboundBuildResult BuildCoreObj() { return {}; };
|
virtual CoreObjOutboundBuildResult BuildCoreObj() { return {}; };
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace NekoRay::fmt {
|
|||||||
QString DisplayInsecureHint(const QSharedPointer<AbstractBean> &bean) {
|
QString DisplayInsecureHint(const QSharedPointer<AbstractBean> &bean) {
|
||||||
if (!dataStore->insecure_hint) return {};
|
if (!dataStore->insecure_hint) return {};
|
||||||
auto insecure_hint = bean->InsecureHint();
|
auto insecure_hint = bean->InsecureHint();
|
||||||
auto stream = GetStreamSettings(bean);
|
auto stream = GetStreamSettings(bean.data());
|
||||||
if (stream != nullptr) insecure_hint += "\n" + stream->InsecureHint();
|
if (stream != nullptr) insecure_hint += "\n" + stream->InsecureHint();
|
||||||
return insecure_hint.trimmed();
|
return insecure_hint.trimmed();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace NekoRay::fmt {
|
|||||||
[[nodiscard]] QString InsecureHint() const;
|
[[nodiscard]] QString InsecureHint() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline V2rayStreamSettings *GetStreamSettings(const QSharedPointer<AbstractBean> &bean) {
|
inline V2rayStreamSettings *GetStreamSettings(AbstractBean *bean) {
|
||||||
if (bean == nullptr) return nullptr;
|
if (bean == nullptr) return nullptr;
|
||||||
auto stream_item = bean->_get("stream");
|
auto stream_item = bean->_get("stream");
|
||||||
if (stream_item != nullptr) {
|
if (stream_item != nullptr) {
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ namespace NekoRay {
|
|||||||
Routing *routing = new Routing;
|
Routing *routing = new Routing;
|
||||||
int imported_count = 0;
|
int imported_count = 0;
|
||||||
bool refreshing_group_list = false;
|
bool refreshing_group_list = false;
|
||||||
|
int resolve_count = 0;
|
||||||
|
|
||||||
// Flags
|
// Flags
|
||||||
bool flag_use_appdata = false;
|
bool flag_use_appdata = false;
|
||||||
|
|||||||
@@ -1117,6 +1117,14 @@ End: %2</source>
|
|||||||
<source>Manual addition of profiles is not allowed in subscription groupings.</source>
|
<source>Manual addition of profiles is not allowed in subscription groupings.</source>
|
||||||
<translation>订阅分组中不允许手动添加配置。</translation>
|
<translation>订阅分组中不允许手动添加配置。</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Resolve domain</source>
|
||||||
|
<translation>将服务器域名解析为 IP</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Resolving current group domain to IP, if support.</source>
|
||||||
|
<translation>将当前分组内服务器域名解析为 IP(如果支持)。</translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ProxyItem</name>
|
<name>ProxyItem</name>
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ void DialogEditProfile::typeSelected(const QString &newType) {
|
|||||||
ui->port_l->setVisible(notChain);
|
ui->port_l->setVisible(notChain);
|
||||||
|
|
||||||
// 右边 Outbound: settings
|
// 右边 Outbound: settings
|
||||||
auto stream = GetStreamSettings(ent->bean);
|
auto stream = GetStreamSettings(ent->bean.data());
|
||||||
if (stream != nullptr) {
|
if (stream != nullptr) {
|
||||||
ui->right_all_w->setVisible(true);
|
ui->right_all_w->setVisible(true);
|
||||||
ui->network->setCurrentText(stream->network);
|
ui->network->setCurrentText(stream->network);
|
||||||
@@ -249,7 +249,7 @@ void DialogEditProfile::accept() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 右边
|
// 右边
|
||||||
auto stream = GetStreamSettings(ent->bean);
|
auto stream = GetStreamSettings(ent->bean.data());
|
||||||
if (stream != nullptr) {
|
if (stream != nullptr) {
|
||||||
stream->network = ui->network->currentText();
|
stream->network = ui->network->currentText();
|
||||||
stream->security = ui->security->currentText();
|
stream->security = ui->security->currentText();
|
||||||
|
|||||||
@@ -1147,6 +1147,32 @@ void MainWindow::on_menu_remove_unavailable_triggered() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_menu_resolve_domain_triggered() {
|
||||||
|
if (QMessageBox::question(this,
|
||||||
|
tr("Confirmation"),
|
||||||
|
tr("Resolving current group domain to IP, if support.")
|
||||||
|
) != QMessageBox::StandardButton::Yes) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (mw_sub_updating) return;
|
||||||
|
mw_sub_updating = true;
|
||||||
|
|
||||||
|
auto group = NekoRay::profileManager->CurrentGroup();
|
||||||
|
if (group == nullptr) return;
|
||||||
|
|
||||||
|
auto profiles = group->ProfilesWithOrder();
|
||||||
|
NekoRay::dataStore->resolve_count = profiles.length();
|
||||||
|
|
||||||
|
for (const auto &profile: profiles) {
|
||||||
|
profile->bean->ResolveDomainToIP([=] {
|
||||||
|
profile->Save();
|
||||||
|
if (--NekoRay::dataStore->resolve_count != 0) return;
|
||||||
|
refresh_proxy_list();
|
||||||
|
mw_sub_updating = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_proxyListTable_customContextMenuRequested(const QPoint &pos) {
|
void MainWindow::on_proxyListTable_customContextMenuRequested(const QPoint &pos) {
|
||||||
ui->menu_server->popup(ui->proxyListTable->viewport()->mapToGlobal(pos)); //弹出菜单
|
ui->menu_server->popup(ui->proxyListTable->viewport()->mapToGlobal(pos)); //弹出菜单
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,6 +109,8 @@ private slots:
|
|||||||
|
|
||||||
void on_menu_update_subscripton_triggered();
|
void on_menu_update_subscripton_triggered();
|
||||||
|
|
||||||
|
void on_menu_resolve_domain_triggered();
|
||||||
|
|
||||||
void on_proxyListTable_itemDoubleClicked(QTableWidgetItem *item);
|
void on_proxyListTable_itemDoubleClicked(QTableWidgetItem *item);
|
||||||
|
|
||||||
void on_proxyListTable_customContextMenuRequested(const QPoint &pos);
|
void on_proxyListTable_customContextMenuRequested(const QPoint &pos);
|
||||||
|
|||||||
@@ -519,11 +519,15 @@
|
|||||||
<string>Current Group</string>
|
<string>Current Group</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="menu_delete_repeat"/>
|
<addaction name="menu_delete_repeat"/>
|
||||||
<addaction name="menu_remove_unavailable"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="menu_tcp_ping"/>
|
<addaction name="menu_tcp_ping"/>
|
||||||
<addaction name="menu_url_test"/>
|
<addaction name="menu_url_test"/>
|
||||||
<addaction name="menu_full_test"/>
|
<addaction name="menu_full_test"/>
|
||||||
|
<addaction name="menu_remove_unavailable"/>
|
||||||
<addaction name="menu_clear_test_result"/>
|
<addaction name="menu_clear_test_result"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="menu_resolve_domain"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
<addaction name="menu_update_subscripton"/>
|
<addaction name="menu_update_subscripton"/>
|
||||||
</widget>
|
</widget>
|
||||||
<addaction name="menu_add_from_input"/>
|
<addaction name="menu_add_from_input"/>
|
||||||
@@ -814,6 +818,11 @@
|
|||||||
<string notr="true">Ctrl+U</string>
|
<string notr="true">Ctrl+U</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="menu_resolve_domain">
|
||||||
|
<property name="text">
|
||||||
|
<string>Resolve domain</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
|||||||
Reference in New Issue
Block a user