1
0

dnscrypt-proxy.init 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 syslog syslog_prefix local_cache query_log_file block_ipv6
  16. local config_path="$2"
  17. [ ! -d "$CONFIG_DIR" ] && mkdir -p "$CONFIG_DIR"
  18. [ -f "$config_path" ] && rm "$config_path"
  19. config_get address $1 'address' '127.0.0.1'
  20. config_get port $1 'port' '5353'
  21. config_get resolver $1 'resolver' ''
  22. config_get resolvers_list $1 'resolvers_list' '/usr/share/dnscrypt-proxy/dnscrypt-resolvers.csv'
  23. config_get client_key $1 'client_key' ''
  24. config_get syslog_prefix $1 'syslog_prefix' 'dnscrypt-proxy'
  25. config_get query_log_file $1 'query_log_file' ''
  26. config_get_bool syslog $1 'syslog' '1'
  27. config_get_bool ephemeral_keys $1 'ephemeral_keys' '0'
  28. config_get_bool local_cache $1 'local_cache' '0'
  29. config_get_bool block_ipv6 $1 'block_ipv6' '0'
  30. append_param_not_empty "ResolverName" "$resolver" $config_path
  31. append_param "ResolversList" "$resolvers_list" $config_path
  32. append_param "User" "$USER" $config_path
  33. append_param "LocalAddress" "$address:$port" $config_path
  34. append_param_not_empty "ClientKey" "$client_key" $config_path
  35. append_on_off "EphemeralKeys" $ephemeral_keys $config_path
  36. append_on_off "Syslog" $syslog $config_path
  37. append_param "SyslogPrefix" "$syslog_prefix" $config_path
  38. append_on_off "LocalCache" $local_cache $config_path
  39. append_param_not_empty "QueryLogFile" "$query_log_file" $config_path
  40. append_yes_no "BlockIPv6" $block_ipv6 $config_path
  41. config_list_foreach $1 'blacklist' append_blacklists $config_path
  42. }
  43. append_on_off() {
  44. local param_name=$1
  45. local param_value=$2
  46. local config_path=$3
  47. local value
  48. if [ $param_value -eq 1 ]
  49. then
  50. value="on"
  51. else
  52. value="off"
  53. fi
  54. echo "$param_name $value" >> $config_path
  55. }
  56. append_yes_no() {
  57. local param_name=$1
  58. local param_value=$2
  59. local config_path=$3
  60. local value
  61. if [ $param_value -eq 1 ]
  62. then
  63. value="yes"
  64. else
  65. value="no"
  66. fi
  67. echo "$param_name $value" >> $config_path
  68. }
  69. append_param() {
  70. local param_name=$1
  71. local param_value=$2
  72. local config_path=$3
  73. echo "$param_name $param_value" >> $config_path
  74. }
  75. append_param_not_empty() {
  76. local param_name=$1
  77. local param_value=$2
  78. local config_path=$3
  79. if [ ! -z "$param_value" -a "$param_value" != " " ]
  80. then
  81. append_param "$param_name" "$param_value" "$config_path"
  82. fi
  83. }
  84. append_blacklists() {
  85. local value="$1"
  86. local config_path="$2"
  87. append_param_not_empty "BlackList" "$value" $config_path
  88. }
  89. start_service() {
  90. config_load dnscrypt-proxy
  91. config_foreach dnscrypt_instance dnscrypt-proxy
  92. }
  93. service_triggers() {
  94. procd_add_reload_trigger 'dnscrypt-proxy'
  95. }