You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
4.5 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=50
  3. USE_PROCD=1
  4. PROG=/usr/sbin/dnscrypt-proxy
  5. CONFIG_DIR=/var/etc
  6. USER=nobody
  7. dnscrypt_instance() {
  8. local config_path="$CONFIG_DIR/dnscrypt-proxy-$1.conf"
  9. create_config_file $1 "$config_path"
  10. procd_open_instance
  11. procd_set_param command $PROG "$config_path"
  12. procd_close_instance
  13. }
  14. create_config_file() {
  15. local address port resolver resolvers_list ephemeral_keys client_key log_level syslog syslog_prefix local_cache query_log_file block_ipv6 provider_name provider_key resolver_address
  16. local config_path="$2"
  17. local plugins_support_enabled=$(dnscrypt-proxy --version | grep 'Support for plugins: present' | wc -l)
  18. [ ! -d "$CONFIG_DIR" ] && mkdir -p "$CONFIG_DIR"
  19. [ -f "$config_path" ] && rm "$config_path"
  20. config_get address $1 'address' '127.0.0.1'
  21. config_get port $1 'port' '5353'
  22. config_get resolver $1 'resolver' ''
  23. config_get provider_name $1 'providername' ''
  24. config_get provider_key $1 'providerkey' ''
  25. config_get resolver_address $1 'resolveraddress' ''
  26. config_get resolvers_list $1 'resolvers_list' '/usr/share/dnscrypt-proxy/dnscrypt-resolvers.csv'
  27. config_get client_key $1 'client_key' ''
  28. config_get syslog_prefix $1 'syslog_prefix' 'dnscrypt-proxy'
  29. config_get query_log_file $1 'query_log_file' ''
  30. config_get log_level $1 'log_level' '6'
  31. config_get_bool syslog $1 'syslog' '1'
  32. config_get_bool ephemeral_keys $1 'ephemeral_keys' '0'
  33. config_get_bool local_cache $1 'local_cache' '0'
  34. config_get_bool block_ipv6 $1 'block_ipv6' '0'
  35. append_param_not_empty "ResolverName" "$resolver" $config_path
  36. append_param "ResolversList" "$resolvers_list" $config_path
  37. append_param_not_empty "ProviderName" "$provider_name" $config_path
  38. append_param_not_empty "ProviderKey" "$provider_key" $config_path
  39. append_param_not_empty "ResolverAddress" "$resolver_address" $config_path
  40. append_param "User" "$USER" $config_path
  41. append_param "LocalAddress" "$address:$port" $config_path
  42. append_param_not_empty "ClientKey" "$client_key" $config_path
  43. append_on_off "EphemeralKeys" $ephemeral_keys $config_path
  44. append_param "LogLevel" "$log_level" $config_path
  45. append_on_off "Syslog" $syslog $config_path
  46. append_param "SyslogPrefix" "$syslog_prefix" $config_path
  47. append_on_off "LocalCache" $local_cache $config_path
  48. append_param_not_empty "QueryLogFile" "$query_log_file" $config_path
  49. if [ $plugins_support_enabled -ne 0 ]
  50. then
  51. append_yes_no "BlockIPv6" $block_ipv6 $config_path
  52. else
  53. log_ignored_param "block_ipv6"
  54. fi
  55. if [ $plugins_support_enabled -ne 0 ]
  56. then
  57. config_list_foreach $1 'blacklist' append_blacklists $config_path
  58. else
  59. log_ignored_param "blacklist"
  60. fi
  61. }
  62. log_ignored_param() {
  63. local param_name=$1
  64. logger -t dnscrypt-proxy -p user.warn dnscrypt-proxy plugins support not present, ignoring $param_name parameter...
  65. }
  66. append_on_off() {
  67. local param_name=$1
  68. local param_value=$2
  69. local config_path=$3
  70. local value
  71. if [ $param_value -eq 1 ]
  72. then
  73. value="on"
  74. else
  75. value="off"
  76. fi
  77. echo "$param_name $value" >> $config_path
  78. }
  79. append_yes_no() {
  80. local param_name=$1
  81. local param_value=$2
  82. local config_path=$3
  83. local value
  84. if [ $param_value -eq 1 ]
  85. then
  86. value="yes"
  87. else
  88. value="no"
  89. fi
  90. echo "$param_name $value" >> $config_path
  91. }
  92. append_param() {
  93. local param_name=$1
  94. local param_value=$2
  95. local config_path=$3
  96. echo "$param_name $param_value" >> $config_path
  97. }
  98. append_param_not_empty() {
  99. local param_name=$1
  100. local param_value=$2
  101. local config_path=$3
  102. if [ ! -z "$param_value" -a "$param_value" != " " ]
  103. then
  104. append_param "$param_name" "$param_value" "$config_path"
  105. fi
  106. }
  107. append_blacklists() {
  108. local value="$1"
  109. local config_path="$2"
  110. append_param_not_empty "BlackList" "$value" $config_path
  111. }
  112. start_service() {
  113. config_load dnscrypt-proxy
  114. config_foreach dnscrypt_instance dnscrypt-proxy
  115. }
  116. service_triggers() {
  117. procd_add_reload_trigger 'dnscrypt-proxy'
  118. }