Restart router tunnel after WAN reconnect
This commit is contained in:
1 parent
be465e47b0
commit
fdd12f3880
2 files changed
+58
No files matched your search
Executable
+57
@@ -0,0 +1,57 @@
|
||||
#!/bin/sh
|
||||
|
||||
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
TAG="owrt-remote"
|
||||
STATE_DIR="${TMPDIR:-/tmp}/owrt-remote-hotplug"
|
||||
STAMP_FILE="$STATE_DIR/wan.stamp"
|
||||
|
||||
[ "$ACTION" = "ifup" ] || [ "$ACTION" = "ifupdate" ] || [ "$ACTION" = "ifrestart" ] || exit 0
|
||||
|
||||
case "$(uci -q get owrtremote.main.enabled 2>/dev/null || echo 0)" in
|
||||
1|yes|true|on|enabled) ;;
|
||||
*) exit 0 ;;
|
||||
esac
|
||||
|
||||
log() {
|
||||
logger -t "$TAG" "$*" 2>/dev/null || true
|
||||
}
|
||||
|
||||
proto=""
|
||||
if [ -n "$INTERFACE" ] && command -v ubus >/dev/null 2>&1; then
|
||||
proto="$(
|
||||
ubus -S call "network.interface.$INTERFACE" status 2>/dev/null | sed -n 's/.*"proto"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n 1
|
||||
)"
|
||||
fi
|
||||
|
||||
case "$INTERFACE:$DEVICE:$proto" in
|
||||
wan:*:*|wan6:*:*|*:pppoe*:*|*:ppp*:*|*:*:pppoe|*:*:ppp) ;;
|
||||
*) exit 0 ;;
|
||||
esac
|
||||
|
||||
network_ready() {
|
||||
if command -v ip >/dev/null 2>&1 && ip route get 1.1.1.1 >/dev/null 2>&1; then
|
||||
return 0
|
||||
fi
|
||||
route -n 2>/dev/null | awk '$4 ~ /G/ { found = 1 } END { exit found ? 0 : 1 }'
|
||||
}
|
||||
|
||||
mkdir -p "$STATE_DIR"
|
||||
stamp="$(date +%s 2>/dev/null || echo 0)-$$-${ACTION:-event}-${INTERFACE:-iface}-${DEVICE:-dev}"
|
||||
printf '%s\n' "$stamp" >"$STAMP_FILE"
|
||||
|
||||
(
|
||||
i=0
|
||||
while [ "$i" -lt 30 ]; do
|
||||
[ "$(cat "$STAMP_FILE" 2>/dev/null)" = "$stamp" ] || exit 0
|
||||
network_ready && break
|
||||
i=$((i + 1))
|
||||
sleep 1
|
||||
done
|
||||
|
||||
[ "$(cat "$STAMP_FILE" 2>/dev/null)" = "$stamp" ] || exit 0
|
||||
sleep 3
|
||||
log "WAN event $ACTION on ${INTERFACE:-unknown}/${DEVICE:-unknown}, restarting reverse tunnel"
|
||||
/etc/init.d/owrt-remote restart >/dev/null 2>&1 || log "restart failed"
|
||||
) &
|
||||
|
||||
exit 0
|
||||
@@ -145,6 +145,7 @@ install_xray_runtime() {
|
||||
|
||||
install_file "usr/sbin/owrt-remote" 0755
|
||||
install_file "etc/init.d/owrt-remote" 0755
|
||||
install_file "etc/hotplug.d/iface/99-owrt-remote" 0755
|
||||
install_config
|
||||
install_file "www/cgi-bin/owrt-remote" 0755
|
||||
install_file "usr/share/luci/menu.d/luci-app-owrt-remote.json" 0644
|
||||
|
||||
Reference in new issue
Block a user