ServerX commited on
Commit
561e417
·
verified ·
1 Parent(s): 7462773

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +144 -112
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
- '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()
 
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()