Template
QR code show
This commit is contained in:
@@ -13,6 +13,7 @@ cd "$SCRIPT_DIR"
|
||||
# Global variables
|
||||
server_pubkey=""
|
||||
ips=""
|
||||
users=""
|
||||
|
||||
# ==============================================================================
|
||||
# 2. HELPER FUNCTIONS
|
||||
@@ -34,20 +35,21 @@ environment_var() {
|
||||
# --- Variable Checks ---
|
||||
server_pubkey=$(cat ${WG0_DIR}/publickey)
|
||||
ips=$(grep -i '^\s*AllowedIPs\s*=\s*' "${WG0_DIR}/wg0.conf" | sed 's/^\s*AllowedIPs\s*=\s*//I; s/\s*$//')
|
||||
users=$(grep -i '^\s*# BEGIN_PEER \s*' "${WG0_DIR}/wg0.conf" | sed 's/^\s*# BEGIN_PEER \s*//i; s/\s*$//')
|
||||
}
|
||||
|
||||
# Find the last registered client IP
|
||||
find_last_ip() {
|
||||
# Find the last ip an create the next ip
|
||||
if [ -n "$ips" ]; then
|
||||
last=$(printf '%s\n' "$ips" | tail -1)
|
||||
last=$(printf "%s\n" "$ips" | tail -1)
|
||||
addr=${last%/*} # strip /32 if present
|
||||
IFS=. read -r a b c d <<< "$addr"
|
||||
next_ip="10.0.0.$((d + 1))"
|
||||
printf 'Last CIDR: %s\nNext IP: %s/32\n' "$last" "$next_ip"
|
||||
printf "Last CIDR: %s\nNext IP: %s/32\n" "$last" "$next_ip"
|
||||
else
|
||||
next_ip="10.0.0.2"
|
||||
printf 'No peers found, starting at %s/32\n' "$next_ip"
|
||||
printf "No peers found, starting at %s/32\n" "$next_ip"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -78,8 +80,12 @@ main() {
|
||||
environment_var
|
||||
|
||||
# Print current values
|
||||
printf 'Public Key of the server: %s\n' "$server_pubkey"
|
||||
printf 'List of current clients: %s\n' "$ips"
|
||||
printf "Public Key of the server: %s\n" "$server_pubkey"
|
||||
printf "List of current clients:\n"
|
||||
paste -d '|' <(echo "$users") <(echo "$ips") | while IFS='|' read -r user ip; do
|
||||
echo "User: $user -> IP: $ip"
|
||||
done
|
||||
printf "\n"
|
||||
|
||||
# Find the last IP
|
||||
find_last_ip
|
||||
|
||||
Reference in New Issue
Block a user