2025-06-12 22:34:19 +00:00
|
|
|
# This depends on `geckodriver`.
|
|
|
|
|
|
2025-06-12 22:11:08 +00:00
|
|
|
from flask import Flask, render_template_string, request, redirect, url_for
|
|
|
|
|
from selenium import webdriver
|
2025-06-12 22:34:19 +00:00
|
|
|
from selenium.webdriver.firefox.options import Options
|
2025-06-12 22:11:08 +00:00
|
|
|
import threading
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
# Start browser in kiosk mode at server startup
|
2025-06-12 22:34:19 +00:00
|
|
|
firefox_options = Options()
|
|
|
|
|
firefox_options.add_argument("--kiosk") # Kiosk mode, for fullscreen on some platforms
|
2025-06-12 22:11:08 +00:00
|
|
|
|
|
|
|
|
# Store the browser globally
|
2025-06-12 22:34:19 +00:00
|
|
|
browser = webdriver.Firefox(options=firefox_options)
|
2025-06-12 22:11:08 +00:00
|
|
|
browser.get("about:blank")
|
|
|
|
|
|
|
|
|
|
@app.route("/", methods=["GET", "POST"])
|
|
|
|
|
def index():
|
|
|
|
|
if request.method == "POST":
|
|
|
|
|
url = request.form.get("url")
|
|
|
|
|
if url:
|
|
|
|
|
# Ensure URL has a protocol
|
|
|
|
|
if not url.startswith(("http://", "https://")):
|
|
|
|
|
url = "http://" + url
|
|
|
|
|
# Use Selenium to navigate current tab to new URL
|
|
|
|
|
browser.get(url)
|
|
|
|
|
return redirect(url_for("index"))
|
|
|
|
|
|
|
|
|
|
# Render a minimalist HTML page
|
|
|
|
|
return render_template_string("""
|
|
|
|
|
<html>
|
|
|
|
|
<head>
|
|
|
|
|
<title>KPR Media Naranja</title>
|
|
|
|
|
<style>
|
|
|
|
|
body { font-family: sans-serif; margin: 2em; background: #222; color: #fff; }
|
|
|
|
|
form { display: flex; gap: 1em; }
|
|
|
|
|
input[type=text] { flex: 1; padding: 0.5em; font-size: 1.2em; border-radius: 8px; border: none;}
|
|
|
|
|
button { padding: 0.5em 1em; font-size: 1.2em; border-radius: 8px; background: #4caf50; color: #fff; border: none; }
|
|
|
|
|
</style>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<h1>Alimenta una URL</h1>
|
|
|
|
|
<form method="post">
|
|
|
|
|
<input type="text" name="url" placeholder="Pon la URL justo aqui" autofocus>
|
|
|
|
|
<button type="submit">Send</button>
|
|
|
|
|
</form>
|
2025-06-12 22:34:19 +00:00
|
|
|
<!-- <p style="opacity:0.5;font-size:smaller;">Tip: Solo se muestra una pestana a la vez!.</p> --!>
|
2025-06-12 22:11:08 +00:00
|
|
|
</body>
|
|
|
|
|
</html>
|
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
# Run Flask in a thread so Selenium's browser stays alive
|
|
|
|
|
threading.Thread(target=lambda: app.run(host="0.0.0.0", port=80, debug=False, use_reloader=False)).start()
|