del-pptp.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/bash
  2. red='\e[1;31m'
  3. green='\e[0;32m'
  4. NC='\e[0m'
  5. MYIP=$(wget -qO- ifconfig.me/ip);
  6. export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
  7. NUMBER_OF_CLIENTS=$(grep -c -E "^### " "/var/lib/premium-script/data-user-pptp")
  8. if [[ ${NUMBER_OF_CLIENTS} == '0' ]]; then
  9. echo ""
  10. echo "You have no existing clients!"
  11. exit 1
  12. fi
  13. echo ""
  14. echo " Select the existing client you want to remove"
  15. echo " Press CTRL+C to return"
  16. echo " ==============================="
  17. echo " No Expired User"
  18. grep -E "^### " "/var/lib/premium-script/data-user-pptp" | cut -d ' ' -f 2-3 | nl -s ') '
  19. until [[ ${CLIENT_NUMBER} -ge 1 && ${CLIENT_NUMBER} -le ${NUMBER_OF_CLIENTS} ]]; do
  20. if [[ ${CLIENT_NUMBER} == '1' ]]; then
  21. read -rp "Select One Client[1]: " CLIENT_NUMBER
  22. else
  23. read -rp "Select One Client [1-${NUMBER_OF_CLIENTS}]: " CLIENT_NUMBER
  24. fi
  25. done
  26. # match the selected number to a client name
  27. VPN_USER=$(grep -E "^### " "/var/lib/premium-script/data-user-pptp" | cut -d ' ' -f 2 | sed -n "${CLIENT_NUMBER}"p)
  28. exp=$(grep -E "^### " "/var/lib/premium-script/data-user-pptp" | cut -d ' ' -f 3 | sed -n "${CLIENT_NUMBER}"p)
  29. # Delete VPN user
  30. sed -i '/^"'"$VPN_USER"'" pptpd/d' /etc/ppp/chap-secrets
  31. sed -i "/^### $VPN_USER $exp/d" /var/lib/premium-script/data-user-pptp
  32. # Update file attributes
  33. chmod 600 /etc/ppp/chap-secrets* /etc/ipsec.d/passwd*
  34. clear
  35. echo " PPTP Account Has Been Successfully Deleted"
  36. echo " =========================="
  37. echo " Client Name : $VPN_USER"
  38. echo " Expired On : $exp"
  39. echo " =========================="