vpn-client-script/gen.sh

120 lines
3.2 KiB
Bash

#!/usr/bin
source IPS
source push-to-repo
#--------------------Input---------------------
echo -e "File Name with .conf:\r"
read file_name
echo -e "Please Put The Client Ip Address With Subnet:\r"
echo -e "The Ip Please:\r"; read user_input
sleep 1
echo -e "Would You Like To Have DNS:\r";echo -e "[1=yes] or [2=no]\r";read answer
sleep 1
echo -e "Which DNS Would You Like To Have:\r";read DNS
echo "Please add allow ips with subnet Ex:10.10.11.1/24:"
sleep 1
echo -e "Input Your Allow IPS :\r";read allow
echo "Would You Like To Have This Config On QR-Code Or File:"
sleep 1
echo -e "QR-code Press 1: File Press 2: \r"
read user_wish
sleep 1
#--------------------End---------------------
#---------------Start-Checking---------------
echo -ne '# (1%)\n'
sleep 1
#Checking IPS
echo "Checking.....";sleep 1
check_ip () {
for ip in "${ips[@]}"
do
if [[ "$ip" == "$user_input" ]];then
echo "ip exist"
ip_checked= return 1
fi
done
#Checking if the ip net exist do this:
if [[ $i -ne 1 ]]
then
echo "Ip Accepted:";echo "Your Config will be generate in seconds."
sleep 2
gen
fi
}
echo -ne '##### (33%)\n'
sleep 1
#---------------End-Checking-----------------
#---------------Start-Build------------------
echo -ne '######### (40%)\n'
sleep 1
gen () {
#gen keys for Clinet:
wg genkey | tee privatekey | wg pubkey > publickey
#___________________________________________________
#Create file for config the clinet.
#Request Check Function From ips.sh
touch $file_name;echo "[Interface]" >> $file_name;echo "Address = $user_input" >> $file_name
echo "PrivateKey = $(cat privatekey)" >> $file_name
echo "$user_input = privatekey= $(cat privatekey) publickey= $(cat publickey)" >> user_info
echo -ne '############# (50%)\n'
sleep 1
if [ $answer -eq 1 ];then
echo "DNS = $DNS" >> $file_name
elif [ $answer -eq 2 ];then
echo "Ok Continue....."
else
echo "Oops Wrong input the code will continue....."
fi
echo -ne '################ (60%)\n'
sleep 1
echo "Adding peer......";sleep 2
echo "[Peer]">>$file_name;
echo "PublicKey = w3qegSSuqFTFrGk4XJaWBSwGDOiqbnnAIR9MzwjYVA8=">> $file_name
echo "Endpoint = 81.201.149.152:18800">> $file_name
echo "AllowedIPs= $allow ">> $file_name
echo "PersistentKeepalive = 25" >> $file_name
echo -ne '################## (65%)\n'
sleep 1
if [ $user_wish -eq 1 ];then
qrencode -t PNG -o qrscanme.png < "$file_name"
echo "Please scan this code with wireguard-app"
elif [ $user_wish -eq 2 ];then
echo "Your file is ready"
else
echo "Oops wrong input"
fi
echo -ne '################### (70%)\n'
sleep 1
#---------------Done-Build------------------
#--------------Writing-New-Data-------------
sed -i '' '7i\'$'\n'' "'$user_input'/24" ' IPS
echo -ne '###################### (85%)\n'
sleep 1
#cleaning files
echo "Cleaning....";sleep 1
rm privatekey publickey
echo -ne '######################## (90%)\n'
sleep 1
echo -ne '\n'
}
#---------------Call-Functions-----------------
echo -ne '######################### (95%)\n'
check_ip
push
echo -ne '##########################(100%)\n'
#-----------------End--Pushing------------------
sleep 1
echo "Done generating config:"