123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- #!/usr/bin/env bash
- # shellcheck shell=bash
- # ``````````````````````````````````````````````````````````````````````````````
- # Function name: CreateWebProxyProcess()
- #
- # Description:
- # It creates web proxy process like a polipo, privoxy or hpts
- #
- # Usage:
- # CreateWebProxyProcess
- #
- # Examples:
- # CreateWebProxyProcess
- #
- function CreateWebProxyProcess() {
- # shellcheck disable=SC2034
- local _FUNCTION_ID="CreateWebProxyProcess"
- local _STATE=0
- local _proxy_http_state=0
- # shellcheck disable=SC2154
- if [[ "$frontend_type" == "haproxy" ]] ; then
- # shellcheck disable=SC2154
- if [[ "$proxy_type" = *"polipo"* ]] || \
- [[ "$proxy_type" = *"privoxy"* ]] || \
- [[ "$proxy_type" = *"hpts"* ]] ; then
- if [[ "$proxy_type" == "polipo" ]] ; then
- # shellcheck disable=SC2154
- _pfd="${_tml_po1}.${_bk_port_new}"
- # shellcheck disable=SC2154
- cp "${_tml_po0}" "${_pfd}"
- printf "proxyPort = %d\\n" "$_bk_port_new" \
- >>"${_pfd}"
- # shellcheck disable=SC2154
- printf "socksParentProxy = \"127.0.0.1:%d\"\\n" "$_bk_port" \
- >>"${_pfd}"
- _proxy_http_state=1
- _logger "info" \
- "${_FUNCTION_ID}()" \
- "added backend port (polipo): '$_bk_port'"
- polipo -c "${_pfd}"
- elif [[ "$proxy_type" == "privoxy" ]] ; then
- # shellcheck disable=SC2154
- _pfd="${_tml_po1}.${_bk_port_new}"
- # shellcheck disable=SC2154
- cp "${_tml_po0}" "${_pfd}"
- # https://github.com/trimstray/multitor/issues/15
- # shellcheck disable=SC2154,SC2129
- # printf "logfile privoxy.%d\\n" "$_bk_port_new" \
- # >>"${_pfd}"
- # shellcheck disable=SC2154,SC2129
- printf "listen-address 127.0.0.1:%d\\n" "$_bk_port_new" \
- >>"${_pfd}"
- # shellcheck disable=SC2154,SC2129
- printf "forward-socks5t / 127.0.0.1:%d .\\n" "$_bk_port" \
- >>"${_pfd}"
- # shellcheck disable=SC2034
- _proxy_http_state=1
- _logger "info" \
- "${_FUNCTION_ID}()" \
- "added backend port (privoxy): '$_bk_port'"
- privoxy "${_pfd}"
- elif [[ "$proxy_type" == "hpts" ]] ; then
- # shellcheck disable=SC2034
- _proxy_http_state=1
- _logger "info" \
- "${_FUNCTION_ID}()" \
- "added backend port (hpts): '$_bk_port'"
- hpts -s 127.0.0.1:"${_bk_port}" -p "${_bk_port_new}" >/dev/null 2>&1 &
- fi
- fi
- else
- # shellcheck disable=SC2154
- if [[ "$proxy_type" = *"polipo"* ]] || \
- [[ "$proxy_type" = *"privoxy"* ]] || \
- [[ "$proxy_type" = *"hpts"* ]] ; then
- if [[ "$proxy_type" == "polipo" ]] ; then
- # shellcheck disable=SC2154
- # _pfd="${_tml_po1}.${_bk_port_new}"
- _pfd="${_tml_po1}"
- # shellcheck disable=SC2154
- cp "${_tml_po0}" "${_pfd}"
- printf "proxyPort = %d\\n" "$_bk_port_new" \
- >>"${_pfd}"
- # shellcheck disable=SC2154
- printf "socksParentProxy = \"127.0.0.1:%d\"\\n" "$_bk_port" \
- >>"${_pfd}"
- _proxy_http_state=1
- _logger "info" \
- "${_FUNCTION_ID}()" \
- "added backend port (polipo): '$_bk_port'"
- polipo -c "${_pfd}"
- elif [[ "$proxy_type" == "privoxy" ]] ; then
- # shellcheck disable=SC2154
- # _pfd="${_tml_po1}.${_bk_port_new}"
- _pfd="${_tml_po1}"
- # shellcheck disable=SC2154
- cp "${_tml_po0}" "${_pfd}"
- # https://github.com/trimstray/multitor/issues/15
- # shellcheck disable=SC2154,SC2129
- # printf "logfile privoxy.%d\\n" "$_bk_port_new" \
- # >>"${_pfd}"
- # shellcheck disable=SC2154,SC2129
- printf "listen-address 127.0.0.1:%d\\n" "$_bk_port_new" \
- >>"${_pfd}"
- # shellcheck disable=SC2154,SC2129
- printf "forward-socks5t / 127.0.0.1:%d .\\n" "$_bk_port" \
- >>"${_pfd}"
- # shellcheck disable=SC2034
- _proxy_http_state=1
- _logger "info" \
- "${_FUNCTION_ID}()" \
- "added backend port (privoxy): '$_bk_port'"
- privoxy "${_pfd}"
- elif [[ "$proxy_type" == "hpts" ]] ; then
- # shellcheck disable=SC2034
- _proxy_http_state=1
- _logger "info" \
- "${_FUNCTION_ID}()" \
- "added backend port (hpts): '$_bk_port'"
- hpts -s 127.0.0.1:"${_bk_port}" -p "${_bk_port_new}" >/dev/null 2>&1 &
- fi
- fi
- fi
- return $_STATE
- }
|