1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-vps.git synced 2025-02-12 11:21:56 +00:00
This commit is contained in:
Ycarus (Yannick Chabanois) 2020-03-10 10:45:06 +01:00
parent 61b4452941
commit 4285efb8c7
5 changed files with 18 additions and 123 deletions

View file

@ -23,7 +23,7 @@ GLORYTUN_UDP_VERSION="a9408e799ddbb74b5476fba70a495770322cd327"
#MLVPN_VERSION="8f9720978b28c1954f9f229525333547283316d2" #MLVPN_VERSION="8f9720978b28c1954f9f229525333547283316d2"
MLVPN_VERSION="f45cec350a6879b8b020143a78134a022b5df2a7" MLVPN_VERSION="f45cec350a6879b8b020143a78134a022b5df2a7"
OBFS_VERSION="486bebd9208539058e57e23a12f23103016e09b4" OBFS_VERSION="486bebd9208539058e57e23a12f23103016e09b4"
OMR_ADMIN_VERSION="6cc1a3236a61344a03245284082a9602da709aca" OMR_ADMIN_VERSION="0bee06d21605c9d9b4494a77e71043ce432aa5c2"
DSVPN_VERSION="3b99d2ef6c02b2ef68b5784bec8adfdd55b29b1a" DSVPN_VERSION="3b99d2ef6c02b2ef68b5784bec8adfdd55b29b1a"
#V2RAY_VERSION="v1.1.0" #V2RAY_VERSION="v1.1.0"
V2RAY_VERSION="v1.2.0-8-g59b8f4f" V2RAY_VERSION="v1.2.0-8-g59b8f4f"
@ -570,7 +570,7 @@ fi
echo 'Glorytun UDP' echo 'Glorytun UDP'
# Install Glorytun UDP # Install Glorytun UDP
if systemctl -q is-active glorytun-udp@tun0.service; then if systemctl -q is-active glorytun-udp@tun0.service; then
systemctl -q stop glorytun-udp@tun0 > /dev/null 2>&1 systemctl -q stop glorytun-udp@* > /dev/null 2>&1
fi fi
rm -f /var/lib/dpkg/lock rm -f /var/lib/dpkg/lock
rm -f /var/lib/dpkg/lock-frontend rm -f /var/lib/dpkg/lock-frontend
@ -648,7 +648,7 @@ fi
# Install Glorytun TCP # Install Glorytun TCP
if systemctl -q is-active glorytun-tcp@tun0.service; then if systemctl -q is-active glorytun-tcp@tun0.service; then
systemctl -q stop glorytun-tcp@tun0 > /dev/null 2>&1 systemctl -q stop glorytun-tcp@* > /dev/null 2>&1
fi fi
if [ "$ID" = "debian" ]; then if [ "$ID" = "debian" ]; then
if [ "$VERSION_ID" = "9" ]; then if [ "$VERSION_ID" = "9" ]; then
@ -708,7 +708,7 @@ if systemctl -q is-active omr-6in4.service; then
systemctl -q stop omr-6in4 > /dev/null 2>&1 systemctl -q stop omr-6in4 > /dev/null 2>&1
systemctl -q disable omr-6in4 > /dev/null 2>&1 systemctl -q disable omr-6in4 > /dev/null 2>&1
fi fi
systemctl enable omr6in4@user1.service systemctl enable omr6in4@user0.service
systemctl enable omr.service systemctl enable omr.service
# Change SSH port to 65222 # Change SSH port to 65222
@ -906,20 +906,20 @@ else
echo 'done' echo 'done'
if [ "$MLVPN" = "yes" ]; then if [ "$MLVPN" = "yes" ]; then
echo 'Restarting mlvpn...' echo 'Restarting mlvpn...'
systemctl -q start mlvpn@mlvpn0 systemctl -q restart mlvpn@mlvpn0
echo 'done' echo 'done'
fi fi
if [ "$DSVPN" = "yes" ]; then if [ "$DSVPN" = "yes" ]; then
echo 'Restarting dsvpn...' echo 'Restarting dsvpn...'
systemctl -q start dsvpn-server@dsvpn0 systemctl -q restart dsvpn-server@* || true
echo 'done' echo 'done'
fi fi
echo 'Restarting glorytun...' echo 'Restarting glorytun...'
systemctl -q start glorytun-tcp@tun0 systemctl -q restart glorytun-tcp@* || true
systemctl -q start glorytun-udp@tun0 systemctl -q restart glorytun-udp@* || true
echo 'done' echo 'done'
echo 'Restarting omr...' echo 'Restarting omr6in4...'
systemctl -q restart omr systemctl -q restart omr6in4@* || true
echo 'done' echo 'done'
if [ "$OPENVPN" = "yes" ]; then if [ "$OPENVPN" = "yes" ]; then
echo 'Restarting OpenVPN' echo 'Restarting OpenVPN'
@ -957,6 +957,9 @@ else
echo 'Apply latest sysctl...' echo 'Apply latest sysctl...'
sysctl -p /etc/sysctl.d/90-shadowsocks.conf > /dev/null 2>&1 sysctl -p /etc/sysctl.d/90-shadowsocks.conf > /dev/null 2>&1
echo 'done' echo 'done'
echo 'Restarting omr...'
systemctl -q restart omr
echo 'done'
echo 'Restarting shadowsocks...' echo 'Restarting shadowsocks...'
systemctl -q restart shadowsocks-libev-manager@manager systemctl -q restart shadowsocks-libev-manager@manager
# if [ $NBCPU -gt 1 ]; then # if [ $NBCPU -gt 1 ]; then

