LPX55 commited on
Commit
b4436ad
·
verified ·
1 Parent(s): f88c9f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -12
app.py CHANGED
@@ -12,7 +12,7 @@ HOME_PAGE = """
12
  <!DOCTYPE html>
13
  <html>
14
  <head>
15
- <title>Simple Web Proxy</title>
16
  <style>
17
  body { font-family: Arial, sans-serif; text-align: center; margin-top: 50px; }
18
  .container { max-width: 600px; margin: 0 auto; }
@@ -23,21 +23,17 @@ HOME_PAGE = """
23
  </head>
24
  <body>
25
  <div class="container">
26
- <h1>Web Proxy</h1>
27
  <form id="proxyForm">
28
- <input type="text" id="urlInput" placeholder="Enter URL to visit (e.g.: https://github.com)" required>
29
  <button type="submit">Access</button>
30
  </form>
31
- <div class="note">
32
- <p>Enter full URL including https:// prefix</p>
33
- </div>
34
  </div>
35
  <script>
36
  document.getElementById('proxyForm').addEventListener('submit', function(e) {
37
  e.preventDefault();
38
  const url = document.getElementById('urlInput').value;
39
  if(url) {
40
- window.location.href = '/proxy/' + encodeURIComponent(btoa(url));
41
  }
42
  });
43
  </script>
@@ -48,7 +44,7 @@ HOME_PAGE = """
48
  def index():
49
  return HOME_PAGE
50
 
51
- @app.route('/proxy/<path:encoded_url>')
52
  def proxy_path(encoded_url):
53
  try:
54
  # Base64 decode the URL
@@ -74,6 +70,7 @@ def base64_decode(encoded):
74
  # If decoding fails, return the original value
75
  return encoded
76
 
 
77
  def proxy_request(url):
78
  try:
79
  # If the URL is not a complete HTTP URL, add the protocol
@@ -130,7 +127,7 @@ def rewrite_links(content, base_url):
130
  # Encode the URL as Base64 and add the proxy prefix
131
  if absolute_url.startswith('http'):
132
  encoded = base64.b64encode(absolute_url.encode()).decode()
133
- return f"/proxy/{urllib.parse.quote(encoded)}"
134
  return url
135
  # 1. Replace href attributes
136
  content_str = re.sub(r'href=["\'](.*?)["\']',
@@ -151,7 +148,7 @@ def rewrite_links(content, base_url):
151
  // Create Base64 encoding function
152
  function encodeURL(url) {
153
  if(url && url.startsWith('http')) {
154
- return '/proxy/' + encodeURIComponent(btoa(url));
155
  }
156
  return url;
157
  }
@@ -175,7 +172,7 @@ def rewrite_links(content, base_url):
175
  document.addEventListener('click', function(e) {
176
  const target = e.target.closest('a');
177
  if(target && target.href && target.href.startsWith('http') &&
178
- !target.href.includes('/proxy/')) {
179
  e.preventDefault();
180
  location.href = encodeURL(target.href);
181
  }
@@ -195,7 +192,7 @@ def rewrite_links(content, base_url):
195
 
196
  import base64
197
 
198
- @app.route('/proxy', methods=['GET'])
199
  def proxy_get():
200
  url = request.args.get('url', '')
201
  if not url:
 
12
  <!DOCTYPE html>
13
  <html>
14
  <head>
15
+ <title>Hello</title>
16
  <style>
17
  body { font-family: Arial, sans-serif; text-align: center; margin-top: 50px; }
18
  .container { max-width: 600px; margin: 0 auto; }
 
23
  </head>
24
  <body>
25
  <div class="container">
 
26
  <form id="proxyForm">
27
+ <input type="text" id="urlInput" placeholder="Enter URL" required>
28
  <button type="submit">Access</button>
29
  </form>
 
 
 
30
  </div>
31
  <script>
32
  document.getElementById('proxyForm').addEventListener('submit', function(e) {
33
  e.preventDefault();
34
  const url = document.getElementById('urlInput').value;
35
  if(url) {
36
+ window.location.href = '/go/' + encodeURIComponent(btoa(url));
37
  }
38
  });
39
  </script>
 
44
  def index():
45
  return HOME_PAGE
46
 
47
+ @app.route('/go/<path:encoded_url>')
48
  def proxy_path(encoded_url):
49
  try:
50
  # Base64 decode the URL
 
70
  # If decoding fails, return the original value
71
  return encoded
72
 
73
+
74
  def proxy_request(url):
75
  try:
76
  # If the URL is not a complete HTTP URL, add the protocol
 
127
  # Encode the URL as Base64 and add the proxy prefix
128
  if absolute_url.startswith('http'):
129
  encoded = base64.b64encode(absolute_url.encode()).decode()
130
+ return f"/go/{urllib.parse.quote(encoded)}"
131
  return url
132
  # 1. Replace href attributes
133
  content_str = re.sub(r'href=["\'](.*?)["\']',
 
148
  // Create Base64 encoding function
149
  function encodeURL(url) {
150
  if(url && url.startsWith('http')) {
151
+ return '/go/' + encodeURIComponent(btoa(url));
152
  }
153
  return url;
154
  }
 
172
  document.addEventListener('click', function(e) {
173
  const target = e.target.closest('a');
174
  if(target && target.href && target.href.startsWith('http') &&
175
+ !target.href.includes('/go/')) {
176
  e.preventDefault();
177
  location.href = encodeURL(target.href);
178
  }
 
192
 
193
  import base64
194
 
195
+ @app.route('/go', methods=['GET'])
196
  def proxy_get():
197
  url = request.args.get('url', '')
198
  if not url: