1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00
This commit is contained in:
Ycarus (Yannick Chabanois) 2019-11-13 19:22:08 +01:00
parent e00c6705e0
commit 85eef04377
2 changed files with 25 additions and 12 deletions

View file

@ -10,8 +10,10 @@ set_route() {
interface_if=$(ifstatus "$INTERFACE" 2>/dev/null | jsonfilter -q -e '@["l3_device"]') interface_if=$(ifstatus "$INTERFACE" 2>/dev/null | jsonfilter -q -e '@["l3_device"]')
[ -z "$interface_if" ] && interface_if=$(ifstatus "${INTERFACE}_4" 2>/dev/null | jsonfilter -q -e '@["l3_device"]') [ -z "$interface_if" ] && interface_if=$(ifstatus "${INTERFACE}_4" 2>/dev/null | jsonfilter -q -e '@["l3_device"]')
[ -z "$interface_if" ] && interface_if=$(uci -q get network.$INTERFACE.ifname) [ -z "$interface_if" ] && interface_if=$(uci -q get network.$INTERFACE.ifname)
multipath_current_config=$(multipath $interface_if | grep 'deactivated') #multipath_current_config=$(multipath $interface_if | grep 'deactivated')
if [ "$multipath_config" != "off" ] && [ "$SETROUTE" != true ] && [ "$INTERFACE" != "$PREVINTERFACE" ] && [ "$multipath_current_config" = "" ]; then interface_current_config=$(uci -q get openmptcprouter.$INTERFACE.state || echo "up")
#if [ "$multipath_config" != "off" ] && [ "$SETROUTE" != true ] && [ "$INTERFACE" != "$PREVINTERFACE" ] && [ "$multipath_current_config" = "" ]; then
if [ "$multipath_config" != "off" ] && [ "$SETROUTE" != true ] && [ "$INTERFACE" != "$PREVINTERFACE" ] && [ "$interface_current_config" = "up" ]; then
interface_gw="$(uci -q get network.$INTERFACE.gateway)" interface_gw="$(uci -q get network.$INTERFACE.gateway)"
if [ -z "$interface_gw" ]; then if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e '@.inactive.route[@.target="0.0.0.0"].nexthop' | tr -d "\n") interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e '@.inactive.route[@.target="0.0.0.0"].nexthop' | tr -d "\n")
@ -81,8 +83,10 @@ set_routes_intf() {
interface_if=$(ifstatus "$INTERFACE" 2>/dev/null | jsonfilter -q -e '@["l3_device"]') interface_if=$(ifstatus "$INTERFACE" 2>/dev/null | jsonfilter -q -e '@["l3_device"]')
[ -z "$interface_if" ] && interface_if=$(ifstatus "${INTERFACE}_4" 2>/dev/null | jsonfilter -q -e '@["l3_device"]') [ -z "$interface_if" ] && interface_if=$(ifstatus "${INTERFACE}_4" 2>/dev/null | jsonfilter -q -e '@["l3_device"]')
[ -z "$interface_if" ] && interface_if=$(uci -q get network.$INTERFACE.ifname) [ -z "$interface_if" ] && interface_if=$(uci -q get network.$INTERFACE.ifname)
multipath_current_config=$(multipath $interface_if | grep 'deactivated') #multipath_current_config=$(multipath $interface_if | grep 'deactivated')
if [ "$multipath_config" != "off" ] && [ "$multipath_current_config" = "" ] && [ "$interface_if" != "" ]; then interface_current_config=$(uci -q openmptcprouter.$INTERFACE.state || echo "up")
#if [ "$multipath_config" != "off" ] && [ "$multipath_current_config" = "" ] && [ "$interface_if" != "" ]; then
if [ "$multipath_config" != "off" ] && [ "$interface_current_config" = "up" ] && [ "$interface_if" != "" ]; then
interface_gw="$(uci -q get network.$INTERFACE.gateway)" interface_gw="$(uci -q get network.$INTERFACE.gateway)"
if [ -z "$interface_gw" ]; then if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e '@.inactive.route[@.target="0.0.0.0"].nexthop' | tr -d "\n") interface_gw=$(ubus call network.interface.$INTERFACE status 2>/dev/null | jsonfilter -q -l 1 -e '@.inactive.route[@.target="0.0.0.0"].nexthop' | tr -d "\n")
@ -106,7 +110,6 @@ set_server_all_routes() {
interface_if=$(uci -q get network.$OMR_TRACKER_INTERFACE.ifname) interface_if=$(uci -q get network.$OMR_TRACKER_INTERFACE.ifname)
[ -z "$interface_if" ] && interface_if=$(ifstatus "$OMR_TRACKER_INTERFACE" 2>/dev/null | jsonfilter -q -e '@["l3_device"]') [ -z "$interface_if" ] && interface_if=$(ifstatus "$OMR_TRACKER_INTERFACE" 2>/dev/null | jsonfilter -q -e '@["l3_device"]')
[ -z "$interface_if" ] && interface_if=$(ifstatus "${OMR_TRACKER_INTERFACE}_4" 2>/dev/null | jsonfilter -q -e '@["l3_device"]') [ -z "$interface_if" ] && interface_if=$(ifstatus "${OMR_TRACKER_INTERFACE}_4" 2>/dev/null | jsonfilter -q -e '@["l3_device"]')
multipath_current_config=$(multipath $interface_if | grep "deactivated")
multipath_config_route=$(uci -q get network.$OMR_TRACKER_INTERFACE.multipath) multipath_config_route=$(uci -q get network.$OMR_TRACKER_INTERFACE.multipath)
[ -z "$multipath_config_route" ] && multipath_config_route=$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.multipath || echo "off") [ -z "$multipath_config_route" ] && multipath_config_route=$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.multipath || echo "off")
if [ "$serverip" != "" ] && [ "$OMR_TRACKER_DEVICE_GATEWAY" != "" ] && [ "$(ip route show $serverip | grep nexthop | grep $OMR_TRACKER_DEVICE_GATEWAY | grep $OMR_TRACKER_INTERFACE)" = "" ] && [ "$multipath_config_route" != "off" ]; then if [ "$serverip" != "" ] && [ "$OMR_TRACKER_DEVICE_GATEWAY" != "" ] && [ "$(ip route show $serverip | grep nexthop | grep $OMR_TRACKER_DEVICE_GATEWAY | grep $OMR_TRACKER_INTERFACE)" = "" ] && [ "$multipath_config_route" != "off" ]; then
@ -133,8 +136,10 @@ set_server_route() {
interface_if=$(uci -q get network.$OMR_TRACKER_INTERFACE.ifname) interface_if=$(uci -q get network.$OMR_TRACKER_INTERFACE.ifname)
[ -z "$interface_if" ] && interface_if=$(ifstatus "$OMR_TRACKER_INTERFACE" 2>/dev/null | jsonfilter -q -e '@["l3_device"]') [ -z "$interface_if" ] && interface_if=$(ifstatus "$OMR_TRACKER_INTERFACE" 2>/dev/null | jsonfilter -q -e '@["l3_device"]')
[ -z "$interface_if" ] && interface_if=$(ifstatus "${OMR_TRACKER_INTERFACE}_4" 2>/dev/null | jsonfilter -q -e '@["l3_device"]') [ -z "$interface_if" ] && interface_if=$(ifstatus "${OMR_TRACKER_INTERFACE}_4" 2>/dev/null | jsonfilter -q -e '@["l3_device"]')
multipath_current_config=$(multipath $interface_if | grep "deactivated") #multipath_current_config=$(multipath $interface_if | grep "deactivated")
if [ "$serverip" != "" ] && [ "$OMR_TRACKER_DEVICE_GATEWAY" != "" ] && [ "$(ip route show dev $OMR_TRACKER_DEVICE metric $metric | grep $serverip | grep $OMR_TRACKER_DEVICE_GATEWAY)" = "" ] && [ "$multipath_config_route" != "off" ] && [ "$multipath_current_config" = "" ]; then interface_current_config=$(uci -q openmptcprouter.$OMR_TRACKER_INTERFACE.state || echo "up")
#if [ "$serverip" != "" ] && [ "$OMR_TRACKER_DEVICE_GATEWAY" != "" ] && [ "$(ip route show dev $OMR_TRACKER_DEVICE metric $metric | grep $serverip | grep $OMR_TRACKER_DEVICE_GATEWAY)" = "" ] && [ "$multipath_config_route" != "off" ] && [ "$multipath_current_config" = "" ]; then
if [ "$serverip" != "" ] && [ "$OMR_TRACKER_DEVICE_GATEWAY" != "" ] && [ "$(ip route show dev $OMR_TRACKER_DEVICE metric $metric | grep $serverip | grep $OMR_TRACKER_DEVICE_GATEWAY)" = "" ] && [ "$multipath_config_route" != "off" ] && [ "$interface_current_config" = "up" ]; then
_log "Set server $server ($serverip) route via $OMR_TRACKER_DEVICE_GATEWAY metric $metric" _log "Set server $server ($serverip) route via $OMR_TRACKER_DEVICE_GATEWAY metric $metric"
if [ "$(uci -q get openmptcprouter.settings.uci_route)" = "1" ]; then if [ "$(uci -q get openmptcprouter.settings.uci_route)" = "1" ]; then
uci -q batch <<-EOF >/dev/null uci -q batch <<-EOF >/dev/null
@ -204,9 +209,9 @@ disable_pihole() {
enable_pihole() { enable_pihole() {
local server=$1 local server=$1
nbserver=$((nbserver+1))
if [ "$(uci -q get openmptcprouter.${server}.pihole)" = "1" ] && [ "$(uci -q get dhcp.@dnsmasq[0].server)" = "127.0.0.1#5353" ]; then if [ "$(uci -q get openmptcprouter.${server}.pihole)" = "1" ] && [ "$(uci -q get dhcp.@dnsmasq[0].server)" = "127.0.0.1#5353" ]; then
_log "Enable Pi-Hole..." piholeenabled=$((piholeenabled+1))
/etc/init.d/openmptcprouter-vps set_pihole
fi fi
} }
@ -246,9 +251,9 @@ if [ "$OMR_TRACKER_STATUS" = "ERROR" ]; then
_log "$OMR_TRACKER_DEVICE switched off because $OMR_TRACKER_STATUS_MSG" _log "$OMR_TRACKER_DEVICE switched off because $OMR_TRACKER_STATUS_MSG"
fi fi
uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.state='down' uci -q set openmptcprouter.$OMR_TRACKER_INTERFACE.state='down'
if [ "$(sysctl -n net.mptcp.mptcp_enabled | tr -d '\n')" = "1" ]; then #if [ "$(sysctl -n net.mptcp.mptcp_enabled | tr -d '\n')" = "1" ]; then
multipath "$OMR_TRACKER_DEVICE" off > /dev/null 2>&1 # multipath "$OMR_TRACKER_DEVICE" off > /dev/null 2>&1
fi #fi
if [ -n "$OMR_TRACKER_DEVICE_IP" ]; then if [ -n "$OMR_TRACKER_DEVICE_IP" ]; then
glorytun-udp path $OMR_TRACKER_DEVICE_IP dev tun0 down > /dev/null 2>&1 glorytun-udp path $OMR_TRACKER_DEVICE_IP dev tun0 down > /dev/null 2>&1
fi fi
@ -350,8 +355,11 @@ if [ "$OMR_TRACKER_INTERFACE" = "glorytun" ] || [ "$OMR_TRACKER_INTERFACE" = "om
fi fi
uci -q commit openmptcprouter uci -q commit openmptcprouter
fi fi
nbserver=0
piholeenabled=0
config_load openmptcprouter config_load openmptcprouter
config_foreach enable_pihole server config_foreach enable_pihole server
[ "$nbserver" = "$piholeenabled" ] && /etc/init.d/openmptcprouter-vps set_pihole
#ubus call network reload #ubus call network reload
exit 0 exit 0
fi fi
@ -558,6 +566,9 @@ fi
if [ "$(uci -q get openmptcprouter.settings.master_lcintf | grep $OMR_TRACKER_INTERFACE)" = "" ]; then if [ "$(uci -q get openmptcprouter.settings.master_lcintf | grep $OMR_TRACKER_INTERFACE)" = "" ]; then
uci -q add_list openmptcprouter.settings.master_lcintf="$OMR_TRACKER_INTERFACE" uci -q add_list openmptcprouter.settings.master_lcintf="$OMR_TRACKER_INTERFACE"
fi fi
if [ "$(uci -q get openmptcprouter.settings.master)" = "" ]; then
uci -q set openmptcprouter.settings.master="change"
fi
if [ "$(uci -q get openmptcprouter.settings.master)" != "dynamic" ]; then if [ "$(uci -q get openmptcprouter.settings.master)" != "dynamic" ]; then
uci -q commit network uci -q commit network
uci -q commit openmptcprouter uci -q commit openmptcprouter

View file

@ -499,6 +499,7 @@ _vps_firewall_close_port() {
_set_vps_firewall() { _set_vps_firewall() {
fwservername=$1 fwservername=$1
[ -z "$servername" ] && servername=$fwservername
[ "$(uci -q get openmptcprouter.${fwservername}.nofwredirect)" = "1" ] && return [ "$(uci -q get openmptcprouter.${fwservername}.nofwredirect)" = "1" ] && return
[ -z "$(uci -q get openmptcprouter.${fwservername}.username)" ] && return [ -z "$(uci -q get openmptcprouter.${fwservername}.username)" ] && return
[ -z "$(uci -q get openmptcprouter.${fwservername}.password)" ] && return [ -z "$(uci -q get openmptcprouter.${fwservername}.password)" ] && return
@ -985,6 +986,7 @@ _config_service() {
_set_pihole_server() { _set_pihole_server() {
pservername=$1 pservername=$1
[ -z "$servername" ] && servername=$pservername
[ -z "$(uci -q get openmptcprouter.${pservername}.username)" ] && return [ -z "$(uci -q get openmptcprouter.${pservername}.username)" ] && return
[ -z "$(uci -q get openmptcprouter.${pservername}.password)" ] && return [ -z "$(uci -q get openmptcprouter.${pservername}.password)" ] && return
[ -z "$(uci -q get openmptcprouter.${pservername}.port)" ] && return [ -z "$(uci -q get openmptcprouter.${pservername}.port)" ] && return