Release v115 with router global logs and mobile header layout
This commit is contained in:
1 parent
0508438de0
commit
4ceb3d031a
39 files changed
+1181
-93
No files matched your search
@@ -0,0 +1,143 @@
|
||||
#!/bin/sh
|
||||
# The private Remote journal lives in RAM. It never changes the system logd.
|
||||
LOG_DIR="${OWRT_REMOTE_LOG_DIR:-/tmp/owrt-remote-logs}"
|
||||
LOG_LIMIT=1048576
|
||||
LOG_KEEP_SECONDS=86400
|
||||
|
||||
log_clock() { cut -d. -f1 /proc/uptime; }
|
||||
log_init() {
|
||||
umask 077
|
||||
mkdir -p "$LOG_DIR" || return 1
|
||||
chmod 700 "$LOG_DIR"
|
||||
}
|
||||
log_lock() {
|
||||
local attempt owner
|
||||
log_init || return 1
|
||||
attempt=0
|
||||
while ! mkdir "$LOG_DIR/lock" 2>/dev/null; do
|
||||
owner="$(cat "$LOG_DIR/lock/pid" 2>/dev/null)"
|
||||
case "$owner" in
|
||||
''|*[!0-9]*)
|
||||
# Recover a writer killed between mkdir and writing its PID.
|
||||
if [ "$attempt" -ge 20 ]; then
|
||||
rm -f "$LOG_DIR/lock/pid"
|
||||
rmdir "$LOG_DIR/lock" 2>/dev/null || true
|
||||
fi ;;
|
||||
*) if ! kill -0 "$owner" 2>/dev/null; then
|
||||
rm -f "$LOG_DIR/lock/pid"
|
||||
rmdir "$LOG_DIR/lock" 2>/dev/null || true
|
||||
fi ;;
|
||||
esac
|
||||
attempt=$((attempt + 1))
|
||||
[ "$attempt" -lt 100 ] || return 1
|
||||
sleep 0.1
|
||||
done
|
||||
printf '%s\n' "$$" >"$LOG_DIR/lock/pid"
|
||||
}
|
||||
log_unlock() {
|
||||
rm -f "$LOG_DIR/lock/pid"
|
||||
rmdir "$LOG_DIR/lock" 2>/dev/null || true
|
||||
}
|
||||
log_reset_locked() {
|
||||
: >"$LOG_DIR/current.log"
|
||||
rm -f "$LOG_DIR/previous.log"
|
||||
log_clock >"$LOG_DIR/age"
|
||||
}
|
||||
log_maintain_locked() {
|
||||
local now age
|
||||
now="$(log_clock)"
|
||||
age="$(cat "$LOG_DIR/age" 2>/dev/null)"
|
||||
case "$age" in ''|*[!0-9]*) log_reset_locked; return ;; esac
|
||||
if [ "$now" -lt "$age" ] || [ "$((now - age))" -ge "$LOG_KEEP_SECONDS" ]; then
|
||||
log_reset_locked
|
||||
fi
|
||||
}
|
||||
log_redact() {
|
||||
# Never retain command blocks containing credentials or authenticated URLs.
|
||||
LC_ALL=C awk '
|
||||
{
|
||||
line = substr($0, 1, 4096); lower = tolower(line)
|
||||
if (lower ~ /(authorization|hub_token|vless_uuid|ssh_vless_uuid|password|passwd|web[._ -]?key|[?&]key=|[?&]token=|"uuid"|"privatekey"|"password")/ ||
|
||||
lower ~ /[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f-]+-[0-9a-f-]+-[0-9a-f-]+/)
|
||||
print "[строка с ключом или паролем скрыта]"
|
||||
else print line
|
||||
}'
|
||||
}
|
||||
log_append() {
|
||||
local line size
|
||||
# Process one bounded line at a time and release the lock between writes.
|
||||
log_redact | while IFS= read -r line; do
|
||||
log_lock || exit 1
|
||||
trap 'log_unlock' EXIT
|
||||
trap 'exit 0' INT TERM
|
||||
log_maintain_locked
|
||||
size="$(wc -c <"$LOG_DIR/current.log")"
|
||||
if [ "$size" -ge "$LOG_LIMIT" ]; then
|
||||
mv -f "$LOG_DIR/current.log" "$LOG_DIR/previous.log"
|
||||
: >"$LOG_DIR/current.log"
|
||||
fi
|
||||
printf '%s\n' "$line" >>"$LOG_DIR/current.log"
|
||||
log_unlock
|
||||
trap - EXIT INT TERM
|
||||
done
|
||||
}
|
||||
log_read() {
|
||||
local previous_size current_size
|
||||
log_lock || return 1
|
||||
log_maintain_locked
|
||||
# Open the retained files under the lock, then release it before streaming
|
||||
# to a slow phone. Downloads must not prevent the collector from writing.
|
||||
previous_size=0
|
||||
if [ -f "$LOG_DIR/previous.log" ]; then
|
||||
previous_size="$(wc -c <"$LOG_DIR/previous.log")"
|
||||
exec 3<"$LOG_DIR/previous.log"
|
||||
else
|
||||
exec 3</dev/null
|
||||
fi
|
||||
current_size="$(wc -c <"$LOG_DIR/current.log")"
|
||||
exec 4<"$LOG_DIR/current.log"
|
||||
log_unlock
|
||||
if [ "${1:-}" = live ]; then
|
||||
{ head -c "$previous_size" <&3; head -c "$current_size" <&4; } | tail -c 65536
|
||||
else
|
||||
head -c "$previous_size" <&3
|
||||
head -c "$current_size" <&4
|
||||
fi
|
||||
exec 3<&- 4<&-
|
||||
}
|
||||
log_clear() {
|
||||
log_lock || return 1
|
||||
log_reset_locked
|
||||
log_unlock
|
||||
}
|
||||
log_collect() {
|
||||
# These variables must remain visible to EXIT even after this function returns.
|
||||
log_init || return 1
|
||||
fifo="$LOG_DIR/stream.$$"
|
||||
mkfifo "$fifo" || return 1
|
||||
reader=''; writer=''; timer=''
|
||||
trap 'trap - EXIT; for child in "$reader" "$writer" "$timer"; do [ -z "$child" ] || kill "$child" 2>/dev/null || true; done; wait; rm -f "$fifo"' EXIT
|
||||
trap 'exit 0' INT TERM
|
||||
# Follow only new Remote/Xray service records: a clear must not reload history.
|
||||
logread -f -e 'owrt-remote\(\[[0-9][0-9]*\]\)\{0,1\}:' >"$fifo" 2>/dev/null &
|
||||
reader=$!
|
||||
while IFS= read -r line; do printf '%s\n' "$line" | log_append; done <"$fifo" &
|
||||
writer=$!
|
||||
while :; do
|
||||
log_lock || return 1
|
||||
log_maintain_locked
|
||||
log_unlock
|
||||
sleep 60 & timer=$!
|
||||
wait "$timer" || return 0
|
||||
kill -0 "$reader" 2>/dev/null && kill -0 "$writer" 2>/dev/null || return 1
|
||||
done
|
||||
}
|
||||
|
||||
case "${1:-}" in
|
||||
collect) log_collect ;;
|
||||
read) log_read "${2:-}" ;;
|
||||
clear) log_clear ;;
|
||||
append) log_append ;;
|
||||
event) { printf '%s owrt-remote: %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$2"; cat; } | log_append ;;
|
||||
*) printf 'Usage: logs.sh collect|read [live]|clear|append|event MESSAGE\n' >&2; exit 2 ;;
|
||||
esac
|
||||
@@ -12,7 +12,7 @@ log() {
|
||||
}
|
||||
|
||||
die() {
|
||||
printf 'ОШИБКА: %s\n' "$*" >&2
|
||||
log "ОШИБКА: $*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -559,7 +559,7 @@ render_client_config() {
|
||||
cat >"$out" <<EOF
|
||||
{
|
||||
"log": {
|
||||
"loglevel": "warning"
|
||||
"loglevel": "info"
|
||||
},
|
||||
"inbounds": [],
|
||||
"outbounds": [
|
||||
@@ -859,7 +859,7 @@ heartbeat_apply_hub_update() {
|
||||
}
|
||||
|
||||
send_heartbeat() {
|
||||
local hub_url token endpoint tmp response event used fallback_base
|
||||
local hub_url token endpoint tmp response event used fallback_base errors rc
|
||||
event="${1:-}"
|
||||
hub_url="$(uci_get hub_url '')"
|
||||
token="$(uci_get hub_token '')"
|
||||
@@ -867,30 +867,35 @@ send_heartbeat() {
|
||||
[ -n "$token" ] || die "hub_token пустой"
|
||||
if truthy "$(uci_get wan_direct 0)"; then
|
||||
command -v wan_prepare >/dev/null 2>&1 || die "WAN helper missing: $WAN_HELPER"
|
||||
wan_prepare || return 1
|
||||
wan_prepare || { log 'Heartbeat: не удалось подготовить прямой WAN'; return 1; }
|
||||
wan_reconcile_xray
|
||||
fi
|
||||
|
||||
endpoint="${hub_url%/}/api/heartbeat"
|
||||
tmp="${TMPDIR:-/tmp}/owrt-remote-heartbeat.$$"
|
||||
response="${TMPDIR:-/tmp}/owrt-remote-heartbeat.response.$$"
|
||||
errors="$response.error"
|
||||
heartbeat_json "$event" >"$tmp"
|
||||
used=0
|
||||
for endpoint in $(heartbeat_candidate_endpoints); do
|
||||
used=1
|
||||
if post_json "$endpoint" "$token" "$tmp" >"$response" \
|
||||
&& grep -Eq '"ok"[[:space:]]*:[[:space:]]*true' "$response"; then
|
||||
rc=0
|
||||
post_json "$endpoint" "$token" "$tmp" >"$response" 2>"$errors" || rc=$?
|
||||
if [ "$rc" = 0 ] && grep -Eq '"ok"[[:space:]]*:[[:space:]]*true' "$response"; then
|
||||
fallback_base="$(heartbeat_base_from_endpoint "$endpoint")"
|
||||
if ! heartbeat_apply_hub_update "$response" "$fallback_base"; then
|
||||
rm -f "$tmp" "$response"
|
||||
log 'Heartbeat: Hub ответил, но обновление настроек не применилось'
|
||||
rm -f "$tmp" "$response" "$errors"
|
||||
return 1
|
||||
fi
|
||||
cat "$response"
|
||||
rm -f "$tmp" "$response"
|
||||
log "Heartbeat: OK; Hub=$fallback_base; WAN_direct=$(uci_get wan_direct 0); WAN_active=$(cat "$WAN_STATE/active-interface" 2>/dev/null)"
|
||||
rm -f "$tmp" "$response" "$errors"
|
||||
return 0
|
||||
fi
|
||||
log "Heartbeat: ошибка; endpoint=$endpoint; rc=$rc; $(head -c 1024 "$errors"); ответ=$(head -c 1024 "$response")"
|
||||
done
|
||||
rm -f "$tmp" "$response"
|
||||
rm -f "$tmp" "$response" "$errors"
|
||||
[ "$used" = "1" ] || die "hub_url/public_url/vps_host пустые"
|
||||
return 1
|
||||
}
|
||||
@@ -969,6 +974,7 @@ heartbeat_loop() {
|
||||
local interval
|
||||
interval="$(safe_num "$(uci_get heartbeat_interval 30)" 30)"
|
||||
[ "$interval" -lt 10 ] && interval=10
|
||||
log "Heartbeat: цикл запущен; интервал=${interval}s"
|
||||
while :; do
|
||||
if send_heartbeat >/dev/null 2>&1; then
|
||||
heartbeat_mark_ok
|
||||
@@ -1227,6 +1233,7 @@ run_xray() {
|
||||
xray_config="$(render_client_config)" || die "cannot create Xray configuration"
|
||||
[ -n "$xray_config" ] && [ -s "$xray_config" ] || die "Xray configuration is missing or empty"
|
||||
[ -x "$xray_bin" ] || die "xray not found or not executable: $xray_bin"
|
||||
log "Xray: запуск туннеля; config=$xray_config; VPS=$(uci_get vps_host ''):$(uci_get vps_port 8443); WAN_direct=$(uci_get wan_direct 0); WAN_selected=$(uci_get wan_interface wan)"
|
||||
|
||||
if "$xray_bin" help 2>/dev/null | grep -q 'run'; then
|
||||
exec "$xray_bin" run -config "$xray_config"
|
||||
|
||||
Reference in new issue
Block a user