mirror of
https://github.com/Ysurac/openmptcprouter-vps.git
synced 2025-02-12 11:21:56 +00:00
77 lines
2.1 KiB
Bash
Executable file
77 lines
2.1 KiB
Bash
Executable file
#!/bin/bash
|
|
# OpenMPTCProuter VPS service script
|
|
|
|
_multipath() {
|
|
# Force multipath status
|
|
source /etc/shorewall/params.net
|
|
for intf in `ls -1 /sys/class/net`; do
|
|
if [ "$intf" = "$NET_IFACE" ]; then
|
|
[ "$(multipath $intf | tr -d '\n')" != "$intf is in default mode" ] && multipath $intf on
|
|
else
|
|
[ "$(multipath $intf | tr -d '\n')" != "$intf is deactivated" ] && multipath $intf off
|
|
fi
|
|
done
|
|
}
|
|
|
|
_glorytun_udp() {
|
|
[ -z "$(glorytun show dev gt-udp-tun0 2>/dev/null | grep server)" ] && {
|
|
logger -t "OMR-Service" "Restart Glorytun-UDP"
|
|
systemctl -q restart 'glorytun-udp@*'
|
|
}
|
|
for intf in /etc/glorytun-udp/tun*; do
|
|
[ "$(echo $intf | grep key)" = "" ] && /etc/glorytun-udp/post.sh ${intf}
|
|
done
|
|
}
|
|
|
|
_glorytun_tcp() {
|
|
for intf in /etc/glorytun-tcp/tun*; do
|
|
[ "$(echo $intf | grep key)" = "" ] && /etc/glorytun-tcp/post.sh ${intf}
|
|
done
|
|
}
|
|
|
|
_omr_api() {
|
|
[ -z "$(curl -s -k -m 3 https://127.0.0.1:65500/)" ] && {
|
|
logger -t "OMR-Service" "Restart OMR-Admin"
|
|
systemctl -q restart omr-admin
|
|
}
|
|
}
|
|
|
|
_lan_route() {
|
|
cat /etc/openmptcprouter-vps-admin/omr-admin-config.json | jq -c '.users[0][]' |
|
|
while IFS=$"\n" read -r c; do
|
|
vpnremoteip=$(echo "$c" | jq -r '.vpnremoteip')
|
|
if [ -n "$vpnremoteip" ]; then
|
|
echo "$c" | jq -c '.lanips //empty' |
|
|
while IFS=$"\n" read -r d; do
|
|
network=$(ipcalc -n $d | grep Network | awk '{print $2}')
|
|
[ -n "$network" ] && [ -z "$(ip r show $network via $vpnremoteip)" ] && ip r replace $network via $vpnremoteip 2>&1 >/dev/null
|
|
done
|
|
fi
|
|
done
|
|
}
|
|
|
|
_gre_tunnels() {
|
|
. "$(readlink -f "/etc/shorewall/params.vpn")"
|
|
for intf in /etc/openmptcprouter-vps-admin/intf/*; do
|
|
. "$(readlink -f "$intf")"
|
|
iface="$(basename $intf)"
|
|
if [ "$(ip tunnel show $iface 2>/dev/null | awk '{print $4}')" != "$OMR_ADDR" ]; then
|
|
ip tunnel del $iface 2>&1 >/dev/null
|
|
ip tunnel add $iface mode gre local $INTFADDR remote $OMR_ADDR
|
|
ip link set $iface up
|
|
ip addr add $LOCALIP dev $iface
|
|
ip route add $NETWORK dev $iface 2>&1 >/dev/null
|
|
fi
|
|
done
|
|
}
|
|
|
|
|
|
while true; do
|
|
_glorytun_udp
|
|
_glorytun_tcp
|
|
_multipath
|
|
_omr_api
|
|
_lan_route
|
|
_gre_tunnels
|
|
sleep 10
|
|
done
|