Load SNI From env

This commit is contained in:
ReturnFI
2024-09-05 13:58:45 +00:00
parent ff07e14d98
commit 20e99e3575
4 changed files with 16 additions and 11 deletions

View File

@ -1,19 +1,15 @@
#!/bin/bash #!/bin/bash
# Source the path.sh script to load the CONFIG_FILE variable
source /etc/hysteria/core/scripts/path.sh source /etc/hysteria/core/scripts/path.sh
# Function to update port number in configuration
update_port() { update_port() {
local port=$1 local port=$1
# Validate the port number
if ! [[ "$port" =~ ^[0-9]+$ ]] || [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then if ! [[ "$port" =~ ^[0-9]+$ ]] || [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
echo "Invalid port number. Please enter a number between 1 and 65535." echo "Invalid port number. Please enter a number between 1 and 65535."
return 1 return 1
fi fi
# Check if the config file exists and update the port number
if [ -f "$CONFIG_FILE" ]; then if [ -f "$CONFIG_FILE" ]; then
jq --arg port "$port" '.listen = ":" + $port' "$CONFIG_FILE" > "${CONFIG_FILE}.temp" && mv "${CONFIG_FILE}.temp" "$CONFIG_FILE" jq --arg port "$port" '.listen = ":" + $port' "$CONFIG_FILE" > "${CONFIG_FILE}.temp" && mv "${CONFIG_FILE}.temp" "$CONFIG_FILE"
python3 "$CLI_PATH" restart-hysteria2 > /dev/null 2>&1 python3 "$CLI_PATH" restart-hysteria2 > /dev/null 2>&1

View File

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
source /etc/hysteria/core/scripts/path.sh source /etc/hysteria/core/scripts/path.sh
source /etc/hysteria/core/scripts/utils.sh
get_singbox_domain_and_port() { get_singbox_domain_and_port() {
if [ -f "$SINGBOX_ENV" ]; then if [ -f "$SINGBOX_ENV" ]; then
@ -22,6 +23,8 @@ show_uri() {
local show_all=false local show_all=false
local generate_singbox=false local generate_singbox=false
load_hysteria2_env
while [[ "$#" -gt 0 ]]; do while [[ "$#" -gt 0 ]]; do
case $1 in case $1 in
-u|--username) username="$2"; shift ;; -u|--username) username="$2"; shift ;;
@ -49,9 +52,9 @@ show_uri() {
local ip_version=$1 local ip_version=$1
local ip=$2 local ip=$2
if [ "$ip_version" -eq 4 ]; then if [ "$ip_version" -eq 4 ]; then
echo "hy2://$username%3A$authpassword@$ip:$port?obfs=salamander&obfs-password=$obfspassword&pinSHA256=$sha256&insecure=1&sni=bts.com#$username-IPv4" echo "hy2://$username%3A$authpassword@$ip:$port?obfs=salamander&obfs-password=$obfspassword&pinSHA256=$sha256&insecure=1&sni=$SNI#$username-IPv4"
elif [ "$ip_version" -eq 6 ]; then elif [ "$ip_version" -eq 6 ]; then
echo "hy2://$username%3A$authpassword@[$ip]:$port?obfs=salamander&obfs-password=$obfspassword&pinSHA256=$sha256&insecure=1&sni=bts.com#$username-IPv6" echo "hy2://$username%3A$authpassword@[$ip]:$port?obfs=salamander&obfs-password=$obfspassword&pinSHA256=$sha256&insecure=1&sni=$SNI#$username-IPv6"
fi fi
} }
@ -112,4 +115,4 @@ show_uri() {
fi fi
} }
show_uri "$@" show_uri "$@"

View File

@ -9,11 +9,9 @@ define_colors() {
NC='\033[0m' # No Color NC='\033[0m' # No Color
} }
# Function to get system information
get_system_info() { get_system_info() {
OS=$(lsb_release -d | awk -F'\t' '{print $2}') OS=$(lsb_release -d | awk -F'\t' '{print $2}')
ARCH=$(uname -m) ARCH=$(uname -m)
# Fetching detailed IP information in JSON format
IP_API_DATA=$(curl -s https://ipapi.co/json/ -4) IP_API_DATA=$(curl -s https://ipapi.co/json/ -4)
ISP=$(echo "$IP_API_DATA" | jq -r '.org') ISP=$(echo "$IP_API_DATA" | jq -r '.org')
IP=$(echo "$IP_API_DATA" | jq -r '.ip') IP=$(echo "$IP_API_DATA" | jq -r '.ip')
@ -53,3 +51,13 @@ check_version() {
echo -e "${cyan}Bug squashing party!${yellow} Update for the best invitation.${NC}" echo -e "${cyan}Bug squashing party!${yellow} Update for the best invitation.${NC}"
fi fi
} }
load_hysteria2_env() {
if [ -f /etc/hysteria/hysteria2.env ]; then
export $(grep -v '^#' /etc/hysteria/hysteria2.env | xargs)
else
echo "Error: hysteria2.env file not found. Using default SNI 'bts.com'."
SNI="bts.com"
fi
}

View File

@ -29,8 +29,6 @@ hysteria2_install_handler() {
cat <<EOF > /etc/hysteria/hysteria2.env cat <<EOF > /etc/hysteria/hysteria2.env
SNI=$sni SNI=$sni
EOF EOF
echo "Installation complete."
} }
hysteria2_add_user_handler() { hysteria2_add_user_handler() {