File size: 4,121 Bytes
f206303
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from flask import Flask, render_template_string, request
import requests
from bs4 import BeautifulSoup

app = Flask(__name__)

HTML_TEMPLATE = """
<!doctype html>
<html lang="en">
  <head>
    <title>πŸ” Privacy Score Analyzer</title>
    <style>
      body { font-family: Arial, sans-serif; background-color: #f2f2f2; padding: 30px; }
      .container { max-width: 700px; margin: auto; background-color: white; padding: 25px; border-radius: 10px; box-shadow: 0px 0px 10px rgba(0,0,0,0.1); }
      h1 { color: #333; }
      .score { font-size: 1.5em; color: #007bff; margin-top: 20px; }
      .issues { color: red; }
      .success { color: green; }
      input[type="text"] { width: 100%; padding: 10px; margin-top: 10px; margin-bottom: 15px; border-radius: 5px; border: 1px solid #ccc; }
      input[type="submit"] { padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer; }
      input[type="submit"]:hover { background-color: #0056b3; }
    </style>
  </head>
  <body>
    <div class="container">
      <h1>πŸ” Privacy Score Analyzer</h1>
      <form method="post">
        <label for="url">Enter a website:</label>
        <input type="text" name="url" placeholder="e.g. nytimes.com" required>
        <input type="submit" value="Analyze">
      </form>
      {% if score is not none %}
        <div class="score">πŸ”Ž Privacy Score: {{ score }}/100</div>
        {% if issues %}
          <div class="issues">
            <h3>⚠️ Issues Found:</h3>
            <ul>
              {% for issue in issues %}
                <li>{{ issue }}</li>
              {% endfor %}
            </ul>
          </div>
        {% else %}
          <div class="success">βœ… Excellent! No major privacy issues found.</div>
        {% endif %}
      {% endif %}
      {% if error %}
        <div class="issues"><strong>Error:</strong> {{ error }}</div>
      {% endif %}
    </div>
  </body>
</html>
"""

@app.route('/', methods=['GET', 'POST'])
def analyze():
    score = None
    issues = []
    error = None

    if request.method == 'POST':
        url_input = request.form.get('url', '').strip()
        if not url_input:
            error = "Please enter a valid URL."
        else:
            try:
                # Add http:// if missing
                if not url_input.startswith("http"):
                    url_input = "http://" + url_input

                headers = {
                    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
                }
                response = requests.get(url_input, headers=headers, timeout=8)
                html = response.text
                soup = BeautifulSoup(html, "html.parser")

                score = 100
                final_url = response.url

                # Check HTTPS
                if not final_url.startswith("https"):
                    score -= 20
                    issues.append("❌ Website does not use HTTPS.")

                # Check trackers
                tracker_keywords = ["google-analytics", "doubleclick", "facebook.net"]
                trackers_found = []
                for script in soup.find_all("script"):
                    for keyword in tracker_keywords:
                        if keyword in str(script).lower():
                            trackers_found.append(keyword)
                if trackers_found:
                    score -= 20
                    issues.append(f"❌ Trackers found: {', '.join(set(trackers_found))}")

                # Check Content-Security-Policy
                meta_csp = soup.find("meta", attrs={"http-equiv": "Content-Security-Policy"})
                if not meta_csp:
                    score -= 10
                    issues.append("❌ Missing Content-Security-Policy tag.")

            except requests.exceptions.RequestException as e:
                error = f"Network error: {e}"
            except Exception as e:
                error = f"Unexpected error: {e}"

    return render_template_string(HTML_TEMPLATE, score=score, issues=issues, error=error)

if __name__ == '__main__':
    app.run(debug=True)