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:
@@ -2158,6 +2158,8 @@ function import_builtin_subnets_from_rule(section, settings) {
|
||||
if (type(urls) != "array")
|
||||
continue;
|
||||
|
||||
let cached_file = TMP_RULESET_FOLDER + "/community-subnets-" + as_string(service) + ".lst";
|
||||
let combined_lines = [];
|
||||
for (let url in urls) {
|
||||
let tmpfile = temp_path();
|
||||
if (tmpfile == "") {
|
||||
@@ -2171,6 +2173,13 @@ function import_builtin_subnets_from_rule(section, settings) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let lines = split(as_string(fs.readfile(tmpfile)), "\n");
|
||||
for (let l in lines) {
|
||||
l = trim(replace(as_string(l), /\r/g, ""));
|
||||
if (l != "" && substr(l, 0, 1) != "#")
|
||||
push(combined_lines, l);
|
||||
}
|
||||
|
||||
if (!nft_module_success([
|
||||
"nft-add-community-subnet-file-for-uci-section",
|
||||
section_name(section),
|
||||
@@ -2191,6 +2200,11 @@ function import_builtin_subnets_from_rule(section, settings) {
|
||||
|
||||
remove_file(tmpfile);
|
||||
}
|
||||
|
||||
if (length(combined_lines) > 0) {
|
||||
ensure_dir(TMP_RULESET_FOLDER);
|
||||
write_file(cached_file, join("\n", combined_lines) + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
|
||||
Reference in New Issue
Block a user