bin bash echo Select on option echo Set up new PoPToP server AND creat

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
#!/bin/bash
echo "Select on option:"
echo "1. Set up new PoPToP server AND create one user"
echo "2. Create additional users"
read x
if test $x -eq 1; then
echo "Enter username that you want to create, e.g. Client1 or John:"
read u
echo "Specify password that you want the server to use:"
read p
# Get the VPS IP
ip=`ifconfig eth0 | grep 'inet addr' | awk {'print $2'} | sed s/.*://`
echo "Downloading and Installing PoPToP"
aptitude update
aptitude upgrade -y
aptitude install -y pptpd
echo "Creating server config"
cat > /etc/ppp/pptpd-options <<END
name pptpd
refuse-pap
refuse-chap
refuse-mschap
require-mschap-v2
require-mppe-128
ms-dns 8.8.8.8
ms-dns 8.8.4.4
proxyarp
nodefaultroute
lock
nobsdcomp
END
# Setting up pptpd.conf
echo "option /etc/ppp/pptpd-options" > /etc/pptpd.conf
echo "logwtmp" >> /etc/pptpd.conf
echo "localip $ip" >> /etc/pptpd.conf
echo "remoteip 10.1.0.1-200" >> /etc/pptpd.conf
# Adding new user
echo "$u * $p *" > /etc/ppp/chap-secrets
echo "Forwarding IPv4 and enabling it on boot"
cat >> /etc/sysctl.conf <<END
net.ipv4.ip_forward=1
END
# Apply the settings
sysctl -p
echo "Updating iptables routing and enabling it on boot"
iptables -t nat -A POSTROUTING -j SNAT --to $ip
# Saves iptables routing rules and enables them on-boot
iptables-save > /etc/iptables.conf
cat > /etc/network/if-pre-up.d/iptables <<END
#!/bin/sh
iptables-restore < /etc/iptables.conf
END
chmod +x /etc/network/if-pre-up.d/iptables
cat >> /etc/ppp/ip-up <<END
ifconfig ppp0 mtu 1400
END
echo "Restarting PoPToP"
/etc/init.d/pptpd restart
echo "Addtional user added!"
echo "Connect to your VPS at $ip with these credentials:"
echo "Username: $u"
echo "Password: $p"
# Runs this if option 2 is selected
elif test $x -eq 2; then
echo "Enter username that you want to create, e.g. Client1 or John:"
read u
echo "Specify password that you want the server to use:"
read p
echo "Enter ip:"
read Ip
# get the VPS IP
ip=`ifconfig eth0 | grep 'inet addr' | awk {'print $2'} | sed s/.*://`
# Adding new user
echo "$u * $p $Ip" >> /etc/ppp/chap-secrets
echo "Addtional user added!"
echo "Connect to your VPS at $ip with these credentials:"
echo "Username: $u"
echo "Password: $p"
echo "IP: $Ip"
else
echo "Invalid selection, quitting..."
exit
fi