vpn-client-script/gen.sh

138 lines
3.4 KiB
Bash
Executable File

#!/usr/bin
source IPS
#--------------------Input---------------------
echo -e "File Name with:\r"
read file_name
echo -e "Please Put The Client Ip Address:\r"
echo -e "The Ip Please:\r"; read user_input
sleep 1
echo -e "Choose DNS: [1=Default 2=Google 3=Both 4=noDNS]";read DNS
echo "Please add allow ips:"
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---------------------
#------------- Update-Variables--------------
user_input+="/24"
allow+="/24"
#---------------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 [ $DNS -eq 1 ];then
echo "DNS = 10.10.11.1" >> $file_name
elif [ $DNS -eq 2 ];then
echo "DNS = 8.8.8.8" >> $file_name
elif [ $DNS -eq 3 ];then
echo "DNS = 10.10.11.1,8.8.8.8" >> $file_name
elif [ $DNS -eq 4 ];then
:
else
echo "Wrong Input"
exit 1
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' ' 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'
}
#---------------Pushing-to-repo-----------------
push (){
echo -e "Start Pushing To Repo:"
git add .
git commit -m "add new client='$userinput'"
git push
echo -e "Done Pushing."
}
#---------------Pushing-to-repo-----------------
#---------------Call-Functions-----------------
echo -ne '######################### (95%)\n'
check_ip
push
echo -ne '##########################(100%)\n'
#-----------------End--Pushing------------------
sleep 1
echo "Done generating config:"