renew-l2tp.sh 1.5 KB

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