webroot_real = os.path.realpath(script_directory + "/webroot")
folderPath = os.path.realpath(script_directory + "/webroot" + requestPath)
if not folderPath.startswith(webroot_real + os.sep) and folderPath != webroot_real:
responseType = "403 Forbidden"
contentType = "text/html"
responsecontent = b"
403 Forbidden
"
else:
filesList = list(os.scandir(folderPath))
responseType = "200 OK"
contentType = "text/html"
template = open(script_directory + "/webroot/Templates/fileList.html").read()
template = template.replace("", html.escape(requestPath))
listText = "Folder: .."
for i in filesList:
temp = "File: "
funnynameorsomethingidk = i.name
if os.path.isdir(folderPath + "/" + funnynameorsomethingidk):
temp = "Folder: "
funnynameorsomethingidk += "/"
link = requestPath + "/" + funnynameorsomethingidk
link = link.replace("//", "/")
if link.endswith(".py"):
link = "/raw/?p=" + html.escape(link)
else:
link = html.escape(link)
listText += ("" + temp + "" + html.escape(i.name) + "")
template = template.replace("", listText)
responsecontent = template.encode()