From 2860000112a0f653b6425b4f0b761175e2eadc15 Mon Sep 17 00:00:00 2001 From: CerteKim <18364439+CerteKim@users.noreply.github.com> Date: Thu, 7 Oct 2021 23:19:39 +0800 Subject: [PATCH] mege watch.service to xray.tproxy --- xray/etc/confs/base.json | 2 +- xray/etc/confs/dns.json | 1 + xray/scripts/watch.service | 69 -------------------------------------- xray/scripts/watch.sh | 2 +- xray/scripts/xray.tproxy | 54 +++++++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 71 deletions(-) delete mode 100755 xray/scripts/watch.service diff --git a/xray/etc/confs/base.json b/xray/etc/confs/base.json index 912be8a..a20cbb8 100755 --- a/xray/etc/confs/base.json +++ b/xray/etc/confs/base.json @@ -32,7 +32,7 @@ "tag": "direct", "protocol": "freedom", "settings": { - "domainStrategy": "UseIPv4" + "domainStrategy": "UseIP" } }, { diff --git a/xray/etc/confs/dns.json b/xray/etc/confs/dns.json index f66ea22..e69fbb1 100755 --- a/xray/etc/confs/dns.json +++ b/xray/etc/confs/dns.json @@ -14,6 +14,7 @@ { "address": "https+local://223.5.5.5/dns-query", "domains": [ + "geosite:cn", "geosite:geolocation-cn" ] }, diff --git a/xray/scripts/watch.service b/xray/scripts/watch.service deleted file mode 100755 index 995a9a7..0000000 --- a/xray/scripts/watch.service +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/sh -magisk_busybox="/data/adb/magisk/busybox" - -data_path="/data/adb/xray" -bin_name="watch.sh" -bin_path="${data_path}/scripts/${bin_name}" -run_path="${data_path}/run" -pid_file="${run_path}/${bin_name}.pid" -error_log="${run_path}/watch.error.log" - -probe_alive() { - [ -f ${pid_file} ] && cmd_file="/proc/`cat ${pid_file}`/cmdline" || return 1 - [ -f ${cmd_file} ] && grep -q ${bin_path} ${cmd_file} && return 0 || return 1 -} - -display_pid() { - if probe_alive ; then - echo "[Info]: ${bin_name} service is running. ( PID: `cat ${pid_file}` )" - return 0 - else - echo "[Info]: ${bin_name} service is stopped." - return 1 - fi -} - -start_service() { - if probe_alive ; then - echo "[Info]: ${bin_name} service is running. ( PID: `cat ${pid_file}` )" - else - echo "[Info]: Starting ${bin_name} service." - nohup ${bin_path} &>${error_log} & - echo -n $! > ${pid_file} - if probe_alive ; then - echo "[Warning]: ${bin_name} service is running ( PID: `cat ${pid_file}` )" - else - echo "[Error]: Start ${bin_name} service Failed." - rm -f ${pid_file} - fi - fi -} - -stop_service() { - if display_pid ; then - echo "[Info]: Stopping ${bin_name} service." - kill `cat ${pid_file}` - sleep 1 - display_pid - fi - rm -f ${pid_file} -} - -case "$1" in - start) - start_service - ;; - stop) - stop_service - ;; - restart) - stop_service - start_service - ;; - status) - display_pid - ;; - *) - echo "$0: usage: $0 {start|stop|restart|status}" - ;; -esac diff --git a/xray/scripts/watch.sh b/xray/scripts/watch.sh index 35b057f..2dc88c4 100755 --- a/xray/scripts/watch.sh +++ b/xray/scripts/watch.sh @@ -9,7 +9,7 @@ # check online ip # ip route get 1.2.3.4 | awk '{print $9}' -lastIP6="2001:da8::666" +lastIP6="::114:514:1919:810" bypass() { if [ "$isChanged" = true ]; then diff --git a/xray/scripts/xray.tproxy b/xray/scripts/xray.tproxy index b4e8605..7e9f21c 100755 --- a/xray/scripts/xray.tproxy +++ b/xray/scripts/xray.tproxy @@ -26,6 +26,58 @@ intranet6=(::/128 ::1/128 ::ffff:0:0/96 100::/64 64:ff9b::/96 2001::/32 2001:10: # 2900-2999 5000-5999 OEM; 10000+ APP; 99000-99999 ISOLATE; 100000 USER; 50000-59999 SHARED_GID AIDs=(1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 2001 2002 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 9997 9998 9999) + + +# watch +data_path="/data/adb/xray" +bin_name="watch.sh" +bin_path="${data_path}/scripts/${bin_name}" +run_path="${data_path}/run" +pid_file="${run_path}/${bin_name}.pid" +error_log="${run_path}/watch.error.log" + +probe_alive() { + [ -f ${pid_file} ] && cmd_file="/proc/`cat ${pid_file}`/cmdline" || return 1 + [ -f ${cmd_file} ] && grep -q ${bin_path} ${cmd_file} && return 0 || return 1 +} + +display_pid() { + if probe_alive ; then + echo "[Info]: ${bin_name} service is running. ( PID: `cat ${pid_file}` )" + return 0 + else + echo "[Info]: ${bin_name} service is stopped." + return 1 + fi +} + +start_service() { + if probe_alive ; then + echo "[Info]: ${bin_name} service is running. ( PID: `cat ${pid_file}` )" + else + echo "[Info]: Starting ${bin_name} service." + nohup ${bin_path} &>${error_log} & + echo -n $! > ${pid_file} + if probe_alive ; then + echo "[Warning]: ${bin_name} service is running ( PID: `cat ${pid_file}` )" + else + echo "[Error]: Start ${bin_name} service Failed." + rm -f ${pid_file} + fi + fi +} + +stop_service() { + if display_pid ; then + echo "[Info]: Stopping ${bin_name} service." + kill `cat ${pid_file}` + sleep 1 + display_pid + fi + rm -f ${pid_file} +} + + add_route() { ip rule add fwmark ${mark_id} table ${table_id} [ $proxy2_enable -eq 1 ] && ip rule add fwmark ${mark2_id} table ${table_id} @@ -261,6 +313,7 @@ disable_proxy() { if [ -f /data/adb/xray/ipv6 ] ; then echo "disable ipv6 proxy" iptables="ip6tables -w 100" + stop_service clean_mangle_iptables 2> /dev/null fi } @@ -280,6 +333,7 @@ enable_proxy() { echo "enable ipv6 proxy" iptables="ip6tables -w 100" create_mangle_iptables + start_service else disable_ipv6 fi