File size: 4,180 Bytes
561e417 c8dd460 561e417 c8dd460 561e417 c8dd460 561e417 c8dd460 561e417 c8dd460 561e417 c8dd460 561e417 c8dd460 561e417 c8dd460 561e417 f0155d3 |
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
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')
# Rimozione script
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()
# Rimozione elementi
for selector in AD_CONFIG['blocked_patterns']['elements']:
for element in soup.select(selector):
element.decompose()
# Iniezione CSS
style = soup.new_tag('style')
style.string = AD_CONFIG['security']['css']
soup.head.append(style)
# Iniezione JS
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() |