diff --git a/README.md b/README.md
index 72d3f39..80d59b1 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@
·
Xray Reverse
·
- HTTPS
+ HTTPS через nginx
@@ -23,7 +23,7 @@
-
+
@@ -35,7 +35,7 @@
## Быстрый старт
-### VPS: поставить Hub, Xray, firewall и HTTPS одной командой
+### VPS: поставить Hub, Xray, firewall и HTTPS через nginx одной командой
```sh
curl -fsSL "https://raw.githubusercontent.com/kzolotarev95/luci-app-owrt-remote/main/vps/install-vps.sh?v=$(date +%s)" | sudo sh
@@ -103,11 +103,14 @@ curl -fsSL "https://raw.githubusercontent.com/kzolotarev95/luci-app-owrt-remote/
HTTPS / SSL
-Установщик пытается включить HTTPS сам. Для этого должны быть открыты порты:
+Установщик пытается включить HTTPS сам. Схема такая: Hub работает внутри на `80` и `8088`, а HTTPS на `443` принимает nginx и прокидывает запросы в Hub.
+
+Для установки должны быть открыты порты:
```text
-80/tcp - проверка Let's Encrypt
-443/tcp - HTTPS-панель
+80/tcp - HTTP-панель и проверка Let's Encrypt
+443/tcp - HTTPS-панель через nginx
+8088/tcp - прямой HTTP-порт Hub, можно закрыть позже в firewall провайдера
```
Включить HTTPS вручную на IP:
@@ -126,10 +129,12 @@ curl -fsSL "https://raw.githubusercontent.com/kzolotarev95/luci-app-owrt-remote/
```sh
sudo ss -lntp | grep -E ':(80|443|8088)\b'
+curl -sS http://127.0.0.1:8088/health
curl -k https://127.0.0.1/health
+sudo nginx -t
```
-Важно: IP-сертификаты Let's Encrypt короткие. Certbot ставит auto-renew, а скрипт добавляет hook для перезапуска Hub после обновления сертификата.
+Нормальная картина: `443` слушает `nginx`, а `80` и `8088` слушает `python3` Hub. Certbot ставит auto-renew, а скрипт добавляет hook для перезагрузки nginx после обновления сертификата.
@@ -351,7 +356,7 @@ curl -fsSL "https://raw.githubusercontent.com/kzolotarev95/luci-app-owrt-remote/
- `/opt/owrt-remote`;
- `/etc/xray/owrt-remote.json`;
- `/var/lib/owrt-remote`;
-- HTTPS systemd override и renewal hook;
+- nginx-конфиг HTTPS, certbot renewal hook и старые TLS override-файлы;
- правила `ufw` для `80/tcp`, `443/tcp`, `8088/tcp`, `8443/tcp`.
Удалить Hub, но оставить базу роутеров:
@@ -418,9 +423,9 @@ wget -O - "https://raw.githubusercontent.com/kzolotarev95/luci-app-owrt-remote/m
│ └── права LuCI/rpcd
└── vps/
├── install-vps.sh
- │ └── установка Hub, Xray, firewall и HTTPS
+ │ └── установка Hub, Xray, firewall и HTTPS через nginx
├── enable-https.sh
- │ └── включение HTTPS/443 вручную
+ │ └── включение HTTPS/443 через nginx вручную
├── uninstall-vps.sh
│ └── удаление Hub с VPS
├── owrt-remote-hub.py
diff --git a/vps/owrt-remote-hub.py b/vps/owrt-remote-hub.py
index 84b89b9..a8c88dd 100644
--- a/vps/owrt-remote-hub.py
+++ b/vps/owrt-remote-hub.py
@@ -2810,6 +2810,60 @@ def proxy_runtime_script(prefix):
const fixed = fixUrl(value);
if (fixed !== value) el.setAttribute(attr, fixed);
}
+ function fixTree(node) {
+ if (!node || node.nodeType !== 1) return node;
+ if (node.hasAttribute) {
+ if (node.hasAttribute("href")) fixElementUrl(node, "href");
+ if (node.hasAttribute("action")) fixElementUrl(node, "action");
+ if (node.hasAttribute("src")) fixElementUrl(node, "src");
+ }
+ if (node.querySelectorAll) {
+ node.querySelectorAll("a[href], form[action], link[href], script[src], img[src]").forEach(function(el) {
+ if (el.hasAttribute("href")) fixElementUrl(el, "href");
+ if (el.hasAttribute("action")) fixElementUrl(el, "action");
+ if (el.hasAttribute("src")) fixElementUrl(el, "src");
+ });
+ }
+ return node;
+ }
+ function patchUrlProperty(proto, prop) {
+ if (!proto) return;
+ const desc = Object.getOwnPropertyDescriptor(proto, prop);
+ if (!desc || !desc.set || !desc.get) return;
+ Object.defineProperty(proto, prop, {
+ configurable: true,
+ enumerable: desc.enumerable,
+ get: function() { return desc.get.call(this); },
+ set: function(value) { return desc.set.call(this, fixUrl(value)); }
+ });
+ }
+ if (window.Element && Element.prototype.setAttribute) {
+ const nativeSetAttribute = Element.prototype.setAttribute;
+ Element.prototype.setAttribute = function(name, value) {
+ const attr = String(name || "").toLowerCase();
+ if (attr === "href" || attr === "src" || attr === "action") value = fixUrl(value);
+ return nativeSetAttribute.call(this, name, value);
+ };
+ }
+ if (window.Node) {
+ const nativeAppendChild = Node.prototype.appendChild;
+ const nativeInsertBefore = Node.prototype.insertBefore;
+ if (nativeAppendChild) {
+ Node.prototype.appendChild = function(node) {
+ return nativeAppendChild.call(this, fixTree(node));
+ };
+ }
+ if (nativeInsertBefore) {
+ Node.prototype.insertBefore = function(node, before) {
+ return nativeInsertBefore.call(this, fixTree(node), before);
+ };
+ }
+ }
+ patchUrlProperty(window.HTMLAnchorElement && HTMLAnchorElement.prototype, "href");
+ patchUrlProperty(window.HTMLLinkElement && HTMLLinkElement.prototype, "href");
+ patchUrlProperty(window.HTMLScriptElement && HTMLScriptElement.prototype, "src");
+ patchUrlProperty(window.HTMLImageElement && HTMLImageElement.prototype, "src");
+ patchUrlProperty(window.HTMLFormElement && HTMLFormElement.prototype, "action");
if (window.fetch) {
const nativeFetch = window.fetch;
window.fetch = function(input, init) {
@@ -2857,6 +2911,29 @@ def proxy_runtime_script(prefix):
""" % prefix_json
+def protect_luci_resource_root(text):
+ protected = []
+
+ def protect_value(match):
+ token = f"__OWRT_REMOTE_LUCI_RESOURCE_{len(protected)}__"
+ protected.append(match.group(0))
+ return token
+
+ patterns = (
+ r"""((?:"resource"|'resource'|resource)\s*[:=]\s*)(["'])(/luci-static/resources)(\2)""",
+ r"""((?:"resource"|'resource'|resource)\s*[:=]\s*)(["'])(\\/luci-static\\/resources)(\2)""",
+ )
+ for pattern in patterns:
+ text = re.sub(pattern, protect_value, text)
+ return text, protected
+
+
+def restore_luci_resource_root(text, protected):
+ for index, value in enumerate(protected):
+ text = text.replace(f"__OWRT_REMOTE_LUCI_RESOURCE_{index}__", value)
+ return text
+
+
def normalize_public_hosts(*values):
hosts = set()
for value in values:
@@ -2915,6 +2992,7 @@ def rewrite_remaining_luci_roots(text, prefix):
def rewrite_html(body, prefix, content_type="", public_hosts=None):
text = body.decode("utf-8", errors="ignore")
escaped_prefix = prefix.replace("/", "\\/")
+ text, protected_resource_roots = protect_luci_resource_root(text)
replacements = {
'href="/': f'href="{prefix}/',
'src="/': f'src="{prefix}/',
@@ -2966,6 +3044,7 @@ def rewrite_html(body, prefix, content_type="", public_hosts=None):
text = text.replace(old, new)
text = rewrite_public_absolute_urls(text, prefix, public_hosts or [])
text = rewrite_remaining_luci_roots(text, prefix)
+ text = restore_luci_resource_root(text, protected_resource_roots)
if "text/html" in (content_type or "").lower():
script = proxy_runtime_script(prefix)
head_match = re.search(r"]*>", text, flags=re.IGNORECASE)