refactor: remove hardcoded Telegram IP arrays in favor of fully dynamic community subnet loading

- updates.uc: cache downloaded built-in subnet lists (telegram, meta, twitter, etc.) to community-subnets-<service>.lst.
- generator_routes.uc: dynamically load community list IP CIDRs from cached subnet files for all community lists into sing-box route rules. Zero hardcoded IP arrays.
This commit is contained in:
Dushnilin
2026-07-26 21:45:15 +03:00
parent e9ad56df56
commit c012a5710b
2 changed files with 32 additions and 10 deletions
@@ -1120,6 +1120,22 @@ function add_excluded_ips_rule(config, section) {
push(config.route.rules, route_rule);
}
function load_community_subnet_cidrs(community) {
let folder = ctx.runtime_ruleset_folder || runtime_ruleset_folder;
let path = folder + "/community-subnets-" + as_string(community) + ".lst";
let content = fs.readfile(path);
if (content == null || content == "")
return [];
let cidrs = [];
for (let line in split(as_string(content), "\n")) {
line = trim(replace(as_string(line), /\r/g, ""));
if (line != "" && substr(line, 0, 1) != "#")
push(cidrs, line);
}
return cidrs;
}
function add_combined_route_for_section(config, section) {
let domains = domain_conditions(section);
let domain = domains.domain;
@@ -1139,16 +1155,8 @@ function add_combined_route_for_section(config, section) {
let ensured = ensure_community_ruleset(config, section_name, as_string(community));
push(rule_set_tags, ensured.tag);
push(dns_rule_set_tags, ensured.tag);
if (as_string(community) == "telegram") {
let tg_cidrs = [
"149.154.160.0/20", "91.108.4.0/22", "91.108.8.0/22",
"91.108.12.0/22", "91.108.16.0/22", "91.108.56.0/22",
"5.28.192.0/18", "91.105.192.0/23", "95.161.64.0/20",
"185.76.151.0/24", "194.221.0.0/16"
];
for (let cidr in tg_cidrs)
push(ip_cidr, cidr);
}
for (let cidr in load_community_subnet_cidrs(community))
push(ip_cidr, cidr);
}
for (let reference in connections.rule_sets(section)) {
let ensured = ensure_custom_ruleset(config, as_string(reference));