|
24 | 24 |
|
25 | 25 | readonly packageName='adblock-fast' |
26 | 26 | readonly PKG_VERSION='dev-test' |
27 | | -readonly packageCompat='10' |
| 27 | +readonly packageCompat='11' |
28 | 28 | readonly serviceName="$packageName $PKG_VERSION" |
29 | 29 | readonly packageMemoryThreshold='33554432' |
30 | 30 | readonly packageConfigFile="/etc/config/${packageName}" |
@@ -796,12 +796,13 @@ load_package_config() { |
796 | 796 | config_get_bool config_update_enabled 'config' 'config_update_enabled' '0' |
797 | 797 | config_get_bool debug_init_script 'config' 'debug_init_script' '0' |
798 | 798 | config_get_bool debug_performance 'config' 'debug_performance' '0' |
| 799 | + config_get_bool dnsmasq_sanity_check 'config' 'dnsmasq_sanity_check' '1' |
| 800 | + config_get_bool dnsmasq_validity_check 'config' 'dnsmasq_validity_check' '0' |
799 | 801 | config_get_bool enabled 'config' 'enabled' '0' |
800 | 802 | config_get_bool force_dns 'config' 'force_dns' '1' |
801 | 803 | config_get_bool ipv6_enabled 'config' 'ipv6_enabled' '0' |
802 | 804 | config_get_bool parallel_downloads 'config' 'parallel_downloads' '1' |
803 | 805 | config_get_bool procd_trigger_wan6 'config' 'procd_trigger_wan6' '0' |
804 | | - config_get_bool sanity_check 'config' 'sanity_check' '1' |
805 | 806 | config_get_bool update_config_sizes 'config' 'update_config_sizes' '1' |
806 | 807 | config_get allowed_domain 'config' 'allowed_domain' |
807 | 808 | config_get blocked_domain 'config' 'blocked_domain' |
@@ -831,12 +832,13 @@ load_package_config() { |
831 | 832 | [ "$config_update_enabled" = '1' ] || unset config_update_enabled |
832 | 833 | [ "$debug_init_script" = '1' ] || unset debug_init_script |
833 | 834 | [ "$debug_performance" = '1' ] || unset debug_performance |
| 835 | + [ "$dnsmasq_sanity_check" = '1' ] || unset dnsmasq_sanity_check |
| 836 | + [ "$dnsmasq_validity_check" = '1' ] || unset dnsmasq_validity_check |
834 | 837 | [ "$enabled" = '1' ] || unset enabled |
835 | 838 | [ "$force_dns" = '1' ] || unset force_dns |
836 | 839 | [ "$ipv6_enabled" = '1' ] || unset ipv6_enabled |
837 | 840 | [ "$parallel_downloads" = '1' ] || unset parallel_downloads |
838 | 841 | [ "$procd_trigger_wan6" = '1' ] || unset procd_trigger_wan6 |
839 | | - [ "$sanity_check" = '1' ] || unset sanity_check |
840 | 842 | [ "$update_config_sizes" = '1' ] || unset update_config_sizes |
841 | 843 |
|
842 | 844 | dns_set_output_values "$dns" |
@@ -1820,67 +1822,70 @@ download_lists() { |
1820 | 1822 | esac |
1821 | 1823 |
|
1822 | 1824 | # Validate and remove invalid domain entries (RFC 1123 compliant) |
1823 | | - case "$dns" in |
1824 | | - dnsmasq.conf|dnsmasq.ipset|dnsmasq.nftset|dnsmasq.servers|dnsmasq.addnhosts) |
1825 | | - start_time=$(date +%s) |
1826 | | - step_title='Validating domain entries' |
1827 | | - output 2 "[PROC] ${step_title} " |
1828 | | - json set message "$(get_text 'statusProcessing'): ${step_title}" |
1829 | | - invalid_file="/tmp/${packageName}.invalid.tmp" |
1830 | | - rm -f "$invalid_file" |
1831 | | - # Fast validation: remove entries where domain: |
1832 | | - # - starts with dash or dot (invalid per RFC) |
1833 | | - # - is all numeric with dots (IP-like, invalid for domain) |
1834 | | - # - has consecutive dots |
1835 | | - # - ends with dash or dot (invalid per RFC) |
1836 | | - sed "$outputParseFilter" "$outputFile" | \ |
1837 | | - grep -E '^-|^\.|^[0-9.]+$|\.\.|-$|\.$' > "$invalid_file" 2>/dev/null || true |
1838 | | - if [ -s "$invalid_file" ]; then |
1839 | | - invalid_count=$(wc -l < "$invalid_file" 2>/dev/null || echo 0) |
1840 | | - if [ "$invalid_count" -gt 0 ]; then |
1841 | | - # Create pattern file for grep -vFf (fastest removal method) |
1842 | | - # Use appropriate prefix based on dns type |
1843 | | - case "$dns" in |
1844 | | - dnsmasq.conf) |
1845 | | - sed "$dnsmasqConfGrepPattern" "$invalid_file" > "${invalid_file}.pat" 2>/dev/null |
1846 | | - ;; |
1847 | | - dnsmasq.ipset) |
1848 | | - sed "$dnsmasqIpsetGrepPattern" "$invalid_file" > "${invalid_file}.pat" 2>/dev/null |
1849 | | - ;; |
1850 | | - dnsmasq.nftset) |
1851 | | - sed "$dnsmasqNftsetGrepPattern" "$invalid_file" > "${invalid_file}.pat" 2>/dev/null |
1852 | | - ;; |
1853 | | - dnsmasq.servers) |
1854 | | - sed "$dnsmasqServersGrepPattern" "$invalid_file" > "${invalid_file}.pat" 2>/dev/null |
1855 | | - ;; |
1856 | | - dnsmasq.addnhosts) |
1857 | | - # Create patterns for both IPv4 and IPv6 formats |
1858 | | - { sed "$dnsmasqAddnhostsGrepPatternIPv4" "$invalid_file"; sed "$dnsmasqAddnhostsGrepPatternIPv6" "$invalid_file"; } > "${invalid_file}.pat" 2>/dev/null |
1859 | | - ;; |
1860 | | - esac |
1861 | | - # Remove invalid entries |
1862 | | - grep -vFf "${invalid_file}.pat" "$outputFile" > "${outputFile}.valid" 2>/dev/null && \ |
1863 | | - mv "${outputFile}.valid" "$outputFile" 2>/dev/null |
1864 | | - # Report (limit to first 20 for performance) |
1865 | | - logger -t "$packageName" "Removed $invalid_count invalid entries from ${dns}." |
1866 | | - json add warning 'warningInvalidDomainsRemoved' "$invalid_count" |
1867 | | - rm -f "${invalid_file}.pat" |
1868 | | - fi |
| 1825 | + if [ -n "$dnsmasq_validity_check" ]; then |
| 1826 | + case "$dns" in |
| 1827 | + dnsmasq.conf|dnsmasq.ipset|dnsmasq.nftset|dnsmasq.servers|dnsmasq.addnhosts) |
| 1828 | + start_time=$(date +%s) |
| 1829 | + step_title='Validating domain entries' |
| 1830 | + output 2 "[PROC] ${step_title} " |
| 1831 | + json set message "$(get_text 'statusProcessing'): ${step_title}" |
| 1832 | + invalid_file="/tmp/${packageName}.invalid.tmp" |
1869 | 1833 | rm -f "$invalid_file" |
1870 | | - fi |
1871 | | - if [ "${invalid_count:-0}" -gt 0 ]; then |
1872 | | - output_warn |
1873 | | - else |
1874 | | - output_ok |
1875 | | - fi |
1876 | | - end_time=$(date +%s) |
1877 | | - elapsed=$(( end_time - start_time )) |
1878 | | - logger_debug "[PERF-DEBUG] ${step_title} took ${elapsed}s" |
1879 | | - ;; |
1880 | | - esac |
| 1834 | + # Fast validation: remove entries where domain: |
| 1835 | + # - starts with dash or dot (invalid per RFC) |
| 1836 | + # - is all numeric with dots (IP-like, invalid for domain) |
| 1837 | + # - has consecutive dots |
| 1838 | + # - ends with dash or dot (invalid per RFC) |
| 1839 | + sed "$outputParseFilter" "$outputFile" | \ |
| 1840 | + grep -E '^-|^\.|^[0-9.]+$|\.\.|-$|\.$' > "$invalid_file" 2>/dev/null || true |
| 1841 | + if [ -s "$invalid_file" ]; then |
| 1842 | + invalid_count=$(wc -l < "$invalid_file" 2>/dev/null || echo 0) |
| 1843 | + if [ "$invalid_count" -gt 0 ]; then |
| 1844 | + # Create pattern file for grep -vFf (fastest removal method) |
| 1845 | + # Use appropriate prefix based on dns type |
| 1846 | + case "$dns" in |
| 1847 | + dnsmasq.conf) |
| 1848 | + sed "$dnsmasqConfGrepPattern" "$invalid_file" > "${invalid_file}.pat" 2>/dev/null |
| 1849 | + ;; |
| 1850 | + dnsmasq.ipset) |
| 1851 | + sed "$dnsmasqIpsetGrepPattern" "$invalid_file" > "${invalid_file}.pat" 2>/dev/null |
| 1852 | + ;; |
| 1853 | + dnsmasq.nftset) |
| 1854 | + sed "$dnsmasqNftsetGrepPattern" "$invalid_file" > "${invalid_file}.pat" 2>/dev/null |
| 1855 | + ;; |
| 1856 | + dnsmasq.servers) |
| 1857 | + sed "$dnsmasqServersGrepPattern" "$invalid_file" > "${invalid_file}.pat" 2>/dev/null |
| 1858 | + ;; |
| 1859 | + dnsmasq.addnhosts) |
| 1860 | + # Create patterns for both IPv4 and IPv6 formats |
| 1861 | + { sed "$dnsmasqAddnhostsGrepPatternIPv4" "$invalid_file"; sed "$dnsmasqAddnhostsGrepPatternIPv6" "$invalid_file"; } > "${invalid_file}.pat" 2>/dev/null |
| 1862 | + ;; |
| 1863 | + esac |
| 1864 | + # Remove invalid entries |
| 1865 | + grep -vFf "${invalid_file}.pat" "$outputFile" > "${outputFile}.valid" 2>/dev/null && \ |
| 1866 | + mv "${outputFile}.valid" "$outputFile" 2>/dev/null |
| 1867 | + # Report (limit to first 20 for performance) |
| 1868 | + logger -t "$packageName" "Removed $invalid_count invalid entries from ${dns}." |
| 1869 | + json add warning 'warningInvalidDomainsRemoved' "$invalid_count" |
| 1870 | + rm -f "${invalid_file}.pat" |
| 1871 | + fi |
| 1872 | + rm -f "$invalid_file" |
| 1873 | + fi |
| 1874 | + if [ "${invalid_count:-0}" -gt 0 ]; then |
| 1875 | + output_warn |
| 1876 | + else |
| 1877 | + output_ok |
| 1878 | + fi |
| 1879 | + end_time=$(date +%s) |
| 1880 | + elapsed=$(( end_time - start_time )) |
| 1881 | + logger_debug "[PERF-DEBUG] ${step_title} took ${elapsed}s" |
| 1882 | + ;; |
| 1883 | + esac |
| 1884 | + fi |
1881 | 1885 |
|
1882 | | - output 2 '[PROC] Removing temporary files ' |
1883 | | - json set message "$(get_text 'statusProcessing'): removing temporary files" |
| 1886 | + step_title='Removing temporary files' |
| 1887 | + output 2 "[PROC] ${step_title} " |
| 1888 | + json set message "$(get_text 'statusProcessing'): ${step_title}" |
1884 | 1889 | if rm -f "/tmp/${packageName}_tmp."* "$ALLOWED_TMP" "$A_TMP" "$B_TMP" "$SED_TMP" "$outputCache"; then |
1885 | 1890 | output_ok |
1886 | 1891 | else |
@@ -2724,7 +2729,8 @@ load_validate_config() { |
2724 | 2729 | 'smartdns_instance:list(or(integer, string)):*' \ |
2725 | 2730 | 'heartbeat_domain:or("-", string):heartbeat.melmac.ca' \ |
2726 | 2731 | 'heartbeat_sleep_timeout:range(1,60):10' \ |
2727 | | - 'sanity_check:bool:1' \ |
| 2732 | + 'dnsmasq_sanity_check:bool:1' \ |
| 2733 | + 'dnsmasq_validity_check:bool:0' \ |
2728 | 2734 | 'update_config_sizes:bool:1' \ |
2729 | 2735 | 'allowed_domain:list(string)' \ |
2730 | 2736 | 'blocked_domain:list(string)' \ |
|
0 commit comments