From ec936e236942ae518b2a3a1da3d950c54731facf Mon Sep 17 00:00:00 2001 From: Nikita Skryabin Date: Thu, 20 Feb 2025 22:49:58 +0300 Subject: [PATCH 1/6] feat(podkop): add configurable cache file path support --- .../luci-static/resources/view/podkop/podkop.js | 7 +++++++ podkop/files/etc/init.d/podkop | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js index ffd136d..01f02fc 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js @@ -697,6 +697,13 @@ return view.extend({ return true; }; + o = s.taboption('additional', form.Value, 'cache_file', 'Cache File Path', 'Select or enter path for sing-box cache file'); + 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'; + // Diagnostics tab o = s.tab('diagnostics', _('Diagnostics')); diff --git a/podkop/files/etc/init.d/podkop b/podkop/files/etc/init.d/podkop index 4caf1a7..30794e1 100755 --- a/podkop/files/etc/init.d/podkop +++ b/podkop/files/etc/init.d/podkop @@ -754,9 +754,20 @@ sing_box_dns_rule_fakeip_section() { } sing_box_cache_file() { - log "Configure cache.db in sing-box" + local cache_path + + config_get cache_file "main" "cache_file" "/tmp/cache.db" + + if [ "$cache_file" = "custom" ]; then + config_get cache_path "main" "custom_cache_path" + else + cache_path="$cache_file" + fi + + log "Configure sing-box cache.db path" + jq \ - --arg CACHE_FILE_PATH "$CACHE_FILE_PATH" \ + --arg CACHE_FILE_PATH "$cache_path" \ '.experimental = { "cache_file": { "enabled": true, From 1f3a65347e3735e99ae675130a9029e34149a1a2 Mon Sep 17 00:00:00 2001 From: Nikita Skryabin Date: Thu, 20 Feb 2025 23:27:50 +0300 Subject: [PATCH 2/6] feat(podkop): add DNS Rewrite TTL configuration option --- .../resources/view/podkop/podkop.js | 18 ++++++++++++++++++ podkop/files/etc/init.d/podkop | 15 ++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js index 01f02fc..88f310c 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js @@ -697,6 +697,24 @@ return view.extend({ 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'); o.value('/tmp/cache.db', 'RAM (/tmp/cache.db)'); o.value('/usr/share/sing-box/cache.db', 'Flash (/usr/share/sing-box/cache.db)'); diff --git a/podkop/files/etc/init.d/podkop b/podkop/files/etc/init.d/podkop index 30794e1..1de6917 100755 --- a/podkop/files/etc/init.d/podkop +++ b/podkop/files/etc/init.d/podkop @@ -709,8 +709,13 @@ sing_box_dns() { } 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 \ + --arg ttl "$rewrite_ttl" \ '.dns += { "rules": [ { @@ -727,6 +732,8 @@ sing_box_dns_rule_fakeip() { }, { "server": "fakeip-server", + "domain": "", + "rewrite_ttl": ($ttl | tonumber), "rule_set": [] } ] @@ -1854,10 +1861,8 @@ sing_box_add_secure_dns_probe_domain() { --arg override "$override_address" \ '.dns.rules |= map( if .server == "fakeip-server" then - { - "server": .server, - "domain": $domain, - "rule_set": .rule_set + . + { + "domain": $domain } else . From 255c08a6def04d89993b6d4d75a93cd90855b3bf Mon Sep 17 00:00:00 2001 From: Nikita Skryabin Date: Thu, 20 Feb 2025 23:38:27 +0300 Subject: [PATCH 3/6] feat(podkop.js): add validation for cache file path to ensure it meets specific criteria --- .../resources/view/podkop/podkop.js | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js index 88f310c..c9d25c7 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js @@ -715,13 +715,39 @@ return view.extend({ return true; }; - o = s.taboption('additional', form.Value, 'cache_file', 'Cache File Path', 'Select or enter path for sing-box cache file'); + 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)'); + } + + const pathRegex = /^\/(?:[^/]+\/)+[^/]+\.db$/; + if (!pathRegex.test(value)) { + return _('Invalid path format. Must be like /tmp/cache.db'); + } + + return true; + }; + // Diagnostics tab o = s.tab('diagnostics', _('Diagnostics')); From 560dda86046250cb7875358692693abdd8074b7b Mon Sep 17 00:00:00 2001 From: Nikita Skryabin Date: Thu, 20 Feb 2025 23:49:41 +0300 Subject: [PATCH 4/6] feat(podkop): add translations for cache file and rewrite ttl options --- .../resources/view/podkop/podkop.js | 8 ++--- luci-app-podkop/po/ru/podkop.po | 35 ++++++++++++++++++- luci-app-podkop/po/templates/podkop.pot | 33 +++++++++++++++++ 3 files changed, 71 insertions(+), 5 deletions(-) diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js index c9d25c7..e80b20f 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js @@ -697,25 +697,25 @@ return view.extend({ return true; }; - o = s.taboption('additional', form.Value, 'dns_rewrite_ttl', 'DNS Rewrite TTL', 'Time in seconds for DNS record caching (default: 600)'); + 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'; + return _('TTL value cannot be empty'); } const ttl = parseInt(value); if (isNaN(ttl) || ttl < 0) { - return 'TTL must be a positive number'; + 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 = 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'; diff --git a/luci-app-podkop/po/ru/podkop.po b/luci-app-podkop/po/ru/podkop.po index 93c6974..dd32b14 100644 --- a/luci-app-podkop/po/ru/podkop.po +++ b/luci-app-podkop/po/ru/podkop.po @@ -521,4 +521,37 @@ msgid "DNS server address cannot be empty" msgstr "Адрес DNS сервера не может быть пустым" msgid "Invalid DNS server format. Examples: 8.8.8.8 or dns.example.com" -msgstr "Неверный формат DNS сервера. Примеры: 8.8.8.8 или dns.example.com" \ No newline at end of file +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" \ No newline at end of file diff --git a/luci-app-podkop/po/templates/podkop.pot b/luci-app-podkop/po/templates/podkop.pot index 1506f1b..28cb66f 100644 --- a/luci-app-podkop/po/templates/podkop.pot +++ b/luci-app-podkop/po/templates/podkop.pot @@ -875,4 +875,37 @@ msgid "DNS Server" msgstr "" msgid "Select or enter DNS server address" +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 "" \ No newline at end of file From 134a79cb3bf122e519da0db269320e711d570f1c Mon Sep 17 00:00:00 2001 From: Nikita Skryabin Date: Thu, 20 Feb 2025 23:56:20 +0300 Subject: [PATCH 5/6] refactor(podkop.js): remove redundant path validation logic --- .../htdocs/luci-static/resources/view/podkop/podkop.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js index e80b20f..bdf515e 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js @@ -740,11 +740,6 @@ return view.extend({ return _('Path must contain at least one directory (like /tmp/cache.db)'); } - const pathRegex = /^\/(?:[^/]+\/)+[^/]+\.db$/; - if (!pathRegex.test(value)) { - return _('Invalid path format. Must be like /tmp/cache.db'); - } - return true; }; From 7ff49c3e4e2d07279556ce97e832931814209e0c Mon Sep 17 00:00:00 2001 From: Nikita Skryabin Date: Fri, 21 Feb 2025 00:15:37 +0300 Subject: [PATCH 6/6] chore(init.d/podkop): remove unused cache file path and constant --- podkop/files/etc/init.d/podkop | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/podkop/files/etc/init.d/podkop b/podkop/files/etc/init.d/podkop index 1de6917..44ddbf5 100755 --- a/podkop/files/etc/init.d/podkop +++ b/podkop/files/etc/init.d/podkop @@ -37,7 +37,6 @@ SUBNETS_META="${GITHUB_RAW_URL}/Subnets/IPv4/meta.lst" SUBNETS_DISCORD="${GITHUB_RAW_URL}/Subnets/IPv4/discord.lst" SUBNETS_TELERAM="${GITHUB_RAW_URL}/Subnets/IPv4/telegram.lst" SING_BOX_CONFIG="/etc/sing-box/config.json" -CACHE_FILE_PATH="/tmp/cache.db" 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" 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" @@ -761,25 +760,17 @@ sing_box_dns_rule_fakeip_section() { } sing_box_cache_file() { - local cache_path - config_get cache_file "main" "cache_file" "/tmp/cache.db" - if [ "$cache_file" = "custom" ]; then - config_get cache_path "main" "custom_cache_path" - else - cache_path="$cache_file" - fi - log "Configure sing-box cache.db path" jq \ - --arg CACHE_FILE_PATH "$cache_path" \ + --arg cache_file "$cache_file" \ '.experimental = { "cache_file": { "enabled": 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 }