diff --git a/.gitignore b/.gitignore index 42bfcc29..190f39cf 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,5 @@ build/ .vscode/ nginx/logs/ nginx/temp/ -nginx/conf/nginx.conf .idea/ Python39/* \ No newline at end of file diff --git a/config.ini b/config.ini index 6b00f64c..3cd7e4dd 100644 --- a/config.ini +++ b/config.ini @@ -12,5 +12,5 @@ threads = 200 server = khms1.google.com [general] -warning = disabled +warning = enabled diff --git a/nginx/conf/nginx.conf b/nginx/conf/nginx.conf new file mode 100644 index 00000000..7ba591ac --- /dev/null +++ b/nginx/conf/nginx.conf @@ -0,0 +1,95 @@ +worker_processes 8; + +error_log logs/error.log; +error_log logs/error.log notice; +error_log logs/error.log info; + +events { + worker_connections 1024; +} + +http { + server_names_hash_bucket_size 64; + + include mime.types; + default_type application/octet-stream; + + keepalive_timeout 65; + + server { + listen 443 ssl; + server_name khstorelive.azureedge.net; + + ssl_certificate cert.pem; + ssl_certificate_key key.pem; + + ssl_ciphers HIGH:!aNULL:!MD5; + ssl_prefer_server_ciphers on; + + access_log logs/khstore-access.log; + + location ~* /.*?tsom_cc_activation_masks.* { + return 404; + } + + location ~* /.*?/coverage_maps/.* { + return 404; + } + + location ~* /.*?texture_synthesis_online_map_high_res.* { + return 404; + } + + location ~* /.*?color_corrected_images.* { + return 404; + } + + location / { + proxy_set_header Host khstorelive.azureedge.net; + proxy_pass https://khstorelive.afd.azureedge.net; + proxy_pass_request_headers on; + proxy_ssl_verify off; + } + } + + server { + listen 443 ssl; + server_name kh.ssl.ak.tiles.virtualearth.net; + + ssl_certificate cert.pem; + ssl_certificate_key key.pem; + + ssl_ciphers HIGH:!aNULL:!MD5; + ssl_prefer_server_ciphers on; + + access_log logs/virtualearth-access.log; + + location /health { + proxy_pass http://localhost:39871/health; + proxy_ssl_verify off; + access_log logs/health-check.log; + } + + location ~* /tiles/akh.*? { + proxy_pass http://localhost:39871; + proxy_pass_request_headers on; + proxy_ssl_verify off; + access_log logs/localgoogle-access.log; + } + + location ~* /tiles/mtx.*? { + proxy_pass http://localhost:39871; + proxy_pass_request_headers on; + proxy_set_header Host kh.ssl.ak.tiles.virtualearth.net; + proxy_ssl_verify off; + access_log logs/localgoogle-access.log; + } + + location / { + proxy_set_header Host kh.ssl.ak.tiles.virtualearth.net; + proxy_pass https://kh.ssl.ak.tiles.virtualearth.net.edgekey.net; + proxy_pass_request_headers on; + proxy_ssl_verify off; + } + } +} diff --git a/run.bat b/run.bat index b39fb07c..545665e6 100644 --- a/run.bat +++ b/run.bat @@ -1,43 +1,6 @@ @setlocal enableextensions @cd /d "%~dp0" -@echo off -:: BatchGotAdmin -:------------------------------------- -REM --> Check for permissions - IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" ( ->nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system" -) ELSE ( ->nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" -) +.\Python39\python.exe src\app.py -REM --> If error flag set, we do not have admin. -if '%errorlevel%' NEQ '0' ( - echo Requesting administrative privileges... - goto UACPrompt -) else ( goto gotAdmin ) - -:UACPrompt - echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" - set params= %* - echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params:"=""%", "", "runas", 1 >> "%temp%\getadmin.vbs" - - "%temp%\getadmin.vbs" - del "%temp%\getadmin.vbs" - exit /B - -:gotAdmin - pushd "%CD%" - CD /D "%~dp0" -:-------------------------------------- - -if exist .\Python39\python.exe ( - echo "Use embedded python" - .\Python39\python.exe src\app.py -) else ( - echo "Use user python" - py -m pip install -r requirements.txt - py src\app.py -) - -pause +pause \ No newline at end of file diff --git a/src/app.py b/src/app.py index b6fe4498..eea2fca3 100644 --- a/src/app.py +++ b/src/app.py @@ -9,7 +9,7 @@ import webbrowser from diskcache import Cache from multiprocessing import Process -from runner import add_cert, override_hosts, restore_hosts, get_hosts_origin_ips, del_cert +from runner import add_cert, override_hosts, restore_hosts, del_cert from server import run_server, clear_cache, url_mapping from settings import Settings from threading import Thread @@ -233,12 +233,6 @@ def enable_features(template: str): out = out.replace(f"#{feature}#", "") return out - @staticmethod - def config_dns(template: str): - for k, v in get_hosts_origin_ips().items(): - template = template.replace(f"#{k}#", v) - return template - def run(self): if self.is_warning_enabled(): messagebox.showwarning(title="IMPORTANT", @@ -259,19 +253,6 @@ def run(self): messagebox.showerror(message=f"Add certificate failed: {traceback.format_exc()}") return - try: - with open("./src/nginx.conf.template", "rt") as nginx: - template = nginx.read() - output = self.enable_features(template) - output = self.config_dns(output) - - with open("./nginx/conf/nginx.conf", "wt") as out: - out.write(output) - except Exception: - traceback.print_exc() - messagebox.showerror(message=f"Generate nginx file failed:\n {traceback.format_exc()}") - return - try: override_hosts() except: @@ -289,8 +270,7 @@ def run(self): self.server_process = Process( target=run_server, args=( - self.settings.cache_size, self.settings.proxy_url, self.settings.google_server, - get_hosts_origin_ips())) + self.settings.cache_size, self.settings.proxy_url, self.settings.google_server)) self.server_process.start() self.nginx_process = subprocess.Popen( "nginx.exe", shell=True, cwd="./nginx") diff --git a/src/runner.py b/src/runner.py index 11de80ee..192cf4a0 100644 --- a/src/runner.py +++ b/src/runner.py @@ -9,10 +9,6 @@ urllib3.disable_warnings() __domains = ['kh.ssl.ak.tiles.virtualearth.net', 'khstorelive.azureedge.net'] -__default_ip = { - 'kh.ssl.ak.tiles.virtualearth.net': '104.85.242.213', - 'khstorelive.azureedge.net': '104.212.68.114' -} host_path = "C:\\Windows\\System32\\drivers\\etc\\hosts" host_entries = [f"\n127.0.0.1 {domain}\n" for domain in __domains] @@ -21,24 +17,12 @@ def add_cert(): subprocess.run(["certutil", "-addstore", "-f", "root", ".\\certs\\cert.crt"], shell=True, check=True) + def del_cert(): subprocess.run(["certutil", "-delstore", "-f", "root", ".\\certs\\cert.crt"], shell=True, check=True) -def get_hosts_origin_ips(): - try: - origin_ips = {} - dns_resolver = dns.resolver.Resolver() - for d in __domains: - origin_ips[d] = dns_resolver.resolve(d)[0].to_text() - print(origin_ips) - return origin_ips - except: - traceback.print_exc() - return __default_ip - - def override_hosts(): print("Overriding hosts") os.chmod(host_path, stat.S_IWRITE) @@ -57,4 +41,4 @@ def restore_hosts(): f.seek(0) f.write(host) f.truncate() - print("Restored hosts") \ No newline at end of file + print("Restored hosts") diff --git a/src/server.py b/src/server.py index e2c9fd12..b3bfd0d5 100644 --- a/src/server.py +++ b/src/server.py @@ -15,7 +15,6 @@ __cache: Cache = None __proxies = None __google_server = "mt1.google.com" -__original_ips = None app = Flask(__name__) @@ -125,12 +124,11 @@ def tiles(path): return response -def run_server(cache_size, proxies, google_server, original_ips): - global __cache, __proxies, __google_server, __original_ips +def run_server(cache_size, proxies, google_server): + global __cache, __proxies, __google_server __cache = Cache( "./cache", size_limit=int(cache_size) * 1024 * 1024 * 1024, shards=10) __proxies = {"https": proxies} __google_server = google_server - __original_ips = original_ips app.run(port=39871, host="0.0.0.0", threaded=True)