Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import http.server
- import socketserver
- import os
- blacklist = {}
- packet = b"server|127.0.0.1\nport|17091\ntype|1\n#maint|Mainetrance message GTPS\n\nbeta_server|127.0.0.1\nbeta_port|17091\n\nbeta_type|1\nmeta|localhost\nRTENDMARKERBS1001"
- files = {}
- for file in os.listdir("assets"):
- if not file.endswith(".rrtex"):
- continue
- with open(os.path.join("assets", file), "rb") as f:
- files[file] = f.read()
- timeout = 10
- def add_address(address):
- blacklist[address] = timeout + time.time()
- class RequestHandler(http.server.BaseHTTPRequestHandler):
- def do_POST(self):
- self.process_request()
- def do_GET(self):
- self.process_request()
- def process_request(self):
- url = self.path.split("/growtopia/")[1]
- if url and url.startswith("server_data.php") and self.command.lower() == "post":
- print(f"Connection from: {self.client_address[0]}")
- if (address := self.client_address[0] + self.path) not in blacklist:
- print(f"{self.client_address[0]} agora está na lista negra para {timeout} segundos. na rotae: {self.path}")
- add_address(address)
- else:
- not_allowed = blacklist[address]
- if time.time() > not_allowed:
- print(f"Timeout done for: {self.client_address[0]}")
- del blacklist[address]
- else:
- print(f"Connection blocked: {self.client_address[0]}")
- self.connection.close()
- return
- print(f"Entered correct route: {self.client_address[0]}")
- self.send_response(200)
- self.send_header('Content-Type', 'text/html')
- self.end_headers()
- self.wfile.write(packet)
- elif url and url in files and self.command.lower() == "get":
- print(f"Connection from: {self.client_address[0]}")
- if (address := self.client_address[0] + self.path) not in blacklist:
- print(f"{self.client_address[0]} agora está na blacklist pata {timeout} segundos. Na rota: {self.path}")
- add_address(address)
- else:
- not_allowed = blacklist[address]
- if time.time() > not_allowed:
- print(f"Timeout done for: {self.client_address[0]}")
- del blacklist[address]
- else:
- print(f"Connection blocked: {self.client_address[0]}")
- self.connection.close()
- return
- self.send_response(200)
- self.send_header('Content-Type', 'application/octet-stream')
- self.send_header('Content-Disposition', f'attachment; filename={url + ".rrtex" if not url.endswith(".rrtex") else url}')
- self.end_headers()
- self.wfile.write(files[url])
- else:
- print(f"Connection blocked: {self.client_address[0]}")
- self.connection.close()
- def run(server_class=socketserver.TCPServer, handler_class=RequestHandler, port=80):
- server_address = ('', port)
- httpd = server_class(server_address, handler_class)
- print("HTTP Server now up.")
- httpd.serve_forever()
- if __name__ == "__main__":
- run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement