switching from HTTP proxy to SOCKS proxy for --tor (sick and tired of Polipo/Privoxy bull; either Tor flag is overwritten every here and there or they are putting all kinds of filter warnings)

This commit is contained in:
Miroslav Stampar 2011-11-23 21:17:08 +00:00
parent 8ea9b19b66
commit ba4234dc42
2 changed files with 31 additions and 8 deletions

View File

@ -25,6 +25,7 @@ import lib.core.threads
from extra.keepalive import keepalive from extra.keepalive import keepalive
from extra.oset.pyoset import oset from extra.oset.pyoset import oset
from extra.socks import socks
from lib.controller.checks import checkConnection from lib.controller.checks import checkConnection
from lib.core.common import Backend from lib.core.common import Backend
from lib.core.common import dataToStdout from lib.core.common import dataToStdout
@ -1674,11 +1675,21 @@ def __setTrafficOutputFP():
conf.trafficFP = openFile(conf.trafficFile, "w+") conf.trafficFP = openFile(conf.trafficFile, "w+")
def __setTorProxySettings(): def __setTorSocksProxySettings():
if not conf.tor: if not conf.tor:
return return
infoMsg = "setting Tor proxy settings" infoMsg = "setting Tor SOCKS proxy settings"
logger.info(infoMsg)
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, 'localhost', 9050)
socks.wrapmodule(urllib2)
def __setTorHTTPProxySettings():
if not conf.tor:
return
infoMsg = "setting Tor HTTP proxy settings"
logger.info(infoMsg) logger.info(infoMsg)
found = None found = None
@ -1852,7 +1863,7 @@ def init(inputOptions=AttribDict(), overrideOptions=False):
__cleanupOptions() __cleanupOptions()
__checkDependencies() __checkDependencies()
__basicOptionValidation() __basicOptionValidation()
__setTorProxySettings() __setTorSocksProxySettings()
__setMultipleTargets() __setMultipleTargets()
__setTamperingFunctions() __setTamperingFunctions()
__setTrafficOutputFP() __setTrafficOutputFP()

View File

@ -15,7 +15,9 @@ import urllib2
import urlparse import urlparse
import traceback import traceback
from extra.socks.socks import GeneralProxyError
from extra.multipart import multipartpost from extra.multipart import multipartpost
from lib.core.agent import agent from lib.core.agent import agent
from lib.core.common import asciifyUrl from lib.core.common import asciifyUrl
from lib.core.common import average from lib.core.common import average
@ -92,10 +94,20 @@ class Connect:
warnMsg += "lower the --time-sec value (e.g. --time-sec=2)" warnMsg += "lower the --time-sec value (e.g. --time-sec=2)"
singleTimeWarnMessage(warnMsg) singleTimeWarnMessage(warnMsg)
elif kb.originalPage is None: elif kb.originalPage is None:
warnMsg = "if the problem persists please check that the provided " if conf.tor:
warnMsg += "target url is valid. If it is, you can try to rerun " warnMsg = "please make sure that you have "
warnMsg += "with the --random-agent switch turned on " warnMsg += "Tor installed and running so "
warnMsg += "and/or proxy switches (--ignore-proxy, --proxy,...)" warnMsg += "you could successfully use "
warnMsg += "--tor switch "
if IS_WIN:
warnMsg += "(e.g. https://www.torproject.org/download/download.html.en)"
else:
warnMsg += "(e.g. https://help.ubuntu.com/community/Tor)"
else:
warnMsg = "if the problem persists please check that the provided "
warnMsg += "target url is valid. If it is, you can try to rerun "
warnMsg += "with the --random-agent switch turned on "
warnMsg += "and/or proxy switches (--ignore-proxy, --proxy,...)"
singleTimeWarnMessage(warnMsg) singleTimeWarnMessage(warnMsg)
elif conf.threads > 1: elif conf.threads > 1:
warnMsg = "if the problem persists please try to lower " warnMsg = "if the problem persists please try to lower "
@ -440,7 +452,7 @@ class Connect:
processResponse(page, responseHeaders) processResponse(page, responseHeaders)
return page, responseHeaders, code return page, responseHeaders, code
except (urllib2.URLError, socket.error, socket.timeout, httplib.BadStatusLine, httplib.IncompleteRead), e: except (urllib2.URLError, socket.error, socket.timeout, httplib.BadStatusLine, httplib.IncompleteRead, GeneralProxyError), e:
tbMsg = traceback.format_exc() tbMsg = traceback.format_exc()
if "no host given" in tbMsg: if "no host given" in tbMsg: