#!/bin/bash
clear
echo "一个用于创建虚拟专用网络(Virtual Private Network)加密通道的免费开源软件。使用Open×××可以方便地在家庭、办公场所、住宿酒店等不同网络访问场所之间搭建类似于局域网的专用网络通道"
echo -e ""
read -p "按回车进行安装... ... "
clear
cd /tmp/
if [ ! -s lzo-2.09.tar.gz ];then
wget
fi
clear
if [ ! -s open***-2.2.2.tar.gz ];then
wget
fi
clear
yum install pam-devel openssl* gcc -y
clear
ntpdate pool.ntp.org
tar zxf lzo-2.09.tar.gz
tar zxf open***-2.2.2.tar.gz
clear
cd lzo-2.09/
./configure
make && make install
clear
cd ../open***-2.2.2/
./configure --with-lzo-headers=/usr/local/include/ --with-lzo-lib=/usr/local/lib
make && make install
clear
mkdir /etc/open***
cd easy-rsa/2.0/
cp vars vars_bak
read -p "定义所在国家(比如中国就是:CN): " dygj
read -p "定义所在省份(比如广西就是:GX): " dysf
read -p "定义所在城市(比如南宁就是:NanNing): " dycs
read -p "定义所在组织或公司(比如联想就是:Lenovo): " dygs
read -p "设置你的电子邮件: " dymail
read -p "定义所在部门(比如IT部就是:IT): " dybm
read -p "定义你的名称: " dyname
cat > vars <<EOF
export EASY_RSA="`pwd`"
export OPENSSL="openssl"
export PKCS11TOOL="pkcs11-tool"
export GREP="grep"
export KEY_CONFIG=`$EASY_RSA/whichopensslcnf $EASY_RSA`
export KEY_DIR="$EASY_RSA/keys"
echo NOTE: If you run ./clean-all, I will be doing a rm -rf on $KEY_DIR
export PKCS11_MODULE_PATH="dummy"
export PKCS11_PIN="dummy"
export KEY_SIZE=1024
export CA_EXPIRE=3650
export KEY_EXPIRE=3650
export KEY_COUNTRY="$dygj"
export KEY_PROVINCE="$dysf"
export KEY_CITY="$dycs"
export KEY_ORG="$dygs"
export KEY_EMAIL="$dymail"
export KEY_EMAIL=$dymail
export KEY_CN=CN
export KEY_NAME=dyname
export KEY_OU=$dybm
export PKCS11_MODULE_PATH=changeme
export PKCS11_PIN=1234
EOF
source ./vars
./clean-all
./build-ca
./build-key-server server
./build-key $dyname
./build-key-pass $dyname
./build-dh
open*** --genkey --secret keys/ta.key
clear
cp -arp /tmp/open***-2.2.2/easy-rsa/2.0/keys /etc/open***
cp /tmp/open***-2.2.2/sample-config-files/server.conf /etc/open***/
cp /tmp/open***-2.2.2/sample-config-files/client.conf /etc/open***/
cd /etc/open***/
cp server.conf server.conf_bak
local***ip=`ifconfig eth0|awk -F'[ :]+' 'NR==2 {print $4}'`
cat > server.conf <<EOF
local $local***ip
port 52115
proto tcp
dev tap
ca /etc/open***/keys/ca.crt
cert /etc/open***/keys/server.crt
key /etc/open***/keys/server.key
dh /etc/open***/keys/dh1024.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "route 192.168.169.0 255.255.255.0"
client-to-client
duplicate-cn
keepalive 10 120
comp-lzo
persist-key
persist-tun
status open***-status.log
log /var/log/open***.log
verb 3
EOF
sed -i '/ip_forward/s/0/1/g' /etc/sysctl.conf
sysctl -p
clear
/usr/local/sbin/open*** --config /etc/open***/server.conf &
echo "#startup open*** service by $dybm" >> /etc/rc.local
echo "/usr/local/sbin/open*** --config /etc/open***/server.conf &" >> /etc/rc.local
cp /tmp/open***-2.2.2/sample-scripts/open***.init /etc/init.d/open***
cat > /etc/init.d/open*** << EOF
line148: *.conf --> server.conf
EOF
chmod 700 /etc/init.d/open***
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
read -t 5 -p "服务器端安装配置完成!!!"