Use dnspython

dnspython will be used to resolve hostnames, allowing CDN proxy to work even if zoffline is running on the same machine as the Zwift client
This commit is contained in:
oldnapalm
2023-02-11 12:18:57 -03:00
parent 3f21baa20c
commit 1a0650a97d
5 changed files with 20 additions and 11 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ jobs:
pathInArchive: "upx-4.0.1-win64/upx.exe"
- run: pip install -r requirements.txt
- run: pip install dnspython==2.3.0 git+https://github.com/oldnapalm/garmin-uploader.git git+https://github.com/oldnapalm/pyinstaller.git
- run: pip install git+https://github.com/oldnapalm/garmin-uploader.git git+https://github.com/oldnapalm/pyinstaller.git
- run: pyinstaller standalone.spec
- uses: vimtor/action-zip@v1
+1 -1
View File
@@ -8,7 +8,7 @@ RUN git clone --depth 1 https://github.com/zoffline/zwift-offline
COPY requirements.txt requirements.txt
RUN pip install --user --requirement requirements.txt
RUN pip install --user dnspython==2.3.0 git+https://github.com/oldnapalm/garmin-uploader.git
RUN pip install --user git+https://github.com/oldnapalm/garmin-uploader.git
FROM python:3.10-alpine
MAINTAINER zoffline <zoffline@tutanota.com>
+1 -4
View File
@@ -177,7 +177,6 @@ to generate your own certificates and do the same.
```
* Run `Host Changer`, select created `hosts.txt` file and press the button
* Optionally, instead of using the "Host Changer" app, you can create a ``fake-dns.txt`` file in the ``storage`` directory and set the "DNS 1" of your phone Wi-Fi connection to the IP address of the PC running zoffline
* If running from source, install the required module with ``pip3 install dnspython``
* Note: If you know what you're doing and have a capable enough router you can adjust your router to alter these DNS records instead of using the "Host Changer" app or changing your phone DNS.
* Patch after every installation or update:
* Install/update Zwift from Google play, but do not start it yet.
@@ -321,7 +320,6 @@ Create a ``server-ip.txt`` file in the ``storage`` directory containing the IP a
```
* Run "Host Changer", select created ``hosts.txt`` file and press the button
* Optionally, instead of using the "Host Changer" app, you can create a ``fake-dns.txt`` file in the ``storage`` directory and set the "DNS 1" of your phone Wi-Fi connection to the IP address of the PC running zoffline
* If running from source, install the required module with ``pip3 install dnspython``
* Note: If you know what you're doing and have a capable enough router you can adjust your router to alter these DNS records instead of using the "Host Changer" app or changing your phone DNS.
</details>
@@ -330,7 +328,6 @@ Create a ``server-ip.txt`` file in the ``storage`` directory containing the IP a
<details><summary>Expand</summary>
* To obtain the official map schedule and update files from Zwift server: create a ``cdn-proxy.txt`` file in the ``storage`` directory. This can only work if you are running zoffline on a different machine than the Zwift client.
* To enable the password reset feature when multiplayer is enabled: create a ``gmail_credentials.txt`` file in the ``storage`` directory containing the login credentials of a Gmail account. You need to enable the "Less secure app access" in the account settings and you may need to access https://accounts.google.com/DisplayUnlockCaptcha to allow the login from the server.
* To enable the Discord bridge bot: ``pip3 install discord`` and create a ``discord.cfg`` file in the ``storage`` directory containing
```
@@ -368,10 +365,10 @@ Docker
* Flask-SQLAlchemy (https://flask-sqlalchemy.palletsprojects.com/)
* gevent (http://www.gevent.org/)
* pycryptodome (https://pypi.org/project/pycryptodome/)
* dnspython (https://www.dnspython.org/)
* OPTIONAL: stravalib (https://github.com/hozn/stravalib)
* OPTIONAL: garmin-uploader (https://github.com/La0/garmin-uploader)
* OPTIONAL: discord.py (https://discordpy.readthedocs.io/)
* OPTIONAL: dnspython (https://www.dnspython.org/)
## Note
+1
View File
@@ -6,3 +6,4 @@ protobuf==4.21.12
pycryptodome==3.17
pyjwt==2.6.0
stravalib==1.1.0
dnspython==2.3.0
+16 -5
View File
@@ -11,7 +11,9 @@ import math
import random
import itertools
import socketserver
import dns.resolver
from urllib3 import PoolManager
from urllib3.util import connection
from http.server import SimpleHTTPRequestHandler
from http.cookies import SimpleCookie
from collections import deque
@@ -41,7 +43,6 @@ else:
CDN_DIR = "%s/cdn" % SCRIPT_DIR
PROXYPASS_FILE = "%s/cdn-proxy.txt" % STORAGE_DIR
SERVER_IP_FILE = "%s/server-ip.txt" % STORAGE_DIR
FAKE_DNS_FILE = "%s/fake-dns.txt" % STORAGE_DIR
DISCORD_CONFIG_FILE = "%s/discord.cfg" % STORAGE_DIR
@@ -84,6 +85,19 @@ def sigint_handler(num, frame):
signal.signal(signal.SIGINT, sigint_handler)
resolver = dns.resolver.Resolver()
resolver.nameservers = ['8.8.8.8', '8.8.4.4']
resolver.cache = dns.resolver.Cache()
_orig_create_connection = connection.create_connection
def patched_create_connection(address, *args, **kwargs):
host, port = address
answer = resolver.resolve(host)[0].to_text()
return _orig_create_connection((answer, port), *args, **kwargs)
connection.create_connection = patched_create_connection
class CDNHandler(SimpleHTTPRequestHandler):
def translate_path(self, path):
path = SimpleHTTPRequestHandler.translate_path(self, path)
@@ -119,10 +133,7 @@ class CDNHandler(SimpleHTTPRequestHandler):
exceptions = ['Launcher_ver_cur.xml', 'LauncherMac_ver_cur.xml',
'Zwift_ver_cur.xml', 'ZwiftMac_ver_cur.xml',
'ZwiftAndroid_ver_cur.xml', 'Zwift_StreamingFiles_ver_cur.xml']
if os.path.exists(PROXYPASS_FILE) and self.path.startswith('/gameassets/') and not path_end in exceptions:
# PROXYPASS_FILE existence indicates we know what we're doing and
# we can try to obtain the official map schedule and update files.
# This can only work if we're running on a different machine than the Zwift client.
if self.path.startswith('/gameassets/') and not path_end in exceptions:
try:
self.send_response(200)
self.end_headers()