mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-05 03:02:06 +00:00
Enhancements
Rework generation of sing-box rules. Add a dns outbound to sing-box configs.
This commit is contained in:
5 files changed
+67
-8
No files matched your search
@@ -481,6 +481,22 @@ static rapidjson::Value transformRuleToSingBox(const std::string& rule, const st
|
||||
return rule_obj;
|
||||
}
|
||||
|
||||
static void appendSingBoxRule(rapidjson::Value &rules, const std::string& rule, rapidjson::MemoryPoolAllocator<>& allocator)
|
||||
{
|
||||
using namespace rapidjson_ext;
|
||||
auto args = split(rule, ",");
|
||||
if (args.size() < 2) return;
|
||||
auto type = toLower(std::string(args[0]));
|
||||
auto value = toLower(args[1]);
|
||||
// std::string_view option;
|
||||
// if (args.size() >= 3) option = args[2];
|
||||
|
||||
type = replaceAllDistinct(type, "-", "_");
|
||||
type = replaceAllDistinct(type, "ip_cidr6", "ip_cidr");
|
||||
|
||||
rules | AppendToArray(type.c_str(), rapidjson::Value(value.c_str(), allocator), allocator);
|
||||
}
|
||||
|
||||
void rulesetToSingBox(rapidjson::Document &base_rule, std::vector<RulesetContent> &ruleset_content_array, bool overwrite_original_rules)
|
||||
{
|
||||
using namespace rapidjson_ext;
|
||||
@@ -504,6 +520,9 @@ void rulesetToSingBox(rapidjson::Document &base_rule, std::vector<RulesetContent
|
||||
rules.PushBack(direct_object, allocator);
|
||||
}
|
||||
|
||||
auto dns_object = buildObject(allocator, "protocol", "dns", "outbound", "dns-out");
|
||||
rules.PushBack(dns_object, allocator);
|
||||
|
||||
for(RulesetContent &x : ruleset_content_array)
|
||||
{
|
||||
if(global.maxAllowedRules && total_rules > global.maxAllowedRules)
|
||||
@@ -532,7 +551,10 @@ void rulesetToSingBox(rapidjson::Document &base_rule, std::vector<RulesetContent
|
||||
|
||||
strStrm.clear();
|
||||
strStrm<<retrieved_rules;
|
||||
|
||||
std::string::size_type lineSize;
|
||||
rapidjson::Value rule(rapidjson::kObjectType);
|
||||
|
||||
while(getline(strStrm, strLine, delimiter))
|
||||
{
|
||||
if(global.maxAllowedRules && total_rules > global.maxAllowedRules)
|
||||
@@ -548,8 +570,11 @@ void rulesetToSingBox(rapidjson::Document &base_rule, std::vector<RulesetContent
|
||||
strLine.erase(strLine.find("//"));
|
||||
strLine = trimWhitespace(strLine);
|
||||
}
|
||||
rules.PushBack(transformRuleToSingBox(strLine, rule_group, allocator), allocator);
|
||||
appendSingBoxRule(rule, strLine, allocator);
|
||||
}
|
||||
if (rule.ObjectEmpty()) continue;
|
||||
rule.AddMember("outbound", rapidjson::Value(rule_group.c_str(), allocator), allocator);
|
||||
rules.PushBack(rule, allocator);
|
||||
}
|
||||
|
||||
if (!base_rule.HasMember("route"))
|
||||
|
||||
@@ -2097,6 +2097,8 @@ void proxyToSingBox(std::vector<Proxy> &nodes, rapidjson::Document &json, std::v
|
||||
outbounds.PushBack(direct, allocator);
|
||||
auto reject = buildObject(allocator, "type", "block", "tag", "REJECT");
|
||||
outbounds.PushBack(reject, allocator);
|
||||
auto dns = buildObject(allocator, "type", "dns", "tag", "dns-out");
|
||||
outbounds.PushBack(dns, allocator);
|
||||
|
||||
for (Proxy &x : nodes)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user