sing-box-manager/Install.sh

5032 lines
264 KiB
Bash
Raw Permalink Normal View History

2023-07-29 12:09:39 +08:00
#!/bin/bash
RED='\033[0;31m'
CYAN='\033[0;36m'
2023-07-29 15:12:16 +08:00
YELLOW='\033[0;33m'
2023-09-12 14:44:29 +08:00
NC='\033[0m'
2023-07-29 12:09:39 +08:00
2023-10-12 13:39:59 +08:00
disable_option=false
2023-11-12 17:47:06 +08:00
enable_ech=false
2023-10-09 11:28:46 +08:00
listen_port=""
override_port=""
ip_v4=""
ip_v6=""
2023-10-23 16:06:40 +08:00
record_content=""
record_type=""
record_name=""
2023-10-12 13:39:59 +08:00
obfs_password=""
domain=""
domain_name=""
2023-10-09 11:28:46 +08:00
up_mbps=""
down_mbps=""
2023-09-25 17:12:43 +08:00
certificate_path=""
private_key_path=""
2023-09-28 15:53:33 +08:00
public_key=""
private_key=""
2023-11-12 17:47:06 +08:00
multiplex_config=""
brutal_config=""
ech_key=()
ech_config=()
user_names=()
user_passwords=()
user_uuids=()
2024-01-02 02:21:44 +08:00
ss_passwords=()
2023-11-12 17:47:06 +08:00
stls_passwords=()
short_ids=()
2023-07-27 18:18:35 +08:00
function check_firewall_configuration() {
local os_name=$(uname -s)
local firewall
if [[ $os_name == "Linux" ]]; then
if command -v ufw >/dev/null 2>&1 && ufw status | grep -q "Status: active"; then
firewall="ufw"
2023-09-05 18:13:52 +08:00
elif command -v ip6tables >/dev/null 2>&1 && ip6tables -S | grep -q "INPUT -j DROP"; then
firewall="ip6tables"
2023-07-27 18:18:35 +08:00
elif command -v iptables >/dev/null 2>&1 && iptables -S | grep -q "INPUT -j DROP"; then
firewall="iptables"
2023-09-05 18:13:52 +08:00
elif systemctl is-active --quiet netfilter-persistent; then
firewall="iptables-persistent"
2023-09-06 11:31:49 +08:00
elif systemctl is-active --quiet iptables.service; then
2024-01-02 02:21:44 +08:00
firewall="iptables-service"
2023-07-27 18:18:35 +08:00
elif command -v firewalld >/dev/null 2>&1 && firewall-cmd --state | grep -q "running"; then
firewall="firewalld"
fi
fi
if [[ -z $firewall ]]; then
2023-08-25 11:56:25 +08:00
echo "No firewall configuration detected or firewall is not enabled, skipping firewall configuration."
2023-07-27 18:18:35 +08:00
return
fi
2023-08-25 11:56:25 +08:00
echo "Checking firewall configuration..."
2023-07-27 18:18:35 +08:00
case $firewall in
2024-01-02 02:21:44 +08:00
ufw)
if ! ufw status | grep -q "Status: active" 2>/dev/null; then
ufw enable >/dev/null 2>&1
fi
if ! ufw status | grep -q " $listen_port" 2>/dev/null; then
ufw allow "$listen_port" >/dev/null 2>&1
fi
2023-08-19 17:45:08 +08:00
2024-01-02 02:21:44 +08:00
if ! ufw status | grep -q " $override_port" 2>/dev/null; then
ufw allow "$override_port" >/dev/null 2>&1
fi
2023-08-19 17:45:08 +08:00
2024-01-02 02:21:44 +08:00
if ! ufw status | grep -q " $fallback_port" 2>/dev/null; then
ufw allow "$fallback_port" >/dev/null 2>&1
fi
2023-07-27 18:18:35 +08:00
2024-01-02 02:21:44 +08:00
if ! ufw status | grep -q " 80" 2>/dev/null; then
ufw allow 80 >/dev/null 2>&1
fi
echo "Firewall configuration has been updated."
;;
iptables | iptables-persistent | iptables-service)
if ! iptables -C INPUT -p tcp --dport "$listen_port" -j ACCEPT >/dev/null 2>&1; then
iptables -A INPUT -p tcp --dport "$listen_port" -j ACCEPT >/dev/null 2>&1
fi
2023-08-30 16:56:50 +08:00
2024-01-02 02:21:44 +08:00
if ! iptables -C INPUT -p udp --dport "$listen_port" -j ACCEPT >/dev/null 2>&1; then
iptables -A INPUT -p udp --dport "$listen_port" -j ACCEPT >/dev/null 2>&1
fi
2023-08-30 16:56:50 +08:00
2024-01-02 02:21:44 +08:00
if ! iptables -C INPUT -p tcp --dport "$override_port" -j ACCEPT >/dev/null 2>&1; then
iptables -A INPUT -p tcp --dport "$override_port" -j ACCEPT >/dev/null 2>&1
fi
2023-08-30 16:56:50 +08:00
2024-01-02 02:21:44 +08:00
if ! iptables -C INPUT -p udp --dport "$override_port" -j ACCEPT >/dev/null 2>&1; then
iptables -A INPUT -p udp --dport "$override_port" -j ACCEPT >/dev/null 2>&1
fi
2023-07-27 18:18:35 +08:00
2024-01-02 02:21:44 +08:00
if ! iptables -C INPUT -p tcp --dport "$fallback_port" -j ACCEPT >/dev/null 2>&1; then
iptables -A INPUT -p tcp --dport "$fallback_port" -j ACCEPT >/dev/null 2>&1
fi
2023-08-17 17:46:42 +08:00
2024-01-02 02:21:44 +08:00
if ! iptables -C INPUT -p udp --dport "$fallback_port" -j ACCEPT >/dev/null 2>&1; then
iptables -A INPUT -p udp --dport "$fallback_port" -j ACCEPT >/dev/null 2>&1
fi
2023-07-27 18:18:35 +08:00
2024-01-02 02:21:44 +08:00
if ! iptables -C INPUT -p tcp --dport 80 -j ACCEPT >/dev/null 2>&1; then
iptables -A INPUT -p tcp --dport 80 -j ACCEPT >/dev/null 2>&1
fi
2023-07-27 18:18:35 +08:00
2024-01-02 02:21:44 +08:00
if ! iptables -C INPUT -p udp --dport 80 -j ACCEPT >/dev/null 2>&1; then
iptables -A INPUT -p udp --dport 80 -j ACCEPT >/dev/null 2>&1
fi
2023-08-30 16:56:50 +08:00
2024-01-02 02:21:44 +08:00
if ! ip6tables -C INPUT -p tcp --dport "$listen_port" -j ACCEPT >/dev/null 2>&1; then
ip6tables -A INPUT -p tcp --dport "$listen_port" -j ACCEPT >/dev/null 2>&1
fi
2023-09-05 18:13:52 +08:00
2024-01-02 02:21:44 +08:00
if ! ip6tables -C INPUT -p udp --dport "$listen_port" -j ACCEPT >/dev/null 2>&1; then
ip6tables -A INPUT -p udp --dport "$listen_port" -j ACCEPT >/dev/null 2>&1
fi
2023-09-05 18:13:52 +08:00
2024-01-02 02:21:44 +08:00
if ! ip6tables -C INPUT -p tcp --dport "$override_port" -j ACCEPT >/dev/null 2>&1; then
ip6tables -A INPUT -p tcp --dport "$override_port" -j ACCEPT >/dev/null 2>&1
fi
2023-09-05 18:13:52 +08:00
2024-01-02 02:21:44 +08:00
if ! ip6tables -C INPUT -p udp --dport "$override_port" -j ACCEPT >/dev/null 2>&1; then
ip6tables -A INPUT -p udp --dport "$override_port" -j ACCEPT >/dev/null 2>&1
fi
2023-09-05 18:13:52 +08:00
2024-01-02 02:21:44 +08:00
if ! ip6tables -C INPUT -p tcp --dport "$fallback_port" -j ACCEPT >/dev/null 2>&1; then
ip6tables -A INPUT -p tcp --dport "$fallback_port" -j ACCEPT >/dev/null 2>&1
fi
2023-09-05 18:13:52 +08:00
2024-01-02 02:21:44 +08:00
if ! ip6tables -C INPUT -p udp --dport "$fallback_port" -j ACCEPT >/dev/null 2>&1; then
ip6tables -A INPUT -p udp --dport "$fallback_port" -j ACCEPT >/dev/null 2>&1
fi
2023-09-05 18:13:52 +08:00
2024-01-02 02:21:44 +08:00
if ! ip6tables -C INPUT -p tcp --dport 80 -j ACCEPT >/dev/null 2>&1; then
ip6tables -A INPUT -p tcp --dport 80 -j ACCEPT >/dev/null 2>&1
fi
2023-09-05 18:13:52 +08:00
2024-01-02 02:21:44 +08:00
if ! ip6tables -C INPUT -p udp --dport 80 -j ACCEPT >/dev/null 2>&1; then
ip6tables -A INPUT -p udp --dport 80 -j ACCEPT >/dev/null 2>&1
fi
2023-09-05 18:13:52 +08:00
2024-01-02 02:21:44 +08:00
if [[ -e /etc/iptables/rules.v4 ]]; then
iptables-save >/etc/iptables/rules.v4
elif [[ -e /etc/sysconfig/iptables ]]; then
iptables-save >/etc/sysconfig/iptables
fi
2023-09-06 11:31:49 +08:00
2024-01-02 02:21:44 +08:00
if [[ -e /etc/iptables/rules.v6 ]]; then
ip6tables-save >/etc/iptables/rules.v6
elif [[ -e /etc/sysconfig/ip6tables ]]; then
ip6tables-save >/etc/sysconfig/ip6tables
fi
echo "Firewall configuration has been updated."
;;
firewalld)
if ! firewall-cmd --zone=public --list-ports | grep -q "$listen_port/tcp" 2>/dev/null; then
firewall-cmd --zone=public --add-port="$listen_port/tcp" --permanent >/dev/null 2>&1
fi
2023-09-05 18:13:52 +08:00
2024-01-02 02:21:44 +08:00
if ! firewall-cmd --zone=public --list-ports | grep -q "$listen_port/udp" 2>/dev/null; then
firewall-cmd --zone=public --add-port="$listen_port/udp" --permanent >/dev/null 2>&1
fi
2023-09-05 18:13:52 +08:00
2024-01-02 02:21:44 +08:00
if ! firewall-cmd --zone=public --list-ports | grep -q "$override_port/tcp" 2>/dev/null; then
firewall-cmd --zone=public --add-port="$override_port/tcp" --permanent >/dev/null 2>&1
fi
2023-09-05 18:13:52 +08:00
2024-01-02 02:21:44 +08:00
if ! firewall-cmd --zone=public --list-ports | grep -q "$override_port/udp" 2>/dev/null; then
firewall-cmd --zone=public --add-port="$override_port/udp" --permanent >/dev/null 2>&1
fi
2023-09-05 18:13:52 +08:00
2024-01-02 02:21:44 +08:00
if ! firewall-cmd --zone=public --list-ports | grep -q "$fallback_port/tcp" 2>/dev/null; then
firewall-cmd --zone=public --add-port="$fallback_port/tcp" --permanent >/dev/null 2>&1
fi
2023-09-05 18:13:52 +08:00
2024-01-02 02:21:44 +08:00
if ! firewall-cmd --zone=public --list-ports | grep -q "$fallback_port/udp" 2>/dev/null; then
firewall-cmd --zone=public --add-port="$fallback_port/udp" --permanent >/dev/null 2>&1
fi
2023-09-05 18:13:52 +08:00
2024-01-02 02:21:44 +08:00
if ! firewall-cmd --zone=public --list-ports | grep -q "80/tcp" 2>/dev/null; then
firewall-cmd --zone=public --add-port=80/tcp --permanent >/dev/null 2>&1
fi
2023-09-05 18:13:52 +08:00
2024-01-02 02:21:44 +08:00
if ! firewall-cmd --zone=public --list-ports | grep -q "80/udp" 2>/dev/null; then
firewall-cmd --zone=public --add-port=80/udp --permanent >/dev/null 2>&1
fi
2023-09-05 18:13:52 +08:00
2024-01-02 02:21:44 +08:00
if ! firewall-cmd --zone=public --list-ports | grep -q "$listen_port/tcp" 2>/dev/null; then
firewall-cmd --zone=public --add-port="$listen_port/tcp" --permanent >/dev/null 2>&1
fi
2023-07-27 18:18:35 +08:00
2024-01-02 02:21:44 +08:00
if ! firewall-cmd --zone=public --list-ports | grep -q "$listen_port/udp" 2>/dev/null; then
firewall-cmd --zone=public --add-port="$listen_port/udp" --permanent >/dev/null 2>&1
fi
2023-07-27 18:18:35 +08:00
2024-01-02 02:21:44 +08:00
if ! firewall-cmd --zone=public --list-ports | grep -q "$override_port/tcp" 2>/dev/null; then
firewall-cmd --zone=public --add-port="$override_port/tcp" --permanent >/dev/null 2>&1
fi
2023-08-30 16:56:50 +08:00
2024-01-02 02:21:44 +08:00
if ! firewall-cmd --zone=public --list-ports | grep -q "$override_port/udp" 2>/dev/null; then
firewall-cmd --zone=public --add-port="$override_port/udp" --permanent >/dev/null 2>&1
fi
2023-08-30 16:56:50 +08:00
2024-01-02 02:21:44 +08:00
if ! firewall-cmd --zone=public --list-ports | grep -q "$fallback_port/tcp" 2>/dev/null; then
firewall-cmd --zone=public --add-port="$fallback_port/tcp" --permanent >/dev/null 2>&1
fi
2023-08-30 16:56:50 +08:00
2024-01-02 02:21:44 +08:00
if ! firewall-cmd --zone=public --list-ports | grep -q "$fallback_port/udp" 2>/dev/null; then
firewall-cmd --zone=public --add-port="$fallback_port/udp" --permanent >/dev/null 2>&1
fi
2023-08-30 16:56:50 +08:00
2024-01-02 02:21:44 +08:00
if ! firewall-cmd --zone=public --list-ports | grep -q "80/tcp" 2>/dev/null; then
firewall-cmd --zone=public --add-port=80/tcp --permanent >/dev/null 2>&1
fi
2023-08-30 16:56:50 +08:00
2024-01-02 02:21:44 +08:00
if ! firewall-cmd --zone=public --list-ports | grep -q "80/udp" 2>/dev/null; then
firewall-cmd --zone=public --add-port=80/udp --permanent >/dev/null 2>&1
fi
firewall-cmd --reload
echo "Firewall configuration has been updated."
;;
2023-07-27 18:18:35 +08:00
esac
}
2023-11-12 17:47:06 +08:00
function create_sing_box_folders() {
local folders=("/usr/local/etc/sing-box" "/etc/ssl/private")
for folder in "${folders[@]}"; do
if [[ ! -d "$folder" ]]; then
mkdir -p "$folder"
[ "$folder" = "/usr/local/etc/sing-box" ] && touch "$folder/config.json"
fi
done
2023-07-29 12:09:39 +08:00
}
2023-08-30 16:56:50 +08:00
function create_juicity_folder() {
2023-11-12 17:47:06 +08:00
local folders=("/usr/local/etc/juicity" "/etc/ssl/private")
for folder in "${folders[@]}"; do
if [[ ! -d "$folder" ]]; then
mkdir -p "$folder"
[ "$folder" = "/usr/local/etc/juicity" ] && touch "$folder/config.json"
fi
done
2023-08-25 18:01:25 +08:00
}
2023-09-24 10:05:14 +08:00
function ensure_clash_yaml() {
2023-11-12 17:47:06 +08:00
local clash_yaml="/usr/local/etc/sing-box/clash.yaml"
if [ ! -e "$clash_yaml" ]; then
touch "$clash_yaml"
2023-09-24 10:05:14 +08:00
fi
}
2023-08-30 16:56:50 +08:00
function check_config_file_existence() {
local config_file="/usr/local/etc/sing-box/config.json"
if [ ! -f "$config_file" ]; then
2024-01-02 02:21:44 +08:00
echo -e "${RED}sing-box config file does not exist, please build node first!${NC}"
exit 1
2023-08-30 16:56:50 +08:00
fi
}
2023-09-18 14:34:32 +08:00
function generate_naive_random_filename() {
local dir="/usr/local/etc/sing-box"
2024-01-02 02:21:44 +08:00
local filename=""
2023-09-18 14:34:32 +08:00
while true; do
2024-01-02 02:21:44 +08:00
random_value=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 5 | head -n 1)
filename="naive_client_${random_value}.json"
2023-09-18 14:34:32 +08:00
if [ ! -e "${dir}/${filename}" ]; then
touch "${dir}/${filename}"
naive_client_filename="${dir}/${filename}"
break
fi
done
}
2023-11-12 17:47:06 +08:00
function get_temp_config_file() {
temp_file=$(mktemp)
2024-01-02 02:21:44 +08:00
curl -sSL "https://api.zeroteam.top/warp?format=sing-box" >"$temp_file"
2023-09-03 12:22:11 +08:00
}
function install_sing_box() {
2023-11-12 17:47:06 +08:00
if [[ -f "/usr/local/bin/sing-box" && -f "/usr/local/etc/sing-box/config.json" ]]; then
return 1
else
get_local_ip
2024-01-22 03:11:19 +08:00
configure_dns64
2024-01-22 03:07:45 +08:00
select_sing_box_install_option
2023-09-03 12:22:11 +08:00
configure_sing_box_service
2023-11-12 17:47:06 +08:00
create_sing_box_folders
fi
}
function configure_dns64() {
if [[ -n $ip_v4 ]]; then
return
fi
if [[ -n $ip_v6 ]]; then
echo "Check that the machine is IPv6 single-stack network, configure DNS64..."
2024-01-02 02:21:44 +08:00
sed -i '/^nameserver /s/^/#/' /etc/resolv.conf
echo "nameserver 2001:67c:2b0::4" >>/etc/resolv.conf
echo "nameserver 2001:67c:2b0::6" >>/etc/resolv.conf
2023-11-12 17:47:06 +08:00
echo "DNS64 configuration is complete."
fi
2023-09-03 12:22:11 +08:00
}
2023-07-29 14:54:19 +08:00
function enable_bbr() {
2023-10-12 13:39:59 +08:00
if grep -q "net.core.default_qdisc=fq" /etc/sysctl.conf; then
echo "BBR is already enabled, skipping configuration."
return
fi
2023-10-09 11:28:46 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Whether to enable BBR (Y/N, default N)? " -i "N" response
2023-11-12 17:47:06 +08:00
response=${response:-"N"}
2023-10-09 11:28:46 +08:00
if [[ $response == "y" || $response == "Y" ]]; then
2023-10-12 13:39:59 +08:00
echo "Enable BBR..."
2024-01-02 02:21:44 +08:00
echo "net.core.default_qdisc=fq" >>/etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >>/etc/sysctl.conf
sysctl -p >/dev/null
2023-10-12 13:39:59 +08:00
echo "BBR has been enabled"
2023-10-09 11:28:46 +08:00
break
elif [[ $response == "n" || $response == "N" ]]; then
echo "BBR will not be enabled."
break
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid input, please re-enter!${NC}"
2023-10-09 11:28:46 +08:00
fi
done
2023-07-27 18:18:35 +08:00
}
function select_sing_box_install_option() {
while true; do
2024-01-02 02:21:44 +08:00
echo "Please select sing-box installation method (default 1):"
echo "1). Download and install sing-box (Latest version)"
echo "2). Download and install sing-box (Beta version)"
echo "3). Compile and install sing-box (full featured version)"
read -p "Please select [1-3]: " install_option
2024-01-22 02:46:26 +08:00
install_option="${install_option:-1}"
2023-07-27 18:18:35 +08:00
case $install_option in
2024-01-02 02:21:44 +08:00
1)
install_latest_sing_box
break
;;
2)
install_Pre_release_sing_box
break
;;
3)
install_go
compile_install_sing_box
break
;;
*)
echo -e "${RED}Invalid selection, please re-enter!${NC}"
;;
2023-07-27 18:18:35 +08:00
esac
done
}
2023-07-29 14:54:19 +08:00
function install_go() {
2024-01-02 02:21:44 +08:00
if ! command -v go &>/dev/null; then
2023-08-25 11:56:25 +08:00
echo "Downloading Go..."
2023-07-27 18:18:35 +08:00
local go_arch
case $(uname -m) in
2024-01-02 02:21:44 +08:00
x86_64)
go_arch="amd64"
;;
i686)
go_arch="386"
;;
aarch64)
go_arch="arm64"
;;
armv6l)
go_arch="armv6"
;;
*)
echo -e "${RED}unsupported architecture: $(uname -m)${NC}"
exit 1
;;
2023-07-27 18:18:35 +08:00
esac
local go_version
2023-08-19 17:45:08 +08:00
go_version=$(curl -sL "https://golang.org/VERSION?m=text" | grep -o 'go[0-9]\+\.[0-9]\+\.[0-9]\+')
local go_download_url="https://go.dev/dl/$go_version.linux-$go_arch.tar.gz"
2023-08-10 17:30:49 +08:00
wget -qO- "$go_download_url" | tar -xz -C /usr/local
2024-01-02 02:21:44 +08:00
echo 'export PATH=$PATH:/usr/local/go/bin' | tee -a /etc/profile >/dev/null
2023-07-27 18:18:35 +08:00
source /etc/profile
go version
2023-08-25 11:56:25 +08:00
echo "Go has been installed."
2023-07-27 18:18:35 +08:00
else
2023-08-25 11:56:25 +08:00
echo "Go is already installed, skipping installation."
2023-07-27 18:18:35 +08:00
fi
}
function compile_install_sing_box() {
local go_install_command="go install -v -tags \
with_quic,\
with_grpc,\
with_dhcp,\
with_wireguard,\
with_shadowsocksr,\
with_ech,\
with_utls,\
with_reality_server,\
with_acme,\
with_clash_api,\
with_v2ray_api,\
with_gvisor,\
with_lwip \
github.com/sagernet/sing-box/cmd/sing-box@latest"
2023-08-25 11:56:25 +08:00
echo "Compiling and installing sing-box, please wait..."
2023-07-27 18:18:35 +08:00
$go_install_command
if [[ $? -eq 0 ]]; then
mv ~/go/bin/sing-box /usr/local/bin/
chmod +x /usr/local/bin/sing-box
2023-08-25 11:56:25 +08:00
echo "sing-box has been compiled and installed successfully."
2023-07-27 18:18:35 +08:00
else
2023-08-25 11:56:25 +08:00
echo -e "${RED}sing-box compilation and installation failed.${NC}"
2023-07-27 18:18:35 +08:00
exit 1
fi
}
function install_latest_sing_box() {
local arch=$(uname -m)
local url="https://api.github.com/repos/SagerNet/sing-box/releases/latest"
local download_url
case $arch in
2024-01-02 02:21:44 +08:00
x86_64 | amd64)
download_url=$(curl -s $url | grep -o "https://github.com[^\"']*linux-amd64.tar.gz")
;;
armv7l)
download_url=$(curl -s $url | grep -o "https://github.com[^\"']*linux-armv7.tar.gz")
;;
aarch64 | arm64)
download_url=$(curl -s $url | grep -o "https://github.com[^\"']*linux-arm64.tar.gz")
;;
amd64v3)
download_url=$(curl -s $url | grep -o "https://github.com[^\"']*linux-amd64v3.tar.gz")
;;
s390x)
download_url=$(curl -s $url | grep -o "https://github.com[^\"']*linux-s390x.tar.gz")
;;
*)
echo -e "${RED}Unsupported architecture: $arch${NC}"
return 1
;;
2023-07-27 18:18:35 +08:00
esac
if [ -n "$download_url" ]; then
2023-08-25 11:56:25 +08:00
echo "Downloading Sing-Box..."
2023-08-10 17:30:49 +08:00
wget -qO sing-box.tar.gz "$download_url" 2>&1 >/dev/null
2023-07-27 18:18:35 +08:00
tar -xzf sing-box.tar.gz -C /usr/local/bin --strip-components=1
rm sing-box.tar.gz
chmod +x /usr/local/bin/sing-box
2023-08-25 11:56:25 +08:00
echo "Sing-Box installed successfully."
2023-07-27 18:18:35 +08:00
else
2023-08-25 11:56:25 +08:00
echo -e "${RED}Unable to retrieve the download URL for Sing-Box.${NC}"
2023-07-27 18:18:35 +08:00
return 1
fi
}
2023-09-04 11:22:03 +08:00
function install_Pre_release_sing_box() {
local arch=$(uname -m)
local url="https://api.github.com/repos/SagerNet/sing-box/releases"
local download_url
case $arch in
2024-01-02 02:21:44 +08:00
x86_64 | amd64)
download_url=$(curl -s "$url" | jq -r '.[] | select(.prerelease == true) | .assets[] | select(.browser_download_url | contains("linux-amd64.tar.gz")) | .browser_download_url' | head -n 1)
;;
armv7l)
download_url=$(curl -s "$url" | jq -r '.[] | select(.prerelease == true) | .assets[] | select(.browser_download_url | contains("linux-armv7.tar.gz")) | .browser_download_url' | head -n 1)
;;
aarch64 | arm64)
download_url=$(curl -s "$url" | jq -r '.[] | select(.prerelease == true) | .assets[] | select(.browser_download_url | contains("linux-arm64.tar.gz")) | .browser_download_url' | head -n 1)
;;
amd64v3)
download_url=$(curl -s "$url" | jq -r '.[] | select(.prerelease == true) | .assets[] | select(.browser_download_url | contains("linux-amd64v3.tar.gz")) | .browser_download_url' | head -n 1)
;;
s390x)
download_url=$(curl -s "$url" | jq -r '.[] | select(.prerelease == true) | .assets[] | select(.browser_download_url | contains("linux-s390x.tar.gz")) | .browser_download_url' | head -n 1)
;;
*)
echo -e "${RED}Unsupported architecture: $arch${NC}"
return 1
;;
2023-09-04 11:22:03 +08:00
esac
if [ -n "$download_url" ]; then
echo "Downloading Sing-Box..."
wget -qO sing-box.tar.gz "$download_url" 2>&1 >/dev/null
tar -xzf sing-box.tar.gz -C /usr/local/bin --strip-components=1
rm sing-box.tar.gz
chmod +x /usr/local/bin/sing-box
echo "Sing-Box installed successfully."
else
echo -e "${RED}Unable to get pre-release download link for Sing-Box.${NC}"
return 1
fi
}
2023-08-30 16:56:50 +08:00
function install_latest_juicity() {
2023-08-25 18:01:25 +08:00
local arch=$(uname -m)
case $arch in
2024-01-02 02:21:44 +08:00
"arm64")
arch_suffix="arm64"
;;
"armv5")
arch_suffix="armv5"
;;
"armv6")
arch_suffix="armv6"
;;
"armv7")
arch_suffix="armv7"
;;
"mips")
arch_suffix="mips32"
;;
"mipsel")
arch_suffix="mips32le"
;;
"mips64")
arch_suffix="mips64"
;;
"mips64el")
arch_suffix="mips64le"
;;
"riscv64")
arch_suffix="riscv64"
;;
"i686")
arch_suffix="x86_32"
;;
"x86_64")
if [ -n "$(grep avx2 /proc/cpuinfo)" ]; then
arch_suffix="x86_64_v3_avx2"
else
arch_suffix="x86_64_v2_sse"
fi
;;
*)
echo "Unsupported architecture: $arch"
return 1
;;
2023-08-25 18:01:25 +08:00
esac
local github_api_url="https://api.github.com/repos/juicity/juicity/releases/latest"
local download_url=$(curl -s "$github_api_url" | grep "browser_download_url.*$arch_suffix.zip\"" | cut -d '"' -f 4)
local temp_dir=$(mktemp -d)
local install_path="/usr/local/bin/juicity-server"
echo "Downloading the latest version of juicity-server..."
wget -P "$temp_dir" "$download_url" >/dev/null 2>&1
2024-01-02 02:21:44 +08:00
unzip "$temp_dir/*.zip" -d "$temp_dir" >/dev/null 2>&1
2023-08-25 18:01:25 +08:00
mv "$temp_dir/juicity-server" "$install_path" >/dev/null 2>&1
chmod +x /usr/local/bin/juicity-server
2024-01-02 02:21:44 +08:00
echo "juicity-server has been downloaded."
2023-08-25 18:01:25 +08:00
rm -rf "$temp_dir"
}
2023-07-27 18:18:35 +08:00
function configure_sing_box_service() {
2023-08-25 11:56:25 +08:00
echo "Configuring sing-box startup service..."
2023-07-27 18:18:35 +08:00
local service_file="/etc/systemd/system/sing-box.service"
if [[ -f $service_file ]]; then
rm "$service_file"
fi
2024-01-02 02:21:44 +08:00
local service_config="[Unit]
2023-07-27 18:18:35 +08:00
Description=sing-box service
Documentation=https://sing-box.sagernet.org
After=network.target nss-lookup.target
[Service]
2023-08-10 17:30:49 +08:00
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
2023-07-27 18:18:35 +08:00
ExecStart=/usr/local/bin/sing-box run -c /usr/local/etc/sing-box/config.json
2023-08-10 17:30:49 +08:00
ExecReload=/bin/kill -HUP $MAINPID
2023-07-27 18:18:35 +08:00
Restart=on-failure
2023-08-10 17:30:49 +08:00
RestartSec=10s
2023-07-27 18:18:35 +08:00
LimitNOFILE=infinity
[Install]
2024-01-02 02:21:44 +08:00
WantedBy=multi-user.target"
2023-11-12 17:47:06 +08:00
echo "$service_config" >"$service_file"
echo "sing-box startup service has been configured."
2023-07-27 18:18:35 +08:00
}
2023-08-25 18:01:25 +08:00
function configure_juicity_service() {
echo "Configuring juicity startup service..."
local service_file="/etc/systemd/system/juicity.service"
if [[ -f $service_file ]]; then
rm "$service_file"
fi
2024-01-02 02:21:44 +08:00
local service_config="[Unit]
2023-08-25 18:01:25 +08:00
Description=juicity-server Service
Documentation=https://github.com/juicity/juicity
After=network.target nss-lookup.target
[Service]
Type=simple
User=root
Environment=QUIC_GO_ENABLE_GSO=true
ExecStart=/usr/local/bin/juicity-server run -c /usr/local/etc/juicity/config.json --disable-timestamp
Restart=on-failure
LimitNPROC=512
LimitNOFILE=infinity
[Install]
2024-01-02 02:21:44 +08:00
WantedBy=multi-user.target"
2023-11-12 17:47:06 +08:00
echo "$service_config" >"$service_file"
echo "juicity startup service has been configured."
2023-08-25 18:01:25 +08:00
}
2023-10-09 11:28:46 +08:00
function set_listen_port() {
2023-07-29 12:09:39 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter the listening port (default 443): " new_listen_port
2023-10-09 11:28:46 +08:00
new_listen_port=${new_listen_port:-443}
if [[ $new_listen_port =~ ^[1-9][0-9]{0,4}$ && $new_listen_port -le 65535 ]]; then
2023-11-14 09:49:28 +08:00
check_result=$(netstat -tulpn | grep -E "\b${new_listen_port}\b")
if [ -z "$check_result" ]; then
2024-01-02 02:21:44 +08:00
echo "Listening Port: $new_listen_port"
2023-11-14 09:49:28 +08:00
break
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Error: Port is already in use. Please select another port!${NC}" >&2
2023-11-14 09:49:28 +08:00
fi
2023-08-19 17:45:08 +08:00
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Error: Port range is 1-65535. Please re-enter!${NC}" >&2
2023-08-19 17:45:08 +08:00
fi
2023-11-03 17:20:00 +08:00
done
listen_port="$new_listen_port"
2023-08-30 16:56:50 +08:00
}
2024-01-02 02:21:44 +08:00
function set_user_name() {
2023-10-09 11:28:46 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter username (default randomly generated): " new_user_name
2023-10-09 11:28:46 +08:00
if [[ -z "$new_user_name" ]]; then
2024-01-02 02:21:44 +08:00
new_user_name=$(sing-box generate rand --base64 6 2>/dev/null || openssl rand -base64 5)
echo "Username: $new_user_name"
2023-10-09 11:28:46 +08:00
break
elif [[ ! -z "$new_user_name" ]]; then
break
fi
2024-01-02 02:21:44 +08:00
done
user_names+=("$new_user_name")
2023-08-30 16:56:50 +08:00
}
2024-01-02 02:21:44 +08:00
function set_user_password() {
2023-08-30 16:56:50 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter password (default randomly generated): " new_user_password
2023-10-09 11:28:46 +08:00
if [[ -z "$new_user_password" ]]; then
new_user_password=$(sing-box generate rand --base64 9 2>/dev/null || openssl rand -base64 9)
2024-01-02 02:21:44 +08:00
echo "Password: $new_user_password"
2023-10-09 11:28:46 +08:00
break
elif [[ ! -z "$new_user_password" ]]; then
2023-08-30 16:56:50 +08:00
break
fi
done
2024-01-02 02:21:44 +08:00
user_passwords+=("$new_user_password")
2023-08-30 16:56:50 +08:00
}
2023-10-09 11:28:46 +08:00
function set_ss_password() {
2023-08-30 16:56:50 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter Shadowsocks password (default randomly generated): " ss_user_password
2023-10-09 11:28:46 +08:00
if [[ -z $ss_user_password ]]; then
if [[ $encryption_choice == 1 || $encryption_choice == 2 ]]; then
ss_password=$(sing-box generate rand --base64 32)
2024-01-02 02:21:44 +08:00
echo "Shadowsocks Password: $ss_password"
2023-10-09 11:28:46 +08:00
else
ss_password=$(sing-box generate rand --base64 16)
2024-01-02 02:21:44 +08:00
echo "Shadowsocks Password: $ss_password"
2023-10-09 11:28:46 +08:00
fi
ss_passwords+=("$ss_password")
break
elif [[ $encryption_choice == 1 || $encryption_choice == 2 ]] && [[ ${#ss_user_password} -eq 32 ]]; then
ss_password="$ss_user_password"
2024-01-02 02:21:44 +08:00
echo "Shadowsocks Password: $ss_password"
2023-10-09 11:28:46 +08:00
ss_passwords+=("$ss_password")
break
elif [[ $encryption_choice != 1 && $encryption_choice != 2 ]] && [[ ${#ss_user_password} -eq 16 ]]; then
ss_password="$ss_user_password"
2024-01-02 02:21:44 +08:00
echo "Shadowsocks Password: $ss_password"
2023-10-09 11:28:46 +08:00
ss_passwords+=("$ss_password")
2023-08-30 16:56:50 +08:00
break
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Error: Password length does not meet requirements. Please re-enter!${NC}"
2023-08-30 16:56:50 +08:00
fi
done
}
2023-10-09 11:28:46 +08:00
function set_stls_password() {
2023-08-30 16:56:50 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter ShadowTLS password (default randomly generated): " stls_user_password
2023-10-09 11:28:46 +08:00
if [[ -z $stls_user_password ]]; then
if [[ $encryption_choice == 1 || $encryption_choice == 2 ]]; then
stls_password=$(sing-box generate rand --base64 32)
2024-01-02 02:21:44 +08:00
echo "ShadowTLS Password: $stls_password"
2023-08-30 16:56:50 +08:00
else
2023-10-09 11:28:46 +08:00
stls_password=$(sing-box generate rand --base64 16)
2024-01-02 02:21:44 +08:00
echo "ShadowTLS Password: $stls_password"
2023-08-30 16:56:50 +08:00
fi
2023-10-09 11:28:46 +08:00
stls_passwords+=("$stls_password")
break
elif [[ $encryption_choice == 1 || $encryption_choice == 2 ]] && [[ ${#stls_user_password} -eq 32 ]]; then
stls_password="$stls_user_password"
2024-01-02 02:21:44 +08:00
echo "ShadowTLS Password: $stls_password"
2023-10-09 11:28:46 +08:00
stls_passwords+=("$stls_password")
break
elif [[ $encryption_choice != 1 && $encryption_choice != 2 ]] && [[ ${#stls_user_password} -eq 16 ]]; then
stls_password="$stls_user_password"
2024-01-02 02:21:44 +08:00
echo "ShadowTLS Password: $stls_password"
2023-10-09 11:28:46 +08:00
stls_passwords+=("$stls_password")
2023-08-30 16:56:50 +08:00
break
2023-10-09 11:28:46 +08:00
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Error: Password length does not meet requirements. Please re-enter!${NC}"
2023-08-30 16:56:50 +08:00
fi
done
}
2024-01-02 02:21:44 +08:00
function set_up_speed() {
2023-08-30 16:56:50 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter upload speed (default 50): " new_up_mbps
2023-10-12 20:30:16 +08:00
new_up_mbps=${new_up_mbps:-50}
2024-01-02 02:21:44 +08:00
if [[ $new_up_mbps =~ ^[0-9]+$ ]]; then
echo "Upload Speed: $new_up_mbps Mbps"
2023-10-09 11:28:46 +08:00
break
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Error: Please enter a number as upload speed!${NC}"
2023-10-09 11:28:46 +08:00
fi
done
up_mbps="$new_up_mbps"
}
2023-08-30 16:56:50 +08:00
2023-10-09 11:28:46 +08:00
function set_down_speed() {
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter download speed (default 100): " new_down_mbps
2023-10-09 11:28:46 +08:00
new_down_mbps=${new_down_mbps:-100}
2024-01-02 02:21:44 +08:00
if [[ $new_down_mbps =~ ^[0-9]+$ ]]; then
echo "Download Speed: $new_down_mbps Mbps"
2023-08-30 16:56:50 +08:00
break
2023-10-09 11:28:46 +08:00
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Error: Please enter a number as download speed!${NC}"
2023-10-09 11:28:46 +08:00
fi
done
down_mbps="$new_down_mbps"
}
function set_uuid() {
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter UUID (default randomly generated): " new_user_uuid
2023-10-09 11:28:46 +08:00
if [ -z "$new_user_uuid" ]; then
new_user_uuid=$(sing-box generate uuid 2>/dev/null || openssl rand -hex 16 | awk '{print substr($1,1,8) "-" substr($1,9,4) "-" substr($1,13,4) "-" substr($1,17,4) "-" substr($1,21)}')
fi
2024-01-02 02:21:44 +08:00
if [[ $new_user_uuid =~ ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$ ]]; then
echo "UUID: $new_user_uuid"
2023-08-30 16:56:50 +08:00
break
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid UUID format, please re-enter!${NC}"
2023-08-30 16:56:50 +08:00
fi
done
2023-10-09 11:28:46 +08:00
user_uuids+=("$new_user_uuid")
2023-08-30 16:56:50 +08:00
}
2023-10-09 11:28:46 +08:00
function set_override_port() {
2023-08-19 17:45:08 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter target port (default 443): " new_override_port
2023-10-09 11:28:46 +08:00
new_override_port=${new_override_port:-443}
2024-01-02 02:21:44 +08:00
if [[ $new_override_port =~ ^[1-9][0-9]{0,4}$ && $new_override_port -le 65535 ]]; then
echo "Target Port: $new_override_port"
2023-07-27 18:18:35 +08:00
break
2023-07-29 12:09:39 +08:00
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Error: Port range should be 1-65535, please re-enter!${NC}"
2023-07-29 15:12:16 +08:00
fi
done
2023-10-09 11:28:46 +08:00
override_port="$new_override_port"
2023-07-29 15:12:16 +08:00
}
2023-09-05 18:13:52 +08:00
function generate_unique_tag() {
local config_file="/usr/local/etc/sing-box/config.json"
while true; do
random_tag=$(head /dev/urandom | tr -dc 'a-z0-9' | fold -w 8 | head -n 1)
tag_label="${random_tag}-in"
if ! grep -qE "\"tag\":\\s*\"$tag_label\"(,|$)" "$config_file"; then
break
fi
done
}
2023-10-09 11:28:46 +08:00
function set_override_address() {
2024-01-02 02:21:44 +08:00
while true; do
read -p "Please enter target address (IP or domain name): " target_address
if [[ -z "$target_address" ]]; then
echo -e "${RED}Error: Target address cannot be empty!${NC}"
continue
fi
if ([[ $target_address =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]] && [[ $(grep -o '\.' <<<"$target_address" | wc -l) -eq 3 ]]) || ([[ $target_address =~ ^[a-fA-F0-9:]+$ ]] && [[ $(grep -o ':' <<<"$target_address" | wc -l) -ge 2 ]]); then
break
else
resolved_ips=$(host -t A "$target_address" | awk '/has address/ { print $4 }')
2023-08-30 16:56:50 +08:00
2024-01-02 02:21:44 +08:00
if [[ -n "$resolved_ips" ]] && ([[ "$resolved_ips" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]] || [[ "$resolved_ips" =~ ^[a-fA-F0-9:]+$ ]]); then
break
else
echo -e "${RED}Error: Please enter a valid IP address or domain name!${NC}"
fi
fi
done
2023-07-27 18:18:35 +08:00
}
2023-10-09 11:28:46 +08:00
function set_server_name() {
2023-07-29 12:09:39 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter a list of available ServerNames (default is nijigen-works.jp): " user_input
2023-08-30 16:56:50 +08:00
if [[ -z "$user_input" ]]; then
2023-08-31 17:34:24 +08:00
server_name="nijigen-works.jp"
2024-01-02 02:21:44 +08:00
echo "ServerName: $server_name"
2023-08-30 16:56:50 +08:00
break
else
server_name="$user_input"
2024-01-02 02:21:44 +08:00
echo "ServerName: $server_name"
2023-08-30 16:56:50 +08:00
echo "Verifying server's TLS version support..."
if command -v openssl >/dev/null 2>&1; then
local openssl_output=$(timeout 10s openssl s_client -connect "$server_name:443" -tls1_3 2>&1)
2024-01-02 02:21:44 +08:00
if [[ $openssl_output == *"TLS_AES_256_GCM_SHA384"* ||
$openssl_output == *"TLS_AES_128_GCM_SHA256"* ||
$openssl_output == *"TLS_CHACHA20_POLY1305_SHA256"* ||
$openssl_output == *"TLS_AES_128_CCM_SHA256"* ||
$openssl_output == *"TLS_AES_128_CCM_8_SHA256"* ]]; then
2023-08-30 16:56:50 +08:00
break
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}This website does not support TLS 1.3, please re-enter!${NC}"
2023-08-30 16:56:50 +08:00
fi
else
echo "OpenSSL is not installed, cannot verify TLS support."
break
fi
fi
done
}
2023-10-09 11:28:46 +08:00
function set_target_server() {
2023-08-30 16:56:50 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter target website address (default is nijigen-works.jp): " user_input
2023-08-30 16:56:50 +08:00
if [[ -z "$user_input" ]]; then
2023-08-31 17:34:24 +08:00
target_server="nijigen-works.jp"
2024-01-02 02:21:44 +08:00
echo "Target Website: $target_server"
2023-08-30 16:56:50 +08:00
break
else
target_server="$user_input"
2024-01-02 02:21:44 +08:00
echo "Target Website: $target_server"
2023-08-30 16:56:50 +08:00
echo "Verifying server's TLS version support..."
if command -v openssl >/dev/null 2>&1; then
local openssl_output=$(timeout 10s openssl s_client -connect "$target_server:443" -tls1_3 2>&1)
2024-01-02 02:21:44 +08:00
if [[ $openssl_output == *"TLS_AES_256_GCM_SHA384"* ||
$openssl_output == *"TLS_AES_128_GCM_SHA256"* ||
$openssl_output == *"TLS_CHACHA20_POLY1305_SHA256"* ||
$openssl_output == *"TLS_AES_128_CCM_SHA256"* ||
$openssl_output == *"TLS_AES_128_CCM_8_SHA256"* ]]; then
2023-08-30 16:56:50 +08:00
break
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}This target website address does not support TLS 1.3, please re-enter!${NC}"
2023-08-30 16:56:50 +08:00
fi
else
echo "OpenSSL is not installed, cannot verify TLS support."
break
fi
fi
done
}
2023-09-05 14:25:56 +08:00
function get_local_ip() {
local local_ip_v4
local local_ip_v6
2024-01-22 03:16:44 +08:00
local_ip_v4=$(wget -qO- --no-check-certificate --user-agent=Mozilla --tries=2 --timeout=1 https://v4.ident.me)
2023-10-09 11:28:46 +08:00
ip_v4="$local_ip_v4"
2024-01-22 03:27:22 +08:00
2024-01-22 03:16:44 +08:00
local_ip_v6=$(wget -qO- --no-check-certificate --user-agent=Mozilla --tries=2 --timeout=1 https://v6.ident.me)
2023-10-09 11:28:46 +08:00
ip_v6="$local_ip_v6"
2024-01-22 03:27:22 +08:00
2023-11-01 09:59:34 +08:00
if [[ -z "$ip_v4" && -z "$ip_v6" ]]; then
2024-01-02 02:21:44 +08:00
echo -e "${RED}Unable to retrieve local IP address!${NC}"
2023-09-05 14:25:56 +08:00
fi
}
2023-11-12 17:47:06 +08:00
function get_ech_keys() {
local input_file="/etc/ssl/private/ech.tmp"
local output_file="/etc/ssl/private/ech.pem"
2024-01-02 02:21:44 +08:00
sing-box generate ech-keypair [--pq-signature-schemes-enabled] >"$input_file"
IFS=$'\n' read -d '' -ra lines <"$input_file"
2023-11-12 17:47:06 +08:00
exec 3>"$output_file"
in_ech_keys_section=false
in_ech_configs_section=false
for line in "${lines[@]}"; do
if [[ "$line" == *"BEGIN ECH KEYS"* ]]; then
in_ech_keys_section=true
ech_key+=" \"$line\",\n"
elif [[ "$line" == *"END ECH KEYS"* ]]; then
in_ech_keys_section=false
ech_key+=" \"$line\""
elif [[ "$line" == *"BEGIN ECH CONFIGS"* ]]; then
in_ech_configs_section=true
ech_config+=" \"$line\",\n"
elif [[ "$line" == *"END ECH CONFIGS"* ]]; then
in_ech_configs_section=false
ech_config+=" \"$line\""
elif [ "$in_ech_keys_section" = true ]; then
ech_key+=" \"$line\",\n"
elif [ "$in_ech_configs_section" = true ]; then
ech_config+=" \"$line\",\n"
else
echo "\"$line\"," >&3
fi
2024-01-02 02:21:44 +08:00
done
exec 3>&-
rm "$input_file"
2023-11-12 17:47:06 +08:00
}
2023-08-30 16:56:50 +08:00
function get_domain() {
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter domain (disable Cloudflare proxy): " user_domain
2023-10-12 13:39:59 +08:00
resolved_ipv4=$(dig +short A "$user_domain" 2>/dev/null)
resolved_ipv6=$(dig +short AAAA "$user_domain" 2>/dev/null)
if [[ -z $user_domain ]]; then
2024-01-02 02:21:44 +08:00
echo -e "${RED}Error: Domain cannot be empty, please re-enter!${NC}"
2023-07-29 12:09:39 +08:00
else
2023-10-09 11:28:46 +08:00
if [[ ("$resolved_ipv4" == "$ip_v4" && ! -z "$resolved_ipv4") || ("$resolved_ipv6" == "$ip_v6" && ! -z "$resolved_ipv6") ]]; then
2023-07-29 12:09:39 +08:00
break
else
2023-10-09 11:28:46 +08:00
if [[ -z "$resolved_ipv4" && -n "$ip_v4" ]]; then
2023-10-12 13:39:59 +08:00
resolved_ip_v4=$(ping -4 "$user_domain" -c 1 2>/dev/null | sed '1{s/[^(]*(//;s/).*//;q}')
2023-10-09 11:28:46 +08:00
if [[ ("$resolved_ip_v4" == "$ip_v4" && ! -z "$resolved_ip_v4") ]]; then
2023-09-05 21:24:08 +08:00
break
fi
2023-09-03 12:22:11 +08:00
fi
2023-10-09 11:28:46 +08:00
if [[ -z "$resolved_ipv6" && -n "$ip_v6" ]]; then
2023-10-12 13:39:59 +08:00
resolved_ip_v6=$(ping -6 "$user_domain" -c 1 2>/dev/null | sed '1{s/[^(]*(//;s/).*//;q}')
2023-10-09 11:28:46 +08:00
if [[ ("$resolved_ip_v6" == "$ip_v6" && ! -z "$resolved_ip_v6") ]]; then
2023-09-05 21:24:08 +08:00
break
fi
fi
2024-01-02 02:21:44 +08:00
echo -e "${RED}Error: Domain is not bound to local IP, please re-enter!${NC}"
2023-07-29 12:09:39 +08:00
fi
fi
done
2023-10-12 13:39:59 +08:00
domain="$user_domain"
2023-07-29 12:09:39 +08:00
}
2023-10-14 14:56:42 +08:00
function verify_domain() {
2023-10-23 16:06:40 +08:00
new_domain=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_id" \
2024-01-02 02:21:44 +08:00
-H "Authorization: Bearer $api_token" | jq -r '.result.name')
2023-10-23 16:06:40 +08:00
if [[ $new_domain =~ \.(tk|ml|ga|gq|cf)$ ]]; then
2024-01-02 02:21:44 +08:00
echo -e "${RED}Your domain is $new_domain, which does not support using CloudFlare's API to apply for a certificate, please choose another method to apply for the certificate!${NC}"
2023-10-23 16:06:40 +08:00
domain_supported=false
else
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter the main domain prefix (if empty, use the main domain to apply for the certificate, no need to add DNS resolution record in CloudFlare): " domain_prefix
2023-10-14 14:56:42 +08:00
2023-10-23 16:06:40 +08:00
if [ -z "$domain_prefix" ]; then
domain="$new_domain"
record_name="$domain_prefix"
break
2023-10-14 14:56:42 +08:00
else
2023-10-23 16:06:40 +08:00
domain="$domain_prefix"."$new_domain"
record_name="$domain_prefix"
break
2023-10-14 14:56:42 +08:00
fi
2023-10-23 16:06:40 +08:00
done
domain_supported=true
fi
}
function set_dns_record() {
if [[ -z "$record_name" ]]; then
name_value="@"
else
name_value="$record_name"
fi
if [[ -n "$ip_v4" ]]; then
record_content=" $ip_v4"
record_type="A"
elif [[ -z "$ip_v4" && -n "$ip_v6" ]]; then
record_content=" $ip_v6"
record_type="AAAA"
fi
curl -s -X POST "https://api.cloudflare.com/client/v4/zones/$CF_Zone_ID/dns_records" \
2024-01-02 02:21:44 +08:00
-H "Authorization: Bearer $CF_Token" \
-H "Content-Type: application/json" \
--data "{\"type\":\"$record_type\",\"name\":\"$name_value\",\"content\":\"$record_content\",\"ttl\":120,\"proxied\":false}" >/dev/null
2023-10-14 14:56:42 +08:00
}
function get_api_token() {
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter CloudFlare's restrictive API token: " api_token
2023-10-14 14:56:42 +08:00
if [[ ! $api_token =~ ^[A-Za-z0-9_-]{40}$ ]]; then
2024-01-02 02:21:44 +08:00
echo -e "${RED}Incorrect API token format, please re-enter!${NC}"
2023-10-14 14:56:42 +08:00
else
2024-01-02 02:21:44 +08:00
export CF_Token="$api_token"
break
2023-10-14 14:56:42 +08:00
fi
done
}
function get_zone_id() {
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter CloudFlare's zone ID: " zone_id
2023-10-14 14:56:42 +08:00
if [[ ! $zone_id =~ ^[a-z0-9]{32}$ ]]; then
2024-01-02 02:21:44 +08:00
echo -e "${RED}Incorrect CloudFlare zone ID format, please re-enter!${NC}"
2023-10-14 14:56:42 +08:00
else
export CF_Zone_ID="$zone_id"
break
fi
done
}
function get_api_email() {
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter CloudFlare login email: " api_email
2023-10-14 14:56:42 +08:00
if [[ ! $api_email =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$ ]]; then
2024-01-02 02:21:44 +08:00
echo -e "${RED}Incorrect email format, please re-enter!${NC}"
2023-10-14 14:56:42 +08:00
else
export CF_Email="$api_email"
break
fi
done
}
2024-01-02 02:21:44 +08:00
2023-10-09 11:28:46 +08:00
function set_fake_domain() {
2023-08-30 16:56:50 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter spoofed URL (default: www.fan-2000.com): " fake_domain
2023-08-30 16:56:50 +08:00
fake_domain=${fake_domain:-"www.fan-2000.com"}
if curl --output /dev/null --silent --head --fail "$fake_domain"; then
2024-01-02 02:21:44 +08:00
echo "Spoofed URL: $fake_domain"
2023-08-30 16:56:50 +08:00
break
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid or unavailable spoofed URL, please re-enter!${NC}"
2023-08-30 16:56:50 +08:00
fi
done
}
2023-08-25 11:56:25 +08:00
2023-10-09 11:28:46 +08:00
function set_certificate_path() {
2023-08-30 16:56:50 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter PEM certificate location: " certificate_path_input
2023-09-25 17:12:43 +08:00
if [[ ! -f "$certificate_path_input" ]]; then
2024-01-02 02:21:44 +08:00
echo -e "${RED}Error: Certificate file does not exist, please re-enter!${NC}"
2023-09-25 17:12:43 +08:00
continue
2023-08-30 16:56:50 +08:00
fi
2023-09-25 17:12:43 +08:00
certificate_file=$(basename "$certificate_path_input")
allowed_extensions=("crt" "pem")
if [[ ! "${allowed_extensions[@]}" =~ "${certificate_file##*.}" ]]; then
2024-01-02 02:21:44 +08:00
echo -e "${RED}Error: Unsupported certificate format, please configure a .crt or .pem format certificate file!${NC}"
2023-09-25 17:12:43 +08:00
continue
fi
2024-01-02 02:21:44 +08:00
certificate_path="$certificate_path_input"
2023-09-06 08:32:39 +08:00
break
2023-08-30 16:56:50 +08:00
done
2023-10-09 11:28:46 +08:00
}
2023-08-30 16:56:50 +08:00
2023-10-09 11:28:46 +08:00
function set_private_key_path() {
2023-08-30 16:56:50 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter PEM private key location: " private_key_path_input
2023-09-25 17:12:43 +08:00
if [[ ! -f "$private_key_path_input" ]]; then
2024-01-02 02:21:44 +08:00
echo -e "${RED}Error: Private key file does not exist, please re-enter!${NC}"
2023-09-25 17:12:43 +08:00
continue
2023-08-30 16:56:50 +08:00
fi
2023-09-25 17:12:43 +08:00
private_key_file=$(basename "$private_key_path_input")
allowed_extensions=("key" "pem")
if [[ ! "${allowed_extensions[@]}" =~ "${private_key_file##*.}" ]]; then
2024-01-02 02:21:44 +08:00
echo -e "${RED}Error: Unsupported private key format, please configure a .key or .pem format private key file!${NC}"
2023-09-25 17:12:43 +08:00
continue
fi
2024-01-02 02:21:44 +08:00
private_key_path="$private_key_path_input"
2023-09-06 08:32:39 +08:00
break
2023-08-30 16:56:50 +08:00
done
2023-08-19 17:45:08 +08:00
}
2023-08-30 16:56:50 +08:00
function apply_certificate() {
2023-09-25 17:12:43 +08:00
certificate_path="/etc/ssl/private/"$domain".crt"
private_key_path="/etc/ssl/private/"$domain".key"
2023-08-30 16:56:50 +08:00
local has_ipv4=false
2023-09-21 16:15:36 +08:00
local ca_servers=("letsencrypt" "zerossl")
2023-11-04 13:36:54 +08:00
local return_to_menu=false
2023-10-09 11:28:46 +08:00
if [[ -n "$ip_v4" ]]; then
2023-08-30 16:56:50 +08:00
has_ipv4=true
fi
2024-01-02 02:21:44 +08:00
echo "Requesting a certificate..."
2023-09-21 16:15:36 +08:00
curl -s https://get.acme.sh | sh -s email=example@gmail.com 2>&1 | tail -n 1
2023-08-30 16:56:50 +08:00
alias acme.sh=~/.acme.sh/acme.sh
2023-09-21 16:15:36 +08:00
for ca_server in "${ca_servers[@]}"; do
echo "Requesting a certificate from $ca_server..."
~/.acme.sh/acme.sh --set-default-ca --server "$ca_server"
if $has_ipv4; then
2023-10-14 14:56:42 +08:00
result=$(~/.acme.sh/acme.sh --issue -d "$domain" --standalone -k ec-256 2>&1)
2023-09-21 16:15:36 +08:00
else
2023-10-14 14:56:42 +08:00
result=$(~/.acme.sh/acme.sh --issue -d "$domain" --standalone -k ec-256 --listen-v6 2>&1)
2023-09-21 16:15:36 +08:00
fi
2023-11-04 13:36:54 +08:00
if [[ $result == *"force"* ]]; then
if $has_ipv4; then
result=$(~/.acme.sh/acme.sh --issue -d "$domain" --standalone -k ec-256 --force 2>&1)
else
result=$(~/.acme.sh/acme.sh --issue -d "$domain" --standalone -k ec-256 --listen-v6 --force 2>&1)
fi
fi
if [[ $result == *"log"* || $result == *"debug"* || $result == *"error"* ]]; then
2024-01-02 02:21:44 +08:00
echo -e "${RED}$result ${NC}"
continue
2023-10-14 14:56:42 +08:00
fi
if [[ $? -eq 0 ]]; then
echo "Installing the certificate..."
~/.acme.sh/acme.sh --install-cert -d "$domain" --ecc --key-file "$private_key_path" --fullchain-file "$certificate_path"
2024-01-02 02:21:44 +08:00
break
2023-10-14 14:56:42 +08:00
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Failed to obtain a certificate from $ca_server!${NC}"
2023-10-14 14:56:42 +08:00
return_to_menu=true
fi
done
if [ "$return_to_menu" = true ]; then
2024-01-02 02:21:44 +08:00
echo -e "${RED}Certificate application failed, please use another method to apply for the certificate!${NC}"
2023-10-14 14:56:42 +08:00
return 1
fi
}
function Apply_api_certificate() {
certificate_path="/etc/ssl/private/"$domain".crt"
private_key_path="/etc/ssl/private/"$domain".key"
local has_ipv4=false
local ca_servers=("letsencrypt" "zerossl")
if [[ -n "$ip_v4" ]]; then
has_ipv4=true
fi
2024-01-02 02:21:44 +08:00
echo "Requesting a certificate..."
2023-10-14 14:56:42 +08:00
curl -s https://get.acme.sh | sh -s email=example@gmail.com 2>&1 | tail -n 1
alias acme.sh=~/.acme.sh/acme.sh
for ca_server in "${ca_servers[@]}"; do
echo "Requesting a certificate from $ca_server..."
~/.acme.sh/acme.sh --set-default-ca --server "$ca_server"
if $has_ipv4; then
result=$(~/.acme.sh/acme.sh --issue --dns dns_cf -d "$domain" -k ec-256 2>&1)
else
result=$(~/.acme.sh/acme.sh --issue --dns dns_cf -d "$domain" -k ec-256 --listen-v6 2>&1)
fi
if [[ $result == *"log"* || $result == *"debug"* || $result == *"error"* || $result == *"force"* ]]; then
echo -e "${RED}$result ${NC}"
2024-01-02 02:21:44 +08:00
return_to_menu=true
continue
2023-10-14 14:56:42 +08:00
fi
2023-09-21 16:15:36 +08:00
if [[ $? -eq 0 ]]; then
echo "Installing the certificate..."
2023-09-25 17:12:43 +08:00
~/.acme.sh/acme.sh --install-cert -d "$domain" --ecc --key-file "$private_key_path" --fullchain-file "$certificate_path"
2024-01-02 02:21:44 +08:00
break
2023-09-21 16:15:36 +08:00
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Failed to obtain a certificate from $ca_server!${NC}"
2023-10-14 14:56:42 +08:00
return_to_menu=true
2023-09-21 16:15:36 +08:00
fi
done
2023-10-14 14:56:42 +08:00
if [ "$return_to_menu" = true ]; then
2024-01-02 02:21:44 +08:00
echo -e "${RED}Certificate application failed, please use another method to apply for the certificate!${NC}"
2023-10-14 14:56:42 +08:00
return 1
fi
2023-07-29 12:09:39 +08:00
}
2023-09-19 18:19:39 +08:00
function Reapply_certificates() {
local tls_info_file="/usr/local/etc/sing-box/tls_info.json"
local has_ipv4=false
2023-10-09 11:28:46 +08:00
if [ -n "$ip_v4" ]; then
2023-09-19 18:19:39 +08:00
has_ipv4=true
fi
if ! command -v acme.sh &>/dev/null; then
curl -s https://get.acme.sh | sh -s email=example@gmail.com
fi
alias acme.sh=~/.acme.sh/acme.sh
2023-10-23 16:06:40 +08:00
echo "Setting CA server to Let's Encrypt..."
~/.acme.sh/acme.sh --set-default-ca --server "letsencrypt"
jq -c '.[]' "$tls_info_file" | while read -r tls_info; do
server_name=$(echo "$tls_info" | jq -r '.server_name')
key_path=$(echo "$tls_info" | jq -r '.key_path')
certificate_path=$(echo "$tls_info" | jq -r '.certificate_path')
echo "Requesting certificate for $server_name..."
result=$(
if $has_ipv4; then
~/.acme.sh/acme.sh --issue --dns dns_cf -d "$server_name" -k ec-256 --force
else
~/.acme.sh/acme.sh --issue --dns dns_cf -d "$server_name" -k ec-256 --listen-v6 --force
fi
)
if [[ "$result" =~ "Cert success." ]]; then
echo "Certificate for $server_name has been applied using Cloudflare DNS verification."
else
echo "Cloudflare DNS verification failed for $server_name. Trying standalone verification..."
2023-10-09 11:28:46 +08:00
result=$(
if $has_ipv4; then
2023-10-23 16:06:40 +08:00
~/.acme.sh/acme.sh --issue -d "$server_name" --standalone --force
2023-10-09 11:28:46 +08:00
else
2023-10-23 16:06:40 +08:00
~/.acme.sh/acme.sh --issue -d "$server_name" --standalone --listen-v6 --force
2023-10-09 11:28:46 +08:00
fi
)
if [[ "$result" =~ "BEGIN CERTIFICATE" && "$result" =~ "END CERTIFICATE" ]]; then
2023-10-23 16:06:40 +08:00
echo "Certificate for $server_name has been applied using Let's Encrypt CA."
2023-09-21 16:15:36 +08:00
else
2023-10-23 16:06:40 +08:00
echo "Failed to obtain certificate for $server_name using standalone verification as well."
return 1
2023-09-21 16:15:36 +08:00
fi
2024-01-02 02:21:44 +08:00
fi
2023-10-23 16:06:40 +08:00
~/.acme.sh/acme.sh --install-cert -d "$server_name" --ecc --key-file "$key_path" --fullchain-file "$certificate_path"
echo "Certificate for $server_name has been installed."
2023-09-19 18:19:39 +08:00
done
rm -f "$tls_info_file"
}
2023-08-30 16:56:50 +08:00
function generate_private_key() {
2023-09-28 15:53:33 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter private key (default: generate a random private key): " local_private_key
2023-09-28 15:53:33 +08:00
if [[ -z "$local_private_key" ]]; then
2023-08-30 16:56:50 +08:00
local keypair_output=$(sing-box generate reality-keypair)
2023-09-28 15:53:33 +08:00
local_private_key=$(echo "$keypair_output" | awk -F: '/PrivateKey/{gsub(/ /, "", $2); print $2}')
local_public_key=$(echo "$keypair_output" | awk -F: '/PublicKey/{gsub(/ /, "", $2); print $2}')
2024-01-02 02:21:44 +08:00
echo "private_key: $local_private_key"
echo "public_key: $local_public_key"
2023-08-30 16:56:50 +08:00
break
2023-07-29 12:09:39 +08:00
else
2023-09-28 15:53:33 +08:00
if [[ "$local_private_key" =~ ^[A-Za-z0-9_\-]{43}$ ]]; then
2024-01-02 02:21:44 +08:00
read -p "Please enter public key: " local_public_key
2023-09-28 15:53:33 +08:00
if ! [[ "$local_public_key" =~ ^[A-Za-z0-9_\-]{43}$ ]]; then
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid public key, please re-enter!${NC}"
2023-09-28 15:53:33 +08:00
else
break
fi
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid private key, please re-enter!${NC}"
2023-09-28 15:53:33 +08:00
fi
2023-07-29 12:09:39 +08:00
fi
2023-09-28 15:53:33 +08:00
done
public_key="$local_public_key"
private_key="$local_private_key"
2023-07-29 12:09:39 +08:00
}
2023-10-12 13:39:59 +08:00
function create_self_signed_cert() {
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter the domain for the self-signed certificate (default is bing.com): " user_domain
2023-10-12 13:39:59 +08:00
domain_name=${user_domain:-"bing.com"}
if curl --output /dev/null --silent --head --fail "$domain_name"; then
openssl req -x509 -nodes -newkey ec:<(openssl ecparam -name prime256v1) -keyout /etc/ssl/private/$domain_name.key -out /etc/ssl/private/$domain_name.crt -subj "/CN=$domain_name" -days 36500
chmod 777 /etc/ssl/private/$domain_name.key
chmod 777 /etc/ssl/private/$domain_name.crt
2024-01-02 02:21:44 +08:00
break
2023-10-12 13:39:59 +08:00
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid or unavailable domain name, please enter a valid domain!${NC}"
2023-10-12 13:39:59 +08:00
fi
done
certificate_path="/etc/ssl/private/$domain_name.crt"
private_key_path="/etc/ssl/private/$domain_name.key"
}
2023-10-09 11:28:46 +08:00
function select_encryption_method() {
2023-07-29 12:09:39 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please select encryption method (default 1):
2023-09-12 14:44:29 +08:00
1). 2022-blake3-chacha20-poly1305
2023-08-30 16:56:50 +08:00
2). 2022-blake3-aes-256-gcm
2023-09-12 14:44:29 +08:00
3). 2022-blake3-aes-128-gcm
4). xchacha20-ietf-poly1305
5). chacha20-ietf-poly1305
6). aes-256-gcm
7). aes-192-gcm
8). aes-128-gcm
2024-01-02 02:21:44 +08:00
Select [1-8]: " encryption_choice
2023-09-12 14:44:29 +08:00
encryption_choice=${encryption_choice:-1}
2023-08-30 16:56:50 +08:00
case $encryption_choice in
2024-01-02 02:21:44 +08:00
1)
ss_method="2022-blake3-chacha20-poly1305"
ss_password=$(sing-box generate rand --base64 32)
shadowtls_password=$(sing-box generate rand --base64 32)
break
;;
2)
ss_method="2022-blake3-aes-256-gcm"
ss_password=$(sing-box generate rand --base64 32)
shadowtls_password=$(sing-box generate rand --base64 32)
break
;;
3)
ss_method="2022-blake3-aes-128-gcm"
ss_password=$(sing-box generate rand --base64 16)
shadowtls_password=$(sing-box generate rand --base64 16)
break
;;
2023-09-12 14:44:29 +08:00
2024-01-02 02:21:44 +08:00
4)
ss_method="xchacha20-ietf-poly1305"
ss_password=$(sing-box generate rand --base64 16)
shadowtls_password=$(sing-box generate rand --base64 16)
break
;;
5)
ss_method="chacha20-ietf-poly1305"
ss_password=$(sing-box generate rand --base64 16)
shadowtls_password=$(sing-box generate rand --base64 16)
break
;;
6)
ss_method="aes-256-gcm"
ss_password=$(sing-box generate rand --base64 16)
shadowtls_password=$(sing-box generate rand --base64 16)
break
;;
7)
ss_method="aes-192-gcm"
ss_password=$(sing-box generate rand --base64 16)
shadowtls_password=$(sing-box generate rand --base64 16)
break
;;
8)
ss_method="aes-128-gcm"
ss_password=$(sing-box generate rand --base64 16)
shadowtls_password=$(sing-box generate rand --base64 16)
break
;;
*)
echo -e "${RED}Error: Invalid selection, please try again!${NC}"
;;
2023-08-30 16:56:50 +08:00
esac
2023-07-29 12:09:39 +08:00
done
2023-08-30 16:56:50 +08:00
}
2023-07-29 12:09:39 +08:00
2023-08-30 16:56:50 +08:00
function select_unlocked_items() {
2023-07-29 12:09:39 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please select items to unlock (supports multiple selection):
2023-08-30 16:56:50 +08:00
1). ChatGPT
2). Netflix
3). Disney+
2023-11-03 17:20:00 +08:00
4). YouTube
2024-01-02 03:40:09 +08:00
5). Google
6). Spotify
2024-01-04 14:36:52 +08:00
7). Reddit
Select [1-7]: " choices
if [[ "$choices" =~ ^[1234567]+$ ]]; then
2023-08-30 16:56:50 +08:00
selected=($(echo "$choices" | sed 's/./& /g'))
2023-07-29 12:09:39 +08:00
break
2023-08-30 16:56:50 +08:00
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Error: Invalid selection, please try again!${NC}"
2023-07-29 12:09:39 +08:00
fi
done
}
2023-08-30 16:56:50 +08:00
function update_geosite_array() {
for choice in "${selected[@]}"; do
2024-01-02 02:21:44 +08:00
case $choice in
2023-08-30 16:56:50 +08:00
1)
2024-01-02 02:21:44 +08:00
geosite+=("\"openai\"")
;;
2023-08-30 16:56:50 +08:00
2)
2024-01-02 02:21:44 +08:00
geosite+=("\"netflix\"")
;;
2023-08-30 16:56:50 +08:00
3)
2024-01-02 02:21:44 +08:00
geosite+=("\"disney\"")
;;
2023-11-03 17:20:00 +08:00
4)
2024-01-02 02:21:44 +08:00
geosite+=("\"youtube\"")
;;
2024-01-02 03:40:09 +08:00
5)
geosite+=("\"google\"")
;;
6)
geosite+=("\"spotify\"")
2024-01-04 14:36:52 +08:00
;;
7)
geosite+=("\"reddit\"")
;;
2023-08-30 16:56:50 +08:00
*)
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid choice: $choice${NC}"
;;
esac
2023-08-30 16:56:50 +08:00
done
}
function select_outbound() {
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please select outbound network (default 1):
2023-08-30 16:56:50 +08:00
1). warp-IPv4
2). warp-IPv6
2024-01-02 02:21:44 +08:00
Select [1-2]: " outbound_choice
case $outbound_choice in
1 | "")
outbound="warp-IPv4-out"
break
;;
2023-08-30 16:56:50 +08:00
2)
2024-01-02 02:21:44 +08:00
outbound="warp-IPv6-out"
break
;;
2023-08-30 16:56:50 +08:00
*)
2024-01-02 02:21:44 +08:00
echo -e "${RED}Error: Invalid option, please enter a valid choice!${NC}"
;;
esac
2023-08-30 16:56:50 +08:00
done
}
2023-10-09 11:28:46 +08:00
function select_congestion_control() {
2023-07-29 12:09:39 +08:00
local default_congestion_control="bbr"
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please select congestion control algorithm (default $default_congestion_control):
2023-08-19 17:45:08 +08:00
1). bbr
2). cubic
3). new_reno
2024-01-02 02:21:44 +08:00
Select [1-3]: " congestion_control
2023-07-29 12:09:39 +08:00
case $congestion_control in
2024-01-02 02:21:44 +08:00
1)
congestion_control="bbr"
break
;;
2)
congestion_control="cubic"
break
;;
3)
congestion_control="new_reno"
break
;;
"")
congestion_control=$default_congestion_control
break
;;
*)
echo -e "${RED}Error: Invalid choice, please try again!${NC}"
;;
2023-07-29 12:09:39 +08:00
esac
done
}
2023-10-09 11:28:46 +08:00
function select_certificate_option() {
2023-09-26 17:09:50 +08:00
local certificate_option
2023-10-14 14:56:42 +08:00
local domain_supported=false
local return_to_menu=false
2023-07-29 12:09:39 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please select certificate source (default 1):
1). Self-signed certificate
2). Request certificate listening on port 80 (standalone mode)
3). Cloudflare API certificate request (DNS API mode)
4). Custom certificate path
Select [1-4]: " certificate_option
2023-09-25 17:12:43 +08:00
certificate_option=${certificate_option:-1}
2023-07-29 12:09:39 +08:00
case $certificate_option in
2024-01-02 02:21:44 +08:00
1)
if $disable_option; then
echo -e "${RED}NaiveProxy node doesn't support self-signed certificates, please use acme to request a certificate!${NC}"
continue
fi
check_firewall_configuration
create_self_signed_cert
break
;;
2)
get_local_ip
get_domain
check_firewall_configuration
apply_certificate
if [ "$return_to_menu" == true ]; then
return_to_menu=false
continue
fi
break
;;
3)
get_local_ip
get_api_token
get_zone_id
get_api_email
verify_domain
set_dns_record
check_firewall_configuration
if [ "$domain_supported" == "false" ]; then
continue
else
Apply_api_certificate
2023-10-14 14:56:42 +08:00
if [ "$return_to_menu" == true ]; then
return_to_menu=false
continue
fi
2023-07-29 12:09:39 +08:00
break
2024-01-02 02:21:44 +08:00
fi
;;
4)
get_local_ip
get_domain
check_firewall_configuration
set_certificate_path
set_private_key_path
break
;;
*)
echo -e "${RED}Error: Invalid selection, please try again!${NC}"
;;
2023-07-29 12:09:39 +08:00
esac
done
}
2023-10-09 11:28:46 +08:00
function select_vmess_type() {
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please select node type (default 1):
2023-10-23 16:34:01 +08:00
1). VMess+TCP
2). VMess+WebSocket
3). VMess+gRPC
2023-11-14 14:20:52 +08:00
4). VMess+HTTPUpgrade
5). VMess+TCP+TLS
6). VMess+WebSocket+TLS
7). VMess+H2C+TLS
8). VMess+gRPC+TLS
9). VMess+HTTPUpgrade+TLS
2024-01-02 02:21:44 +08:00
Select [1-9]: " node_type
2023-10-09 11:28:46 +08:00
case $node_type in
2024-01-02 02:21:44 +08:00
"" | 1)
tls_enabled=false
break
;;
2)
transport_ws=true
tls_enabled=false
break
;;
3)
transport_grpc=true
tls_enabled=false
break
;;
4)
transport_httpupgrade=true
tls_enabled=false
break
;;
5)
tls_enabled=true
break
;;
6)
transport_ws=true
tls_enabled=true
break
;;
7)
transport_http=true
tls_enabled=true
break
;;
8)
transport_grpc=true
tls_enabled=true
break
;;
9)
transport_httpupgrade=true
tls_enabled=true
break
;;
*)
echo -e "${RED}Invalid selection, please try again!${NC}"
;;
2023-10-09 11:28:46 +08:00
esac
done
}
function select_vless_type() {
2023-07-29 12:09:39 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please select node type (default 1):
2023-10-23 16:34:01 +08:00
1). VLESS+TCP
2). VLESS+WebSocket
3). VLESS+gRPC
2023-11-14 14:20:52 +08:00
4). VLESS+HTTPUpgrade
5). VLESS+Vision+REALITY
6). VLESS+H2C+REALITY
7). VLESS+gRPC+REALITY
2024-01-02 02:21:44 +08:00
Select [1-7]: " flow_option
2023-08-30 16:56:50 +08:00
case $flow_option in
2024-01-02 02:21:44 +08:00
"" | 1)
flow_type=""
break
;;
2)
flow_type=""
transport_ws=true
break
;;
3)
flow_type=""
transport_grpc=true
break
;;
4)
flow_type=""
transport_httpupgrade=true
break
;;
5)
flow_type="xtls-rprx-vision"
reality_enabled=true
break
;;
6)
flow_type=""
transport_http=true
reality_enabled=true
break
;;
7)
flow_type=""
transport_grpc=true
reality_enabled=true
break
;;
*)
echo -e "${RED}Invalid option, please try again!${NC}" >&2
;;
2023-08-30 16:56:50 +08:00
esac
2023-07-29 12:09:39 +08:00
done
}
2023-10-09 11:28:46 +08:00
function select_trojan_type() {
2023-07-29 12:09:39 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please select node type (default 1):
2023-10-23 16:34:01 +08:00
1). Trojan+TCP
2). Trojan+WebSocket
3). Trojan+gRPC
2023-11-14 14:20:52 +08:00
4). Trojan+HTTPUpgrade
5). Trojan+TCP+TLS
6). Trojan+WebSocket+TLS
7). Trojan+H2C+TLS
8). Trojan+gRPC+TLS
9). Trojan+HTTPUpgrade+TLS
2024-01-02 02:21:44 +08:00
Select [1-9]: " setup_type
2023-08-30 16:56:50 +08:00
case $setup_type in
2024-01-02 02:21:44 +08:00
"" | 1)
tls_enabled=false
break
;;
2)
transport_ws=true
tls_enabled=false
break
;;
3)
transport_grpc=true
tls_enabled=false
break
;;
4)
transport_httpupgrade=true
tls_enabled=false
break
;;
5)
tls_enabled=true
break
;;
6)
transport_ws=true
tls_enabled=true
break
;;
7)
transport_http=true
tls_enabled=true
break
;;
8)
transport_grpc=true
tls_enabled=true
break
;;
9)
transport_httpupgrade=true
tls_enabled=true
break
;;
*)
echo -e "${RED}Invalid selection, please try again!${NC}"
;;
2023-08-19 17:45:08 +08:00
esac
done
2023-07-29 12:09:39 +08:00
}
2023-10-09 11:28:46 +08:00
function set_short_id() {
2023-08-30 16:56:50 +08:00
while true; do
2024-01-02 02:21:44 +08:00
read -p "Please enter Short_Id (used to distinguish different clients, default is randomly generated): " short_id
2023-10-09 11:28:46 +08:00
if [[ -z "$short_id" ]]; then
short_id=$(openssl rand -hex 8)
2024-01-02 02:21:44 +08:00
echo "Short_Id: $short_id"
2023-10-09 11:28:46 +08:00
break
elif [[ "$short_id" =~ ^[0-9a-fA-F]{2,16}$ ]]; then
2024-01-02 02:21:44 +08:00
echo "Short_Id: $short_id"
2023-08-30 16:56:50 +08:00
break
else
2024-01-02 02:21:44 +08:00
echo "Error: Please enter a hexadecimal string between two to sixteen characters!"
2023-08-30 16:56:50 +08:00
fi
done
2023-10-09 11:28:46 +08:00
short_ids+=("$short_id")
2023-08-30 16:56:50 +08:00
}
2023-07-29 12:09:39 +08:00
2023-10-09 11:28:46 +08:00
function set_short_ids() {
2023-08-30 16:56:50 +08:00
while true; do
2023-10-09 11:28:46 +08:00
set_short_id
2024-01-02 02:21:44 +08:00
for ((i = 0; i < ${#short_ids[@]}; i++)); do
2023-10-09 11:28:46 +08:00
short_id="${short_ids[$i]}"
2024-01-02 02:21:44 +08:00
done
read -p "Would you like to continue adding short ids? (Y/N, default N): " -e choice
2023-10-09 11:28:46 +08:00
if [[ -z "$choice" ]]; then
choice="N"
2023-08-30 16:56:50 +08:00
fi
2023-10-09 11:28:46 +08:00
if [[ "$choice" == "N" || "$choice" == "n" ]]; then
2023-11-12 17:47:06 +08:00
short_Ids+="\n \"$short_id\""
2023-08-30 16:56:50 +08:00
break
2023-10-09 11:28:46 +08:00
elif [[ "$choice" == "Y" || "$choice" == "y" ]]; then
2023-11-12 17:47:06 +08:00
short_Ids+="\n \"$short_id\","
2023-10-09 11:28:46 +08:00
continue
2023-08-30 16:56:50 +08:00
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid input, please try again!${NC}"
2023-08-30 16:56:50 +08:00
fi
done
2023-07-29 12:09:39 +08:00
}
2023-10-09 11:28:46 +08:00
function tuic_multiple_users() {
2023-08-17 17:46:42 +08:00
while true; do
2023-10-09 11:28:46 +08:00
set_user_name
set_user_password
set_uuid
2024-01-02 02:21:44 +08:00
for ((i = 0; i < ${#user_names[@]}; i++)); do
2023-10-09 11:28:46 +08:00
user_name="${user_names[$i]}"
user_uuid="${user_uuids[$i]}"
user_password="${user_passwords[$i]}"
2023-11-12 17:47:06 +08:00
done
2024-01-02 02:21:44 +08:00
read -p "Would you like to continue adding users? (Y/N, default N): " -e add_multiple_users
2023-08-30 16:56:50 +08:00
if [[ -z "$add_multiple_users" ]]; then
add_multiple_users="N"
2023-08-25 11:56:25 +08:00
fi
2023-10-09 11:28:46 +08:00
if [[ "$add_multiple_users" == "N" || "$add_multiple_users" == "n" ]]; then
2023-11-12 17:47:06 +08:00
users+="\n {\n \"name\": \"$user_name\",\n \"uuid\": \"$user_uuid\",\n \"password\": \"$user_password\"\n }"
2023-08-30 16:56:50 +08:00
break
2023-10-09 11:28:46 +08:00
elif [[ "$add_multiple_users" == "Y" || "$add_multiple_users" == "y" ]]; then
2023-11-12 17:47:06 +08:00
users+="\n {\n \"name\": \"$user_name\",\n \"uuid\": \"$user_uuid\",\n \"password\": \"$user_password\"\n },"
2023-10-09 11:28:46 +08:00
continue
2023-08-30 16:56:50 +08:00
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid input, please try again!${NC}"
2023-09-19 16:37:08 +08:00
fi
done
}
function vmess_multiple_users() {
while true; do
2023-10-09 11:28:46 +08:00
set_uuid
2024-01-02 02:21:44 +08:00
for ((i = 0; i < ${#user_uuids[@]}; i++)); do
2023-10-09 11:28:46 +08:00
user_uuid="${user_uuids[$i]}"
2023-11-12 17:47:06 +08:00
done
2024-01-02 02:21:44 +08:00
read -p "Would you like to continue adding users? (Y/N, default N): " -e add_multiple_users
2023-09-19 16:37:08 +08:00
if [[ -z "$add_multiple_users" ]]; then
add_multiple_users="N"
fi
2023-10-09 11:28:46 +08:00
if [[ "$add_multiple_users" == "N" || "$add_multiple_users" == "n" ]]; then
2023-11-12 17:47:06 +08:00
users+="\n {\n \"uuid\": \"$user_uuid\",\n \"alterId\": 0\n }"
2023-09-19 16:37:08 +08:00
break
2023-10-09 11:28:46 +08:00
elif [[ "$add_multiple_users" == "Y" || "$add_multiple_users" == "y" ]]; then
2023-11-12 17:47:06 +08:00
users+="\n {\n \"uuid\": \"$user_uuid\",\n \"alterId\": 0\n },"
2023-10-09 11:28:46 +08:00
continue
2023-09-19 16:37:08 +08:00
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid input, please try again!${NC}"
2023-08-30 16:56:50 +08:00
fi
2023-08-17 17:46:42 +08:00
done
}
2023-10-12 13:39:59 +08:00
function vless_multiple_users() {
while true; do
set_uuid
2024-01-02 02:21:44 +08:00
for ((i = 0; i < ${#user_uuids[@]}; i++)); do
2023-10-12 13:39:59 +08:00
user_uuid="${user_uuids[$i]}"
2023-11-12 17:47:06 +08:00
done
2024-01-02 02:21:44 +08:00
read -p "Would you like to continue adding users? (Y/N, default N): " -e add_multiple_users
2023-10-12 13:39:59 +08:00
if [[ -z "$add_multiple_users" ]]; then
add_multiple_users="N"
fi
if [[ "$add_multiple_users" == "N" || "$add_multiple_users" == "n" ]]; then
2023-11-12 17:47:06 +08:00
users+="\n {\n \"uuid\": \"$user_uuid\",\n \"flow\": \"$flow_type\"\n }"
2023-10-12 13:39:59 +08:00
break
elif [[ "$add_multiple_users" == "Y" || "$add_multiple_users" == "y" ]]; then
2023-11-12 17:47:06 +08:00
users+="\n {\n \"uuid\": \"$user_uuid\",\n \"flow\": \"$flow_type\"\n },"
2023-10-12 13:39:59 +08:00
continue
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid input, please try again!${NC}"
2023-10-12 13:39:59 +08:00
fi
done
}
2024-01-02 02:21:44 +08:00
function socks_naive_multiple_users() {
2023-09-18 16:36:33 +08:00
while true; do
2023-10-09 11:28:46 +08:00
set_user_name
set_user_password
2024-01-02 02:21:44 +08:00
for ((i = 0; i < ${#user_names[@]}; i++)); do
2023-10-09 11:28:46 +08:00
user_name="${user_names[$i]}"
user_password="${user_passwords[$i]}"
2023-11-12 17:47:06 +08:00
done
2024-01-02 02:21:44 +08:00
read -p "Would you like to continue adding users? (Y/N, default N): " -e add_multiple_users
2023-09-18 16:36:33 +08:00
if [[ -z "$add_multiple_users" ]]; then
add_multiple_users="N"
fi
2023-10-09 11:28:46 +08:00
if [[ "$add_multiple_users" == "N" || "$add_multiple_users" == "n" ]]; then
2023-11-12 17:47:06 +08:00
users+="\n {\n \"username\": \"$user_name\",\n \"password\": \"$user_password\"\n }"
2023-09-18 16:36:33 +08:00
break
2023-10-09 11:28:46 +08:00
elif [[ "$add_multiple_users" == "Y" || "$add_multiple_users" == "y" ]]; then
2023-11-12 17:47:06 +08:00
users+="\n {\n \"username\": \"$user_name\",\n \"password\": \"$user_password\"\n },"
2023-10-09 11:28:46 +08:00
continue
2023-09-18 16:36:33 +08:00
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid input, please try again!${NC}"
2023-09-18 16:36:33 +08:00
fi
done
}
2023-08-30 16:56:50 +08:00
function hysteria_multiple_users() {
while true; do
2023-10-09 11:28:46 +08:00
set_user_name
set_user_password
2024-01-02 02:21:44 +08:00
for ((i = 0; i < ${#user_names[@]}; i++)); do
2023-10-09 11:28:46 +08:00
user_name="${user_names[$i]}"
user_password="${user_passwords[$i]}"
2023-11-12 17:47:06 +08:00
done
2024-01-02 02:21:44 +08:00
read -p "Would you like to continue adding users? (Y/N, default N): " -e add_multiple_users
2023-08-17 17:46:42 +08:00
2023-08-30 16:56:50 +08:00
if [[ -z "$add_multiple_users" ]]; then
add_multiple_users="N"
2023-08-17 17:46:42 +08:00
fi
2023-10-09 11:28:46 +08:00
if [[ "$add_multiple_users" == "N" || "$add_multiple_users" == "n" ]]; then
2023-11-12 17:47:06 +08:00
users+="\n {\n \"name\": \"$user_name\",\n \"auth_str\": \"$user_password\"\n }"
2023-08-30 16:56:50 +08:00
break
2023-10-09 11:28:46 +08:00
elif [[ "$add_multiple_users" == "Y" || "$add_multiple_users" == "y" ]]; then
2023-11-12 17:47:06 +08:00
users+="\n {\n \"name\": \"$user_name\",\n \"auth_str\": \"$user_password\"\n },"
2023-10-09 11:28:46 +08:00
continue
2023-08-17 17:46:42 +08:00
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid input, please try again!${NC}"
2023-08-30 16:56:50 +08:00
fi
done
}
2023-09-04 11:22:03 +08:00
function hy2_multiple_users() {
while true; do
2023-10-09 11:28:46 +08:00
set_user_name
set_user_password
2024-01-02 02:21:44 +08:00
for ((i = 0; i < ${#user_names[@]}; i++)); do
2023-10-09 11:28:46 +08:00
user_name="${user_names[$i]}"
user_password="${user_passwords[$i]}"
2023-11-12 17:47:06 +08:00
done
2024-01-02 02:21:44 +08:00
read -p "Would you like to continue adding users? (Y/N, default N): " -e add_multiple_users
2023-09-04 11:22:03 +08:00
if [[ -z "$add_multiple_users" ]]; then
add_multiple_users="N"
fi
2023-10-09 11:28:46 +08:00
if [[ "$add_multiple_users" == "N" || "$add_multiple_users" == "n" ]]; then
2023-11-12 17:47:06 +08:00
users+="\n {\n \"name\": \"$user_name\",\n \"password\": \"$user_password\"\n }"
2023-09-04 11:22:03 +08:00
break
2023-10-09 11:28:46 +08:00
elif [[ "$add_multiple_users" == "Y" || "$add_multiple_users" == "y" ]]; then
2023-11-12 17:47:06 +08:00
users+="\n {\n \"name\": \"$user_name\",\n \"password\": \"$user_password\"\n },"
2023-10-09 11:28:46 +08:00
continue
2023-09-04 11:22:03 +08:00
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid input, please try again!${NC}"
2023-09-04 11:22:03 +08:00
fi
done
}
2023-10-09 11:28:46 +08:00
function trojan_multiple_users() {
while true; do
set_user_password
2024-01-02 02:21:44 +08:00
for ((i = 0; i < ${#user_passwords[@]}; i++)); do
2023-10-09 11:28:46 +08:00
user_password="${user_passwords[$i]}"
2023-11-12 17:47:06 +08:00
done
2024-01-02 02:21:44 +08:00
read -p "Would you like to continue adding users? (Y/N, default N): " -e add_multiple_users
2023-10-09 11:28:46 +08:00
if [[ -z "$add_multiple_users" ]]; then
add_multiple_users="N"
fi
if [[ "$add_multiple_users" == "N" || "$add_multiple_users" == "n" ]]; then
2023-11-12 17:47:06 +08:00
users+="\n {\n \"password\": \"$user_password\"\n }"
2023-10-09 11:28:46 +08:00
break
elif [[ "$add_multiple_users" == "Y" || "$add_multiple_users" == "y" ]]; then
2023-11-12 17:47:06 +08:00
users+="\n {\n \"password\": \"$user_password\"\n },"
2023-10-09 11:28:46 +08:00
continue
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid input, please try again!${NC}"
2023-10-09 11:28:46 +08:00
fi
done
}
2023-08-30 16:56:50 +08:00
2023-10-09 11:28:46 +08:00
function shadowtls_multiple_users() {
2023-08-30 16:56:50 +08:00
while true; do
2023-10-09 11:28:46 +08:00
set_user_name
set_stls_password
2024-01-02 02:21:44 +08:00
for ((i = 0; i < ${#user_names[@]}; i++)); do
2023-10-09 11:28:46 +08:00
user_name="${user_names[$i]}"
stls_password="${stls_passwords[$i]}"
2023-11-12 17:47:06 +08:00
done
2024-01-02 02:21:44 +08:00
read -p "Would you like to continue adding users? (Y/N, default N): " -e add_multiple_users
2023-08-30 16:56:50 +08:00
if [[ -z "$add_multiple_users" ]]; then
add_multiple_users="N"
2023-08-17 17:46:42 +08:00
fi
2023-10-09 11:28:46 +08:00
if [[ "$add_multiple_users" == "N" || "$add_multiple_users" == "n" ]]; then
2023-11-12 17:47:06 +08:00
users+="\n {\n \"name\": \"$user_name\",\n \"password\": \"$stls_password\"\n }"
2023-08-17 17:46:42 +08:00
break
2023-10-09 11:28:46 +08:00
elif [[ "$add_multiple_users" == "Y" || "$add_multiple_users" == "y" ]]; then
2023-11-12 17:47:06 +08:00
users+="\n {\n \"name\": \"$user_name\",\n \"password\": \"$stls_password\"\n },"
2023-10-09 11:28:46 +08:00
continue
2023-08-30 16:56:50 +08:00
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid input, please try again!${NC}"
2023-08-30 16:56:50 +08:00
fi
done
2023-08-17 17:46:42 +08:00
}
2024-01-02 02:21:44 +08:00
function generate_transport_config() {
2023-11-12 17:47:06 +08:00
if [[ "$transport_ws" = true ]]; then
2024-01-02 02:21:44 +08:00
read -p "Please enter the ws path (default: randomly generated): " transport_path_input
2023-08-17 17:46:42 +08:00
transport_path=${transport_path_input:-/$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 8)}
if [[ ! "$transport_path" =~ ^/ ]]; then
transport_path="/$transport_path"
fi
2023-11-12 17:47:06 +08:00
transport_config="\n \"transport\": {\n \"type\": \"ws\",\n \"path\": \"$transport_path\",\n \"max_early_data\": 2048,\n \"early_data_header_name\": \"Sec-WebSocket-Protocol\"\n },"
2023-11-14 14:20:52 +08:00
elif [[ "$transport_httpupgrade" = true ]]; then
transport_path=${transport_path_input:-/$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 8)}
if [[ ! "$transport_path" =~ ^/ ]]; then
transport_path="/$transport_path"
fi
transport_config="\n \"transport\": {\n \"type\": \"httpupgrade\",\n \"path\": \"$transport_path\"\n },"
2023-11-12 17:47:06 +08:00
elif [[ "$transport_grpc" = true ]]; then
2023-09-21 16:15:36 +08:00
service_name=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 8)
2023-11-12 17:47:06 +08:00
transport_config="\n \"transport\": {\n \"type\": \"grpc\",\n \"service_name\": \"$service_name\"\n },"
elif [[ "$transport_http" = true ]]; then
transport_config="\n \"transport\": {\n \"type\": \"http\"\n },"
2023-10-12 13:39:59 +08:00
else
2024-01-02 02:21:44 +08:00
transport_config=""
2023-09-26 17:09:50 +08:00
fi
}
2023-10-12 13:39:59 +08:00
function generate_tls_config() {
2023-11-12 17:47:06 +08:00
if [[ "$tls_enabled" = true ]]; then
set_ech_config
select_certificate_option
2023-09-26 17:09:50 +08:00
fi
2023-10-12 13:39:59 +08:00
if [ -z "$domain_name" ]; then
if [ -n "$domain" ]; then
server_name="$domain"
fi
else
server_name="$domain_name"
fi
2024-01-02 02:21:44 +08:00
2023-11-12 17:47:06 +08:00
if [[ "$tls_enabled" = true ]]; then
tls_config=",\n \"tls\": {\n \"enabled\": true,\n \"server_name\": \"$server_name\",\n \"certificate_path\": \"$certificate_path\",\n \"key_path\": \"$private_key_path\"$ech_server_config\n }"
2023-09-21 16:15:36 +08:00
fi
}
2023-11-12 17:47:06 +08:00
function set_ech_config() {
while true; do
2024-01-02 02:21:44 +08:00
read -p "Enable ECH? (Y/N, default: Y):" enable_ech
2023-11-12 17:47:06 +08:00
enable_ech="${enable_ech:-Y}"
if [[ "$enable_ech" == "y" || "$enable_ech" == "Y" ]]; then
get_ech_keys
enable_ech=true
ech_server_config=",\n \"ech\": {\n \"enabled\": true,\n \"pq_signature_schemes_enabled\": true,\n \"dynamic_record_sizing_disabled\": false,\n \"key\": [\n$ech_key\n ]\n }"
break
elif [[ "$enable_ech" == "n" || "$enable_ech" == "N" ]]; then
enable_ech=false
ech_server_config=""
break
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid input, please try again!${NC}"
2023-11-12 17:47:06 +08:00
fi
done
}
2024-01-02 02:21:44 +08:00
2023-11-12 17:47:06 +08:00
function generate_reality_config() {
if [[ "$reality_enabled" = true ]]; then
2023-10-12 13:39:59 +08:00
set_server_name
set_target_server
generate_private_key
2023-11-12 17:47:06 +08:00
set_short_ids
reality_config=",\n \"tls\": {\n \"enabled\": true,\n \"server_name\": \"$server_name\",\n \"reality\": {\n \"enabled\": true,\n \"handshake\": {\n \"server\": \"$target_server\",\n \"server_port\": 443\n },\n \"private_key\": \"$private_key\",\n \"short_id\": [$short_Ids\n ]\n }\n }"
2023-10-12 13:39:59 +08:00
fi
}
function configure_quic_obfuscation() {
while true; do
2024-01-02 02:21:44 +08:00
read -p "Enable QUIC traffic obfuscation (if your network blocks QUIC or HTTP/3 traffic, choose to enable)? (Y/N, default: N): " choice
2023-10-12 13:39:59 +08:00
choice="${choice:-N}"
if [[ "$choice" == "y" || "$choice" == "Y" ]]; then
2024-01-02 02:21:44 +08:00
read -p "Enter obfuscation password (default: randomly generated): " new_obfs_password
2023-10-12 13:39:59 +08:00
if [[ -z "$new_obfs_password" ]]; then
new_obfs_password=$(sing-box generate rand --base64 9 2>/dev/null || openssl rand -base64 9)
fi
2023-11-12 17:47:06 +08:00
obfs_config="\n \"obfs\": {\n \"type\": \"salamander\",\n \"password\": \"$new_obfs_password\"\n },"
2023-10-12 13:39:59 +08:00
obfs_password="$new_obfs_password"
2024-01-02 02:21:44 +08:00
echo "Obfuscation password: $obfs_password"
2023-10-12 13:39:59 +08:00
break
elif [[ "$choice" == "n" || "$choice" == "N" ]]; then
obfs_config=""
break
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid input, please try again!${NC}"
2023-10-12 13:39:59 +08:00
fi
done
}
function configure_obfuscation() {
while true; do
2024-01-02 02:21:44 +08:00
read -p "Enable obfuscation (used to bypass targeted DPI blocking or QoS)? (Y/N, default: N): " choice
2023-10-12 13:39:59 +08:00
choice="${choice:-N}"
if [[ "$choice" == "y" || "$choice" == "Y" ]]; then
2024-01-02 02:21:44 +08:00
read -p "Enter obfuscation password (default: randomly generated): " new_obfs_password
2023-10-12 13:39:59 +08:00
if [[ -z "$new_obfs_password" ]]; then
new_obfs_password=$(sing-box generate rand --base64 9 2>/dev/null || openssl rand -base64 9)
fi
2023-11-12 17:47:06 +08:00
obfs_config="\n \"obfs\": \"$new_obfs_password\","
2023-10-12 13:39:59 +08:00
obfs_password="$new_obfs_password"
2024-01-02 02:21:44 +08:00
echo "Obfuscation password: $obfs_password"
2023-10-12 13:39:59 +08:00
break
elif [[ "$choice" == "n" || "$choice" == "N" ]]; then
obfs_config=""
break
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid input, please try again!${NC}"
2023-10-12 13:39:59 +08:00
fi
done
}
2023-11-12 17:47:06 +08:00
function configure_multiplex() {
while true; do
2024-01-02 02:21:44 +08:00
read -p "Enable multiplexing? (Y/N, default: Y): " choice
2023-11-12 17:47:06 +08:00
choice="${choice:-Y}"
if [[ "$choice" == "y" || "$choice" == "Y" ]]; then
configure_brutal
multiplex_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"padding\": false$brutal_config\n }"
break
elif [[ "$choice" == "n" || "$choice" == "N" ]]; then
multiplex_config=""
break
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid input, please try again!${NC}"
2023-11-12 17:47:06 +08:00
fi
done
}
2023-10-12 13:39:59 +08:00
2023-11-12 17:47:06 +08:00
function configure_brutal() {
while true; do
2024-01-02 02:21:44 +08:00
read -p "Enable TCP Brutal? (Y/N, default: N): " choice
2023-11-12 17:47:06 +08:00
choice="${choice:-N}"
if [[ "$choice" == "y" || "$choice" == "Y" ]]; then
set_up_speed
set_down_speed
brutal_config=",\n \"brutal\": {\n \"enabled\": true,\n \"up_mbps\": $up_mbps,\n \"down_mbps\": $down_mbps\n }"
break
elif [[ "$choice" == "n" || "$choice" == "N" ]]; then
brutal_config=""
break
else
2024-01-02 02:21:44 +08:00
echo -e "${RED}Invalid input, please try again!${NC}"
2023-11-12 17:47:06 +08:00
fi
done
}
function extract_tls_info() {
local config_file="/usr/local/etc/sing-box/config.json"
local tls_info_file="/usr/local/etc/sing-box/tls_info.json"
2024-01-02 02:21:44 +08:00
jq '.inbounds[].tls | select(.server_name and .certificate_path and .key_path) | {server_name: .server_name, certificate_path: .certificate_path, key_path: .key_path}' "$config_file" | jq -s 'unique' >"$tls_info_file"
2023-11-12 17:47:06 +08:00
}
2023-10-12 13:39:59 +08:00
2023-11-12 17:47:06 +08:00
function validate_tls_info() {
local tls_info_file="/usr/local/etc/sing-box/tls_info.json"
local temp_tls_file="/usr/local/etc/sing-box/temp_tls_info.json"
server_names=($(jq -r '.[].server_name' "$tls_info_file"))
2023-10-12 13:39:59 +08:00
for server_name in "${server_names[@]}"; do
local resolved_ipv4=$(dig +short A "$server_name" 2>/dev/null)
local resolved_ipv6=$(dig +short AAAA "$server_name" 2>/dev/null)
if [[ (-n "$resolved_ipv4" && "$resolved_ipv4" == "$ip_v4") || (-n "$resolved_ipv6" && "$resolved_ipv6" == "$ip_v6") ]]; then
continue
else
2024-01-02 02:21:44 +08:00
jq 'map(select(.server_name != "'"$server_name"'"))' "$tls_info_file" >"$temp_tls_file"
2023-10-12 13:39:59 +08:00
mv "$temp_tls_file" "$tls_info_file"
fi
done
}
2023-11-14 14:20:52 +08:00
function modify_route_rules() {
local config_file="/usr/local/etc/sing-box/config.json"
local temp_config_file="/usr/local/etc/sing-box/temp_config.json"
if jq -e '.route.rules[] | select(.geosite != null)' "$config_file" >/dev/null; then
2024-01-02 02:21:44 +08:00
jq '(.route.rules |= [.[] | select(.geosite != null)] + [.[] | select(.geosite == null)])' "$config_file" >"$temp_config_file"
2023-11-14 14:20:52 +08:00
mv "$temp_config_file" "$config_file"
fi
}
2023-08-30 16:56:50 +08:00
function extract_variables_and_cleanup() {
server=$(jq -r '.server' "$temp_file")
server_port=$(jq -r '.server_port' "$temp_file")
local_address_ipv4=$(jq -r '.local_address[0]' "$temp_file")
local_address_ipv6=$(jq -r '.local_address[1]' "$temp_file")
private_key=$(jq -r '.private_key' "$temp_file")
peer_public_key=$(jq -r '.peer_public_key' "$temp_file")
reserved=$(jq -c '.reserved' "$temp_file")
mtu=$(jq -r '.mtu' "$temp_file")
rm "$temp_file"
}
2023-08-31 16:32:10 +08:00
function log_outbound_config() {
2024-01-02 02:21:44 +08:00
local config_file="/usr/local/etc/sing-box/config.json"
if ! grep -q '"log": {' "$config_file" || ! grep -q '"route": {' "$config_file" || ! grep -q '"inbounds": \[' "$config_file" || ! grep -q '"outbounds": \[' "$config_file"; then
echo -e '{\n "log": {\n },\n "route": {\n },\n "inbounds": [\n ],\n "outbounds": [\n ]\n}' >"$config_file"
sed -i '/"log": {/!b;n;c\ "disabled": false,\n "level": "info",\n "timestamp": true\n },' "$config_file"
sed -i '/"route": {/!b;n;c\ "rules": [\n ]\n },' "$config_file"
sed -i '/"outbounds": \[/!b;n;c\ {\n "type": "direct",\n "tag": "direct"\n }\n ]' "$config_file"
fi
2023-08-31 16:32:10 +08:00
}
2023-09-08 14:48:08 +08:00
function modify_format_inbounds_and_outbounds() {
2023-08-31 16:32:10 +08:00
file_path="/usr/local/etc/sing-box/config.json"
2023-09-08 14:48:08 +08:00
start_line_inbounds=$(grep -n '"inbounds": \[' "$file_path" | cut -d: -f1)
start_line_outbounds=$(grep -n '"outbounds": \[' "$file_path" | cut -d: -f1)
if [ -n "$start_line_inbounds" ]; then
line_to_modify_inbounds=$((start_line_inbounds - 3))
if [ "$line_to_modify_inbounds" -ge 1 ]; then
sed -i "$line_to_modify_inbounds s/,//" "$file_path"
fi
fi
if [ -n "$start_line_outbounds" ]; then
line_to_modify_outbounds_1=$((start_line_outbounds - 2))
line_to_modify_outbounds_2=$((start_line_outbounds - 1))
if [ "$line_to_modify_outbounds_1" -ge 1 ]; then
sed -i "$line_to_modify_outbounds_1 s/.*/ }/" "$file_path"
sed -i "$line_to_modify_outbounds_2 s/.*/ ],/" "$file_path"
2023-08-31 16:32:10 +08:00
fi
fi
}
2023-08-30 16:56:50 +08:00
2023-11-12 17:47:06 +08:00
function generate_http_config() {
local config_file="/usr/local/etc/sing-box/config.json"
local cert_path="$certificate_path"
local key_path="$private_key_path"
tls_enabled=true
local tag_label
2024-01-02 02:21:44 +08:00
generate_unique_tag
2023-11-12 17:47:06 +08:00
set_listen_port
socks_naive_multiple_users
get_local_ip
generate_tls_config
local found_rules=0
local found_inbounds=0
awk -v tag_label="$tag_label" -v listen_port="$listen_port" -v users="$users" -v tls_config="$tls_config" '
/"rules": \[/{found_rules=1}
/"inbounds": \[/{found_inbounds=1}
{print}
found_rules && /"rules": \[/{print " {"; print " \"inbound\": [\"" tag_label "\"],"; print " \"outbound\": \"direct\""; print " },"; found_rules=0}
found_inbounds && /"inbounds": \[/{print " {"; print " \"type\": \"http\","; print " \"tag\": \"" tag_label "\","; print " \"listen\": \"::\","; print " \"listen_port\": " listen_port ","; print " \"sniff\": true,"; print " \"sniff_override_destination\": true,"; print " \"set_system_proxy\": false,"; print " \"users\": [" users ""; print " ]" tls_config ""; print " },"; found_inbounds=0}
2024-01-02 02:21:44 +08:00
' "$config_file" >"$config_file.tmp"
2023-11-12 17:47:06 +08:00
mv "$config_file.tmp" "$config_file"
}
2023-08-19 17:45:08 +08:00
function generate_Direct_config() {
2023-07-29 12:09:39 +08:00
local config_file="/usr/local/etc/sing-box/config.json"
2023-09-05 18:13:52 +08:00
local tag_label
generate_unique_tag
2023-09-08 14:48:08 +08:00
local found_rules=0
local found_inbounds=0
2023-09-05 18:13:52 +08:00
awk -v tag_label="$tag_label" -v listen_port="$listen_port" -v target_address="$target_address" -v override_port="$override_port" '
2023-09-08 14:48:08 +08:00
/"rules": \[/{found_rules=1}
/"inbounds": \[/{found_inbounds=1}
2023-08-31 16:32:10 +08:00
{print}
2023-09-08 14:48:08 +08:00
found_rules && /"rules": \[/{print " {"; print " \"inbound\": [\"" tag_label "\"],"; print " \"outbound\": \"direct\""; print " },"; found_rules=0}
2023-09-12 17:21:05 +08:00
found_inbounds && /"inbounds": \[/{print " {"; print " \"type\": \"direct\","; print " \"tag\": \"" tag_label "\","; print " \"listen\": \"::\","; print " \"listen_port\": " listen_port ","; print " \"sniff\": true,"; print " \"sniff_override_destination\": true,"; print " \"sniff_timeout\": \"300ms\","; print " \"proxy_protocol\": false,"; print " \"override_address\": \"" target_address "\","; print " \"override_port\": " override_port; print " },"; found_inbounds=0}
2024-01-02 02:21:44 +08:00
' "$config_file" >"$config_file.tmp"
2023-08-31 16:32:10 +08:00
mv "$config_file.tmp" "$config_file"
2023-07-29 12:09:39 +08:00
}
2023-08-19 17:45:08 +08:00
function generate_ss_config() {
2023-07-29 12:09:39 +08:00
local config_file="/usr/local/etc/sing-box/config.json"
2023-09-05 18:13:52 +08:00
local tag_label
2023-09-08 14:48:08 +08:00
generate_unique_tag
2023-11-12 17:47:06 +08:00
configure_multiplex
2023-09-08 14:48:08 +08:00
local found_rules=0
local found_inbounds=0
2023-11-12 17:47:06 +08:00
awk -v tag_label="$tag_label" -v listen_port="$listen_port" -v ss_method="$ss_method" -v ss_password="$ss_password" -v multiplex_config="$multiplex_config" '
2023-09-08 14:48:08 +08:00
/"rules": \[/{found_rules=1}
/"inbounds": \[/{found_inbounds=1}
2023-08-31 16:32:10 +08:00
{print}
2023-09-08 14:48:08 +08:00
found_rules && /"rules": \[/{print " {"; print " \"inbound\": [\"" tag_label "\"],"; print " \"outbound\": \"direct\""; print " },"; found_rules=0}
2023-11-12 17:47:06 +08:00
found_inbounds && /"inbounds": \[/{print " {"; print " \"type\": \"shadowsocks\","; print " \"tag\": \"" tag_label "\","; print " \"listen\": \"::\","; print " \"listen_port\": " listen_port ","; print " \"sniff\": true,"; print " \"sniff_override_destination\": true,"; print " \"method\": \"" ss_method "\","; print " \"password\": \"" ss_password "\"" multiplex_config ""; print " },"; found_inbounds=0}
2024-01-02 02:21:44 +08:00
' "$config_file" >"$config_file.tmp"
2023-08-31 16:32:10 +08:00
mv "$config_file.tmp" "$config_file"
2023-07-29 15:12:16 +08:00
}
2023-09-19 16:37:08 +08:00
function generate_vmess_config() {
local config_file="/usr/local/etc/sing-box/config.json"
2023-10-09 11:28:46 +08:00
local cert_path="$certificate_path"
2024-01-02 02:21:44 +08:00
local key_path="$private_key_path"
2023-09-19 16:37:08 +08:00
local tag_label
generate_unique_tag
2024-01-02 02:21:44 +08:00
select_vmess_type
set_listen_port
vmess_multiple_users
2023-10-12 13:39:59 +08:00
generate_transport_config
2023-11-12 17:47:06 +08:00
if [ "$transport_grpc" != true ] && [ "$transport_http" != true ]; then
configure_multiplex
fi
2023-10-12 13:39:59 +08:00
get_local_ip
2023-09-19 16:37:08 +08:00
generate_tls_config
2023-09-25 17:38:09 +08:00
check_firewall_configuration
2023-09-19 16:37:08 +08:00
local found_rules=0
2023-10-12 13:39:59 +08:00
local found_inbounds=0
2023-11-12 17:47:06 +08:00
awk -v tag_label="$tag_label" -v listen_port="$listen_port" -v users="$users" -v transport_config="$transport_config" -v tls_config="$tls_config" -v multiplex_config="$multiplex_config" '
2023-09-19 16:37:08 +08:00
/"rules": \[/{found_rules=1}
/"inbounds": \[/{found_inbounds=1}
{print}
found_rules && /"rules": \[/{print " {"; print " \"inbound\": [\"" tag_label "\"],"; print " \"outbound\": \"direct\""; print " },"; found_rules=0}
2023-11-12 17:47:06 +08:00
found_inbounds && /"inbounds": \[/{print " {"; print " \"type\": \"vmess\","; print " \"tag\": \"" tag_label "\","; print " \"listen\": \"::\","; print " \"listen_port\": " listen_port ","; print " \"sniff\": true,"; print " \"sniff_override_destination\": true," transport_config ""; print " \"users\": [" users ""; print " ]" tls_config "" multiplex_config ""; print " },"; found=0}
2024-01-02 02:21:44 +08:00
' "$config_file" >"$config_file.tmp"
2023-09-19 16:37:08 +08:00
mv "$config_file.tmp" "$config_file"
2024-01-02 02:21:44 +08:00
}
2023-09-19 16:37:08 +08:00
2023-09-18 16:36:33 +08:00
function generate_socks_config() {
local config_file="/usr/local/etc/sing-box/config.json"
local tag_label
generate_unique_tag
2024-01-02 02:21:44 +08:00
set_listen_port
socks_naive_multiple_users
2023-09-18 16:36:33 +08:00
local found_rules=0
local found_inbounds=0
awk -v tag_label="$tag_label" -v listen_port="$listen_port" -v users="$users" '
/"rules": \[/{found_rules=1}
/"inbounds": \[/{found_inbounds=1}
{print}
found_rules && /"rules": \[/{print " {"; print " \"inbound\": [\"" tag_label "\"],"; print " \"outbound\": \"direct\""; print " },"; found_rules=0}
2023-10-09 11:28:46 +08:00
found_inbounds && /"inbounds": \[/{print " {"; print " \"type\": \"socks\","; print " \"tag\": \"" tag_label "\","; print " \"listen\": \"::\","; print " \"listen_port\": " listen_port ","; print " \"sniff\": true,"; print " \"sniff_override_destination\": true,"; print " \"users\": [" users ""; print " ]"; print " },"; found_inbounds=0}
2024-01-02 02:21:44 +08:00
' "$config_file" >"$config_file.tmp"
2023-09-18 16:36:33 +08:00
mv "$config_file.tmp" "$config_file"
}
2023-08-19 17:45:08 +08:00
function generate_naive_config() {
2023-08-30 16:56:50 +08:00
local config_file="/usr/local/etc/sing-box/config.json"
2023-10-12 13:39:59 +08:00
disable_option=true
2023-09-05 18:13:52 +08:00
local tag_label
2024-01-02 02:21:44 +08:00
generate_unique_tag
set_listen_port
2023-10-09 11:28:46 +08:00
socks_naive_multiple_users
get_local_ip
select_certificate_option
2023-09-25 17:12:43 +08:00
local cert_path="$certificate_path"
2024-01-02 02:21:44 +08:00
local key_path="$private_key_path"
2023-09-08 14:48:08 +08:00
local found_rules=0
2023-10-12 13:39:59 +08:00
local found_inbounds=0
2023-09-05 18:13:52 +08:00
awk -v tag_label="$tag_label" -v listen_port="$listen_port" -v users="$users" -v domain="$domain" -v certificate_path="$certificate_path" -v private_key_path="$private_key_path" '
2023-09-08 14:48:08 +08:00
/"rules": \[/{found_rules=1}
/"inbounds": \[/{found_inbounds=1}
2023-08-31 16:32:10 +08:00
{print}
2023-09-08 14:48:08 +08:00
found_rules && /"rules": \[/{print " {"; print " \"inbound\": [\"" tag_label "\"],"; print " \"outbound\": \"direct\""; print " },"; found_rules=0}
2023-10-09 11:28:46 +08:00
found_inbounds && /"inbounds": \[/{print " {"; print " \"type\": \"naive\","; print " \"tag\": \"" tag_label "\","; print " \"listen\": \"::\","; print " \"listen_port\": " listen_port ","; print " \"sniff\": true,"; print " \"sniff_override_destination\": true,"; print " \"users\": [" users ""; print " ],"; print " \"tls\": {"; print " \"enabled\": true,"; print " \"server_name\": \"" domain "\","; print " \"certificate_path\": \"" certificate_path "\","; print " \"key_path\": \"" private_key_path "\""; print " }"; print " },"; found_inbounds=0}
2024-01-02 02:21:44 +08:00
' "$config_file" >"$config_file.tmp"
2023-08-31 16:32:10 +08:00
mv "$config_file.tmp" "$config_file"
2023-08-30 16:56:50 +08:00
}
function generate_tuic_config() {
local config_file="/usr/local/etc/sing-box/config.json"
2023-09-05 18:13:52 +08:00
local tag_label
2024-01-02 02:21:44 +08:00
generate_unique_tag
2023-10-09 11:28:46 +08:00
set_listen_port
2024-01-02 02:21:44 +08:00
tuic_multiple_users
2023-10-09 11:28:46 +08:00
select_congestion_control
2023-10-12 13:39:59 +08:00
get_local_ip
2023-11-12 17:47:06 +08:00
set_ech_config
2023-10-09 11:28:46 +08:00
select_certificate_option
2023-09-25 17:12:43 +08:00
local cert_path="$certificate_path"
2024-01-02 02:21:44 +08:00
local key_path="$private_key_path"
2023-09-08 14:48:08 +08:00
local found_rules=0
2023-10-12 13:39:59 +08:00
local found_inbounds=0
local server_name="$domain"
if [ -z "$domain" ]; then
server_name="$domain_name"
fi
2023-11-12 17:47:06 +08:00
awk -v tag_label="$tag_label" -v listen_port="$listen_port" -v users="$users" -v congestion_control="$congestion_control" -v server_name="$server_name" -v certificate_path="$certificate_path" -v private_key_path="$private_key_path" -v ech_server_config="$ech_server_config" '
2023-09-08 14:48:08 +08:00
/"rules": \[/{found_rules=1}
/"inbounds": \[/{found_inbounds=1}
2023-08-31 16:32:10 +08:00
{print}
2023-09-08 14:48:08 +08:00
found_rules && /"rules": \[/{print " {"; print " \"inbound\": [\"" tag_label "\"],"; print " \"outbound\": \"direct\""; print " },"; found_rules=0}
2023-11-12 17:47:06 +08:00
found_inbounds && /"inbounds": \[/{print " {"; print " \"type\": \"tuic\","; print " \"tag\": \"" tag_label "\","; print " \"listen\": \"::\","; print " \"listen_port\": " listen_port ","; print " \"sniff\": true,"; print " \"sniff_override_destination\": true,"; print " \"users\": [" users ""; print " ],"; print " \"congestion_control\": \"" congestion_control "\","; print " \"auth_timeout\": \"3s\","; print " \"zero_rtt_handshake\": false,"; print " \"heartbeat\": \"10s\","; print " \"tls\": {"; print " \"enabled\": true,"; print " \"server_name\": \"" server_name "\","; print " \"alpn\": ["; print " \"h3\""; print " ],"; print " \"certificate_path\": \"" certificate_path "\","; print " \"key_path\": \"" private_key_path "\"" ech_server_config ""; print " }"; print " },"; found_inbounds=0}
2024-01-02 02:21:44 +08:00
' "$config_file" >"$config_file.tmp"
2023-08-31 16:32:10 +08:00
mv "$config_file.tmp" "$config_file"
2023-07-29 15:12:16 +08:00
}
function generate_Hysteria_config() {
local config_file="/usr/local/etc/sing-box/config.json"
2023-09-05 18:13:52 +08:00
local tag_label
2024-01-02 02:21:44 +08:00
generate_unique_tag
2023-10-09 11:28:46 +08:00
set_listen_port
set_up_speed
2024-01-02 02:21:44 +08:00
set_down_speed
2023-10-12 13:39:59 +08:00
hysteria_multiple_users
2024-01-02 02:21:44 +08:00
configure_obfuscation
2023-11-12 17:47:06 +08:00
get_local_ip
set_ech_config
2023-10-09 11:28:46 +08:00
select_certificate_option
2023-09-25 17:12:43 +08:00
local cert_path="$certificate_path"
local key_path="$private_key_path"
2023-09-08 14:48:08 +08:00
local found_rules=0
2023-10-12 13:39:59 +08:00
local found_inbounds=0
local server_name="$domain"
if [ -z "$domain" ]; then
server_name="$domain_name"
fi
2023-11-12 17:47:06 +08:00
awk -v tag_label="$tag_label" -v listen_port="$listen_port" -v up_mbps="$up_mbps" -v down_mbps="$down_mbps" -v obfs_config="$obfs_config" -v users="$users" -v server_name="$server_name" -v certificate_path="$certificate_path" -v private_key_path="$private_key_path" -v ech_server_config="$ech_server_config" '
2023-09-08 14:48:08 +08:00
/"rules": \[/{found_rules=1}
/"inbounds": \[/{found_inbounds=1}
2023-08-31 16:32:10 +08:00
{print}
2023-09-08 14:48:08 +08:00
found_rules && /"rules": \[/{print " {"; print " \"inbound\": [\"" tag_label "\"],"; print " \"outbound\": \"direct\""; print " },"; found_rules=0}
2023-11-12 17:47:06 +08:00
found_inbounds && /"inbounds": \[/{print " {"; print " \"type\": \"hysteria\","; print " \"tag\": \"" tag_label "\","; print " \"listen\": \"::\","; print " \"listen_port\": " listen_port ","; print " \"sniff\": true,"; print " \"sniff_override_destination\": true,"; print " \"up_mbps\": " up_mbps ","; print " \"down_mbps\": " down_mbps ","obfs_config""; print " \"users\": [" users ""; print " ],"; print " \"tls\": {"; print " \"enabled\": true,"; print " \"server_name\": \"" server_name "\","; print " \"alpn\": ["; print " \"h3\""; print " ],"; print " \"certificate_path\": \"" certificate_path "\","; print " \"key_path\": \"" private_key_path "\"" ech_server_config ""; print " }"; print " },"; found_inbounds=0}
2024-01-02 02:21:44 +08:00
' "$config_file" >"$config_file.tmp"
2023-08-31 16:32:10 +08:00
mv "$config_file.tmp" "$config_file"
2023-07-29 15:12:16 +08:00
}
2023-08-19 17:45:08 +08:00
function generate_shadowtls_config() {
2023-07-29 15:12:16 +08:00
local config_file="/usr/local/etc/sing-box/config.json"
2023-09-05 18:13:52 +08:00
local tag_label
generate_unique_tag
2024-01-02 02:21:44 +08:00
tag_label1="$tag_label"
2023-09-05 18:13:52 +08:00
generate_unique_tag
2024-01-02 02:21:44 +08:00
tag_label2="$tag_label"
2023-10-09 11:28:46 +08:00
set_listen_port
select_encryption_method
shadowtls_multiple_users
set_ss_password
set_target_server
2023-11-12 17:47:06 +08:00
configure_multiplex
2023-09-08 14:48:08 +08:00
local found_rules=0
local found_inbounds=0
2023-11-12 17:47:06 +08:00
awk -v tag_label1="$tag_label1" -v tag_label2="$tag_label2" -v listen_port="$listen_port" -v users="$users" -v target_server="$target_server" -v ss_method="$ss_method" -v ss_password="$ss_password" -v multiplex_config="$multiplex_config" '
2023-09-08 14:48:08 +08:00
/"rules": \[/{found_rules=1}
/"inbounds": \[/{found_inbounds=1}
2023-08-31 16:32:10 +08:00
{print}
2023-09-08 14:48:08 +08:00
found_rules && /"rules": \[/{print " {"; print " \"inbound\": [\"" tag_label1 "\"],"; print " \"outbound\": \"direct\""; print " },"; found_rules=0}
2023-11-12 17:47:06 +08:00
found_inbounds && /"inbounds": \[/{print " {"; print " \"type\": \"shadowtls\","; print " \"tag\": \"" tag_label1 "\","; print " \"listen\": \"::\","; print " \"listen_port\": " listen_port ","; print " \"sniff\": true,"; print " \"sniff_override_destination\": true,"; print " \"version\": 3,"; print " \"users\": [" users ""; print " ],"; print " \"handshake\": {"; print " \"server\": \"" target_server "\","; print " \"server_port\": 443"; print " },"; print " \"strict_mode\": true,"; print " \"detour\": \"" tag_label2 "\""; print " },"; print " {"; print " \"type\": \"shadowsocks\","; print " \"tag\": \"" tag_label2 "\","; print " \"listen\": \"127.0.0.1\","; print " \"method\": \"" ss_method "\","; print " \"password\": \"" ss_password "\"" multiplex_config ""; print " },"; found=0}
2024-01-02 02:21:44 +08:00
' "$config_file" >"$config_file.tmp"
2023-08-31 16:32:10 +08:00
mv "$config_file.tmp" "$config_file"
2023-07-29 15:12:16 +08:00
}
2023-08-25 18:01:25 +08:00
function generate_juicity_config() {
local config_file="/usr/local/etc/juicity/config.json"
2023-10-09 11:28:46 +08:00
set_listen_port
set_uuid
set_user_password
select_congestion_control
2023-10-12 13:39:59 +08:00
get_local_ip
2023-10-09 11:28:46 +08:00
select_certificate_option
2023-09-25 17:12:43 +08:00
local cert_path="$certificate_path"
local key_path="$private_key_path"
2024-01-02 02:21:44 +08:00
awk -v listen_port="$listen_port" -v user_uuids="$user_uuids" -v user_passwords="$user_passwords" -v certificate_path="$certificate_path" -v private_key_path="$private_key_path" -v congestion_control="$congestion_control" 'BEGIN { print "{"; printf " \"listen\": \":%s\",\n", listen_port; printf " \"users\": {\n"; printf " \"%s\": \"%s\"\n", user_uuids, user_passwords; printf " },\n"; printf " \"certificate\": \"%s\",\n", certificate_path; printf " \"private_key\": \"%s\",\n", private_key_path; printf " \"congestion_control\": \"%s\",\n", congestion_control; printf " \"disable_outbound_udp443\": true,\n"; print " \"log_level\": \"info\""; print "}"}' >"$config_file"
2023-08-25 18:01:25 +08:00
}
2023-10-12 13:39:59 +08:00
function generate_vless_config() {
2023-07-29 15:12:16 +08:00
local config_file="/usr/local/etc/sing-box/config.json"
2024-01-02 02:21:44 +08:00
local tag_label
generate_unique_tag
select_vless_type
2023-10-09 11:28:46 +08:00
set_listen_port
2023-10-12 13:39:59 +08:00
vless_multiple_users
2024-01-02 02:21:44 +08:00
generate_transport_config
2023-11-12 17:47:06 +08:00
generate_reality_config
if [[ "$flow_type" != xtls-rprx-vision ]] && [[ "$transport_grpc" != true ]] && [[ "$transport_http" != true ]]; then
configure_multiplex
fi
2023-09-08 14:48:08 +08:00
local found_rules=0
2024-01-02 02:21:44 +08:00
local found_inbounds=0
2023-11-12 17:47:06 +08:00
awk -v tag_label="$tag_label" -v listen_port="$listen_port" -v users="$users" -v transport_config="$transport_config" -v reality_config="$reality_config" -v multiplex_config="$multiplex_config" '
2023-09-08 14:48:08 +08:00
/"rules": \[/{found_rules=1}
/"inbounds": \[/{found_inbounds=1}
2023-08-31 16:32:10 +08:00
{print}
2023-09-08 14:48:08 +08:00
found_rules && /"rules": \[/{print " {"; print " \"inbound\": [\"" tag_label "\"],"; print " \"outbound\": \"direct\""; print " },"; found_rules=0}
2023-11-12 17:47:06 +08:00
found_inbounds && /"inbounds": \[/{print " {"; print " \"type\": \"vless\","; print " \"tag\": \"" tag_label "\","; print " \"listen\": \"::\","; print " \"listen_port\": " listen_port ","; print " \"sniff\": true,"; print " \"sniff_override_destination\": true," transport_config ""; print " \"users\": [" users ""; print " ]"reality_config"" multiplex_config ""; print " },"; found=0}
2024-01-02 02:21:44 +08:00
' "$config_file" >"$config_file.tmp"
2023-08-31 16:32:10 +08:00
mv "$config_file.tmp" "$config_file"
2023-08-30 16:56:50 +08:00
}
2023-09-04 11:22:03 +08:00
function generate_Hy2_config() {
local config_file="/usr/local/etc/sing-box/config.json"
2023-09-05 18:13:52 +08:00
local tag_label
2024-01-02 02:21:44 +08:00
generate_unique_tag
2023-10-09 11:28:46 +08:00
set_listen_port
set_up_speed
2024-01-02 02:21:44 +08:00
set_down_speed
2023-09-04 11:22:03 +08:00
hy2_multiple_users
2023-10-12 13:39:59 +08:00
configure_quic_obfuscation
2023-10-09 11:28:46 +08:00
set_fake_domain
2023-10-12 13:39:59 +08:00
get_local_ip
2023-11-12 17:47:06 +08:00
set_ech_config
2023-10-09 11:28:46 +08:00
select_certificate_option
2023-09-25 17:12:43 +08:00
local cert_path="$certificate_path"
local key_path="$private_key_path"
2023-09-08 14:48:08 +08:00
local found_rules=0
2023-10-12 13:39:59 +08:00
local found_inbounds=0
local server_name="$domain"
if [ -z "$domain" ]; then
server_name="$domain_name"
fi
2023-11-12 17:47:06 +08:00
awk -v tag_label="$tag_label" -v listen_port="$listen_port" -v up_mbps="$up_mbps" -v down_mbps="$down_mbps" -v obfs_config="$obfs_config" -v users="$users" -v fake_domain="$fake_domain" -v server_name="$server_name" -v certificate_path="$certificate_path" -v private_key_path="$private_key_path" -v ech_server_config="$ech_server_config" '
2023-09-08 14:48:08 +08:00
/"rules": \[/{found_rules=1}
/"inbounds": \[/{found_inbounds=1}
2023-09-04 11:22:03 +08:00
{print}
2023-09-08 14:48:08 +08:00
found_rules && /"rules": \[/{print " {"; print " \"inbound\": [\"" tag_label "\"],"; print " \"outbound\": \"direct\""; print " },"; found_rules=0}
2023-11-12 17:47:06 +08:00
found_inbounds && /"inbounds": \[/{print " {"; print " \"type\": \"hysteria2\","; print " \"tag\": \"" tag_label "\","; print " \"listen\": \"::\","; print " \"listen_port\": " listen_port ","; print " \"sniff\": true,"; print " \"sniff_override_destination\": true,"; print " \"up_mbps\": " up_mbps ","; print " \"down_mbps\": " down_mbps ","obfs_config""; print " \"users\": [" users ""; print " ],"; print " \"ignore_client_bandwidth\": false,"; print " \"masquerade\": \"https://" fake_domain "\","; print " \"tls\": {"; print " \"enabled\": true,"; print " \"server_name\": \"" server_name "\","; print " \"alpn\": ["; print " \"h3\""; print " ],"; print " \"certificate_path\": \"" certificate_path "\","; print " \"key_path\": \"" private_key_path "\"" ech_server_config ""; print " }"; print " },"; found=0}
2024-01-02 02:21:44 +08:00
' "$config_file" >"$config_file.tmp"
2023-09-04 11:22:03 +08:00
mv "$config_file.tmp" "$config_file"
}
2023-08-30 16:56:50 +08:00
function generate_trojan_config() {
2024-01-02 02:21:44 +08:00
local config_file="/usr/local/etc/sing-box/config.json"
2023-09-05 18:13:52 +08:00
local tag_label
generate_unique_tag
2024-01-02 02:21:44 +08:00
select_trojan_type
2023-10-09 11:28:46 +08:00
set_listen_port
2023-09-26 17:09:50 +08:00
trojan_multiple_users
2023-10-12 13:39:59 +08:00
generate_transport_config
2023-11-12 17:47:06 +08:00
if [ "$transport_grpc" != true ] && [ "$transport_http" != true ]; then
configure_multiplex
fi
2023-10-12 13:39:59 +08:00
get_local_ip
generate_tls_config
2023-09-25 17:12:43 +08:00
local cert_path="$certificate_path"
2023-10-12 13:39:59 +08:00
local key_path="$private_key_path"
check_firewall_configuration
2023-09-08 14:48:08 +08:00
local found_rules=0
2024-01-02 02:21:44 +08:00
local found_inbounds=0
2023-11-12 17:47:06 +08:00
awk -v tag_label="$tag_label" -v listen_port="$listen_port" -v users="$users" -v transport_config="$transport_config" -v tls_config="$tls_config" -v multiplex_config="$multiplex_config" '
2023-09-08 14:48:08 +08:00
/"rules": \[/{found_rules=1}
/"inbounds": \[/{found_inbounds=1}
2023-08-31 16:32:10 +08:00
{print}
2023-09-08 14:48:08 +08:00
found_rules && /"rules": \[/{print " {"; print " \"inbound\": [\"" tag_label "\"],"; print " \"outbound\": \"direct\""; print " },"; found_rules=0}
2023-11-12 17:47:06 +08:00
found_inbounds && /"inbounds": \[/{print " {"; print " \"type\": \"trojan\","; print " \"tag\": \"" tag_label "\","; print " \"listen\": \"::\","; print " \"listen_port\": " listen_port ","; print " \"sniff\": true,"; print " \"sniff_override_destination\": true," transport_config ""; print " \"users\": [" users ""; print " ]" tls_config "" multiplex_config ""; print " },"; found=0}
2024-01-02 02:21:44 +08:00
' "$config_file" >"$config_file.tmp"
2023-08-31 16:32:10 +08:00
mv "$config_file.tmp" "$config_file"
2024-01-02 02:21:44 +08:00
}
2023-08-30 16:56:50 +08:00
function update_route_file() {
local config_file="/usr/local/etc/sing-box/config.json"
2024-01-02 02:21:44 +08:00
local geosite_list=$(
IFS=,
echo "${geosite[*]}"
)
local geosite_formatted=$(sed 's/,/,\\n /g' <<<"$geosite_list")
2024-01-02 08:03:34 +08:00
echo "Configuring WireGuard..."
2023-09-08 14:48:08 +08:00
sed -i '/"rules": \[/!b;a\
2023-08-30 16:56:50 +08:00
{\
"geosite": [\
'"$geosite_formatted"'\
],\
2023-09-08 14:48:08 +08:00
"outbound": "'"$1"'"\
},' "$config_file"
2023-08-30 16:56:50 +08:00
}
2024-01-08 06:33:24 +08:00
convert_rule_set() {
input_file="/usr/local/etc/sing-box/config.json"
temp_file="/usr/local/etc/sing-box/temp_file.json"
has_geosite=$(jq '.route.rules[0] | has("geosite")' "$input_file")
if [ "$has_geosite" == "true" ]; then
jq '.route.rules[0] |= . + {"rule_set": [.geosite[] | "geosite-\(.)"]} |
.route.rules[0] |= del(.geosite)' "$input_file" >"$temp_file"
jq '.route += {rule_set: [.route.rules[0].rule_set[] as $gs |
{
tag: ("geosite-" + $gs | sub("^geosite-"; "")),
type: "remote",
format: "binary",
url: ("https://raw.githubusercontent.com/SagerNet/sing-geosite/rule-set/" + $gs + ".srs"),
download_detour: "direct"
}
]}' "$temp_file" >"$input_file"
jq '. |= . + {
"experimental": {
"cache_file": {
"enabled": true
}
}
}' "$input_file" >"$temp_file"
mv "$temp_file" "$input_file"
fi
}
2023-08-30 16:56:50 +08:00
function update_outbound_file() {
local config_file="/usr/local/etc/sing-box/config.json"
awk -v server="$server" -v server_port="$server_port" -v local_address_ipv4="$local_address_ipv4" -v local_address_ipv6="$local_address_ipv6" -v private_key="$private_key" -v peer_public_key="$peer_public_key" -v reserved="$reserved" -v mtu="$mtu" '
2023-08-17 17:46:42 +08:00
{
2023-08-30 16:56:50 +08:00
if ($0 ~ /"outbounds": \[/) {
print $0
for (i=1; i<=4; i++) {
getline
if (i == 4) {
print "" $0 ","
} else {
print $0
}
}
2023-09-12 14:44:29 +08:00
print " {"; print " \"type\": \"direct\","; print " \"tag\": \"warp-IPv4-out\","; print " \"detour\": \"wireguard-out\","; print " \"domain_strategy\": \"ipv4_only\""; print " },"; print " {"; print " \"type\": \"direct\","; print " \"tag\": \"warp-IPv6-out\","; print " \"detour\": \"wireguard-out\","; print " \"domain_strategy\": \"ipv6_only\""; print " },"; print " {"; print " \"type\": \"wireguard\","; print " \"tag\": \"wireguard-out\","; print " \"server\": \"" server "\","; print " \"server_port\": " server_port ","; print " \"system_interface\": false,"; print " \"interface_name\": \"wg0\","; print " \"local_address\": ["; print " \"" local_address_ipv4 "\","; print " \"" local_address_ipv6 "\"" ; print " ],"; print " \"private_key\": \"" private_key "\","; print " \"peer_public_key\": \"" peer_public_key "\","; print " \"reserved\": " reserved ","; print " \"mtu\": " mtu; print " }"
2023-08-30 16:56:50 +08:00
} else {
print $0
}
}
2024-01-02 02:21:44 +08:00
' "$config_file" >"$config_file.tmp"
2023-08-30 16:56:50 +08:00
mv "$config_file.tmp" "$config_file"
2024-01-03 09:45:51 +08:00
echo "WireGuard configuration is complete."
2023-08-17 17:46:42 +08:00
}
2023-09-15 18:48:54 +08:00
function write_phone_client_file() {
2023-11-12 17:47:06 +08:00
local dir="/usr/local/etc/sing-box"
local phone_client="${dir}/phone_client.json"
if [ ! -s "${phone_client}" ]; then
2024-01-08 06:33:24 +08:00
awk 'BEGIN { print "{"; print " \"log\": {"; print " \"disabled\": false,"; print " \"level\": \"warn\","; print " \"timestamp\": true"; print " },"; print " \"dns\": {"; print " \"servers\": ["; print " {"; print " \"tag\": \"dns_proxy\","; print " \"address\": \"https://dns.google/dns-query\","; print " \"address_resolver\": \"dns_local\","; print " \"detour\": \"select\""; print " },"; print " {"; print " \"tag\": \"dns_direct\","; print " \"address\": \"https://dns.alidns.com/dns-query\","; print " \"address_resolver\": \"dns_local\","; print " \"detour\": \"direct\""; print " },"; print " {"; print " \"tag\": \"dns_block\","; print " \"address\": \"rcode://success\""; print " },"; print " {"; print " \"tag\": \"dns_fakeip\","; print " \"address\": \"fakeip\""; print " },"; print " {"; print " \"tag\": \"dns_local\","; print " \"address\": \"223.5.5.5\","; print " \"detour\": \"direct\""; print " }"; print " ],"; print " \"rules\": ["; print " {"; print " \"outbound\": \"any\","; print " \"server\": \"dns_local\""; print " },"; print " {"; print " \"geosite\": ["; print " \"category-ads-all\""; print " ],"; print " \"server\": \"dns_block\","; print " \"disable_cache\": true"; print " },"; print " {"; print " \"query_type\": ["; print " \"A\","; print " \"AAAA\""; print " ],"; print " \"server\": \"dns_fakeip\""; print " },"; print " {"; print " \"clash_mode\": \"Direct\","; print " \"server\": \"dns_direct\""; print " },"; print " {"; print " \"clash_mode\": \"Global\","; print " \"server\": \"dns_proxy\""; print " },"; print " {"; print " \"type\": \"logical\","; print " \"mode\": \"and\","; print " \"rules\": ["; print " {"; print " \"geosite\": \"geolocation-!cn\","; print " \"invert\": true"; print " },"; print " {"; print " \"geosite\": ["; print " \"cn\","; print " \"category-companies@cn\""; print " ]"; print " }"; print " ],"; print " \"server\": \"dns_direct\""; print " }"; print " ],"; print " \"final\": \"dns_proxy\","; print " \"strategy\": \"ipv4_only\","; print " \"independent_cache\": true,"; print " \"fakeip\": {"; print " \"enabled\": true,"; print " \"inet4_range\": \"198.18.0.0/15\","; print " \"inet6_range\": \"fc00::/18\""; print " }"; print " },"; print " \"route\": {"; print " \"geoip\": {"; print " \"download_url\": \"https://github.com/SagerNet/sing-geoip/releases/latest/download/geoip.db\","; print " \"download_detour\": \"select\""; print " },"; print " \"geosite\": {"; print " \"download_url\": \"https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db\","; print " \"download_detour\": \"select\""; print " },"; print " \"rules\": ["; print " {"; print " \"protocol\": \"dns\","; print " \"outbound\": \"dns-out\""; print " },"; print " {"; print " \"geoip\": \"private\","; print " \"outbound\": \"direct\""; print " },"; print " {"; print " \"clash_mode\": \"Direct\","; print " \"outbound\": \"direct\""; print " },"; print " {"; print " \"clash_mode\": \"Global\","; print " \"outbound\": \"select\""; print " },"; print " {"; print " \"type\": \"logical\","; print " \"mode\": \"and\","; print " \"rules\": ["; print " {"; print " \"geosite\": \"geolocation-!cn\","; print " \"invert\": true"; print " },"; print " {"; print " \"geosite\": ["; print " \"cn\","; print " \"category-companies@cn\""; print "
2024-01-02 02:21:44 +08:00
fi
2023-07-29 15:33:43 +08:00
}
2023-09-15 18:48:54 +08:00
function write_win_client_file() {
2023-11-12 17:47:06 +08:00
local dir="/usr/local/etc/sing-box"
local win_client="${dir}/win_client.json"
if [ ! -s "${win_client}" ]; then
2024-01-08 06:33:24 +08:00
awk 'BEGIN { print "{"; print " \"log\": {"; print " \"disabled\": false,"; print " \"level\": \"warn\","; print " \"timestamp\": true"; print " },"; print " \"dns\": {"; print " \"servers\": ["; print " {"; print " \"tag\": \"dns_proxy\","; print " \"address\": \"https://dns.google/dns-query\","; print " \"address_resolver\": \"dns_local\","; print " \"detour\": \"select\""; print " },"; print " {"; print " \"tag\": \"dns_direct\","; print " \"address\": \"https://dns.alidns.com/dns-query\","; print " \"address_resolver\": \"dns_local\","; print " \"detour\": \"direct\""; print " },"; print " {"; print " \"tag\": \"dns_block\","; print " \"address\": \"rcode://success\""; print " },"; print " {"; print " \"tag\": \"dns_fakeip\","; print " \"address\": \"fakeip\""; print " },"; print " {"; print " \"tag\": \"dns_local\","; print " \"address\": \"223.5.5.5\","; print " \"detour\": \"direct\""; print " }"; print " ],"; print " \"rules\": ["; print " {"; print " \"outbound\": \"any\","; print " \"server\": \"dns_local\""; print " },"; print " {"; print " \"geosite\": ["; print " \"category-ads-all\""; print " ],"; print " \"server\": \"dns_block\","; print " \"disable_cache\": true"; print " },"; print " {"; print " \"query_type\": ["; print " \"A\","; print " \"AAAA\""; print " ],"; print " \"server\": \"dns_fakeip\""; print " },"; print " {"; print " \"clash_mode\": \"Direct\","; print " \"server\": \"dns_direct\""; print " },"; print " {"; print " \"clash_mode\": \"Global\","; print " \"server\": \"dns_proxy\""; print " },"; print " {"; print " \"type\": \"logical\","; print " \"mode\": \"and\","; print " \"rules\": ["; print " {"; print " \"geosite\": \"geolocation-!cn\","; print " \"invert\": true"; print " },"; print " {"; print " \"geosite\": ["; print " \"cn\","; print " \"category-companies@cn\""; print " ]"; print " }"; print " ],"; print " \"server\": \"dns_direct\""; print " }"; print " ],"; print " \"final\": \"dns_proxy\","; print " \"strategy\": \"ipv4_only\","; print " \"independent_cache\": true,"; print " \"fakeip\": {"; print " \"enabled\": true,"; print " \"inet4_range\": \"198.18.0.0/15\","; print " \"inet6_range\": \"fc00::/18\""; print " }"; print " },"; print " \"route\": {"; print " \"geoip\": {"; print " \"download_url\": \"https://github.com/SagerNet/sing-geoip/releases/latest/download/geoip.db\","; print " \"download_detour\": \"select\""; print " },"; print " \"geosite\": {"; print " \"download_url\": \"https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db\","; print " \"download_detour\": \"select\""; print " },"; print " \"rules\": ["; print " {"; print " \"protocol\": \"dns\","; print " \"outbound\": \"dns-out\""; print " },"; print " {"; print " \"geoip\": \"private\","; print " \"outbound\": \"direct\""; print " },"; print " {"; print " \"clash_mode\": \"Direct\","; print " \"outbound\": \"direct\""; print " },"; print " {"; print " \"clash_mode\": \"Global\","; print " \"outbound\": \"select\""; print " },"; print " {"; print " \"type\": \"logical\","; print " \"mode\": \"and\","; print " \"rules\": ["; print " {"; print " \"geosite\": \"geolocation-!cn\","; print " \"invert\": true"; print " },"; print " {"; print " \"geosite\": ["; print " \"cn\","; print " \"category-companies@cn\""; print "
2024-01-02 02:21:44 +08:00
fi
2023-09-15 18:48:54 +08:00
}
2023-09-24 10:05:14 +08:00
function write_clash_yaml() {
2023-11-12 17:47:06 +08:00
local dir="/usr/local/etc/sing-box"
local clash_yaml="${dir}/clash.yaml"
if [ ! -s "${clash_yaml}" ]; then
2024-01-02 02:21:44 +08:00
awk 'BEGIN { print "mixed-port: 10801"; print "allow-lan: true"; print "bind-address: \"*\""; print "find-process-mode: strict"; print "mode: rule"; print "geodata-mode: true"; print "geox-url:"; print " geoip: \"https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.dat\""; print " geosite: \"https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat\""; print " mmdb: \"https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/country.mmdb\""; print "log-level: info"; print "ipv6: true"; print "global-client-fingerprint: chrome"; print "tun:"; print " enable: true"; print " stack: system"; print " dns-hijack:"; print " - 0.0.0.0:53"; print " auto-detect-interface: true"; print " auto-route: true"; print " mtu: 9000"; print "profile:"; print " store-selected: false"; print " store-fake-ip: true"; print "sniffer:"; print " enable: true"; print " override-destination: false"; print " sniff:"; print " TLS:"; print " ports: [443, 8443]"; print " HTTP:"; print " ports: [80, 8080-8880]"; print " override-destination: true"; print "dns:"; print " enable: true"; print " prefer-h3: true"; print " listen: 0.0.0.0:53"; print " ipv6: true"; print " ipv6-timeout: 300"; print " default-nameserver:"; print " - 223.5.5.5"; print " enhanced-mode: fake-ip"; print " fake-ip-range: 198.18.0.1/16"; print " nameserver:"; print " - https://doh.pub/dns-query"; print " - https://dns.alidns.com/dns-query"; print " fallback:"; print " - https://dns.google/dns-query"; print " - https://1.1.1.1/dns-query"; print " fallback-filter:"; print " geoip: true"; print " geoip-code: CN"; print " geosite:"; print " - gfw"; print " ipcidr:"; print " - 240.0.0.0/4"; print " domain:"; print " - \"+.google.com\""; print " - \"+.facebook.com\""; print " - \"+.youtube.com\""; print " nameserver-policy:"; print " \"geosite:cn,private\":"; print " - https://doh.pub/dns-query"; print " - https://dns.alidns.com/dns-query"; print " \"geosite:category-ads-all\": rcode://success"; print "proxies:"; print "proxy-groups:"; print " - name: Proxy"; print " type: select"; print " proxies:"; print " - auto"; print " - name: auto"; print " type: url-test"; print " proxies:"; print " url: \"https://cp.cloudflare.com/generate_204\""; print " interval: 300"; print "rules:"; print " - GEOSITE,private,DIRECT"; print " - GEOSITE,category-ads-all,REJECT"; print " - GEOSITE,cn,DIRECT"; print " - GEOIP,cn,DIRECT"; print " - MATCH,Proxy"; }' >"${clash_yaml}"
2023-11-12 17:47:06 +08:00
sed -i'' -e '/^ - "+\.google\.com"/s/"/'\''/g' "${clash_yaml}"
sed -i'' -e '/^ - "+\.facebook\.com"/s/"/'\''/g' "${clash_yaml}"
2024-01-02 02:21:44 +08:00
sed -i'' -e '/^ - "+\.youtube\.com"/s/"/'\''/g' "${clash_yaml}"
2023-11-12 17:47:06 +08:00
fi
2023-09-24 10:05:14 +08:00
}
2023-09-18 14:34:32 +08:00
function write_naive_client_file() {
local naive_client_file="$naive_client_filename"
2024-01-02 02:21:44 +08:00
awk -v naive_client_file="$naive_client_file" 'BEGIN { print "{"; print " \"listen\": \"socks://127.0.0.1:1080\","; print " \"proxy\": \"https://user_name:user_password@server_name:listen_port\""; print "}" }' >"$naive_client_file"
2023-09-18 14:34:32 +08:00
}
2023-09-15 18:48:54 +08:00
function generate_shadowsocks_win_client_config() {
2023-11-12 17:47:06 +08:00
local win_client_file="/usr/local/etc/sing-box/win_client.json"
local proxy_name
if [ -n "$multiplex_config" ] && [ -n "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false,\n \"brutal\": {\n \"enabled\": true,\n \"up_mbps\": $down_mbps,\n \"down_mbps\": $up_mbps\n }\n }"
elif [ -n "$multiplex_config" ] && [ -z "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false\n }"
2023-09-25 11:30:38 +08:00
fi
2023-11-12 17:47:06 +08:00
while true; do
proxy_name="ss-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$win_client_file"; then
break
fi
done
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v listen_port="$listen_port" -v ss_method="$ss_method" -v ss_password="$ss_password" -v multiplex_client_config="$multiplex_client_config" '
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"shadowsocks\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" local_ip "\", "; print " \"server_port\": " listen_port ","; print " \"method\": \"" ss_method "\", "; print " \"password\": \"" ss_password "\"" multiplex_client_config ""; print " },";}
2023-09-25 11:30:38 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$win_client_file" >"$win_client_file.tmp"
2023-11-12 17:47:06 +08:00
mv "$win_client_file.tmp" "$win_client_file"
2023-09-15 18:48:54 +08:00
}
function generate_shadowsocks_phone_client_config() {
2023-11-12 17:47:06 +08:00
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
local proxy_name
if [ -n "$multiplex_config" ] && [ -n "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false,\n \"brutal\": {\n \"enabled\": true,\n \"up_mbps\": $down_mbps,\n \"down_mbps\": $up_mbps\n }\n }"
elif [ -n "$multiplex_config" ] && [ -z "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false\n }"
2023-09-25 11:30:38 +08:00
fi
2023-11-12 17:47:06 +08:00
while true; do
proxy_name="ss-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$phone_client_file"; then
break
fi
2024-01-02 02:21:44 +08:00
done
2023-11-12 17:47:06 +08:00
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v listen_port="$listen_port" -v ss_method="$ss_method" -v ss_password="$ss_password" -v multiplex_client_config="$multiplex_client_config" '
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"shadowsocks\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" local_ip "\", "; print " \"server_port\": " listen_port ","; print " \"method\": \"" ss_method "\", "; print " \"password\": \"" ss_password "\"" multiplex_client_config ""; print " },";}
2023-09-25 11:30:38 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$phone_client_file" >"$phone_client_file.tmp"
2023-11-12 17:47:06 +08:00
mv "$phone_client_file.tmp" "$phone_client_file"
2023-09-15 18:48:54 +08:00
}
2023-09-24 10:05:14 +08:00
function generate_shadowsocks_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
local proxy_name
while true; do
proxy_name="ss-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v listen_port="$listen_port" -v ss_method="$ss_method" -v ss_password="$ss_password" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: ss"; print " server:", local_ip; print " port:", listen_port; print " cipher:", ss_method; print " password:", "\"" ss_password "\""; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-11-12 17:47:06 +08:00
}
function generate_juicity_win_client_config() {
local client_file="/usr/local/etc/juicity/client.json"
local server_name="$domain"
local server_value
local tls_insecure
if [ -z "$domain" ]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
else
server_value="$domain"
tls_insecure="false"
fi
2024-01-02 02:21:44 +08:00
awk -v listen_port="$listen_port" -v server_value="$server_value" -v user_uuids="$user_uuids" -v user_passwords="$user_passwords" -v server_name="$server_name" -v tls_insecure="$tls_insecure" -v congestion_control="$congestion_control" 'BEGIN { print "{"; printf " \"listen\": \":%s\",\n", 1080; printf " \"server\": \"%s:%s\",\n", server_value, listen_port; printf " \"uuid\": \"%s\",\n", user_uuids; printf " \"password\": \"%s\",\n", user_passwords; printf " \"sni\": \"%s\",\n", server_name; printf " \"allow_insecure\": %s,\n", tls_insecure; printf " \"congestion_control\": \"%s\",\n", congestion_control; printf " \"log_level\": \"info\"\n"; print "}"}' >"$client_file"
echo "The client configuration file has been saved to $client_file, please download and use it!"
2023-09-24 10:05:14 +08:00
}
2023-09-15 18:48:54 +08:00
function generate_tuic_phone_client_config() {
2023-11-12 17:47:06 +08:00
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
local server_name="$domain"
local proxy_name
local server_value
local tls_insecure
if [ -z "$domain" ]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
else
server_value="$domain"
tls_insecure="false"
2023-09-25 11:30:38 +08:00
fi
2023-11-12 17:47:06 +08:00
if [ -n "$ech_config" ]; then
ech_client_config=",\n \"ech\": {\n \"enabled\": true,\n \"pq_signature_schemes_enabled\": true,\n \"dynamic_record_sizing_disabled\": false,\n \"config\": [\n$ech_config\n ]\n }"
fi
while true; do
proxy_name="tuic-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$phone_client_file"; then
break
fi
done
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v user_password="$user_password" -v congestion_control="$congestion_control" -v tls_insecure="$tls_insecure" -v ech_client_config="$ech_client_config" '
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"tuic\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" server_value "\", "; print " \"server_port\": " listen_port ","; print " \"uuid\": \"" user_uuid "\", "; print " \"password\": \"" user_password "\", "; print " \"congestion_control\": \""congestion_control"\","; print " \"udp_relay_mode\": \"native\","; print " \"zero_rtt_handshake\": false,"; print " \"heartbeat\": \"10s\","; print " \"tls\": {"; print " \"enabled\": true,"; print " \"insecure\": " tls_insecure ","; print " \"server_name\": \"" server_name "\", "; print " \"alpn\": ["; print " \"h3\""; print " ]" ech_client_config ""; print " }"; print " },";}
2023-09-25 11:30:38 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$phone_client_file" >"$phone_client_file.tmp"
2023-11-12 17:47:06 +08:00
mv "$phone_client_file.tmp" "$phone_client_file"
2023-09-15 18:48:54 +08:00
}
function generate_tuic_win_client_config() {
2023-11-12 17:47:06 +08:00
local win_client_file="/usr/local/etc/sing-box/win_client.json"
local server_name="$domain"
local proxy_name
local server_value
local tls_insecure
if [ -z "$domain" ]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
else
server_value="$domain"
tls_insecure="false"
2023-09-25 11:30:38 +08:00
fi
2023-11-12 17:47:06 +08:00
if [ -n "$ech_config" ]; then
ech_client_config=",\n \"ech\": {\n \"enabled\": true,\n \"pq_signature_schemes_enabled\": true,\n \"dynamic_record_sizing_disabled\": false,\n \"config\": [\n$ech_config\n ]\n }"
fi
while true; do
proxy_name="tuic-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$win_client_file"; then
break
fi
done
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v user_password="$user_password" -v congestion_control="$congestion_control" -v tls_insecure="$tls_insecure" -v ech_client_config="$ech_client_config" '
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"tuic\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" server_value "\", "; print " \"server_port\": " listen_port ","; print " \"uuid\": \"" user_uuid "\", "; print " \"password\": \"" user_password "\", "; print " \"congestion_control\": \""congestion_control"\","; print " \"udp_relay_mode\": \"native\","; print " \"zero_rtt_handshake\": false,"; print " \"heartbeat\": \"10s\","; print " \"tls\": {"; print " \"enabled\": true,"; print " \"insecure\": " tls_insecure ","; print " \"server_name\": \"" server_name "\", "; print " \"alpn\": ["; print " \"h3\""; print " ]" ech_client_config ""; print " }"; print " },";}
2023-09-25 11:30:38 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$win_client_file" >"$win_client_file.tmp"
2023-11-12 17:47:06 +08:00
mv "$win_client_file.tmp" "$win_client_file"
2023-09-15 18:48:54 +08:00
}
2023-09-24 10:05:14 +08:00
function generate_tuic_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
local server_name="$domain"
local proxy_name
local server_value
local tls_insecure
if [ -z "$domain" ]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
else
server_value="$domain"
tls_insecure="false"
fi
while true; do
proxy_name="tuic-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v user_password="$user_password" -v congestion_control="$congestion_control" -v tls_insecure="$tls_insecure" '/^proxies:$/ {print; print " - name: " proxy_name; print " server:", server_value; print " port:", listen_port; print " type: tuic"; print " uuid:", user_uuid; print " password:", user_password; print " sni:", server_name; print " alpn: [h3]"; print " request-timeout: 8000"; print " udp-relay-mode: native"; print " skip-cert-verify:", tls_insecure; print " congestion-controller:", congestion_control; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-09-24 10:05:14 +08:00
}
2023-09-18 16:36:33 +08:00
function generate_socks_win_client_config() {
2023-11-12 17:47:06 +08:00
local win_client_file="/usr/local/etc/sing-box/win_client.json"
local proxy_name
while true; do
proxy_name="socks-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$win_client_file"; then
break
fi
done
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v listen_port="$listen_port" -v user_name="$user_name" -v user_password="$user_password" '
2023-10-09 11:28:46 +08:00
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"socks\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" local_ip "\", "; print " \"server_port\": " listen_port ","; print " \"username\": \"" user_name "\", "; print " \"password\": \"" user_password "\" "; print " },";}
2023-09-25 11:30:38 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$win_client_file" >"$win_client_file.tmp"
2023-11-12 17:47:06 +08:00
mv "$win_client_file.tmp" "$win_client_file"
2023-09-18 16:36:33 +08:00
}
function generate_socks_phone_client_config() {
2023-11-12 17:47:06 +08:00
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
local proxy_name
while true; do
proxy_name="socks-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$phone_client_file"; then
break
fi
done
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v listen_port="$listen_port" -v user_name="$user_name" -v user_password="$user_password" '
2023-10-09 11:28:46 +08:00
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"socks\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" local_ip "\", "; print " \"server_port\": " listen_port ","; print " \"username\": \"" user_name "\", "; print " \"password\": \"" user_password "\" "; print " },";}
2023-09-25 11:30:38 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$phone_client_file" >"$phone_client_file.tmp"
2023-11-12 17:47:06 +08:00
mv "$phone_client_file.tmp" "$phone_client_file"
2023-09-18 16:36:33 +08:00
}
2023-09-24 10:05:14 +08:00
function generate_socks_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
local proxy_name
while true; do
proxy_name="socks-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v listen_port="$listen_port" -v user_name="$user_name" -v user_password="$user_password" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: socks5"; print " server:", local_ip; print " port:", listen_port; print " username:", user_name; print " password:", user_password; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-09-24 10:05:14 +08:00
}
2023-09-15 18:48:54 +08:00
function generate_Hysteria_win_client_config() {
2023-11-12 17:47:06 +08:00
local win_client_file="/usr/local/etc/sing-box/win_client.json"
local server_name="$domain"
local proxy_name
local server_value
local tls_insecure
if [ -z "$domain" ]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
else
server_value="$domain"
tls_insecure="false"
2023-09-25 11:30:38 +08:00
fi
2023-11-12 17:47:06 +08:00
if [ -n "$obfs_password" ]; then
obfs_config="\n \"obfs\": \"$obfs_password\","
fi
if [ -n "$ech_config" ]; then
ech_client_config=",\n \"ech\": {\n \"enabled\": true,\n \"pq_signature_schemes_enabled\": true,\n \"dynamic_record_sizing_disabled\": false,\n \"config\": [\n$ech_config\n ]\n }"
fi
while true; do
proxy_name="Hysteria-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$win_client_file"; then
break
fi
done
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v up_mbps="$up_mbps" -v down_mbps="$down_mbps" -v obfs_config="$obfs_config" -v user_password="$user_password" -v tls_insecure="$tls_insecure" -v ech_client_config="$ech_client_config" '
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"hysteria\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" server_value "\", "; print " \"server_port\": " listen_port ","; print " \"up_mbps\": " down_mbps ", "; print " \"down_mbps\": " up_mbps ","obfs_config""; print " \"auth_str\": \""user_password"\","; print " \"tls\": {"; print " \"enabled\": true,"; print " \"insecure\": " tls_insecure ","; print " \"server_name\": \"" server_name "\", "; print " \"alpn\": ["; print " \"h3\""; print " ]" ech_client_config ""; print " }"; print " },";}
2023-09-25 11:30:38 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$win_client_file" >"$win_client_file.tmp"
2023-11-12 17:47:06 +08:00
mv "$win_client_file.tmp" "$win_client_file"
2023-09-15 18:48:54 +08:00
}
function generate_Hysteria_phone_client_config() {
2023-11-12 17:47:06 +08:00
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
local server_name="$domain"
local proxy_name
local server_value
local tls_insecure
if [ -z "$domain" ]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
else
server_value="$domain"
tls_insecure="false"
2023-09-25 11:30:38 +08:00
fi
2023-11-12 17:47:06 +08:00
if [ -n "$obfs_password" ]; then
obfs_config="\n \"obfs\": \"$obfs_password\","
fi
if [ -n "$ech_config" ]; then
ech_client_config=",\n \"ech\": {\n \"enabled\": true,\n \"pq_signature_schemes_enabled\": true,\n \"dynamic_record_sizing_disabled\": false,\n \"config\": [\n$ech_config\n ]\n }"
fi
while true; do
proxy_name="Hysteria-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$phone_client_file"; then
break
fi
done
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v up_mbps="$up_mbps" -v down_mbps="$down_mbps" -v obfs_config="$obfs_config" -v user_password="$user_password" -v tls_insecure="$tls_insecure" -v ech_client_config="$ech_client_config" '
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"hysteria\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" server_value "\", "; print " \"server_port\": " listen_port ","; print " \"up_mbps\": " down_mbps ", "; print " \"down_mbps\": " up_mbps ","obfs_config""; print " \"auth_str\": \""user_password"\","; print " \"tls\": {"; print " \"enabled\": true,"; print " \"insecure\": " tls_insecure ","; print " \"server_name\": \"" server_name "\", "; print " \"alpn\": ["; print " \"h3\""; print " ]" ech_client_config ""; print " }"; print " },";}
2023-09-25 11:30:38 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$phone_client_file" >"$phone_client_file.tmp"
2023-11-12 17:47:06 +08:00
mv "$phone_client_file.tmp" "$phone_client_file"
2023-09-15 18:48:54 +08:00
}
2023-09-24 10:05:14 +08:00
function generate_Hysteria_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
local server_name="$domain"
local proxy_name
local server_value
local tls_insecure
if [ -z "$domain" ]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
else
server_value="$domain"
tls_insecure="false"
2023-09-24 10:05:14 +08:00
fi
2023-11-12 17:47:06 +08:00
if [ -n "$obfs_password" ]; then
obfs_config="
2023-10-12 13:39:59 +08:00
obfs: $obfs_password"
2023-11-12 17:47:06 +08:00
fi
2023-10-12 13:39:59 +08:00
2023-11-12 17:47:06 +08:00
while true; do
proxy_name="hysteria-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v up_mbps="$up_mbps" -v down_mbps="$down_mbps" -v user_password="$user_password" -v obfs_config="$obfs_config" -v tls_insecure="$tls_insecure" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: hysteria"; print " server:", server_value; print " port:", listen_port; print " auth-str:", user_password obfs_config; print " sni:", server_name; print " skip-cert-verify:", tls_insecure; print " alpn:"; print " - h3"; print " protocol: udp"; print " up: \"" down_mbps " Mbps\""; print " down: \"" up_mbps " Mbps\""; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-09-24 10:05:14 +08:00
}
2023-09-19 16:37:08 +08:00
function generate_vmess_win_client_config() {
2023-11-12 17:47:06 +08:00
local win_client_file="/usr/local/etc/sing-box/win_client.json"
local proxy_name
local server_name="$domain"
local server_value
local tls_insecure
if [[ -z "$domain" && -n "$domain_name" ]]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
elif [[ -z "$domain" && -z "$domain_name" ]]; then
server_value="$local_ip"
elif [[ -z "$domain_name" && -n "$domain" ]]; then
server_name="$domain"
server_value="$domain"
tls_insecure="false"
fi
if [ -n "$multiplex_config" ] && [ -n "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false,\n \"brutal\": {\n \"enabled\": true,\n \"up_mbps\": $down_mbps,\n \"down_mbps\": $up_mbps\n }\n }"
elif [ -n "$multiplex_config" ] && [ -z "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false\n }"
fi
if [ -n "$ech_config" ]; then
2024-01-02 02:21:44 +08:00
ech_client_config=",\n \"ech\": {\n \"enabled\": true,\n \"pq_signature_schemes_enabled\": true,\n \"dynamic_record_sizing_disabled\": false,\n \"config\": [\n$ech_config\n ]\n }"
2023-11-12 17:47:06 +08:00
fi
while true; do
proxy_name="vmess-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$win_client_file"; then
break
fi
done
2024-01-02 02:21:44 +08:00
if [[ -n "$domain" || -n "$domain_name" ]]; then
2023-11-12 17:47:06 +08:00
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v transport_config="$transport_config" -v tls_insecure="$tls_insecure" -v ech_client_config="$ech_client_config" -v multiplex_client_config="$multiplex_client_config" '
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"vmess\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" server_value "\", "; print " \"server_port\": " listen_port ","; print " \"uuid\": \"" user_uuid "\"," transport_config " "; print " \"tls\": {"; print " \"enabled\": true,"; print " \"insecure\": " tls_insecure ","; print " \"server_name\": \"" server_name "\"" ech_client_config ""; print " },"; print " \"security\": \"auto\","; print " \"alter_id\": 0,"; print " \"packet_encoding\": \"xudp\"" multiplex_client_config ""; print " },";}
2023-09-25 11:30:38 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$win_client_file" >"$win_client_file.tmp"
2023-11-12 17:47:06 +08:00
else
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v transport_config="$transport_config" -v multiplex_client_config="$multiplex_client_config" '
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"vmess\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" local_ip "\", "; print " \"server_port\": " listen_port ","; print " \"uuid\": \"" user_uuid "\"," transport_config " "; print " \"security\": \"auto\","; print " \"alter_id\": 0,"; print " \"packet_encoding\": \"xudp\"" multiplex_client_config ""; print " },";}
2023-09-25 11:30:38 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$win_client_file" >"$win_client_file.tmp"
2023-11-12 17:47:06 +08:00
fi
mv "$win_client_file.tmp" "$win_client_file"
2023-09-19 16:37:08 +08:00
}
function generate_vmess_phone_client_config() {
2023-11-12 17:47:06 +08:00
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
local proxy_name
local server_name="$domain"
local server_value
local tls_insecure
if [[ -z "$domain" && -n "$domain_name" ]]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
elif [[ -z "$domain" && -z "$domain_name" ]]; then
server_value="$local_ip"
elif [[ -z "$domain_name" && -n "$domain" ]]; then
server_name="$domain"
server_value="$domain"
tls_insecure="false"
2023-09-25 11:30:38 +08:00
fi
2023-11-12 17:47:06 +08:00
if [ -n "$multiplex_config" ] && [ -n "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false,\n \"brutal\": {\n \"enabled\": true,\n \"up_mbps\": $down_mbps,\n \"down_mbps\": $up_mbps\n }\n }"
elif [ -n "$multiplex_config" ] && [ -z "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false\n }"
fi
if [ -n "$ech_config" ]; then
ech_client_config=",\n \"ech\": {\n \"enabled\": true,\n \"pq_signature_schemes_enabled\": true,\n \"dynamic_record_sizing_disabled\": false,\n \"config\": [\n$ech_config\n ]\n }"
fi
while true; do
proxy_name="vmess-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$phone_client_file"; then
break
fi
done
2024-01-02 02:21:44 +08:00
if [[ -n "$domain" || -n "$domain_name" ]]; then
2023-11-12 17:47:06 +08:00
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v transport_config="$transport_config" -v tls_insecure="$tls_insecure" -v ech_client_config="$ech_client_config" -v multiplex_client_config="$multiplex_client_config" '
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"vmess\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" server_value "\", "; print " \"server_port\": " listen_port ","; print " \"uuid\": \"" user_uuid "\"," transport_config " "; print " \"tls\": {"; print " \"enabled\": true,"; print " \"insecure\": " tls_insecure ","; print " \"server_name\": \"" server_name "\"" ech_client_config ""; print " },"; print " \"security\": \"auto\","; print " \"alter_id\": 0,"; print " \"packet_encoding\": \"xudp\"" multiplex_client_config ""; print " },";}
2023-09-25 11:30:38 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$phone_client_file" >"$phone_client_file.tmp"
2023-11-12 17:47:06 +08:00
else
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v transport_config="$transport_config" -v multiplex_client_config="$multiplex_client_config" '
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"vmess\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" local_ip "\", "; print " \"server_port\": " listen_port ","; print " \"uuid\": \"" user_uuid "\"," transport_config " "; print " \"security\": \"auto\","; print " \"alter_id\": 0,"; print " \"packet_encoding\": \"xudp\"" multiplex_client_config ""; print " },";}
2023-10-12 13:39:59 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$phone_client_file" >"$phone_client_file.tmp"
fi
2023-11-12 17:47:06 +08:00
mv "$phone_client_file.tmp" "$phone_client_file"
2023-09-19 16:37:08 +08:00
}
2023-09-24 10:05:14 +08:00
function generate_vmess_tcp_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
local proxy_name
while true; do
proxy_name="vmess-tcp-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v listen_port="$listen_port" -v user_uuid="$user_uuid" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: vmess"; print " server:", local_ip; print " port:", listen_port; print " uuid:", user_uuid; print " alterId: 0"; print " cipher: auto"; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-09-24 10:05:14 +08:00
}
function generate_vmess_tcp_tls_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
local server_name="$domain"
local proxy_name
local server_value
local tls_insecure
if [ -z "$domain" ]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
else
server_value="$domain"
tls_insecure="false"
2023-09-24 10:05:14 +08:00
fi
2023-11-12 17:47:06 +08:00
while true; do
proxy_name="vmess-tcp-tls-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v tls_insecure="$tls_insecure" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: vmess"; print " server:", server_value; print " port:", listen_port; print " uuid:", user_uuid; print " alterId: 0"; print " cipher: auto"; print " tls: true"; print " skip-cert-verify:", tls_insecure; print " servername: " server_name; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-09-24 10:05:14 +08:00
}
function generate_vmess_ws_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
local proxy_name
while true; do
proxy_name="vmess-ws-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v transport_path="$transport_path" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: vmess"; print " server:", local_ip; print " port:", listen_port; print " uuid:", user_uuid; print " alterId: 0"; print " cipher: auto"; print " network: ws"; print " ws-opts:"; print " path: " transport_path; print " max-early-data: 2048"; print " early-data-header-name: Sec-WebSocket-Protocol"; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-09-24 10:05:14 +08:00
}
function generate_vmess_ws_tls_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
local server_name="$domain"
local proxy_name
local server_value
local tls_insecure
if [ -z "$domain" ]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
else
server_value="$domain"
tls_insecure="false"
2023-09-24 10:05:14 +08:00
fi
2023-11-12 17:47:06 +08:00
while true; do
proxy_name="vmess-ws-tls-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v transport_path="$transport_path" -v tls_insecure="$tls_insecure" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: vmess"; print " server:", server_value; print " port:", listen_port; print " uuid:", user_uuid; print " alterId: 0"; print " cipher: auto"; print " network: ws"; print " tls: true"; print " skip-cert-verify:", tls_insecure; print " servername:", server_name; print " ws-opts:"; print " path: " transport_path; print " max-early-data: 2048"; print " early-data-header-name: Sec-WebSocket-Protocol"; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-09-24 10:05:14 +08:00
}
function generate_vmess_grpc_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
local proxy_name
while true; do
proxy_name="vmess-grpc-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v transport_service_name="$transport_service_name" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: vmess"; print " server:", local_ip; print " port:", listen_port; print " uuid:", user_uuid; print " alterId: 0"; print " cipher: auto"; print " network: grpc"; print " grpc-opts:"; print " grpc-service-name:", "\"" transport_service_name "\""; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-09-24 10:05:14 +08:00
}
function generate_vmess_grpc_tls_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
local server_name="$domain"
local proxy_name
local server_value
local tls_insecure
if [ -z "$domain" ]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
else
server_value="$domain"
tls_insecure="false"
2023-09-24 10:05:14 +08:00
fi
2023-11-12 17:47:06 +08:00
while true; do
proxy_name="vmess-grpc-tls-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v transport_service_name="$transport_service_name" -v tls_insecure="$tls_insecure" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: vmess"; print " server:", server_value; print " port:", listen_port; print " uuid:", user_uuid; print " alterId: 0"; print " cipher: auto"; print " network: grpc"; print " tls: true"; print " skip-cert-verify:", tls_insecure; print " servername:", server_name; print " grpc-opts:"; print " grpc-service-name:", "\"" transport_service_name "\""; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-11-12 17:47:06 +08:00
}
2023-10-12 13:39:59 +08:00
2023-11-12 17:47:06 +08:00
function generate_http_phone_client_config() {
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
local server_name="$domain"
local proxy_name
local server_value
local tls_insecure
if [ -z "$domain" ]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
else
server_value="$domain"
tls_insecure="false"
fi
if [ -n "$ech_config" ]; then
ech_client_config=",\n \"ech\": {\n \"enabled\": true,\n \"pq_signature_schemes_enabled\": true,\n \"dynamic_record_sizing_disabled\": false,\n \"config\": [\n$ech_config\n ]\n }"
fi
while true; do
proxy_name="http-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$phone_client_file"; then
break
fi
done
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v user_name="$user_name" -v user_password="$user_password" -v tls_insecure="$tls_insecure" -v ech_client_config="$ech_client_config" '
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"http\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" server_value "\", "; print " \"server_port\": " listen_port ","; print " \"username\": \"" user_name "\", "; print " \"password\": \"" user_password "\","; print " \"tls\": {"; print " \"enabled\": true,"; print " \"insecure\": " tls_insecure ","; print " \"server_name\": \"" server_name "\"" ech_client_config ""; print " }"; print " },";}
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$phone_client_file" >"$phone_client_file.tmp"
2023-11-12 17:47:06 +08:00
mv "$phone_client_file.tmp" "$phone_client_file"
2023-09-24 10:05:14 +08:00
}
2023-11-12 17:47:06 +08:00
function generate_http_win_client_config() {
local win_client_file="/usr/local/etc/sing-box/win_client.json"
local server_name="$domain"
local proxy_name
local server_value
local tls_insecure
if [ -z "$domain" ]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
else
server_value="$domain"
tls_insecure="false"
2023-09-25 11:30:38 +08:00
fi
2023-11-12 17:47:06 +08:00
if [ -n "$ech_config" ]; then
ech_client_config=",\n \"ech\": {\n \"enabled\": true,\n \"pq_signature_schemes_enabled\": true,\n \"dynamic_record_sizing_disabled\": false,\n \"config\": [\n$ech_config\n ]\n }"
fi
while true; do
proxy_name="http-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$win_client_file"; then
break
fi
done
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v user_name="$user_name" -v user_password="$user_password" -v tls_insecure="$tls_insecure" -v ech_client_config="$ech_client_config" '
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"http\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" server_value "\", "; print " \"server_port\": " listen_port ","; print " \"username\": \"" user_name "\", "; print " \"password\": \"" user_password "\","; print " \"tls\": {"; print " \"enabled\": true,"; print " \"insecure\": " tls_insecure ","; print " \"server_name\": \"" server_name "\"" ech_client_config ""; print " }"; print " },";}
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$win_client_file" >"$win_client_file.tmp"
2023-11-12 17:47:06 +08:00
mv "$win_client_file.tmp" "$win_client_file"
}
2023-10-12 13:39:59 +08:00
2023-11-12 17:47:06 +08:00
function generate_http_yaml() {
local filename="/usr/local/etc/sing-box/clash.yaml"
local server_name="$domain"
local proxy_name
local server_value
local tls_insecure
if [ -z "$domain" ]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
else
server_value="$domain"
tls_insecure="false"
fi
while true; do
proxy_name="http-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v user_name="$user_name" -v user_password="$user_password" -v tls_insecure="$tls_insecure" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: http"; print " server:", server_value; print " port:", listen_port; print " username:", user_name; print " password:", user_password; print " tls: true"; print " sni:", server_name; print " skip-cert-verify:", tls_insecure; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-11-12 17:47:06 +08:00
}
2023-10-12 13:39:59 +08:00
2023-11-12 17:47:06 +08:00
function generate_Hysteria2_phone_client_config() {
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
local server_name="$domain"
local proxy_name
local server_value
local tls_insecure
if [ -z "$domain" ]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
else
server_value="$domain"
tls_insecure="false"
fi
if [ -n "$obfs_password" ]; then
obfs_config="\n \"obfs\": {\n \"type\": \"salamander\",\n \"password\": \"$obfs_password\"\n },"
fi
if [ -n "$ech_config" ]; then
ech_client_config=",\n \"ech\": {\n \"enabled\": true,\n \"pq_signature_schemes_enabled\": true,\n \"dynamic_record_sizing_disabled\": false,\n \"config\": [\n$ech_config\n ]\n }"
fi
while true; do
proxy_name="Hysteria2-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$phone_client_file"; then
break
fi
done
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v up_mbps="$up_mbps" -v down_mbps="$down_mbps" -v obfs_config="$obfs_config" -v user_password="$user_password" -v tls_insecure="$tls_insecure" -v ech_client_config="$ech_client_config" '
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"hysteria2\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" server_value "\", "; print " \"server_port\": " listen_port ","; print " \"up_mbps\": " down_mbps ", "; print " \"down_mbps\": " up_mbps ","obfs_config""; print " \"password\": \"" user_password "\","; print " \"tls\": {"; print " \"enabled\": true,"; print " \"insecure\": " tls_insecure ","; print " \"server_name\": \"" server_name "\", "; print " \"alpn\": ["; print " \"h3\""; print " ]" ech_client_config ""; print " }"; print " },";}
2023-09-25 11:30:38 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$phone_client_file" >"$phone_client_file.tmp"
2023-11-12 17:47:06 +08:00
mv "$phone_client_file.tmp" "$phone_client_file"
2023-09-15 18:48:54 +08:00
}
function generate_Hysteria2_win_client_config() {
2023-11-12 17:47:06 +08:00
local win_client_file="/usr/local/etc/sing-box/win_client.json"
local server_name="$domain"
local proxy_name
local server_value
local tls_insecure
if [ -z "$domain" ]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
else
server_value="$domain"
tls_insecure="false"
2023-09-25 11:30:38 +08:00
fi
2023-11-12 17:47:06 +08:00
if [ -n "$obfs_password" ]; then
obfs_config="\n \"obfs\": {\n \"type\": \"salamander\",\n \"password\": \"$obfs_password\"\n },"
fi
if [ -n "$ech_config" ]; then
ech_client_config=",\n \"ech\": {\n \"enabled\": true,\n \"pq_signature_schemes_enabled\": true,\n \"dynamic_record_sizing_disabled\": false,\n \"config\": [\n$ech_config\n ]\n }"
fi
while true; do
proxy_name="Hysteria2-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$win_client_file"; then
break
fi
done
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v up_mbps="$up_mbps" -v down_mbps="$down_mbps" -v obfs_config="$obfs_config" -v user_password="$user_password" -v tls_insecure="$tls_insecure" -v ech_client_config="$ech_client_config" '
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"hysteria2\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" server_value "\", "; print " \"server_port\": " listen_port ","; print " \"up_mbps\": " down_mbps ", "; print " \"down_mbps\": " up_mbps ","obfs_config""; print " \"password\": \"" user_password "\","; print " \"tls\": {"; print " \"enabled\": true,"; print " \"insecure\": " tls_insecure ","; print " \"server_name\": \"" server_name "\", "; print " \"alpn\": ["; print " \"h3\""; print " ]" ech_client_config ""; print " }"; print " },";}
2023-09-25 11:30:38 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$win_client_file" >"$win_client_file.tmp"
2023-11-12 17:47:06 +08:00
mv "$win_client_file.tmp" "$win_client_file"
2023-09-15 18:48:54 +08:00
}
2023-09-24 10:05:14 +08:00
function generate_Hysteria2_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
local server_name="$domain"
local proxy_name
local server_value
local tls_insecure
if [ -z "$domain" ]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
else
server_value="$domain"
tls_insecure="false"
2023-09-24 10:05:14 +08:00
fi
2023-11-12 17:47:06 +08:00
if [ -n "$obfs_password" ]; then
obfs_config="
2023-10-12 13:39:59 +08:00
obfs: salamander
obfs-password: $obfs_password"
2023-11-12 17:47:06 +08:00
fi
while true; do
proxy_name="hysteria2-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v up_mbps="$up_mbps" -v down_mbps="$down_mbps" -v user_password="$user_password" -v obfs_config="$obfs_config" -v tls_insecure="$tls_insecure" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: hysteria2"; print " server:", server_value; print " port:", listen_port; print " password:", user_password obfs_config; print " alpn:"; print " - h3"; print " sni:", server_name; print " skip-cert-verify:", tls_insecure; print " up: \"" down_mbps " Mbps\""; print " down: \"" up_mbps " Mbps\""; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-09-24 10:05:14 +08:00
}
2023-09-15 18:48:54 +08:00
function generate_vless_win_client_config() {
2023-11-12 17:47:06 +08:00
local win_client_file="/usr/local/etc/sing-box/win_client.json"
local proxy_name
local server_name_in_config=$(jq -r '.inbounds[0].tls.server_name' "$config_file")
if [ -n "$multiplex_config" ] && [ -n "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false,\n \"brutal\": {\n \"enabled\": true,\n \"up_mbps\": $down_mbps,\n \"down_mbps\": $up_mbps\n }\n }"
elif [ -n "$multiplex_config" ] && [ -z "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false\n }"
2023-09-25 11:30:38 +08:00
fi
2023-11-12 17:47:06 +08:00
while true; do
proxy_name="vless-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$win_client_file"; then
break
fi
done
if [ "$server_name_in_config" != "null" ]; then
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v server_name="$server_name" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v flow_type="$flow_type" -v public_key="$public_key" -v short_id="$short_id" -v transport_config="$transport_config" -v multiplex_client_config="$multiplex_client_config" '
2023-11-12 17:47:06 +08:00
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"vless\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" local_ip "\", "; print " \"server_port\": " listen_port ","; print " \"uuid\": \"" user_uuid "\", "; print " \"flow\": \"" flow_type "\"," transport_config ""; print " \"tls\": {"; print " \"enabled\": true,"; print " \"server_name\": \"" server_name "\", "; print " \"utls\": {"; print " \"enabled\": true,"; print " \"fingerprint\": \"chrome\""; print " },"; print " \"reality\": {"; print " \"enabled\": true,"; print " \"public_key\": \"" public_key "\","; print " \"short_id\": \"" short_id "\""; print " }"; print " }" multiplex_client_config ""; print " },";}
2023-10-12 13:39:59 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$win_client_file" >"$win_client_file.tmp"
2023-11-12 17:47:06 +08:00
else
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v flow_type="$flow_type" -v transport_config="$transport_config" -v multiplex_client_config="$multiplex_client_config" '
2023-11-12 17:47:06 +08:00
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"vless\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" local_ip "\", "; print " \"server_port\": " listen_port ","; print " \"uuid\": \"" user_uuid "\"," transport_config ""; print " \"flow\": \"" flow_type "\"" multiplex_client_config ""; print " },";}
2023-09-25 11:30:38 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$win_client_file" >"$win_client_file.tmp"
2023-11-12 17:47:06 +08:00
fi
mv "$win_client_file.tmp" "$win_client_file"
2023-09-15 18:48:54 +08:00
}
function generate_vless_phone_client_config() {
2023-11-12 17:47:06 +08:00
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
local proxy_name
local server_name_in_config=$(jq -r '.inbounds[0].tls.server_name' "$config_file")
if [ -n "$multiplex_config" ] && [ -n "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false,\n \"brutal\": {\n \"enabled\": true,\n \"up_mbps\": $down_mbps,\n \"down_mbps\": $up_mbps\n }\n }"
elif [ -n "$multiplex_config" ] && [ -z "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false\n }"
2023-09-25 11:30:38 +08:00
fi
2023-11-12 17:47:06 +08:00
while true; do
proxy_name="vless-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$phone_client_file"; then
break
fi
done
if [ "$server_name_in_config" != "null" ]; then
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v server_name="$server_name" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v flow_type="$flow_type" -v public_key="$public_key" -v short_id="$short_id" -v transport_config="$transport_config" -v multiplex_client_config="$multiplex_client_config" '
2023-11-12 17:47:06 +08:00
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"vless\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" local_ip "\", "; print " \"server_port\": " listen_port ","; print " \"uuid\": \"" user_uuid "\", "; print " \"flow\": \"" flow_type "\"," transport_config ""; print " \"tls\": {"; print " \"enabled\": true,"; print " \"server_name\": \"" server_name "\", "; print " \"utls\": {"; print " \"enabled\": true,"; print " \"fingerprint\": \"chrome\""; print " },"; print " \"reality\": {"; print " \"enabled\": true,"; print " \"public_key\": \"" public_key "\","; print " \"short_id\": \"" short_id "\""; print " }"; print " }" multiplex_client_config ""; print " },";}
2023-09-25 11:30:38 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$phone_client_file" >"$phone_client_file.tmp"
2023-11-12 17:47:06 +08:00
else
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v flow_type="$flow_type" -v transport_config="$transport_config" -v multiplex_client_config="$multiplex_client_config" '
2023-11-12 17:47:06 +08:00
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"vless\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" local_ip "\", "; print " \"server_port\": " listen_port ","; print " \"uuid\": \"" user_uuid "\"," transport_config ""; print " \"flow\": \"" flow_type "\"" multiplex_client_config ""; print " },";}
2023-10-12 13:39:59 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$phone_client_file" >"$phone_client_file.tmp"
2023-11-12 17:47:06 +08:00
fi
mv "$phone_client_file.tmp" "$phone_client_file"
2023-09-15 18:48:54 +08:00
}
2023-10-12 13:39:59 +08:00
function generate_vless_tcp_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
local proxy_name
while true; do
proxy_name="vless-tcp-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v listen_port="$listen_port" -v user_uuid="$user_uuid" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: vless"; print " server:", local_ip; print " port:", listen_port; print " uuid:", user_uuid; print " network: tcp"; print " udp: true"; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-10-12 13:39:59 +08:00
}
function generate_vless_ws_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
local proxy_name
while true; do
proxy_name="vless-ws-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v transport_path="$transport_path" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: vless"; print " server:", local_ip; print " port:", listen_port; print " uuid:", user_uuid; print " network: ws"; print " udp: true"; print " ws-opts:"; print " path: " transport_path; print " max-early-data: 2048"; print " early-data-header-name: Sec-WebSocket-Protocol"; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-10-12 13:39:59 +08:00
}
function generate_vless_grpc_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
local proxy_name
while true; do
proxy_name="vless-grpc-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v transport_service_name="$transport_service_name" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: vless"; print " server:", local_ip; print " port:", listen_port; print " uuid:", user_uuid; print " network: grpc"; print " udp: true"; print " grpc-opts:"; print " grpc-service-name:", "\"" transport_service_name "\""; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-10-12 13:39:59 +08:00
}
2023-09-24 10:05:14 +08:00
function generate_vless_reality_vision_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
local proxy_name
while true; do
proxy_name="vless-reality-vision-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v server_name="$server_name" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v public_key="$public_key" -v short_id="$short_id" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: vless"; print " server:", local_ip; print " port:", listen_port; print " uuid:", user_uuid; print " network: tcp"; print " udp: true"; print " tls: true"; print " flow: xtls-rprx-vision"; print " servername:", server_name; print " reality-opts:"; print " public-key:", public_key; print " short-id:", short_id; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-09-24 10:05:14 +08:00
}
function generate_vless_reality_grpc_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
2024-01-02 02:21:44 +08:00
local proxy_name
2023-11-12 17:47:06 +08:00
while true; do
proxy_name="vless-reality-grpc-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v server_name="$server_name" -v listen_port="$listen_port" -v user_uuid="$user_uuid" -v public_key="$public_key" -v short_id="$short_id" -v transport_service_name="$transport_service_name" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: vless"; print " server:", local_ip; print " port:", listen_port; print " uuid:", user_uuid; print " network: grpc"; print " udp: true"; print " tls: true"; print " flow: "; print " servername:", server_name; print " reality-opts:"; print " public-key:", public_key; print " short-id:", short_id; print " grpc-opts:"; print " grpc-service-name:", "\"" transport_service_name "\""; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-09-24 10:05:14 +08:00
}
2023-09-15 18:48:54 +08:00
function generate_trojan_phone_client_config() {
2023-11-12 17:47:06 +08:00
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
local proxy_name
local server_name="$domain"
local server_value
local tls_insecure
if [[ -z "$domain" && -n "$domain_name" ]]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
elif [[ -z "$domain" && -z "$domain_name" ]]; then
server_value="$local_ip"
elif [[ -z "$domain_name" && -n "$domain" ]]; then
server_name="$domain"
server_value="$domain"
tls_insecure="false"
2023-09-25 11:30:38 +08:00
fi
2023-11-12 17:47:06 +08:00
if [ -n "$multiplex_config" ] && [ -n "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false,\n \"brutal\": {\n \"enabled\": true,\n \"up_mbps\": $down_mbps,\n \"down_mbps\": $up_mbps\n }\n }"
elif [ -n "$multiplex_config" ] && [ -z "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false\n }"
fi
if [ -n "$ech_config" ]; then
ech_client_config=",\n \"ech\": {\n \"enabled\": true,\n \"pq_signature_schemes_enabled\": true,\n \"dynamic_record_sizing_disabled\": false,\n \"config\": [\n$ech_config\n ]\n }"
fi
while true; do
proxy_name="trojan-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$phone_client_file"; then
break
fi
done
2024-01-02 02:21:44 +08:00
if [[ -n "$domain" || -n "$domain_name" ]]; then
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v user_password="$user_password" -v transport_config="$transport_config" -v tls_insecure="$tls_insecure" -v ech_client_config="$ech_client_config" -v multiplex_client_config="$multiplex_client_config" '
2023-11-12 17:47:06 +08:00
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"trojan\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" server_value "\", "; print " \"server_port\": " listen_port ","; print " \"password\": \"" user_password "\"," transport_config " "; print " \"tls\": {"; print " \"enabled\": true,"; print " \"insecure\": " tls_insecure ","; print " \"server_name\": \"" server_name "\"" ech_client_config ""; print " }"multiplex_client_config""; print " },";}
2023-09-25 11:30:38 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$phone_client_file" >"$phone_client_file.tmp"
2023-11-12 17:47:06 +08:00
else
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v listen_port="$listen_port" -v user_password="$user_password" -v transport_config="$transport_config" -v multiplex_client_config="$multiplex_client_config" '
2023-11-12 17:47:06 +08:00
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"trojan\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" local_ip "\", "; print " \"server_port\": " listen_port "," transport_config " "; print " \"password\": \"" user_password "\""multiplex_client_config""; print " },";}
2023-10-12 13:39:59 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$phone_client_file" >"$phone_client_file.tmp"
2023-11-12 17:47:06 +08:00
fi
mv "$phone_client_file.tmp" "$phone_client_file"
2023-09-15 18:48:54 +08:00
}
function generate_trojan_win_client_config() {
2023-11-12 17:47:06 +08:00
local win_client_file="/usr/local/etc/sing-box/win_client.json"
local proxy_name
local server_name="$domain"
local server_value
local tls_insecure
if [[ -z "$domain" && -n "$domain_name" ]]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
elif [[ -z "$domain" && -z "$domain_name" ]]; then
server_value="$local_ip"
elif [[ -z "$domain_name" && -n "$domain" ]]; then
server_name="$domain"
server_value="$domain"
tls_insecure="false"
2023-09-25 11:30:38 +08:00
fi
2023-11-12 17:47:06 +08:00
if [ -n "$multiplex_config" ] && [ -n "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false,\n \"brutal\": {\n \"enabled\": true,\n \"up_mbps\": $down_mbps,\n \"down_mbps\": $up_mbps\n }\n }"
elif [ -n "$multiplex_config" ] && [ -z "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false\n }"
fi
if [ -n "$ech_config" ]; then
ech_client_config=",\n \"ech\": {\n \"enabled\": true,\n \"pq_signature_schemes_enabled\": true,\n \"dynamic_record_sizing_disabled\": false,\n \"config\": [\n$ech_config\n ]\n }"
fi
while true; do
proxy_name="trojan-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$win_client_file"; then
break
fi
done
2024-01-02 02:21:44 +08:00
if [[ -n "$domain" || -n "$domain_name" ]]; then
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v user_password="$user_password" -v transport_config="$transport_config" -v tls_insecure="$tls_insecure" -v ech_client_config="$ech_client_config" -v multiplex_client_config="$multiplex_client_config" '
2023-11-12 17:47:06 +08:00
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"trojan\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" server_value "\", "; print " \"server_port\": " listen_port ","; print " \"password\": \"" user_password "\"," transport_config " "; print " \"tls\": {"; print " \"enabled\": true,"; print " \"insecure\": " tls_insecure ","; print " \"server_name\": \"" server_name "\"" ech_client_config ""; print " }"multiplex_client_config""; print " },";}
2023-10-12 13:39:59 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$win_client_file" >"$win_client_file.tmp"
2023-11-12 17:47:06 +08:00
else
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v local_ip="$local_ip" -v listen_port="$listen_port" -v user_password="$user_password" -v transport_config="$transport_config" -v multiplex_client_config="$multiplex_client_config" '
2023-11-12 17:47:06 +08:00
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"trojan\","; print " \"tag\": \"" proxy_name "\","; print " \"server\": \"" local_ip "\", "; print " \"server_port\": " listen_port "," transport_config " "; print " \"password\": \"" user_password "\""multiplex_client_config""; print " },";}
2023-10-12 13:39:59 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$win_client_file" >"$win_client_file.tmp"
2023-11-12 17:47:06 +08:00
fi
mv "$win_client_file.tmp" "$win_client_file"
2023-09-15 18:48:54 +08:00
}
2023-10-12 13:39:59 +08:00
function generate_trojan_tcp_tls_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
local server_name="$domain"
local proxy_name
local server_value
local tls_insecure
if [ -z "$domain" ]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
else
server_value="$domain"
tls_insecure="false"
2023-09-24 10:05:14 +08:00
fi
2023-11-12 17:47:06 +08:00
while true; do
proxy_name="trojan-tcp-tls-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
2024-01-02 02:21:44 +08:00
fi
2023-11-12 17:47:06 +08:00
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v user_password="$user_password" -v tls_insecure="$tls_insecure" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: trojan"; print " server:", server_value; print " port:", listen_port; print " password:", user_password; print " udp: true"; print " sni:", server_name; print " skip-cert-verify:", tls_insecure; print " alpn:"; print " - h2"; print " - http/1.1"; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-09-24 10:05:14 +08:00
}
2023-10-12 13:39:59 +08:00
function generate_trojan_ws_tls_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
local server_name="$domain"
local proxy_name
local server_value
local tls_insecure
if [ -z "$domain" ]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
else
server_value="$domain"
tls_insecure="false"
2023-09-24 10:05:14 +08:00
fi
2023-11-12 17:47:06 +08:00
while true; do
proxy_name="trojan-ws-tls-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v user_password="$user_password" -v transport_path="$transport_path" -v tls_insecure="$tls_insecure" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: trojan"; print " server:", server_value; print " port:", listen_port; print " password:", "\"" user_password "\""; print " network: ws"; print " sni:", server_name; print " skip-cert-verify:", tls_insecure; print " udp: true"; print " ws-opts:"; print " path:", transport_path; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-09-24 10:05:14 +08:00
}
2023-10-12 13:39:59 +08:00
function generate_trojan_grpc_tls_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
local server_name="$domain"
local proxy_name
local server_value
local tls_insecure
if [ -z "$domain" ]; then
server_name="$domain_name"
server_value="$local_ip"
tls_insecure="true"
else
server_value="$domain"
tls_insecure="false"
2023-09-24 10:05:14 +08:00
fi
2023-11-12 17:47:06 +08:00
while true; do
proxy_name="trojan-grpc-tls-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v server_value="$server_value" -v server_name="$server_name" -v listen_port="$listen_port" -v user_password="$user_password" -v transport_service_name="$transport_service_name" -v tls_insecure="$tls_insecure" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: trojan"; print " server:", server_value; print " port:", listen_port; print " password:", "\"" user_password "\""; print " network: grpc"; print " sni:", server_name; print " udp: true"; print " skip-cert-verify:", tls_insecure; print " grpc-opts:"; print " grpc-service-name:", "\"" transport_service_name "\""; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-09-24 10:05:14 +08:00
}
2023-09-15 18:48:54 +08:00
function generate_shadowtls_win_client_config() {
2023-11-12 17:47:06 +08:00
local win_client_file="/usr/local/etc/sing-box/win_client.json"
local proxy_name
local shadowtls_out
if [ -n "$multiplex_config" ] && [ -n "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false,\n \"brutal\": {\n \"enabled\": true,\n \"up_mbps\": $down_mbps,\n \"down_mbps\": $up_mbps\n }\n }"
elif [ -n "$multiplex_config" ] && [ -z "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false\n }"
fi
while true; do
proxy_name="shadowtls-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
shadowtls_out="stl-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$win_client_file" && ! grep -q "name: $shadowtls_out" "$win_client_file" && [ "$proxy_name" != "$shadowtls_out" ]; then
break
fi
done
awk -v shadowtls_out="$shadowtls_out" -v proxy_name="$proxy_name" -v method="$method" -v ss_password="$ss_password" -v local_ip="$local_ip" -v listen_port="$listen_port" -v stls_password="$stls_password" -v user_input="$user_input" -v multiplex_client_config="$multiplex_client_config" '
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"shadowsocks\","; print " \"tag\": \"" proxy_name "\","; print " \"method\": \"" method "\", "; print " \"password\": \"" ss_password "\","; print " \"detour\": \"" shadowtls_out "\""multiplex_client_config""; print " },"; print " {"; print " \"type\": \"shadowtls\","; print " \"tag\": \"" shadowtls_out "\","; print " \"server\": \"" local_ip "\", "; print " \"server_port\": " listen_port ","; print " \"version\": 3, "; print " \"password\": \""stls_password"\", "; print " \"tls\": {"; print " \"enabled\": true,"; print " \"server_name\": \"" user_input "\", "; print " \"utls\": {"; print " \"enabled\": true,"; print " \"fingerprint\": \"chrome\" "; print " }"; print " }"; print " },";}
2023-09-25 11:30:38 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$win_client_file" >"$win_client_file.tmp"
2023-11-12 17:47:06 +08:00
mv "$win_client_file.tmp" "$win_client_file"
2023-09-15 18:48:54 +08:00
}
function generate_shadowtls_phone_client_config() {
2023-11-12 17:47:06 +08:00
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
local proxy_name
local shadowtls_out
if [ -n "$multiplex_config" ] && [ -n "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false,\n \"brutal\": {\n \"enabled\": true,\n \"up_mbps\": $down_mbps,\n \"down_mbps\": $up_mbps\n }\n }"
elif [ -n "$multiplex_config" ] && [ -z "$brutal_config" ]; then
multiplex_client_config=",\n \"multiplex\": {\n \"enabled\": true,\n \"protocol\": \"h2mux\",\n \"max_connections\": 1,\n \"min_streams\": 4,\n \"padding\": false\n }"
2023-09-25 11:30:38 +08:00
fi
2023-11-12 17:47:06 +08:00
while true; do
proxy_name="shadowtls-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
shadowtls_out="stl-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$phone_client_file" && ! grep -q "name: $shadowtls_out" "$phone_client_file" && [ "$proxy_name" != "$shadowtls_out" ]; then
break
fi
2024-01-02 02:21:44 +08:00
done
2023-11-12 17:47:06 +08:00
awk -v shadowtls_out="$shadowtls_out" -v proxy_name="$proxy_name" -v method="$method" -v ss_password="$ss_password" -v local_ip="$local_ip" -v listen_port="$listen_port" -v stls_password="$stls_password" -v user_input="$user_input" -v multiplex_client_config="$multiplex_client_config" '
/^ "outbounds": \[/ {print; getline; print " {"; print " \"type\": \"shadowsocks\","; print " \"tag\": \"" proxy_name "\","; print " \"method\": \"" method "\", "; print " \"password\": \"" ss_password "\","; print " \"detour\": \"" shadowtls_out "\""multiplex_client_config""; print " },"; print " {"; print " \"type\": \"shadowtls\","; print " \"tag\": \"" shadowtls_out "\","; print " \"server\": \"" local_ip "\", "; print " \"server_port\": " listen_port ","; print " \"version\": 3, "; print " \"password\": \""stls_password"\", "; print " \"tls\": {"; print " \"enabled\": true,"; print " \"server_name\": \"" user_input "\", "; print " \"utls\": {"; print " \"enabled\": true,"; print " \"fingerprint\": \"chrome\" "; print " }"; print " }"; print " },";}
2023-09-25 11:30:38 +08:00
/^ "outbounds": \[/ {print; getline; if ($0 ~ /^ \],$/) {print " \"" proxy_name "\""} else {print " \"" proxy_name "\", "} }
2024-01-02 02:21:44 +08:00
{print}' "$phone_client_file" >"$phone_client_file.tmp"
mv "$phone_client_file.tmp" "$phone_client_file"
2023-09-15 18:48:54 +08:00
}
2023-09-24 10:05:14 +08:00
function generate_shadowtls_yaml() {
2023-11-12 17:47:06 +08:00
local filename="/usr/local/etc/sing-box/clash.yaml"
local proxy_name
while true; do
proxy_name="shadowtls-$(head /dev/urandom | tr -dc '0-9' | head -c 4)"
if ! grep -q "name: $proxy_name" "$filename"; then
break
fi
done
2024-01-02 02:21:44 +08:00
awk -v proxy_name="$proxy_name" -v method="$method" -v ss_password="$ss_password" -v local_ip="$local_ip" -v listen_port="$listen_port" -v stls_password="$stls_password" -v user_input="$user_input" '/^proxies:$/ {print; print " - name: " proxy_name; print " type: ss"; print " server:", local_ip; print " port:", listen_port; print " cipher:", method; print " password:", "\"" ss_password "\""; print " plugin: shadow-tls"; print " plugin-opts:"; print " host: \"" user_input "\""; print " password:", "\"" stls_password "\""; print " version: 3"; print ""; next} /- name: Proxy/ { print; flag_proxy=1; next } flag_proxy && flag_proxy++ == 3 { print " - " proxy_name } /- name: auto/ { print; flag_auto=1; next } flag_auto && flag_auto++ == 3 { print " - " proxy_name } 1' "$filename" >temp_file && mv temp_file "$filename"
2023-09-24 10:05:14 +08:00
}
2023-09-15 18:48:54 +08:00
function generate_naive_win_client_config() {
local naive_client_file="$naive_client_filename"
2023-10-12 13:39:59 +08:00
sed -i -e "s,user_name,$user_name," -e "s,user_password,$user_password," -e "s,listen_port,$listen_port," -e "s,server_name,$domain," "$naive_client_file"
2024-01-02 02:21:44 +08:00
echo "Computer-side configuration file has been saved to $naive_client_file, please download and use it!"
2023-09-15 18:48:54 +08:00
}
2023-11-03 17:20:00 +08:00
function extract_types_tags() {
local config_file="/usr/local/etc/sing-box/config.json"
filtered_tags=()
types=()
tags=($(jq -r '.inbounds[] | select(.tag != null) | .tag' "$config_file"))
detour_tag=$(jq -r '.inbounds[] | select(.type == "shadowtls") | .detour' "$config_file")
wireguard_type=$(jq -r '.outbounds[] | select(.type == "wireguard" and .tag == "wireguard-out") | .type' "$config_file")
if [ -z "$tags" ] && [ -z "$wireguard_type" ]; then
2024-01-02 02:21:44 +08:00
echo "No node configurations detected, please build nodes before using this option!"
2023-11-03 17:20:00 +08:00
exit 0
fi
filtered_tags=()
for tag in "${tags[@]}"; do
if [ "$tag" != "$detour_tag" ]; then
filtered_tags+=("$tag")
fi
done
max_length=0
for tag in "${filtered_tags[@]}"; do
tag_length=${#tag}
if ((tag_length > max_length)); then
max_length=$tag_length
fi
done
2024-01-02 02:21:44 +08:00
for ((i = 0; i < ${#filtered_tags[@]}; i++)); do
2023-11-03 17:20:00 +08:00
type=$(jq -r --arg tag "${filtered_tags[$i]}" '.inbounds[] | select(.tag == $tag) | .type' "$config_file")
types[$i]=$type
2024-01-02 02:21:44 +08:00
printf "%d).Protocol Type: %-20s Inbound Tag: %s\n" "$((i + 1))" "$type" "${filtered_tags[$i]}"
2023-11-03 17:20:00 +08:00
done
if [ ! -z "$wireguard_type" ]; then
types[$i]=$wireguard_type
2024-01-02 02:21:44 +08:00
printf "%d).Protocol Type: %-20s Outbound Tag: %s\n" "$((i + 1))" "$wireguard_type" "wireguard-out"
2023-11-03 17:20:00 +08:00
fi
}
function delete_choice() {
local config_file="/usr/local/etc/sing-box/config.json"
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
local win_client_file="/usr/local/etc/sing-box/win_client.json"
local clash_yaml="/usr/local/etc/sing-box/clash.yaml"
local output_file="/usr/local/etc/sing-box/output.txt"
local temp_json="/usr/local/etc/sing-box/temp.json"
local temp_yaml="/usr/local/etc/sing-box/temp.yaml"
extract_types_tags
valid_choice=false
while [ "$valid_choice" == false ]; do
2024-01-02 02:21:44 +08:00
read -p "Please select the node configuration to delete (input the corresponding number): " choice
2023-11-03 17:20:00 +08:00
if [[ ! $choice =~ ^[0-9]+$ || $choice -lt 1 || $choice -gt ${#types[@]} ]]; then
2024-01-02 02:21:44 +08:00
echo -e "${RED}Error: Invalid selection, please re-enter!${NC}"
2023-11-03 17:20:00 +08:00
else
valid_choice=true
fi
done
2024-01-02 02:21:44 +08:00
selected_tag="${filtered_tags[$choice - 1]}"
selected_type="${types[$choice - 1]}"
2023-11-03 17:20:00 +08:00
listen_port=$(jq -r --arg selected_tag "$selected_tag" '.inbounds[] | select(.tag == $selected_tag) | .listen_port' "$config_file" | awk '{print int($0)}')
if [ "$selected_type" == "wireguard" ]; then
2024-01-02 02:21:44 +08:00
jq '.outbounds |= map(select(.tag != "warp-IPv4-out" and .tag != "warp-IPv6-out" and .tag != "wireguard-out"))' "$config_file" >"$temp_json"
2023-11-03 17:20:00 +08:00
mv "$temp_json" "$config_file"
2024-01-02 02:21:44 +08:00
jq '.route.rules |= map(select(.outbound != "warp-IPv4-out" and .outbound != "warp-IPv6-out"))' "$config_file" >"$temp_json"
2023-11-03 17:20:00 +08:00
mv "$temp_json" "$config_file"
else
detour_tag=$(jq -r --arg selected_tag "$selected_tag" '.inbounds[] | select(.type == "shadowtls" and .tag == $selected_tag) | .detour' "$config_file")
2024-01-02 02:21:44 +08:00
jq --arg selected_tag "$selected_tag" --arg detour_tag "$detour_tag" '.inbounds |= map(select(.tag != $selected_tag and .tag != $detour_tag))' "$config_file" >"$temp_json"
2023-11-03 17:20:00 +08:00
mv "$temp_json" "$config_file"
2024-01-02 02:21:44 +08:00
jq --arg selected_tag "$selected_tag" '.route.rules |= map(select(.inbound[0] != $selected_tag))' "$config_file" >"$temp_json"
2023-11-03 17:20:00 +08:00
mv "$temp_json" "$config_file"
fi
if [ "$selected_type" != "wireguard" ]; then
2024-01-02 02:21:44 +08:00
awk -v port="$listen_port" '$0 ~ "Listening Port: " port {print; in_block=1; next} in_block && NF == 0 {in_block=0} !in_block' "$output_file" >"$output_file.tmp1"
2023-11-03 17:20:00 +08:00
mv "$output_file.tmp1" "$output_file"
2024-01-02 02:21:44 +08:00
awk -v port="$listen_port" '$0 ~ "Listening Port: " port {start=NR; next} {lines[NR]=$0} END {for (i=1; i<=NR; i++) if (i < start - 4 || i > start) print lines[i]}' "$output_file" >"$output_file.tmp2"
2023-11-03 17:20:00 +08:00
mv "$output_file.tmp2" "$output_file"
sed -i '/./,$!d' "$output_file"
fi
2023-12-05 13:34:57 +08:00
if [ -f "$clash_yaml" ]; then
2024-01-02 02:21:44 +08:00
get_clash_tags=$(awk '/proxies:/ {in_proxies_block=1} in_proxies_block && /- name:/ {name = $3} in_proxies_block && /port:/ {port = $2; print "Name:", name, "Port:", port}' "$clash_yaml" >"$temp_yaml")
matching_clash_tag=$(grep "Port: $listen_port" "$temp_yaml" | awk '{print $2}')
2023-12-05 13:34:57 +08:00
fi
2023-11-03 17:20:00 +08:00
if [ -n "$listen_port" ]; then
phone_matching_tag=$(jq -r --argjson listen_port "$listen_port" '.outbounds[] | select(.server_port == $listen_port) | .tag' "$phone_client_file")
win_matching_tag=$(jq -r --argjson listen_port "$listen_port" '.outbounds[] | select(.server_port == $listen_port) | .tag' "$win_client_file")
fi
2024-01-02 02:21:44 +08:00
jq --arg tag "$phone_matching_tag" '.outbounds |= map(select(.tag != $tag))' "$phone_client_file" >"$temp_json"
2023-11-03 17:20:00 +08:00
mv "$temp_json" "$phone_client_file"
2024-01-02 02:21:44 +08:00
jq --arg tag "$win_matching_tag" '.outbounds |= map(select(.tag != $tag))' "$win_client_file" >"$temp_json"
2023-11-03 17:20:00 +08:00
mv "$temp_json" "$win_client_file"
if [ -n "$matching_clash_tag" ] && [ "$selected_type" != "wireguard" ]; then
2024-01-02 02:21:44 +08:00
sed -i "/^ - name: $matching_clash_tag$/,/^\s*$/d" "$clash_yaml"
sed -i "/proxy-groups:/,/^\s*$/ {/ - $matching_clash_tag/d}" "$clash_yaml"
2023-11-03 17:20:00 +08:00
fi
phone_matching_detour=$(jq -r --arg phone_matching_tag "$phone_matching_tag" '.outbounds[] | select(.detour == $phone_matching_tag) | .detour' "$phone_client_file")
win_matching_detour=$(jq -r --arg win_matching_tag "$win_matching_tag" '.outbounds[] | select(.detour == $win_matching_tag) | .detour' "$win_client_file")
phone_matching_detour_tag=$(jq -r --arg phone_matching_detour "$phone_matching_detour" '.outbounds[] | select(.detour == $phone_matching_detour) | .tag' "$phone_client_file")
win_matching_detour_tag=$(jq -r --arg win_matching_detour "$win_matching_detour" '.outbounds[] | select(.detour == $win_matching_detour) | .tag' "$win_client_file")
2024-01-02 02:21:44 +08:00
awk -v phone_matching_tag="$phone_matching_tag" '!/^ "outbounds": \[$/,/^\s*]/{if (!($0 ~ "^ * \"" phone_matching_tag "\"")) print; else next; }' "$phone_client_file" >"$phone_client_file.tmp"
2023-11-03 17:20:00 +08:00
mv "$phone_client_file.tmp" "$phone_client_file"
2024-01-02 02:21:44 +08:00
awk -v win_matching_tag="$win_matching_tag" '!/^ "outbounds": \[$/,/^\s*]/{if (!($0 ~ "^ * \"" win_matching_tag "\"")) print; else next; }' "$win_client_file" >"$win_client_file.tmp"
2023-11-03 17:20:00 +08:00
mv "$win_client_file.tmp" "$win_client_file"
if [ "$phone_matching_tag" == "$phone_matching_detour" ]; then
2024-01-02 02:21:44 +08:00
jq --arg phone_matching_detour "$phone_matching_detour" '.outbounds |= map(select(.detour != $phone_matching_detour))' "$phone_client_file" >"$temp_json"
2023-11-03 17:20:00 +08:00
mv "$temp_json" "$phone_client_file"
2024-01-02 02:21:44 +08:00
awk -v phone_matching_detour_tag="$phone_matching_detour_tag" '!/^ "outbounds": \[$/,/^\s*]/{if (!($0 ~ "^ * \"" phone_matching_detour_tag "\"")) print; else next; }' "$phone_client_file" >"$phone_client_file.tmp"
2023-11-03 17:20:00 +08:00
mv "$phone_client_file.tmp" "$phone_client_file"
fi
if [ "$win_matching_tag" == "$win_matching_detour" ]; then
2024-01-02 02:21:44 +08:00
jq --arg win_matching_detour "$win_matching_detour" '.outbounds |= map(select(.detour != $win_matching_detour))' "$win_client_file" >"$temp_json"
2023-11-03 17:20:00 +08:00
mv "$temp_json" "$win_client_file"
2024-01-02 02:21:44 +08:00
awk -v win_matching_detour_tag="$win_matching_detour_tag" '!/^ "outbounds": \[$/,/^\s*]/{if (!($0 ~ "^ * \"" win_matching_detour_tag "\"")) print; else next; }' "$win_client_file" >"$win_client_file.tmp"
2023-11-03 17:20:00 +08:00
mv "$win_client_file.tmp" "$win_client_file"
fi
2024-01-02 02:21:44 +08:00
awk '{if ($0 ~ /],$/ && p ~ /,$/) sub(/,$/, "", p); if (NR > 1) print p; p = $0;}END{print p;}' "$phone_client_file" >"$phone_client_file.tmp"
2023-11-03 17:20:00 +08:00
mv "$phone_client_file.tmp" "$phone_client_file"
2024-01-02 02:21:44 +08:00
awk '{if ($0 ~ /],$/ && p ~ /,$/) sub(/,$/, "", p); if (NR > 1) print p; p = $0;}END{print p;}' "$win_client_file" >"$win_client_file.tmp"
2023-11-03 17:20:00 +08:00
mv "$win_client_file.tmp" "$win_client_file"
2023-12-05 13:34:57 +08:00
[ -f "$temp_yaml" ] && rm "$temp_yaml"
2024-01-02 02:21:44 +08:00
if ! jq -e 'select(.inbounds[] | .listen == "::")' "$config_file" >/dev/null; then
2023-11-03 17:20:00 +08:00
sed -i 's/"rules": \[\]/"rules": [\n ]/' "$config_file"
sed -i 's/^ "inbounds": \[\],/ "inbounds": [\n ],/' "$config_file"
sed -i 's/^ "outbounds": \[\],/ "outbounds": [\n ],/' "$win_client_file"
sed -i 's/^ "outbounds": \[\],/ "outbounds": [\n ],/' "$phone_client_file"
fi
systemctl restart sing-box
2024-01-02 02:21:44 +08:00
echo "$selected_type configuration information has been deleted. Server and client configuration information have been updated. Please download the new configuration file to use!"
2023-11-03 17:20:00 +08:00
}
2023-09-25 11:30:38 +08:00
function display_naive_config_info() {
2023-08-19 17:45:08 +08:00
local config_file="/usr/local/etc/sing-box/config.json"
2024-01-02 02:21:44 +08:00
local output_file="/usr/local/etc/sing-box/output.txt"
2023-11-03 17:20:00 +08:00
local num_users=${#user_names[@]}
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}NaiveProxy Node Configuration Information:${NC}" | tee -a "$output_file"
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "Server Address: $domain" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Listening Port: $listen_port" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "User Name Password" | tee -a "$output_file"
echo "------------------------------------------------------------------------------" | tee -a "$output_file"
for ((i = 0; i < num_users; i++)); do
2023-10-09 11:28:46 +08:00
local user_name="${user_names[i]}"
2024-01-02 02:21:44 +08:00
local user_password="${user_passwords[i]}"
2023-10-09 11:28:46 +08:00
printf "%-38s %s\n" "$user_name" "$user_password" | tee -a "$output_file"
2024-01-02 02:21:44 +08:00
done
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "" >>"$output_file"
echo "Configuration information has been saved to $output_file"
2023-09-25 11:30:38 +08:00
}
function generate_naive_config_files() {
local config_file="/usr/local/etc/sing-box/config.json"
2023-10-12 13:39:59 +08:00
local naive_client_file="$naive_client_filename"
2024-01-02 02:21:44 +08:00
local num_users=${#user_names[@]}
for ((i = 0; i < num_users; i++)); do
2023-10-09 11:28:46 +08:00
local user_name="${user_names[i]}"
2024-01-02 02:21:44 +08:00
local user_password="${user_passwords[i]}"
2023-09-15 18:48:54 +08:00
generate_naive_random_filename
write_naive_client_file
2024-01-02 02:21:44 +08:00
generate_naive_win_client_config "$user_name" "$user_password" "$listen_port" "$domain"
2023-08-19 17:45:08 +08:00
done
2023-09-15 18:48:54 +08:00
}
2023-08-19 17:45:08 +08:00
2023-09-15 18:48:54 +08:00
function display_Direct_config() {
local config_file="/usr/local/etc/sing-box/config.json"
2023-10-09 11:28:46 +08:00
local output_file="/usr/local/etc/sing-box/output.txt"
2024-01-02 02:21:44 +08:00
local override_address=$(jq -r '.inbounds[0].override_address' "$config_file")
2023-10-09 11:28:46 +08:00
if [[ -n "$ip_v4" ]]; then
local_ip="$ip_v4"
elif [[ -n "$ip_v6" ]]; then
local_ip="$ip_v6"
2023-11-03 17:20:00 +08:00
fi
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}Direct Node Configuration Information:${NC}" | tee -a "$output_file"
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "Relay Address: $local_ip" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Listening Port: $listen_port" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Target Address: $override_address" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Target Port: $override_port" | tee -a "$output_file"
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "" >>"$output_file"
echo "Configuration information has been saved to $output_file"
2023-09-15 18:48:54 +08:00
}
function display_juicity_config() {
local config_file="/usr/local/etc/juicity/config.json"
2023-10-12 13:39:59 +08:00
local output_file="/usr/local/etc/juicity/output.txt"
local server_address
local congestion_control=$(jq -r '.congestion_control' "$config_file")
if [[ -n "$ip_v4" ]]; then
local_ip="$ip_v4"
elif [[ -n "$ip_v6" ]]; then
local_ip="$ip_v6"
fi
if [ -z "$domain" ]; then
server_address="$local_ip"
else
server_address="$domain"
fi
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}Juicity Node Configuration Information:${NC}" | tee -a "$output_file"
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "Server Address: $server_address" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Listening Port: $listen_port" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "UUID: $user_uuids Password: $user_passwords " | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Congestion Control Algorithm: $congestion_control" | tee -a "$output_file"
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "" >>"$output_file"
echo "Share Link:"
2023-11-12 17:47:06 +08:00
juicity-server generate-sharelink -c "$config_file"
generate_juicity_win_client_config
2024-01-02 02:21:44 +08:00
echo "Configuration information has been saved to $output_file"
2023-11-12 17:47:06 +08:00
}
function display_http_config_info() {
local config_file="/usr/local/etc/sing-box/config.json"
local output_file="/usr/local/etc/sing-box/output.txt"
local num_users=${#user_names[@]}
local server_address
if [[ -n "$ip_v4" ]]; then
local_ip="$ip_v4"
elif [[ -n "$ip_v6" ]]; then
local_ip="$ip_v6"
fi
if [ -z "$domain" ]; then
server_address="$local_ip"
else
server_address="$domain"
fi
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}HTTP Node Configuration Information:${NC}" | tee -a "$output_file"
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "Server Address: $server_address" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Listening Port: $listen_port" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Username Password" | tee -a "$output_file"
echo "------------------------------------------------------------------------------" | tee -a "$output_file"
for ((i = 0; i < num_users; i++)); do
2023-11-12 17:47:06 +08:00
local user_name="${user_names[i]}"
2024-01-02 02:21:44 +08:00
local user_password="${user_passwords[i]}"
2023-11-12 17:47:06 +08:00
printf "%-38s %s\n" "$user_name" "$user_password" | tee -a "$output_file"
2024-01-02 02:21:44 +08:00
done
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "" >>"$output_file"
echo "Configuration information has been saved to $output_file"
2023-11-12 17:47:06 +08:00
}
function display_http_config_files() {
local config_file="/usr/local/etc/sing-box/config.json"
2024-01-02 02:21:44 +08:00
local clash_file="/usr/local/etc/sing-box/clash.yaml"
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
local win_client_file="/usr/local/etc/sing-box/win_client.json"
for ((i = 0; i < ${#user_passwords[@]}; i++)); do
2023-11-12 17:47:06 +08:00
user_password="${user_passwords[$i]}"
if [ "$enable_ech" = true ]; then
write_phone_client_file
write_win_client_file
generate_http_win_client_config "$user_password"
generate_http_phone_client_config "$user_password"
else
write_phone_client_file
write_win_client_file
generate_http_win_client_config "$user_password"
generate_http_phone_client_config "$user_password"
ensure_clash_yaml
write_clash_yaml
generate_http_yaml
fi
done
if [ "$enable_ech" = true ]; then
2024-01-02 02:21:44 +08:00
echo "Phone client configuration file has been saved to $phone_client_file. Please download and use!"
echo "Win client configuration file has been saved to $win_client_file. Please download and use!"
2023-11-12 17:47:06 +08:00
else
2024-01-02 02:21:44 +08:00
echo "Phone client configuration file has been saved to $phone_client_file. Please download and use!"
echo "Win client configuration file has been saved to $win_client_file. Please download and use!"
echo "Clash configuration file has been saved to $clash_file. Please download and use!"
2023-11-12 17:47:06 +08:00
fi
2023-08-17 17:46:42 +08:00
}
2023-09-25 11:30:38 +08:00
function display_tuic_config_info() {
2023-08-30 16:56:50 +08:00
local config_file="/usr/local/etc/sing-box/config.json"
2023-10-12 13:39:59 +08:00
local output_file="/usr/local/etc/sing-box/output.txt"
local server_address
2023-08-30 16:56:50 +08:00
local congestion_control=$(jq -r '.inbounds[0].congestion_control' "$config_file")
2023-10-12 13:39:59 +08:00
local alpn=$(jq -r '.inbounds[0].tls.alpn[0]' "$config_file")
if [[ -n "$ip_v4" ]]; then
local_ip="$ip_v4"
elif [[ -n "$ip_v6" ]]; then
local_ip="$ip_v6"
fi
if [ -z "$domain" ]; then
server_address="$local_ip"
else
server_address="$domain"
fi
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}TUIC Node Configuration Information:${NC}" | tee -a "$output_file"
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "Server Address: $server_address" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Listening Port: $listen_port" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "User Password List:" | tee -a "$output_file"
echo "------------------------------------------------------------------------------" | tee -a "$output_file"
echo " Username UUID Password" | tee -a "$output_file"
echo "------------------------------------------------------------------------------" | tee -a "$output_file"
for ((i = 0; i < ${#user_names[@]}; i++)); do
2023-10-09 11:28:46 +08:00
user_name="${user_names[$i]}"
user_uuid="${user_uuids[$i]}"
user_password="${user_passwords[$i]}"
printf "%-13s %-42s %s\n" "$user_name" "$user_uuid" "$user_password" | tee -a "$output_file"
2024-01-02 02:21:44 +08:00
done
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Congestion Control Algorithm: $congestion_control" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "ALPN: $alpn" | tee -a "$output_file"
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "" >>"$output_file"
echo "Configuration information has been saved to $output_file"
2023-09-25 11:30:38 +08:00
}
function display_tuic_config_files() {
local config_file="/usr/local/etc/sing-box/config.json"
2024-01-02 02:21:44 +08:00
local clash_file="/usr/local/etc/sing-box/clash.yaml"
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
local win_client_file="/usr/local/etc/sing-box/win_client.json"
2023-09-25 11:30:38 +08:00
local congestion_control=$(jq -r '.inbounds[0].congestion_control' "$config_file")
2023-10-09 11:28:46 +08:00
local alpn=$(jq -r '.inbounds[0].tls.alpn[0]' "$config_file")
2024-01-02 02:21:44 +08:00
local num_users=${#user_uuids[@]}
for ((i = 0; i < num_users; i++)); do
2023-10-09 11:28:46 +08:00
local user_uuid="${user_uuids[i]}"
2023-11-12 17:47:06 +08:00
local user_password="${user_passwords[i]}"
if [ "$enable_ech" = true ]; then
write_phone_client_file
2024-01-02 02:21:44 +08:00
write_win_client_file
2023-11-12 17:47:06 +08:00
generate_tuic_win_client_config "$user_uuid" "$user_password"
generate_tuic_phone_client_config "$user_uuid" "$user_password"
else
write_phone_client_file
2024-01-02 02:21:44 +08:00
write_win_client_file
2023-11-12 17:47:06 +08:00
generate_tuic_win_client_config "$user_uuid" "$user_password"
generate_tuic_phone_client_config "$user_uuid" "$user_password"
ensure_clash_yaml
write_clash_yaml
generate_tuic_yaml
fi
2023-09-15 18:48:54 +08:00
done
2023-11-12 17:47:06 +08:00
if [ "$enable_ech" = true ]; then
2024-01-02 02:21:44 +08:00
echo "Phone client configuration file has been saved to $phone_client_file. Please download and use!"
echo "Win client configuration file has been saved to $win_client_file. Please download and use!"
2023-11-12 17:47:06 +08:00
else
2024-01-02 02:21:44 +08:00
echo "Phone client configuration file has been saved to $phone_client_file. Please download and use!"
echo "Win client configuration file has been saved to $win_client_file. Please download and use!"
echo "Clash configuration file has been saved to $clash_file. Please download and use!"
2023-11-12 17:47:06 +08:00
fi
2023-09-15 18:48:54 +08:00
}
2023-09-25 11:30:38 +08:00
function display_Shadowsocks_config_info() {
2023-09-15 18:48:54 +08:00
local config_file="/usr/local/etc/sing-box/config.json"
2024-01-02 02:21:44 +08:00
local output_file="/usr/local/etc/sing-box/output.txt"
2023-09-15 18:48:54 +08:00
local ss_method=$(jq -r '.inbounds[0].method' "$config_file")
2023-10-09 11:28:46 +08:00
if [[ -n "$ip_v4" ]]; then
local_ip="$ip_v4"
elif [[ -n "$ip_v6" ]]; then
local_ip="$ip_v6"
2023-11-03 17:20:00 +08:00
fi
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}Shadowsocks Node Configuration Information:${NC}" | tee -a "$output_file"
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "Server Address: $local_ip" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Listening Port: $listen_port" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Encryption Method: $ss_method" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Password: $ss_passwords" | tee -a "$output_file"
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "" >>"$output_file"
echo "Configuration information has been saved to $output_file"
2023-09-25 11:30:38 +08:00
}
function display_Shadowsocks_config_files() {
local config_file="/usr/local/etc/sing-box/config.json"
2024-01-02 02:21:44 +08:00
local clash_file="/usr/local/etc/sing-box/clash.yaml"
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
local win_client_file="/usr/local/etc/sing-box/win_client.json"
2023-09-25 11:30:38 +08:00
local ss_method=$(jq -r '.inbounds[0].method' "$config_file")
2023-10-09 11:28:46 +08:00
if [[ -n "$ip_v4" ]]; then
local_ip="$ip_v4"
elif [[ -n "$ip_v6" ]]; then
local_ip="$ip_v6"
2024-01-02 02:21:44 +08:00
fi
2023-09-15 18:48:54 +08:00
write_phone_client_file
write_win_client_file
generate_shadowsocks_win_client_config
generate_shadowsocks_phone_client_config
2023-09-24 10:05:14 +08:00
ensure_clash_yaml
write_clash_yaml
2024-01-02 02:21:44 +08:00
generate_shadowsocks_yaml
echo "Phone client configuration file has been saved to $phone_client_file. Please download and use!"
echo "Win client configuration file has been saved to $win_client_file. Please download and use!"
echo "Clash configuration file has been saved to $clash_file. Please download and use!"
2023-08-19 17:45:08 +08:00
}
2023-09-25 11:30:38 +08:00
function display_socks_config_info() {
2023-09-18 16:36:33 +08:00
local config_file="/usr/local/etc/sing-box/config.json"
2024-01-02 02:21:44 +08:00
local output_file="/usr/local/etc/sing-box/output.txt"
2023-10-09 11:28:46 +08:00
if [[ -n "$ip_v4" ]]; then
local_ip="$ip_v4"
elif [[ -n "$ip_v6" ]]; then
local_ip="$ip_v6"
2023-11-03 17:20:00 +08:00
fi
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}SOCKS Node Configuration Information:${NC}" | tee -a "$output_file"
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "Server Address: $local_ip" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Listening Port: $listen_port" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "User Password List:" | tee -a "$output_file"
echo "------------------------------------------------------------------------------" | tee -a "$output_file"
echo "Username Password" | tee -a "$output_file"
for ((i = 0; i < ${#user_names[@]}; i++)); do
2023-10-09 11:28:46 +08:00
user_name="${user_names[$i]}"
user_password="${user_passwords[$i]}"
printf "%-35s %s\n" "$user_name" "$user_password" | tee -a "$output_file"
2024-01-02 02:21:44 +08:00
done
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "" >>"$output_file"
echo "Node configuration information has been saved to $output_file"
2023-09-25 11:30:38 +08:00
}
function display_socks_config_files() {
local config_file="/usr/local/etc/sing-box/config.json"
2024-01-02 02:21:44 +08:00
local clash_file="/usr/local/etc/sing-box/clash.yaml"
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
local win_client_file="/usr/local/etc/sing-box/win_client.json"
local num_users=${#user_names[@]}
2023-10-09 11:28:46 +08:00
if [[ -n "$ip_v4" ]]; then
local_ip="$ip_v4"
elif [[ -n "$ip_v6" ]]; then
local_ip="$ip_v6"
2023-11-12 17:47:06 +08:00
fi
2024-01-02 02:21:44 +08:00
for ((i = 0; i < num_users; i++)); do
local user_name="${user_names[i]}"
local user_password="${user_passwords[i]}"
write_phone_client_file
write_win_client_file
generate_socks_win_client_config "$user_name" "$user_password"
generate_socks_phone_client_config "$user_name" "$user_password"
ensure_clash_yaml
write_clash_yaml
generate_socks_yaml
2023-09-18 16:36:33 +08:00
done
2024-01-02 02:21:44 +08:00
echo "Phone client configuration file has been saved to $phone_client_file. Please download and use!"
echo "Win client configuration file has been saved to $win_client_file. Please download and use!"
echo "Clash configuration file has been saved to $clash_file. Please download and use!"
2023-09-18 16:36:33 +08:00
}
2023-09-25 11:30:38 +08:00
function display_Hysteria_config_info() {
2023-08-19 17:45:08 +08:00
local config_file="/usr/local/etc/sing-box/config.json"
2024-01-02 02:21:44 +08:00
local output_file="/usr/local/etc/sing-box/output.txt"
local server_address
2023-08-30 16:56:50 +08:00
local alpn=$(jq -r '.inbounds[0].tls.alpn[0]' "$config_file")
2023-10-12 13:39:59 +08:00
if [[ -n "$ip_v4" ]]; then
local_ip="$ip_v4"
elif [[ -n "$ip_v6" ]]; then
local_ip="$ip_v6"
fi
if [ -z "$domain" ]; then
server_address="$local_ip"
else
server_address="$domain"
fi
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}Hysteria Node Configuration Information:${NC}" | tee -a "$output_file"
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "Server Address: $server_address" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Listening Port: $listen_port" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Upload Speed: ${up_mbps}Mbps" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Download Speed: ${down_mbps}Mbps" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "ALPN: $alpn" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Username Password" | tee -a "$output_file"
echo "------------------------------------------------------------------------------" | tee -a "$output_file"
for ((i = 0; i < ${#user_names[@]}; i++)); do
2023-10-09 11:28:46 +08:00
user_name="${user_names[$i]}"
user_password="${user_passwords[$i]}"
printf "%-35s %s\n" "$user_name" "$user_password" | tee -a "$output_file"
2023-07-29 15:12:16 +08:00
done
2023-10-12 13:39:59 +08:00
if [ -n "$obfs_password" ]; then
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "obfs Obfuscation Password: $obfs_password" | tee -a "$output_file"
2023-10-12 13:39:59 +08:00
fi
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "" >>"$output_file"
echo "Configuration information has been saved to $output_file"
2023-09-25 11:30:38 +08:00
}
function display_Hysteria_config_files() {
local config_file="/usr/local/etc/sing-box/config.json"
2024-01-02 02:21:44 +08:00
local clash_file="/usr/local/etc/sing-box/clash.yaml"
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
local win_client_file="/usr/local/etc/sing-box/win_client.json"
2023-09-25 11:30:38 +08:00
local alpn=$(jq -r '.inbounds[0].tls.alpn[0]' "$config_file")
2024-01-02 02:21:44 +08:00
for ((i = 0; i < ${#user_passwords[@]}; i++)); do
2023-10-09 11:28:46 +08:00
user_password="${user_passwords[$i]}"
2023-11-12 17:47:06 +08:00
if [ "$enable_ech" = true ]; then
write_phone_client_file
write_win_client_file
generate_Hysteria_win_client_config "$user_password"
generate_Hysteria_phone_client_config "$user_password"
else
write_phone_client_file
write_win_client_file
generate_Hysteria_win_client_config "$user_password"
generate_Hysteria_phone_client_config "$user_password"
ensure_clash_yaml
write_clash_yaml
generate_Hysteria_yaml
2024-01-02 02:21:44 +08:00
fi
2023-09-15 18:48:54 +08:00
done
2023-11-12 17:47:06 +08:00
if [ "$enable_ech" = true ]; then
2024-01-02 02:21:44 +08:00
echo "Phone client configuration file has been saved to $phone_client_file. Please download and use!"
echo "Win client configuration file has been saved to $win_client_file. Please download and use!"
2023-11-12 17:47:06 +08:00
else
2024-01-02 02:21:44 +08:00
echo "Phone client configuration file has been saved to $phone_client_file. Please download and use!"
echo "Win client configuration file has been saved to $win_client_file. Please download and use!"
echo "Clash configuration file has been saved to $clash_file. Please download and use!"
fi
2023-07-29 15:12:16 +08:00
}
2023-09-25 11:30:38 +08:00
function display_Hy2_config_info() {
2023-09-04 11:22:03 +08:00
local config_file="/usr/local/etc/sing-box/config.json"
2024-01-02 02:21:44 +08:00
local output_file="/usr/local/etc/sing-box/output.txt"
2023-10-12 13:39:59 +08:00
local server_address
2023-09-04 11:22:03 +08:00
local alpn=$(jq -r '.inbounds[0].tls.alpn[0]' "$config_file")
2023-10-12 13:39:59 +08:00
if [[ -n "$ip_v4" ]]; then
local_ip="$ip_v4"
elif [[ -n "$ip_v6" ]]; then
local_ip="$ip_v6"
fi
if [ -z "$domain" ]; then
server_address="$local_ip"
else
server_address="$domain"
fi
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}Hysteria2 Node Configuration Information:${NC}" | tee -a "$output_file"
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "Server Address: $server_address" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Listening Port: $listen_port" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Upload Speed: ${up_mbps}Mbps" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Download Speed: ${down_mbps}Mbps" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "ALPN: $alpn" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Username Password" | tee -a "$output_file"
echo "------------------------------------------------------------------------------" | tee -a "$output_file"
for ((i = 0; i < ${#user_names[@]}; i++)); do
2023-10-09 11:28:46 +08:00
user_name="${user_names[$i]}"
user_password="${user_passwords[$i]}"
printf "%-35s %s\n" "$user_name" "$user_password" | tee -a "$output_file"
2023-09-04 11:22:03 +08:00
done
2023-10-12 13:39:59 +08:00
if [ -n "$obfs_password" ]; then
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "QUIC Traffic Obfuscation Password: $obfs_password" | tee -a "$output_file"
2023-10-12 13:39:59 +08:00
fi
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "" >>"$output_file"
echo "Configuration information has been saved to $output_file"
2023-09-25 11:30:38 +08:00
}
function display_Hy2_config_files() {
local config_file="/usr/local/etc/sing-box/config.json"
2024-01-02 02:21:44 +08:00
local clash_file="/usr/local/etc/sing-box/clash.yaml"
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
2023-10-12 13:39:59 +08:00
local win_client_file="/usr/local/etc/sing-box/win_client.json"
2023-09-25 11:30:38 +08:00
local alpn=$(jq -r '.inbounds[0].tls.alpn[0]' "$config_file")
2024-01-02 02:21:44 +08:00
for ((i = 0; i < ${#user_passwords[@]}; i++)); do
2023-10-09 11:28:46 +08:00
user_password="${user_passwords[$i]}"
2023-11-12 17:47:06 +08:00
if [ "$enable_ech" = true ]; then
write_phone_client_file
write_win_client_file
2024-01-04 14:45:52 +08:00
generate_Hysteria2_win_client_config "$user_password"
generate_Hysteria2_phone_client_config "$user_password"
2023-11-12 17:47:06 +08:00
else
write_phone_client_file
write_win_client_file
2024-01-04 14:45:52 +08:00
generate_Hysteria2_win_client_config "$user_password"
generate_Hysteria2_phone_client_config "$user_password"
2023-11-12 17:47:06 +08:00
ensure_clash_yaml
write_clash_yaml
2024-01-04 14:45:52 +08:00
generate_Hysteria2_yaml
2023-11-12 17:47:06 +08:00
fi
2023-09-24 10:05:14 +08:00
done
2023-11-12 17:47:06 +08:00
if [ "$enable_ech" = true ]; then
2024-01-02 02:21:44 +08:00
echo "Phone client configuration file has been saved to $phone_client_file. Please download and use!"
echo "Win client configuration file has been saved to $win_client_file. Please download and use!"
2023-11-12 17:47:06 +08:00
else
2024-01-02 02:21:44 +08:00
echo "Phone client configuration file has been saved to $phone_client_file. Please download and use!"
echo "Win client configuration file has been saved to $win_client_file. Please download and use!"
echo "Clash configuration file has been saved to $clash_file. Please download and use!"
fi
2023-09-15 18:48:54 +08:00
}
2023-09-25 11:30:38 +08:00
function display_reality_config_info() {
2023-09-15 18:48:54 +08:00
local config_file="/usr/local/etc/sing-box/config.json"
2023-10-09 11:28:46 +08:00
local output_file="/usr/local/etc/sing-box/output.txt"
2023-09-15 18:48:54 +08:00
local flow_type=$(jq -r '.inbounds[0].users[0].flow' "$config_file")
local transport_type=$(jq -r '.inbounds[0].transport.type' "$config_file")
local server_name=$(jq -r '.inbounds[0].tls.server_name' "$config_file")
local target_server=$(jq -r '.inbounds[0].tls.reality.handshake.server' "$config_file")
2024-01-02 02:21:44 +08:00
local transport_service_name=$(jq -r '.inbounds[0].transport.service_name' "$config_file")
local lobal_public_key="$public_key"
2023-10-09 11:28:46 +08:00
if [[ -n "$ip_v4" ]]; then
local_ip="$ip_v4"
elif [[ -n "$ip_v6" ]]; then
local_ip="$ip_v6"
2024-01-02 02:21:44 +08:00
fi
2023-09-15 18:48:54 +08:00
if [[ "$flow_type" == "xtls-rprx-vision" ]]; then
transport_type="tcp"
fi
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}VLESS Node Configuration Information:${NC}" | tee -a "$output_file"
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "Server Address: $local_ip" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Listening Port: $listen_port" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "UUID List:" | tee -a "$output_file"
for ((i = 0; i < ${#user_uuids[@]}; i++)); do
2023-10-12 13:39:59 +08:00
user_uuid="${user_uuids[$i]}"
2024-01-02 02:21:44 +08:00
echo "$user_uuid" | tee -a "$output_file"
2023-11-12 17:47:06 +08:00
done
2023-10-12 13:39:59 +08:00
if [ -n "$flow_type" ]; then
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Flow Control Type: $flow_type" | tee -a "$output_file"
2023-10-12 13:39:59 +08:00
fi
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
2023-10-12 13:39:59 +08:00
if [ "$transport_type" != "null" ]; then
2024-01-02 02:21:44 +08:00
echo "Transport Protocol: $transport_type" | tee -a "$output_file"
2023-10-12 13:39:59 +08:00
if [ "$transport_type" == "ws" ]; then
2024-01-02 02:21:44 +08:00
echo "Path: $transport_path" | tee -a "$output_file"
2023-11-14 14:20:52 +08:00
elif [ "$transport_type" == "httpupgrade" ]; then
2024-01-02 02:21:44 +08:00
echo "Path: $transport_path" | tee -a "$output_file"
2023-10-12 13:39:59 +08:00
elif [ "$transport_type" == "grpc" ]; then
2024-01-02 02:21:44 +08:00
echo "gRPC Service Name: $transport_service_name" | tee -a "$output_file"
2023-10-12 13:39:59 +08:00
fi
2023-09-24 10:05:14 +08:00
else
2024-01-02 02:21:44 +08:00
echo "Transport Protocol: tcp" | tee -a "$output_file"
2023-10-12 13:39:59 +08:00
fi
if [ -n "$server_name" ] && [ "$server_name" != "null" ]; then
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
2023-10-12 13:39:59 +08:00
echo "ServerName: $server_name" | tee -a "$output_file"
fi
if [ -n "$target_server" ] && [ "$target_server" != "null" ]; then
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Target Server Address: $target_server" | tee -a "$output_file"
2023-10-12 13:39:59 +08:00
fi
if [ -n "$short_id" ]; then
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
2023-10-12 13:39:59 +08:00
echo "Short ID:" | tee -a "$output_file"
2024-01-02 02:21:44 +08:00
for ((i = 0; i < ${#short_ids[@]}; i++)); do
2023-10-12 13:39:59 +08:00
short_id="${short_ids[$i]}"
echo "$short_id" | tee -a "$output_file"
done
fi
if [ -n "$public_key" ]; then
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
2023-10-12 13:39:59 +08:00
echo "PublicKey: $public_key" | tee -a "$output_file"
2023-09-24 10:05:14 +08:00
fi
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "" >>"$output_file"
echo "Configuration information has been saved to $output_file"
2023-09-25 11:30:38 +08:00
}
function display_reality_config_files() {
2024-01-02 02:21:44 +08:00
local config_file="/usr/local/etc/sing-box/config.json"
local clash_file="/usr/local/etc/sing-box/clash.yaml"
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
2023-10-09 11:28:46 +08:00
local win_client_file="/usr/local/etc/sing-box/win_client.json"
2023-09-25 11:30:38 +08:00
local flow_type=$(jq -r '.inbounds[0].users[0].flow' "$config_file")
local transport_type=$(jq -r '.inbounds[0].transport.type' "$config_file")
local server_name=$(jq -r '.inbounds[0].tls.server_name' "$config_file")
local target_server=$(jq -r '.inbounds[0].tls.reality.handshake.server' "$config_file")
2024-01-02 02:21:44 +08:00
local transport_service_name=$(jq -r '.inbounds[0].transport.service_name' "$config_file")
2023-10-09 11:28:46 +08:00
local lobal_public_key="$public_key"
if [[ -n "$ip_v4" ]]; then
local_ip="$ip_v4"
elif [[ -n "$ip_v6" ]]; then
local_ip="$ip_v6"
2023-10-12 13:39:59 +08:00
fi
2024-01-02 02:21:44 +08:00
for ((i = 0; i < ${#user_uuids[@]}; i++)); do
2023-10-12 13:39:59 +08:00
local user_uuid="${user_uuids[$i]}"
2023-11-12 17:47:06 +08:00
write_phone_client_file
write_win_client_file
2023-11-14 14:20:52 +08:00
if [[ "$server_name" == "null" ]] && [[ "$transport_type" == "null" ]]; then
2023-11-12 17:47:06 +08:00
ensure_clash_yaml
write_clash_yaml
generate_vless_tcp_yaml
generate_vless_win_client_config
generate_vless_phone_client_config
2023-11-14 14:20:52 +08:00
elif [[ "$server_name" == "null" ]] && [[ "$transport_type" == "ws" ]]; then
2023-11-12 17:47:06 +08:00
ensure_clash_yaml
write_clash_yaml
generate_vless_ws_yaml
generate_vless_win_client_config
generate_vless_phone_client_config
2023-11-14 14:20:52 +08:00
elif [[ "$server_name" == "null" ]] && [[ "$transport_type" == "grpc" ]]; then
2023-11-12 17:47:06 +08:00
ensure_clash_yaml
write_clash_yaml
generate_vless_grpc_yaml
generate_vless_win_client_config
generate_vless_phone_client_config
2023-11-14 14:20:52 +08:00
elif [[ "$server_name" == "null" ]] && [[ "$transport_type" == "httpupgrade" ]]; then
generate_vless_win_client_config
generate_vless_phone_client_config
2023-11-12 17:47:06 +08:00
fi
2024-01-02 02:21:44 +08:00
for ((j = 0; j < ${#short_ids[@]}; j++)); do
local short_id="${short_ids[$j]}"
2023-10-12 13:39:59 +08:00
write_phone_client_file
write_win_client_file
2023-11-14 14:20:52 +08:00
if [[ -n "$server_name" ]] && [[ "$server_name" != "null" ]] && [[ "$transport_type" == "null" ]]; then
2023-10-12 13:39:59 +08:00
ensure_clash_yaml
write_clash_yaml
generate_vless_reality_vision_yaml
generate_vless_win_client_config
generate_vless_phone_client_config
2023-11-14 14:20:52 +08:00
elif [[ -n "$server_name" ]] && [[ "$server_name" != "null" ]] && [[ "$transport_type" == "http" ]]; then
2023-10-12 13:39:59 +08:00
generate_vless_win_client_config
generate_vless_phone_client_config
2023-11-14 14:20:52 +08:00
elif [[ -n "$server_name" ]] && [[ "$server_name" != "null" ]] && [[ "$transport_type" == "grpc" ]]; then
2023-10-12 13:39:59 +08:00
ensure_clash_yaml
write_clash_yaml
generate_vless_reality_grpc_yaml
generate_vless_win_client_config
generate_vless_phone_client_config
fi
done
2023-09-25 11:30:38 +08:00
done
2023-11-14 14:20:52 +08:00
if [[ "$transport_type" != "http" && "$transport_type" != "httpupgrade" ]]; then
2024-01-02 02:21:44 +08:00
echo "Clash configuration file has been saved to $clash_file. Please download and use!"
fi
echo "Phone client configuration file has been saved to $phone_client_file. Please download and use!"
echo "Win client configuration file has been saved to $win_client_file. Please download and use!"
2023-09-15 18:48:54 +08:00
}
2023-09-25 11:30:38 +08:00
function display_vmess_config_info() {
2023-09-19 16:37:08 +08:00
local config_file="/usr/local/etc/sing-box/config.json"
2023-10-12 13:39:59 +08:00
local output_file="/usr/local/etc/sing-box/output.txt"
local server_address
2023-09-19 16:37:08 +08:00
local transport_type=$(jq -r '.inbounds[0].transport.type' "$config_file")
2024-01-02 02:21:44 +08:00
local transport_path=$(jq -r '.inbounds[0].transport.path' "$config_file")
local transport_service_name=$(jq -r '.inbounds[0].transport.service_name' "$config_file")
2023-10-09 11:28:46 +08:00
if [[ -n "$ip_v4" ]]; then
local_ip="$ip_v4"
elif [[ -n "$ip_v6" ]]; then
local_ip="$ip_v6"
2023-10-12 13:39:59 +08:00
fi
if [[ -z "$domain" && -n "$domain_name" ]]; then
server_address="$local_ip"
elif [[ -z "$domain" && -z "$domain_name" ]]; then
server_address="$local_ip"
elif [[ -n "$domain" ]]; then
server_address="$domain"
fi
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}VMess Node Configuration Information:${NC}" | tee -a "$output_file"
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "Server Address: $server_address" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Listening Port: $listen_port" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "UUID List:" | tee -a "$output_file"
echo "------------------------------------------------------------------------------" | tee -a "$output_file"
for ((i = 0; i < ${#user_uuids[@]}; i++)); do
2023-10-09 11:28:46 +08:00
user_uuid="${user_uuids[$i]}"
2024-01-02 02:21:44 +08:00
echo "$user_uuid" | tee -a "$output_file"
done
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
2023-09-24 10:05:14 +08:00
if [ "$transport_type" != "null" ]; then
2024-01-02 02:21:44 +08:00
echo "Transport Protocol: $transport_type" | tee -a "$output_file"
2023-09-24 10:05:14 +08:00
if [ "$transport_type" == "ws" ]; then
2024-01-02 02:21:44 +08:00
echo "Path: $transport_path" | tee -a "$output_file"
2023-11-14 14:20:52 +08:00
elif [ "$transport_type" == "httpupgrade" ]; then
2024-01-02 02:21:44 +08:00
echo "Path: $transport_path" | tee -a "$output_file"
2023-09-24 10:05:14 +08:00
elif [ "$transport_type" == "grpc" ]; then
2024-01-02 02:21:44 +08:00
echo "gRPC Service Name: $transport_service_name" | tee -a "$output_file"
2023-09-19 16:37:08 +08:00
fi
else
2024-01-02 02:21:44 +08:00
echo "Transport Protocol: tcp" | tee -a "$output_file"
2023-09-24 10:05:14 +08:00
fi
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "" >>"$output_file"
echo "Configuration information has been saved to $output_file"
2023-09-25 11:30:38 +08:00
}
function display_vmess_config_files() {
local config_file="/usr/local/etc/sing-box/config.json"
2024-01-02 02:21:44 +08:00
local clash_file="/usr/local/etc/sing-box/clash.yaml"
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
2023-10-12 13:39:59 +08:00
local win_client_file="/usr/local/etc/sing-box/win_client.json"
2023-09-25 11:30:38 +08:00
local transport_type=$(jq -r '.inbounds[0].transport.type' "$config_file")
2024-01-02 02:21:44 +08:00
local transport_path=$(jq -r '.inbounds[0].transport.path' "$config_file")
local transport_service_name=$(jq -r '.inbounds[0].transport.service_name' "$config_file")
2023-09-25 11:30:38 +08:00
local show_clash_message=true
2023-10-09 11:28:46 +08:00
if [[ -n "$ip_v4" ]]; then
local_ip="$ip_v4"
elif [[ -n "$ip_v6" ]]; then
local_ip="$ip_v6"
2024-01-02 02:21:44 +08:00
fi
for ((i = 0; i < ${#user_uuids[@]}; i++)); do
2023-10-09 11:28:46 +08:00
user_uuid="${user_uuids[$i]}"
2023-09-19 16:37:08 +08:00
write_phone_client_file
write_win_client_file
generate_vmess_win_client_config
generate_vmess_phone_client_config
2023-11-12 17:47:06 +08:00
if [ "$enable_ech" != true ] && [ -z "$domain" ] && [ -z "$domain_name" ] && [ "$transport_type" == "null" ]; then
2023-09-24 10:05:14 +08:00
ensure_clash_yaml
write_clash_yaml
generate_vmess_tcp_yaml
2023-11-12 17:47:06 +08:00
elif [ "$enable_ech" != true ] && [ -z "$domain" ] && [ -z "$domain_name" ] && [ "$transport_type" == "ws" ]; then
2023-09-24 10:05:14 +08:00
ensure_clash_yaml
write_clash_yaml
generate_vmess_ws_yaml
2023-11-12 17:47:06 +08:00
elif [ "$enable_ech" != true ] && [ -z "$domain" ] && [ -z "$domain_name" ] && [ "$transport_type" == "grpc" ]; then
2023-09-24 10:05:14 +08:00
ensure_clash_yaml
write_clash_yaml
generate_vmess_grpc_yaml
2023-11-12 17:47:06 +08:00
elif [ "$enable_ech" != true ] && [[ -n "$domain" || -n "$domain_name" ]] && [ "$transport_type" == "null" ]; then
2023-09-24 10:05:14 +08:00
ensure_clash_yaml
write_clash_yaml
generate_vmess_tcp_tls_yaml
2023-11-12 17:47:06 +08:00
elif [ "$enable_ech" != true ] && [[ -n "$domain" || -n "$domain_name" ]] && [ "$transport_type" == "ws" ]; then
2023-09-24 10:05:14 +08:00
ensure_clash_yaml
write_clash_yaml
generate_vmess_ws_tls_yaml
2023-11-12 17:47:06 +08:00
elif [ "$enable_ech" != true ] && [[ -n "$domain" || -n "$domain_name" ]] && [ "$transport_type" == "grpc" ]; then
2023-09-24 10:05:14 +08:00
ensure_clash_yaml
write_clash_yaml
generate_vmess_grpc_tls_yaml
2023-11-12 17:47:06 +08:00
elif [ "$enable_ech" != true ] && [[ -n "$domain" || -n "$domain_name" ]] && [ "$transport_type" == "http" ]; then
2023-09-25 11:30:38 +08:00
show_clash_message=false
2024-01-02 02:21:44 +08:00
fi
2023-09-24 10:05:14 +08:00
done
2023-11-14 14:20:52 +08:00
if [ "$transport_type" == "http" ] || [ "$transport_type" == "httpupgrade" ] || [ "$enable_ech" = true ]; then
2024-01-02 02:21:44 +08:00
echo "Phone client configuration file has been saved to $phone_client_file. Please download and use!"
echo "Win client configuration file has been saved to $win_client_file. Please download and use!"
2023-11-12 17:47:06 +08:00
else
2024-01-02 02:21:44 +08:00
echo "Phone client configuration file has been saved to $phone_client_file. Please download and use!"
echo "Win client configuration file has been saved to $win_client_file. Please download and use!"
echo "Clash configuration file has been saved to $clash_file. Please download and use!"
2023-09-25 11:30:38 +08:00
fi
2023-09-19 16:37:08 +08:00
}
2023-09-25 11:30:38 +08:00
function display_trojan_config_info() {
2023-09-15 18:48:54 +08:00
local config_file="/usr/local/etc/sing-box/config.json"
2024-01-02 02:21:44 +08:00
local output_file="/usr/local/etc/sing-box/output.txt"
2023-10-12 13:39:59 +08:00
local server_address
2023-09-15 18:48:54 +08:00
local transport_type=$(jq -r '.inbounds[0].transport.type' "$config_file")
local transport_path=$(jq -r '.inbounds[0].transport.path' "$config_file")
2023-10-12 13:39:59 +08:00
local transport_service_name=$(jq -r '.inbounds[0].transport.service_name' "$config_file")
if [[ -n "$ip_v4" ]]; then
local_ip="$ip_v4"
elif [[ -n "$ip_v6" ]]; then
local_ip="$ip_v6"
fi
if [[ -z "$domain" && -n "$domain_name" ]]; then
server_address="$local_ip"
elif [[ -z "$domain" && -z "$domain_name" ]]; then
server_address="$local_ip"
elif [[ -n "$domain" ]]; then
server_address="$domain"
fi
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}Trojan Node Configuration Information:${NC}" | tee -a "$output_file"
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "Server Address: $server_address" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Listening Port: $listen_port" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "Password List:" | tee -a "$output_file"
echo "------------------------------------------------------------------------------" | tee -a "$output_file"
2023-10-09 11:28:46 +08:00
for ((i = 0; i < ${#user_passwords[@]}; i++)); do
2024-01-02 02:21:44 +08:00
user_password="${user_passwords[i]}"
echo "$user_password" | tee -a "$output_file"
done
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
2023-09-15 18:48:54 +08:00
if [ "$transport_type" != "null" ]; then
2024-01-02 02:21:44 +08:00
echo "Transport Protocol: $transport_type" | tee -a "$output_file"
2023-09-24 10:05:14 +08:00
if [ "$transport_type" == "ws" ]; then
2024-01-02 02:21:44 +08:00
echo "Path: $transport_path" | tee -a "$output_file"
2023-11-14 14:20:52 +08:00
elif [ "$transport_type" == "httpupgrade" ]; then
2024-01-02 02:21:44 +08:00
echo "Path: $transport_path" | tee -a "$output_file"
2023-09-24 10:05:14 +08:00
elif [ "$transport_type" == "grpc" ]; then
2024-01-02 02:21:44 +08:00
echo "gRPC Service Name: $transport_service_name" | tee -a "$output_file"
2023-09-18 14:34:32 +08:00
fi
2023-09-15 18:48:54 +08:00
else
2024-01-02 02:21:44 +08:00
echo "Transport Protocol: tcp" | tee -a "$output_file"
2023-09-15 18:48:54 +08:00
fi
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
echo "" >>"$output_file"
echo "Configuration information has been saved to $output_file"
2023-09-25 11:30:38 +08:00
}
function display_trojan_config_files() {
local config_file="/usr/local/etc/sing-box/config.json"
2024-01-02 02:21:44 +08:00
local clash_file="/usr/local/etc/sing-box/clash.yaml"
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
local win_client_file="/usr/local/etc/sing-box/win_client.json"
2023-09-25 11:30:38 +08:00
local transport_type=$(jq -r '.inbounds[0].transport.type' "$config_file")
local transport_path=$(jq -r '.inbounds[0].transport.path' "$config_file")
2023-10-12 13:39:59 +08:00
local transport_service_name=$(jq -r '.inbounds[0].transport.service_name' "$config_file")
if [[ -n "$ip_v4" ]]; then
local_ip="$ip_v4"
elif [[ -n "$ip_v6" ]]; then
local_ip="$ip_v6"
2024-01-02 02:21:44 +08:00
fi
2023-10-09 11:28:46 +08:00
for ((i = 0; i < ${#user_passwords[@]}; i++)); do
2024-01-02 02:21:44 +08:00
user_password="${user_passwords[i]}"
2023-09-15 18:48:54 +08:00
write_phone_client_file
write_win_client_file
generate_trojan_win_client_config
generate_trojan_phone_client_config
2023-11-12 17:47:06 +08:00
if [[ "$enable_ech" != true ]] && [[ -n "$domain" || -n "$domain_name" ]] && [ "$transport_type" == "null" ]; then
2023-09-24 10:05:14 +08:00
ensure_clash_yaml
write_clash_yaml
2023-10-12 13:39:59 +08:00
generate_trojan_tcp_tls_yaml
2023-11-12 17:47:06 +08:00
elif [[ "$enable_ech" != true ]] && [[ -n "$domain" || -n "$domain_name" ]] && [ "$transport_type" == "ws" ]; then
2023-09-24 10:05:14 +08:00
ensure_clash_yaml
write_clash_yaml
2023-10-12 13:39:59 +08:00
generate_trojan_ws_tls_yaml
2023-11-12 17:47:06 +08:00
elif [[ "$enable_ech" != true ]] && [[ -n "$domain" || -n "$domain_name" ]] && [ "$transport_type" == "grpc" ]; then
2023-09-24 10:05:14 +08:00
ensure_clash_yaml
write_clash_yaml
2023-10-12 13:39:59 +08:00
generate_trojan_grpc_tls_yaml
2024-01-02 02:21:44 +08:00
fi
2023-09-15 18:48:54 +08:00
done
2023-11-14 14:20:52 +08:00
if [[ "$enable_ech" != true ]] && [[ -n "$domain" || -n "$domain_name" ]] && [[ "$transport_type" != "http" || "$transport_type" != "httpupgrade" ]]; then
2024-01-02 02:21:44 +08:00
echo "Clash configuration file has been saved to $clash_file. Please download and use!"
fi
echo "Phone client configuration file has been saved to $phone_client_file. Please download and use!"
echo "Win client configuration file has been saved to $win_client_file. Please download and use!"
2023-09-04 11:22:03 +08:00
}
2023-09-25 11:30:38 +08:00
function display_shadowtls_config_info() {
2023-07-29 15:12:16 +08:00
local config_file="/usr/local/etc/sing-box/config.json"
2024-01-02 02:21:44 +08:00
local output_file="/usr/local/etc/sing-box/output.txt"
2023-08-19 17:45:08 +08:00
local user_input=$(jq -r '.inbounds[0].handshake.server' "$config_file")
2023-10-09 11:28:46 +08:00
local method=$(jq -r '.inbounds[1].method' "$config_file")
if [[ -n "$ip_v4" ]]; then
local_ip="$ip_v4"
elif [[ -n "$ip_v6" ]]; then
local_ip="$ip_v6"
2023-11-03 17:20:00 +08:00
fi
2024-01-02 02:21:44 +08:00
echo -e "${CYAN}ShadowTLS Node Configuration Information:${NC}" | tee -a "$output_file"
2023-10-09 11:28:46 +08:00
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
2024-01-02 02:21:44 +08:00
echo "Server Address: $local_ip" | tee -a "$output_file"
2023-10-09 11:28:46 +08:00
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
2024-01-02 02:21:44 +08:00
echo "Listening Port: $listen_port" | tee -a "$output_file"
2023-10-09 11:28:46 +08:00
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
2024-01-02 02:21:44 +08:00
echo "Encryption Method: $method" | tee -a "$output_file"
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
echo "ShadowTLS Username ShadowTLS Password" | tee -a "$output_file"
echo "------------------------------------------------------------------------------" | tee -a "$output_file"
2023-10-09 11:28:46 +08:00
for ((i = 0; i < ${#stls_passwords[@]}; i++)); do
2024-01-02 02:21:44 +08:00
local stls_password="${stls_passwords[i]}"
2023-10-09 11:28:46 +08:00
printf "%-25s %s\n" "$user_name" "$stls_password" | tee -a "$output_file"
2024-01-02 02:21:44 +08:00
done
2023-10-09 11:28:46 +08:00
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
2024-01-02 02:21:44 +08:00
echo "Shadowsocks Password: $ss_passwords" | tee -a "$output_file"
2023-10-09 11:28:46 +08:00
echo -e "${CYAN}------------------------------------------------------------------------------${NC}" | tee -a "$output_file"
2024-01-02 02:21:44 +08:00
echo "Handshake Server Address: $user_input" | tee -a "$output_file"
2023-10-09 11:28:46 +08:00
echo -e "${CYAN}==============================================================================${NC}" | tee -a "$output_file"
2024-01-02 02:21:44 +08:00
echo "" >>"$output_file"
echo "Configuration information has been saved to $output_file"
2023-09-25 11:30:38 +08:00
}
function display_shadowtls_config_files() {
local config_file="/usr/local/etc/sing-box/config.json"
2024-01-02 02:21:44 +08:00
local clash_file="/usr/local/etc/sing-box/clash.yaml"
local phone_client_file="/usr/local/etc/sing-box/phone_client.json"
2023-10-09 11:28:46 +08:00
local win_client_file="/usr/local/etc/sing-box/win_client.json"
2023-09-25 11:30:38 +08:00
local user_input=$(jq -r '.inbounds[0].handshake.server' "$config_file")
2023-10-09 11:28:46 +08:00
local method=$(jq -r '.inbounds[1].method' "$config_file")
for ((i = 0; i < ${#stls_passwords[@]}; i++)); do
2024-01-02 02:21:44 +08:00
local stls_password="${stls_passwords[i]}"
2023-09-15 18:48:54 +08:00
write_phone_client_file
write_win_client_file
2023-10-09 11:28:46 +08:00
generate_shadowtls_win_client_config "$stls_password"
generate_shadowtls_phone_client_config "$stls_password"
2023-09-24 10:05:14 +08:00
ensure_clash_yaml
write_clash_yaml
2024-01-02 02:21:44 +08:00
generate_shadowtls_yaml
2023-09-24 10:05:14 +08:00
done
2024-01-02 02:21:44 +08:00
echo "Phone client configuration file has been saved to $phone_client_file. Please download and use!"
echo "Win client configuration file has been saved to $win_client_file. Please download and use!"
echo "Clash configuration file has been saved to $clash_file. Please download and use!"
2023-08-25 18:01:25 +08:00
}
2023-08-30 16:56:50 +08:00
function view_saved_config() {
local config_paths=(
"/usr/local/etc/sing-box/output.txt"
"/usr/local/etc/juicity/output.txt"
)
local found=false
for path in "${config_paths[@]}"; do
if [[ -f "$path" ]]; then
2024-01-02 02:21:44 +08:00
echo "Configuration information file ($path):"
2023-08-30 16:56:50 +08:00
cat "$path"
found=true
fi
done
if [[ "$found" == false ]]; then
2024-01-02 02:21:44 +08:00
echo "No saved configuration information file found!"
2023-07-29 12:09:39 +08:00
fi
2023-08-30 16:56:50 +08:00
}
2023-07-29 12:09:39 +08:00
2023-09-03 12:22:11 +08:00
function check_and_restart_services() {
2023-08-25 11:56:25 +08:00
if [ -f "/etc/systemd/system/sing-box.service" ]; then
systemctl restart sing-box.service
systemctl status --no-pager sing-box.service
2023-07-29 12:09:39 +08:00
fi
2023-08-25 18:01:25 +08:00
if [ -f "/etc/systemd/system/juicity.service" ]; then
systemctl restart juicity.service
systemctl status --no-pager juicity.service
2024-01-02 02:21:44 +08:00
fi
2023-07-29 12:09:39 +08:00
}
function uninstall_sing_box() {
2024-01-02 02:21:44 +08:00
echo "Uninstalling sing-box..."
2023-07-29 12:09:39 +08:00
systemctl stop sing-box
2023-08-10 17:30:49 +08:00
systemctl disable sing-box
2023-07-29 12:09:39 +08:00
rm -rf /usr/local/bin/sing-box
rm -rf /usr/local/etc/sing-box
rm -rf /etc/systemd/system/sing-box.service
systemctl daemon-reload
2024-01-02 02:21:44 +08:00
echo "sing-box has been uninstalled."
2023-07-29 12:09:39 +08:00
}
2023-08-25 18:01:25 +08:00
function uninstall_juicity() {
2024-01-02 02:21:44 +08:00
echo "Uninstalling juicity..."
2023-08-25 18:01:25 +08:00
systemctl stop juicity.service
systemctl disable juicity.service
rm -rf /etc/systemd/system/juicity.service
rm -rf /usr/local/etc/juicity
rm -rf /usr/local/bin/juicity-server
2024-01-02 02:21:44 +08:00
echo "juicity has been uninstalled."
2023-08-25 18:01:25 +08:00
}
2023-09-04 11:22:03 +08:00
function update_proxy_tool() {
if [ -e /usr/local/bin/juicity-server ]; then
install_latest_juicity
2023-11-12 17:47:06 +08:00
fi
2023-09-04 11:22:03 +08:00
if [ -e /usr/local/bin/sing-box ]; then
select_sing_box_install_option
fi
}
2023-08-19 17:45:08 +08:00
function uninstall() {
local uninstall_sing_box=false
2023-08-25 18:01:25 +08:00
local uninstall_juicity=false
2023-09-03 12:22:11 +08:00
if [[ -f "/etc/systemd/system/sing-box.service" ]] || [[ -f "/usr/local/bin/sing-box" ]] || [[ -d "/usr/local/etc/sing-box/" ]]; then
2023-08-19 17:45:08 +08:00
uninstall_sing_box=true
2023-11-12 17:47:06 +08:00
fi
2023-09-03 12:22:11 +08:00
if [[ -f "/etc/systemd/system/juicity.service" ]] || [[ -f "/usr/local/bin/juicity-server" ]] || [[ -d "/usr/local/etc/juicity/" ]]; then
2023-08-25 18:01:25 +08:00
uninstall_juicity=true
2023-09-03 12:22:11 +08:00
fi
2023-08-19 17:45:08 +08:00
if [[ "$uninstall_sing_box" == true ]]; then
uninstall_sing_box
fi
2023-08-25 18:01:25 +08:00
if [[ "$uninstall_juicity" == true ]]; then
uninstall_juicity
2024-01-02 02:21:44 +08:00
fi
2023-08-25 18:01:25 +08:00
}
2023-09-03 12:22:11 +08:00
function check_wireguard_config() {
local config_file="/usr/local/etc/sing-box/config.json"
if grep -q "wireguard" "$config_file"; then
2024-01-02 02:21:44 +08:00
echo -e "${RED}Warp is already installed. Please do not install it again!${NC}"
2023-09-03 12:22:11 +08:00
exit 1
fi
}
2023-11-14 14:20:52 +08:00
function Update_Script() {
2024-01-02 02:21:44 +08:00
wget -O /root/singbox.sh https://raw.githubusercontent.com/TheyCallMeSecond/sing-box-manager/main/Install.sh
chmod +x /root/singbox.sh
2023-11-14 14:20:52 +08:00
}
function add_cron_job() {
2024-01-02 02:21:44 +08:00
if command -v crontab >/dev/null && crontab -l | grep -q "singbox.sh"; then
2023-11-14 14:20:52 +08:00
echo "Cron job already exists."
else
2024-01-02 02:21:44 +08:00
(
crontab -l 2>/dev/null
echo "0 2 * * 1 /bin/bash /root/singbox.sh >> /usr/local/etc/certificate.log 2>&1"
) | crontab -
2023-11-14 14:20:52 +08:00
echo "Cron job added successfully."
fi
}
2023-08-25 18:01:25 +08:00
function juicity_install() {
configure_dns64
enable_bbr
2024-01-02 02:21:44 +08:00
create_juicity_folder
2023-08-30 16:56:50 +08:00
install_latest_juicity
2023-10-12 13:39:59 +08:00
get_local_ip
2023-08-25 18:01:25 +08:00
generate_juicity_config
2023-10-15 16:26:47 +08:00
add_cron_job
2023-08-25 18:01:25 +08:00
configure_juicity_service
systemctl daemon-reload
systemctl enable juicity.service
systemctl start juicity.service
systemctl restart juicity.service
display_juicity_config
2023-07-29 12:09:39 +08:00
}
function Direct_install() {
2023-09-03 12:22:11 +08:00
install_sing_box
2024-01-02 02:21:44 +08:00
enable_bbr
log_outbound_config
2023-10-09 11:28:46 +08:00
set_listen_port
set_override_address
set_override_port
2023-08-19 17:45:08 +08:00
generate_Direct_config
2023-09-08 14:48:08 +08:00
modify_format_inbounds_and_outbounds
2023-11-03 17:20:00 +08:00
modify_route_rules
2024-01-02 02:21:44 +08:00
check_firewall_configuration
systemctl daemon-reload
2023-08-31 17:05:32 +08:00
systemctl enable sing-box
2023-07-29 12:09:39 +08:00
systemctl start sing-box
2023-08-31 17:05:32 +08:00
systemctl restart sing-box
2024-01-02 02:21:44 +08:00
get_local_ip
2023-08-19 17:45:08 +08:00
display_Direct_config
2023-07-29 12:09:39 +08:00
}
function Shadowsocks_install() {
2023-09-03 12:22:11 +08:00
install_sing_box
2023-10-09 11:28:46 +08:00
enable_bbr
2024-01-02 02:21:44 +08:00
log_outbound_config
2023-10-09 11:28:46 +08:00
set_listen_port
select_encryption_method
set_ss_password
2023-08-19 17:45:08 +08:00
generate_ss_config
2023-09-08 14:48:08 +08:00
modify_format_inbounds_and_outbounds
2023-11-03 17:20:00 +08:00
modify_route_rules
2024-01-02 02:21:44 +08:00
check_firewall_configuration
systemctl daemon-reload
systemctl enable sing-box
2023-07-29 12:09:39 +08:00
systemctl start sing-box
2023-08-31 17:05:32 +08:00
systemctl restart sing-box
2023-10-09 11:28:46 +08:00
get_local_ip
2023-09-25 11:30:38 +08:00
display_Shadowsocks_config_info
display_Shadowsocks_config_files
2023-07-29 12:09:39 +08:00
}
2023-09-18 16:36:33 +08:00
function socks_install() {
install_sing_box
2024-01-02 02:21:44 +08:00
enable_bbr
log_outbound_config
2023-09-18 16:36:33 +08:00
generate_socks_config
modify_format_inbounds_and_outbounds
2023-11-03 17:20:00 +08:00
modify_route_rules
2024-01-02 02:21:44 +08:00
check_firewall_configuration
systemctl daemon-reload
systemctl enable sing-box
2023-09-18 16:36:33 +08:00
systemctl start sing-box
systemctl restart sing-box
2023-10-09 11:28:46 +08:00
get_local_ip
2023-09-25 11:30:38 +08:00
display_socks_config_info
display_socks_config_files
2023-09-18 16:36:33 +08:00
}
2023-07-29 12:09:39 +08:00
function NaiveProxy_install() {
2023-10-15 16:26:47 +08:00
install_sing_box
2023-10-09 11:28:46 +08:00
enable_bbr
2024-01-02 02:21:44 +08:00
log_outbound_config
2023-08-19 17:45:08 +08:00
generate_naive_config
2023-10-15 16:26:47 +08:00
add_cron_job
2024-01-02 02:21:44 +08:00
modify_format_inbounds_and_outbounds
modify_route_rules
2023-08-30 16:56:50 +08:00
systemctl daemon-reload
systemctl enable sing-box
systemctl start sing-box
2023-08-31 17:05:32 +08:00
systemctl restart sing-box
2023-09-25 11:30:38 +08:00
display_naive_config_info
generate_naive_config_files
2023-07-29 12:09:39 +08:00
}
2023-11-12 17:47:06 +08:00
function http_install() {
install_sing_box
enable_bbr
2024-01-02 02:21:44 +08:00
log_outbound_config
2023-11-12 17:47:06 +08:00
generate_http_config
add_cron_job
2024-01-02 02:21:44 +08:00
modify_format_inbounds_and_outbounds
modify_route_rules
2023-11-12 17:47:06 +08:00
systemctl daemon-reload
systemctl enable sing-box
systemctl start sing-box
systemctl restart sing-box
display_http_config_info
display_http_config_files
}
2023-07-29 12:09:39 +08:00
function tuic_install() {
2023-10-15 16:26:47 +08:00
install_sing_box
2023-10-09 11:28:46 +08:00
enable_bbr
2024-01-02 02:21:44 +08:00
log_outbound_config
2023-07-29 12:09:39 +08:00
generate_tuic_config
2023-10-15 16:26:47 +08:00
add_cron_job
2023-11-03 17:20:00 +08:00
modify_format_inbounds_and_outbounds
2024-01-02 02:21:44 +08:00
modify_route_rules
2023-07-29 12:09:39 +08:00
systemctl daemon-reload
2023-08-30 16:56:50 +08:00
systemctl enable sing-box
systemctl start sing-box
2023-08-31 17:05:32 +08:00
systemctl restart sing-box
2024-01-02 02:21:44 +08:00
get_local_ip
2023-09-25 11:30:38 +08:00
display_tuic_config_info
display_tuic_config_files
2023-07-29 12:09:39 +08:00
}
function Hysteria_install() {
2023-10-09 11:28:46 +08:00
install_sing_box
2024-01-02 02:21:44 +08:00
enable_bbr
log_outbound_config
2023-07-29 12:09:39 +08:00
generate_Hysteria_config
2023-10-15 16:26:47 +08:00
add_cron_job
2023-11-03 17:20:00 +08:00
modify_format_inbounds_and_outbounds
2024-01-02 02:21:44 +08:00
modify_route_rules
2023-07-29 12:09:39 +08:00
systemctl daemon-reload
systemctl enable sing-box
systemctl start sing-box
2023-08-31 17:05:32 +08:00
systemctl restart sing-box
2023-09-25 11:30:38 +08:00
display_Hysteria_config_info
display_Hysteria_config_files
2023-07-29 12:09:39 +08:00
}
2023-07-29 15:33:43 +08:00
2023-07-29 12:09:39 +08:00
function shadowtls_install() {
2023-10-14 14:56:42 +08:00
install_sing_box
2023-10-09 11:28:46 +08:00
enable_bbr
2024-01-02 02:21:44 +08:00
log_outbound_config
2023-08-19 17:45:08 +08:00
generate_shadowtls_config
2023-11-03 17:20:00 +08:00
modify_format_inbounds_and_outbounds
modify_route_rules
2024-01-02 02:21:44 +08:00
check_firewall_configuration
2023-07-29 12:09:39 +08:00
systemctl daemon-reload
systemctl enable sing-box
systemctl start sing-box
2023-08-31 17:05:32 +08:00
systemctl restart sing-box
2024-01-02 02:21:44 +08:00
get_local_ip
2023-09-25 11:30:38 +08:00
display_shadowtls_config_info
display_shadowtls_config_files
2023-07-29 12:09:39 +08:00
}
2023-07-29 15:33:43 +08:00
2023-07-29 12:09:39 +08:00
function reality_install() {
2023-10-09 11:28:46 +08:00
install_sing_box
enable_bbr
2024-01-02 02:21:44 +08:00
log_outbound_config
generate_vless_config
2023-11-03 17:20:00 +08:00
modify_format_inbounds_and_outbounds
modify_route_rules
2024-01-02 02:21:44 +08:00
check_firewall_configuration
2023-07-29 12:09:39 +08:00
systemctl daemon-reload
systemctl enable sing-box
systemctl start sing-box
2023-08-31 17:05:32 +08:00
systemctl restart sing-box
2024-01-02 02:21:44 +08:00
get_local_ip
2023-09-25 11:30:38 +08:00
display_reality_config_info
display_reality_config_files
2023-07-29 12:09:39 +08:00
}
2023-09-18 14:34:32 +08:00
function Hysteria2_install() {
2023-10-09 11:28:46 +08:00
install_sing_box
2024-01-02 02:21:44 +08:00
enable_bbr
log_outbound_config
2023-09-18 14:34:32 +08:00
generate_Hy2_config
2023-10-15 16:26:47 +08:00
add_cron_job
2023-11-03 17:20:00 +08:00
modify_format_inbounds_and_outbounds
modify_route_rules
2023-09-18 14:34:32 +08:00
systemctl daemon-reload
systemctl enable sing-box
systemctl start sing-box
systemctl restart sing-box
2023-09-25 11:30:38 +08:00
display_Hy2_config_info
display_Hy2_config_files
2023-09-18 14:34:32 +08:00
}
2023-08-17 17:46:42 +08:00
function trojan_install() {
2023-10-09 11:28:46 +08:00
install_sing_box
2024-01-02 02:21:44 +08:00
enable_bbr
2023-09-18 14:34:32 +08:00
log_outbound_config
2024-01-02 02:21:44 +08:00
generate_trojan_config
2023-10-15 16:26:47 +08:00
add_cron_job
2023-11-03 17:20:00 +08:00
modify_format_inbounds_and_outbounds
modify_route_rules
2024-01-02 02:21:44 +08:00
systemctl daemon-reload
systemctl enable sing-box
2023-08-17 17:46:42 +08:00
systemctl start sing-box
2023-08-31 17:05:32 +08:00
systemctl restart sing-box
2023-09-25 11:30:38 +08:00
display_trojan_config_info
display_trojan_config_files
2023-08-17 17:46:42 +08:00
}
2023-09-19 16:37:08 +08:00
function vmess_install() {
install_sing_box
2023-10-09 11:28:46 +08:00
enable_bbr
2024-01-02 02:21:44 +08:00
log_outbound_config
2023-10-12 13:39:59 +08:00
get_local_ip
2023-09-19 16:37:08 +08:00
generate_vmess_config
2023-10-15 16:26:47 +08:00
add_cron_job
2023-11-03 17:20:00 +08:00
modify_format_inbounds_and_outbounds
modify_route_rules
2024-01-02 02:21:44 +08:00
systemctl daemon-reload
2023-09-19 16:37:08 +08:00
systemctl enable sing-box
systemctl start sing-box
systemctl restart sing-box
2023-09-25 11:30:38 +08:00
display_vmess_config_info
display_vmess_config_files
2023-09-19 16:37:08 +08:00
}
2023-08-30 16:56:50 +08:00
function wireguard_install() {
2023-09-03 12:22:11 +08:00
check_wireguard_config
2023-08-30 16:56:50 +08:00
check_config_file_existence
select_unlocked_items
geosite=()
update_geosite_array
select_outbound
update_route_file "$outbound"
get_temp_config_file
extract_variables_and_cleanup
update_outbound_file
2024-01-08 06:33:24 +08:00
convert_rule_set
2023-08-31 17:05:32 +08:00
systemctl restart sing-box
2023-08-19 17:45:08 +08:00
}
2023-09-19 18:19:39 +08:00
function Update_certificate() {
2024-01-02 02:21:44 +08:00
get_local_ip
2023-09-19 18:19:39 +08:00
extract_tls_info
2023-10-12 13:39:59 +08:00
validate_tls_info
2023-09-19 18:19:39 +08:00
Reapply_certificates
2024-01-02 02:21:44 +08:00
}
2023-09-19 18:19:39 +08:00
2023-07-29 12:09:39 +08:00
function main_menu() {
2024-01-02 02:21:44 +08:00
echo "╔════════════════════════════════════════════════════════════════════════╗"
echo -e "${YELLOW} ░██████╗██╗███╗░░██╗░██████╗░░░░░░░██████╗░░█████╗░██╗░░██╗${NC}"
echo -e "${YELLOW} ██╔════╝██║████╗░██║██╔════╝░░░░░░░██╔══██╗██╔══██╗╚██╗██╔╝${NC}"
echo -e "${YELLOW} ╚█████╗░██║██╔██╗██║██║░░██╗░█████╗██████╦╝██║░░██║░╚███╔╝░${NC}"
echo -e "${YELLOW} ░╚═══██╗██║██║╚████║██║░░╚██╗╚════╝██╔══██╗██║░░██║░██╔██╗░${NC}"
echo -e "${YELLOW} ██████╔╝██║██║░╚███║╚██████╔╝░░░░░░██████╦╝╚█████╔╝██╔╝╚██╗${NC}"
echo -e "${YELLOW} ╚═════╝░╚═╝╚═╝░░╚══╝░╚═════╝░░░░░░░╚═════╝░░╚════╝░╚═╝░░╚═╝${NC}"
echo -e "║ ║"
echo -e "${YELLOW} ███╗░░░███╗░█████╗░███╗░░██╗░█████╗░░██████╗░███████╗██████╗░${NC}"
echo -e "${YELLOW} ████╗░████║██╔══██╗████╗░██║██╔══██╗██╔════╝░██╔════╝██╔══██╗${NC}"
echo -e "${YELLOW} ██╔████╔██║███████║██╔██╗██║███████║██║░░██╗░█████╗░░██████╔╝${NC}"
echo -e "${YELLOW} ██║╚██╔╝██║██╔══██║██║╚████║██╔══██║██║░░╚██╗██╔══╝░░██╔══██╗${NC}"
echo -e "${YELLOW} ██║░╚═╝░██║██║░░██║██║░╚███║██║░░██║╚██████╔╝███████╗██║░░██║${NC}"
echo -e "${YELLOW} ╚═╝░░░░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝╚═╝░░╚═╝░╚═════╝░╚══════╝╚═╝░░╚═╝${NC}"
echo "╠════════════════════════════════════════════════════════════════════════╣"
echo "║ Please choose an action to execute: ║"
echo -e "${CYAN}[1]${NC} SOCKS ${CYAN}[2]${NC} Direct ║"
echo -e "${CYAN}[3]${NC} HTTP ${CYAN}[4]${NC} VMess ║"
echo -e "${CYAN}[5]${NC} VLESS ${CYAN}[6]${NC} TUIC ║"
echo -e "${CYAN}[7]${NC} Juicity ${CYAN}[8]${NC} Trojan ║"
echo -e "${CYAN}[9]${NC} Hysteria ${CYAN}[10]${NC} Hysteria2 ║"
echo -e "${CYAN}[11]${NC} ShadowTLS ${CYAN}[12]${NC} NaiveProxy ║"
echo -e "${CYAN}[13]${NC} Shadowsocks ${CYAN}[14]${NC} WireGuard ║"
echo -e "${CYAN}[15]${NC} View Node Information ${CYAN}[16]${NC} Update Kernel ║"
echo -e "${CYAN}[17]${NC} Update Script ${CYAN}[18]${NC} Update Certificate ║"
echo -e "${CYAN}[19]${NC} Restart Services ${CYAN}[20]${NC} Node Management ║"
echo -e "${CYAN}[21]${NC} Uninstall ${CYAN}[0]${NC} Exit ║"
echo "╚════════════════════════════════════════════════════════════════════════╝"
2023-08-19 17:45:08 +08:00
local choice
2024-01-02 02:21:44 +08:00
read -p "Please select [0-21]: " choice
2023-08-19 17:45:08 +08:00
case $choice in
2024-01-02 02:21:44 +08:00
1)
socks_install
exit 0
;;
2)
Direct_install
exit 0
;;
3)
http_install
exit 0
;;
4)
vmess_install
exit 0
;;
5)
reality_install
exit 0
;;
6)
tuic_install
exit 0
;;
7)
juicity_install
exit 0
;;
8)
trojan_install
exit 0
;;
9)
Hysteria_install
exit 0
;;
10)
Hysteria2_install
exit 0
;;
11)
shadowtls_install
exit 0
;;
12)
NaiveProxy_install
exit 0
;;
13)
Shadowsocks_install
exit 0
;;
14)
wireguard_install
exit 0
;;
15)
view_saved_config
exit 0
;;
2023-07-29 12:09:39 +08:00
2024-01-02 02:21:44 +08:00
16)
update_proxy_tool
exit 0
;;
17)
Update_Script
exit 0
;;
18)
Update_certificate
;;
19)
check_and_restart_services
exit 0
;;
20)
delete_choice
exit 0
;;
21)
uninstall
exit 0
;;
0)
echo "Thanks for using! goodbye!"
exit 0
;;
*)
echo -e "${RED}Invalid selection, please re-enter.${NC}"
main_menu
;;
2023-08-19 17:45:08 +08:00
esac
2023-07-28 11:28:46 +08:00
}
2023-10-14 14:56:42 +08:00
function run_option() {
case "$1" in
2024-01-02 02:21:44 +08:00
"18")
Update_certificate
exit 0
;;
2023-10-14 14:56:42 +08:00
esac
}
if [ $# -eq 0 ]; then
main_menu
else
run_option "$1"
fi
2023-07-29 12:09:39 +08:00
main_menu