renew-pptp.sh 1.5 KB

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