1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00

Fix IPv6 in openmptcprouter-vps init script

This commit is contained in:
Ycarus (Yannick Chabanois) 2025-02-25 14:21:20 +01:00
parent 31f404e8a5
commit 9e4fdc3420

View file

@ -1,5 +1,5 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2018-2023 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
# Copyright (C) 2018-2025 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
# Released under GPL 3. See LICENSE for the full terms.
START=99
@ -45,19 +45,19 @@ _login() {
server=$1
[ -n "$token" ] && return
#auth=`curl --max-time 10 -s -k -H "Content-Type: application/json" -X POST -d '{"username":"'$username'","password":"'$password'"}' https://$server:$serverport/login`
resolve="$(resolveip -t 5 $server)"
#resolve="$(resolveip -t 5 $server)"
valid_ip6=$(valid_subnet6 $server)
if [ "$resolve" != "$server" ] || [ "$valid_ip6" != "ok" ]; then
auth=`curl --max-time 10 -s -k -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -X POST -d 'username='$username'&password='$password https://$server:$serverport/token`
else
if [ "$valid_ip6" = "ok" ]; then
auth=`curl --max-time 10 -s -k -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -X POST -d 'username='$username'&password='$password https://[$server]:$serverport/token`
else
auth=`curl --max-time 10 -s -k -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -X POST -d 'username='$username'&password='$password https://$server:$serverport/token`
fi
if [ -z "$auth" ]; then
for intf in $(multipath 2>/dev/null | awk '/default/ { print $1 }'); do
if [ "$resolve" != "$server" ] || [ "$valid_ip6" != "ok" ]; then
auth=`curl --max-time 10 -s -k --interface $intf -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -X POST -d 'username='$username'&password='$password https://$server:$serverport/token`
else
if [ "$valid_ip6" = "ok" ]; then
auth=`curl --max-time 10 -s -k --interface $intf -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -X POST -d 'username='$username'&password='$password https://[$server]:$serverport/token`
else
auth=`curl --max-time 10 -s -k --interface $intf -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -X POST -d 'username='$username'&password='$password https://$server:$serverport/token`
fi
[ -n "$auth" ] && break
done
@ -85,17 +85,17 @@ _get_json() {
[ -n "$token" ] && {
resolve="$(resolveip -t 5 $server)"
valid_ip6=$(valid_subnet6 $server)
if [ "$resolve" != "$server" ] || [ "$valid_ip6" != "ok" ]; then
result=`curl --max-time 10 -s -k -H "accept: application/json" -H "Authorization: Bearer $token" https://$server:$serverport/$route`
else
if [ "$valid_ip6" = "ok" ]; then
result=`curl --max-time 10 -s -k -H "accept: application/json" -H "Authorization: Bearer $token" https://[$server]:$serverport/$route`
else
result=`curl --max-time 10 -s -k -H "accept: application/json" -H "Authorization: Bearer $token" https://$server:$serverport/$route`
fi
if [ -z "$result" ]; then
for intf in $(multipath 2>/dev/null | awk '/default/ { print $1 }'); do
if [ "$resolve" != "$server" ] || [ "$valid_ip6" != "ok" ]; then
result=`curl --max-time 10 -s -k --interface $intf -H "accept: application/json" -H "Authorization: Bearer $token" https://$server:$serverport/$route`
else
if [ "$valid_ip6" = "ok" ]; then
result=`curl --max-time 10 -s -k --interface $intf -H "accept: application/json" -H "Authorization: Bearer $token" https://[$server]:$serverport/$route`
else
result=`curl --max-time 10 -s -k --interface $intf -H "accept: application/json" -H "Authorization: Bearer $token" https://$server:$serverport/$route`
fi
[ -n "$result" ] && break
done
@ -117,17 +117,17 @@ _set_json() {
[ -n "$token" ] && {
resolve="$(resolveip -t 5 $server)"
valid_ip6=$(valid_subnet6 $server)
if [ "$resolve" != "$server" ] || [ "$valid_ip6" != "ok" ]; then
result=`curl --max-time 10 -s -k -H "Authorization: Bearer $token" -H "Content-Type: application/json" -X POST -d "$settings" https://$server:$serverport/$route`
else
if [ "$valid_ip6" = "ok" ]; then
result=`curl --max-time 10 -s -k -H "Authorization: Bearer $token" -H "Content-Type: application/json" -X POST -d "$settings" https://[$server]:$serverport/$route`
else
result=`curl --max-time 10 -s -k -H "Authorization: Bearer $token" -H "Content-Type: application/json" -X POST -d "$settings" https://$server:$serverport/$route`
fi
if [ -z "$result" ]; then
for intf in $(multipath 2>/dev/null | awk '/default/ { print $1 }'); do
if [ "$resolve" != "$server" ] || [ "$valid_ip6" != "ok" ]; then
result=`curl --max-time 10 -s -k --interface $intf -H "Authorization: Bearer $token" -H "Content-Type: application/json" -X POST -d "$settings" https://$server:$serverport/$route`
else
if [ "$valid_ip6" = "ok" ]; then
result=`curl --max-time 10 -s -k --interface $intf -H "Authorization: Bearer $token" -H "Content-Type: application/json" -X POST -d "$settings" https://[$server]:$serverport/$route`
else
result=`curl --max-time 10 -s -k --interface $intf -H "Authorization: Bearer $token" -H "Content-Type: application/json" -X POST -d "$settings" https://$server:$serverport/$route`
fi
[ -n "$result" ] && break
done
@ -1013,11 +1013,11 @@ _set_vpn_ip() {
[ "$(uci -q get openmptcprouter.settings.vpn)" = "none" ] && return
vpnifname="$(uci -q get network.omrvpn.device)"
vpnip_local_current="$(echo "$vps_config" | jsonfilter -q -e '@.vpn.remoteip')"
vpnip_local=$(ip -4 -br addr ls dev ${vpnifname} | awk -F'[ /]+' '{print $3}')
vpnip_local=$(ip -4 -br addr ls dev ${vpnifname} 2>/dev/null | awk -F'[ /]+' '{print $3}')
vpnip_remote_current="$(echo "$vps_config" | jsonfilter -q -e '@.vpn.localip')"
vpnip_remote=$(ip -4 r show default dev ${vpnifname} | awk '{print $3}' | tr -d "\n")
[ -z "$vpnip_remote" ] && [ -n "$vpnifname" ] && vpnip_remote=$(ip -4 r list dev ${vpnifname} | grep kernel | awk '{print $1}' | tr -d "\n")
[ -z "$vpnip_remote" ] && [ -n "$vpnifname" ] && vpnip_remote=$(ip -4 r list dev ${vpnifname} | grep "proto static src" | awk '{print $3}' | tr -d "\n")
[ -z "$vpnip_remote" ] && [ -n "$vpnifname" ] && vpnip_remote=$(ip -4 r list dev ${vpnifname} 2>/dev/null | grep kernel | awk '{print $1}' | tr -d "\n")
[ -z "$vpnip_remote" ] && [ -n "$vpnifname" ] && vpnip_remote=$(ip -4 r list dev ${vpnifname} 2>/dev/null | grep "proto static src" | awk '{print $3}' | tr -d "\n")
[ -z "$vpnip_remote" ] && vpnip_remote=$(ifstatus omrvpn | jsonfilter -e '@.route[0].nexthop')
[ -z "$vpnip_remote" ] && [ "$vpnifname" = "bonding-omrvpn" ] && vpnip_remote="10.255.248.1"
ula="$(uci -q get network.globals.ula_prefix)"