del-l2tp.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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-l2tp")
  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-l2tp" | 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-l2tp" | cut -d ' ' -f 2 | sed -n "${CLIENT_NUMBER}"p)
  24. exp=$(grep -E "^### " "/var/lib/premium-script/data-user-l2tp" | cut -d ' ' -f 3 | sed -n "${CLIENT_NUMBER}"p)
  25. # Delete VPN user
  26. sed -i '/^"'"$VPN_USER"'" l2tpd/d' /etc/ppp/chap-secrets
  27. # shellcheck disable=SC2016
  28. sed -i '/^'"$VPN_USER"':\$1\$/d' /etc/ipsec.d/passwd
  29. sed -i "/^### $VPN_USER $exp/d" /var/lib/premium-script/data-user-l2tp
  30. # Update file attributes
  31. chmod 600 /etc/ppp/chap-secrets* /etc/ipsec.d/passwd*
  32. clear
  33. echo " L2TP Account Has Been Successfully Deleted"
  34. echo " =========================="
  35. echo " Client Name : $VPN_USER"
  36. echo " Expired On : $exp"
  37. echo " =========================="