mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-26 19:22:59 -03:00
Make hidserv_dir a class variable so it can be cleaned up (fixes #232), and refactor _hsdic2list (#199)
This commit is contained in:
parent
9723270794
commit
2ce32e2327
1 changed files with 9 additions and 9 deletions
|
@ -107,26 +107,26 @@ class HS(object):
|
||||||
if not os.access(path, os.W_OK):
|
if not os.access(path, os.W_OK):
|
||||||
raise HSDirError(strings._("error_hs_dir_not_writable").format(path))
|
raise HSDirError(strings._("error_hs_dir_not_writable").format(path))
|
||||||
|
|
||||||
hidserv_dir = tempfile.mkdtemp(dir=path)
|
self.hidserv_dir = tempfile.mkdtemp(dir=path)
|
||||||
self.cleanup_filenames.append(hidserv_dir)
|
self.cleanup_filenames.append(self.hidserv_dir)
|
||||||
|
|
||||||
# set up hidden service
|
# set up hidden service
|
||||||
hsdic = self.c.get_conf_map('HiddenServiceOptions') or {
|
hsdic = self.c.get_conf_map('HiddenServiceOptions') or {
|
||||||
'HiddenServiceDir': [], 'HiddenServicePort': []
|
'HiddenServiceDir': [], 'HiddenServicePort': []
|
||||||
}
|
}
|
||||||
if hidserv_dir in hsdic.get('HiddenServiceDir', []):
|
if self.hidserv_dir in hsdic.get('HiddenServiceDir', []):
|
||||||
# Maybe a stale service with the wrong local port
|
# Maybe a stale service with the wrong local port
|
||||||
dropme = hsdic['HiddenServiceDir'].index(hidserv_dir)
|
dropme = hsdic['HiddenServiceDir'].index(self.hidserv_dir)
|
||||||
del hsdic['HiddenServiceDir'][dropme]
|
del hsdic['HiddenServiceDir'][dropme]
|
||||||
del hsdic['HiddenServicePort'][dropme]
|
del hsdic['HiddenServicePort'][dropme]
|
||||||
hsdic['HiddenServiceDir'] = hsdic.get('HiddenServiceDir', [])+[hidserv_dir]
|
hsdic['HiddenServiceDir'] = hsdic.get('HiddenServiceDir', [])+[self.hidserv_dir]
|
||||||
hsdic['HiddenServicePort'] = hsdic.get('HiddenServicePort', [])+[
|
hsdic['HiddenServicePort'] = hsdic.get('HiddenServicePort', [])+[
|
||||||
'80 127.0.0.1:{0:d}'.format(port)]
|
'80 127.0.0.1:{0:d}'.format(port)]
|
||||||
|
|
||||||
self.c.set_options(self._hsdic2list(hsdic))
|
self.c.set_options(self._hsdic2list(hsdic))
|
||||||
|
|
||||||
# figure out the .onion hostname
|
# figure out the .onion hostname
|
||||||
hostname_file = '{0:s}/hostname'.format(hidserv_dir)
|
hostname_file = '{0:s}/hostname'.format(self.hidserv_dir)
|
||||||
onion_host = open(hostname_file, 'r').read().strip()
|
onion_host = open(hostname_file, 'r').read().strip()
|
||||||
return onion_host
|
return onion_host
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ class HS(object):
|
||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
l = []
|
l = []
|
||||||
for i in range(len(dic['HiddenServiceDir'])):
|
for dir, port in zip(dic['HiddenServiceDir'], dic['HiddenServicePort']):
|
||||||
l.append(('HiddenServiceDir', dic['HiddenServiceDir'][i]))
|
l.append(('HiddenServiceDir', dir))
|
||||||
l.append(('HiddenServicePort', dic['HiddenServicePort'][i]))
|
l.append(('HiddenServicePort', port))
|
||||||
return l
|
return l
|
||||||
|
|
Loading…
Add table
Reference in a new issue