本文整理汇总了Python中txtorcon.TorConfig.User方法的典型用法代码示例。如果您正苦于以下问题:Python TorConfig.User方法的具体用法?Python TorConfig.User怎么用?Python TorConfig.User使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类txtorcon.TorConfig
的用法示例。
在下文中一共展示了TorConfig.User方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_tor_config
# 需要导入模块: from txtorcon import TorConfig [as 别名]
# 或者: from txtorcon.TorConfig import User [as 别名]
def get_tor_config():
tor_config = TorConfig()
if config.tor.control_port is None:
config.tor.control_port = int(randomFreePort())
if config.tor.socks_port is None:
config.tor.socks_port = int(randomFreePort())
tor_config.ControlPort = config.tor.control_port
tor_config.SocksPort = config.tor.socks_port
if config.tor.data_dir:
data_dir = os.path.expanduser(config.tor.data_dir)
# We only use the Tor data dir specified in the config file if
# 1. It is not locked (i.e. another process is using it)
# 2. We have write permissions to it
data_dir_usable = is_tor_data_dir_usable(data_dir)
try:
mkdir_p(data_dir)
except OSError as ose:
if ose.errno == errno.EACCESS:
data_dir_usable = False
else:
raise
if data_dir_usable:
tor_config.DataDirectory = data_dir
if config.tor.bridges:
tor_config.UseBridges = 1
if config.advanced.obfsproxy_binary:
tor_config.ClientTransportPlugin = (
'obfs2,obfs3 exec %s managed' %
config.advanced.obfsproxy_binary
)
bridges = []
with open(config.tor.bridges) as f:
for bridge in f:
if 'obfs' in bridge:
if config.advanced.obfsproxy_binary:
bridges.append(bridge.strip())
else:
bridges.append(bridge.strip())
tor_config.Bridge = bridges
if config.tor.torrc:
for i in config.tor.torrc.keys():
setattr(tor_config, i, config.tor.torrc[i])
if os.geteuid() == 0:
tor_config.User = pwd.getpwuid(os.geteuid()).pw_name
tor_config.save()
log.debug("Setting control port as %s" % tor_config.ControlPort)
log.debug("Setting SOCKS port as %s" % tor_config.SocksPort)
return tor_config
示例2: startTor
# 需要导入模块: from txtorcon import TorConfig [as 别名]
# 或者: from txtorcon.TorConfig import User [as 别名]
def startTor(self):
""" Starts Tor
Launches a Tor with :param: socks_port :param: control_port
:param: tor_binary set in ooniprobe.conf
"""
log.msg("Starting Tor...")
from txtorcon import TorConfig
tor_config = TorConfig()
if config.tor.control_port is None:
config.tor.control_port = int(randomFreePort())
if config.tor.socks_port is None:
config.tor.socks_port = int(randomFreePort())
tor_config.ControlPort = config.tor.control_port
tor_config.SocksPort = config.tor.socks_port
if config.tor.data_dir:
data_dir = os.path.expanduser(config.tor.data_dir)
if not os.path.exists(data_dir):
log.msg("%s does not exist. Creating it." % data_dir)
os.makedirs(data_dir)
tor_config.DataDirectory = data_dir
if config.tor.bridges:
tor_config.UseBridges = 1
if config.advanced.obfsproxy_binary:
tor_config.ClientTransportPlugin = (
'obfs2,obfs3 exec %s managed' %
config.advanced.obfsproxy_binary
)
bridges = []
with open(config.tor.bridges) as f:
for bridge in f:
if 'obfs' in bridge:
if config.advanced.obfsproxy_binary:
bridges.append(bridge.strip())
else:
bridges.append(bridge.strip())
tor_config.Bridge = bridges
if config.tor.torrc:
for i in config.tor.torrc.keys():
setattr(tor_config, i, config.tor.torrc[i])
if os.geteuid() == 0:
tor_config.User = pwd.getpwuid(os.geteuid()).pw_name
tor_config.save()
log.debug("Setting control port as %s" % tor_config.ControlPort)
log.debug("Setting SOCKS port as %s" % tor_config.SocksPort)
return start_tor(tor_config)
示例3: _configTor
# 需要导入模块: from txtorcon import TorConfig [as 别名]
# 或者: from txtorcon.TorConfig import User [as 别名]
def _configTor():
torconfig = TorConfig()
if config.main.socks_port is None:
config.main.socks_port = int(randomFreePort())
torconfig.SocksPort = config.main.socks_port
if config.main.control_port is None:
config.main.control_port = int(randomFreePort())
torconfig.ControlPort = config.main.control_port
if config.main.tor2webmode is True:
torconfig.Tor2webMode = 1
torconfig.CircuitBuildTimeout = 60
if config.main.tor_datadir is None:
temporary_data_dir = tempfile.mkdtemp()
log.warn("Option 'tor_datadir' in oonib.conf is unspecified!")
log.warn("Using %s" % temporary_data_dir)
torconfig.DataDirectory = temporary_data_dir
uid = -1
gid = -1
if config.main.uid is not None:
uid = config.main.uid
if config.main.gid is not None:
gid = config.main.gid
os.chown(temporary_data_dir, uid, gid)
else:
if os.path.exists(config.main.tor_datadir):
torconfig.DataDirectory = os.path.abspath(config.main.tor_datadir)
else:
raise Exception("Could not find tor datadir")
if config.main.uid is not None:
try:
user = pwd.getpwuid(config.main.uid)[0]
except KeyError:
raise Exception("Invalid user ID")
torconfig.User = user
tor_log_file = os.path.join(torconfig.DataDirectory, "tor.log")
torconfig.Log = ["notice stdout", "notice file %s" % tor_log_file]
torconfig.save()
return torconfig
示例4: startTor
# 需要导入模块: from txtorcon import TorConfig [as 别名]
# 或者: from txtorcon.TorConfig import User [as 别名]
def startTor(self):
""" Starts Tor
Launches a Tor with :param: socks_port :param: control_port
:param: tor_binary set in ooniprobe.conf
"""
log.msg("Starting Tor...")
@defer.inlineCallbacks
def state_complete(state):
config.tor_state = state
log.msg("Successfully bootstrapped Tor")
log.debug("We now have the following circuits: ")
for circuit in state.circuits.values():
log.debug(" * %s" % circuit)
socks_port = yield state.protocol.get_conf("SocksPort")
control_port = yield state.protocol.get_conf("ControlPort")
config.tor.socks_port = int(socks_port.values()[0])
config.tor.control_port = int(control_port.values()[0])
def setup_failed(failure):
log.exception(failure)
raise errors.UnableToStartTor
def setup_complete(proto):
"""
Called when we read from stdout that Tor has reached 100%.
"""
log.debug("Building a TorState")
config.tor.protocol = proto
state = TorState(proto.tor_protocol)
state.post_bootstrap.addCallback(state_complete)
state.post_bootstrap.addErrback(setup_failed)
return state.post_bootstrap
def updates(prog, tag, summary):
log.msg("%d%%: %s" % (prog, summary))
tor_config = TorConfig()
if config.tor.control_port:
tor_config.ControlPort = config.tor.control_port
if config.tor.socks_port:
tor_config.SocksPort = config.tor.socks_port
if config.tor.data_dir:
data_dir = os.path.expanduser(config.tor.data_dir)
if not os.path.exists(data_dir):
log.msg("%s does not exist. Creating it." % data_dir)
os.makedirs(data_dir)
tor_config.DataDirectory = data_dir
if config.tor.bridges:
tor_config.UseBridges = 1
if config.advanced.obfsproxy_binary:
tor_config.ClientTransportPlugin = (
'obfs2,obfs3 exec %s managed' %
config.advanced.obfsproxy_binary
)
bridges = []
with open(config.tor.bridges) as f:
for bridge in f:
if 'obfs' in bridge:
if config.advanced.obfsproxy_binary:
bridges.append(bridge.strip())
else:
bridges.append(bridge.strip())
tor_config.Bridge = bridges
if config.tor.torrc:
for i in config.tor.torrc.keys():
setattr(tor_config, i, config.tor.torrc[i])
if os.geteuid() == 0:
tor_config.User = pwd.getpwuid(os.geteuid()).pw_name
tor_config.save()
if not hasattr(tor_config, 'ControlPort'):
control_port = int(randomFreePort())
tor_config.ControlPort = control_port
config.tor.control_port = control_port
if not hasattr(tor_config, 'SocksPort'):
socks_port = int(randomFreePort())
tor_config.SocksPort = socks_port
config.tor.socks_port = socks_port
tor_config.save()
log.debug("Setting control port as %s" % tor_config.ControlPort)
log.debug("Setting SOCKS port as %s" % tor_config.SocksPort)
if config.advanced.tor_binary:
d = launch_tor(tor_config, reactor,
tor_binary=config.advanced.tor_binary,
progress_updates=updates)
else:
d = launch_tor(tor_config, reactor,
#.........这里部分代码省略.........