diff --git a/oml/tor.py b/oml/tor.py index b9dbf5c..98bc945 100644 --- a/oml/tor.py +++ b/oml/tor.py @@ -44,17 +44,18 @@ SocksPort 9830 ControlPort 9831 CookieAuthentication 1 '''.strip()) + tor_data = os.path.join(settings.data_path, 'TorData') if not os.path.exists(torrc): with open(torrc, 'w') as fd: fd.write(''' -DataDirectory {base}/TorData +DataDirectory {tor_data} DirReqStatistics 0 - '''.strip().format(base=settings.data_path)) + '''.strip().format(tor_data=tor_data)) else: with open(torrc, 'r') as fd: data = fd.read() - modified_data = re.sub('DataDirectory.*?/TorData', - 'DataDirectory {base}/TorData'.format(base=settings.data_path), data) + modified_data = re.sub('DataDirectory.*?TorData', + 'DataDirectory {tor_data}'.format(tor_data=tor_data), data) if data != modified_data: with open(torrc, 'w') as fd: fd.write(modified_data) @@ -63,6 +64,7 @@ DirReqStatistics 0 def run(self): defaults, torrc = self.create_torrc() + tor_data = os.path.join(settings.data_path, 'TorData') tor = get_tor() if not tor: self._status.append('No tor binary found. Please install TorBrowser or tor') @@ -77,7 +79,8 @@ DirReqStatistics 0 } else: env = None - cmd = [tor, '--defaults-torrc', defaults, '-f', torrc] + cmd = [tor, '--defaults-torrc', defaults, '-f', torrc, 'DataDirectory', tor_data] + cmd += self.geoip(tor) while self.running: self.p = subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1, universal_newlines=True, start_new_session=True, env=env) @@ -87,6 +90,17 @@ DirReqStatistics 0 time.sleep(0.5) self.p = None + def geoip(self, tor): + geo = [] + tordir = os.path.dirname(os.path.dirname(tor)) + gepipfile = os.path.join(tordir, 'Data', 'Tor', 'geoip') + gepipv6file = os.path.join(tordir, 'Data', 'Tor', 'geoip6') + if os.path.exists(gepipfile): + geo += ['GeoIPFile', gepipfile] + if os.path.exists(gepipv6file): + geo += ['GeoIPv6File', gepipv6file] + return geo + def kill(self): self.running = False if self.p: