renew-wg.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. red='\e[1;31m'
  3. green='\e[0;32m'
  4. NC='\e[0m'
  5. MYIP=$(wget -qO- https://icanhazip.com);
  6. echo "Checking VPS"
  7. clear
  8. source /etc/wireguard/params
  9. NUMBER_OF_CLIENTS=$(grep -c -E "^### Client" "/etc/wireguard/$SERVER_WG_NIC.conf")
  10. if [[ ${NUMBER_OF_CLIENTS} == '0' ]]; then
  11. clear
  12. echo ""
  13. echo "You have no existing clients!"
  14. exit 1
  15. fi
  16. clear
  17. echo ""
  18. echo "Select an existing client that you want to renew"
  19. echo " Press CTRL+C to return"
  20. echo -e "==============================="
  21. echo " No Expired User"
  22. grep -E "^### Client" "/etc/wireguard/$SERVER_WG_NIC.conf" | cut -d ' ' -f 3-4 | nl -s ') '
  23. until [[ ${CLIENT_NUMBER} -ge 1 && ${CLIENT_NUMBER} -le ${NUMBER_OF_CLIENTS} ]]; do
  24. if [[ ${CLIENT_NUMBER} == '1' ]]; then
  25. read -rp "Select one client [1]: " CLIENT_NUMBER
  26. else
  27. read -rp "Select one client [1-${NUMBER_OF_CLIENTS}]: " CLIENT_NUMBER
  28. fi
  29. done
  30. read -p "Expired (days): " masaaktif
  31. user=$(grep -E "^### Client" "/etc/wireguard/wg0.conf" | cut -d ' ' -f 3 | sed -n "${CLIENT_NUMBER}"p)
  32. exp=$(grep -E "^### Client" "/etc/wireguard/wg0.conf" | cut -d ' ' -f 4 | sed -n "${CLIENT_NUMBER}"p)
  33. now=$(date +%Y-%m-%d)
  34. d1=$(date -d "$exp" +%s)
  35. d2=$(date -d "$now" +%s)
  36. exp2=$(( (d1 - d2) / 86400 ))
  37. exp3=$(($exp2 + $masaaktif))
  38. exp4=`date -d "$exp3 days" +"%Y-%m-%d"`
  39. sed -i "s/### Client $user $exp/### Client $user $exp4/g" /etc/wireguard/wg0.conf
  40. clear
  41. echo " ==============================================="
  42. echo " Wireguard Account Has Been Successfully Renewed"
  43. echo " ==============================================="
  44. echo " Client Name : $user"
  45. echo " Expired On: $exp4"
  46. echo " ==============================================="
  47. echo ""