View file

@ -9,7 +9,7 @@ NotifyAccess=main
ExecStart=/usr/local/sbin/mlvpn --config /etc/mlvpn/%i.conf --name %i --user mlvpn --quiet ExecStart=/usr/local/sbin/mlvpn --config /etc/mlvpn/%i.conf --name %i --user mlvpn --quiet
ExecReload=/bin/kill -HUP $MAINPID ExecReload=/bin/kill -HUP $MAINPID
WorkingDirectory=/etc/mlvpn WorkingDirectory=/etc/mlvpn
Restart=on-failure Restart=always
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View file

@ -1,13 +1,5 @@
#!/bin/bash #!/bin/bash
# OpenMPTCProuter VPS service script # OpenMPTCProuter VPS service script
# This script configure 6in4, multipath and firewall for current VPN
if [ "$1" = "stop" ] && [ "$(ip link show omr-6in4 up 2>/dev/null)" ]; then
ip route del fd00::/8 via fe80::a00:2 dev omr-6in4
ip link set omr-6in4 down
ip tunnel del omr-6in4
exit 0
fi
_multipath() { _multipath() {
# Force multipath status # Force multipath status
@ -21,109 +13,7 @@ _multipath() {
done done
} }
# Add IPv6 tunnel
if [ "$(ip link show omr-6in4 up 2>/dev/null)" ]; then
ip tunnel change omr-6in4 mode sit remote 10.255.255.2 local 10.255.255.1
else
ip tunnel add omr-6in4 mode sit remote 10.255.255.2 local 10.255.255.1
ip addr add fe80::a00:1/126 dev omr-6in4 >/dev/null 2>&1
fi
ip link set omr-6in4 up
ip route replace fd00::/8 via fe80::a00:2 dev omr-6in4
_ping() {
local host=$1
ret=$(ping -4 "${host}" \
-W 5 \
-c 1 \
-q
)
[ -n "$ret" ] && echo "$ret" | grep -s " 0% packet loss" > /dev/null && {
return
}
false
}
_ping_range() {
local network=$1
for i in {2..50} ;do
_ping $network$i
pingr=$?
if $(exit $pingr); then
ipd=$network$i
return
fi
done
false
}
while true; do while true; do
source /etc/shorewall/params.vpn _multipath
iface=""
currentaddr=$(ip addr show omr-6in4 | grep link/sit | awk '{print $2}' | tr -d "\n")
currentpeer=$(ip addr show omr-6in4 | grep link/sit | awk '{print $4}' | tr -d "\n")
if [ -n "$currentpeer" ]; then
_ping $currentpeer
status=$?
if ! $(exit $status) || [ "$currentpeer" != "$OMR_ADDR" ]; then
allip_tcp=$(ip -4 addr show gt-tun0 2>/dev/null | grep inet)
allip_udp=$(ip -4 addr show gt-udp-tun0 2>/dev/null | grep inet)
[ -d "/sys/class/net/mlvpn0" ] && allip_mlvpn=$(ip -4 addr show mlvpn0 2>/dev/null | grep inet)
[ -d "/sys/class/net/tun0" ] && allip_openvpn=$(ip -4 addr show tun0 2>/dev/null | grep inet)
[ -d "/sys/class/net/dsvpn0" ] && allip_dsvpn=$(ip -4 addr show dsvpn0 2>/dev/null | grep inet)
if [ -f /etc/openmptcprouter-vps-admin/current-vpn ]; then
current_vpn="$(cat /etc/openmptcprouter-vps-admin/current-vpn)"
[ "$current_vpn" = "glorytun_tcp" ] && allip="$allip_tcp"
[ "$current_vpn" = "glorytun_udp" ] && allip="$allip_udp"
[ "$current_vpn" = "mlvpn" ] && allip="$allip_mlvpn"
[ "$current_vpn" = "openvpn" ] && allip="$allip_openvpn"
[ "$current_vpn" = "dsvpn" ] && allip="$allip_dsvpn"
fi
if [ -z "$allip" ]; then
allip="$allip_tcp
$allip_udp
$allip_openvpn
$allip_dsvpn
$allip_mlvpn"
fi
while IFS= read -r inet; do
ip=$(echo $inet | awk '{print $2}' | cut -d/ -f1 | tr -d "\n")
if [ "$ip" != "" ]; then
_ping_range $(echo $ip | sed 's/.1$/./' | tr -d "\n")
statusr=$?
if $(exit $statusr); then
_ping $ipd
statusp=$?
if $(exit $statusp); then
logger -t "OMR-Service" "Set new 6in4 tunnel IPs"
ip tunnel change omr-6in4 mode sit remote $ipd local $ip
#echo "VPS_ADDR=$ip" > /etc/shorewall/params.vpn
#echo "OMR_ADDR=$ipd" >> /etc/shorewall/params.vpn
iface=$(ip -4 addr | grep $ip/ | awk '{print $7}' | tr -d "\n")
#echo "VPS_IFACE=$iface" >> /etc/shorewall/params.vpn
#systemctl reload shorewall
_multipath
break
fi
fi
fi
done < <(printf '%s\n' "$allip")
[ -z "$iface" ] && [ -f /etc/openmptcprouter-vps-admin/current-vpn ] && {
logger -t "OMR-Service" "Restart Glorytun"
current_vpn="$(cat /etc/openmptcprouter-vps-admin/current-vpn)"
[ "$current_vpn" = "glorytun_tcp" ] && systemctl -q restart glorytun-tcp@tun0
[ "$current_vpn" = "glorytun_udp" ] && systemctl -q restart glorytun-udp@tun0
#systemctl -q restart systemd-networkd
_multipath
sleep 10
}
fi
fi
#result="$(curl -Isk -m 30 https://127.0.0.1:65500/status | head -n 1 | grep 405)"
#if [ "$result" = "" ]; then
# logger -t "OMR-Service" "Restart OMR Admin"
# systemctl -q restart omr-admin
# sleep 10
#fi
sleep 10 sleep 10
done done

View file

@ -5,7 +5,8 @@ After=network.target network-online.target
[Service] [Service]
Type=oneshot Type=oneshot
ExecStart=/usr/local/bin/omr-6in4-run start /etc/openmptcprouter-vps-admin/omr-6in4/%i ExecStart=/usr/local/bin/omr-6in4-run start /etc/openmptcprouter-vps-admin/omr-6in4/%i
ExecStop=/usr/local/bin/omr-6in4-run start /etc/openmptcprouter-vps-admin/omr-6in4/%i RemainAfterExit=true
ExecStop=/usr/local/bin/omr-6in4-run stop /etc/openmptcprouter-vps-admin/omr-6in4/%i
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View file

@ -9,6 +9,7 @@ AmbientCapabilities=CAP_NET_BIND_SERVICE
LimitNOFILE=99999 LimitNOFILE=99999
LimitNPROC=99999 LimitNPROC=99999
ExecStart=/usr/bin/ss-manager -c /etc/shadowsocks-libev/%i.json ExecStart=/usr/bin/ss-manager -c /etc/shadowsocks-libev/%i.json
Restart=always
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target