del-l2tp.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-l2tp")
  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-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. # match the selected number to a client name
  29. VPN_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. # Delete VPN user
  32. sed -i '/^"'"$VPN_USER"'" l2tpd/d' /etc/ppp/chap-secrets
  33. # shellcheck disable=SC2016
  34. sed -i '/^'"$VPN_USER"':\$1\$/d' /etc/ipsec.d/passwd
  35. sed -i "/^### $VPN_USER $exp/d" /var/lib/premium-script/data-user-l2tp
  36. # Update file attributes
  37. chmod 600 /etc/ppp/chap-secrets* /etc/ipsec.d/passwd*
  38. clear
  39. echo " L2TP Account Has Been Successfully Deleted"
  40. echo " =========================="
  41. echo " Client Name : $VPN_USER"
  42. echo " Expired On : $exp"
  43. echo " =========================="