This repository has been archived by the owner on Nov 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathconfig_server.py
55 lines (47 loc) · 1.8 KB
/
config_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import BaseHTTPServer, SimpleHTTPServer
import ssl
import patch_hosts
import threading
BLOG_URL = "README.md"
class ConfigHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
if self.path.strip() == "/sync.conf":
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
print "Processed request from Sync. Server shutting down..."
assassin = threading.Thread(target=self.server.shutdown)
assassin.daemon = True
assassin.start()
else:
self.send_response(404, 'Not Found')
self.end_headers()
def main():
print "Please refer to %s for detailed instructions." % BLOG_URL
# Step 1
#print "\r\nStep 1: patch hosts file (Admin required)...",
if not patch_hosts.sync_patch_hosts(): return False
#print "Done"
# Step 2
#print "\r\nStep 2: start fake config.resilio.com server..."
httpd = BaseHTTPServer.HTTPServer(('127.0.0.1', 443), ConfigHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, keyfile='./resilio.key', certfile='./resilio.crt', server_side=True)
print "Fake server started."
print "After Sync has requested the config file, this program should go on automatically."
print "If this program blocks here, please refer to %s" % BLOG_URL
print """
*****************************
* Now, please restart Sync. *
*****************************
"""
httpd.serve_forever()
# Step 3
#print "\r\nStep 3: restore hosts file (Admin required)...",
if not patch_hosts.sync_unpatch_hosts(): return False
#print "Done"
return True
if __name__ == '__main__':
if main():
print "\r\nAll done. Sync should have updated the tracker/relay cache."
print "Press Enter to exit."
else:
print "Error and abort."
raw_input()