chore: bump release to v114
This commit is contained in:
1 parent
d54d551cd5
commit
84f4d43486
22 files changed
+693
-99
No files matched your search
@@ -13,7 +13,7 @@ $RemoteScript = @'
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
stage=/tmp/__UPLOAD_NAME__
|
||||
backup=/root/owrt-remote-backup-before-heartbeat-redirect-v113
|
||||
backup=/root/owrt-remote-backup-before-heartbeat-redirect-v114
|
||||
agent=/usr/sbin/owrt-remote
|
||||
wan=/usr/lib/owrt-remote/wan.sh
|
||||
changed=0
|
||||
|
||||
@@ -5,7 +5,7 @@ param(
|
||||
[string]$PinnedVpsHost = '193.233.82.38',
|
||||
[ValidatePattern('^[a-zA-Z0-9_-]+$')][string]$WanInterface = 'wan',
|
||||
[switch]$PreserveConnectionSettings,
|
||||
[ValidatePattern('^[a-zA-Z0-9_-]+$')][string]$BackupName = 'host-policy-v113',
|
||||
[ValidatePattern('^[a-zA-Z0-9_-]+$')][string]$BackupName = 'host-policy-v114',
|
||||
[switch]$PrepareOnly
|
||||
)
|
||||
|
||||
@@ -90,7 +90,7 @@ test -s "$config"
|
||||
if [ '__ACTION__' = Install ]; then
|
||||
for item in agent wan.sh cgi init; do test -s "$stage/$item"; sh -n "$stage/$item"; done
|
||||
test -s "$stage/luci"
|
||||
for item in cgi luci; do grep -F -q 'v113' "$stage/$item"; done
|
||||
for item in cgi luci; do grep -F -q 'v114' "$stage/$item"; done
|
||||
# curl is needed to preserve HTTPS SNI and bypass the local DNS/proxy.
|
||||
if ! command -v curl >/dev/null 2>&1; then
|
||||
if command -v opkg >/dev/null 2>&1; then opkg update && opkg install curl ca-bundle
|
||||
@@ -156,16 +156,16 @@ if [ '__ACTION__' = Install ]; then
|
||||
exit 1
|
||||
fi
|
||||
/usr/sbin/owrt-remote status
|
||||
grep -F -q 'v113' /www/cgi-bin/owrt-remote
|
||||
grep -F -q 'v113' /www/luci-static/resources/view/owrt_remote.js
|
||||
echo HOST_POLICY_ROUTER_V113_OK
|
||||
grep -F -q 'v114' /www/cgi-bin/owrt-remote
|
||||
grep -F -q 'v114' /www/luci-static/resources/view/owrt_remote.js
|
||||
echo HOST_POLICY_ROUTER_V114_OK
|
||||
else
|
||||
test -f "$backup/complete"
|
||||
save_files "$stage/previous"
|
||||
changed=1
|
||||
restore_files "$backup"
|
||||
/usr/sbin/owrt-remote status
|
||||
echo HOST_POLICY_ROUTER_V113_ROLLBACK_OK
|
||||
echo HOST_POLICY_ROUTER_V114_ROLLBACK_OK
|
||||
fi
|
||||
'@
|
||||
} else {
|
||||
@@ -180,7 +180,7 @@ fi
|
||||
set -eu
|
||||
stage=/tmp/__UPLOAD_NAME__
|
||||
target=/opt/owrt-remote/owrt-remote-hub.py
|
||||
backup=/opt/owrt-remote/owrt-remote-hub.py.bak-before-host-policy-v113
|
||||
backup=/opt/owrt-remote/owrt-remote-hub.py.bak-before-host-policy-v114
|
||||
changed=0
|
||||
cleanup() {
|
||||
code=$?
|
||||
@@ -200,7 +200,7 @@ test -s "$target"
|
||||
python_bin=/opt/owrt-remote/venv/bin/python
|
||||
[ -x "$python_bin" ] || python_bin=python3
|
||||
if [ '__ACTION__' = Install ]; then
|
||||
grep -F -q 'v113' "$stage/hub.py"
|
||||
grep -F -q 'v114' "$stage/hub.py"
|
||||
"$python_bin" -m py_compile "$stage/hub.py"
|
||||
OWRT_HOST_POLICY_HUB_SOURCE="$stage/hub.py" "$python_bin" "$stage/test_host_policy.py" HostPolicyTests -v
|
||||
OWRT_RESOURCE_HUB_SOURCE="$stage/hub.py" "$python_bin" "$stage/resources.py" -v
|
||||
@@ -226,7 +226,7 @@ for attempt in 1 2 3 4 5 6 7 8 9 10; do
|
||||
done
|
||||
test "$healthy" = 1
|
||||
cmp "$candidate" "$target"
|
||||
printf '\nHOST_POLICY_VPS_V113_%s_OK\n' '__ACTION__'
|
||||
printf '\nHOST_POLICY_VPS_V114_%s_OK\n' '__ACTION__'
|
||||
'@
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
param(
|
||||
[Parameter(Mandatory = $true)][ValidateSet('Router', 'Vps')][string]$Target,
|
||||
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$Machine,
|
||||
[ValidateSet('Install', 'Rollback')][string]$Action = 'Install',
|
||||
[string]$HubUrl = '',
|
||||
[switch]$PrepareOnly
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$RepoRoot = Split-Path -Parent $PSScriptRoot
|
||||
$UploadName = 'owrt-hub-url-' + [guid]::NewGuid().ToString('N')
|
||||
$StageRoot = Join-Path ([System.IO.Path]::GetTempPath()) $UploadName
|
||||
$Utf8 = [System.Text.UTF8Encoding]::new($false)
|
||||
if ($HubUrl) {
|
||||
$HubUri = $null
|
||||
if (-not [Uri]::TryCreate($HubUrl, [UriKind]::Absolute, [ref]$HubUri) -or
|
||||
$HubUri.Scheme -notin @('http', 'https') -or -not $HubUri.Host -or
|
||||
$HubUri.UserInfo -or $HubUri.Query -or $HubUri.Fragment -or
|
||||
$HubUri.AbsolutePath -ne '/' -or $HubUrl -notmatch '^https?://[A-Za-z0-9.\[\]:-]+/?$') {
|
||||
throw 'HubUrl must be an HTTP/HTTPS origin, for example https://hub.example:9443.'
|
||||
}
|
||||
if ($Target -ne 'Router' -or $Action -ne 'Install') { throw 'HubUrl is only used by Router Install.' }
|
||||
$HubUrl = $HubUrl.TrimEnd('/')
|
||||
}
|
||||
|
||||
if ($Target -eq 'Router') {
|
||||
$Payloads = @{
|
||||
'agent' = 'files\usr\sbin\owrt-remote'
|
||||
'wan.sh' = 'files\usr\lib\owrt-remote\wan.sh'
|
||||
'cgi' = 'files\www\cgi-bin\owrt-remote'
|
||||
'luci' = 'files\www\luci-static\resources\view\owrt_remote.js'
|
||||
}
|
||||
$RemoteScript = @'
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
stage=/tmp/__UPLOAD_NAME__
|
||||
backup=/root/owrt-remote-backup-before-hub-url-v114
|
||||
chmod 700 "$stage"
|
||||
config=/etc/config/owrtremote
|
||||
changed=0
|
||||
item_path() {
|
||||
case "$1" in
|
||||
agent) printf /usr/sbin/owrt-remote ;;
|
||||
wan.sh) printf /usr/lib/owrt-remote/wan.sh ;;
|
||||
cgi) printf /www/cgi-bin/owrt-remote ;;
|
||||
luci) printf /www/luci-static/resources/view/owrt_remote.js ;;
|
||||
esac
|
||||
}
|
||||
save_files() {
|
||||
dir=$1
|
||||
mkdir -p "$dir"
|
||||
chmod 700 "$dir"
|
||||
cp -p "$config" "$dir/config"
|
||||
for item in agent wan.sh cgi luci; do
|
||||
path=$(item_path "$item")
|
||||
test -s "$path"
|
||||
cp -p "$path" "$dir/$item"
|
||||
done
|
||||
xray_config=$(uci -q get owrtremote.main.xray_config || true)
|
||||
[ -n "$xray_config" ] || xray_config=/etc/xray/owrt-remote-client.json
|
||||
printf '%s' "$xray_config" >"$dir/xray-path"
|
||||
if [ -f "$xray_config" ]; then cp -p "$xray_config" "$dir/xray"; else touch "$dir/xray.absent"; fi
|
||||
chmod 600 "$dir/config" "$dir/xray-path"
|
||||
[ ! -f "$dir/xray" ] || chmod 600 "$dir/xray"
|
||||
touch "$dir/complete"
|
||||
}
|
||||
restore_files() {
|
||||
dir=$1
|
||||
test -f "$dir/complete"
|
||||
/etc/init.d/owrt-remote stop >/dev/null 2>&1 || true
|
||||
cp -p "$dir/config" "$config"
|
||||
for item in agent wan.sh cgi luci; do
|
||||
path=$(item_path "$item")
|
||||
cp -p "$dir/$item" "$path"
|
||||
done
|
||||
xray_config=$(cat "$dir/xray-path")
|
||||
if [ -f "$dir/xray.absent" ]; then rm -f "$xray_config"; else cp -p "$dir/xray" "$xray_config"; fi
|
||||
/etc/init.d/owrt-remote restart
|
||||
}
|
||||
cleanup() {
|
||||
code=$?
|
||||
trap - EXIT
|
||||
if [ "$code" -ne 0 ] && [ "$changed" = 1 ]; then
|
||||
echo 'Operation failed; restoring the files and settings from this attempt.' >&2
|
||||
restore_files "$stage/previous" || true
|
||||
fi
|
||||
for item in agent wan.sh cgi luci; do
|
||||
path=$(item_path "$item")
|
||||
rm -f "$path.new-__UPLOAD_NAME__"
|
||||
done
|
||||
rm -rf "$stage"
|
||||
exit "$code"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
test -s "$config"
|
||||
if [ '__ACTION__' = Install ]; then
|
||||
for item in agent wan.sh cgi; do test -s "$stage/$item"; sh -n "$stage/$item"; done
|
||||
test -s "$stage/luci"
|
||||
grep -F -q 'heartbeat_set_url_if_changed()' "$stage/agent"
|
||||
grep -F -q 'reason=https-downgrade' "$stage/agent"
|
||||
for item in agent wan.sh; do grep -F -q -- '--post301' "$stage/$item"; done
|
||||
for item in cgi luci; do grep -F -q 'v114' "$stage/$item"; done
|
||||
if [ ! -e "$backup" ]; then
|
||||
save_files "$stage/retained-backup"
|
||||
mv "$stage/retained-backup" "$backup"
|
||||
fi
|
||||
test -f "$backup/complete"
|
||||
save_files "$stage/previous"
|
||||
changed=1
|
||||
/etc/init.d/owrt-remote stop >/dev/null 2>&1 || true
|
||||
for item in agent wan.sh cgi luci; do
|
||||
path=$(item_path "$item")
|
||||
cp "$stage/$item" "$path.new-__UPLOAD_NAME__"
|
||||
case "$item" in wan.sh|luci) chmod 644 "$path.new-__UPLOAD_NAME__" ;; *) chmod 755 "$path.new-__UPLOAD_NAME__" ;; esac
|
||||
mv -f "$path.new-__UPLOAD_NAME__" "$path"
|
||||
done
|
||||
if [ -n '__HUB_URL__' ]; then
|
||||
uci set 'owrtremote.main.hub_url=__HUB_URL__'
|
||||
uci commit owrtremote
|
||||
fi
|
||||
/etc/init.d/owrt-remote restart
|
||||
for item in agent wan.sh cgi luci; do
|
||||
path=$(item_path "$item")
|
||||
cmp "$stage/$item" "$path"
|
||||
done
|
||||
printf 'Installed Hub URL: %s\n' "$(uci -q get owrtremote.main.hub_url || true)"
|
||||
# Failure to reach Hub is reported separately from successful file installation.
|
||||
if /usr/sbin/owrt-remote heartbeat >"$stage/heartbeat.json"; then
|
||||
printf 'HEARTBEAT_OK\n'
|
||||
else
|
||||
printf 'Files installed, but Heartbeat failed. Check the connection and router logs.\n' >&2
|
||||
printf 'HEARTBEAT_FAILED\n'
|
||||
fi
|
||||
printf 'Hub URL after Heartbeat: %s\n' "$(uci -q get owrtremote.main.hub_url || true)"
|
||||
else
|
||||
test -f "$backup/complete"
|
||||
save_files "$stage/previous"
|
||||
changed=1
|
||||
restore_files "$backup"
|
||||
fi
|
||||
printf '\nBackup: %s\nHUB_URL_ROUTER_V114_%s_OK\n' "$backup" '__ACTION__'
|
||||
'@
|
||||
} else {
|
||||
$Payloads = @{
|
||||
'hub.py' = 'vps\owrt-remote-hub.py'
|
||||
'host_policy.py' = 'tests\test_host_policy.py'
|
||||
'resources.py' = 'tests\test_resource_lifecycle.py'
|
||||
}
|
||||
$RemoteScript = @'
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
stage=/tmp/__UPLOAD_NAME__
|
||||
target=/opt/owrt-remote/owrt-remote-hub.py
|
||||
chmod 700 "$stage"
|
||||
backup=/opt/owrt-remote/owrt-remote-hub.py.bak-before-hub-url-v114
|
||||
candidate=$target.new-__UPLOAD_NAME__
|
||||
changed=0
|
||||
cleanup() {
|
||||
code=$?
|
||||
trap - EXIT
|
||||
if [ "$code" -ne 0 ] && [ "$changed" = 1 ]; then
|
||||
echo 'Operation failed; restoring Hub from this attempt.' >&2
|
||||
cp -p "$stage/previous.py" "$candidate"
|
||||
mv -f "$candidate" "$target"
|
||||
systemctl restart owrt-remote || true
|
||||
fi
|
||||
rm -f "$candidate"
|
||||
rm -rf "$stage"
|
||||
exit "$code"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
test -s "$target"
|
||||
python_bin=/opt/owrt-remote/venv/bin/python
|
||||
[ -x "$python_bin" ] || python_bin=python3
|
||||
if [ '__ACTION__' = Install ]; then
|
||||
grep -F -q 'def router_hub_origins(' "$stage/hub.py"
|
||||
grep -F -q 'v114' "$stage/hub.py"
|
||||
"$python_bin" -m py_compile "$stage/hub.py"
|
||||
OWRT_HOST_POLICY_HUB_SOURCE="$stage/hub.py" "$python_bin" "$stage/host_policy.py" HostPolicyTests -v
|
||||
OWRT_RESOURCE_HUB_SOURCE="$stage/hub.py" "$python_bin" "$stage/resources.py" IntegrationTests -v
|
||||
if [ ! -e "$backup" ]; then cp -p "$target" "$backup"; fi
|
||||
source_file="$stage/hub.py"
|
||||
else
|
||||
test -s "$backup"
|
||||
"$python_bin" -m py_compile "$backup"
|
||||
source_file="$backup"
|
||||
fi
|
||||
cp -p "$target" "$stage/previous.py"
|
||||
cp "$source_file" "$candidate"
|
||||
chmod 755 "$candidate"
|
||||
changed=1
|
||||
mv -f "$candidate" "$target"
|
||||
systemctl restart owrt-remote
|
||||
healthy=0
|
||||
for attempt in 1 2 3 4 5 6 7 8 9 10; do
|
||||
if systemctl is-active --quiet owrt-remote && curl -fsS --max-time 5 http://127.0.0.1:8088/health; then healthy=1; break; fi
|
||||
sleep 2
|
||||
done
|
||||
test "$healthy" = 1
|
||||
cmp "$source_file" "$target"
|
||||
printf '\nBackup: %s\nHUB_URL_VPS_V114_%s_OK\n' "$backup" '__ACTION__'
|
||||
'@
|
||||
}
|
||||
$RemoteScript = $RemoteScript.Replace('__UPLOAD_NAME__', $UploadName).Replace('__ACTION__', $Action).Replace('__HUB_URL__', $HubUrl)
|
||||
try {
|
||||
[System.IO.Directory]::CreateDirectory($StageRoot) | Out-Null
|
||||
[System.IO.File]::WriteAllText((Join-Path $StageRoot 'run.sh'), $RemoteScript.Replace("`r`n", "`n") + "`n", $Utf8)
|
||||
if ($Action -eq 'Install') {
|
||||
foreach ($Item in $Payloads.GetEnumerator()) {
|
||||
$Content = [System.IO.File]::ReadAllText((Join-Path $RepoRoot $Item.Value)).Replace("`r`n", "`n")
|
||||
[System.IO.File]::WriteAllText((Join-Path $StageRoot $Item.Key), $Content, $Utf8)
|
||||
}
|
||||
}
|
||||
if ($PrepareOnly) { Write-Host "Prepared only: $StageRoot"; return }
|
||||
& scp -O -r -- $StageRoot "${Machine}:/tmp/"
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Upload failed. Installation has not started.' }
|
||||
& ssh -T -o ConnectTimeout=10 $Machine "sh /tmp/$UploadName/run.sh"
|
||||
if ($LASTEXITCODE -ne 0) { throw "$Action failed. See the output above; success was not confirmed." }
|
||||
Write-Host "Hub URL $Target $Action finished successfully."
|
||||
} finally {
|
||||
if (-not $PrepareOnly) {
|
||||
$Resolved = [System.IO.Path]::GetFullPath($StageRoot)
|
||||
$Expected = [System.IO.Path]::GetFullPath((Join-Path ([System.IO.Path]::GetTempPath()) $UploadName))
|
||||
if ($Resolved -ne $Expected -or (Split-Path -Leaf $Resolved) -ne $UploadName) { throw 'Unsafe staging cleanup path.' }
|
||||
if (Test-Path -LiteralPath $Resolved) { Remove-Item -LiteralPath $Resolved -Recurse -Force }
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ $RemoteScript = @'
|
||||
set -eu
|
||||
stage=/tmp/__UPLOAD_NAME__
|
||||
target=/opt/owrt-remote/owrt-remote-hub.py
|
||||
backup=/opt/owrt-remote/owrt-remote-hub.py.bak-before-online-status-v113
|
||||
backup=/opt/owrt-remote/owrt-remote-hub.py.bak-before-online-status-v114
|
||||
candidate=$target.new-__UPLOAD_NAME__
|
||||
changed=0
|
||||
cleanup() {
|
||||
@@ -59,7 +59,7 @@ for attempt in 1 2 3 4 5 6 7 8 9 10; do
|
||||
done
|
||||
test "$healthy" = 1
|
||||
cmp "$source_file" "$target"
|
||||
printf '\nBackup: %s\nONLINE_STATUS_V113_%s_OK\n' "$backup" '__ACTION__'
|
||||
printf '\nBackup: %s\nONLINE_STATUS_V114_%s_OK\n' "$backup" '__ACTION__'
|
||||
'@
|
||||
$RemoteScript = $RemoteScript.Replace('__UPLOAD_NAME__', $UploadName).Replace('__ACTION__', $Action)
|
||||
try {
|
||||
|
||||
@@ -17,8 +17,8 @@ if ($Action -eq 'Install') {
|
||||
set -Eeuo pipefail
|
||||
stage=/tmp/__UPLOAD_NAME__
|
||||
target=/opt/owrt-remote/owrt-remote-hub.py
|
||||
backup=/opt/owrt-remote/owrt-remote-hub.py.bak-before-recaptcha-v3-v113
|
||||
captcha_backup=/opt/owrt-remote/captcha-before-recaptcha-v3-v113.json
|
||||
backup=/opt/owrt-remote/owrt-remote-hub.py.bak-before-recaptcha-v3-v114
|
||||
captcha_backup=/opt/owrt-remote/captcha-before-recaptcha-v3-v114.json
|
||||
candidate=$target.new-__UPLOAD_NAME__
|
||||
changed=0
|
||||
cleanup() {
|
||||
@@ -45,7 +45,7 @@ if [ ! -x "$python_bin" ]; then python_bin=python3; fi
|
||||
import ast, pathlib, sys
|
||||
source = pathlib.Path(sys.argv[1]).read_text(encoding='utf-8')
|
||||
tree = ast.parse(source)
|
||||
assert 'v113' in source
|
||||
assert 'v114' in source
|
||||
assert 'v108' not in source
|
||||
assert 'CAPTCHA_MODE_RECAPTCHA_V3' in source
|
||||
assert 'prepareLoginRecaptcha' in source
|
||||
@@ -88,7 +88,7 @@ pid=$(systemctl show owrt-remote -p MainPID --value)
|
||||
test "$pid" -gt 0
|
||||
printf 'PID=%s FD=%s\n' "$pid" "$(find /proc/$pid/fd -maxdepth 1 -type l | wc -l)"
|
||||
systemctl --no-pager --full status owrt-remote | sed -n '1,16p'
|
||||
echo RECAPTCHA_V3_V113_OK
|
||||
echo RECAPTCHA_V3_V114_OK
|
||||
'@
|
||||
} elseif ($Action -eq 'Rollback') {
|
||||
$RemoteScript = @'
|
||||
@@ -96,8 +96,8 @@ echo RECAPTCHA_V3_V113_OK
|
||||
set -Eeuo pipefail
|
||||
stage=/tmp/__UPLOAD_NAME__
|
||||
target=/opt/owrt-remote/owrt-remote-hub.py
|
||||
backup=/opt/owrt-remote/owrt-remote-hub.py.bak-before-recaptcha-v3-v113
|
||||
captcha_backup=/opt/owrt-remote/captcha-before-recaptcha-v3-v113.json
|
||||
backup=/opt/owrt-remote/owrt-remote-hub.py.bak-before-recaptcha-v3-v114
|
||||
captcha_backup=/opt/owrt-remote/captcha-before-recaptcha-v3-v114.json
|
||||
candidate=$target.rollback-__UPLOAD_NAME__
|
||||
changed=0
|
||||
restore_captcha() {
|
||||
|
||||
@@ -18,7 +18,7 @@ if ($Action -eq 'Install') {
|
||||
set -Eeuo pipefail
|
||||
stage=/tmp/__UPLOAD_NAME__
|
||||
target=/opt/owrt-remote/owrt-remote-hub.py
|
||||
backup=/opt/owrt-remote/owrt-remote-hub.py.bak-before-resource-fix-v113
|
||||
backup=/opt/owrt-remote/owrt-remote-hub.py.bak-before-resource-fix-v114
|
||||
candidate=$target.new-__UPLOAD_NAME__
|
||||
changed=0
|
||||
cleanup() {
|
||||
@@ -45,7 +45,7 @@ if [ ! -x "$python_bin" ]; then python_bin=python3; fi
|
||||
import ast, pathlib, sys
|
||||
source = pathlib.Path(sys.argv[1]).read_text(encoding='utf-8')
|
||||
tree = ast.parse(source)
|
||||
assert 'v113' in source
|
||||
assert 'v114' in source
|
||||
assert 'v108' not in source
|
||||
factory = next(node for node in tree.body if isinstance(node, ast.FunctionDef) and node.name == 'connect')
|
||||
assert any(isinstance(item, ast.Name) and item.id == 'contextmanager' for item in factory.decorator_list)
|
||||
@@ -78,7 +78,7 @@ pid=$(systemctl show owrt-remote -p MainPID --value)
|
||||
test "$pid" -gt 0
|
||||
printf 'PID=%s FD=%s\n' "$pid" "$(find /proc/$pid/fd -maxdepth 1 -type l | wc -l)"
|
||||
systemctl --no-pager --full status owrt-remote | sed -n '1,16p'
|
||||
echo RESOURCE_FIX_V113_OK
|
||||
echo RESOURCE_FIX_V114_OK
|
||||
'@
|
||||
} elseif ($Action -eq 'Rollback') {
|
||||
$RemoteScript = @'
|
||||
@@ -86,7 +86,7 @@ echo RESOURCE_FIX_V113_OK
|
||||
set -Eeuo pipefail
|
||||
stage=/tmp/__UPLOAD_NAME__
|
||||
target=/opt/owrt-remote/owrt-remote-hub.py
|
||||
backup=/opt/owrt-remote/owrt-remote-hub.py.bak-before-resource-fix-v113
|
||||
backup=/opt/owrt-remote/owrt-remote-hub.py.bak-before-resource-fix-v114
|
||||
candidate=$target.rollback-__UPLOAD_NAME__
|
||||
changed=0
|
||||
cleanup() {
|
||||
|
||||
@@ -14,7 +14,7 @@ $RemoteScript = @'
|
||||
set -eu
|
||||
stage=/tmp/__UPLOAD_NAME__
|
||||
target=/opt/owrt-remote/owrt-remote-hub.py
|
||||
backup=/opt/owrt-remote/owrt-remote-hub.py.bak-before-vps-widgets-v113
|
||||
backup=/opt/owrt-remote/owrt-remote-hub.py.bak-before-vps-widgets-v114
|
||||
candidate=$target.new-__UPLOAD_NAME__
|
||||
changed=0
|
||||
cleanup() {
|
||||
@@ -37,7 +37,7 @@ python_bin=/opt/owrt-remote/venv/bin/python
|
||||
[ -x "$python_bin" ] || python_bin=python3
|
||||
if [ '__ACTION__' = Install ]; then
|
||||
test -s "$stage/hub.py"
|
||||
grep -F -q 'v113' "$stage/hub.py"
|
||||
grep -F -q 'v114' "$stage/hub.py"
|
||||
"$python_bin" -m py_compile "$stage/hub.py"
|
||||
OWRT_VPS_WIDGETS_HUB_SOURCE="$stage/hub.py" "$python_bin" "$stage/tests.py" -v
|
||||
if [ ! -e "$backup" ]; then cp -p "$target" "$backup"; fi
|
||||
@@ -67,7 +67,7 @@ if [ '__ACTION__' = Install ]; then
|
||||
code=$(curl -sS --max-time 5 -o "$stage/response.json" -w '%{http_code}' http://127.0.0.1:8088/api/vps/resources)
|
||||
test "$code" = 401
|
||||
fi
|
||||
printf '\nVPS_WIDGETS_V113_%s_OK\n' '__ACTION__'
|
||||
printf '\nVPS_WIDGETS_V114_%s_OK\n' '__ACTION__'
|
||||
'@
|
||||
$RemoteScript = $RemoteScript.Replace('__UPLOAD_NAME__', $UploadName).Replace('__ACTION__', $Action)
|
||||
try {
|
||||
|
||||
@@ -20,7 +20,7 @@ $RemoteScript = @'
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
stage=/tmp/__UPLOAD_NAME__
|
||||
backup=/root/owrt-remote-backup-before-wan-multi-v113
|
||||
backup=/root/owrt-remote-backup-before-wan-multi-v114
|
||||
config=/etc/config/owrtremote
|
||||
changed=0
|
||||
item_path() {
|
||||
@@ -81,7 +81,7 @@ test -s "$config"
|
||||
if [ '__ACTION__' = Install ]; then
|
||||
for item in agent wan.sh cgi hotplug; do test -s "$stage/$item"; sh -n "$stage/$item"; done
|
||||
test -s "$stage/luci"
|
||||
for item in cgi luci; do grep -F -q 'v113' "$stage/$item"; done
|
||||
for item in cgi luci; do grep -F -q 'v114' "$stage/$item"; done
|
||||
grep -F -q 'wan_interface_picker' "$stage/cgi"
|
||||
grep -F -q 'wan_select_interface()' "$stage/wan.sh"
|
||||
grep -F -q 'wan_reconcile_xray()' "$stage/agent"
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
param(
|
||||
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$Vps,
|
||||
[ValidateSet('Install', 'Rollback')][string]$Action = 'Install',
|
||||
[switch]$PrepareOnly
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$RepoRoot = Split-Path -Parent $PSScriptRoot
|
||||
$UploadName = 'owrt-web-push-' + [guid]::NewGuid().ToString('N')
|
||||
$StageRoot = Join-Path ([System.IO.Path]::GetTempPath()) $UploadName
|
||||
$Utf8 = [System.Text.UTF8Encoding]::new($false)
|
||||
|
||||
$RemoteScript = @'
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
stage=/tmp/__UPLOAD_NAME__
|
||||
target=/opt/owrt-remote/owrt-remote-hub.py
|
||||
backup=/opt/owrt-remote/owrt-remote-hub.py.bak-before-web-push-v114
|
||||
candidate=$target.new-__UPLOAD_NAME__
|
||||
changed=0
|
||||
|
||||
cleanup() {
|
||||
code=$?
|
||||
trap - EXIT
|
||||
if [ "$code" -ne 0 ] && [ "$changed" = 1 ] && [ -s "$stage/previous.py" ]; then
|
||||
cp -p "$stage/previous.py" "$candidate"
|
||||
mv -f "$candidate" "$target"
|
||||
systemctl restart owrt-remote || true
|
||||
fi
|
||||
rm -f "$candidate"
|
||||
rm -rf "$stage"
|
||||
exit "$code"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
test -s "$target"
|
||||
python_bin=/opt/owrt-remote/venv/bin/python
|
||||
[ -x "$python_bin" ] || python_bin=python3
|
||||
|
||||
if [ '__ACTION__' = Install ]; then
|
||||
test -s "$stage/hub.py"
|
||||
grep -F -q 'Existing subscriptions must be reused' "$stage/hub.py"
|
||||
grep -F -q 'Update the existing registration in place' "$stage/hub.py"
|
||||
grep -F -q 'subscription = await pushManager.getSubscription();' "$stage/hub.py"
|
||||
grep -F -q 'forceFresh: false' "$stage/hub.py"
|
||||
grep -F -q 'push_test: false' "$stage/hub.py"
|
||||
grep -F -q 'result in ("gone", "stale")' "$stage/hub.py"
|
||||
"$python_bin" -m py_compile "$stage/hub.py"
|
||||
OWRT_RESOURCE_HUB_SOURCE="$stage/hub.py" "$python_bin" "$stage/tests.py" -v
|
||||
if [ ! -e "$backup" ]; then cp -p "$target" "$backup"; fi
|
||||
source_file="$stage/hub.py"
|
||||
else
|
||||
test -s "$backup"
|
||||
"$python_bin" -m py_compile "$backup"
|
||||
source_file="$backup"
|
||||
fi
|
||||
|
||||
cp -p "$target" "$stage/previous.py"
|
||||
cp "$source_file" "$candidate"
|
||||
chmod 755 "$candidate"
|
||||
changed=1
|
||||
mv -f "$candidate" "$target"
|
||||
systemctl restart owrt-remote
|
||||
|
||||
healthy=0
|
||||
for attempt in 1 2 3 4 5 6 7 8 9 10; do
|
||||
if systemctl is-active --quiet owrt-remote && curl -fsS --max-time 5 http://127.0.0.1:8088/health; then
|
||||
healthy=1
|
||||
break
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
test "$healthy" = 1
|
||||
cmp "$source_file" "$target"
|
||||
printf '\nBackup: %s\nWEB_PUSH_V114_%s_OK\n' "$backup" '__ACTION__'
|
||||
'@
|
||||
|
||||
$RemoteScript = $RemoteScript.Replace('__UPLOAD_NAME__', $UploadName).Replace('__ACTION__', $Action)
|
||||
|
||||
try {
|
||||
[System.IO.Directory]::CreateDirectory($StageRoot) | Out-Null
|
||||
[System.IO.File]::WriteAllText(
|
||||
(Join-Path $StageRoot 'run.sh'),
|
||||
$RemoteScript.Replace("`r`n", "`n") + "`n",
|
||||
$Utf8
|
||||
)
|
||||
|
||||
if ($Action -eq 'Install') {
|
||||
foreach ($Item in @{
|
||||
'hub.py' = 'vps\owrt-remote-hub.py'
|
||||
'tests.py' = 'tests\test_resource_lifecycle.py'
|
||||
}.GetEnumerator()) {
|
||||
$Content = [System.IO.File]::ReadAllText((Join-Path $RepoRoot $Item.Value)).Replace("`r`n", "`n")
|
||||
[System.IO.File]::WriteAllText((Join-Path $StageRoot $Item.Key), $Content, $Utf8)
|
||||
}
|
||||
}
|
||||
|
||||
if ($PrepareOnly) {
|
||||
Write-Host "Prepared only: $StageRoot"
|
||||
return
|
||||
}
|
||||
|
||||
& scp -O -r -- $StageRoot "${Vps}:/tmp/"
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Upload failed. Installation has not started.' }
|
||||
& ssh -T -o ConnectTimeout=10 $Vps "sh /tmp/$UploadName/run.sh"
|
||||
if ($LASTEXITCODE -ne 0) { throw "$Action failed. See the output above; success was not confirmed." }
|
||||
Write-Host "Web Push fix $Action finished successfully."
|
||||
}
|
||||
finally {
|
||||
if (-not $PrepareOnly) {
|
||||
$Resolved = [System.IO.Path]::GetFullPath($StageRoot)
|
||||
$Expected = [System.IO.Path]::GetFullPath((Join-Path ([System.IO.Path]::GetTempPath()) $UploadName))
|
||||
if ($Resolved -ne $Expected -or (Split-Path -Leaf $Resolved) -ne $UploadName) {
|
||||
throw 'Unsafe staging cleanup path.'
|
||||
}
|
||||
if (Test-Path -LiteralPath $Resolved) {
|
||||
Remove-Item -LiteralPath $Resolved -Recurse -Force
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ $RemoteScript = @'
|
||||
set -eu
|
||||
stage=/tmp/__UPLOAD_NAME__
|
||||
target=/www/cgi-bin/owrt-remote
|
||||
backup_dir=/root/owrt-remote-backup-before-xray-apply-v113
|
||||
backup_dir=/root/owrt-remote-backup-before-xray-apply-v114
|
||||
backup=$backup_dir/owrt-remote
|
||||
candidate=$target.new-__UPLOAD_NAME__
|
||||
changed=0
|
||||
|
||||
+124
-38
@@ -1367,7 +1367,7 @@ def row_int_value(row, key, default=0):
|
||||
return int(default)
|
||||
|
||||
|
||||
def router_reported_connection(router, *, legacy_mode="auto"):
|
||||
def router_reported_status(router):
|
||||
row = dict(router or {})
|
||||
status = row.get("status")
|
||||
if not isinstance(status, dict):
|
||||
@@ -1377,6 +1377,12 @@ def router_reported_connection(router, *, legacy_mode="auto"):
|
||||
status = {}
|
||||
if not isinstance(status, dict):
|
||||
status = {}
|
||||
return status
|
||||
|
||||
|
||||
def router_reported_connection(router, *, legacy_mode="auto"):
|
||||
row = dict(router or {})
|
||||
status = router_reported_status(row)
|
||||
# Legacy agents had automatic endpoint updates. Keep that server behavior
|
||||
# until they report a policy; the patched agent itself defaults to manual.
|
||||
mode = legacy_mode if status.get("vps_host_mode") is None else ("auto" if status.get("vps_host_mode") == "auto" else "manual")
|
||||
@@ -1431,14 +1437,34 @@ echo VPS_HOST_APPLIED
|
||||
'''
|
||||
|
||||
|
||||
def canonical_router_hub_update(router, app_public_url="", request_origin=""):
|
||||
router = router or {}
|
||||
def router_hub_origins(router, app_public_url="", request_origin=""):
|
||||
router = dict(router or {})
|
||||
status = router_reported_status(router)
|
||||
router_public_url = public_url_origin(router.get("public_url", ""))
|
||||
app_origin = public_url_origin(app_public_url)
|
||||
request_origin = public_url_origin(request_origin)
|
||||
public_url = prefer_origin_with_explicit_port(router_public_url, app_origin)
|
||||
public_url = prefer_origin_with_explicit_port(public_url, request_origin)
|
||||
# A stale HTTP row or an internal HTTP request must not override a known
|
||||
# HTTPS origin for the same Hub. Keep custom hosts and HTTPS ports intact.
|
||||
if urllib.parse.urlsplit(public_url).scheme == "http":
|
||||
for candidate in (
|
||||
app_origin,
|
||||
request_origin,
|
||||
public_url_origin(status.get("hub_url", "")),
|
||||
public_url_origin(status.get("public_url", "")),
|
||||
):
|
||||
parts = urllib.parse.urlsplit(candidate)
|
||||
if parts.scheme == "https" and parts.hostname == urllib.parse.urlsplit(public_url).hostname:
|
||||
public_url = candidate
|
||||
break
|
||||
hub_url = public_url or request_origin
|
||||
return public_url, hub_url
|
||||
|
||||
|
||||
def canonical_router_hub_update(router, app_public_url="", request_origin=""):
|
||||
router = router or {}
|
||||
public_url, hub_url = router_hub_origins(router, app_public_url, request_origin)
|
||||
vps_host = str(router.get("vps_host") or "").strip()
|
||||
if not vps_host and hub_url:
|
||||
try:
|
||||
@@ -2504,6 +2530,8 @@ def send_web_push(subscription, payload):
|
||||
detail = detail[:160]
|
||||
if status_code in (404, 410):
|
||||
return "gone"
|
||||
if status_code in (400, 401, 403):
|
||||
return "stale"
|
||||
if detail:
|
||||
return f"error:{status_code or exc.__class__.__name__}:{detail}"
|
||||
return f"error:{status_code or exc.__class__.__name__}"
|
||||
@@ -2519,6 +2547,8 @@ def push_result_message(result, subscription=None):
|
||||
return "На VPS не готов Web Push. Запусти свежий install-vps.sh и проверь HTTPS."
|
||||
if result == "gone":
|
||||
return "Подписка браузера устарела. Включи push заново на этом устройстве."
|
||||
if result == "stale":
|
||||
return "Подписка браузера больше не совпадает с ключами VPS. Hub удалил её; включи Push заново на этом устройстве."
|
||||
if str(result).startswith("error:"):
|
||||
parts = str(result).split(":", 2)
|
||||
code = parts[1] if len(parts) > 1 and parts[1] else "unknown"
|
||||
@@ -2551,7 +2581,7 @@ def queue_web_push_payload(payload, subscriptions=None):
|
||||
"result": result,
|
||||
}
|
||||
)
|
||||
if result == "gone":
|
||||
if result in ("gone", "stale"):
|
||||
gone.append(subscription.get("endpoint", ""))
|
||||
for endpoint in gone:
|
||||
remove_push_subscription(endpoint)
|
||||
@@ -2583,6 +2613,56 @@ self.addEventListener('activate', event => {
|
||||
event.waitUntil(self.clients.claim());
|
||||
});
|
||||
|
||||
function pushBase64ToUint8Array(value) {
|
||||
const padding = '='.repeat((4 - value.length % 4) % 4);
|
||||
const base64 = (value + padding).replace(/-/g, '+').replace(/_/g, '/');
|
||||
const raw = atob(base64);
|
||||
const output = new Uint8Array(raw.length);
|
||||
for (let i = 0; i < raw.length; i++) output[i] = raw.charCodeAt(i);
|
||||
return output;
|
||||
}
|
||||
|
||||
async function syncChangedPushSubscription(event) {
|
||||
const oldEndpoint = event && event.oldSubscription && event.oldSubscription.endpoint || '';
|
||||
let subscription = event && event.newSubscription || null;
|
||||
try {
|
||||
if (!subscription) {
|
||||
const keyResponse = await fetch('/api/push/vapid-public-key', {cache: 'no-store', credentials: 'same-origin'});
|
||||
const keyData = await keyResponse.json().catch(() => ({}));
|
||||
if (!keyResponse.ok || !keyData.ok || !keyData.publicKey) return;
|
||||
subscription = await self.registration.pushManager.subscribe({
|
||||
userVisibleOnly: true,
|
||||
applicationServerKey: pushBase64ToUint8Array(keyData.publicKey)
|
||||
});
|
||||
}
|
||||
if (!subscription) return;
|
||||
const body = {
|
||||
...(subscription.toJSON ? subscription.toJSON() : subscription),
|
||||
client_hint: 'hub',
|
||||
push_test: false
|
||||
};
|
||||
const response = await fetch('/api/push/subscribe', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
if (!response.ok) return;
|
||||
if (oldEndpoint && subscription.endpoint && oldEndpoint !== subscription.endpoint) {
|
||||
await fetch('/api/push/unsubscribe', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({endpoint: oldEndpoint})
|
||||
}).catch(() => {});
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
self.addEventListener('pushsubscriptionchange', event => {
|
||||
event.waitUntil(syncChangedPushSubscription(event));
|
||||
});
|
||||
|
||||
self.addEventListener('push', event => {
|
||||
let data = {};
|
||||
try {
|
||||
@@ -3695,12 +3775,10 @@ def rewrite_router_endpoints(conn, vps_host="", public_url="", preserve_vps_fall
|
||||
|
||||
def router_current_hub_bundle(router, app_public_url="", request_origin="", fallback_host=""):
|
||||
row = dict(router or {})
|
||||
router_public_url = public_url_origin(row.get("public_url", ""))
|
||||
app_origin = public_url_origin(app_public_url)
|
||||
request_origin = public_url_origin(request_origin)
|
||||
public_url = prefer_origin_with_explicit_port(router_public_url, app_origin)
|
||||
public_url = prefer_origin_with_explicit_port(public_url, request_origin)
|
||||
hub_url = public_url or request_origin or router_fallback_hub_url(row, fallback_host, 8088)
|
||||
public_url, hub_url = router_hub_origins(row, app_public_url, request_origin)
|
||||
hub_url = hub_url or router_fallback_hub_url(row, fallback_host, 8088)
|
||||
reported_mode, reported_host = router_reported_connection(row)
|
||||
config_vps_host = (
|
||||
(reported_host if reported_mode == "manual" else "")
|
||||
@@ -4778,7 +4856,7 @@ input,select{{min-width:0;border:1px solid var(--line);border-radius:8px;padding
|
||||
<div class="brand">
|
||||
<div class="desktopHeader">
|
||||
<div class="desktopHeaderTop">
|
||||
<h1 class="appBanner"><span>OpenWrt Remote Hub <span class="appBannerVersion">v113</span></span></h1>
|
||||
<h1 class="appBanner"><span>OpenWrt Remote Hub <span class="appBannerVersion">v114</span></span></h1>
|
||||
<div class="routerSearchDock" id="routerSearchDock">
|
||||
<button class="routerSearchToggle" id="routerSearchToggle" type="button" aria-expanded="false" aria-controls="routerSearchPanel" data-active="false">
|
||||
<span>Поиск роутеров</span>
|
||||
@@ -5131,7 +5209,7 @@ systemctl restart owrt-remote-xray</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mobileSearchDock" id="mobileRouterSearchDock">
|
||||
<span class="mobileSearchVersion">v113</span>
|
||||
<span class="mobileSearchVersion">v114</span>
|
||||
<button class="routerSearchToggle mobilePanelToggle primary" id="mobileRouterSearchToggle" type="button" aria-expanded="false" aria-controls="mobileRouterSearchPanel" data-active="false">
|
||||
<span>Поиск роутеров</span>
|
||||
</button>
|
||||
@@ -10478,7 +10556,7 @@ let pushVapidConfig = embeddedPushVapidConfig();
|
||||
let pushVapidPromise = null;
|
||||
|
||||
function pushEnvironmentReady() {{
|
||||
return !!(((pushServiceWorkerReady && pushServiceWorkerReady.pushManager) || hasWindowPushManager()) && pushVapidConfig && pushVapidConfig.publicKey);
|
||||
return !!(((pushRegistrationUsable(pushServiceWorkerReady)) || hasWindowPushManager()) && pushVapidConfig && pushVapidConfig.publicKey);
|
||||
}}
|
||||
|
||||
function ensureClientVersion() {{
|
||||
@@ -10669,7 +10747,9 @@ async function warmPushEnvironment({{silent = true}} = {{}}) {{
|
||||
try {{
|
||||
const tasks = [fetchPushVapidConfig()];
|
||||
if ('serviceWorker' in navigator) {{
|
||||
tasks.unshift(ensurePushServiceWorkerReady({{forceFresh: isIOSDevice() && !hasWindowPushManager(), forceUpdate: isIOSDevice() && !hasWindowPushManager()}}).catch((e) => {{
|
||||
// Update the existing registration in place. On iOS, forcing a new
|
||||
// registration can detach Safari's existing PushSubscription.
|
||||
tasks.unshift(ensurePushServiceWorkerReady({{forceFresh: false, forceUpdate: true}}).catch((e) => {{
|
||||
if (hasWindowPushManager()) return null;
|
||||
throw e;
|
||||
}}));
|
||||
@@ -10710,17 +10790,20 @@ async function resolvePushSubscriptionManager({{forceFresh = false, forceUpdate
|
||||
}};
|
||||
}}
|
||||
|
||||
async function registerPushSubscription({{preferCached = false, directSubscribeFirst = false}} = {{}}) {{
|
||||
async function registerPushSubscription({{preferCached = false, directSubscribeFirst = false, sendTest = true}} = {{}}) {{
|
||||
let ready = pushServiceWorkerReady;
|
||||
let keyData = pushVapidConfig;
|
||||
let pushManager = ready && ready.pushManager ? ready.pushManager : null;
|
||||
let pushSource = 'serviceWorker';
|
||||
const preferWindowManager = hasWindowPushManager();
|
||||
const requireFreshRegistration = preferWindowManager || isIOSDevice() || !preferCached || !pushEnvironmentReady();
|
||||
// Read an existing subscription before subscribing. Calling subscribe()
|
||||
// first is unreliable in iOS standalone Safari and can produce a broken
|
||||
// PushRegistration even when the current subscription is still valid.
|
||||
const requireFreshRegistration = preferWindowManager || !pushEnvironmentReady();
|
||||
if (requireFreshRegistration) {{
|
||||
const resolved = await resolvePushSubscriptionManager({{
|
||||
forceFresh: !preferWindowManager && isIOSDevice(),
|
||||
forceUpdate: !preferWindowManager && isIOSDevice()
|
||||
forceFresh: false,
|
||||
forceUpdate: false
|
||||
}});
|
||||
ready = resolved.registration;
|
||||
keyData = resolved.keyData;
|
||||
@@ -10738,22 +10821,10 @@ async function registerPushSubscription({{preferCached = false, directSubscribeF
|
||||
const trySubscribe = async () => {{
|
||||
return await pushManager.subscribe(subscribeOptions);
|
||||
}};
|
||||
if (directSubscribeFirst && isIOSDevice()) {{
|
||||
try {{
|
||||
subscription = await trySubscribe();
|
||||
}} catch (e) {{
|
||||
if (!(pushSource === 'serviceWorker' && isPushInitStateError(e))) {{
|
||||
if (String((e && e.name) || '').toLowerCase() === 'aborterror') {{
|
||||
throw new Error('iPhone прервал создание push-подписки. Полностью закрой Hub свайпом, открой снова с экрана Домой и повтори "Включить Push".');
|
||||
}}
|
||||
}}
|
||||
if (pushSource !== 'serviceWorker' || !isPushInitStateError(e)) {{
|
||||
throw new Error(`pushManager.subscribe failed: ${{pushErrorText(e, 'unknown error')}}`);
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
try {{
|
||||
if (!subscription) subscription = await pushManager.getSubscription();
|
||||
// Existing subscriptions must be reused. This is essential for iOS,
|
||||
// where subscribe() before getSubscription() may throw InvalidStateError.
|
||||
subscription = await pushManager.getSubscription();
|
||||
}} catch (e) {{
|
||||
if (!isPushInitStateError(e)) {{
|
||||
throw new Error(`pushManager.getSubscription failed: ${{pushErrorText(e, 'unknown error')}}`);
|
||||
@@ -10761,7 +10832,9 @@ async function registerPushSubscription({{preferCached = false, directSubscribeF
|
||||
if (pushSource !== 'serviceWorker') {{
|
||||
throw new Error(`pushManager.getSubscription failed: ${{pushErrorText(e, 'unknown error')}}`);
|
||||
}}
|
||||
await resetHubPushState({{unregister: false}});
|
||||
// Only the recovery path unregisters the worker. Normal checks reuse the
|
||||
// current registration so Safari keeps its valid PushSubscription.
|
||||
await resetHubPushState({{unregister: true}});
|
||||
const resolved = await resolvePushSubscriptionManager({{forceFresh: true, forceUpdate: true}});
|
||||
ready = resolved.registration;
|
||||
keyData = resolved.keyData;
|
||||
@@ -10809,7 +10882,7 @@ async function registerPushSubscription({{preferCached = false, directSubscribeF
|
||||
res = await fetch('/api/push/subscribe', {{
|
||||
method: 'POST',
|
||||
headers: {{'Content-Type': 'application/json'}},
|
||||
body: JSON.stringify({{...(subscription.toJSON ? subscription.toJSON() : subscription), client_hint: currentClientHint()}})
|
||||
body: JSON.stringify({{...(subscription.toJSON ? subscription.toJSON() : subscription), client_hint: currentClientHint(), push_test: !!sendTest}})
|
||||
}});
|
||||
}} catch (e) {{
|
||||
throw new Error(`Не смог отправить подписку на VPS: ${{pushErrorText(e, 'network error')}}`);
|
||||
@@ -10857,7 +10930,7 @@ async function enableNotifications() {{
|
||||
}}
|
||||
showRouterMsg('Включаю настоящий Web Push для этого устройства...');
|
||||
setNotifyStatus(`Пробую включить Web Push. Текущее состояние: ${{pushSupportSummary()}}`);
|
||||
await registerPushSubscription({{preferCached: isIOSDevice(), directSubscribeFirst: isIOSDevice()}});
|
||||
await registerPushSubscription({{preferCached: isIOSDevice()}});
|
||||
localStorage.setItem('owrtPushEnabled', '1');
|
||||
showRouterMsg('Push включён. Теперь уведомления должны приходить даже когда вкладка закрыта.');
|
||||
setNotifyStatus(`Web Push включён. Текущее состояние: ${{pushSupportSummary()}}`);
|
||||
@@ -10899,7 +10972,7 @@ async function testPushDelivery() {{
|
||||
}}
|
||||
showRouterMsg('Проверяю доставку Web Push на это устройство...');
|
||||
setNotifyStatus(`Проверяю доставку Web Push. Текущее состояние: ${{pushSupportSummary()}}`);
|
||||
const data = await registerPushSubscription({{preferCached: isIOSDevice(), directSubscribeFirst: isIOSDevice()}});
|
||||
const data = await registerPushSubscription({{preferCached: isIOSDevice(), sendTest: true}});
|
||||
const client = data && data.subscription && data.subscription.client ? data.subscription.client : 'устройство';
|
||||
showRouterMsg(`VPS принял подписку и отправил тестовый Web Push на ${{client}}.`);
|
||||
setNotifyStatus(`VPS принял подписку и отправил тестовый Web Push на ${{client}}.`);
|
||||
@@ -12659,7 +12732,7 @@ button:hover{{filter:brightness(1.06)}}
|
||||
<form class="login" method="post" action="/login">
|
||||
{error_html}
|
||||
<span class="brand">
|
||||
<h1 class="appBanner"><span>OpenWrt Remote Hub <span class="appBannerVersion">v113</span></span></h1>
|
||||
<h1 class="appBanner"><span>OpenWrt Remote Hub <span class="appBannerVersion">v114</span></span></h1>
|
||||
</span>
|
||||
<label for="hubUsername">Логин</label>
|
||||
<input id="hubUsername" name="username" autocomplete="off" autofocus required>
|
||||
@@ -13131,7 +13204,7 @@ body::after{{content:"";position:fixed;inset:0;pointer-events:none;background:li
|
||||
<circle cx="65" cy="59" r="3" fill="#E5F2FF"/>
|
||||
</svg>
|
||||
</div>
|
||||
<h2 class="brandTitle">OpenWrt Remote Hub <span class="brandVersion">v113</span></h2>
|
||||
<h2 class="brandTitle">OpenWrt Remote Hub <span class="brandVersion">v114</span></h2>
|
||||
</div>
|
||||
</div>
|
||||
<div class="brandBottom">
|
||||
@@ -17604,6 +17677,19 @@ exit 127
|
||||
client_ip,
|
||||
user_agent,
|
||||
)
|
||||
if not bool(payload.get("push_test", True)):
|
||||
self.send_json(
|
||||
200,
|
||||
{
|
||||
"ok": True,
|
||||
"delivery": "registered",
|
||||
"subscription": {
|
||||
"id": subscription.get("id"),
|
||||
"client": subscription.get("client"),
|
||||
},
|
||||
},
|
||||
)
|
||||
return
|
||||
test_payload = {
|
||||
"title": APP_NAME,
|
||||
"body": "Push включён на этом устройстве.",
|
||||
@@ -17632,7 +17718,7 @@ exit 127
|
||||
],
|
||||
"ok" if result == "ok" else "partial",
|
||||
)
|
||||
if result == "gone":
|
||||
if result in ("gone", "stale"):
|
||||
remove_push_subscription(subscription.get("endpoint", ""))
|
||||
if result != "ok":
|
||||
self.send_json(503, {"ok": False, "error": push_result_message(result, subscription), "delivery": result, "subscription": {"id": subscription.get("id"), "client": subscription.get("client")}})
|
||||
|
||||
Reference in new issue
Block a user