mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
fix bug caused by refactoring that made Tails launch infinite onionshare processes (oops)
This commit is contained in:
parent
53a965a143
commit
cf52c2dcd0
@ -43,20 +43,20 @@ class OnionShare(object):
|
|||||||
self.port = tmpsock.getsockname()[1]
|
self.port = tmpsock.getsockname()[1]
|
||||||
tmpsock.close()
|
tmpsock.close()
|
||||||
|
|
||||||
def start_hidden_service(self, gui=False):
|
def start_hidden_service(self, gui=False, tails_root=False):
|
||||||
if helpers.get_platform() == 'Tails':
|
if helpers.get_platform() == 'Tails' and not tails_root:
|
||||||
# in Tails, start the hidden service in a root process
|
# in Tails, start the hidden service in a root process
|
||||||
if gui:
|
if gui:
|
||||||
args = ['/usr/bin/gksudo', '-D', 'OnionShare', '--', '/usr/bin/onionshare']
|
args = ['/usr/bin/gksudo', '-D', 'OnionShare', '--', '/usr/bin/onionshare']
|
||||||
else:
|
else:
|
||||||
args = ['/usr/bin/sudo', '--', '/usr/bin/onionshare']
|
args = ['/usr/bin/sudo', '--', '/usr/bin/onionshare']
|
||||||
p = subprocess.Popen(args+[str(app.port)], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
p = subprocess.Popen(args+[str(self.port)], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
stdout = p.stdout.read(22) # .onion URLs are 22 chars long
|
stdout = p.stdout.read(22) # .onion URLs are 22 chars long
|
||||||
|
|
||||||
if stdout:
|
if stdout:
|
||||||
self.onion_host = stdout
|
self.onion_host = stdout
|
||||||
else:
|
else:
|
||||||
if root_p.poll() == -1:
|
if p.poll() == -1:
|
||||||
raise TailsError(o.stderr.read())
|
raise TailsError(o.stderr.read())
|
||||||
else:
|
else:
|
||||||
raise TailsError(strings._("error_tails_unknown_root"))
|
raise TailsError(strings._("error_tails_unknown_root"))
|
||||||
@ -66,8 +66,6 @@ class OnionShare(object):
|
|||||||
self.onion_host = '127.0.0.1:{0}'.format(self.port)
|
self.onion_host = '127.0.0.1:{0}'.format(self.port)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print strings._("connecting_ctrlport").format(self.port)
|
|
||||||
|
|
||||||
# come up with a hidden service directory name
|
# come up with a hidden service directory name
|
||||||
hidserv_dir = '{0}/onionshare_{1}'.format(helpers.get_tmp_dir(), helpers.random_string(8))
|
hidserv_dir = '{0}/onionshare_{1}'.format(helpers.get_tmp_dir(), helpers.random_string(8))
|
||||||
self.cleanup_filenames.append(hidserv_dir)
|
self.cleanup_filenames.append(hidserv_dir)
|
||||||
@ -97,19 +95,27 @@ class OnionShare(object):
|
|||||||
def wait_for_hs(self):
|
def wait_for_hs(self):
|
||||||
print strings._('wait_for_hs')
|
print strings._('wait_for_hs')
|
||||||
|
|
||||||
|
if helpers.get_platform() == 'Tails':
|
||||||
|
import urllib2
|
||||||
|
|
||||||
ready = False
|
ready = False
|
||||||
while not ready:
|
while not ready:
|
||||||
try:
|
try:
|
||||||
sys.stdout.write('{0} '.format(strings._('wait_for_hs_trying')))
|
sys.stdout.write('{0} '.format(strings._('wait_for_hs_trying')))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
s = socks.socksocket()
|
if helpers.get_platform() == 'Tails':
|
||||||
s.setproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 9150)
|
# in Tails everything is proxies over Tor already
|
||||||
s.connect((self.onion_host, 80))
|
# so no need to set the socks5 proxy
|
||||||
|
urllib2.urlopen('http://{0}'.format(self.onion_host))
|
||||||
|
else:
|
||||||
|
s = socks.socksocket()
|
||||||
|
s.setproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 9150)
|
||||||
|
s.connect((self.onion_host, 80))
|
||||||
ready = True
|
ready = True
|
||||||
|
|
||||||
sys.stdout.write('{0}\n'.format(strings._('wait_for_hs_yup')))
|
sys.stdout.write('{0}\n'.format(strings._('wait_for_hs_yup')))
|
||||||
except TypeError as e:
|
except:
|
||||||
sys.stdout.write('{0}\n'.format(strings._('wait_for_hs_nope')))
|
sys.stdout.write('{0}\n'.format(strings._('wait_for_hs_nope')))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
@ -130,8 +136,10 @@ def tails_root():
|
|||||||
subprocess.call(['/sbin/iptables', '-I', 'OUTPUT', '-o', 'lo', '-p', 'tcp', '--dport', str(port), '-j', 'ACCEPT'])
|
subprocess.call(['/sbin/iptables', '-I', 'OUTPUT', '-o', 'lo', '-p', 'tcp', '--dport', str(port), '-j', 'ACCEPT'])
|
||||||
|
|
||||||
# start hidden service
|
# start hidden service
|
||||||
onion_host = start_hidden_service(port)
|
app = OnionShare()
|
||||||
sys.stdout.write(onion_host)
|
app.port = port
|
||||||
|
app.start_hidden_service(False, True)
|
||||||
|
sys.stdout.write(app.onion_host)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
# close hole in firewall on shutdown
|
# close hole in firewall on shutdown
|
||||||
@ -178,6 +186,7 @@ def main():
|
|||||||
# start the onionshare app
|
# start the onionshare app
|
||||||
try:
|
try:
|
||||||
app = OnionShare(debug, local_only, stay_open)
|
app = OnionShare(debug, local_only, stay_open)
|
||||||
|
print strings._("connecting_ctrlport").format(app.port)
|
||||||
app.start_hidden_service()
|
app.start_hidden_service()
|
||||||
except NoTor as e:
|
except NoTor as e:
|
||||||
sys.exit(e.args[0])
|
sys.exit(e.args[0])
|
||||||
|
@ -83,6 +83,7 @@ class OnionShareGui(QtGui.QWidget):
|
|||||||
# start the hidden service
|
# start the hidden service
|
||||||
self.status_bar.showMessage(strings._('gui_starting_server').format(self.app.port))
|
self.status_bar.showMessage(strings._('gui_starting_server').format(self.app.port))
|
||||||
try:
|
try:
|
||||||
|
print strings._("connecting_ctrlport").format(self.app.port)
|
||||||
self.app.start_hidden_service(gui=True)
|
self.app.start_hidden_service(gui=True)
|
||||||
except onionshare.NoTor as e:
|
except onionshare.NoTor as e:
|
||||||
alert(e.args[0], QtGui.QMessageBox.Warning)
|
alert(e.args[0], QtGui.QMessageBox.Warning)
|
||||||
|
Loading…
Reference in New Issue
Block a user