mirror of
https://github.com/hotyue/IP-Sentinel.git
synced 2026-06-06 17:29:49 +08:00
chore: revert failed v3.6.0 attempts, rollback to safe state
This commit is contained in:
@@ -292,86 +292,7 @@ class AgentHandler(http.server.BaseHTTPRequestHandler):
|
||||
self.send_response(400)
|
||||
self.end_headers()
|
||||
self.wfile.write(b"400 Bad Request: Invalid Characters\n")
|
||||
|
||||
# ================== [v3.6.0 新增: 远程 OTA 升级接口] ==================
|
||||
elif req_path == '/trigger_upgrade':
|
||||
try:
|
||||
allow_ota = "false"
|
||||
if os.path.exists('/opt/ip_sentinel/config.conf'):
|
||||
with open('/opt/ip_sentinel/config.conf', 'r') as f:
|
||||
for line in f:
|
||||
if line.startswith('ALLOW_OTA='):
|
||||
allow_ota = line.strip().split('=', 1)[1].strip('"\'')
|
||||
break
|
||||
|
||||
if allow_ota.lower() != "true":
|
||||
self.send_response(403)
|
||||
self.end_headers()
|
||||
self.wfile.write(b"403 Forbidden: OTA Disabled\n")
|
||||
return
|
||||
|
||||
# 1. 精确斩断 HTTP:声明内容长度并强制 Close,让 Master 瞬间拿到回执并断开 TCP 连接
|
||||
resp_msg = b"Action Accepted: trigger_upgrade\n"
|
||||
self.send_response(200)
|
||||
self.send_header("Content-type", "text/plain")
|
||||
self.send_header("Content-Length", str(len(resp_msg)))
|
||||
self.send_header("Connection", "close")
|
||||
self.end_headers()
|
||||
self.wfile.write(resp_msg)
|
||||
self.wfile.flush()
|
||||
|
||||
# 2. 终极无状态执行脱壳:
|
||||
# stdin=subprocess.DEVNULL: 彻底切断标准输入,防止 curl|bash 误读环境吞噬管道
|
||||
# close_fds=True & start_new_session=True: 剥夺所有网络 Socket 和进程树的血缘关系
|
||||
cmd = "sleep 2 && export SILENT_OTA=true && curl -sL https://raw.githubusercontent.com/hotyue/IP-Sentinel/main/core/install.sh | bash"
|
||||
subprocess.Popen(cmd, shell=True, start_new_session=True, close_fds=True,
|
||||
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
|
||||
except Exception as e:
|
||||
self.send_response(500)
|
||||
self.end_headers()
|
||||
|
||||
# ================== [v3.6.0 新增: 模块动态启停接口] ==================
|
||||
elif req_path == '/trigger_toggle':
|
||||
mod_name = query.get('mod', [''])[0]
|
||||
target_state = query.get('state', [''])[0].lower()
|
||||
|
||||
if mod_name not in ['google', 'trust'] or target_state not in ['true', 'false']:
|
||||
self.send_response(400)
|
||||
self.end_headers()
|
||||
self.wfile.write(b"400 Bad Request: Invalid parameters\n")
|
||||
return
|
||||
|
||||
config_key = f"ENABLE_{mod_name.upper()}="
|
||||
|
||||
try:
|
||||
config_path = '/opt/ip_sentinel/config.conf'
|
||||
with open(config_path, 'r', encoding='utf-8', errors='ignore') as f:
|
||||
lines = f.readlines()
|
||||
|
||||
found = False
|
||||
for i, line in enumerate(lines):
|
||||
if line.startswith(config_key):
|
||||
lines[i] = f'{config_key}"{target_state}"\n'
|
||||
found = True
|
||||
break
|
||||
|
||||
if not found:
|
||||
lines.append(f'{config_key}"{target_state}"\n')
|
||||
|
||||
with open(config_path, 'w', encoding='utf-8') as f:
|
||||
f.writelines(lines)
|
||||
|
||||
self.send_response(200)
|
||||
self.send_header("Content-type", "text/plain")
|
||||
self.end_headers()
|
||||
self.wfile.write(b"Action Accepted: trigger_toggle\n")
|
||||
|
||||
except Exception as e:
|
||||
self.send_response(500)
|
||||
self.end_headers()
|
||||
self.wfile.write(f"500 Internal Error: {str(e)}\n".encode('utf-8'))
|
||||
|
||||
else:
|
||||
self.send_response(404)
|
||||
self.end_headers()
|
||||
|
||||
Reference in New Issue
Block a user