Fix LuCI resource proxy paths
This commit is contained in:
1 parent
cc6f7a26ab
commit
0bcce2c4a8
2 files changed
+94
-10
No files matched your search
@@ -15,7 +15,7 @@
|
||||
·
|
||||
Xray Reverse
|
||||
·
|
||||
HTTPS
|
||||
HTTPS через nginx
|
||||
</p>
|
||||
|
||||
<p>
|
||||
@@ -23,7 +23,7 @@
|
||||
<img alt="LuCI" src="https://img.shields.io/badge/LUCI-SUPPORTED-44CC11?style=for-the-badge&labelColor=555555">
|
||||
<img alt="VPS" src="https://img.shields.io/badge/VPS-HUB-7C3AED?style=for-the-badge&labelColor=555555">
|
||||
<img alt="Xray" src="https://img.shields.io/badge/XRAY-REVERSE-F97316?style=for-the-badge&labelColor=555555">
|
||||
<img alt="HTTPS" src="https://img.shields.io/badge/HTTPS-AUTO-22C55E?style=for-the-badge&labelColor=555555">
|
||||
<img alt="HTTPS" src="https://img.shields.io/badge/HTTPS-NGINX-22C55E?style=for-the-badge&labelColor=555555">
|
||||
<img alt="Build" src="https://img.shields.io/badge/BUILD-V275-A855F7?style=for-the-badge&labelColor=555555">
|
||||
</p>
|
||||
|
||||
@@ -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/
|
||||
<details>
|
||||
<summary><b>HTTPS / SSL</b></summary>
|
||||
|
||||
Установщик пытается включить 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 после обновления сертификата.
|
||||
|
||||
</details>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
</script>""" % 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"<head[^>]*>", text, flags=re.IGNORECASE)
|
||||
|
||||
Reference in new issue
Block a user