add-pptp.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 "Script By geo"
  7. clear
  8. source /var/lib/premium-script/ipvps.conf
  9. if [[ "$IP" = "" ]]; then
  10. PUBLIC_IP=$(wget -qO- icanhazip.com);
  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" +"%d-%m-%Y"`
  26. created=`date -d "0 days" +"%d-%m-%Y"`
  27. clear
  28. # Add or update VPN user
  29. cat >> /etc/ppp/chap-secrets <<EOF
  30. "$VPN_USER" pptpd "$VPN_PASSWORD" *
  31. EOF
  32. # Update file attributes
  33. chmod 600 /etc/ppp/chap-secrets*
  34. echo -e "### $VPN_USER $exp">>"/var/lib/premium-script/data-user-pptp"
  35. cat <<EOF
  36. ================================
  37. PPTP VPN
  38. Server IP : $PUBLIC_IP
  39. Username : $VPN_USER
  40. Password : $VPN_PASSWORD
  41. Created : $created
  42. Expired : $exp
  43. =================================
  44. EOF