add-pptp.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. echo "Checking VPS"
  7. clear
  8. source /var/lib/premium-script/ipvps.conf
  9. if [[ "$IP" = "" ]]; then
  10. PUBLIC_IP=$(wget -qO- ifconfig.me/ip);
  11. else
  12. PUBLIC_IP=$IP
  13. fi
  14. until [[ $VPN_USER =~ ^[a-zA-Z0-9_]+$ && ${CLIENT_EXISTS} == '0' ]]; do
  15. read -rp "Username: " -e VPN_USER
  16. CLIENT_EXISTS=$(grep -w $VPN_USER /var/lib/premium-script/data-user-pptp | wc -l)
  17. if [[ ${CLIENT_EXISTS} == '1' ]]; then
  18. echo ""
  19. echo "A client with the specified name was already created, please choose another name."
  20. exit 1
  21. fi
  22. done
  23. read -p "Password: " VPN_PASSWORD
  24. read -p "Expired (days): " masaaktif
  25. exp=`date -d "$masaaktif days" +"%Y-%m-%d"`
  26. clear
  27. # Add or update VPN user
  28. cat >> /etc/ppp/chap-secrets <<EOF
  29. "$VPN_USER" pptpd "$VPN_PASSWORD" *
  30. EOF
  31. # Update file attributes
  32. chmod 600 /etc/ppp/chap-secrets*
  33. echo -e "### $VPN_USER $exp">>"/var/lib/premium-script/data-user-pptp"
  34. cat <<EOF
  35. ================================
  36. PPTP VPN
  37. Server IP : $PUBLIC_IP
  38. Username : $VPN_USER
  39. Password : $VPN_PASSWORD
  40. Expired On : $exp
  41. =================================
  42. EOF