mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-19 05:30:06 +08:00
Fix process path &&
Some more fixes
This commit is contained in:
parent
6bacd1c7a3
commit
70c0ecd926
@ -137,7 +137,7 @@ func BatchURLTest(ctx context.Context, i *boxbox.Box, outboundTags []string, url
|
|||||||
}
|
}
|
||||||
client := &http.Client{
|
client := &http.Client{
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
DialContext: func(ctx context.Context, network string, addr string) (net.Conn, error) {
|
DialContext: func(_ context.Context, network string, addr string) (net.Conn, error) {
|
||||||
return outbound.DialContext(ctx, "tcp", metadata.ParseSocksaddr(addr))
|
return outbound.DialContext(ctx, "tcp", metadata.ParseSocksaddr(addr))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <QHostInfo>
|
#include <QHostInfo>
|
||||||
|
#include <utility>
|
||||||
#include "DialFields.h"
|
#include "DialFields.h"
|
||||||
#include "multiplex.h"
|
#include "multiplex.h"
|
||||||
#include "TLS.h"
|
#include "TLS.h"
|
||||||
@ -27,18 +28,23 @@ namespace Configs
|
|||||||
|
|
||||||
void ResolveDomainToIP(const std::function<void()> &onFinished) {
|
void ResolveDomainToIP(const std::function<void()> &onFinished) {
|
||||||
bool noResolve = false;
|
bool noResolve = false;
|
||||||
if (IsIpAddress(server) || server.isEmpty()) noResolve = true;
|
auto serverAddr = GetAddress();
|
||||||
|
if (IsIpAddress(serverAddr) || serverAddr.isEmpty()) noResolve = true;
|
||||||
if (noResolve) {
|
if (noResolve) {
|
||||||
onFinished();
|
onFinished();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QHostInfo::lookupHost(server, QApplication::instance(), [=, this](const QHostInfo &host) {
|
QHostInfo::lookupHost(serverAddr, QApplication::instance(), [=, this](const QHostInfo &host) {
|
||||||
auto addrs = host.addresses();
|
auto addrs = host.addresses();
|
||||||
if (!addrs.isEmpty()) server = addrs.first().toString();
|
if (!addrs.isEmpty()) SetAddress(addrs.first().toString());
|
||||||
onFinished();
|
onFinished();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void SetAddress(QString newAddr) {
|
||||||
|
server = std::move(newAddr);
|
||||||
|
}
|
||||||
|
|
||||||
virtual QString GetAddress()
|
virtual QString GetAddress()
|
||||||
{
|
{
|
||||||
return server;
|
return server;
|
||||||
|
|||||||
@ -40,6 +40,8 @@ namespace Configs
|
|||||||
QJsonObject ExportToJson() override;
|
QJsonObject ExportToJson() override;
|
||||||
BuildResult Build() override;
|
BuildResult Build() override;
|
||||||
|
|
||||||
|
void SetAddress(QString newAddr) override;
|
||||||
|
QString GetAddress() override;
|
||||||
QString DisplayAddress() override;
|
QString DisplayAddress() override;
|
||||||
QString DisplayType() override;
|
QString DisplayType() override;
|
||||||
bool IsEndpoint() override;
|
bool IsEndpoint() override;
|
||||||
|
|||||||
@ -83,6 +83,8 @@ namespace Configs
|
|||||||
QJsonObject ExportToJson() override;
|
QJsonObject ExportToJson() override;
|
||||||
BuildResult Build() override;
|
BuildResult Build() override;
|
||||||
|
|
||||||
|
void SetAddress(QString newAddr) override;
|
||||||
|
QString GetAddress() override;
|
||||||
QString DisplayAddress() override;
|
QString DisplayAddress() override;
|
||||||
QString DisplayType() override;
|
QString DisplayType() override;
|
||||||
bool IsEndpoint() override;
|
bool IsEndpoint() override;
|
||||||
|
|||||||
@ -529,7 +529,7 @@ namespace Configs {
|
|||||||
ctx->buildConfigResult->coreConfig["inbounds"] = inbounds;
|
ctx->buildConfigResult->coreConfig["inbounds"] = inbounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
void unwrapChain(const QList<int>& entIDs, QList<std::shared_ptr<ProxyEntity>> &ents, QString& error)
|
void entIDListtoEntList(const QList<int>& entIDs, QList<std::shared_ptr<ProxyEntity>> &ents, QString& error)
|
||||||
{
|
{
|
||||||
bool hasExtracore = false;
|
bool hasExtracore = false;
|
||||||
bool hasCustom = false;
|
bool hasCustom = false;
|
||||||
@ -556,10 +556,24 @@ namespace Configs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<int> unwrapChain(int entID) {
|
||||||
|
auto ent = profileManager->GetProfile(entID);
|
||||||
|
if (ent == nullptr)
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
if (ent->type == "chain") {
|
||||||
|
auto chain = ent->Chain();
|
||||||
|
if (chain == nullptr) return {};
|
||||||
|
return chain->list;
|
||||||
|
}
|
||||||
|
return {entID};
|
||||||
|
}
|
||||||
|
|
||||||
void buildOutboundChain(std::shared_ptr<BuildSingBoxConfigContext> &ctx, const QList<int>& entIDs, const QString& prefix, bool includeProxy, bool link)
|
void buildOutboundChain(std::shared_ptr<BuildSingBoxConfigContext> &ctx, const QList<int>& entIDs, const QString& prefix, bool includeProxy, bool link)
|
||||||
{
|
{
|
||||||
QList<std::shared_ptr<ProxyEntity>> ents;
|
QList<std::shared_ptr<ProxyEntity>> ents;
|
||||||
unwrapChain(entIDs, ents, ctx->error);
|
entIDListtoEntList(entIDs, ents, ctx->error);
|
||||||
for (int idx = 0; idx < ents.size(); idx++)
|
for (int idx = 0; idx < ents.size(); idx++)
|
||||||
{
|
{
|
||||||
auto tag = prefix + "-" + Int2String(idx);
|
auto tag = prefix + "-" + Int2String(idx);
|
||||||
@ -898,6 +912,7 @@ namespace Configs {
|
|||||||
QList<int> entIDs;
|
QList<int> entIDs;
|
||||||
for (const auto& proxy : profiles) entIDs << proxy->id;
|
for (const auto& proxy : profiles) entIDs << proxy->id;
|
||||||
ctx->buildPrerequisities->dnsDeps->directDomains = QListStr2QJsonArray(getEntDomains(entIDs, ctx->error));
|
ctx->buildPrerequisities->dnsDeps->directDomains = QListStr2QJsonArray(getEntDomains(entIDs, ctx->error));
|
||||||
|
if (!ctx->buildPrerequisities->dnsDeps->directDomains.isEmpty()) ctx->buildPrerequisities->dnsDeps->needDirectDnsRules = true;
|
||||||
buildDNSSection(ctx);
|
buildDNSSection(ctx);
|
||||||
if (!ctx->error.isEmpty())
|
if (!ctx->error.isEmpty())
|
||||||
{
|
{
|
||||||
@ -942,7 +957,11 @@ namespace Configs {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buildOutboundChain(ctx, {item->id}, "proxy-" + Int2String(suffix), false, true);
|
buildOutboundChain(ctx, unwrapChain(item->id), "proxy-" + Int2String(suffix), false, true);
|
||||||
|
if (!ctx->error.isEmpty()) {
|
||||||
|
res->error = ctx->error;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
auto tag = "proxy-" + Int2String(suffix) + "-0";
|
auto tag = "proxy-" + Int2String(suffix) + "-0";
|
||||||
res->outboundTags << tag;
|
res->outboundTags << tag;
|
||||||
res->tag2entID.insert(tag, item->id);
|
res->tag2entID.insert(tag, item->id);
|
||||||
|
|||||||
@ -114,6 +114,14 @@ namespace Configs {
|
|||||||
return {object, ""};
|
return {object, ""};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tailscale::SetAddress(QString newAddr) {
|
||||||
|
control_url = newAddr;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString tailscale::GetAddress() {
|
||||||
|
return control_url;
|
||||||
|
}
|
||||||
|
|
||||||
QString tailscale::DisplayAddress()
|
QString tailscale::DisplayAddress()
|
||||||
{
|
{
|
||||||
return control_url;
|
return control_url;
|
||||||
|
|||||||
@ -261,9 +261,18 @@ namespace Configs {
|
|||||||
return {object, ""};
|
return {object, ""};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wireguard::SetAddress(QString newAddr) {
|
||||||
|
peer->address = newAddr;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString wireguard::GetAddress() {
|
||||||
|
return peer->address;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString wireguard::DisplayAddress()
|
QString wireguard::DisplayAddress()
|
||||||
{
|
{
|
||||||
return ::DisplayAddress(peer->address, peer->port > 0);
|
return ::DisplayAddress(peer->address, peer->port);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString wireguard::DisplayType()
|
QString wireguard::DisplayType()
|
||||||
|
|||||||
@ -784,17 +784,15 @@ namespace Configs {
|
|||||||
|
|
||||||
bool RoutingChain::add_simple_process_rule(const QString& content, const std::shared_ptr<RouteRule>& rule, ruleType type)
|
bool RoutingChain::add_simple_process_rule(const QString& content, const std::shared_ptr<RouteRule>& rule, ruleType type)
|
||||||
{
|
{
|
||||||
auto sp = content.split(":");
|
if (!content.contains(":")) return false;
|
||||||
if (sp.size() < 2) return false;
|
auto prefix = content.first(content.indexOf(':'));
|
||||||
const QString& subType = sp[0];
|
const QString& address = content.section(':', 1);
|
||||||
if (subType == "processPath" && type == simpleProcessPath)
|
if (prefix == "processPath" && type == simpleProcessPath)
|
||||||
{
|
{
|
||||||
const QString& address = content.section(':', 1);
|
|
||||||
if (!rule->process_path.contains(address)) rule->process_path.append(address);
|
if (!rule->process_path.contains(address)) rule->process_path.append(address);
|
||||||
return true;
|
return true;
|
||||||
} else if (subType == "processName" && type == simpleProcessName && sp.size() == 2)
|
} else if (prefix == "processName" && type == simpleProcessName)
|
||||||
{
|
{
|
||||||
const QString& address = sp[1];
|
|
||||||
if (!rule->process_name.contains(address)) rule->process_name.append(address);
|
if (!rule->process_name.contains(address)) rule->process_name.append(address);
|
||||||
return true;
|
return true;
|
||||||
} else
|
} else
|
||||||
|
|||||||
@ -1789,10 +1789,18 @@ void MainWindow::on_menu_export_config_triggered() {
|
|||||||
msg.exec();
|
msg.exec();
|
||||||
if (msg.clickedButton() == button_1) {
|
if (msg.clickedButton() == button_1) {
|
||||||
result = BuildSingBoxConfig(ent);
|
result = BuildSingBoxConfig(ent);
|
||||||
|
if (!result->error.isEmpty()) {
|
||||||
|
MessageBoxWarning("Build config error", result->error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
config_core = QJsonObject2QString(result->coreConfig, true);
|
config_core = QJsonObject2QString(result->coreConfig, true);
|
||||||
QApplication::clipboard()->setText(config_core);
|
QApplication::clipboard()->setText(config_core);
|
||||||
} else if (msg.clickedButton() == button_2) {
|
} else if (msg.clickedButton() == button_2) {
|
||||||
auto res = Configs::BuildTestConfig({ent});
|
auto res = Configs::BuildTestConfig({ent});
|
||||||
|
if (!res->error.isEmpty()) {
|
||||||
|
MessageBoxWarning("Build Test config error", res->error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
config_core = QJsonObject2QString(res->coreConfig, true);
|
config_core = QJsonObject2QString(res->coreConfig, true);
|
||||||
QApplication::clipboard()->setText(config_core);
|
QApplication::clipboard()->setText(config_core);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user