-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.sh
107 lines (106 loc) · 2.8 KB
/
client.sh
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
#!/bin/bash
#Defining variables and functions.
#
openvpn_dir='/usr/share/doc/openvpn'
rsa_default_dir='/usr/share/easy-rsa'
vpnconf_dir='/etc/openvpn'
sampleconf_dir='/etc/openvpn/openvpn-github-package/sample/sample-config-files'
rsaconf_dir='/etc/openvpn/easy-rsa'
rsapki_dir='/etc/openvpn/easy-rsa/pki'
pvtkey_dir='/etc/openvpn/easy-rsa/pki/private'
crt_dir='/etc/openvpn/easy-rsa/pki/issued'
dest_client='/etc/openvpn/client'
PWD=$(pwd)
#pbx_port=$(lsof -i -P -n | grep openvpn | awk '{print$9}'| cut -c3-)
#
loading() {
echo "$1"
t_start=$(date +%s)
while true
do
t_current=$(date +%s)
t_running=$((t_current - t_start))
if [ $t_running -gt $2 ]
then
printf "\033[1A"
echo "$1.....DONE"
break
else
for i in '/' '-' '\' '|'
do
echo -n $i
sleep 0.1
echo -ne "\r"
done
fi
done
}
#
proc_loading () {
echo $2
while true
do
job=$(ps -ef | grep $1 | grep -v grep)
if [ -z "$job" ]
then
printf "\033[1A"
echo "$2......DONE"
break
else
for i in '/' '-' '\' '|';
do
echo -n $i
sleep 0.1
echo -ne "\r"
done
fi
done
}
#
#************************Generating Client Certificate and Private Key**********************
echo "-------------------------Generating Client Certificate and Private Key------------------------------"
echo
while true
do
read -p 'Choose your VPN Client name: ' client_name
if [[ -z $client_name ]]
then
echo
echo 'At-least one input needed'
sleep 1
echo
elif echo $client_name | grep -q "\."
then
echo
echo "Float is not allowd."
sleep 1
echo
else
break
fi
done
$rsaconf_dir/./easyrsa build-client-full $client_name client nopass 2>/dev/null >/dev/null &
echo " "
loading 'Generating Client Certificate and Private key' 3
#Copying CA Cert./Client certs. and key files in respective directories.
f_list=("$rsapki_dir/private/$client_name.key" "$rsapki_dir/issued/$client_name.crt")
for i in ${f_list[@]}
do
cp $i $dest_client
done
#Merging cert and key in client vpn file
echo " "
loading "Generating $client_name Client VPN file" 2
source $PWD/append.sh "$client_name" 'ca.crt' "$client_name.crt" "$client_name.key"
echo
echo "$client_name VPN Client file generated in $PWD."
sleep 1
#
#PROCESS DONE
#
echo
echo "************************************************************************************"
echo
echo "Any Issues ?? Let me know: https://github.com/pbxforce/vpn-server-openvpn"
echo
echo "************************************************************************************"