forked from Notos/seedbox-from-scratch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ovpni
121 lines (120 loc) · 4.48 KB
/
ovpni
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
##################### FIRST LINE
#!/bin/bash
#
#
#
# The Seedbox From Scratch Script
# By Notos ---> https://github.com/Notos/
#
#
######################################################################
#
# Copyright (c) 2013 Notos (https://github.com/Notos/)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# --> Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
#
######################################################################
#
#
# OpenVPN in beta --- Tested on Ubuntu 12.04 64Bit
#
sudo killall openvpn
IPADDRESS1=`ifconfig | sed -n 's/.*inet addr:\([0-9.]\+\)\s.*/\1/p' | grep -v 127 | head -n 1`
OPENVPNPORT1=`cat /etc/seedbox-from-scratch/openvpn.info`
rm -r /etc/openvpn/
cp -R /usr/share/doc/openvpn/examples/easy-rsa/ /etc/openvpn/
cd /etc/openvpn/
cd /etc/openvpn/2.0/
cp ./tmp/openssl-1.0.0.cnf /etc/openvpn/2.0/openssl.cnf
chmod +rwx *
. ./vars
./clean-all
source ./vars
echo -e "\n\n\n\n\n\n\n" | ./build-ca
clear
#echo "-----------------------------------------------------------------------------------------"
#echo ""
#echo "BE AWARE! Do not type a password if you don't want to be asked for one when connecting."
#echo ""
#echo "-----------------------------------------------------------------------------------------"
./build-key-server server
./build-dh
cp keys/{ca.crt,ca.key,server.crt,server.key,dh1024.pem} /etc/openvpn/
clear
#echo "-----------------------------------------------------------------------------------------"
#echo ""
#echo "In this step you can give a password, if you want."
#echo ""
#echo "-----------------------------------------------------------------------------------------"
./build-key client1
cd keys/
client="
client
remote $IPADDRESS1 $OPENVPNPORT1
dev tun
comp-lzo
ca ca.crt
cert client1.crt
key client1.key
route-delay 2
route-method exe
redirect-gateway def1
dhcp-option DNS 10.159.12.1
verb 3"
echo "$client" > $HOSTNAME.ovpn
zip vpn.zip ca.crt ca.key client1.crt client1.csr client1.key $HOSTNAME.ovpn
mv vpn.zip /var/www/rutorrent
opvpn="
dev tun
port $OPENVPNPORT1
server 10.159.12.0 255.255.255.0
ifconfig-pool-persist ipp.txt
ca ca.crt
cert server.crt
key server.key
dh dh1024.pem
push \"route 10.159.12.0 255.255.255.0\"
push \"redirect-gateway\"
push \"dhcp-option DNS 8.8.8.8\"
push \"dhcp-option DNS 8.8.4.4\"
comp-lzo
keepalive 10 60
ping-timer-rem
persist-tun
persist-key
group daemon
daemon"
echo "$opvpn" > /etc/openvpn/openvpn.conf
echo 1 > /proc/sys/net/ipv4/ip_forward
###sudo iptables -t nat -A POSTROUTING -o venet0 -j SNAT --to-source $IPADDRESS1
###sudo iptables -t nat -A POSTROUTING -s 10.159.12.0/24 -j SNAT --to-source $IPADDRESS1
###sudo iptables -A FORWARD -i venet0 -o tun0 -m state --state RELATED,ESTABLISHED -j ACCEPT
###sudo iptables -A FORWARD -i tun0 -o venet0 -j ACCEPT
###sudo iptables -t nat -I POSTROUTING -s 10.159.12.0/24 -j MASQUERADE
iptables -I FORWARD -i tun0 -o eth0 -s 10.159.12.0/24 -m conntrack --ctstate NEW -j ACCEPT
iptables -I FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -t nat -I POSTROUTING -s 10.159.12.0/24 -j MASQUERADE
iptables-save > /etc/iptables.conf
echo '#!/bin/sh' > /etc/network/if-up.d/iptables
echo "iptables-restore < /etc/iptables.conf" >> /etc/network/if-up.d/iptables
chmod +x /etc/network/if-up.d/iptables
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
/etc/init.d/openvpn start
clear
cd
clear
echo ""
echo "Installation process id done."
echo ""
echo ""
echo "Now you just download http://$IPADDRESS1/rutorrent/vpn.zip to use in any OpenVPN client."
echo ""
echo "Enjoy it!"
echo ""
echo ""