Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #!/system/bin/sh
  2.  
  3. DNSCRYPT_PROXY="/system/xbin/dnscrypt-proxy"
  4. CONFFILE="/data/local/dnscrypt-proxy/dnscrypt-proxy.toml"
  5. PIDFILE="/data/local/tmp/dnscrypt-proxy.pid"
  6. APPEND="-A"
  7. WAITFORDAEMON=10
  8. STOP=0
  9. nohup="nohup"
  10.  
  11. _log() {
  12. log -p i -t dnscrypt-init -- $1
  13. echo "$1" 1>&2
  14. }
  15.  
  16. _wait_for_pid() {
  17. cnt=0
  18.  
  19. while true ; do
  20. sleep 1
  21.  
  22. if test -s "$PIDFILE" ; then
  23. pid=$(cat "$PIDFILE")
  24.  
  25. if kill -0 $pid 2>/dev/null ; then
  26. return 0
  27. fi
  28. fi
  29.  
  30. [ "`expr $cnt % 3`" != 2 ] || _log "."
  31.  
  32. cnt=`expr $cnt + 1`
  33. if [ $cnt -gt $WAITFORDAEMON ] ; then
  34. break
  35. fi
  36. done
  37.  
  38. return 1
  39. }
  40.  
  41. ## Begin
  42.  
  43. if [ "$1" = "--debug" ] ; then
  44. nohup=""
  45. _log "Attempting to run dnscrypt-proxy in foreground"
  46. fi
  47.  
  48. if [ "$1" = "--stop" ] ; then
  49. STOP=1
  50. APPEND="-D"
  51. _log "Stopping dnscrypt-proxy"
  52. else
  53. _log "Starting dnscrypt-proxy"
  54. fi
  55.  
  56. if [ -s "$PIDFILE" ] ; then
  57. # if dnscrypt-proxy is running, kill
  58. kill $(cat "$PIDFILE")
  59. rm -f "$PIDFILE"
  60. fi
  61.  
  62. if [ $STOP -eq 0 ] ; then
  63. cmd="""$DNSCRYPT_PROXY"" -config ""$CONFFILE"" -pidfile=""$PIDFILE"""
  64.  
  65. if [ "$nohup" != "" ] ; then
  66. $nohup $cmd >/dev/null 2>&1 &
  67. _wait_for_pid
  68. if [ $? -ne 0 ] ; then
  69. # delete iptable rule
  70. APPEND="-D"
  71. _log "failed to start dnscrypt-proxy"
  72. _log "Try running '$0 --debug' or enable logging and check the logs for errors"
  73. exit 1
  74. fi
  75. else
  76. $cmd
  77. fi
  78. fi
  79.  
  80. iptables -t nat $APPEND OUTPUT -p tcp --dport 53 -j DNAT --to-destination 127.0.0.1:533
  81. iptables -t nat $APPEND OUTPUT -p udp --dport 53 -j DNAT --to-destination 127.0.0.1:533
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement