CreateWebProxyProcess 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #!/usr/bin/env bash
  2. # shellcheck shell=bash
  3. # ``````````````````````````````````````````````````````````````````````````````
  4. # Function name: CreateWebProxyProcess()
  5. #
  6. # Description:
  7. # It creates web proxy process like a polipo, privoxy or hpts
  8. #
  9. # Usage:
  10. # CreateWebProxyProcess
  11. #
  12. # Examples:
  13. # CreateWebProxyProcess
  14. #
  15. function CreateWebProxyProcess() {
  16. # shellcheck disable=SC2034
  17. local _FUNCTION_ID="CreateWebProxyProcess"
  18. local _STATE=0
  19. local _proxy_http_state=0
  20. # shellcheck disable=SC2154
  21. if [[ "$frontend_type" == "haproxy" ]] ; then
  22. # shellcheck disable=SC2154
  23. if [[ "$proxy_type" = *"polipo"* ]] || \
  24. [[ "$proxy_type" = *"privoxy"* ]] || \
  25. [[ "$proxy_type" = *"hpts"* ]] ; then
  26. if [[ "$proxy_type" == "polipo" ]] ; then
  27. # shellcheck disable=SC2154
  28. _pfd="${_tml_po1}.${_bk_port_new}"
  29. # shellcheck disable=SC2154
  30. cp "${_tml_po0}" "${_pfd}"
  31. printf "proxyPort = %d\\n" "$_bk_port_new" \
  32. >>"${_pfd}"
  33. # shellcheck disable=SC2154
  34. printf "socksParentProxy = \"127.0.0.1:%d\"\\n" "$_bk_port" \
  35. >>"${_pfd}"
  36. _proxy_http_state=1
  37. _logger "info" \
  38. "${_FUNCTION_ID}()" \
  39. "added backend port (polipo): '$_bk_port'"
  40. polipo -c "${_pfd}"
  41. elif [[ "$proxy_type" == "privoxy" ]] ; then
  42. # shellcheck disable=SC2154
  43. _pfd="${_tml_po1}.${_bk_port_new}"
  44. # shellcheck disable=SC2154
  45. cp "${_tml_po0}" "${_pfd}"
  46. # https://github.com/trimstray/multitor/issues/15
  47. # shellcheck disable=SC2154,SC2129
  48. # printf "logfile privoxy.%d\\n" "$_bk_port_new" \
  49. # >>"${_pfd}"
  50. # shellcheck disable=SC2154,SC2129
  51. printf "listen-address 127.0.0.1:%d\\n" "$_bk_port_new" \
  52. >>"${_pfd}"
  53. # shellcheck disable=SC2154,SC2129
  54. printf "forward-socks5t / 127.0.0.1:%d .\\n" "$_bk_port" \
  55. >>"${_pfd}"
  56. # shellcheck disable=SC2034
  57. _proxy_http_state=1
  58. _logger "info" \
  59. "${_FUNCTION_ID}()" \
  60. "added backend port (privoxy): '$_bk_port'"
  61. privoxy "${_pfd}"
  62. elif [[ "$proxy_type" == "hpts" ]] ; then
  63. # shellcheck disable=SC2034
  64. _proxy_http_state=1
  65. _logger "info" \
  66. "${_FUNCTION_ID}()" \
  67. "added backend port (hpts): '$_bk_port'"
  68. hpts -s 127.0.0.1:"${_bk_port}" -p "${_bk_port_new}" >/dev/null 2>&1 &
  69. fi
  70. fi
  71. else
  72. # shellcheck disable=SC2154
  73. if [[ "$proxy_type" = *"polipo"* ]] || \
  74. [[ "$proxy_type" = *"privoxy"* ]] || \
  75. [[ "$proxy_type" = *"hpts"* ]] ; then
  76. if [[ "$proxy_type" == "polipo" ]] ; then
  77. # shellcheck disable=SC2154
  78. # _pfd="${_tml_po1}.${_bk_port_new}"
  79. _pfd="${_tml_po1}"
  80. # shellcheck disable=SC2154
  81. cp "${_tml_po0}" "${_pfd}"
  82. printf "proxyPort = %d\\n" "$_bk_port_new" \
  83. >>"${_pfd}"
  84. # shellcheck disable=SC2154
  85. printf "socksParentProxy = \"127.0.0.1:%d\"\\n" "$_bk_port" \
  86. >>"${_pfd}"
  87. _proxy_http_state=1
  88. _logger "info" \
  89. "${_FUNCTION_ID}()" \
  90. "added backend port (polipo): '$_bk_port'"
  91. polipo -c "${_pfd}"
  92. elif [[ "$proxy_type" == "privoxy" ]] ; then
  93. # shellcheck disable=SC2154
  94. # _pfd="${_tml_po1}.${_bk_port_new}"
  95. _pfd="${_tml_po1}"
  96. # shellcheck disable=SC2154
  97. cp "${_tml_po0}" "${_pfd}"
  98. # https://github.com/trimstray/multitor/issues/15
  99. # shellcheck disable=SC2154,SC2129
  100. # printf "logfile privoxy.%d\\n" "$_bk_port_new" \
  101. # >>"${_pfd}"
  102. # shellcheck disable=SC2154,SC2129
  103. printf "listen-address 127.0.0.1:%d\\n" "$_bk_port_new" \
  104. >>"${_pfd}"
  105. # shellcheck disable=SC2154,SC2129
  106. printf "forward-socks5t / 127.0.0.1:%d .\\n" "$_bk_port" \
  107. >>"${_pfd}"
  108. # shellcheck disable=SC2034
  109. _proxy_http_state=1
  110. _logger "info" \
  111. "${_FUNCTION_ID}()" \
  112. "added backend port (privoxy): '$_bk_port'"
  113. privoxy "${_pfd}"
  114. elif [[ "$proxy_type" == "hpts" ]] ; then
  115. # shellcheck disable=SC2034
  116. _proxy_http_state=1
  117. _logger "info" \
  118. "${_FUNCTION_ID}()" \
  119. "added backend port (hpts): '$_bk_port'"
  120. hpts -s 127.0.0.1:"${_bk_port}" -p "${_bk_port_new}" >/dev/null 2>&1 &
  121. fi
  122. fi
  123. fi
  124. return $_STATE
  125. }