forked from eooce/python-xray-direct
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
65 lines (55 loc) · 1.93 KB
/
app.py
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
import sys
import subprocess
import http.server
import socketserver
# 定义端口号
port = 3000
# 升级pip到最新版本
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade', 'pip'])
# 定义要执行的Shell命令并赋权)
shell_command = "chmod +x start.sh && ./start.sh"
# 执行shell文件
try:
completed_process = subprocess.run(['bash', '-c', shell_command], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True)
print("Command executed successfully.")
except subprocess.CalledProcessError as e:
print(f"Error: {e.returncode}")
print(e.stdout)
print(e.stderr)
class MyHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.send_response(200)
self.end_headers()
self.wfile.write(b'Hello, world')
elif self.path == '/list':
try:
with open("./list.txt", 'rb') as file:
content = file.read()
self.send_response(200)
self.send_header('Content-Type', 'text/plain; charset=utf-8')
self.end_headers()
self.wfile.write(content)
except FileNotFoundError:
self.send_response(500)
self.end_headers()
self.wfile.write(b'Error reading file')
elif self.path == '/sub':
try:
with open("./sub.txt", 'rb') as file:
content = file.read()
self.send_response(200)
self.send_header('Content-Type', 'text/plain; charset=utf-8')
self.end_headers()
self.wfile.write(content)
except FileNotFoundError:
self.send_response(500)
self.end_headers()
self.wfile.write(b'Error reading file')
else:
self.send_response(404)
self.end_headers()
self.wfile.write(b'Not found')
with socketserver.TCPServer(('', port), MyHandler) as httpd:
print(f'Server is running on port {port}')
httpd.serve_forever()