|
@@ -9,6 +9,8 @@
|
9
|
9
|
# Freedom in the Cloud
|
10
|
10
|
#
|
11
|
11
|
# VPN functions
|
|
12
|
+# https://www.digitalocean.com/community/tutorials/how-to-set-up-an-openvpn-server-on-debian-8
|
|
13
|
+# https://jamielinux.com/blog/force-all-network-traffic-through-openvpn-using-iptables/
|
12
|
14
|
#
|
13
|
15
|
# License
|
14
|
16
|
# =======
|
|
@@ -28,12 +30,16 @@
|
28
|
30
|
# You should have received a copy of the GNU Affero General Public License
|
29
|
31
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
30
|
32
|
|
31
|
|
-VARIANTS=''
|
|
33
|
+VARIANTS='full full-vim'
|
32
|
34
|
|
33
|
35
|
IN_DEFAULT_INSTALL=0
|
34
|
36
|
SHOW_ON_ABOUT=0
|
35
|
37
|
|
36
|
|
-vpn_variables=()
|
|
38
|
+OPENVPN_SERVER_NAME="${PROJECT_NAME}-vpn"
|
|
39
|
+
|
|
40
|
+vpn_variables=(MY_EMAIL_ADDRESS
|
|
41
|
+ LOCAL_NETWORK_STATIC_IP_ADDRESS
|
|
42
|
+ MY_USERNAME)
|
37
|
43
|
|
38
|
44
|
function logging_on_vpn {
|
39
|
45
|
echo -n ''
|
|
@@ -73,24 +79,143 @@ function restore_remote_vpn {
|
73
|
79
|
}
|
74
|
80
|
|
75
|
81
|
function remove_vpn {
|
76
|
|
- apt-get -yq remove --purge fastd
|
|
82
|
+ apt-get -yq remove --purge fastd openvpn easy-rsa
|
|
83
|
+ if [ -d /etc/openvpn ]; then
|
|
84
|
+ rm -rf /etc/openvpn
|
|
85
|
+ fi
|
|
86
|
+ firewall_deny_forwarding
|
77
|
87
|
remove_completion_param install_vpn
|
78
|
88
|
}
|
79
|
89
|
|
|
90
|
+function create_user_vpn_key {
|
|
91
|
+ username=$1
|
|
92
|
+
|
|
93
|
+ if [ ! -d /home/$username ]; then
|
|
94
|
+ return
|
|
95
|
+ fi
|
|
96
|
+
|
|
97
|
+ echo $"Creating VPN key for $username"
|
|
98
|
+
|
|
99
|
+ cd /etc/openvpn/easy-rsa
|
|
100
|
+ echo '
|
|
101
|
+
|
|
102
|
+y
|
|
103
|
+y
|
|
104
|
+' | ./build-key "$username"
|
|
105
|
+
|
|
106
|
+ if [ ! -f /etc/openvpn/easy-rsa/keys/$username.crt ]; then
|
|
107
|
+ echo $'VPN user cert not generated'
|
|
108
|
+ exit 783528
|
|
109
|
+ fi
|
|
110
|
+ if [ ! -f /etc/openvpn/easy-rsa/keys/$username.key ]; then
|
|
111
|
+ echo $'VPN user key not generated'
|
|
112
|
+ exit 682523
|
|
113
|
+ fi
|
|
114
|
+
|
|
115
|
+ user_vpn_cert_file=/home/$username/vpn.ovpn
|
|
116
|
+
|
|
117
|
+ cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf $user_vpn_cert_file
|
|
118
|
+ sed -i "s|remote .*|remote $DEFAULT_DOMAIN_NAME 1194|g" $user_vpn_cert_file
|
|
119
|
+ sed -i 's|;user nobody|user nobody|g' $user_vpn_cert_file
|
|
120
|
+ sed -i 's|;group nogroup|group nogroup|g' $user_vpn_cert_file
|
|
121
|
+
|
|
122
|
+ sed -i 's|ca ca.crt|;ca ca.crt|g' $user_vpn_cert_file
|
|
123
|
+ sed -i 's|cert client.crt|;cert client.crt|g' $user_vpn_cert_file
|
|
124
|
+ sed -i 's|key client.key|;key client.key|g' $user_vpn_cert_file
|
|
125
|
+
|
|
126
|
+ echo '<ca>' >> $user_vpn_cert_file
|
|
127
|
+ cat /etc/openvpn/ca.crt >> $user_vpn_cert_file
|
|
128
|
+ echo '</ca>' >> $user_vpn_cert_file
|
|
129
|
+
|
|
130
|
+ echo '<cert>' >> $user_vpn_cert_file
|
|
131
|
+ cat /etc/openvpn/easy-rsa/keys/$username.crt >> $user_vpn_cert_file
|
|
132
|
+ echo '</cert>' >> $user_vpn_cert_file
|
|
133
|
+
|
|
134
|
+ echo '<key>' >> $user_vpn_cert_file
|
|
135
|
+ cat /etc/openvpn/easy-rsa/keys/$username.key >> $user_vpn_cert_file
|
|
136
|
+ echo '</key>' >> $user_vpn_cert_file
|
|
137
|
+
|
|
138
|
+ chown $username:$username $user_vpn_cert_file
|
|
139
|
+
|
|
140
|
+ rm /etc/openvpn/easy-rsa/keys/$username.crt
|
|
141
|
+ shred -zu /etc/openvpn/easy-rsa/keys/$username.key
|
|
142
|
+
|
|
143
|
+ echo $"VPN key created at $user_vpn_cert_file"
|
|
144
|
+}
|
|
145
|
+
|
|
146
|
+function add_user_vpn {
|
|
147
|
+ new_username="$1"
|
|
148
|
+ new_user_password="$2"
|
|
149
|
+
|
|
150
|
+ create_user_vpn_key $new_username
|
|
151
|
+}
|
|
152
|
+
|
|
153
|
+function remove_user_vpn {
|
|
154
|
+ new_username="$1"
|
|
155
|
+}
|
|
156
|
+
|
80
|
157
|
function install_vpn {
|
81
|
|
- if ! grep -q "repo.universe-factory.net" /etc/apt/sources.list; then
|
82
|
|
- echo 'deb http://repo.universe-factory.net/debian/ sid main' >> /etc/apt/sources.list
|
83
|
|
- gpg --keyserver pgpkeys.mit.edu --recv-key 16EF3F64CB201D9C
|
84
|
|
- if [ ! "$?" = "0" ]; then
|
85
|
|
- exit 76272
|
86
|
|
- fi
|
87
|
|
- gpg -a --export 16EF3F64CB201D9C | sudo apt-key add -
|
88
|
|
- apt-get update
|
89
|
|
- apt-get -yq install fastd
|
90
|
|
- if [ ! "$?" = "0" ]; then
|
91
|
|
- exit 52026
|
92
|
|
- fi
|
|
158
|
+ if [ ! $LOCAL_NETWORK_STATIC_IP_ADDRESS ]; then
|
|
159
|
+ return
|
93
|
160
|
fi
|
|
161
|
+
|
|
162
|
+ apt-get -yq install fastd openvpn easy-rsa
|
|
163
|
+
|
|
164
|
+ if [ ! -f /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz ]; then
|
|
165
|
+ echo $'Example openvpn server config not found'
|
|
166
|
+ exit 783953
|
|
167
|
+ fi
|
|
168
|
+ gunzip -c /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz > /etc/openvpn/server.conf
|
|
169
|
+ sed -i "s|;push \"redirect-gateway|push \"redirect-gateway|g" /etc/openvpn/server.conf
|
|
170
|
+ sed -i 's|;push "dhcp-option|push "dhcp-option|g' /etc/openvpn/server.conf
|
|
171
|
+ sed -i 's|;user nobody|user nobody|g' /etc/openvpn/server.conf
|
|
172
|
+ sed -i 's|;group nogroup|group nogroup|g' /etc/openvpn/server.conf
|
|
173
|
+ echo 1 > /proc/sys/net/ipv4/ip_forward
|
|
174
|
+ sed -i 's|# net.ipv4.ip_forward|net.ipv4.ip_forward|g' /etc/sysctl.conf
|
|
175
|
+ sed -i 's|#net.ipv4.ip_forward|net.ipv4.ip_forward|g' /etc/sysctl.conf
|
|
176
|
+ sed -i 's|net.ipv4.ip_forward.*|net.ipv4.ip_forward=1|g' /etc/sysctl.conf
|
|
177
|
+
|
|
178
|
+ cp -r /usr/share/easy-rsa/ /etc/openvpn
|
|
179
|
+ if [ ! -d /etc/openvpn/easy-rsa/keys ]; then
|
|
180
|
+ mkdir /etc/openvpn/easy-rsa/keys
|
|
181
|
+ fi
|
|
182
|
+
|
|
183
|
+ sed -i "s|export KEY_COUNTRY.*|export KEY_COUNTRY=\"US\"|g" /etc/openvpn/easy-rsa/vars
|
|
184
|
+ sed -i "s|export KEY_PROVINCE.*|export KEY_PROVINCE=\"TX\"|g" /etc/openvpn/easy-rsa/vars
|
|
185
|
+ sed -i "s|export KEY_CITY.*|export KEY_CITY=\"Dallas\"|g" /etc/openvpn/easy-rsa/vars
|
|
186
|
+ sed -i "s|export KEY_ORG.*|export KEY_ORG=\"$PROJECT_NAME\"|g" /etc/openvpn/easy-rsa/vars
|
|
187
|
+ sed -i "s|export KEY_EMAIL.*|export KEY_EMAIL=\"$MY_EMAIL_ADDRESS\"|g" /etc/openvpn/easy-rsa/vars
|
|
188
|
+ sed -i "s|export KEY_OU=.*|export KEY_OU=\"MoonUnit\"|g" /etc/openvpn/easy-rsa/vars
|
|
189
|
+ sed -i "s|export KEY_NAME.*|export KEY_NAME=\"$OPENVPN_SERVER_NAME\"|g" /etc/openvpn/easy-rsa/vars
|
|
190
|
+ openssl dhparam -out /etc/openvpn/dh2048.pem 2048
|
|
191
|
+ cd /etc/openvpn/easy-rsa
|
|
192
|
+ . ./vars
|
|
193
|
+ ./clean-all
|
|
194
|
+ ./build-ca
|
|
195
|
+ echo '
|
|
196
|
+
|
|
197
|
+y
|
|
198
|
+y
|
|
199
|
+' | ./build-key-server $OPENVPN_SERVER_NAME
|
|
200
|
+ if [ ! -f /etc/openvpn/easy-rsa/keys/$OPENVPN_SERVER_NAME.crt ]; then
|
|
201
|
+ echo $'OpenVPN crt not found'
|
|
202
|
+ exit 7823352
|
|
203
|
+ fi
|
|
204
|
+ if [ ! -f /etc/openvpn/easy-rsa/keys/$OPENVPN_SERVER_NAME.key ]; then
|
|
205
|
+ echo $'OpenVPN key not found'
|
|
206
|
+ exit 6839436
|
|
207
|
+ fi
|
|
208
|
+ if [ ! -f /etc/openvpn/easy-rsa/keys/ca.key ]; then
|
|
209
|
+ echo $'OpenVPN ca not found'
|
|
210
|
+ exit 7935203
|
|
211
|
+ fi
|
|
212
|
+ cp /etc/openvpn/easy-rsa/keys/{$OPENVPN_SERVER_NAME.crt,$OPENVPN_SERVER_NAME.key,ca.crt} /etc/openvpn
|
|
213
|
+
|
|
214
|
+ create_user_vpn_key $MY_USERNAME
|
|
215
|
+
|
|
216
|
+ firewall_allow_forwarding
|
|
217
|
+ systemctl openvpn start
|
|
218
|
+
|
94
|
219
|
APP_INSTALLED=1
|
95
|
220
|
}
|
96
|
221
|
|