|
from flask import Flask, Response, request |
|
import requests |
|
import re |
|
from bs4 import BeautifulSoup |
|
|
|
app = Flask(__name__) |
|
|
|
AD_CONFIG = { |
|
'blocked_patterns': { |
|
'scripts': [ |
|
r'googletag\.js', |
|
r'adsbygoogle\.js', |
|
r'doubleclick\.net', |
|
r'adservice\.google', |
|
r'pagead2\.googlesyndication', |
|
r'analytics\.google', |
|
r'prosecutorremarkablegodforsaken', |
|
r'recordedthereby', |
|
r'cse\.google' |
|
], |
|
'elements': [ |
|
'[class*="ad"]', |
|
'[id*="ad"]', |
|
'[class*="banner"]', |
|
'iframe[src*="ads"]', |
|
'ins.adsbygoogle', |
|
'.gsc-control-cse', |
|
'.menu-search', |
|
'[onclick*="showhide"]' |
|
] |
|
}, |
|
'security': { |
|
'css': """ |
|
.gsc-control-cse, .gsc-input, .menu-search, |
|
[class*="ad"], [id*="ad"], [class*="banner"] { |
|
display: none !important; |
|
height: 0 !important; |
|
width: 0 !important; |
|
opacity: 0 !important; |
|
pointer-events: none !important; |
|
} |
|
""", |
|
'js': """ |
|
document.addEventListener('DOMContentLoaded', () => { |
|
const blockedElements = %s; |
|
|
|
// Pulizia iniziale |
|
blockedElements.forEach(selector => { |
|
document.querySelectorAll(selector).forEach(el => el.remove()); |
|
}); |
|
|
|
// Observer per contenuti dinamici |
|
new MutationObserver(mutations => { |
|
mutations.forEach(({ addedNodes }) => { |
|
addedNodes.forEach(node => { |
|
if(node.nodeType === 1) { |
|
blockedElements.forEach(selector => { |
|
node.querySelectorAll(selector).forEach(el => el.remove()); |
|
}); |
|
} |
|
}); |
|
}); |
|
}).observe(document.body, { |
|
childList: true, |
|
subtree: true |
|
}); |
|
}); |
|
""" |
|
} |
|
} |
|
|
|
def enhance_security(html): |
|
soup = BeautifulSoup(html, 'lxml') |
|
|
|
|
|
for script in soup.find_all('script'): |
|
src = script.get('src', '') |
|
if any(re.search(pattern, src, re.I) for pattern in AD_CONFIG['blocked_patterns']['scripts']): |
|
script.decompose() |
|
|
|
|
|
for selector in AD_CONFIG['blocked_patterns']['elements']: |
|
for element in soup.select(selector): |
|
element.decompose() |
|
|
|
|
|
style = soup.new_tag('style') |
|
style.string = AD_CONFIG['security']['css'] |
|
soup.head.append(style) |
|
|
|
|
|
script = soup.new_tag('script') |
|
script.string = AD_CONFIG['security']['js'] % AD_CONFIG['blocked_patterns']['elements'] |
|
soup.body.append(script) |
|
|
|
return str(soup) |
|
|
|
@app.route('/', defaults={'path': ''}) |
|
@app.route('/<path:path>') |
|
def secure_proxy(path): |
|
BASE_URL = "https://gam.onl/" |
|
target_url = f"{BASE_URL}{path}?{request.query_string.decode()}" |
|
|
|
try: |
|
response = requests.get( |
|
target_url, |
|
headers={ |
|
'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', |
|
'Referer': BASE_URL |
|
}, |
|
timeout=15 |
|
) |
|
|
|
if response.status_code == 200: |
|
content = enhance_security(response.content) |
|
return Response( |
|
content, |
|
content_type=response.headers.get('Content-Type', 'text/html'), |
|
headers={ |
|
'Cache-Control': 'no-store, max-age=0', |
|
'X-Content-Type-Options': 'nosniff' |
|
} |
|
) |
|
return Response("Error: Origin server response", status=502) |
|
|
|
except Exception as e: |
|
return Response(f"Error: {str(e)}", status=500) |
|
|
|
if __name__ == '__main__': |
|
app.run() |