From aae9a59c480be0adba7e4de2e4afe462b171005a Mon Sep 17 00:00:00 2001 From: ozymandias Date: Mon, 19 May 2025 23:58:00 +0000 Subject: [PATCH] Add kpr-links.py --- kpr-links.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 kpr-links.py diff --git a/kpr-links.py b/kpr-links.py new file mode 100644 index 0000000..c8f985a --- /dev/null +++ b/kpr-links.py @@ -0,0 +1,42 @@ +import json +from http.server import BaseHTTPRequestHandler, HTTPServer + +PORT = 80 +LINKS_FILE = 'links.json' + +class RedirectHandler(BaseHTTPRequestHandler): + def do_GET(self): + try: + with open(LINKS_FILE) as f: + links = json.load(f) + except Exception: + self.send_response(500) + self.end_headers() + self.wfile.write(b"500: Error al leer el archivo de links.") + return + + key = self.path.strip("/") + if key in links: + self.send_response(302) + self.send_header('Location', links[key]) + self.end_headers() + else: + self.send_response(404) + self.end_headers() + self.wfile.write(b"404: Link no encontrado.") + + def log_message(self, format, *args): + return # Disable logging + +if __name__ == "__main__": + print(" ___ _ _______ ______ ___ ___ __ _ ___ _ _______ ") + print("| | | || || _ | | | | | | | | || | | || |") + print("| |_| || _ || | || ____ | | | | | |_| || |_| || _____|") + print("| _|| |_| || |_||_ |____| | | | | | || _|| |_____ ") + print("| |_ | ___|| __ | | |___ | | | _ || |_ |_____ |") + print("| _ || | | | | | | || | | | | || _ | _____| |") + print("|___| |_||___| |___| |_| |_______||___| |_| |__||___| |_||_______|") + + print(f"Corriendo servidor de links en el puerto {PORT}") + server = HTTPServer(('', PORT), RedirectHandler) + server.serve_forever()