Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automatic variable detection #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 27 additions & 31 deletions awg/newclient.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ else
IPV6="no"
fi

WG_QUICK_CMD="${WG_CMD}-quick"
#WG_QUICK_CMD="${WG_CMD}-quick"

if [[ ! "$CLIENT_NAME" =~ ^[a-zA-Z0-9_-]+$ ]]; then
echo "Error: Invalid CLIENT_NAME. Only letters, numbers, underscores, and hyphens are allowed."
Expand Down Expand Up @@ -63,7 +63,7 @@ if [ -z "$internal_subnet" ]; then
fi

IFS='/' read -r subnet base_prefix <<< "$internal_subnet"
IFS='.' read -r a b c d <<< "$subnet"
IFS='.' read -r a b c <<< "$subnet"

if [ "$base_prefix" -ne 24 ]; then
echo "Error: Unsupported subnet prefix. Only /24 is supported."
Expand All @@ -88,17 +88,17 @@ mkdir -p "$pwd/users/$CLIENT_NAME"
key=$($WG_CMD genkey)
psk=$($WG_CMD genpsk)

if [[ "$WG_CONFIG_FILE" == *amnezia* ]]; then
jc=4
jmin=15
jmax=1268
s1=131
s2=45
h1=1004746675
h2=1157755290
h3=1273046607
h4=2137162994
fi
get_value() {
local key="$1"
value=$(awk -F '=' -v k="$key" '$1 ~ k {gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2}' "$WG_CONFIG_FILE")

if [[ -z "$value" ]]; then
value=0
echo "Значение для '$key' не найдено. Устанавливаем в 0."
fi

echo "$value"
}

dns_servers=$(awk '/^\[Interface\]/ {flag=1; next} /^\[/ {flag=0} flag && /^DNS\s*=/ {
gsub(/DNS\s*=\s*/, "")
Expand Down Expand Up @@ -187,15 +187,13 @@ EOF

if [[ "$WG_CONFIG_FILE" == *amnezia* ]]; then
cat << EOF >> "$pwd/users/$CLIENT_NAME/$CLIENT_NAME.conf"
Jc = 4
Jmin = 15
Jmax = 1268
S1 = 131
S2 = 45
H1 = 1004746675
H2 = 1157755290
H3 = 1273046607
H4 = 2137162994
Jc=$(get_value "Jc")
Jmin=$(get_value "Jmin")
Jmax=$(get_value "Jmax")
H1=$(get_value "H1")
H2=$(get_value "H2")
H3=$(get_value "H3")
H4=$(get_value "H4")
EOF
fi

Expand All @@ -218,15 +216,13 @@ EOF

if [[ "$WG_CONFIG_FILE" == *amnezia* ]]; then
cat << EOF >> "$pwd/users/$CLIENT_NAME/$CLIENT_NAME.conf"
Jc = 4
Jmin = 15
Jmax = 1268
S1 = 131
S2 = 45
H1 = 1004746675
H2 = 1157755290
H3 = 1273046607
H4 = 2137162994
Jc=$(get_value "Jc")
Jmin=$(get_value "Jmin")
Jmax=$(get_value "Jmax")
H1=$(get_value "H1")
H2=$(get_value "H2")
H3=$(get_value "H3")
H4=$(get_value "H4")
EOF
fi

Expand Down