vpn-client-script/gen.sh

139 lines
3.4 KiB
Bash
Raw Normal View History

2022-08-29 18:50:26 +02:00
#!/usr/bin
2022-09-01 17:35:44 +02:00
source IPS
#--------------------Input---------------------
2022-09-02 00:31:50 +02:00
echo -e "File Name with:\r"
2022-09-01 17:35:44 +02:00
read file_name
2022-09-02 00:31:50 +02:00
echo -e "Please Put The Client Ip Address:\r"
2022-09-01 23:43:10 +02:00
echo -e "The Ip Please:\r"; read user_input
2022-09-02 00:31:50 +02:00
sleep 1
echo -e "Choose DNS: [1=Default 2=Google 3=Both 4=noDNS]";read DNS
echo "Please add allow ips:"
sleep 1
2022-09-01 17:35:44 +02:00
echo -e "Input Your Allow IPS :\r";read allow
echo "Would You Like To Have This Config On QR-Code Or File:"
2022-09-02 00:31:50 +02:00
sleep 1
2022-09-01 17:35:44 +02:00
echo -e "QR-code Press 1: File Press 2: \r"
read user_wish
2022-09-02 00:31:50 +02:00
sleep 1
2022-09-01 17:35:44 +02:00
#--------------------End---------------------
2022-09-02 00:31:50 +02:00
#------------- Update-Variables--------------
2022-09-02 00:36:49 +02:00
file_name+=".conf"
2022-09-02 00:31:50 +02:00
user_input+="/24"
allow+="/24"
2022-09-01 17:35:44 +02:00
#---------------Start-Checking---------------
echo -ne '# (1%)\n'
sleep 1
2022-08-29 18:50:26 +02:00
#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
}
2022-09-01 17:35:44 +02:00
echo -ne '##### (33%)\n'
sleep 1
#---------------End-Checking-----------------
2022-08-29 18:50:26 +02:00
2022-09-01 17:35:44 +02:00
#---------------Start-Build------------------
echo -ne '######### (40%)\n'
sleep 1
2022-08-29 18:50:26 +02:00
gen () {
#gen keys for Clinet:
wg genkey | tee privatekey | wg pubkey > publickey
#___________________________________________________
#Create file for config the clinet.
#Request Check Function From ips.sh
2022-09-01 17:35:44 +02:00
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
2022-09-02 00:31:50 +02:00
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
:
2022-08-29 18:50:26 +02:00
else
2022-09-02 00:31:50 +02:00
echo "Wrong Input"
exit 1
2022-08-29 18:50:26 +02:00
fi
2022-09-02 00:31:50 +02:00
2022-09-01 17:35:44 +02:00
echo -ne '################ (60%)\n'
sleep 1
2022-08-29 18:50:26 +02:00
echo "Adding peer......";sleep 2
2022-09-01 17:35:44 +02:00
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
2022-08-31 06:10:05 +02:00
if [ $user_wish -eq 1 ];then
2022-09-01 17:35:44 +02:00
qrencode -t PNG -o qrscanme.png < "$file_name"
2022-08-29 18:50:26 +02:00
echo "Please scan this code with wireguard-app"
2022-08-31 06:10:05 +02:00
elif [ $user_wish -eq 2 ];then
2022-08-29 18:50:26 +02:00
echo "Your file is ready"
else
echo "Oops wrong input"
fi
2022-09-01 17:35:44 +02:00
echo -ne '################### (70%)\n'
sleep 1
#---------------Done-Build------------------
#--------------Writing-New-Data-------------
2022-09-01 23:46:00 +02:00
sed -i '' '7i\'$'\n'' '$user_input' ' IPS
2022-09-01 17:35:44 +02:00
echo -ne '###################### (85%)\n'
sleep 1
2022-08-29 18:50:26 +02:00
#cleaning files
echo "Cleaning....";sleep 1
rm privatekey publickey
2022-09-01 17:35:44 +02:00
echo -ne '######################## (90%)\n'
sleep 1
echo -ne '\n'
2022-08-29 18:50:26 +02:00
}
2022-09-01 20:25:03 +02:00
2022-09-01 23:15:23 +02:00
#---------------Pushing-to-repo-----------------
push (){
echo -e "Start Pushing To Repo:"
git add .
2022-09-01 23:33:42 +02:00
git commit -m "add new client='$userinput'"
2022-09-01 23:15:23 +02:00
git push
echo -e "Done Pushing."
}
#---------------Pushing-to-repo-----------------
2022-09-01 20:25:03 +02:00
#---------------Call-Functions-----------------
2022-09-01 19:04:48 +02:00
echo -ne '######################### (95%)\n'
2022-09-01 20:25:03 +02:00
check_ip
push
2022-09-01 19:04:48 +02:00
echo -ne '##########################(100%)\n'
#-----------------End--Pushing------------------
sleep 1
echo "Done generating config:"
2022-09-01 20:25:03 +02:00