add-l2tp.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/bash
  2. source /var/lib/premium-script/ipvps.conf
  3. if [[ "$IP" = "" ]]; then
  4. PUBLIC_IP=$(wget -qO- ipinfo.io/ip);
  5. else
  6. PUBLIC_IP=$IP
  7. fi
  8. until [[ $VPN_USER =~ ^[a-zA-Z0-9_]+$ && ${CLIENT_EXISTS} == '0' ]]; do
  9. read -rp "Username: " -e VPN_USER
  10. CLIENT_EXISTS=$(grep -w $VPN_USER /var/lib/premium-script/data-user-l2tp | wc -l)
  11. if [[ ${CLIENT_EXISTS} == '1' ]]; then
  12. echo ""
  13. echo "A client with the specified name was already created, please choose another name."
  14. exit 1
  15. fi
  16. done
  17. read -p "Password: " VPN_PASSWORD
  18. read -p "Expired (days): " masaaktif
  19. exp=`date -d "$masaaktif days" +"%Y-%m-%d"`
  20. clear
  21. # Add or update VPN user
  22. cat >> /etc/ppp/chap-secrets <<EOF
  23. "$VPN_USER" l2tpd "$VPN_PASSWORD" *
  24. EOF
  25. VPN_PASSWORD_ENC=$(openssl passwd -1 "$VPN_PASSWORD")
  26. cat >> /etc/ipsec.d/passwd <<EOF
  27. $VPN_USER:$VPN_PASSWORD_ENC:xauth-psk
  28. EOF
  29. # Update file attributes
  30. chmod 600 /etc/ppp/chap-secrets* /etc/ipsec.d/passwd*
  31. echo -e "### $VPN_USER $exp">>"/var/lib/premium-script/data-user-l2tp"
  32. cat <<EOF
  33. ================================
  34. L2TP/IPSEC PSK VPN
  35. Server IP : $PUBLIC_IP
  36. IPsec PSK : myvpn
  37. Username : $VPN_USER
  38. Password : $VPN_PASSWORD
  39. Expired ON : $exp
  40. =================================
  41. Script BY RIDZLIAN
  42. =================================
  43. EOF