Merge pull request #37 from vernette/feature/fakeip-cache-path-and-ttl

feat(podkop): add configurable cache file path and dns rewrite_ttl options
This commit is contained in:
Nikita Skryabin
2025-02-21 00:20:15 +03:00
committed by GitHub
4 changed files with 129 additions and 10 deletions

View File

@@ -697,6 +697,52 @@ return view.extend({
return true; return true;
}; };
o = s.taboption('additional', form.Value, 'dns_rewrite_ttl', _('DNS Rewrite TTL'), _('Time in seconds for DNS record caching (default: 600)'));
o.default = '600';
o.rmempty = false;
o.ucisection = 'main';
o.validate = function (section_id, value) {
if (!value) {
return _('TTL value cannot be empty');
}
const ttl = parseInt(value);
if (isNaN(ttl) || ttl < 0) {
return _('TTL must be a positive number');
}
return true;
};
o = s.taboption('additional', form.Value, 'cache_file', _('Cache File Path'), _('Select or enter path for sing-box cache file. Change this ONLY if you know what you are doing'));
o.value('/tmp/cache.db', 'RAM (/tmp/cache.db)');
o.value('/usr/share/sing-box/cache.db', 'Flash (/usr/share/sing-box/cache.db)');
o.default = '/tmp/cache.db';
o.rmempty = false;
o.ucisection = 'main';
o.validate = function(section_id, value) {
if (!value) {
return _('Cache file path cannot be empty');
}
if (!value.startsWith('/')) {
return _('Path must be absolute (start with /)');
}
if (!value.endsWith('cache.db')) {
return _('Path must end with cache.db');
}
const parts = value.split('/').filter(Boolean);
if (parts.length < 2) {
return _('Path must contain at least one directory (like /tmp/cache.db)');
}
return true;
};
// Diagnostics tab // Diagnostics tab
o = s.tab('diagnostics', _('Diagnostics')); o = s.tab('diagnostics', _('Diagnostics'));

View File

@@ -522,3 +522,36 @@ msgstr "Адрес DNS сервера не может быть пустым"
msgid "Invalid DNS server format. Examples: 8.8.8.8 or dns.example.com" msgid "Invalid DNS server format. Examples: 8.8.8.8 or dns.example.com"
msgstr "Неверный формат DNS сервера. Примеры: 8.8.8.8 или dns.example.com" msgstr "Неверный формат DNS сервера. Примеры: 8.8.8.8 или dns.example.com"
msgid "DNS Rewrite TTL"
msgstr "Перезапись TTL для DNS"
msgid "Time in seconds for DNS record caching (default: 600)"
msgstr "Время в секундах для кэширования DNS записей (по умолчанию: 600)"
msgid "TTL value cannot be empty"
msgstr "Значение TTL не может быть пустым"
msgid "TTL must be a positive number"
msgstr "TTL должно быть положительным числом"
msgid "Cache File Path"
msgstr "Путь к файлу кэша"
msgid "Select or enter path for sing-box cache file. Change this ONLY if you know what you are doing"
msgstr "Выберите или введите путь к файлу кэша sing-box. Меняйте ТОЛЬКО если знаете, что делаете"
msgid "Cache file path cannot be empty"
msgstr "Путь к файлу кэша не может быть пустым"
msgid "Path must be absolute (start with /)"
msgstr "Путь должен быть абсолютным (начинаться с /)"
msgid "Path must end with cache.db"
msgstr "Путь должен заканчиваться на cache.db"
msgid "Path must contain at least one directory (like /tmp/cache.db)"
msgstr "Путь должен содержать хотя бы одну директорию (например /tmp/cache.db)"
msgid "Invalid path format. Must be like /tmp/cache.db"
msgstr "Неверный формат пути. Пример: /tmp/cache.db"

View File

@@ -876,3 +876,36 @@ msgstr ""
msgid "Select or enter DNS server address" msgid "Select or enter DNS server address"
msgstr "" msgstr ""
msgid "DNS Rewrite TTL"
msgstr ""
msgid "Time in seconds for DNS record caching (default: 600)"
msgstr ""
msgid "TTL value cannot be empty"
msgstr ""
msgid "TTL must be a positive number"
msgstr ""
msgid "Cache File Path"
msgstr ""
msgid "Select or enter path for sing-box cache file. Change this ONLY if you know what you are doing"
msgstr ""
msgid "Cache file path cannot be empty"
msgstr ""
msgid "Path must be absolute (start with /)"
msgstr ""
msgid "Path must end with cache.db"
msgstr ""
msgid "Path must contain at least one directory (like /tmp/cache.db)"
msgstr ""
msgid "Invalid path format. Must be like /tmp/cache.db"
msgstr ""

