sfun commited on
Commit
193d1cd
1 Parent(s): 78baf01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -40,14 +40,25 @@ def extract_and_transform_proxies(input_text):
40
 
41
  transformed = f"{name} = ss, {server}, {port}, encrypt-method={cipher}, password={password}, udp-relay={udp}"
42
  transformed_proxies.append(transformed)
 
 
 
 
 
 
 
 
 
 
43
 
44
- return "\n".join(transformed_proxies) if transformed_proxies else "未找到有效的SS代理配置"
45
 
46
  class RequestHandler(BaseHTTPRequestHandler):
47
  def log_request(self, code='-', size='-'):
48
- timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
49
- sys.stdout.write(f"{timestamp} - {self.client_address[0]} - \"{self.requestline}\" {code} {size}\n")
50
- sys.stdout.flush()
 
51
 
52
  def do_GET(self):
53
  parsed_path = urlparse(self.path)
@@ -91,7 +102,7 @@ class RequestHandler(BaseHTTPRequestHandler):
91
  pass
92
 
93
  def run_server(port=8080):
94
- server_address = ('0.0.0.0', port) # 使用0.0.0.0而不是空字符串
95
  httpd = HTTPServer(server_address, RequestHandler)
96
  sys.stdout.write(f"===== Application Startup at {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')} =====\n")
97
  sys.stdout.write(f"Server running on port {port}\n")
 
40
 
41
  transformed = f"{name} = ss, {server}, {port}, encrypt-method={cipher}, password={password}, udp-relay={udp}"
42
  transformed_proxies.append(transformed)
43
+ elif proxy.get('type') == 'trojan':
44
+ name = proxy.get('name', '').strip()
45
+ server = proxy.get('server', '').strip()
46
+ port = str(proxy.get('port', '')).strip()
47
+ password = proxy.get('password', '').strip()
48
+ sni = proxy.get('sni', '').strip()
49
+ skip_cert_verify = str(proxy.get('skip-cert-verify', '')).lower()
50
+
51
+ transformed = f"{name} = trojan, {server}, {port}, password={password}, sni={sni}, skip-cert-verify={skip_cert_verify}"
52
+ transformed_proxies.append(transformed)
53
 
54
+ return "\n".join(transformed_proxies) if transformed_proxies else "未找到有效的SS或Trojan代理配置"
55
 
56
  class RequestHandler(BaseHTTPRequestHandler):
57
  def log_request(self, code='-', size='-'):
58
+ if 'url=' in self.path:
59
+ timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
60
+ sys.stdout.write(f"{timestamp} - {self.client_address[0]} - \"{self.requestline}\" {code} {size}\n")
61
+ sys.stdout.flush()
62
 
63
  def do_GET(self):
64
  parsed_path = urlparse(self.path)
 
102
  pass
103
 
104
  def run_server(port=8080):
105
+ server_address = ('0.0.0.0', port)
106
  httpd = HTTPServer(server_address, RequestHandler)
107
  sys.stdout.write(f"===== Application Startup at {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')} =====\n")
108
  sys.stdout.write(f"Server running on port {port}\n")