import reqto
from fba import config
-#from fba import instances
from fba import network
def determine(domain: str, headers: dict) -> dict:
# Default headers with no CSRF
reqheaders = headers
- try:
- # Fetch / to check for meta tag indicating csrf
- # DEBUG: print(f"DEBUG: Fetching / from domain='{domain}' for CSRF check ...")
- response = reqto.get(
- f"https://{domain}/",
- headers=network.web_headers,
- timeout=(config.get("connection_timeout"), config.get("read_timeout"))
+ # Fetch / to check for meta tag indicating csrf
+ # DEBUG: print(f"DEBUG: Fetching / from domain='{domain}' for CSRF check ...")
+ response = reqto.get(
+ f"https://{domain}/",
+ headers=network.web_headers,
+ timeout=(config.get("connection_timeout"), config.get("read_timeout"))
+ )
+
+ # DEBUG: print(f"DEBUG: response.ok='{response.ok}',response.status_code={response.status_code},response.text()={len(response.text)}")
+ if response.ok and len(response.text) > 0:
+ meta = bs4.BeautifulSoup(
+ response.text,
+ "html.parser"
)
+ # DEBUG: print(f"DEBUG: meta[]='{type(meta)}'")
+ tag = meta.find("meta", attrs={"name": "csrf-token"})
- # DEBUG: print(f"DEBUG: response.ok='{response.ok}',response.status_code={response.status_code},response.text()={len(response.text)}")
- if response.ok and len(response.text) > 0:
- meta = bs4.BeautifulSoup(
- response.text,
- "html.parser"
- )
- # DEBUG: print(f"DEBUG: meta[]='{type(meta)}'")
-
- tag = meta.find("meta", attrs={"name": "csrf-token"})
- # DEBUG: print(f"DEBUG: tag={tag}")
-
+ # DEBUG: print(f"DEBUG: tag={tag}")
+ if tag is not None:
# DEBUG: print(f"DEBUG: Adding CSRF token='{tag['content']}' for domain='{domain}'")
reqheaders["X-CSRF-Token"] = tag["content"]
- except BaseException as exception:
- # DEBUG: print(f"DEBUG: No CSRF token found, using normal headers: domain='{domain}',exception[{type(exception)}]={exception}")
- pass
-
# DEBUG: print(f"DEBUG: reqheaders()={len(reqheaders)} - EXIT!")
return reqheaders