View File

@@ -37,7 +37,6 @@ SUBNETS_META="${GITHUB_RAW_URL}/Subnets/IPv4/meta.lst"
SUBNETS_DISCORD="${GITHUB_RAW_URL}/Subnets/IPv4/discord.lst" SUBNETS_DISCORD="${GITHUB_RAW_URL}/Subnets/IPv4/discord.lst"
SUBNETS_TELERAM="${GITHUB_RAW_URL}/Subnets/IPv4/telegram.lst" SUBNETS_TELERAM="${GITHUB_RAW_URL}/Subnets/IPv4/telegram.lst"
SING_BOX_CONFIG="/etc/sing-box/config.json" SING_BOX_CONFIG="/etc/sing-box/config.json"
CACHE_FILE_PATH="/tmp/cache.db"
FAKEIP="198.18.0.0/15" FAKEIP="198.18.0.0/15"
VALID_SERVICES="russia_inside russia_outside ukraine_inside geoblock block porn news anime youtube discord meta twitter hdrezka tiktok telegram" VALID_SERVICES="russia_inside russia_outside ukraine_inside geoblock block porn news anime youtube discord meta twitter hdrezka tiktok telegram"
DNS_RESOLVERS="1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4 9.9.9.9 9.9.9.11 94.140.14.14 94.140.15.15 208.67.220.220 208.67.222.222 77.88.8.1 77.88.8.8" DNS_RESOLVERS="1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4 9.9.9.9 9.9.9.11 94.140.14.14 94.140.15.15 208.67.220.220 208.67.222.222 77.88.8.1 77.88.8.8"
@@ -709,8 +708,13 @@ sing_box_dns() {
} }
sing_box_dns_rule_fakeip() { sing_box_dns_rule_fakeip() {
log "Configure fakeip route in sing-box" local rewrite_ttl
config_get rewrite_ttl "main" "dns_rewrite_ttl" "600"
log "Configure fakeip route in sing-box and set TTL to $rewrite_ttl seconds"
jq \ jq \
--arg ttl "$rewrite_ttl" \
'.dns += { '.dns += {
"rules": [ "rules": [
{ {
@@ -727,6 +731,8 @@ sing_box_dns_rule_fakeip() {
}, },
{ {
"server": "fakeip-server", "server": "fakeip-server",
"domain": "",
"rewrite_ttl": ($ttl | tonumber),
"rule_set": [] "rule_set": []
} }
] ]
@@ -754,14 +760,17 @@ sing_box_dns_rule_fakeip_section() {
} }
sing_box_cache_file() { sing_box_cache_file() {
log "Configure cache.db in sing-box" config_get cache_file "main" "cache_file" "/tmp/cache.db"
log "Configure sing-box cache.db path"
jq \ jq \
--arg CACHE_FILE_PATH "$CACHE_FILE_PATH" \ --arg cache_file "$cache_file" \
'.experimental = { '.experimental = {
"cache_file": { "cache_file": {
"enabled": true, "enabled": true,
"store_fakeip": true, "store_fakeip": true,
"path": $CACHE_FILE_PATH "path": $cache_file
} }
}' $SING_BOX_CONFIG >/tmp/sing-box-config-tmp.json && mv /tmp/sing-box-config-tmp.json $SING_BOX_CONFIG }' $SING_BOX_CONFIG >/tmp/sing-box-config-tmp.json && mv /tmp/sing-box-config-tmp.json $SING_BOX_CONFIG
} }
@@ -1843,10 +1852,8 @@ sing_box_add_secure_dns_probe_domain() {
--arg override "$override_address" \ --arg override "$override_address" \
'.dns.rules |= map( '.dns.rules |= map(
if .server == "fakeip-server" then if .server == "fakeip-server" then
{ . + {
"server": .server, "domain": $domain
"domain": $domain,
"rule_set": .rule_set
} }
else else
. .