﻿#!/bin/sh
clear                                                                                         
echo "--------------------------------------"                                                  
echo "-                                    -"                                                    
echo "-          PPTPD INSTALLER           -"                                                   
echo "-                                    -"                                                  
echo "-          By : princehaku           -"                                                  
echo "-       Blog : http://3haku.net      -"                                                                                    
echo "--------------------------------------"
p_local_ip="192.168.77.1"
p_remote_ip="192.168.77.50-200"
server_ip=`ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk 'NR==1 { print $1}'`
echo "Please Input Your Server ip:"
read -p "(Default ip: $server_ip):" temp
if [ "$temp" != "" ]; then
	server_ip=$temp
fi                                                                       
echo "---------  UPDATE APT-GET   ----------"
apt-get update
apt-get install -y pptpd                        
echo "---------   UPDATE CONFIG   ----------"
cat >>/etc/pptpd.conf<<EOF
localip $p_local_ip
remoteip $p_remote_ip
EOF
sed -i -e 's/^#ms-dns 10.0.0.1$/ms-dns 8.8.8.8/' /etc/ppp/pptpd-options
sed -i -e 's/^#ms-dns 10.0.0.2$/ms-dns 8.8.4.4/' /etc/ppp/pptpd-options 
cat >>/etc/ppp/chap-secrets<<EOF
admin pptpd admin *
EOF
service pptpd restart                                                                
echo "---------    INIT FORWARD   ----------"
apt-get install -y iptables
sed -i "s/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g" /etc/sysctl.conf
cat >> /etc/sysctl.conf <<EOF
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
EOF
sysctl -p
iptables -t nat -A POSTROUTING -s 192.168.77.0/24 -j MASQUERADE -o eth0
iptables -t nat -A POSTROUTING -s 192.168.77.0/24 -j SNAT --to-source $server_ip
iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to-destination 8.8.8.8    
iptables-save > /etc/vpnrules
a=`cat /etc/rc.local | grep 'exit' | wc -l`
if [ $a -eq 0 ]; then
 	echo 'iptables-restore < /etc/vpnrules' >> /etc/rc.local
else
  sed '$d' /etc/rc.local > /etc/rc.local
 	echo 'iptables-restore < /etc/vpnrules' >> /etc/rc.local
fi

echo "---------    ALL DONE   -----------"                                                                           
echo "---------    Ip:$server_ip User: admin Pass:admin   -----------"
