diff --git a/blueprints/blog.py b/blueprints/blog.py index 26a2306..c94dc6f 100644 --- a/blueprints/blog.py +++ b/blueprints/blog.py @@ -3,7 +3,7 @@ from flask import Blueprint, render_template, request, jsonify import markdown from bs4 import BeautifulSoup import re -from tools import isCurl, getClientIP, getHandshakeScript +from tools import isCLI, getClientIP, getHandshakeScript blog_bp = Blueprint('blog', __name__) @@ -110,7 +110,7 @@ def render_home(handshake_scripts: str | None = None): @blog_bp.route("/") def index(): - if not isCurl(request): + if not isCLI(request): return render_home(handshake_scripts=getHandshakeScript(request.host)) # Get a list of pages @@ -131,7 +131,7 @@ def index(): @blog_bp.route("/") def path(path): - if not isCurl(request): + if not isCLI(request): return render_page(path, handshake_scripts=getHandshakeScript(request.host)) # Convert md to html diff --git a/server.py b/server.py index a581350..b4b017f 100644 --- a/server.py +++ b/server.py @@ -26,7 +26,7 @@ from blueprints.api import api_bp from blueprints.podcast import podcast_bp from blueprints.acme import acme_bp from blueprints.spotify import spotify_bp -from tools import isCurl, isCrawler, getAddress, getFilePath, error_response, getClientIP, json_response, getHandshakeScript, get_tools_data +from tools import isCLI, isCrawler, getAddress, getFilePath, error_response, getClientIP, json_response, getHandshakeScript, get_tools_data from curl import curl_response app = Flask(__name__) @@ -244,7 +244,7 @@ def index(): # Always load if load is in the query string if request.args.get("load"): loaded = False - if isCurl(request): + if isCLI(request): return curl_response(request) if not loaded and not isCrawler(request): @@ -397,7 +397,7 @@ def index(): # region Donate @app.route("/donate") def donate(): - if isCurl(request): + if isCLI(request): return curl_response(request) coinList = os.listdir(".well-known/wallets") @@ -687,7 +687,7 @@ def resume_pdf(): @app.route("/tools") def tools(): - if isCurl(request): + if isCLI(request): return curl_response(request) return render_template("tools.html", tools=get_tools_data()) @@ -704,7 +704,7 @@ def catch_all(path: str): return error_response(request, message="Restricted route", code=403) # If curl request, return curl response - if isCurl(request): + if isCLI(request): return curl_response(request) if path in REDIRECT_ROUTES: diff --git a/tools.py b/tools.py index 5067065..75ca022 100644 --- a/tools.py +++ b/tools.py @@ -27,6 +27,12 @@ CRAWLERS = [ "Twitterbot" ] +CLI_AGENTS = [ + "curl", + "hurl", + "xh" +] + def getClientIP(request: Request) -> str: """ @@ -75,7 +81,7 @@ def getGitCommit() -> str: return "failed to get version" -def isCurl(request: Request) -> bool: +def isCLI(request: Request) -> bool: """ Check if the request is from curl or hurl. @@ -87,7 +93,7 @@ def isCurl(request: Request) -> bool: """ if request.headers and request.headers.get("User-Agent"): user_agent = request.headers.get("User-Agent", "") - return "curl" in user_agent or "hurl" in user_agent + return any(agent in user_agent for agent in CLI_AGENTS) return False @@ -221,7 +227,7 @@ def error_response( Returns: Union[Tuple[Dict, int], object]: The JSON or HTML response """ - if force_json or isCurl(request): + if force_json or isCLI(request): return json_response(request, message, code) # Check if .html exists in templates