Skip to content

Commit

Permalink
sync (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
suyuan168 authored Jul 16, 2024
2 parents 4673c26 + 462fbaa commit b3148f6
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 60 deletions.
25 changes: 13 additions & 12 deletions omr-schedule/files/usr/share/omr/schedule.d/010-services
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,19 @@ restart_omrtracker() {
}

set_lan_ips() {
config_get ip4table "$1" ip4table
config_get device "$1" device
config_get proto "$1" proto
if [ "$ip4table" != "wan" ] && [ "$ip4table" != "vpn" ] && [ -n "$ip4table" ] && [ -n "$device" ] && ([ "$proto" = "dhcp" ] || [ "$proto" = "static" ]); then
[ -z "$(uci -q get shadowsocks-libev.ss_rules.ifnames | grep $device)" ] && [ -z "$(uci -q get shadowsocks-rust.ss_rules.ifnames | grep $device)" ] && {
uci -q add_list shadowsocks-libev.ss_rules.ifnames="$device"
uci -q add_list shadowsocks-rust.ss_rules.ifnames="$device"
}
elif [ -n "$device" ] && [ -n "$(uci -q get shadowsocks-libev.ss_rules.ifnames | grep $device)" ]; then
uci -q del_list shadowsocks-libev.ss_rules.ifnames="$device"
uci -q del_list shadowsocks-rust.ss_rules.ifnames="$device"
fi
config_get ip4table "$1" ip4table
config_get device "$1" device
config_get proto "$1" proto
[ -n "$(echo $device | grep -)" ] && uci -q set openmptcprouter.settings.restrict_to_lan="0" && uci commit openmptcprouter
if [ "$ip4table" != "wan" ] && [ "$ip4table" != "vpn" ] && [ -n "$ip4table" ] && [ -n "$device" ] && ([ "$proto" = "dhcp" ] || [ "$proto" = "static" ]); then
[ -z "$(uci -q get shadowsocks-libev.ss_rules.ifnames | grep $device)" ] && [ -z "$(uci -q get shadowsocks-rust.ss_rules.ifnames | grep $device)" ] && {
uci -q add_list shadowsocks-libev.ss_rules.ifnames="$device"
uci -q add_list shadowsocks-rust.ss_rules.ifnames="$device"
}
elif [ -n "$device" ] && [ -n "$(uci -q get shadowsocks-libev.ss_rules.ifnames | grep $device)" ]; then
uci -q del_list shadowsocks-libev.ss_rules.ifnames="$device"
uci -q del_list shadowsocks-rust.ss_rules.ifnames="$device"
fi
}
config_load network
config_foreach restart_omrtracker interface
Expand Down
13 changes: 9 additions & 4 deletions omr-tracker/files/bin/omr-tracker
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,18 @@ _ping() {
-t "$OMR_TRACKER_MAX_TTL" \
-Q 184 \
"${host}" 2>&1
) && echo "$ret" | grep -sq " 0% packet loss" && {
)
if [ -n "$loss" ] && [ "$loss" != "100" ]; then
if [ "$localip" = "yes" ]; then
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
#_update_rto "$OMR_TRACKER_LATENCY"
latency=$(echo "$ret" | grep rtt | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
[ -n "$latency" ] && {
OMR_TRACKER_LATENCY="$latency"
#_update_rto "$OMR_TRACKER_LATENCY"
}
OMR_TRACKER_LOSS="$loss"
fi
return
}
fi
else
ret=$(ping -B -I "${device}" \
-w "$OMR_TRACKER_TIMEOUT" \
Expand Down
2 changes: 2 additions & 0 deletions omr-tracker/files/bin/omr-tracker-ss
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ while true; do
_log "Reload Shadowsocks rules"
/etc/init.d/shadowsocks-libev rules_up 2> /dev/null
if ! /etc/init.d/shadowsocks-libev rules_exist ; then
_log "Rules still not set, restart Shadowsocks"
/etc/init.d/shadowsocks-libev restart >/dev/null 2>&1
fi
_get_ip
elif [ "$type" = "rust" ] && [ "$(uci -q get shadowsocks-rust.ss_rules.disabled)" != "1" ]; then
_log "Reload Shadowsocks Rust rules"
/etc/init.d/shadowsocks-rust rules_up 2> /dev/null
if ! /etc/init.d/shadowsocks-rust rules_exist ; then
_log "Rules still not set, restart Shadowsocks-Rust"
/etc/init.d/shadowsocks-rust restart >/dev/null 2>&1
fi
_get_ip
Expand Down
92 changes: 49 additions & 43 deletions omr-tracker/files/etc/init.d/omr-tracker
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ _launch_tracker() {
_validate_section "interface" "$1"

local ifname ip4table
network_get_device ifname $1
[ -z "$ifname" ] && network_get_physdev ifname $1
#network_get_device ifname $1
#[ -z "$ifname" ] && network_get_physdev ifname $1
[ -z "$ifname" ] && ifname=$(ifstatus "$1" | jsonfilter -q -e '@["l3_device"]')
[ -z "$ifname" ] && ifname=$(ifstatus "$1_4" | jsonfilter -q -e '@["l3_device"]')
#[ -z "$ifname" ] && config_get ifname "$1" device
Expand Down Expand Up @@ -116,7 +116,7 @@ _launch_tracker() {
[ -z "${family}" ] && family='ipv4'
#[ -z "${failure_interval}" ] && failure_interval=5

procd_open_instance
procd_open_instance "$1"
# shellcheck disable=SC2086
procd_set_param command /bin/omr-tracker "$1" $options
procd_append_param env "OMR_TRACKER_HOSTS=$hosts"
Expand Down Expand Up @@ -416,49 +416,55 @@ start_interface() {
start_service() {
local ss_enable=0
local ss_rust_enable=0
logger -t "omr-tracker" "Launching..."
count=1111
config_load shadowsocks-libev
config_foreach _initialize_shadowsocks_tracker server

count=1111
config_load shadowsocks-rust
config_foreach _initialize_shadowsocks_rust_tracker server

config_load network
config_foreach _launch_tracker interface

if [ "$ss_enable" = "1" ]; then
local instance="$1"
if [ -z "$instance" ]; then
logger -t "omr-tracker" "Launching..."
count=1111
config_load shadowsocks-libev
config_foreach _launch_shadowsocks_tracker ss_local
#elif [ "$(uci -q get shadowsocks-libev.sss0.disabled)" != "1" ]; then
# /etc/init.d/shadowsocks-libev rules_down
fi
if [ "$ss_rust_enable" = "1" ]; then
config_foreach _initialize_shadowsocks_tracker server

count=1111
config_load shadowsocks-rust
config_foreach _launch_shadowsocks_rust_tracker ss_local
fi
config_load v2ray
config_get v2rayenabled main enabled
if [ "$v2rayenabled" = "1" ]; then
_launch_v2ray_tracker
fi

config_load xray
config_get xrayenabled main enabled
if [ "$xrayenabled" = "1" ]; then
_launch_xray_tracker
fi
config_foreach _initialize_shadowsocks_rust_tracker server

multiserver=false
config_load openmptcprouter
config_foreach _multi_server server
[ "$multiserver" = true ] && _launch_server_tracker
gretunnel=false
config_load network
config_foreach _gre_tunnel interface
[ "$gretunnel" = true ] && _launch_gre_tracker
logger -t "omr-tracker" "Launched"
config_load network
config_foreach _launch_tracker interface

if [ "$ss_enable" = "1" ]; then
config_load shadowsocks-libev
config_foreach _launch_shadowsocks_tracker ss_local
#elif [ "$(uci -q get shadowsocks-libev.sss0.disabled)" != "1" ]; then
# /etc/init.d/shadowsocks-libev rules_down
fi
if [ "$ss_rust_enable" = "1" ]; then
config_load shadowsocks-rust
config_foreach _launch_shadowsocks_rust_tracker ss_local
fi
config_load v2ray
config_get v2rayenabled main enabled
if [ "$v2rayenabled" = "1" ]; then
_launch_v2ray_tracker
fi

config_load xray
config_get xrayenabled main enabled
if [ "$xrayenabled" = "1" ]; then
_launch_xray_tracker
fi

multiserver=false
config_load openmptcprouter
config_foreach _multi_server server
[ "$multiserver" = true ] && _launch_server_tracker
gretunnel=false
config_load network
config_foreach _gre_tunnel interface
[ "$gretunnel" = true ] && _launch_gre_tracker
logger -t "omr-tracker" "Launched"
else
config_load network
_launch_tracker ${instance}
fi
}

service_triggers() {
Expand Down
8 changes: 7 additions & 1 deletion omr-tracker/files/usr/share/omr/post-tracking.d/003-up
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ set_routes_intf() {
local multipath_config_route
local INTERFACE=$1
[ -z "$INTERFACE" ] && return
[ "$INTERFACE" = "omrvpn" ] && continue
multipath_config_route=$(uci -q get openmptcprouter.$INTERFACE.multipath)
[ -z "$multipath_config_route" ] && multipath_config_route=$(uci -q get network.$INTERFACE.multipath || echo "off")
[ "$(uci -q get openmptcprouter.$INTERFACE.multipathvpn)" = "1" ] && {
Expand Down Expand Up @@ -252,6 +253,8 @@ set_routes_intf6() {
local multipath_config_route
local INTERFACE=$1
[ -z "$INTERFACE" ] && return
[ "$INTERFACE" = "omr6in4" ] && continue
[ "$INTERFACE" = "omrvpn" ] && continue
multipath_config_route=$(uci -q get openmptcprouter.$INTERFACE.multipath)
[ -z "$multipath_config_route" ] && multipath_config_route=$(uci -q get network.$INTERFACE.multipath || echo "off")
[ "$(uci -q get openmptcprouter.$INTERFACE.multipathvpn)" = "1" ] && {
Expand Down Expand Up @@ -325,6 +328,7 @@ set_route_balancing() {
local multipath_config_route interface_gw interface_if
INTERFACE=$1
[ -z "$INTERFACE" ] && return
[ "$INTERFACE" = "omrvpn" ] && continue
multipath_config_route=$(uci -q get openmptcprouter.$INTERFACE.multipath)
[ -z "$multipath_config_route" ] && multipath_config_route=$(uci -q get network.$INTERFACE.multipath || echo "off")
[ "$(uci -q get openmptcprouter.$INTERFACE.multipathvpn)" = "1" ] && {
Expand Down Expand Up @@ -384,6 +388,8 @@ set_route_balancing6() {
local multipath_config_route interface_gw interface_if
INTERFACE=$1
[ -z "$INTERFACE" ] && return
[ "$INTERFACE" = "omr6in4" ] && continue
[ "$INTERFACE" = "omrvpn" ] && continue
multipath_config_route=$(uci -q get openmptcprouter.$INTERFACE.multipath)
[ -z "$multipath_config_route" ] && multipath_config_route=$(uci -q get network.$INTERFACE.multipath || echo "off")
[ "$(uci -q get openmptcprouter.$INTERFACE.multipathvpn)" = "1" ] && {
Expand Down Expand Up @@ -1036,7 +1042,7 @@ if [ -n "$OMR_TRACKER_INTERFACE" ] && { [ "$multipath_config" = "on" ] || [ "$mu
}
config_list_foreach $1 ip addpath
}
if [ "$(uci -q get glorytun-udp.vpn.enable)" = "1"]; then
if [ "$(uci -q get glorytun-udp.vpn.enable)" = "1" ]; then
config_load openmptcprouter
config_foreach glorytunudppath server
fi
Expand Down
14 changes: 14 additions & 0 deletions openmptcprouter-api/files/usr/libexec/rpcd/openmptcprouter
Original file line number Diff line number Diff line change
Expand Up @@ -1519,11 +1519,25 @@ function interfaces_status()
if serverip ~= "" then
local server_ping_test = sys.exec("ping -B -w 1 -c 1 -I " .. ifname .. " " .. serverip)
local server_ping_result = ut.trim(sys.exec("echo '" .. server_ping_test .. "' | grep '100% packet loss'"))
local server_ping_nobind = ut.trim(sys.exec("echo '" .. server_ping_test .. "' | grep 'Address not available'"))
if server_ping_result ~= "" then
server_ping = "DOWN"
if connectivity == "OK" then
connectivity = "WARNING"
end
elseif server_ping_nobind ~= "" then
server_ping_test = sys.exec("ping -w 1 -c 1 -I " .. ifname .. " " .. serverip)
server_ping_result = ut.trim(sys.exec("echo '" .. server_ping_test .. "' | grep '100% packet loss'"))
if server_ping_result ~= "" then
server_ping = "DOWN"
if connectivity == "OK" then
connectivity = "WARNING"
end
else
mArray.openmptcprouter["vps_status"] = "UP"
server_ping = "UP"
latency = ut.trim(sys.exec("echo '" .. server_ping_test .. "' | cut -d '/' -s -f5 | cut -d '.' -f1"))
end
else
mArray.openmptcprouter["vps_status"] = "UP"
server_ping = "UP"
Expand Down

0 comments on commit b3148f6

Please sign in to comment.