Last active
September 6, 2024 20:10
-
-
Save Mintedshrimp/f544259835ffc55600804f91f97b9b5e to your computer and use it in GitHub Desktop.
Put index.html In templates folder in working directory then Install flask and requests using pip then run this using "python Browser.py"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from flask import Flask, render_template, request, redirect, Response | |
| from flask_cors import CORS | |
| import requests | |
| import socket | |
| import logging | |
| app = Flask(__name__) | |
| CORS(app) | |
| logging.basicConfig(level=logging.INFO) | |
| DOWNLOADABLE_EXTENSIONS = ['.zip', '.mp4', '.iso', '.pkg', '.mp3', '.pdf'] | |
| @app.route('/') | |
| def index(): | |
| # Get the User-Agent string directly from the request headers | |
| user_agent_string = request.headers.get('User-Agent', '') | |
| return render_template('index.html', user_agent=user_agent_string) | |
| @app.route('/proxy', methods=['GET', 'POST']) | |
| def proxy(): | |
| original_url = request.form.get('url') if request.method == 'POST' else request.args.get('url') | |
| wifi_ip = get_wifi_ip() | |
| # Set the User-Agent header with a string that displays everything about the device and browser | |
| user_agent = request.headers.get('User-Agent', '') | |
| headers = {'User-Agent': user_agent} | |
| if any(original_url.endswith(ext) for ext in DOWNLOADABLE_EXTENSIONS): | |
| response = requests.get(original_url, headers=headers, allow_redirects=True, verify=False) | |
| final_url = response.url if response.history else original_url | |
| download_url = f"http://{wifi_ip}:5000/download?url={final_url}" | |
| return redirect(download_url) | |
| response = requests.get(original_url, headers=headers, allow_redirects=True, verify=False) | |
| content = response.text | |
| content = modify_links(content, original_url, wifi_ip) | |
| return content | |
| @app.route('/download') | |
| def download(): | |
| url = request.args.get('url') | |
| if not url: | |
| return "No URL provided", 400 | |
| logging.info(f"Downloading from URL: {url}") | |
| response = requests.get(url, stream=True) | |
| if response.status_code != 200: | |
| logging.error(f"Error fetching the file: {response.status_code}") | |
| return f"Error fetching the file: {response.status_code}", response.status_code | |
| return Response(response.iter_content(chunk_size=1024), content_type=response.headers['Content-Type']) | |
| def get_wifi_ip(): | |
| with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: | |
| s.connect(("8.8.8.8", 80)) | |
| wifi_ip = s.getsockname()[0] | |
| return wifi_ip | |
| def modify_links(content, base_url, wifi_ip): | |
| proxy_base_url = f"http://{wifi_ip}:5000/proxy?url=" | |
| # Ensure that we only modify links that are relative and do not already contain the proxy base URL | |
| content = content.replace('href="', f'href="{proxy_base_url}{base_url}/') | |
| content = content.replace('src="', f'src="{proxy_base_url}{base_url}/') | |
| return content | |
| if __name__ == '__main__': | |
| app.run(host="0.0.0.0", port=5000, debug=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Cozy Dark Theme with Raindrops</title> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"> | |
| <style> | |
| body { | |
| background-color: #121212; | |
| color: #e0e0e0; | |
| font-family: 'Arial', sans-serif; | |
| margin: 0; | |
| padding: 0; | |
| overflow: hidden; /* Prevent scrollbars */ | |
| position: relative; | |
| } | |
| h1 { | |
| font-size: 2.5rem; | |
| margin-bottom: 20px; | |
| position: relative; | |
| z-index: 1; /* Ensure it appears above the raindrops */ | |
| } | |
| #user-agent { | |
| background-color: #1e1e1e; | |
| padding: 10px 20px; | |
| border-radius: 4px; | |
| box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3); | |
| font-size: 0.9rem; | |
| margin-bottom: 20px; | |
| width: 80%; | |
| text-align: center; | |
| word-wrap: break-word; /* Allow long User-Agent strings to wrap */ | |
| position: relative; | |
| z-index: 1; /* Ensure it appears above the raindrops */ | |
| } | |
| form { | |
| position: relative; | |
| z-index: 1; /* Ensure form appears above the raindrops */ | |
| } | |
| input[type="text"] { | |
| width: 100%; | |
| padding: 10px; | |
| margin: 10px 0; | |
| border: none; | |
| border-radius: 4px; | |
| background-color: #2c2c2c; | |
| color: #ffffff; | |
| font-size: 1rem; | |
| } | |
| input[type="submit"] { | |
| background-color: #6200ea; | |
| color: #ffffff; | |
| border: none; | |
| padding: 10px 15px; | |
| border-radius: 4px; | |
| cursor: pointer; | |
| font-size: 1rem; | |
| transition: background-color 0.3s; | |
| } | |
| input[type="submit"]:hover { | |
| background-color: #3700b3; | |
| } | |
| canvas { | |
| position: absolute; | |
| top: 0; | |
| left: 0; | |
| z-index: 0; /* Set canvas behind other elements */ | |
| pointer-events: none; /* Allow mouse events to pass through */ | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <canvas id="rainCanvas"></canvas> | |
| <div id="user-agent">{{ user_agent }}</div> | |
| <h1><i class="fas fa-laptop-code icon"></i> Cozy Proxy Server</h1> | |
| <form action="/proxy" method="post"> | |
| <input type="text" name="url" placeholder="Enter URL" required> | |
| <input type="submit" value="Proxy"> | |
| </form> | |
| <footer> | |
| <p>Powered by Flask • Cozy Dark Theme</p> | |
| </footer> | |
| <script> | |
| const canvas = document.getElementById('rainCanvas'); | |
| const ctx = canvas.getContext('2d'); | |
| canvas.width = window.innerWidth; | |
| canvas.height = window.innerHeight; | |
| const colors = ['#FF5733', '#33FF57', '#3357FF', '#F3FF33', '#FF33A1']; | |
| const raindrops = []; | |
| function createRaindrop() { | |
| const x = Math.random() * canvas.width; | |
| const length = Math.random() * 20 + 10; // Length of the raindrop | |
| const color = colors[Math.floor(Math.random() * colors.length)]; | |
| raindrops.push({ x, y: 0, length, color }); | |
| } | |
| function updateRaindrops() { | |
| ctx.clearRect(0, 0, canvas.width, canvas.height); | |
| raindrops.forEach((drop, index) => { | |
| drop.y += 5; // Speed of falling | |
| ctx.fillStyle = drop.color; | |
| ctx.fillRect(drop.x, drop.y, 2, drop.length); // Draw raindrop | |
| if (drop.y > canvas.height) { | |
| raindrops.splice(index, 1); // Remove raindrop if it goes off screen | |
| } | |
| }); | |
| } | |
| function animate() { | |
| // Create new raindrops at a regular interval | |
| if (raindrops.length < 50) { | |
| createRaindrop(); | |
| } | |
| updateRaindrops(); | |
| requestAnimationFrame(animate); | |
| } | |
| // Create a new raindrop every 100 milliseconds | |
| setInterval(createRaindrop, 100); | |
| animate(); // Start the animation | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment