2018-06-01 13:11:58 +00:00
|
|
|
#!/bin/bash
|
2018-07-27 12:40:12 +00:00
|
|
|
# OpenMPTCProuter VPS service script
|
2018-06-01 13:11:58 +00:00
|
|
|
|
2019-01-02 08:57:31 +00:00
|
|
|
_multipath() {
|
|
|
|
# Force multipath status
|
|
|
|
source /etc/shorewall/params.net
|
|
|
|
for intf in `ls -1 /sys/class/net`; do
|
|
|
|
if [ "$intf" = "$NET_IFACE" ]; then
|
2020-07-20 14:01:51 +00:00
|
|
|
[ "$(multipath $intf | tr -d '\n')" != "$intf is in default mode" ] && multipath $intf on
|
2019-01-02 08:57:31 +00:00
|
|
|
else
|
2020-07-20 14:01:51 +00:00
|
|
|
[ "$(multipath $intf | tr -d '\n')" != "$intf is deactivated" ] && multipath $intf off
|
2019-01-02 08:57:31 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
2018-07-27 12:40:12 +00:00
|
|
|
|
2020-03-12 18:38:43 +00:00
|
|
|
_glorytun_udp() {
|
2020-03-15 22:41:24 +00:00
|
|
|
[ -z "$(glorytun show dev gt-udp-tun0 2>/dev/null | grep server)" ] && {
|
|
|
|
logger -t "OMR-Service" "Restart Glorytun-UDP"
|
2020-07-20 14:01:51 +00:00
|
|
|
systemctl -q restart 'glorytun-udp@*'
|
2020-03-15 22:41:24 +00:00
|
|
|
}
|
2020-07-20 14:01:51 +00:00
|
|
|
for intf in /etc/glorytun-udp/tun*; do
|
|
|
|
[ "$(echo $intf | grep key)" = "" ] && /etc/glorytun-udp/post.sh ${intf}
|
2020-04-07 14:06:54 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
_glorytun_tcp() {
|
2020-07-20 14:01:51 +00:00
|
|
|
for intf in /etc/glorytun-tcp/tun*; do
|
|
|
|
[ "$(echo $intf | grep key)" = "" ] && /etc/glorytun-tcp/post.sh ${intf}
|
2020-04-07 14:06:54 +00:00
|
|
|
done
|
2020-03-15 22:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_omr_api() {
|
2020-09-15 12:27:08 +00:00
|
|
|
[ -z "$(curl -s -k -m 30 https://127.0.0.1:65500/)" ] && {
|
2020-03-15 22:41:24 +00:00
|
|
|
logger -t "OMR-Service" "Restart OMR-Admin"
|
|
|
|
systemctl -q restart omr-admin
|
|
|
|
}
|
2020-03-12 18:38:43 +00:00
|
|
|
}
|
|
|
|
|
2020-07-20 14:01:51 +00:00
|
|
|
_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')
|
2020-08-14 08:18:13 +00:00
|
|
|
if [ -n "$vpnremoteip" ] && [ "$vpnremoteip" != "null" ]; then
|
2020-07-20 14:01:51 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-07-23 15:01:34 +00:00
|
|
|
_gre_tunnels() {
|
|
|
|
. "$(readlink -f "/etc/shorewall/params.vpn")"
|
|
|
|
for intf in /etc/openmptcprouter-vps-admin/intf/*; do
|
2020-07-28 13:51:00 +00:00
|
|
|
if [ -f "$intf" ]; then
|
|
|
|
. "$(readlink -f "$intf")"
|
|
|
|
iface="$(basename $intf)"
|
2020-09-29 13:43:24 +00:00
|
|
|
if [ "$(ip tunnel show $iface 2>/dev/null | awk '{print $4}')" != "$REMOTEIP" ]; then
|
2020-07-28 13:51:00 +00:00
|
|
|
ip tunnel del $iface 2>&1 >/dev/null
|
2020-09-29 13:43:24 +00:00
|
|
|
ip tunnel add $iface mode gre local $INTFADDR remote $REMOTEIP
|
2020-07-28 13:51:00 +00:00
|
|
|
ip link set $iface up
|
|
|
|
ip addr add $LOCALIP dev $iface
|
|
|
|
ip route add $NETWORK dev $iface 2>&1 >/dev/null
|
|
|
|
fi
|
2020-07-23 15:01:34 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-01 13:11:58 +00:00
|
|
|
while true; do
|
2020-03-12 18:38:43 +00:00
|
|
|
_glorytun_udp
|
2020-04-07 14:06:54 +00:00
|
|
|
_glorytun_tcp
|
2020-03-10 09:45:06 +00:00
|
|
|
_multipath
|
2020-03-15 22:41:24 +00:00
|
|
|
_omr_api
|
2020-07-20 14:01:51 +00:00
|
|
|
_lan_route
|
2020-07-23 15:01:34 +00:00
|
|
|
_gre_tunnels
|
2019-05-12 02:45:49 +00:00
|
|
|
sleep 10
|
2018-06-01 13:11:58 +00:00
|
|
|
done
|