711
elif self.path == "/live_log":
logfile = os.path.expanduser(d.get("logfile", "").strip())
lines = int(d.get("lines", 100))
since_byte = int(d.get("since_byte", 0))
if not logfile:
self._send(400, {"error": "logfile required"}); return
try:
if not os.path.exists(logfile):
self._send(200, {"content": "", "file_size": 0, "success": True}); return
file_size = os.path.getsize(logfile)
if since_byte > 0 and since_byte < file_size:
with open(logfile, "r", errors="replace") as f:
f.seek(since_byte)
content = f.read()
else:
out, _, _ = run_cmd(f"tail -{lines} '{logfile}'", 5)
content = "" if out == "(no output)" else out
self._send(200, {"content": content, "file_size": file_size, "success": True})
except Exception as e:
self._send(200, {"content": "", "file_size": 0, "success": False, "error": str(e)})
elif self.path == "/read_log":
logfile = os.path.expanduser(d.get("logfile", "~/txdost_bg.log"))
lines = int(d.get("lines", 30))
try:
out, _, _ = run_cmd(f"tail -{lines} '{logfile}'", 10)
self._send(200, {"content": out if out != "(no output)" else "(empty)", "success": True})
except Exception as e:
self._send(200, {"content": str(e), "success": False})
else:
self._send(404, {"error": f"Unknown: {self.path}"})
if name == "main":
s = Server(("127.0.0.1", PORT), H)
print(f"[TX_Dost v5.1] Port {PORT} | PATH ready")
try: s.serve_forever()
except KeyboardInterrupt: print("Stopped.")
PYEOF
echo "✅ server.py v5.1 ready!" && cd ~/txdost && python server.py &
sleep 1 && curl -s http://127.0.0.1:8080/ping && echo "" && echo "✅ Server online!"
14 May, 01:29
14 May, ~10:41
