added windows support (#6)

This commit is contained in:
Micah Lee 2014-05-22 14:23:22 -04:00
parent 599c1fd08f
commit 8b55df55c8

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
import os, sys, subprocess, time, hashlib, inspect import os, sys, subprocess, time, hashlib, inspect, platform
from random import randint from random import randint
from functools import wraps from functools import wraps
@ -35,7 +35,21 @@ def get_platform():
if 'ONIONSHARE_PLATFORM' in os.environ: if 'ONIONSHARE_PLATFORM' in os.environ:
return os.environ['ONIONSHARE_PLATFORM'] return os.environ['ONIONSHARE_PLATFORM']
else: else:
return 'unknown' return platform.system()
def get_hidden_service_dir(port):
if get_platform() == "Windows":
if 'Temp' in os.environ:
temp = os.environ['Temp'].replace('\\', '/')
else:
temp = 'C:/tmp'
return "{0}/onionshare_hidden_service_{1}".format(temp, port)
return "/tmp/onionshare_hidden_service_{0}".format(port)
def get_hidden_service_hostname(port):
hostname_file = '{0}/hostname'.format(get_hidden_service_dir(port))
return open(hostname_file, 'r').read().strip()
def tails_open_port(port): def tails_open_port(port):
if get_platform() == 'Tails': if get_platform() == 'Tails':
@ -83,10 +97,10 @@ if __name__ == '__main__':
# set up hidden service # set up hidden service
controller.set_options([ controller.set_options([
('HiddenServiceDir', '/tmp/onionshare_hidden_service_{0}/'.format(port)), ('HiddenServiceDir', get_hidden_service_dir(port)),
('HiddenServicePort', '80 127.0.0.1:{0}'.format(port)) ('HiddenServicePort', '80 127.0.0.1:{0}'.format(port))
]) ])
onion_host = open('/tmp/onionshare_hidden_service_{0}/hostname'.format(port), 'r').read().strip() onion_host = get_hidden_service_hostname(port)
# punch a hole in the firewall # punch a hole in the firewall
tails_open_port(port) tails_open_port(port)