Files
archived-sslocal-manager-al…/app.py
T
WilliamPeterMatthew 0594997c65 change udp config
2025-06-01 22:54:03 +08:00

64 lines
1.5 KiB
Python

import os
import subprocess
import re
import platform
from flask import Flask, render_template, request, redirect
app = Flask(__name__)
kernel_ver = platform.release()
match = re.search(r'(\d+)\.(\d+)', kernel_ver)
cmv, csv = (int(match.group(1)), int(match.group(2))) if match else (0, 0)
TFO = ""
if cmv >= 3 and csv > 7:
TFO = "--tcp-fast-open"
ARGS=os.getenv("ARGS","")
def get_status():
try:
with open('/var/run/sslocal.pid', 'r') as f:
pid = f.read().strip()
# 检查进程是否存在
os.kill(int(pid), 0)
return (True, pid)
except (FileNotFoundError, ValueError, ProcessLookupError):
return (False, None)
@app.route('/')
def index():
status = get_status()
return render_template('index.html',
running=status[0],
pid=status[1])
@app.route('/status')
def status():
running, pid = get_status()
if running:
return f"Running With PID {pid}", 200
return "Not Running", 502
@app.route('/action', methods=['POST'])
def action():
running, pid = get_status()
if running:
subprocess.run(["kill", pid])
os.remove('/var/run/sslocal.pid')
else:
subprocess.Popen([
"sslocal",
"--log-without-time",
"-c", "/.ssconfig.json",
"--daemonize-pid", "/var/run/sslocal.pid",
TFO,
ARGS,
])
return redirect('/')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)