Add VPS Xray reload action

This commit is contained in:
kzolotarev95 committed 2026-06-29 06:10:21 +04:00
1 parent f02161f683
commit d21f279f89
2 files changed
+62

No files matched your search

+10
View File
@@ -125,6 +125,16 @@ sudo /opt/owrt-remote/owrt-remote-hub.py render-xray --out /etc/xray/owrt-remote
sudo systemctl restart owrt-remote-xray sudo systemctl restart owrt-remote-xray
``` ```
Если кнопка `Админка` пишет `proxy error: [Errno 111] Connection refused`, значит VPS Xray еще не слушает `entry_port` этого роутера. В Hub нажми `Обновить Xray VPS` или выполни:
```sh
sudo /opt/owrt-remote/owrt-remote-hub.py render-xray --out /etc/xray/owrt-remote.json
sudo systemctl restart owrt-remote-xray
sudo ss -lntp | grep -E ':(8443|18080|18090|18100|18095)\b'
```
Для роутера с `entry 18095` в выводе должен появиться `127.0.0.1:18095`.
Сгенерировать Xray config для VPS: Сгенерировать Xray config для VPS:
```sh ```sh
+52
View File
@@ -8,6 +8,7 @@ import json
import os import os
import secrets import secrets
import sqlite3 import sqlite3
import subprocess
import sys import sys
import time import time
import urllib.parse import urllib.parse
@@ -481,6 +482,33 @@ def make_router_xray_config(row):
} }
def reload_vps_xray(db_path=DB_PATH):
out = Path(os.environ.get("OWRT_REMOTE_XRAY_CONFIG", "/etc/xray/owrt-remote.json"))
service = os.environ.get("OWRT_REMOTE_XRAY_SERVICE", "owrt-remote-xray")
with connect(db_path) as conn:
init_db(conn)
rows = list_router_rows(conn)
config = make_server_xray_config(rows)
out.parent.mkdir(parents=True, exist_ok=True)
out.write_text(json.dumps(config, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
try:
os.chmod(out, 0o600)
except OSError:
pass
result = subprocess.run(
["systemctl", "restart", service],
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
timeout=20,
check=False,
)
if result.returncode != 0:
detail = (result.stderr or result.stdout or "").strip()
raise RuntimeError(f"systemctl restart {service} failed: {detail}")
return {"config": str(out), "service": service, "routers": len(rows)}
def make_openwrt_config(row, hub_url): def make_openwrt_config(row, hub_url):
lines = [ lines = [
"uci -q delete owrtremote.main", "uci -q delete owrtremote.main",
@@ -581,6 +609,7 @@ input,select{{min-width:0;border:1px solid var(--line);border-radius:8px;padding
</div> </div>
<div class="headerActions"> <div class="headerActions">
<div class="badge"><span class="dot on"></span>Hub online</div> <div class="badge"><span class="dot on"></span>Hub online</div>
<button class="badge" id="xrayReload" type="button">Обновить Xray VPS</button>
<button class="badge authToggle" id="authToggle" type="button">login: {safe_username}</button> <button class="badge authToggle" id="authToggle" type="button">login: {safe_username}</button>
<a class="btn" href="/logout">Выйти</a> <a class="btn" href="/logout">Выйти</a>
<div class="authMenu" id="authMenu" hidden> <div class="authMenu" id="authMenu" hidden>
@@ -760,6 +789,22 @@ routerForm.name.addEventListener('input', () => {{
routerForm.name.dataset.touched = '1'; routerForm.name.dataset.touched = '1';
}}); }});
document.getElementById('xrayReload').addEventListener('click', async () => {{
showRouterMsg('Обновляю Xray на VPS...');
const res = await fetch('/api/xray/reload', {{method: 'POST'}});
const text = await res.text();
if (res.ok) {{
let message = 'Xray VPS обновлён. Теперь кнопка Админка должна идти в свежие порты.';
try {{
const data = JSON.parse(text);
message = `Xray VPS обновлён: ${{data.config}}, роутеров в конфиге: ${{data.routers}}.`;
}} catch (e) {{}}
showRouterMsg(message);
}} else {{
showRouterMsg(text || 'Не удалось обновить Xray VPS', true);
}}
}});
async function loadRouters() {{ async function loadRouters() {{
const res = await fetch('/api/routers', {{cache: 'no-store'}}); const res = await fetch('/api/routers', {{cache: 'no-store'}});
if (res.ok) {{ if (res.ok) {{
@@ -1066,6 +1111,13 @@ class Handler(BaseHTTPRequestHandler):
if path == "/api/auth": if path == "/api/auth":
self.update_auth() self.update_auth()
return return
if path == "/api/xray/reload":
try:
result = reload_vps_xray(self.app.db_path)
self.send_json(200, {"ok": True, **result})
except Exception as exc:
self.send_text(500, str(exc))
return
if path == "/api/router": if path == "/api/router":
try: try:
payload = self.read_payload() payload = self.read_payload()