del-pptp.sh 1.5 KB

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