1
0
Fork 0

script changes

This commit is contained in:
Arthur Khachaturov 2024-08-18 03:41:19 +03:00
parent 6e8683c725
commit 775a43810c
No known key found for this signature in database
GPG key ID: CAC2B7EB6DF45D55
6 changed files with 108 additions and 25 deletions

49
.local/bin/scripts/vpnd Executable file
View file

@ -0,0 +1,49 @@
#!/bin/bash
# shellcheck disable=SC2034
PIPE="/var/run/vpnd.sock"
[ -p $PIPE ] && exit 1
[ "$(id -u)" != "0" ] && exit 1
trap 'die' SIGTERM SIGQUIT SIGINT
declare -a CONFIGS
for config in /etc/wireguard/*; do
config="$(basename "$config")"
CONFIGS+=("${config%.conf}")
done
COMMANDS=("up" "down")
die() {
rm $PIPE
exit 0
}
in_arr() {
declare -n arr="$2"
for value in "${arr[@]}"; do
[ "$value" = "$1" ] && return 0
done
return 1
}
main() {
mkfifo $PIPE -m666
while :; do
read -r cmd ifname < $PIPE
if ! in_arr "$ifname" "CONFIGS"; then
echo "ERROR: Invalid interface $ifname" > $PIPE
elif ! in_arr "$cmd" "COMMANDS"; then
echo "ERROR: Invalid command $cmd" > $PIPE
else
wg-quick "$cmd" "$ifname" > $PIPE 2>&1
fi
done
}
main