ServerX commited on
Commit
f0155d3
·
verified ·
1 Parent(s): 4e8c533

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +113 -0
app.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, Response, request
2
+ import requests
3
+ import re
4
+ from bs4 import BeautifulSoup
5
+
6
+ app = Flask(__name__)
7
+
8
+ AD_CONFIG = {
9
+ 'blocked_scripts': [
10
+ r'googletag\.js',
11
+ r'adsbygoogle\.js',
12
+ r'doubleclick\.net',
13
+ r'adservice\.google',
14
+ r'pagead2\.googlesyndication',
15
+ r'analytics\.google',
16
+ r'prosecutorremarkablegodforsaken',
17
+ r'recordedthereby',
18
+ r'cse\.google'
19
+ ],
20
+ 'blocked_selectors': [
21
+ '[class*="ad"]',
22
+ '[id*="ad"]',
23
+ '[class*="banner"]',
24
+ 'iframe[src*="ads"]',
25
+ 'ins.adsbygoogle',
26
+ '.gsc-control-cse',
27
+ '.menu-search',
28
+ '[onclick*="showhide"]'
29
+ ]
30
+ }
31
+
32
+ def sanitize_content(html):
33
+ soup = BeautifulSoup(html, 'lxml')
34
+
35
+ # Rimozione script
36
+ for script in soup.find_all('script'):
37
+ if script.get('src') and any(re.search(p, script['src'], re.I) for p in AD_CONFIG['blocked_scripts']):
38
+ script.decompose()
39
+
40
+ # Rimozione elementi
41
+ for selector in AD_CONFIG['blocked_selectors']:
42
+ for elem in soup.select(selector):
43
+ elem.decompose()
44
+
45
+ # Iniezione sicurezza
46
+ security_css = """
47
+ <style>
48
+ .gsc-control-cse, .gsc-input, .menu-search,
49
+ [class*="ad"], [id*="ad"], [class*="banner"] {
50
+ display: none !important;
51
+ height: 0 !important;
52
+ width: 0 !important;
53
+ opacity: 0 !important;
54
+ }
55
+ </style>
56
+ """
57
+ soup.head.append(BeautifulSoup(security_css, 'html.parser'))
58
+
59
+ security_js = """
60
+ <script>
61
+ window.addEventListener('DOMContentLoaded', () => {
62
+ const blockedSelectors = %s;
63
+ new MutationObserver(mutations => {
64
+ mutations.forEach(({addedNodes}) => {
65
+ addedNodes.forEach(node => {
66
+ if(node.nodeType === 1) {
67
+ blockedSelectors.forEach(selector => {
68
+ node.querySelectorAll(selector).forEach(el => el.remove());
69
+ });
70
+ }
71
+ });
72
+ });
73
+ }).observe(document.body, {childList: true, subtree: true});
74
+ });
75
+ </script>
76
+ """ % AD_CONFIG['blocked_selectors']
77
+
78
+ soup.body.append(BeautifulSoup(security_js, 'html.parser'))
79
+
80
+ return str(soup)
81
+
82
+ @app.route('/', defaults={'path': ''})
83
+ @app.route('/<path:path>')
84
+ def proxy(path):
85
+ base_url = "https://gam.onl/"
86
+ target_url = f"{base_url}{path}?{request.query_string.decode()}"
87
+
88
+ try:
89
+ response = requests.get(
90
+ target_url,
91
+ headers={
92
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
93
+ 'Referer': base_url
94
+ },
95
+ timeout=15
96
+ )
97
+
98
+ content = sanitize_content(response.content)
99
+
100
+ return Response(
101
+ content,
102
+ content_type=response.headers.get('Content-Type', 'text/html'),
103
+ headers={
104
+ 'Cache-Control': 'no-cache, max-age=0',
105
+ 'X-Frame-Options': 'SAMEORIGIN'
106
+ }
107
+ )
108
+
109
+ except Exception as e:
110
+ return Response(f"Error: {str(e)}", status=500)
111
+
112
+ if __name__ == '__main__':
113
+ app.run()