Update app.py
Browse files
app.py
CHANGED
|
@@ -1,113 +1,145 @@
|
|
| 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 |
-
'
|
| 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 |
app.run()
|
|
|
|
| 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_patterns': {
|
| 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 |
+
const blockedPatterns = %s;
|
| 45 |
+
const blockedElements = %s;
|
| 46 |
+
|
| 47 |
+
function nuclearCleaner() {
|
| 48 |
+
// Clean existing elements
|
| 49 |
+
blockedElements.forEach(selector => {
|
| 50 |
+
document.querySelectorAll(selector).forEach(el => el.remove());
|
| 51 |
+
});
|
| 52 |
+
|
| 53 |
+
// Block dynamic content
|
| 54 |
+
new MutationObserver(mutations => {
|
| 55 |
+
mutations.forEach(({ addedNodes }) => {
|
| 56 |
+
addedNodes.forEach(node => {
|
| 57 |
+
if(node.nodeType === 1) {
|
| 58 |
+
blockedElements.forEach(selector => {
|
| 59 |
+
node.querySelectorAll(selector).forEach(el => el.remove());
|
| 60 |
+
});
|
| 61 |
+
}
|
| 62 |
+
});
|
| 63 |
+
});
|
| 64 |
+
}).observe(document.body, { childList: true, subtree: true });
|
| 65 |
+
|
| 66 |
+
// Block network requests
|
| 67 |
+
const originalFetch = window.fetch;
|
| 68 |
+
window.fetch = function(url, options) {
|
| 69 |
+
if(blockedPatterns.some(pattern => new RegExp(pattern, 'i').test(url))) {
|
| 70 |
+
return new Promise(() => {});
|
| 71 |
+
}
|
| 72 |
+
return originalFetch(url, options);
|
| 73 |
+
};
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
document.addEventListener('DOMContentLoaded', nuclearCleaner);
|
| 77 |
+
window.addEventListener('load', nuclearCleaner);
|
| 78 |
+
"""
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
def enhance_security(html):
|
| 83 |
+
soup = BeautifulSoup(html, 'lxml')
|
| 84 |
+
|
| 85 |
+
# Rimozione script
|
| 86 |
+
for script in soup.find_all('script'):
|
| 87 |
+
src = script.get('src', '')
|
| 88 |
+
if any(re.search(pattern, src, re.I) for pattern in AD_CONFIG['blocked_patterns']['scripts']):
|
| 89 |
+
script.decompose()
|
| 90 |
+
|
| 91 |
+
# Rimozione elementi
|
| 92 |
+
for selector in AD_CONFIG['blocked_patterns']['elements']:
|
| 93 |
+
for element in soup.select(selector):
|
| 94 |
+
element.decompose()
|
| 95 |
+
|
| 96 |
+
# Iniezione protezioni
|
| 97 |
+
style = soup.new_tag('style')
|
| 98 |
+
style.string = AD_CONFIG['security']['css']
|
| 99 |
+
soup.head.append(style)
|
| 100 |
+
|
| 101 |
+
script = soup.new_tag('script')
|
| 102 |
+
script.string = AD_CONFIG['security']['js'] % (
|
| 103 |
+
AD_CONFIG['blocked_patterns']['scripts'],
|
| 104 |
+
AD_CONFIG['blocked_patterns']['elements']
|
| 105 |
+
)
|
| 106 |
+
soup.body.append(script)
|
| 107 |
+
|
| 108 |
+
return str(soup)
|
| 109 |
+
|
| 110 |
+
@app.route('/', defaults={'path': ''})
|
| 111 |
+
@app.route('/<path:path>')
|
| 112 |
+
def secure_proxy(path):
|
| 113 |
+
BASE_URL = "https://gam.onl/"
|
| 114 |
+
target_url = f"{BASE_URL}{path}?{request.query_string.decode()}"
|
| 115 |
+
|
| 116 |
+
try:
|
| 117 |
+
response = requests.get(
|
| 118 |
+
target_url,
|
| 119 |
+
headers={
|
| 120 |
+
'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',
|
| 121 |
+
'Referer': BASE_URL
|
| 122 |
+
},
|
| 123 |
+
timeout=15
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
if response.status_code == 200:
|
| 127 |
+
content = enhance_security(response.content)
|
| 128 |
+
return Response(
|
| 129 |
+
content,
|
| 130 |
+
content_type=response.headers.get('Content-Type', 'text/html'),
|
| 131 |
+
headers={
|
| 132 |
+
'Cache-Control': 'no-store, max-age=0',
|
| 133 |
+
'X-Content-Type-Options': 'nosniff',
|
| 134 |
+
'X-Frame-Options': 'DENY'
|
| 135 |
+
}
|
| 136 |
+
)
|
| 137 |
+
return Response("Error: Origin server response", status=502)
|
| 138 |
+
|
| 139 |
+
except requests.exceptions.RequestException as e:
|
| 140 |
+
return Response(f"Network Error: {str(e)}", status=503)
|
| 141 |
+
except Exception as e:
|
| 142 |
+
return Response(f"Internal Error: {str(e)}", status=500)
|
| 143 |
+
|
| 144 |
+
if __name__ == '__main__':
|
| 145 |
app.run()
|