#!/bin/bash # DOBY PPTP vpn for CentOS # Powered dobyi.com # pptp.sh # Check if user is root if [ $(id -u) != "0" ]; then echo "Error: You must be root to run this script, use sudo $0" exit 1 fi #check if CentOS if [ ! -e '/etc/redhat-release' ]; then echo 'Error: sorry, we currently support CentOS only' exit 1 fi function echoline { echo "=========================================================================" } function repairvpn { echo -n "Repairing pptp vpn..." rm /dev/ppp mknod /dev/ppp c 108 0 echo " [OK]" } function adduser { #ask for some information while [ "${username}" = "" ] do read -p "VPN Username: " username if [ "${username}" = "" ]; then echo "Error: VPN Username Can't be empty!!" fi ifexists=`cat /etc/ppp/chap-secrets | awk -v U="${username}" '{ if(U==$1) printf $1 }'` if [ "$ifexists" != "" ]; then echo "Error: ${username} exists." username="" fi done while [ "$vpnpwd" = "" ] do read -p "VPN Password: " vpnpwd if [ "$vpnpwd" = "" ]; then echo "Error: VPN Password Can't be empty!!" fi done echo "${username} pptpd ${vpnpwd} *" >> /etc/ppp/chap-secrets service pptpd restart if [ "$?" -ne 0 ]; then echo "Error: pptpd restart failed" exit 1 fi echo "${username} is added." } function deluser { #ask for some information while [ "${username}" = "" ] do read -p "VPN Username: " username if [ "${username}" = "" ]; then echo "Error: VPN Username Can't be empty!!" fi done ifexists=`cat /etc/ppp/chap-secrets | awk -v U="${username}" '{ if(U==$1) printf $1 }'` if [ "$ifexists" == "" ]; then echo "Error: ${username} does not exist." else sed -i '/'${username}' pptpd/d' /etc/ppp/chap-secrets service pptpd restart if [ "$?" -ne 0 ]; then echo "Error: pptpd restart failed" exit 1 fi echo "${username} is deleted." fi } function installvpn { #ask for some information while [ "${username}" = "" ] do read -p "VPN Username: " username if [ "${username}" = "" ]; then echo "Error: VPN Username Can't be e Mpty!! "fi " done while [[$vpnpwd] = "" do read -p "VPN Password:" vpnpwd "[]" = "" "];" Yu "," Wei, "and" Yu ". RPM -Uvh epel-release-7*.rpm fi RM -f *.rpm #install pptp Yum install epel/7/x86_64/e/epel-release-7-5.noarch.rpm -Uvh, #install, pptp , yum, #install, pptp , yum, #install, pptp , #install, pptp , yum, #install, pptp , #install, pptp , #install, pptp , #install, pptp , yum, #install, pptp , #install, pptp , #install, pptp , #install, pptp , #install, pptp , and yum. The "108". Epel/7/x86_64/e/epel-release-7-5.noarch.rpm systemctl stop firewalld systemctl mask firewalld systemctl enable iptables fi if [ -d "/proc/vz" ]; then interfaces="venet0" else interfaces=`ifconfig | grep eth | awk '{print $1}' | head -n 1` if [ "$interfaces" = "" ]; then interfaces="eth0" fi fi iptables -t nat -A POSTROUTING -o $interfaces -j MASQUERADE && iptables-save iptables --table nat --append POSTROUTING --out-interface ppp0 -j MASQUERADE iptables -I INPUT -s 10.0.0.0/8 -i ppp0 -j ACCEPT iptables --append FORWARD --in-interface $interfaces -j ACCEPT iptables -A INPUT -p tcp -m tcp --dport 1723 -j ACCEPT iptables -A INPUT -p gre -j ACCEPT service iptables save service iptables restart if [ "$?" -ne 0 ]; then echo "Error: iptables restart failed" exit 1 fi chkconfig pptpd on clear echo "" echo "DOBY PPTP vpn for CentOS" echoline echo "PPTP VPN installation is finished." echo "Username: ${username}" echo "Password: ${vpnpwd}" echo "For more information, please visit our website http://dobyi.com" ech Oline } clear echo "" echo "DOBY PPTP VPN for CentOS" echoline echo "DOBY PPTP VPN DOBY", "1., 2.", "3.", "2.", "4.", "2", "2", "2"; ";"; "3;"; "* 4"); "* *"; "