-
Notifications
You must be signed in to change notification settings - Fork 5
/
vpnbook-get-configs
102 lines (83 loc) · 2.45 KB
/
vpnbook-get-configs
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
#!/bin/bash
VPNBOOKPAGE="https://www.vpnbook.com/"
WORKDIR="/tmp/vpnbook/"
UNPDIR="/tmp/vpnbook/unpack/"
HTMLFILE="vpnhtml.html"
OUTDIR="~/openvpn/vpnbook/"
OUTMASK="*tcp80.ovpn"
ADD_COMMANDS[0]="#EXAMPLE OPTION script-security 2"
ADD_COMMANDS[1]="#EXAMPLE OPTION up '~/openvpn/vpnbook/vb-routes up'"
ADD_COMMANDS[2]="#EXAMPLE OPTION down '~/openvpn/vpnbook/vb-routes down'"
ADD_COMMANDS[3]="#EXAMPLE OPTION auth-user-pass ~/openvpn/vpnbook/vpnbook.auth"
add_commands() #$1-output file
{
CTR="${#ADD_COMMANDS[*]}"; I="0"
until [ "$CTR" -eq "$I" ]; do
CMND_="${ADD_COMMANDS[I]}"
CMND_ST=`echo "$CMND_" |awk '{print $1}'`
CMND_C=`grep -c "$CMND_ST" "$1"`
if [ "$CMND_C" -eq 0 ];then #not found, add
sed -i -e "1 s%^%$CMND_\n%" "$1"
else #found, replace
sed -i "s%^ *$CMND_ST.*%$CMND_%" "$1"
fi
let "I+=1"
done
}
echo "GET VPNBOOK CONFIGS v 0.1"
if [[ "$1" == "-h" ]]; then
echo "Use "`basename $0`" [options]"
echo "Options:"
echo "-c - Clean unpack directory after get configs"
echo "-h - This help"
echo "Please check values of variables at the"
echo "beginning of the script (e.g WORKDIR)"
echo "and add your VPN Config options to ADD_COMMANDS array"
exit
fi
if [[ "$1" == "-c" ]]; then
echo "Cleaning unpack directory..."
rm -rf "$UNPDIR"
fi
rm "$WORKDIR$HTMLFILE"
mkdir -p "$WORKDIR"
mkdir -p "$UNPDIR"
echo "Get vpnbook page..."
wget -P $WORKDIR --default-page=$HTMLFILE --header="Content-type: text/html" $VPNBOOKPAGE
if [[ ! -f "$WORKDIR$HTMLFILE" ]];then
echo "Page not downloaded!"
exit
fi
for ZIPURL in $(xidel -s --extract "//a/@href" "$WORKDIR$HTMLFILE" |grep ".zip"); do
ZIPNAME=`basename $ZIPURL`
echo "Download $ZIPNAME..."
wget -P $WORKDIR "$VPNBOOKPAGE/$ZIPURL" >/dev/null 2>/dev/null
if [ -f "$WORKDIR$ZIPNAME" ];then
echo "Unpacking $ZIPNAME..."
unzip -o "$WORKDIR$ZIPNAME" -d "$UNPDIR" >/dev/null 2>/dev/null
rm "$WORKDIR$ZIPNAME"
fi
done
echo -n "Replacing Windows line ends"
for FLE in $(find $UNPDIR -maxdepth 1 -iname "*.ovpn"); do
echo -n "."
sed -i 's/\r$//' "$FLE"
done
echo
echo -n "Add commands"
for FLE in $(find $UNPDIR -maxdepth 1 -iname "*.ovpn"); do
echo -n "."
add_commands "$FLE"
done
echo
#copyng to outdir
if [ -n "$OUTDIR" ]; then
echo "Copy to outdir:"
for FLE in $(find $UNPDIR -maxdepth 1 -iname $OUTMASK); do
if [ -n "$FLE" ]; then
BN=`basename $FLE`
echo "$BN"
cp "$FLE" "$OUTDIR$BN"
fi
done
fi