-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoft-7debian.sh
More file actions
312 lines (286 loc) · 8.94 KB
/
soft-7debian.sh
File metadata and controls
312 lines (286 loc) · 8.94 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#!/bin/bash
#Requirement
if [ ! -e /usr/bin/curl ]; then
apt-get -y update && apt-get -y upgrade
apt-get -y install curl
fi
#check jika script sudah pernah diinput
scriptname='sshvpn';
mkdir -p /root/
echo " " >> /root/log-install-softether.txt
scriptchecker=`cat /root/log-install-softether.txt | grep $scriptname`;
if [ "$scriptchecker" != "" ]; then
clear
echo -e " ";
echo -e "Error! Anda sudah pernah memasukkan script ini sebelumnya";
echo -e "Script ini hanya boleh dimasukkan 1x saja!";
echo -e "---";
exit 0;
else
echo "";
fi
echo "$scriptname" >> /root/log-install-softether.txt
#inisialisasi
MYIP=$(curl -4 icanhazip.com)
if [ $MYIP = "" ]; then
MYIP=`ifconfig | grep 'inet addr:' | grep -v inet6 | grep -vE '127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | cut -d: -f2 | awk '{ print $1}' | head -1`;
fi
cekport=`netstat -ntulp | grep 443 && netstat -ntulp | grep 1194`;
if [ "$cekport" != "" ]; then
echo "Instalasi Tidak Dapat Dilanjutkan Oleh Sistem";
echo "Penyebab:";
echo "Kami mendeteksi port 443 atau port 1194 anda telah terpakai. Pastikan port 443 dan port 1194 anda tidak terpakai.";
echo "LOG:";
echo "==============";
echo "$cekport";
echo "==============";
exit 0;
fi
clear
red='\e[1;31m'
green='\e[0;32m'
NC='\e[0m'
echo "Connecting..."
sleep 0.1
echo "Checking Permision..."
MYIP=$(wget -qO- ipv4.icanhazip.com);
# check registered ip
wget -q -O daftarip http://ssh-top.xyz/daftarip.txt
if ! grep -w -q $MYIP daftarip; then
echo -e "${red}Permission Denied!${NC}";
if [[ $vps = "FNS" ]]; then
echo ""
else
echo -e "${red}MAAF IP ANDA BELUM TERDAFTAR ${NC}"
fi
rm -f /root/daftarip
exit
else
echo -e "${green}Permission Accepted...${NC}"
sleep 2.0
fi
clear
# disable ipv6
echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
sed -i '$ i\echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6' /etc/rc.local
#Add DNS Server ipv4
echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
sed -i '$ i\echo "nameserver 8.8.8.8" > /etc/resolv.conf' /etc/rc.local
sed -i '$ i\echo "nameserver 8.8.4.4" >> /etc/resolv.conf' /etc/rc.local
# install wget and curl
apt-get update;apt-get -y install wget curl;
# add repo
cat > /etc/apt/sources.list <<END2
deb http://cdn.debian.net/debian wheezy main contrib non-free
deb http://security.debian.org/ wheezy/updates main contrib non-free
deb http://packages.dotdeb.org wheezy all
END2
wget "http://www.dotdeb.org/dotdeb.gpg"
cat dotdeb.gpg | apt-key add -;rm dotdeb.gpg
#update
apt-get -y update && apt-get -y upgrade
#install important
apt-get install -y build-essential
apt-get install -y g++ gcc make nano
#install softether
wget http://www.softether-download.com/files/softether/v4.20-9608-rtm-2016.04.17-tree/Linux/SoftEther_VPN_Server/32bit_-_Intel_x86/softether-vpnserver-v4.20-9608-rtm-2016.04.17-linux-x86-32bit.tar.gz
tar -xzvf softether-vpnserver-v4.20-9608-rtm-2016.04.17-linux-x86-32bit.tar.gz
rm -f softether-vpnserver-v4.20-9608-rtm-2016.04.17-linux-x86-32bit.tar.gz
cd vpnserver
printf '1\n1\n1' | make
#back to root
cd
#move directory
mv vpnserver /usr/local
cd /usr/local/vpnserver/
chmod 600 *
chmod 700 vpncmd
chmod 700 vpnserver
DAEMON='$DAEMON'
LOCK='$LOCK'
VAR0='$0'
VAR1='$1'
syslog='$syslog'
remote_fs='remote_fs'
cat > /etc/init.d/vpnserver <<END
#!/bin/sh
### BEGIN INIT INFO
# Provides: vpnserver
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable Softether by daemon.
### END INIT INFO
DAEMON=/usr/local/vpnserver/vpnserver
LOCK=/var/lock/subsys/vpnserver
test -x $DAEMON || exit 0
case "$VAR1" in
start)
$DAEMON start
touch $LOCK
;;
stop)
$DAEMON stop
rm $LOCK
;;
restart)
$DAEMON stop
sleep 3
$DAEMON start
;;
*)
echo "Usage: $VAR0 {start|stop|restart}"
exit 1
esac
exit 0
END
mkdir /var/lock/subsys
chmod 755 /etc/init.d/vpnserver
#start server
/etc/init.d/vpnserver start
#set startup
update-rc.d vpnserver defaults
#cek apakah work
# cd /usr/local/vpnserver
# ./vpncmd
# ketik check . Jika sudah ketik exit.
#Setting
cd /usr/local/vpnserver/
# printf '1\n\n\nServerPasswordSet\nSetup123ScR\nSetup123ScR\n' | ./vpncmd
cd
clear
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
echo " "
#Setting di Softether Server Manager
clear
echo "=============================="
echo "Untuk melanjutkan instalasi, anda harus setting melalui SoftEther Server Manager"
echo "Pastikan Anda Telah melakukan semua step di bawah!"
echo "-------------------------------------"
echo "TUTORIAL SETTING LOCAL BRIDGE"
echo "1. Buka SoftEther Server Manager"
echo "2. Klik New Setting."
echo "3. Isikan $MYIP pada kolom Hostname. (Lainnya biarkan default)"
echo "4. Klik OK. Jika sudah tekan tombol CONNECT"
echo "5. Anda akan diminta untuk membuat password administrator softether. Masukkan password yang anda kehendaki."
echo "6. Jika ada window SoftEther Easy Setup, centang Remote Access VPN Server. lalu klik NEXT dan OK"
echo "7. Jika ada window Dynamic DNS Fuction, klik Exit"
echo "8. Jika ada window IPsec/L2TP/EtherIP, centang Enable L2TP Server Functions (L2TP over IPsec)"
echo "9. Jika ada window VPN Azure Service Setting, Klik Disable VPN Azure. Kemudian tekan OK"
echo "10. Jika muncul jendela VPN Easy Setup Task atau Permintaan Update, Close saja"
echo "11. Pada halaman utama SoftEther Server Manager, klik tombol LOCAL BRIDGE SETTING"
echo "12. Pada kolom Virtual Hub, pilih VPN. Kemudian centang tulisan Bridge with New Tap Device"
echo "13. Pada kolom New Tap Device Name, isikan dengan tulisan soft"
echo "14. Klik Create Local Bridge."
echo "15. Pastikan statusnya adalah operating. Jika sudah, close softether server manager"
echo "-------------------------------------"
echo "Jika anda telah menyelesaikan step di atas, tekan sembarang tombol"
echo "=============================="
#Verifikasi
read -n1 -r -p "Press any key to continue..." key
if [ "$key" = !'' ]; then
echo "Instalasi Telah Dibatalkan";
fi
echo " "
echo "------------"
echo "Apakah Anda Yakin Telah Menyelesaikan Semua Langkah Di Atas? "
read -n1 -r -p "Jika yakin sudah, tekan sembarang tombol!" key2
if [ "$key2" = !'' ]; then
echo "Instalasi Telah Dibatalkan";
fi
#cd
apt-get -y install dnsmasq
cat >> /etc/dnsmasq.conf <<END
interface=tap_soft
dhcp-range=tap_soft,192.168.7.50,192.168.7.60,12h
dhcp-option=tap_soft,3,192.168.7.1
END
/etc/init.d/dnsmasq restart
#Setting Iptables
#if [ $(ifconfig | cut -c 1-8 | sort | uniq -u | grep venet0 | grep -v venet0:) = "venet0" ];then
# iptables -t nat -A POSTROUTING -o venet0 -j SNAT --to-source $MYIP
# iptables -t nat -A POSTROUTING -s 192.168.7.0/24 -j SNAT --to-source $MYIP
# sed -i '/-A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT/a -A FORWARD -s 192.168.7.0/255.255.255.0 -j ACCEPT' /etc/iptables.up.rules
# echo
# else
# iptables -t nat -A POSTROUTING -s 192.168.7.0/24 -o eth0 -j MASQUERADE
# sed -i '/-A POSTROUTING -o eth0 -j MASQUERADE/a -A POSTROUTING -s 192.168.7.0/24 -o eth0 -j MASQUERADE' /etc/iptables.up.rules
#fi
sed -i 's|#net.ipv4.ip_forward=1|net.ipv4.ip_forward=1|' /etc/sysctl.conf
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s 192.168.7.0/24 -j SNAT --to-source $MYIP
iptables-save > /etc/iptables.up.rules
iptables-restore < /etc/iptables.up.rules
sed -i '$ i\iptables-restore < /etc/iptables.up.rules' /etc/rc.local
#Ganti Startup Scriptnya
DAEMON='$DAEMON'
LOCK='$LOCK'
VAR0='$0'
VAR1='$1'
TAP_ADDR='$TAP_ADDR'
syslog='$syslog'
remote_fs='remote_fs'
cat > /etc/init.d/vpnserver <<END
#!/bin/sh
### BEGIN INIT INFO
# Provides: vpnserver
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable Softether by daemon.
### END INIT INFO
DAEMON=/usr/local/vpnserver/vpnserver
LOCK=/var/lock/subsys/vpnserver
TAP_ADDR=192.168.7.1
test -x $DAEMON || exit 0
case "$VAR1" in
start)
$DAEMON start
touch $LOCK
sleep 1
/sbin/ifconfig tap_soft $TAP_ADDR
;;
stop)
$DAEMON stop
rm $LOCK
;;
restart)
$DAEMON stop
sleep 3
$DAEMON start
sleep 1
/sbin/ifconfig tap_soft $TAP_ADDR
;;
*)
echo "Usage: $VAR0 {start|stop|restart}"
exit 1
esac
exit 0
END
cd
/etc/init.d/vpnserver restart
/etc/init.d/dnsmasq restart
clear
clear
echo "Automatic Script Installer" | tee log-install-softether.txt
echo "===============================================" | tee log-install-softether.txt
echo "" | tee log-install-softether.txt
echo "Service" | tee log-install-softether.txt
echo "-------" | tee log-install-softether.txt
echo "Softehter VPN : TCP 443, 1194, 555, 992" | tee log-install-softether.txt
echo "Hostname: $MYIP" | tee log-install-softether.txt
echo "Password : (Sesuai dengan password yang anda input di SoftEther Server Manager)" | tee log-install-softether.txt
echo "===============================================" | tee log-install-softether.txt