vpn-client-script/gen.sh

150 lines
3.7 KiB
Bash
Raw Permalink Normal View History

2022-08-29 18:50:26 +02:00
#!/usr/bin
2022-09-01 17:35:44 +02:00
source IPS
2022-09-02 04:33:10 +02:00
#--------------------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
2022-09-02 02:21:11 +02:00
echo -e "Choose DNS: [1=Server 2=Google 3=Both 4=noDNS]";read DNS
2022-09-02 00:31:50 +02:00
sleep 1
2022-09-02 01:45:05 +02:00
echo -e "Share Network With Other-Clients:\n"
echo -e "[Yes=1 \ No=2]";read allow
2022-09-02 00:31:50 +02:00
sleep 1
2022-09-02 02:42:59 +02:00
echo -e "QR-code AND File[1] \ Only File[2]: \r"
2022-09-01 17:35:44 +02:00
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"
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
2022-09-02 04:33:10 +02:00
python3 -c 'import cat;cat.cat_search()'
2022-12-30 03:29:21 +01:00
check_ip () {
2022-08-29 18:50:26 +02:00
for ip in "${ips[@]}"
do
if [[ "$ip" == "$user_input" ]];then
echo "ip exist"
2022-09-02 02:21:11 +02:00
echo "Try Again !!"
2022-09-02 04:33:10 +02:00
echo "The Cat Found Existing IP."
2022-09-02 02:08:31 +02:00
checked= return 1
exit 0
2022-08-29 18:50:26 +02:00
fi
done
#Checking if the ip net exist do this:
2022-09-02 02:08:31 +02:00
if [[ $checked -ne 1 ]]
2022-08-29 18:50:26 +02:00
then
2022-09-02 00:43:03 +02:00
echo "Ip Accepted:"
2022-08-29 18:50:26 +02:00
sleep 2
2022-09-02 02:21:11 +02:00
gen #Function for generate the config.
echo "Done generating config:"
2022-09-02 02:42:59 +02:00
mv $file_name config_file
2022-09-02 02:46:14 +02:00
mv "$file_name.png" qr-code
2022-09-02 04:41:48 +02:00
push #Function for Pushing on Gitea.
2022-09-02 04:33:10 +02:00
echo -ne '##########################(100%)\n'
python3 -c 'import cat;cat.cat_done()'
2022-08-29 18:50:26 +02:00
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
2022-09-02 04:33:10 +02:00
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;
2022-12-29 04:31:21 +01:00
echo "PublicKey = iEVq4lvvKFfqjcoYYyNkA0MS8rcSGaDfPwQGN3C7+D0=">> $file_name
2022-10-01 22:05:29 +02:00
echo "Endpoint = 45.158.40.162:18900">> $file_name
2022-09-02 01:45:05 +02:00
if [ $allow -eq 1 ];then
echo -e "AllowedIPs= 10.10.11.0/24 " >> $file_name
elif [ $allow -eq 2 ];then
echo -e "AllowedIPs= $user_input ">> $file_name
else
echo "Wrong input."
exit 1
fi
2022-09-01 17:35:44 +02:00
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-02 02:46:14 +02:00
qrencode -t PNG -o "$file_name.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"
2022-09-02 01:45:05 +02:00
exit 1
2022-08-29 18:50:26 +02:00
fi
2022-09-01 17:35:44 +02:00
echo -ne '################### (70%)\n'
sleep 1
#---------------Done-Build------------------
2022-09-02 04:33:10 +02:00
2022-09-01 17:35:44 +02:00
#--------------Writing-New-Data-------------
2022-09-02 00:43:03 +02:00
sed -i '' '7i\'$'\n'' "'$user_input'" ' IPS
2022-09-02 04:33:10 +02:00
#--------------Done--Writing----------------
2022-09-01 17:35:44 +02:00
echo -ne '###################### (85%)\n'
sleep 1
2022-09-02 04:33:10 +02:00
#--------------cleaning-files---------------
2022-08-29 18:50:26 +02:00
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-09-02 02:21:11 +02:00
2022-08-29 18:50:26 +02:00
}
2022-09-01 23:15:23 +02:00
#---------------Pushing-to-repo-----------------
push (){
echo -e "Start Pushing To Repo:"
git add .
2022-09-02 03:04:50 +02:00
git commit -m "add new client"
2022-09-01 23:15:23 +02:00
git push
echo -e "Done Pushing."
2022-09-02 00:43:03 +02:00
echo -ne '######################### (95%)\n'
2022-09-01 23:15:23 +02:00
}
2022-09-02 01:45:05 +02:00
#-------------Done--Pushing--------------------
2022-09-01 23:15:23 +02:00
2022-09-02 02:21:11 +02:00
2022-09-01 20:25:03 +02:00
#---------------Call-Functions-----------------
check_ip
2022-09-02 02:21:11 +02:00
#-----------------End--Call------------------
exit 0