Update app.py
Browse files
app.py
CHANGED
@@ -1,130 +1,13 @@
|
|
1 |
-
from flask import Flask,
|
2 |
-
import requests
|
3 |
-
import re
|
4 |
-
from bs4 import BeautifulSoup
|
5 |
|
6 |
app = Flask(__name__)
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
'scripts': [
|
11 |
-
r'googletag\.js',
|
12 |
-
r'adsbygoogle\.js',
|
13 |
-
r'doubleclick\.net',
|
14 |
-
r'adservice\.google',
|
15 |
-
r'pagead2\.googlesyndication',
|
16 |
-
r'analytics\.google',
|
17 |
-
r'prosecutorremarkablegodforsaken',
|
18 |
-
r'recordedthereby',
|
19 |
-
r'cse\.google'
|
20 |
-
],
|
21 |
-
'elements': [
|
22 |
-
'[class*="ad"]',
|
23 |
-
'[id*="ad"]',
|
24 |
-
'[class*="banner"]',
|
25 |
-
'iframe[src*="ads"]',
|
26 |
-
'ins.adsbygoogle',
|
27 |
-
'.gsc-control-cse',
|
28 |
-
'.menu-search',
|
29 |
-
'[onclick*="showhide"]'
|
30 |
-
]
|
31 |
-
},
|
32 |
-
'security': {
|
33 |
-
'css': """
|
34 |
-
.gsc-control-cse, .gsc-input, .menu-search,
|
35 |
-
[class*="ad"], [id*="ad"], [class*="banner"] {
|
36 |
-
display: none !important;
|
37 |
-
height: 0 !important;
|
38 |
-
width: 0 !important;
|
39 |
-
opacity: 0 !important;
|
40 |
-
pointer-events: none !important;
|
41 |
-
}
|
42 |
-
""",
|
43 |
-
'js': """
|
44 |
-
document.addEventListener('DOMContentLoaded', () => {
|
45 |
-
const blockedElements = %s;
|
46 |
-
|
47 |
-
// Pulizia iniziale
|
48 |
-
blockedElements.forEach(selector => {
|
49 |
-
document.querySelectorAll(selector).forEach(el => el.remove());
|
50 |
-
});
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
addedNodes.forEach(node => {
|
56 |
-
if(node.nodeType === 1) {
|
57 |
-
blockedElements.forEach(selector => {
|
58 |
-
node.querySelectorAll(selector).forEach(el => el.remove());
|
59 |
-
});
|
60 |
-
}
|
61 |
-
});
|
62 |
-
});
|
63 |
-
}).observe(document.body, {
|
64 |
-
childList: true,
|
65 |
-
subtree: true
|
66 |
-
});
|
67 |
-
});
|
68 |
-
"""
|
69 |
-
}
|
70 |
-
}
|
71 |
-
|
72 |
-
def enhance_security(html):
|
73 |
-
soup = BeautifulSoup(html, 'lxml')
|
74 |
-
|
75 |
-
# Rimozione script
|
76 |
-
for script in soup.find_all('script'):
|
77 |
-
src = script.get('src', '')
|
78 |
-
if any(re.search(pattern, src, re.I) for pattern in AD_CONFIG['blocked_patterns']['scripts']):
|
79 |
-
script.decompose()
|
80 |
-
|
81 |
-
# Rimozione elementi
|
82 |
-
for selector in AD_CONFIG['blocked_patterns']['elements']:
|
83 |
-
for element in soup.select(selector):
|
84 |
-
element.decompose()
|
85 |
-
|
86 |
-
# Iniezione CSS
|
87 |
-
style = soup.new_tag('style')
|
88 |
-
style.string = AD_CONFIG['security']['css']
|
89 |
-
soup.head.append(style)
|
90 |
-
|
91 |
-
# Iniezione JS
|
92 |
-
script = soup.new_tag('script')
|
93 |
-
script.string = AD_CONFIG['security']['js'] % AD_CONFIG['blocked_patterns']['elements']
|
94 |
-
soup.body.append(script)
|
95 |
-
|
96 |
-
return str(soup)
|
97 |
-
|
98 |
-
@app.route('/', defaults={'path': ''})
|
99 |
-
@app.route('/<path:path>')
|
100 |
-
def secure_proxy(path):
|
101 |
-
BASE_URL = "https://gam.onl/"
|
102 |
-
target_url = f"{BASE_URL}{path}?{request.query_string.decode()}"
|
103 |
-
|
104 |
-
try:
|
105 |
-
response = requests.get(
|
106 |
-
target_url,
|
107 |
-
headers={
|
108 |
-
'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',
|
109 |
-
'Referer': BASE_URL
|
110 |
-
},
|
111 |
-
timeout=15
|
112 |
-
)
|
113 |
-
|
114 |
-
if response.status_code == 200:
|
115 |
-
content = enhance_security(response.content)
|
116 |
-
return Response(
|
117 |
-
content,
|
118 |
-
content_type=response.headers.get('Content-Type', 'text/html'),
|
119 |
-
headers={
|
120 |
-
'Cache-Control': 'no-store, max-age=0',
|
121 |
-
'X-Content-Type-Options': 'nosniff'
|
122 |
-
}
|
123 |
-
)
|
124 |
-
return Response("Error: Origin server response", status=502)
|
125 |
-
|
126 |
-
except Exception as e:
|
127 |
-
return Response(f"Error: {str(e)}", status=500)
|
128 |
|
129 |
if __name__ == '__main__':
|
130 |
app.run()
|
|
|
1 |
+
from flask import Flask, render_template_string
|
|
|
|
|
|
|
2 |
|
3 |
app = Flask(__name__)
|
4 |
|
5 |
+
with open('index.html', 'r') as f:
|
6 |
+
html_content = f.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
@app.route('/')
|
9 |
+
def home():
|
10 |
+
return render_template_string(html_content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
if __name__ == '__main__':
|
13 |
app.run()
|