del-pptp.sh 1.6 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. echo "Checking VPS"
  7. clear
  8. export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
  9. NUMBER_OF_CLIENTS=$(grep -c -E "^### " "/var/lib/premium-script/data-user-pptp")
  10. if [[ ${NUMBER_OF_CLIENTS} == '0' ]]; then
  11. echo ""
  12. echo "You have no existing clients!"
  13. exit 1
  14. fi
  15. echo ""
  16. echo " Select the existing client you want to remove"
  17. echo " Press CTRL+C to return"
  18. echo " ==============================="
  19. echo " No Expired User"
  20. grep -E "^### " "/var/lib/premium-script/data-user-pptp" | 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. # match the selected number to a client name
  29. VPN_USER=$(grep -E "^### " "/var/lib/premium-script/data-user-pptp" | cut -d ' ' -f 2 | sed -n "${CLIENT_NUMBER}"p)
  30. exp=$(grep -E "^### " "/var/lib/premium-script/data-user-pptp" | cut -d ' ' -f 3 | sed -n "${CLIENT_NUMBER}"p)
  31. # Delete VPN user
  32. sed -i '/^"'"$VPN_USER"'" pptpd/d' /etc/ppp/chap-secrets
  33. sed -i "/^### $VPN_USER $exp/d" /var/lib/premium-script/data-user-pptp
  34. # Update file attributes
  35. chmod 600 /etc/ppp/chap-secrets* /etc/ipsec.d/passwd*
  36. clear
  37. echo " =========================================="
  38. echo " PPTP Account Has Been Successfully Deleted"
  39. echo " =========================================="
  40. echo " Client Name : $VPN_USER"
  41. echo " Expired On : $exp"
  42. echo " =========================================="
  43. echo ""