-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7d9e17
commit c446160
Showing
10 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/system/bin/sh | ||
export PATH=/data/adb/tailscale/scripts:$PATH | ||
tailscaled.tun "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/system/bin/sh | ||
DIR=${0%/*} | ||
source $DIR/../settings.ini | ||
scripts_name=$(basename $0) | ||
|
||
start_tun(){ | ||
PID=$(busybox pidof "${socks5_tun_bin}") | ||
if [ -n "$PID" ]; then | ||
log Info "✔ socks5-tunnel service already running with PID : ( $PID )." | ||
return | ||
fi | ||
# The logs time cannot set to current timezone, default is UTC. | ||
nohup ${socks5_tun_bin} ${socks5_tun_conf} > "${socks5_tun_log}" 2>&1 & | ||
PID=$! | ||
echo -n $PID > "${socks5_tun_pid}" | ||
log Info "✔ socks5-tunnel service running with PID : ( $PID )." | ||
sh ${socks5_tun_pre_up} | ||
} | ||
|
||
stop_tun(){ | ||
# Check if the binary is running using pgrep | ||
if busybox pgrep "${socks5_tun_bin}" >/dev/null; then | ||
sh ${socks5_tun_pre_down} | ||
# Use `busybox pkill` to kill the binary with signal 15, otherwise use `killall`. | ||
if busybox pkill -15 -e "${socks5_tun_bin}" >/dev/null 2>&1; then | ||
: # Do nothing if busybox pkill is successful | ||
else | ||
killall -15 "${socks5_tun_bin}" >/dev/null 2>&1 || kill -15 "$(busybox pidof "${socks5_tun_bin}")" >/dev/null 2>&1 | ||
fi | ||
else | ||
log Info "✘ socks5-tunnel service already stop." | ||
rm -f "${socks5_tun_pid}" | ||
[ -t 1 ] && echo -e "${white}--------------------------------------------${normal}" | ||
return | ||
fi | ||
# Check if the binary has stopped | ||
sleep 0.5 | ||
if ! busybox pidof "${socks5_tun_bin}" >/dev/null 2>&1; then | ||
# Delete the `socks5-tunnel.pid` file if it exists | ||
rm -f "${socks5_tun_pid}" | ||
log Info "✘ socks5-tunnel shutting down, service is stopped." | ||
log Info "✘ socks5-tunnel disconnected." | ||
[ -t 1 ] && echo -e "${white}--------------------------------------------${normal}" | ||
else | ||
log Warning "⚠️ socks5-tunnel Not stopped; may still be shutting down or failed to shut down." | ||
force_stop | ||
fi | ||
|
||
} | ||
force_stop() { | ||
# try forcing it to shut down. | ||
log Warning "⚠️ try forcing it to shut down." | ||
# Use `busybox pkill` to kill the binary with signal 9, otherwise use `killall`. | ||
if busybox pkill -9 "${socks5_tun_bin}"; then | ||
: # Do nothing if busybox pkill is successful | ||
else | ||
if command -v killall >/dev/null 2>&1; then | ||
killall -9 "${socks5_tun_bin}" >/dev/null 2>&1 || true | ||
else | ||
pkill -9 "${socks5_tun_bin}" >/dev/null 2>&1 || true | ||
fi | ||
fi | ||
sleep 0.5 | ||
if ! busybox pidof "${socks5_tun_bin}" >/dev/null 2>&1; then | ||
log Info "✔ done, you can sleep peacefully." | ||
[ -t 1 ] && echo -e "${white}--------------------------------------------${normal}" | ||
rm -f "${socks5_tun_pid}" | ||
fi | ||
} | ||
case "$1" in | ||
start) | ||
start_tun | ||
;; | ||
stop) | ||
stop_tun | ||
;; | ||
restart) | ||
stop_tun | ||
sleep 0.5 | ||
start_tun | ||
;; | ||
status) | ||
# Check whether the service is running or not | ||
PID=$(busybox pidof "${socks5_tun_bin}") | ||
if [ -n "$PID" ]; then | ||
log Info "✔ socks5-tunnel for tailscaled service is running with PID : ( $PID )." | ||
else | ||
log Info "✘ socks5-tunnel for tailscaled service is stopped." | ||
fi | ||
;; | ||
log) | ||
log_view $2 | ||
;; | ||
*) | ||
if [ -n "$1" ]; then | ||
echo "${red}${scripts_name} $1 not found${normal}" | ||
fi | ||
echo "${yellow}usage${normal}: ${green}${scripts_name}${normal} {${yellow}start|stop|restart|status${normal}}" | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
tunnel: | ||
# Interface name | ||
name: tailscale0 | ||
# Interface MTU | ||
mtu: 8500 | ||
# Multi-queue | ||
multi-queue: false | ||
# IPv4 address | ||
ipv4: 100.100.100.100 | ||
# IPv6 address | ||
ipv6: 'fc00::1' | ||
# Post up script | ||
#post-up-script: /data/adb/tailscale/scripts/tailscaled.tun.up | ||
# Pre down script | ||
#pre-down-script: /data/adb/tailscale/scripts/tailscaled.tun.down | ||
|
||
socks5: | ||
# Socks5 server port | ||
port: 1099 | ||
# Socks5 server address (ipv4/ipv6) | ||
address: 127.0.0.1 | ||
# Socks5 UDP relay mode (tcp|udp) | ||
udp: 'udp' | ||
# Socks5 handshake using pipeline mode | ||
# pipeline: false | ||
# Socks5 server username | ||
# username: 'username' | ||
# Socks5 server password | ||
# password: 'password' | ||
# Socket mark | ||
mark: 1099 | ||
|
||
misc: | ||
# task stack size (bytes) | ||
# task-stack-size: 20480 | ||
# connect timeout (ms) | ||
# connect-timeout: 5000 | ||
# read-write timeout (ms) | ||
# read-write-timeout: 60000 | ||
# stdout, stderr or file-path | ||
log-file: stdout | ||
# debug, info, warn or error | ||
log-level: debug | ||
# If present, run as a daemon with this pid file | ||
#pid-file: /data/adb/tailscale/run/hev-socks5-tunnel.pid | ||
# If present, set rlimit nofile; else use default value | ||
# limit-nofile: 65535 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/system/bin/sh | ||
DIR=${0%/*} | ||
source $DIR/../settings.ini | ||
|
||
ip rule del fwmark 1099 table 1099 | ||
ip rule del fwmark 1099 lookup 1099 | ||
ip route del default dev tailscale0 table 1099 | ||
iptables -t mangle -D OUTPUT -d 100.64.0.0/10 -j MARK --set-mark 1099 | ||
ip route del 100.64.0.0/10 dev tailscale0 | ||
log Info "✘ iptables route deleted" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/system/bin/sh | ||
DIR=${0%/*} | ||
source $DIR/../settings.ini | ||
|
||
# Add route | ||
ip route add 100.64.0.0/10 dev tailscale0 metric 1 | ||
|
||
# Set iptables rules to mark packets | ||
iptables -t mangle -A OUTPUT -d 100.64.0.0/10 -j MARK --set-mark 1099 | ||
|
||
# Add IP rule | ||
ip rule add fwmark 1099 table 1099 pref 18500 | ||
ip rule add fwmark 1099 lookup 1099 | ||
|
||
# Add default route for marked traffic | ||
ip route add default dev tailscale0 table 1099 metric 1 | ||
log Info "✔ iptables route added" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters