File size: 1,402 Bytes
c5ddf8d
 
a7c6564
 
 
c5ddf8d
 
 
 
 
 
 
 
ad07929
c5ddf8d
ad07929
c5ddf8d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from flask import Flask, request, Response
import requests

app = Flask(__name__)

# HTML form template to allow user input
html_form = '''
    <form action="/proxy" method="get">
        <label for="url">Enter URL:</label>
        <input type="text" id="url" name="url" placeholder="https://example.com" required>
        <button type="submit">Browse</button>
    </form>
'''

@app.route('/')
def home():
    # Display the form for URL input
    return html_form

@app.route('/proxy')
def proxy():
    # Get the URL from the user's input
    url = request.args.get('url')
    if not url:
        return "No URL provided", 400

    # Validate URL (must start with http:// or https:// for security)
    if not (url.startswith("http://") or url.startswith("https://")):
        return "Invalid URL. Please include http:// or https://", 400

    try:
        # Fetch the content from the specified URL
        response = requests.get(url)
        response.raise_for_status()  # Ensure the request was successful

        # Return the fetched content as a response to the user
        return Response(response.content, content_type=response.headers['Content-Type'])

    except requests.RequestException as e:
        # Handle errors in fetching the page
        return f"Error fetching the page: {e}"

if __name__ == "__main__":
    # Run the Flask app on port 7860
    app.run(host="0.0.0.0", port=7860)