-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdater.py
executable file
·40 lines (30 loc) · 1.04 KB
/
updater.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
#!/usr/bin/env python3
import os
import sys
from http.server import BaseHTTPRequestHandler, HTTPServer
import urllib.request
import subprocess
settings_filepath = "/home/teamspeak/teamspeak3-server_linux_amd64/tsdns/tsdns_settings.ini"
class MyHandler(BaseHTTPRequestHandler):
def _set_headers(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
def do_GET(self):
self._set_headers()
def do_POST(self):
urllib.request.urlretrieve(os.environ.get('MEH_MAP_URL'), settings_filepath)
subprocess.call(["./tsdnsserver", "--update"])
self._set_headers()
self.wfile.write(b'OK')
if __name__ == '__main__':
if not os.environ.get('MEH_MAP_URL'):
sys.exit('please provide MEH_MAP_URL environement variable. Abording...')
server_address = ('0.0.0.0', 8080)
httpd = HTTPServer(server_address, MyHandler)
print ('Server listening on %s:%s' % (server_address[0], server_address[1]))
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()