text
stringlengths
1
93.6k
def redirect_manifest(self):
hasher = hashlib.md5() # nosec B303
manifest = "CACHE MANIFEST\n\n"
manifest += "CACHE:\n"
manifest += "/\n"
manifest += "/index.html\n"
manifest += "/api/hostname\n"
manifest += "\nNETWORK:\n"
manifest += "*\n"
manifest += "\nSETTINGS:\n"
manifest += "prefer-online\n"
hasher.update(bytes(SETTINGS["HTTP_Interface_IP"] + ":" + str(SETTINGS["HTTP_Port"]), "utf-8"))
manifest += f"\n# Hash: {hasher.hexdigest().upper()}"
self.my_sender("text/cache-manifest", bytes(manifest, "utf-8"), {"Cache-Control": "public, max-age=31536000", "Last-Modified": SCRIPT_START})
def theme_manifest(self):
hasher = hashlib.md5() # nosec B303
manifest = "CACHE MANIFEST\n\n"
manifest += "CACHE:\n"
manifest += "./\n"
manifest += "./index.html\n"
manifest += "./blank.html\n"
manifest += "./api/themes\n"
manifest += "./api/menu\n"
try:
cookies = SimpleCookie(self.headers.get("Cookie"))
theme = cookies["theme"].value
if not os.path.isdir(os.path.join(THEME_LOC, theme)):
theme = SETTINGS["Theme"]
except KeyError:
theme = SETTINGS["Theme"]
# TODO: Change to scandir?
for path, subdirs, files in os.walk(os.path.join(THEME_LOC, theme)):
UNUSED(subdirs)
for filename in files:
try:
with open(os.path.join(path, filename), "rb") as buf:
data = buf.read()
hasher.update(data)
manifest += ".{}\n".format(quote(os.path.join(path, filename).replace(CWD, "").replace("\\", "/"), safe=";,/?:@&=+$-_.!~*'()#"))
except (IOError, PermissionError):
pass
manifest += "\nNETWORK:\n"
manifest += "*\n"
manifest += "\nSETTINGS:\n"
manifest += "prefer-online\n"
categories = self.api_categories()
if categories != {"error": True, "message": "No Categories Found"}:
for key, value in categories.items():
UNUSED(value)
categories[key]["entries"] = self.api_entries(key)
hasher.update(bytes(self.last_mod_time(os.path.join(THEME_LOC, theme)), "utf-8"))
hasher.update(bytes(json.dumps(categories), "utf-8"))
manifest += f"\n# Hash: {hasher.hexdigest().upper()}"
self.my_sender("text/cache-manifest", bytes(manifest, "utf-8"), {"Last-Modified": self.last_mod_time(os.path.join(THEME_LOC, theme))}) # TODO: Cache-Control Headers
def do_GET(self):
try:
self.queries = self.path.split("?")[1]
except IndexError:
pass
self.path = self.path.split("?")[0]
if re.match(r"^\/update\/ps4\/list\/[a-z]{2}\/ps4\-updatelist\.xml", self.path):
return self.ps4_updatelist()
if re.match(r"^\/update\/ps5\/official\/tJMRE80IbXnE9YuG0jzTXgKEjIMoabr6\/list\/[a-z]{2}\/updatelist\.xml", self.path):
return self.ps5_updatelist()
if re.match(r"^\/update\/(psp2|psv)\/list\/[a-z]{2}\/(psp2|psv)\-updatelist\.xml", self.path):
return self.vita_updatelist()
if re.match(r"^\/update\/ps4\/html\/[a-z]{2}\/[a-z]{2}\/ps4\-updatefeature\.html", self.path):
return self.ps4_updatefeature()
if re.match(r"\/update\/ps5\/official\/[a-zA-Z0-9]{32}\/html\/feature\/[a-z]{2}\/[a-z]{2}\/updatefeature\.html", self.path):
return self.ps5_updatefeature()
if re.match(r"^\/update\/ps4\/image\/[0-9]{4}_[0-9]{4}\/(sys|rec)_[a-fA-F0-9]{32}\/PS4UPDATE\.PUP", self.path):
return self.ps4_update_pup()
if re.match(r"^\/update\/ps5\/official\/tJMRE80IbXnE9YuG0jzTXgKEjIMoabr6\/image\/[0-9]{4}_[0-9]{4}\/(sys|rec)_[a-fA-F0-9]{64}\/PS5UPDATE\.PUP", self.path):
return self.ps4_update_pup()
if re.match(r"^\/update\/(psp2|psv)\/image\/[0-9]{4}_[0-9]{4}\/(rel|sd|pre)_[a-fA-F0-9]{32}\/(PSP2|PSV)UPDAT\.PUP", self.path):
return self.vita_update_pup()
if re.match(r"^\/netstart\/icst", self.path):
return self.my_sender("text/plain", b"Success", {"Last-Modified": SCRIPT_START}) # TODO: Cache-Control Headers
if re.match(r"^\/networktest\/get_2m", self.path):
return self.network_test(2097152)
if re.match(r"^\/networktest\/get_6m", self.path):
return self.network_test(6291456)